From 5b37d5479392e6112d72b9156af2865db3d6f575 Mon Sep 17 00:00:00 2001 From: jstebbins Date: Tue, 5 Oct 2010 22:30:37 +0000 Subject: LinGui: fix a display problem in the audio list And tweak default bitrate choices. likely to change :P git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3573 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- gtk/src/audiohandler.c | 38 ++++++++--------- gtk/src/hb-backend.c | 109 ++++++++++++++++++++++++++++++++++++------------- gtk/src/hb-backend.h | 2 + gtk/src/queuehandler.c | 2 +- 4 files changed, 99 insertions(+), 52 deletions(-) (limited to 'gtk') diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c index 6e0748f13..e4bc6b86d 100644 --- a/gtk/src/audiohandler.c +++ b/gtk/src/audiohandler.c @@ -30,6 +30,7 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) GtkWidget *widget; GValue *gval; int mux; + gint bitrate; g_debug("ghb_adjust_audio_rate_combos ()"); mux = ghb_settings_combo_int(ud->settings, "FileFormat"); @@ -49,6 +50,8 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) mix = ghb_lookup_combo_int("AudioMixdown", gval); ghb_value_free(gval); + bitrate = ghb_settings_combo_int(ud->settings, "AudioBitrate"); + select_acodec = acodec; if (mux == HB_MUX_MP4) { @@ -66,12 +69,12 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) ghb_set_default_bitrate_opts (ud->builder, 0, -1); if (ghb_get_audio_info (&ainfo, titleindex, track)) { - gint br = ainfo.bitrate / 1000; + bitrate = ainfo.bitrate / 1000; // Set the values for bitrate and samplerate to the input rates if (ainfo.codec & select_acodec & HB_ACODEC_PASS_MASK) { - ghb_set_passthru_bitrate_opts (ud->builder, br); + ghb_set_passthru_bitrate_opts (ud->builder, bitrate); ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(0)); select_acodec &= ainfo.codec | HB_ACODEC_PASS_FLAG; } @@ -83,17 +86,13 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) ghb_ui_update(ud, "AudioEncoder", ghb_int64_value(select_acodec)); } - int channels, min_rate; + int channels; mix = ghb_get_best_mix( titleindex, track, select_acodec, mix); channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mix); - br = ainfo.bitrate / 1000; - min_rate = channels * 32; - if (br < min_rate) - br = min_rate; - br = ghb_find_closest_audio_bitrate(select_acodec, br); + bitrate = ghb_get_default_audio_bitrate(select_acodec, ainfo.samplerate, bitrate, channels); ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix)); } - ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(br)); + ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate)); ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0)); } else @@ -105,6 +104,9 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) } ghb_ui_update(ud, "AudioTrackDRCSlider", ghb_double_value(0)); } + gint channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mix); + bitrate = ghb_get_best_audio_bitrate(select_acodec, bitrate, channels); + ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate)); if (select_acodec == HB_ACODEC_FAAC) { gint br, last = 320, first = 0; @@ -114,15 +116,6 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) first = 192; last = 768; } - - widget = GHB_WIDGET(ud->builder, "AudioBitrate"); - gval = ghb_widget_value(widget); - br = ghb_lookup_combo_int("AudioBitrate", gval); - ghb_value_free(gval); - if (br > last) - ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(last)); - if (br < first) - ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(first)); ghb_set_default_bitrate_opts (ud->builder, first, last); } else if (select_acodec == HB_ACODEC_AC3) @@ -257,15 +250,16 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) } else { - int channels, min_rate; + int channels, min_rate, max_rate; mix = ghb_get_best_mix( titleindex, track, mix_acodec, mix); channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mix); bitrate = ainfo.bitrate / 1000; - min_rate = channels * 32; + min_rate = channels * 64; + max_rate = channels * 160; if (bitrate < min_rate) bitrate = min_rate; - if (bitrate > 640) - bitrate = 640; + if (bitrate > max_rate) + bitrate = max_rate; rate = 0; } } diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index 8614b0a99..f245cda06 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -1095,35 +1095,6 @@ lookup_audio_rate_option(const GValue *rate) return result; } -gint -ghb_find_closest_audio_bitrate(gint codec, gint rate) -{ - gint ii; - gint low = 32; - gint high = 768; - gint result; - - if (codec == HB_ACODEC_FAAC) - high = 320; - else if (codec == HB_ACODEC_AC3) - high = 640; - - result = high; - for (ii = 0; ii < hb_audio_bitrates_count; ii++) - { - if (hb_audio_bitrates[ii].rate < low) - continue; - if (hb_audio_bitrates[ii].rate > high) - break; - if (rate <= hb_audio_bitrates[ii].rate) - { - result = hb_audio_bitrates[ii].rate; - break; - } - } - return result; -} - gint ghb_find_closest_audio_rate(gint rate) { @@ -1639,6 +1610,35 @@ ghb_grey_combo_options(GtkBuilder *builder) grey_combo_box_item(builder, "AudioMixdown", HB_AMIXDOWN_6CH, !allow_6ch); } +gint +ghb_find_closest_audio_bitrate(gint codec, gint rate) +{ + gint ii; + gint low = 32; + gint high = 768; + gint result; + + if (codec == HB_ACODEC_FAAC) + high = 320; + else if (codec == HB_ACODEC_AC3) + high = 640; + + result = high; + for (ii = 0; ii < hb_audio_bitrates_count; ii++) + { + if (hb_audio_bitrates[ii].rate < low) + continue; + if (hb_audio_bitrates[ii].rate > high) + break; + if (rate <= hb_audio_bitrates[ii].rate) + { + result = hb_audio_bitrates[ii].rate; + break; + } + } + return result; +} + gint ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels) { @@ -1653,6 +1653,57 @@ ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels) if (br > maxbr) br = maxbr; } + if (acodec & HB_ACODEC_AC3) + { + if (br > 640) + br = 640; + } + br = ghb_find_closest_audio_bitrate(acodec, br); + return br; +} + +gint +ghb_get_default_audio_bitrate(gint acodec, gint sr, gint br, gint channels) +{ + gint min_rate, max_rate; + gint sr_div = 1; + + // Min bitrate is established such that we get good quality + // audio as a minimum. If the input bitrate is higher than + // the output codec allows, we will cap the bitrate. + if (sr <= 24000) + { + sr_div = 2; + } + if (acodec & HB_ACODEC_AC3) + { + switch (channels) + { + case 1: + min_rate = 96; + break; + case 2: + min_rate = 224; + break; + case 6: + default: + min_rate = 448; + break; + } + max_rate = channels * 160; + } + else + { + min_rate = channels * 64; + max_rate = channels * 160; + } + max_rate /= sr_div; + min_rate /= sr_div; + if ( br < min_rate ) + br = min_rate; + if ( br > max_rate ) + br = max_rate; + br = ghb_get_best_audio_bitrate(acodec, br, channels); return br; } diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index cd6198c25..48d71528e 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -187,6 +187,8 @@ gint ghb_select_audio_codec(GValue *settings, gint acodec, gint track); const gchar* ghb_select_audio_codec_str(GValue *settings, gint acodec, gint track); gint ghb_find_closest_audio_bitrate(gint codec, gint rate); gint ghb_find_closest_audio_rate(gint rate); +gint ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels); +gint ghb_get_default_audio_bitrate(gint acodec, gint sr, gint br, gint channels); GValue* ghb_lookup_acodec_value(gint val); #endif // _HBBACKEND_H_ diff --git a/gtk/src/queuehandler.c b/gtk/src/queuehandler.c index 6d3261638..2232a219d 100644 --- a/gtk/src/queuehandler.c +++ b/gtk/src/queuehandler.c @@ -549,7 +549,7 @@ audio_list_refresh(signal_user_data_t *ud) else s_drc = g_strdup_printf("%.1f", drc); - if (icodec == HB_ACODEC_MASK) + if (icodec == HB_ACODEC_ANY) codec = ghb_select_audio_codec_str(ud->settings, icodec, itrack); gtk_list_store_set(GTK_LIST_STORE(store), &iter, -- cgit v1.2.3