+ if (hb_audio_bitrates[ii].rate == val)
+ {
+ value = ghb_string_value_new(hb_audio_bitrates[ii].string);
+ break;
+ }
+ }
+ return value;
+}
+#endif
+
+static GValue*
+get_amix_value(gint val)
+{
+ GValue *value = NULL;
+ gint ii;
+
+ for (ii = 0; ii < hb_audio_mixdowns_count; ii++)
+ {
+ if (hb_audio_mixdowns[ii].amixdown == val)
+ {
+ value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name);
+ break;
+ }
+ }
+ return value;
+}
+
+// Handle for libhb. Gets set by ghb_backend_init()
+static hb_handle_t * h_scan = NULL;
+static hb_handle_t * h_queue = NULL;
+
+extern void hb_get_tempory_directory(hb_handle_t *h, char path[512]);
+
+gchar*
+ghb_get_tmp_dir()
+{
+ char dir[512];
+
+ hb_get_tempory_directory(h_scan, dir);
+ return g_strdup(dir);
+}
+
+void
+ghb_hb_cleanup(gboolean partial)
+{
+ char dir[512];
+
+ hb_get_tempory_directory(h_scan, dir);
+ del_tree(dir, !partial);
+}
+
+gint
+ghb_get_title_number(gint titleindex)
+{
+ hb_list_t * list;
+ hb_title_t * title;
+
+ if (h_scan == NULL) return 1;
+ list = hb_get_titles( h_scan );
+ if( !hb_list_count( list ) )
+ {
+ /* No valid title, stop right there */
+ return 1;
+ }
+ title = hb_list_item( list, titleindex );
+ if (title == NULL) return 1; // Bad titleindex
+ return title->index;
+}
+
+static hb_audio_config_t*
+get_hb_audio(gint titleindex, gint track)
+{
+ hb_list_t * list;
+ hb_title_t * title;
+ hb_audio_config_t *audio = NULL;
+
+ if (h_scan == NULL) return NULL;
+ list = hb_get_titles( h_scan );
+ if( !hb_list_count( list ) )
+ {
+ /* No valid title, stop right there */
+ return NULL;
+ }
+ title = hb_list_item( list, titleindex );
+ if (title == NULL) return NULL; // Bad titleindex
+ if (!hb_list_count(title->list_audio))
+ {
+ return NULL;
+ }
+ audio = (hb_audio_config_t *)hb_list_audio_config_item(title->list_audio, track);
+ return audio;
+}
+
+static gint
+search_rates(hb_rate_t *rates, gint rate, gint count)
+{
+ gint ii;
+ for (ii = 0; ii < count; ii++)
+ {
+ if (rates[ii].rate == rate)
+ return ii;
+ }
+ return -1;
+}
+
+static gboolean find_combo_item_by_int(GtkTreeModel *store, gint value, GtkTreeIter *iter);
+
+static GtkListStore*
+get_combo_box_store(GtkBuilder *builder, const gchar *name)
+{
+ GtkComboBox *combo;
+ GtkListStore *store;
+
+ g_debug("get_combo_box_store() %s\n", name);
+ // First modify the combobox model to allow greying out of options
+ combo = GTK_COMBO_BOX(GHB_WIDGET(builder, name));
+ store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
+ return store;
+}
+
+static void
+grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean grey)
+{
+ GtkListStore *store;
+ GtkTreeIter iter;
+
+ store = get_combo_box_store(builder, name);
+ if (find_combo_item_by_int(GTK_TREE_MODEL(store), value, &iter))
+ {
+ gtk_list_store_set(store, &iter,
+ 1, !grey,
+ -1);
+ }
+}
+
+void
+ghb_grey_combo_options(GtkBuilder *builder)
+{
+ GtkWidget *widget;
+ gint container, track, titleindex, acodec;
+ hb_audio_config_t *audio = NULL;
+ GValue *gval;
+
+ widget = GHB_WIDGET (builder, "title");
+ gval = ghb_widget_value(widget);
+ titleindex = ghb_lookup_combo_int("title", gval);
+ ghb_value_free(gval);
+ widget = GHB_WIDGET (builder, "AudioTrack");
+ gval = ghb_widget_value(widget);
+ track = ghb_lookup_combo_int("AudioTrack", gval);
+ ghb_value_free(gval);
+ audio = get_hb_audio(titleindex, track);
+ widget = GHB_WIDGET (builder, "FileFormat");
+ gval = ghb_widget_value(widget);
+ container = ghb_lookup_combo_int("FileFormat", gval);
+ ghb_value_free(gval);
+
+ grey_combo_box_item(builder, "x264_analyse", 3, TRUE);
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, FALSE);
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, FALSE);
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, FALSE);
+
+ gboolean allow_ac3 = TRUE;
+ allow_ac3 = (container != HB_MUX_OGM);
+
+ if (allow_ac3)
+ {
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
+ }
+ else
+ {
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
+ }
+ if (audio && audio->in.codec != HB_ACODEC_AC3)
+ {
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
+ }
+ grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, FALSE);
+
+ widget = GHB_WIDGET (builder, "AudioEncoder");
+ gval = ghb_widget_value(widget);
+ acodec = ghb_lookup_combo_int("AudioEncoder", gval);
+ ghb_value_free(gval);
+ if (acodec != HB_ACODEC_AC3)
+ {
+ grey_combo_box_item(builder, "AudioMixdown", 0, TRUE);
+ }
+ if (container == HB_MUX_MP4)
+ {
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_LAME, TRUE);
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
+ grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
+ }
+ else if (container == HB_MUX_AVI)
+ {
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_VORBIS, TRUE);
+ grey_combo_box_item(builder, "VideoEncoder", HB_VCODEC_THEORA, TRUE);
+ }
+ else if (container == HB_MUX_OGM)
+ {
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_FAAC, TRUE);