githubのコードからのfolk
Revision | 0acc920cdafa286ec11f84a68eb017858846e1de (tree) |
---|---|
Time | 2010-10-06 07:30:37 |
Author | jstebbins <jstebbins@b64f...> |
Commiter | jstebbins |
LinGui: fix a display problem in the audio list
And tweak default bitrate choices. likely to change :P
git-svn-id: svn://localhost/HandBrake/trunk@3573 b64f7644-9d1e-0410-96f1-a4d463321fa5
@@ -30,6 +30,7 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) | ||
30 | 30 | GtkWidget *widget; |
31 | 31 | GValue *gval; |
32 | 32 | int mux; |
33 | + gint bitrate; | |
33 | 34 | |
34 | 35 | g_debug("ghb_adjust_audio_rate_combos ()"); |
35 | 36 | mux = ghb_settings_combo_int(ud->settings, "FileFormat"); |
@@ -49,6 +50,8 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) | ||
49 | 50 | mix = ghb_lookup_combo_int("AudioMixdown", gval); |
50 | 51 | ghb_value_free(gval); |
51 | 52 | |
53 | + bitrate = ghb_settings_combo_int(ud->settings, "AudioBitrate"); | |
54 | + | |
52 | 55 | select_acodec = acodec; |
53 | 56 | if (mux == HB_MUX_MP4) |
54 | 57 | { |
@@ -66,12 +69,12 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) | ||
66 | 69 | ghb_set_default_bitrate_opts (ud->builder, 0, -1); |
67 | 70 | if (ghb_get_audio_info (&ainfo, titleindex, track)) |
68 | 71 | { |
69 | - gint br = ainfo.bitrate / 1000; | |
72 | + bitrate = ainfo.bitrate / 1000; | |
70 | 73 | |
71 | 74 | // Set the values for bitrate and samplerate to the input rates |
72 | 75 | if (ainfo.codec & select_acodec & HB_ACODEC_PASS_MASK) |
73 | 76 | { |
74 | - ghb_set_passthru_bitrate_opts (ud->builder, br); | |
77 | + ghb_set_passthru_bitrate_opts (ud->builder, bitrate); | |
75 | 78 | ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(0)); |
76 | 79 | select_acodec &= ainfo.codec | HB_ACODEC_PASS_FLAG; |
77 | 80 | } |
@@ -83,17 +86,13 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) | ||
83 | 86 | ghb_ui_update(ud, "AudioEncoder", ghb_int64_value(select_acodec)); |
84 | 87 | } |
85 | 88 | |
86 | - int channels, min_rate; | |
89 | + int channels; | |
87 | 90 | mix = ghb_get_best_mix( titleindex, track, select_acodec, mix); |
88 | 91 | channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mix); |
89 | - br = ainfo.bitrate / 1000; | |
90 | - min_rate = channels * 32; | |
91 | - if (br < min_rate) | |
92 | - br = min_rate; | |
93 | - br = ghb_find_closest_audio_bitrate(select_acodec, br); | |
92 | + bitrate = ghb_get_default_audio_bitrate(select_acodec, ainfo.samplerate, bitrate, channels); | |
94 | 93 | ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix)); |
95 | 94 | } |
96 | - ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(br)); | |
95 | + ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate)); | |
97 | 96 | ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0)); |
98 | 97 | } |
99 | 98 | else |
@@ -105,6 +104,9 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) | ||
105 | 104 | } |
106 | 105 | ghb_ui_update(ud, "AudioTrackDRCSlider", ghb_double_value(0)); |
107 | 106 | } |
107 | + gint channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mix); | |
108 | + bitrate = ghb_get_best_audio_bitrate(select_acodec, bitrate, channels); | |
109 | + ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate)); | |
108 | 110 | if (select_acodec == HB_ACODEC_FAAC) |
109 | 111 | { |
110 | 112 | gint br, last = 320, first = 0; |
@@ -114,15 +116,6 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) | ||
114 | 116 | first = 192; |
115 | 117 | last = 768; |
116 | 118 | } |
117 | - | |
118 | - widget = GHB_WIDGET(ud->builder, "AudioBitrate"); | |
119 | - gval = ghb_widget_value(widget); | |
120 | - br = ghb_lookup_combo_int("AudioBitrate", gval); | |
121 | - ghb_value_free(gval); | |
122 | - if (br > last) | |
123 | - ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(last)); | |
124 | - if (br < first) | |
125 | - ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(first)); | |
126 | 119 | ghb_set_default_bitrate_opts (ud->builder, first, last); |
127 | 120 | } |
128 | 121 | else if (select_acodec == HB_ACODEC_AC3) |
@@ -257,15 +250,16 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud) | ||
257 | 250 | } |
258 | 251 | else |
259 | 252 | { |
260 | - int channels, min_rate; | |
253 | + int channels, min_rate, max_rate; | |
261 | 254 | mix = ghb_get_best_mix( titleindex, track, mix_acodec, mix); |
262 | 255 | channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(mix); |
263 | 256 | bitrate = ainfo.bitrate / 1000; |
264 | - min_rate = channels * 32; | |
257 | + min_rate = channels * 64; | |
258 | + max_rate = channels * 160; | |
265 | 259 | if (bitrate < min_rate) |
266 | 260 | bitrate = min_rate; |
267 | - if (bitrate > 640) | |
268 | - bitrate = 640; | |
261 | + if (bitrate > max_rate) | |
262 | + bitrate = max_rate; | |
269 | 263 | rate = 0; |
270 | 264 | } |
271 | 265 | } |
@@ -1096,35 +1096,6 @@ lookup_audio_rate_option(const GValue *rate) | ||
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | gint |
1099 | -ghb_find_closest_audio_bitrate(gint codec, gint rate) | |
1100 | -{ | |
1101 | - gint ii; | |
1102 | - gint low = 32; | |
1103 | - gint high = 768; | |
1104 | - gint result; | |
1105 | - | |
1106 | - if (codec == HB_ACODEC_FAAC) | |
1107 | - high = 320; | |
1108 | - else if (codec == HB_ACODEC_AC3) | |
1109 | - high = 640; | |
1110 | - | |
1111 | - result = high; | |
1112 | - for (ii = 0; ii < hb_audio_bitrates_count; ii++) | |
1113 | - { | |
1114 | - if (hb_audio_bitrates[ii].rate < low) | |
1115 | - continue; | |
1116 | - if (hb_audio_bitrates[ii].rate > high) | |
1117 | - break; | |
1118 | - if (rate <= hb_audio_bitrates[ii].rate) | |
1119 | - { | |
1120 | - result = hb_audio_bitrates[ii].rate; | |
1121 | - break; | |
1122 | - } | |
1123 | - } | |
1124 | - return result; | |
1125 | -} | |
1126 | - | |
1127 | -gint | |
1128 | 1099 | ghb_find_closest_audio_rate(gint rate) |
1129 | 1100 | { |
1130 | 1101 | gint ii; |
@@ -1640,6 +1611,35 @@ ghb_grey_combo_options(GtkBuilder *builder) | ||
1640 | 1611 | } |
1641 | 1612 | |
1642 | 1613 | gint |
1614 | +ghb_find_closest_audio_bitrate(gint codec, gint rate) | |
1615 | +{ | |
1616 | + gint ii; | |
1617 | + gint low = 32; | |
1618 | + gint high = 768; | |
1619 | + gint result; | |
1620 | + | |
1621 | + if (codec == HB_ACODEC_FAAC) | |
1622 | + high = 320; | |
1623 | + else if (codec == HB_ACODEC_AC3) | |
1624 | + high = 640; | |
1625 | + | |
1626 | + result = high; | |
1627 | + for (ii = 0; ii < hb_audio_bitrates_count; ii++) | |
1628 | + { | |
1629 | + if (hb_audio_bitrates[ii].rate < low) | |
1630 | + continue; | |
1631 | + if (hb_audio_bitrates[ii].rate > high) | |
1632 | + break; | |
1633 | + if (rate <= hb_audio_bitrates[ii].rate) | |
1634 | + { | |
1635 | + result = hb_audio_bitrates[ii].rate; | |
1636 | + break; | |
1637 | + } | |
1638 | + } | |
1639 | + return result; | |
1640 | +} | |
1641 | + | |
1642 | +gint | |
1643 | 1643 | ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels) |
1644 | 1644 | { |
1645 | 1645 | if (acodec & HB_ACODEC_FAAC) |
@@ -1653,6 +1653,57 @@ ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels) | ||
1653 | 1653 | if (br > maxbr) |
1654 | 1654 | br = maxbr; |
1655 | 1655 | } |
1656 | + if (acodec & HB_ACODEC_AC3) | |
1657 | + { | |
1658 | + if (br > 640) | |
1659 | + br = 640; | |
1660 | + } | |
1661 | + br = ghb_find_closest_audio_bitrate(acodec, br); | |
1662 | + return br; | |
1663 | +} | |
1664 | + | |
1665 | +gint | |
1666 | +ghb_get_default_audio_bitrate(gint acodec, gint sr, gint br, gint channels) | |
1667 | +{ | |
1668 | + gint min_rate, max_rate; | |
1669 | + gint sr_div = 1; | |
1670 | + | |
1671 | + // Min bitrate is established such that we get good quality | |
1672 | + // audio as a minimum. If the input bitrate is higher than | |
1673 | + // the output codec allows, we will cap the bitrate. | |
1674 | + if (sr <= 24000) | |
1675 | + { | |
1676 | + sr_div = 2; | |
1677 | + } | |
1678 | + if (acodec & HB_ACODEC_AC3) | |
1679 | + { | |
1680 | + switch (channels) | |
1681 | + { | |
1682 | + case 1: | |
1683 | + min_rate = 96; | |
1684 | + break; | |
1685 | + case 2: | |
1686 | + min_rate = 224; | |
1687 | + break; | |
1688 | + case 6: | |
1689 | + default: | |
1690 | + min_rate = 448; | |
1691 | + break; | |
1692 | + } | |
1693 | + max_rate = channels * 160; | |
1694 | + } | |
1695 | + else | |
1696 | + { | |
1697 | + min_rate = channels * 64; | |
1698 | + max_rate = channels * 160; | |
1699 | + } | |
1700 | + max_rate /= sr_div; | |
1701 | + min_rate /= sr_div; | |
1702 | + if ( br < min_rate ) | |
1703 | + br = min_rate; | |
1704 | + if ( br > max_rate ) | |
1705 | + br = max_rate; | |
1706 | + br = ghb_get_best_audio_bitrate(acodec, br, channels); | |
1656 | 1707 | return br; |
1657 | 1708 | } |
1658 | 1709 |
@@ -187,6 +187,8 @@ gint ghb_select_audio_codec(GValue *settings, gint acodec, gint track); | ||
187 | 187 | const gchar* ghb_select_audio_codec_str(GValue *settings, gint acodec, gint track); |
188 | 188 | gint ghb_find_closest_audio_bitrate(gint codec, gint rate); |
189 | 189 | gint ghb_find_closest_audio_rate(gint rate); |
190 | +gint ghb_get_best_audio_bitrate(gint acodec, gint br, gint channels); | |
191 | +gint ghb_get_default_audio_bitrate(gint acodec, gint sr, gint br, gint channels); | |
190 | 192 | GValue* ghb_lookup_acodec_value(gint val); |
191 | 193 | |
192 | 194 | #endif // _HBBACKEND_H_ |
@@ -549,7 +549,7 @@ audio_list_refresh(signal_user_data_t *ud) | ||
549 | 549 | else |
550 | 550 | s_drc = g_strdup_printf("%.1f", drc); |
551 | 551 | |
552 | - if (icodec == HB_ACODEC_MASK) | |
552 | + if (icodec == HB_ACODEC_ANY) | |
553 | 553 | codec = ghb_select_audio_codec_str(ud->settings, icodec, itrack); |
554 | 554 | |
555 | 555 | gtk_list_store_set(GTK_LIST_STORE(store), &iter, |