diff options
author | jstebbins <[email protected]> | 2009-11-24 18:50:01 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2009-11-24 18:50:01 +0000 |
commit | c17739c6af65faf402b4c15aba264b70f6baa4fa (patch) | |
tree | fb705964a3305cbec9b56641e56d3049e30aa846 /gtk | |
parent | 60af6f9d902e5e43cf7b5b527f3b7be38694392a (diff) |
LinGui: enhancements to automatic audio selection when passthru is requested
and the source codec isn't capable of passthru.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2969 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/src/audiohandler.c | 76 | ||||
-rw-r--r-- | gtk/src/hb-backend.c | 85 | ||||
-rw-r--r-- | gtk/src/hb-backend.h | 4 | ||||
-rw-r--r-- | gtk/src/subtitlehandler.c | 1 |
4 files changed, 111 insertions, 55 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c index 935d961c5..773da280e 100644 --- a/gtk/src/audiohandler.c +++ b/gtk/src/audiohandler.c @@ -57,15 +57,17 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) if (ghb_audio_is_passthru (ainfo.codec)) { ghb_set_passthru_bitrate_opts (ud->builder, br); + ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(0)); } else { acodec = ghb_select_audio_codec(ud, audioindex); br = ghb_find_closest_audio_bitrate(acodec, br); + mix = ghb_get_best_mix( titleindex, audioindex, acodec, 0); + ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix)); } ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(br)); ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0)); - ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(0)); } else { @@ -101,8 +103,8 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) } } -void -free_audio_index_list(gpointer data) +static void +free_audio_hash_key_value(gpointer data) { g_free(data); } @@ -125,19 +127,27 @@ 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) { - gint acodec_code, mix_code, track; + gint fallback_acodec, track; gchar *source_lang = NULL; GtkWidget *button; ghb_audio_info_t ainfo; GHashTable *track_indices; + gint mux; const GValue *pref_audio; - const GValue *audio, *acodec, *bitrate, *rate, *mix, *drc; + const GValue *audio, *drc; + gint acodec, bitrate, mix; + gdouble rate; gint count, ii, list_count; g_debug("set_pref_audio"); + mux = ghb_settings_combo_int(ud->settings, "FileFormat"); + if (mux == HB_MUX_MP4) + fallback_acodec = HB_ACODEC_FAAC; + else + fallback_acodec = HB_ACODEC_LAME; track_indices = g_hash_table_new_full(g_int_hash, g_int_equal, - NULL, free_audio_index_list); + free_audio_hash_key_value, free_audio_hash_key_value); // Clear the audio list ghb_clear_audio_list(ud); // Find "best" audio based on audio preferences @@ -156,59 +166,65 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) for (ii = 0; ii < count; ii++) { audio = ghb_array_get_nth(pref_audio, ii); - acodec = ghb_settings_get_value(audio, "AudioEncoder"); - bitrate = ghb_settings_get_value(audio, "AudioBitrate"); - rate = ghb_settings_get_value(audio, "AudioSamplerate"); - mix = ghb_settings_get_value(audio, "AudioMixdown"); + acodec = ghb_settings_combo_int(audio, "AudioEncoder"); + bitrate = ghb_settings_combo_int(audio, "AudioBitrate"); + rate = ghb_settings_combo_double(audio, "AudioSamplerate"); + mix = ghb_settings_combo_int(audio, "AudioMixdown"); drc = ghb_settings_get_value(audio, "AudioTrackDRCSlider"); - acodec_code = ghb_lookup_combo_int("AudioEncoder", acodec); + //acodec_code = ghb_lookup_combo_int("AudioEncoder", acodec); // If there are multiple audios using the same codec, then // select sequential tracks for each. The hash keeps track // of the tracks used for each codec. track = ghb_find_audio_track(titleindex, source_lang, - acodec_code, track_indices); + acodec, fallback_acodec, track_indices); // Check to see if: - // 1. pref codec is ac3 - // 2. source codec is not ac3 + // 1. pref codec is passthru + // 2. source codec is not passthru // 3. next pref is enabled if (ghb_get_audio_info (&ainfo, titleindex, track) && - ghb_audio_is_passthru (acodec_code)) + ghb_audio_is_passthru (acodec)) { - // HB_ACODEC_* are bit fields. Treat acodec_code as mask - if (!(ainfo.codec & acodec_code)) + // HB_ACODEC_* are bit fields. Treat acodec as mask + if (!(ainfo.codec & acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA))) { - acodec_code = ghb_get_default_acodec(); + acodec = fallback_acodec; // If there's more audio to process, or we've already // placed one in the list, then we can skip this one if ((ii + 1 < count) || (list_count != 0)) { // Skip this audio - acodec_code = 0; + acodec = 0; + } + else + { + bitrate = ainfo.bitrate / 1000; + if (bitrate < 8) + bitrate = 160; + rate = 0; + mix = HB_AMIXDOWN_DOLBYPLII; } } else { - acodec_code &= ainfo.codec; + acodec &= ainfo.codec; } } if (titleindex >= 0 && track < 0) - acodec_code = 0; - if (acodec_code != 0) + acodec = 0; + if (acodec != 0) { // Add to audio list g_signal_emit_by_name(button, "clicked", ud); list_count++; ghb_ui_update(ud, "AudioTrack", ghb_int64_value(track)); - ghb_ui_update(ud, "AudioEncoder", acodec); - if (!ghb_audio_is_passthru (acodec_code)) + ghb_ui_update(ud, "AudioEncoder", ghb_int64_value(acodec)); + if (!ghb_audio_is_passthru (acodec)) { // This gets set autimatically if the codec is passthru - ghb_ui_update(ud, "AudioBitrate", bitrate); - ghb_ui_update(ud, "AudioSamplerate", rate); - mix_code = ghb_lookup_combo_int("AudioMixdown", mix); - mix_code = ghb_get_best_mix( - titleindex, track, acodec_code, mix_code); - ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix_code)); + ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate)); + ghb_ui_update(ud, "AudioSamplerate", ghb_double_value(rate)); + mix = ghb_get_best_mix( titleindex, track, acodec, mix); + ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix)); } ghb_adjust_audio_rate_combos(ud); ghb_ui_update(ud, "AudioTrackDRCSlider", drc); diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index 68601ff5c..14db5b085 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -1044,8 +1044,8 @@ lookup_audio_lang_option(const GValue *rate) return result; } -static GValue* -get_acodec_value(gint val) +GValue* +ghb_lookup_acodec_value(gint val) { GValue *value = NULL; gint ii; @@ -2034,37 +2034,51 @@ ghb_get_source_audio_lang(gint titleindex, gint track) return lang; } +static gboolean* +get_track_used(gint acodec, GHashTable *track_indices, gint count) +{ + gboolean *used; + + used = g_hash_table_lookup(track_indices, &acodec); + if (used == NULL) + { + gint *key; + + used = g_malloc0(count * sizeof(gboolean)); + key = g_malloc(sizeof(gint)); + *key = acodec; + g_hash_table_insert(track_indices, key, used); + } + return used; +} + gint ghb_find_audio_track( gint titleindex, const gchar *lang, gint acodec, + gint fallback_acodec, GHashTable *track_indices) { hb_list_t * list; hb_title_t * title; - hb_audio_config_t * audio; + hb_audio_config_t * audio; gint ii; gint count = 0; gint track = -1; gint max_chan = 0; gboolean *used; + gint try_acodec; g_debug("find_audio_track ()\n"); if (h_scan == NULL) return -1; list = hb_get_titles( h_scan ); - title = (hb_title_t*)hb_list_item( list, titleindex ); + title = (hb_title_t*)hb_list_item( list, titleindex ); if (title != NULL) { count = hb_list_count( title->list_audio ); } if (count > 10) count = 10; - used = g_hash_table_lookup(track_indices, &acodec); - if (used == NULL) - { - used = g_malloc0(count * sizeof(gboolean)); - g_hash_table_insert(track_indices, &acodec, used); - } // Try to find an item that matches the preferred language and // the passthru codec type if (acodec & (HB_ACODEC_AC3 | HB_ACODEC_DCA)) @@ -2073,17 +2087,22 @@ ghb_find_audio_track( { gint channels; + audio = (hb_audio_config_t*)hb_list_audio_config_item( + title->list_audio, ii ); + try_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec; + // Is the source track use a passthru capable codec? + if (try_acodec == 0) + continue; + used = get_track_used(try_acodec, track_indices, count); + // Has the track already been used with this codec? if (used[ii]) continue; - audio = (hb_audio_config_t*)hb_list_audio_config_item( - title->list_audio, ii ); channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( audio->in.channel_layout); // Find a track that is not visually impaired or dirctor's // commentary, and has the highest channel count. - if ((audio->in.codec & acodec) && - (audio->lang.type < 2) && + if ((audio->lang.type < 2) && ((strcmp(lang, audio->lang.iso639_2) == 0) || (strcmp(lang, "und") == 0))) { @@ -2094,6 +2113,11 @@ ghb_find_audio_track( } } } + try_acodec = fallback_acodec; + } + else + { + try_acodec = acodec; } if (track > -1) { @@ -2101,11 +2125,13 @@ ghb_find_audio_track( return track; } // Try to find an item that matches the preferred language + used = get_track_used(try_acodec, track_indices, count); for (ii = 0; ii < count; ii++) { + // Has the track already been used with this codec? if (used[ii]) continue; - audio = (hb_audio_config_t*)hb_list_audio_config_item( + audio = (hb_audio_config_t*)hb_list_audio_config_item( title->list_audio, ii ); // Find a track that is not visually impaired or dirctor's commentary if ((audio->lang.type < 2) && @@ -2129,17 +2155,22 @@ ghb_find_audio_track( { gint channels; + audio = (hb_audio_config_t*)hb_list_audio_config_item( + title->list_audio, ii ); + try_acodec = (HB_ACODEC_AC3 | HB_ACODEC_DCA) & audio->in.codec; + // Is the source track use a passthru capable codec? + if (try_acodec == 0) + continue; + used = get_track_used(try_acodec, track_indices, count); + // Has the track already been used with this codec? if (used[ii]) continue; - audio = (hb_audio_config_t*)hb_list_audio_config_item( - title->list_audio, ii ); channels = HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( audio->in.channel_layout); // Find a track that is not visually impaired or dirctor's // commentary, and has the highest channel count. - if ((audio->in.codec & acodec) && - (audio->lang.type < 2)) + if (audio->lang.type < 2) { if (channels > max_chan) { @@ -2148,6 +2179,11 @@ ghb_find_audio_track( } } } + try_acodec = fallback_acodec; + } + else + { + try_acodec = acodec; } if (track > -1) { @@ -2155,11 +2191,13 @@ ghb_find_audio_track( return track; } // Try to fine an item that does not match the preferred language + used = get_track_used(try_acodec, track_indices, count); for (ii = 0; ii < count; ii++) { + // Has the track already been used with this codec? if (used[ii]) continue; - audio = (hb_audio_config_t*)hb_list_audio_config_item( + audio = (hb_audio_config_t*)hb_list_audio_config_item( title->list_audio, ii ); // Find a track that is not visually impaired or dirctor's commentary if (audio->lang.type < 2) @@ -2176,8 +2214,9 @@ ghb_find_audio_track( // Last ditch, anything goes for (ii = 0; ii < count; ii++) { - audio = (hb_audio_config_t*)hb_list_audio_config_item( + audio = (hb_audio_config_t*)hb_list_audio_config_item( title->list_audio, ii ); + // Has the track already been used with this codec? if (!used[ii]) { track = ii; @@ -3892,7 +3931,7 @@ ghb_validate_audio(signal_user_data_t *ud) { codec = HB_ACODEC_FAAC; } - value = get_acodec_value(codec); + value = ghb_lookup_acodec_value(codec); ghb_settings_take_value(asettings, "AudioEncoder", value); } gchar *a_unsup = NULL; @@ -3929,7 +3968,7 @@ ghb_validate_audio(signal_user_data_t *ud) return FALSE; } g_free(message); - value = get_acodec_value(codec); + value = ghb_lookup_acodec_value(codec); ghb_settings_take_value(asettings, "AudioEncoder", value); } gint mix = ghb_settings_combo_int (asettings, "AudioMixdown"); diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index d279b6468..ac5ea70c5 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -140,7 +140,8 @@ void ghb_update_ui_combo_box( signal_user_data_t *ud, const gchar *name, gint user_data, gboolean all); gchar* ghb_get_source_audio_lang(gint titleindex, gint track); gint ghb_find_audio_track( - gint titleindex, const gchar *lang, gint acodec, GHashTable *track_indices); + gint titleindex, const gchar *lang, gint acodec, + gint fallback_acodec, GHashTable *track_indices); void ghb_add_all_subtitles(signal_user_data_t *ud, gint titleindex); gint ghb_find_pref_subtitle_track(const gchar *lang); gint ghb_find_subtitle_track( @@ -175,5 +176,6 @@ gchar* ghb_get_tmp_dir(); gint ghb_select_audio_codec(signal_user_data_t *ud, gint track); const gchar* ghb_select_audio_codec_str(signal_user_data_t *ud, gint track); gint ghb_find_closest_audio_bitrate(gint codec, gint rate); +GValue* ghb_lookup_acodec_value(gint val); #endif // _HBBACKEND_H_ diff --git a/gtk/src/subtitlehandler.c b/gtk/src/subtitlehandler.c index 537440806..b74eb27ea 100644 --- a/gtk/src/subtitlehandler.c +++ b/gtk/src/subtitlehandler.c @@ -613,7 +613,6 @@ subtitle_default_toggled_cb( GValue *subtitle_list; gint count; GValue *settings; - gboolean burned; g_debug("default toggled"); tp = gtk_tree_path_new_from_string (path); |