+ if (strcmp(hb_audio_rates[ii].string, str) == 0)
+ {
+ result = hb_audio_rates[ii].rate;
+ break;
+ }
+ }
+ g_free(str);
+ return result;
+}
+
+static const gchar*
+lookup_audio_rate_option(const GValue *rate)
+{
+ gint ii;
+ gchar *str;
+ const gchar *result = "Same as source";
+
+ // Coincidentally, the string "source" will return 0
+ // which is our flag to use "same as source"
+ str = ghb_value_string(rate);
+ for (ii = 0; ii < hb_audio_rates_count; ii++)
+ {
+ if (strcmp(hb_audio_rates[ii].string, str) == 0)
+ {
+ result = hb_audio_rates[ii].string;
+ break;
+ }
+ }
+ g_free(str);
+ return result;
+}
+
+static gint
+lookup_audio_bitrate_int(const GValue *rate)
+{
+ gint ii;
+ gchar *str;
+ gint result = 0;
+
+ // Coincidentally, the string "source" will return 0
+ // which is our flag to use "same as source"
+ str = ghb_value_string(rate);
+ for (ii = 0; ii < hb_audio_bitrates_count; ii++)
+ {
+ if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
+ {
+ result = hb_audio_bitrates[ii].rate;
+ break;
+ }
+ }
+ g_free(str);
+ return result;
+}
+
+static const gchar*
+lookup_audio_bitrate_option(const GValue *rate)
+{
+ gint ii;
+ gchar *str;
+ const gchar *result = "Same as source";
+
+ // Coincidentally, the string "source" will return 0
+ // which is our flag to use "same as source"
+ str = ghb_value_string(rate);
+ for (ii = 0; ii < hb_audio_bitrates_count; ii++)
+ {
+ if (strcmp(hb_audio_bitrates[ii].string, str) == 0)
+ {
+ result = hb_audio_bitrates[ii].string;
+ break;
+ }
+ }
+ g_free(str);
+ return result;
+}
+
+static gint
+lookup_audio_lang_int(const GValue *rate)
+{
+ gint ii;
+ gchar *str;
+ gint result = 0;
+
+ // Coincidentally, the string "source" will return 0
+ // which is our flag to use "same as source"
+ str = ghb_value_string(rate);
+ for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
+ {
+ if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
+ {
+ result = ii;
+ break;
+ }
+ }
+ g_free(str);
+ return result;
+}
+
+static const gchar*
+lookup_audio_lang_option(const GValue *rate)
+{
+ gint ii;
+ gchar *str;
+ const gchar *result = "Same as source";
+
+ // Coincidentally, the string "source" will return 0
+ // which is our flag to use "same as source"
+ str = ghb_value_string(rate);
+ for (ii = 0; ii < LANG_TABLE_SIZE; ii++)
+ {
+ if (strcmp(ghb_language_table[ii].iso639_2, str) == 0)
+ {
+ if (ghb_language_table[ii].native_name[0] != 0)
+ result = ghb_language_table[ii].native_name;
+ else
+ result = ghb_language_table[ii].eng_name;
+ break;
+ }
+ }
+ g_free(str);
+ return result;
+}
+
+static GValue*
+get_acodec_value(gint val)
+{
+ GValue *value = NULL;
+ gint ii;
+
+ for (ii = 0; ii < acodec_opts.count; ii++)
+ {
+ if ((int)acodec_opts.map[ii].ivalue == val)
+ {
+ value = ghb_string_value_new(acodec_opts.map[ii].shortOpt);
+ break;
+ }
+ }
+ return value;
+}
+
+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_subtitle_track_source(signal_user_data_t *ud, gint track)
+{
+ gint titleindex;
+
+ if (track == -2)
+ return SRTSUB;
+ if (track < 0)
+ return VOBSUB;
+ titleindex = ghb_settings_combo_int(ud->settings, "title");
+ if (titleindex < 0)
+ return VOBSUB;
+
+ hb_list_t * list;
+ hb_title_t * title;
+ hb_subtitle_t * sub;
+
+ if (h_scan == NULL) return VOBSUB;
+ list = hb_get_titles( h_scan );
+ if( !hb_list_count( list ) )
+ {
+ /* No valid title, stop right there */
+ return VOBSUB;
+ }
+ title = hb_list_item( list, titleindex );
+ if (title == NULL) return VOBSUB; // Bad titleindex
+ sub = hb_list_item( title->list_subtitle, track);
+ if (sub != NULL)
+ return sub->source;
+ else
+ return VOBSUB;
+}
+
+const char*
+ghb_subtitle_track_source_name(signal_user_data_t *ud, gint track)
+{
+ gint titleindex;
+ const gchar * name = "Unknown";
+
+ if (track == -2)
+ {
+ name = "SRT";
+ goto done;
+ }
+ if (track == -1)
+ {
+ name = "Bitmap";
+ goto done;
+ }
+
+ titleindex = ghb_settings_combo_int(ud->settings, "title");
+ if (titleindex < 0)
+ goto done;
+
+ hb_list_t * list;
+ hb_title_t * title;
+ hb_subtitle_t * sub;
+
+ if (h_scan == NULL)
+ goto done;
+ list = hb_get_titles( h_scan );
+ if( !hb_list_count( list ) )
+ goto done;
+
+ title = hb_list_item( list, titleindex );
+ if (title == NULL)
+ goto done;
+
+ sub = hb_list_item( title->list_subtitle, track);
+ if (sub != NULL)
+ {
+ switch (sub->source)
+ {
+ case VOBSUB:
+ name = "Bitmap";
+ break;
+ case CC708SUB:
+ case CC608SUB:
+ name = "Text";
+ break;
+ case SRTSUB:
+ name = "SRT";
+ break;
+ default:
+ break;
+ }
+ }
+
+done:
+ return name;
+}
+
+gchar*
+ghb_subtitle_track_lang(signal_user_data_t *ud, gint track)
+{
+ gint titleindex;
+
+ titleindex = ghb_settings_combo_int(ud->settings, "title");
+ if (titleindex < 0)
+ goto fail;
+ if (track == -1)
+ return ghb_get_user_audio_lang(ud, titleindex, 0);
+ if (track < 0)
+ goto fail;
+
+ hb_list_t * list;
+ hb_title_t * title;
+ hb_subtitle_t * sub;
+
+ if (h_scan == NULL)
+ goto fail;
+
+ list = hb_get_titles( h_scan );
+ if( !hb_list_count( list ) )
+ {
+ /* No valid title, stop right there */
+ goto fail;
+ }
+ title = hb_list_item( list, titleindex );
+ if (title == NULL) // Bad titleindex
+ goto fail;
+ sub = hb_list_item( title->list_subtitle, track);
+ if (sub != NULL)
+ return g_strdup(sub->iso639_2);
+
+fail:
+ return g_strdup("und");
+}
+
+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_dca = TRUE;
+ allow_dca = (container != HB_MUX_MP4);
+
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, FALSE);
+ if (allow_dca)
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, FALSE);
+ else
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, TRUE);
+
+ if (audio && audio->in.codec != HB_ACODEC_AC3)
+ {
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_AC3, TRUE);
+ }
+ if (audio && audio->in.codec != HB_ACODEC_DCA)
+ {
+ grey_combo_box_item(builder, "AudioEncoder", HB_ACODEC_DCA, 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);