summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2009-01-25 19:06:13 +0000
committerjstebbins <[email protected]>2009-01-25 19:06:13 +0000
commitc3cbf601deb9a119809d1c63b0e067346ad4970a (patch)
tree99cf16d9da75297b6f8a96f6b0039ab86fe4fa31
parent8586f9e6099b730fc89ff1202cb524e9595ca052 (diff)
LinGui: tweak how audio choices are made again
prefer audio tracks with more channels prefer audio tracks that are not for visually impaired or director's commentary git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@2096 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--gtk/src/audiohandler.c29
-rw-r--r--gtk/src/hb-backend.c126
-rw-r--r--gtk/src/hb-backend.h3
3 files changed, 124 insertions, 34 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c
index 7967870de..1bfdcf2c5 100644
--- a/gtk/src/audiohandler.c
+++ b/gtk/src/audiohandler.c
@@ -83,22 +83,27 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud)
}
void
+free_audio_index_list(gpointer data)
+{
+ g_free(data);
+}
+
+void
ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud)
{
gint acodec_code, mix_code, track;
gchar *source_lang;
GtkWidget *button;
ghb_audio_info_t ainfo;
- gint index;
- GHashTable *track_indicies;
- gint *iptr;
+ GHashTable *track_indices;
const GValue *pref_audio;
const GValue *audio, *acodec, *bitrate, *rate, *mix, *drc;
gint count, ii, list_count;
g_debug("set_pref_audio");
- track_indicies = g_hash_table_new(g_int_hash, g_int_equal);
+ track_indices = g_hash_table_new_full(g_int_hash, g_int_equal,
+ NULL, free_audio_index_list);
// Clear the audio list
ghb_clear_audio_list(ud);
// Find "best" audio based on audio preferences
@@ -119,16 +124,10 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud)
drc = ghb_settings_get_value(audio, "AudioTrackDRCSlider");
acodec_code = ghb_lookup_combo_int("AudioEncoder", acodec);
// If there are multiple audios using the same codec, then
- // select sequential tracks for each. This hash keeps track
- // of the last used track for each codec.
- iptr = g_hash_table_lookup(track_indicies, &acodec_code);
- if (iptr == NULL)
- index = 0;
- else
- index = *(gint*)iptr;
-
+ // 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, index);
+ acodec_code, track_indices);
// Check to see if:
// 1. pref codec is ac3
// 2. source codec is not ac3
@@ -168,12 +167,10 @@ ghb_set_pref_audio(gint titleindex, signal_user_data_t *ud)
ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix_code));
}
ghb_ui_update(ud, "AudioTrackDRCSlider", drc);
- index++;
- g_hash_table_insert(track_indicies, &acodec_code, &index);
}
}
g_free(source_lang);
- g_hash_table_destroy(track_indicies);
+ g_hash_table_destroy(track_indices);
}
static GValue*
diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c
index 501fe7781..ebea3e73f 100644
--- a/gtk/src/hb-backend.c
+++ b/gtk/src/hb-backend.c
@@ -1609,7 +1609,7 @@ ghb_find_audio_track(
gint titleindex,
const gchar *lang,
gint acodec,
- gint index)
+ GHashTable *track_indices)
{
hb_list_t * list;
hb_title_t * title;
@@ -1617,7 +1617,8 @@ ghb_find_audio_track(
gint ii;
gint count = 0;
gint track = -1;
- gint match = 0;
+ gint max_chan = 0;
+ gboolean *used;
g_debug("find_audio_track ()\n");
if (h_scan == NULL) return -1;
@@ -1628,44 +1629,135 @@ ghb_find_audio_track(
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 fine an item that matches the preferred language and
+ // the passthru codec type
if (acodec == HB_ACODEC_AC3 || acodec == HB_ACODEC_DCA)
{
for (ii = 0; ii < count; ii++)
{
+ gint channels;
+
+ 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) &&
((strcmp(lang, audio->lang.iso639_2) == 0) ||
(strcmp(lang, "und") == 0)))
{
- if (index == match)
+ if (channels > max_chan)
{
track = ii;
- break;
+ max_chan = channels;
}
- match++;
}
}
}
- if (track > -1) return track;
- match = 0;
+ if (track > -1)
+ {
+ used[track] = TRUE;
+ return track;
+ }
+ // Try to fine an item that matches the preferred language
for (ii = 0; ii < count; ii++)
{
- audio = (hb_audio_config_t*)hb_list_audio_config_item( title->list_audio, ii );
- if ((strcmp(lang, audio->lang.iso639_2) == 0) ||
- (strcmp(lang, "und") == 0))
+ if (used[ii])
+ continue;
+ 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) &&
+ ((strcmp(lang, audio->lang.iso639_2) == 0) ||
+ (strcmp(lang, "und") == 0)))
{
- if (index == match)
+ track = ii;
+ break;
+ }
+ }
+ if (track > -1)
+ {
+ used[track] = TRUE;
+ return track;
+ }
+ // Try to fine an item that does not match the preferred language and
+ // matches the passthru codec type
+ if (acodec == HB_ACODEC_AC3 || acodec == HB_ACODEC_DCA)
+ {
+ for (ii = 0; ii < count; ii++)
+ {
+ gint channels;
+
+ 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))
{
- track = ii;
- break;
+ if (channels > max_chan)
+ {
+ track = ii;
+ max_chan = channels;
+ }
}
- match++;
}
}
- if (track > -1) return track;
- if (index < count)
- track = index;
+ if (track > -1)
+ {
+ used[track] = TRUE;
+ return track;
+ }
+ // Try to fine an item that does not match the preferred language
+ for (ii = 0; ii < count; ii++)
+ {
+ if (used[ii])
+ continue;
+ 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)
+ {
+ track = ii;
+ break;
+ }
+ }
+ if (track > -1)
+ {
+ used[track] = TRUE;
+ return track;
+ }
+ // Last ditch, anything goes
+ for (ii = 0; ii < count; ii++)
+ {
+ audio = (hb_audio_config_t*)hb_list_audio_config_item(
+ title->list_audio, ii );
+ if (!used[ii])
+ {
+ track = ii;
+ break;
+ }
+ }
+ if (track > -1)
+ {
+ used[track] = TRUE;
+ }
return track;
}
diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h
index 508ea5ce1..69fd0efd4 100644
--- a/gtk/src/hb-backend.h
+++ b/gtk/src/hb-backend.h
@@ -131,7 +131,8 @@ void ghb_grey_combo_options(GtkBuilder *builder);
void ghb_update_ui_combo_box(
GtkBuilder *builder, const gchar *name, gint user_data, gboolean all);
gint ghb_find_audio_track(
- gint titleindex, const gchar *lang, gint acodec, gint index);
+ gint titleindex, const gchar *lang,
+ gint acodec, GHashTable *track_indices);
gint ghb_longest_title(void);
gchar* ghb_build_x264opts_string(GValue *settings);
GdkPixbuf* ghb_get_preview_image(