]> granicus.if.org Git - handbrake/commitdiff
LinGui: fix a display problem in the audio list
authorjstebbins <jstebbins.hb@gmail.com>
Tue, 5 Oct 2010 22:30:37 +0000 (22:30 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Tue, 5 Oct 2010 22:30:37 +0000 (22:30 +0000)
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
gtk/src/hb-backend.c
gtk/src/hb-backend.h
gtk/src/queuehandler.c

index 6e0748f130b50ed0cacad26212526ff8f076c9dd..e4bc6b86d7d9fd6a83c58da6159180a18d2ee1b8 100644 (file)
@@ -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;
                                }
                        }
index 8614b0a99747a92af12f4a4d77905168b24f3727..f245cda0646c0afbe90dfb4f3b414e33e43b11ca 100644 (file)
@@ -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;
 }
 
index cd6198c25349824e7bbe665cce35d9fe357bee06..48d71528ed7b7c7d88ce278f6cb03af1938f7e31 100644 (file)
@@ -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_
index 6d3261638d7c4fc26ad31b5cdfd10fabfbe37efe..2232a219de536c84958bd5bd85ba468114ed1c44 100644 (file)
@@ -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,