diff options
author | jstebbins <[email protected]> | 2011-10-16 17:33:20 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2011-10-16 17:33:20 +0000 |
commit | 49fad04f4365f0c3c01583dabd8d261ec76505f3 (patch) | |
tree | dee0f99ba705f57f21bffa8390380974a521ffba /gtk/src/audiohandler.c | |
parent | cf10a485d3892f8d2d055c62ba0b853a7286bd57 (diff) |
LinGui: experimental support for batch queuing
This allows all titles in the title popup to be added to the queue in
one go. It uses the current *preset* for the settings. I.e. settings
changes in the UI are ignored. This deficiency will be rectified at a
future time.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4294 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src/audiohandler.c')
-rw-r--r-- | gtk/src/audiohandler.c | 268 |
1 files changed, 198 insertions, 70 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c index 39c42bd74..2e12c1939 100644 --- a/gtk/src/audiohandler.c +++ b/gtk/src/audiohandler.c @@ -20,11 +20,26 @@ #include "preview.h" #include "audiohandler.h" -static void ghb_add_audio(signal_user_data_t *ud, GValue *settings); +static gboolean ghb_add_audio_to_settings(GValue *settings, GValue *asettings); +static void ghb_add_audio_to_ui(GtkBuilder *builder, const GValue *settings); static GValue* get_selected_asettings(signal_user_data_t *ud); +static void ghb_clear_audio_list_settings(GValue *settings); +static void ghb_clear_audio_list_ui(GtkBuilder *builder); static gboolean block_updates = FALSE; +void +check_list_full(signal_user_data_t *ud) +{ + GValue *audio_list; + gint count; + + audio_list = ghb_settings_get_value(ud->settings, "audio_list"); + count = ghb_array_len(audio_list); + GtkWidget * widget = GHB_WIDGET(ud->builder, "audio_add"); + gtk_widget_set_sensitive(widget, count != 99); +} + gint ghb_select_audio_codec(gint mux, hb_audio_config_t *aconfig, gint acodec, gint fallback, gint copy_mask) { @@ -122,6 +137,74 @@ static int ghb_select_fallback( GValue *settings, int mux, int acodec ) } void +ghb_sanitize_audio(GValue *settings, GValue *asettings) +{ + gint titleindex, track, acodec, select_acodec, mix; + hb_audio_config_t *aconfig; + gint mux; + gint bitrate; + gint sr; + + g_debug("ghb_santiize_audio ()"); + mux = ghb_settings_combo_int(settings, "FileFormat"); + titleindex = ghb_settings_get_int(settings, "title_no"); + track = ghb_settings_combo_int(asettings, "AudioTrack"); + acodec = ghb_settings_combo_int(asettings, "AudioEncoder"); + mix = ghb_settings_combo_int(asettings, "AudioMixdown"); + bitrate = ghb_settings_combo_int(asettings, "AudioBitrate"); + sr = ghb_settings_combo_int(asettings, "AudioSamplerate"); + + aconfig = ghb_get_scan_audio_info(titleindex, track); + if (sr == 0) + { + sr = aconfig ? aconfig->in.samplerate : 48000; + } + gint fallback = ghb_select_fallback(settings, mux, acodec); + gint copy_mask = ghb_get_copy_mask(settings); + select_acodec = ghb_select_audio_codec(mux, aconfig, acodec, fallback, copy_mask); + gboolean codec_defined_bitrate = FALSE; + if (ghb_audio_is_passthru (select_acodec)) + { + if (aconfig) + { + bitrate = aconfig->in.bitrate / 1000; + + // Set the values for bitrate and samplerate to the input rates + mix = 0; + ghb_settings_set_string(asettings, "AudioMixdown", + ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); + select_acodec &= aconfig->in.codec | HB_ACODEC_PASS_FLAG; + codec_defined_bitrate = TRUE; + ghb_settings_set_string(asettings, "AudioSamplerate", + ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(0))); + } + else + { + mix = 0; + ghb_settings_set_string(asettings, "AudioMixdown", + ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); + ghb_settings_set_string(asettings, "AudioSamplerate", + ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(0))); + bitrate = 448; + } + ghb_settings_set_double(asettings, "AudioTrackDRCSlider", 0.0); + } + else + { + if (mix == 0) + mix = ghb_get_best_mix( aconfig, select_acodec, 0); + bitrate = hb_get_best_audio_bitrate(select_acodec, bitrate, sr, mix); + ghb_settings_set_string(asettings, "AudioMixdown", + ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); + } + ghb_settings_set_string(asettings, "AudioBitrate", + ghb_lookup_combo_string("AudioBitrate", ghb_int_value(bitrate))); + + ghb_settings_take_value(asettings, "AudioEncoderActual", + ghb_lookup_acodec_value(select_acodec)); +} + +void ghb_adjust_audio_rate_combos(signal_user_data_t *ud) { gint titleindex, track, acodec, select_acodec, mix; @@ -226,12 +309,12 @@ free_audio_hash_key_value(gpointer data) } gchar* -ghb_get_user_audio_lang(signal_user_data_t *ud, gint titleindex, gint track) +ghb_get_user_audio_lang(GValue *settings, gint titleindex, gint track) { GValue *audio_list, *asettings; gchar *lang = NULL; - audio_list = ghb_settings_get_value(ud->settings, "audio_list"); + audio_list = ghb_settings_get_value(settings, "audio_list"); if (ghb_array_len(audio_list) <= track) return NULL; asettings = ghb_array_get_nth(audio_list, track); @@ -241,7 +324,7 @@ ghb_get_user_audio_lang(signal_user_data_t *ud, gint titleindex, gint track) } void -ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) +ghb_set_pref_audio_settings(gint titleindex, GValue *settings) { gint track; gchar *source_lang = NULL; @@ -256,20 +339,21 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) gint count, ii, list_count; g_debug("set_pref_audio"); - mux = ghb_settings_combo_int(ud->settings, "FileFormat"); + mux = ghb_settings_combo_int(settings, "FileFormat"); track_indices = g_hash_table_new_full(g_int_hash, g_int_equal, free_audio_hash_key_value, free_audio_hash_key_value); // Clear the audio list - ghb_clear_audio_list(ud); + ghb_clear_audio_list_settings(settings); + // Find "best" audio based on audio preferences - if (!ghb_settings_get_boolean(ud->settings, "AudioDUB")) + if (!ghb_settings_get_boolean(settings, "AudioDUB")) { source_lang = ghb_get_source_audio_lang(titleindex, 0); } if (source_lang == NULL) - source_lang = ghb_settings_get_string(ud->settings, "PreferredLanguage"); + source_lang = ghb_settings_get_string(settings, "PreferredLanguage"); - pref_audio = ghb_settings_get_value(ud->settings, "AudioList"); + pref_audio = ghb_settings_get_value(settings, "AudioList"); list_count = 0; count = ghb_array_len(pref_audio); @@ -280,8 +364,8 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) audio = ghb_array_get_nth(pref_audio, ii); acodec = ghb_settings_combo_int(audio, "AudioEncoder"); - fallback = ghb_select_fallback( ud->settings, mux, acodec ); - gint copy_mask = ghb_get_copy_mask(ud->settings); + fallback = ghb_select_fallback(settings, mux, acodec); + gint copy_mask = ghb_get_copy_mask(settings); select_acodec = ghb_select_audio_codec(mux, NULL, acodec, fallback, copy_mask); bitrate = ghb_settings_combo_int(audio, "AudioBitrate"); rate = ghb_settings_combo_double(audio, "AudioSamplerate"); @@ -305,7 +389,7 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) // HB_ACODEC_* are bit fields. Treat acodec as mask if (!(aconfig->in.codec & select_acodec & HB_ACODEC_PASS_MASK)) { - if (acodec != HB_ACODEC_AUTO_PASS) + if (acodec != HB_ACODEC_ANY) acodec = fallback; // If we can't substitute the passthru with a suitable // encoder and @@ -326,7 +410,6 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) bitrate = aconfig->in.bitrate / 1000; bitrate = hb_get_best_audio_bitrate(select_acodec, bitrate, aconfig->in.samplerate, mix); - quality = hb_get_default_audio_quality( select_acodec ); rate = 0; } } @@ -339,32 +422,53 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) acodec = 0; if (acodec != 0) { - GValue *settings = ghb_dict_value_new(); - ghb_settings_set_int(settings, "AudioTrack", track); - ghb_settings_set_string(settings, "AudioEncoder", + GValue *asettings = ghb_dict_value_new(); + ghb_settings_set_int(asettings, "AudioTrack", track); + ghb_settings_set_string(asettings, "AudioEncoder", ghb_lookup_combo_string("AudioEncoder", ghb_int_value(acodec))); - ghb_settings_set_value(settings, "AudioEncoderActual", + ghb_settings_set_value(asettings, "AudioEncoderActual", ghb_lookup_acodec_value(select_acodec)); - ghb_settings_set_value(settings, "AudioTrackQualityEnable", enable_qual); - ghb_settings_set_double(settings, "AudioTrackQuality", quality); + ghb_settings_set_value(asettings, "AudioTrackQualityEnable", enable_qual); + ghb_settings_set_double(asettings, "AudioTrackQuality", quality); + // This gets set autimatically if the codec is passthru - ghb_settings_set_string(settings, "AudioBitrate", + ghb_settings_set_string(asettings, "AudioBitrate", ghb_lookup_combo_string("AudioBitrate", ghb_int_value(bitrate))); - ghb_settings_set_string(settings, "AudioSamplerate", + ghb_settings_set_string(asettings, "AudioSamplerate", ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(rate))); mix = ghb_get_best_mix( aconfig, select_acodec, mix); - ghb_settings_set_string(settings, "AudioMixdown", + ghb_settings_set_string(asettings, "AudioMixdown", ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); - ghb_settings_set_value(settings, "AudioTrackDRCSlider", drc); - ghb_settings_set_value(settings, "AudioTrackGain", gain); - ghb_add_audio(ud, settings); - ghb_adjust_audio_rate_combos(ud); + ghb_settings_set_value(asettings, "AudioTrackDRCSlider", drc); + ghb_settings_set_value(asettings, "AudioTrackGain", gain); + ghb_sanitize_audio(settings, asettings); + ghb_add_audio_to_settings(settings, asettings); } } g_free(source_lang); g_hash_table_destroy(track_indices); } +void +ghb_set_pref_audio_from_settings(signal_user_data_t *ud, GValue *settings) +{ + const GValue *audio_list, *audio; + gint count, ii; + + // Clear the audio list + ghb_clear_audio_list_ui(ud->builder); + + audio_list = ghb_settings_get_value(settings, "audio_list"); + count = ghb_array_len(audio_list); + for (ii = 0; ii < count; ii++) + { + audio = ghb_array_get_nth(audio_list, ii); + ghb_add_audio_to_ui(ud->builder, audio); + ghb_adjust_audio_rate_combos(ud); + } + check_list_full(ud); +} + static GValue* get_selected_asettings(signal_user_data_t *ud) { @@ -617,7 +721,6 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) ghb_settings_set_value(asettings, "AudioEncoderActual", ghb_settings_get_value(ud->settings, "AudioEncoderActual")); ghb_audio_list_refresh_selected(ud); } - ghb_update_destination_extension(ud); ghb_live_reset(ud); float low, high, gran, defval; @@ -859,28 +962,35 @@ gain_widget_changed_cb(GtkWidget *widget, signal_user_data_t *ud) } void -ghb_clear_audio_list(signal_user_data_t *ud) +ghb_clear_audio_list_settings(GValue *settings) { - GtkTreeView *treeview; - GtkListStore *store; GValue *audio_list; - g_debug("clear_audio_list ()"); - audio_list = ghb_settings_get_value(ud->settings, "audio_list"); + g_debug("clear_audio_list_settings ()"); + audio_list = ghb_settings_get_value(settings, "audio_list"); if (audio_list == NULL) { audio_list = ghb_array_value_new(8); - ghb_settings_set_value(ud->settings, "audio_list", audio_list); + ghb_settings_set_value(settings, "audio_list", audio_list); } else ghb_array_value_reset(audio_list, 8); - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list")); +} + +void +ghb_clear_audio_list_ui(GtkBuilder *builder) +{ + GtkTreeView *treeview; + GtkListStore *store; + + g_debug("clear_audio_list_ui ()"); + treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "audio_list")); store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview)); gtk_list_store_clear (store); } static void -add_to_audio_list(signal_user_data_t *ud, GValue *settings) +ghb_add_audio_to_ui(GtkBuilder *builder, const GValue *settings) { GtkTreeView *treeview; GtkTreeIter iter; @@ -892,8 +1002,8 @@ add_to_audio_list(signal_user_data_t *ud, GValue *settings) gdouble drc; gdouble gain; - g_debug("add_to_audio_list ()"); - treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list")); + g_debug("ghb_add_audio_to_ui ()"); + treeview = GTK_TREE_VIEW(GHB_WIDGET(builder, "audio_list")); selection = gtk_tree_view_get_selection (treeview); store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview)); @@ -994,37 +1104,46 @@ audio_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t } } -static void -ghb_add_audio(signal_user_data_t *ud, GValue *settings) +static gboolean +ghb_add_audio_to_settings(GValue *settings, GValue *asettings) { GValue *audio_list; - int count; const gchar * track; + int count; - track = ghb_settings_combo_option(settings, "AudioTrack"); - ghb_settings_set_string(settings, "AudioTrackDescription", track); - - GValue *aname; - aname = ghb_dict_lookup(settings, "AudioTrackName"); - if (aname == NULL) - { - ghb_settings_set_string(settings, "AudioTrackName", ""); - } - audio_list = ghb_settings_get_value(ud->settings, "audio_list"); + audio_list = ghb_settings_get_value(settings, "audio_list"); if (audio_list == NULL) { audio_list = ghb_array_value_new(8); - ghb_settings_set_value(ud->settings, "audio_list", audio_list); + ghb_settings_set_value(settings, "audio_list", audio_list); } - ghb_array_append(audio_list, settings); - add_to_audio_list(ud, settings); count = ghb_array_len(audio_list); + // Don't allow more than 99 + // This is a hard limit imposed by libhb/reader.c:GetFifoForId() if (count >= 99) { - GtkWidget * widget = GHB_WIDGET(ud->builder, "audio_add"); - gtk_widget_set_sensitive(widget, FALSE); + ghb_value_free(asettings); + return FALSE; + } + + int title_no = ghb_settings_get_int(settings, "title_no"); + int track_no = ghb_settings_get_int(asettings, "AudioTrack"); + track = ghb_audio_track_description(track_no, title_no); + ghb_settings_set_string(asettings, "AudioTrackDescription", track); + + GValue *aname; + aname = ghb_dict_lookup(asettings, "AudioTrackName"); + if (aname == NULL) + { + ghb_settings_set_string(asettings, "AudioTrackName", ""); } - ghb_update_destination_extension(ud); + if (ghb_array_len(audio_list) >= 99) + { + ghb_value_free(asettings); + return FALSE; + } + ghb_array_append(audio_list, asettings); + return TRUE; } G_MODULE_EXPORT void @@ -1057,7 +1176,11 @@ audio_add_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) widget = GHB_WIDGET(ud->builder, "AudioTrackDRCSlider"); ghb_settings_take_value(asettings, "AudioTrackDRCSlider", ghb_widget_value(widget)); - ghb_add_audio(ud, asettings); + if (!ghb_add_audio_to_settings(ud->settings, asettings)) + return; + + ghb_add_audio_to_ui(ud->builder, asettings); + check_list_full(ud); } G_MODULE_EXPORT void @@ -1145,7 +1268,8 @@ ghb_set_audio(signal_user_data_t *ud, GValue *settings) g_debug("set_audio"); // Clear the audio list - ghb_clear_audio_list(ud); + ghb_clear_audio_list_settings(ud->settings); + ghb_clear_audio_list_ui(ud->builder); alist = ghb_settings_get_value(settings, "audio_list"); count = ghb_array_len(alist); @@ -1166,22 +1290,26 @@ ghb_set_audio(signal_user_data_t *ud, GValue *settings) if (acodec_code != 0) { - GValue *settings = ghb_dict_value_new(); - ghb_settings_set_value(settings, "AudioTrack", track); - ghb_settings_set_value(settings, "AudioEncoder", acodec); - ghb_settings_set_value(settings, "AudioEncoderActual", acodec_actual); - ghb_settings_set_value(settings, "AudioTrackQualityEnable", enable_quality); - ghb_settings_set_value(settings, "AudioTrackQuality", quality); + GValue *asettings = ghb_dict_value_new(); + ghb_settings_set_value(asettings, "AudioTrack", track); + ghb_settings_set_value(asettings, "AudioEncoder", acodec); + ghb_settings_set_value(asettings, "AudioEncoderActual", acodec_actual); + ghb_settings_set_value(asettings, "AudioTrackQualityEnable", enable_quality); + ghb_settings_set_value(asettings, "AudioTrackQuality", quality); // This gets set autimatically if the codec is passthru - ghb_settings_set_value(settings, "AudioBitrate", bitrate); - ghb_settings_set_value(settings, "AudioSamplerate", rate); - ghb_settings_set_value(settings, "AudioMixdown", mix); - ghb_settings_set_value(settings, "AudioTrackGain", gain); - ghb_settings_set_value(settings, "AudioTrackDRCSlider", drc); - ghb_add_audio(ud, settings); + ghb_settings_set_value(asettings, "AudioBitrate", bitrate); + ghb_settings_set_value(asettings, "AudioSamplerate", rate); + ghb_settings_set_value(asettings, "AudioMixdown", mix); + ghb_settings_set_value(asettings, "AudioTrackGain", gain); + ghb_settings_set_value(asettings, "AudioTrackDRCSlider", drc); + + ghb_add_audio_to_settings(ud->settings, asettings); + + ghb_add_audio_to_ui(ud->builder, asettings); ghb_adjust_audio_rate_combos(ud); } } + check_list_full(ud); } |