summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2017-06-12 07:44:14 -0700
committerGitHub <[email protected]>2017-06-12 07:44:14 -0700
commit74b10b23b0dd902ba718e8848662c9ac4241412c (patch)
tree0c426a0decb5ecbf2d26ec6b0e2d00b4f8526ef8
parent833d0a9658447647e96347621eb1ce42e9b4161e (diff)
Allow audio fallback to be "None" (#623)
* Allow audio fallback to be "None" When audio fallback is "None", a failure to do passthru will result in no output audio track being added. * simplify audio autopassthru fallback logic Drop track when fallback codec is invalid instead of falling back to a default. Since all presets have a fallback set, the default fallback condition would only ever be triggered by an invalid setting.
-rw-r--r--gtk/src/hb-backend.c57
-rw-r--r--libhb/common.c47
-rw-r--r--libhb/common.h3
-rw-r--r--libhb/preset.c13
4 files changed, 64 insertions, 56 deletions
diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c
index ec819895c..79e7c607d 100644
--- a/gtk/src/hb-backend.c
+++ b/gtk/src/hb-backend.c
@@ -1250,7 +1250,7 @@ ghb_grey_combo_options(signal_user_data_t *ud)
for (enc = hb_audio_encoder_get_next(NULL); enc != NULL;
enc = hb_audio_encoder_get_next(enc))
{
- if (!(mux->format & enc->muxers))
+ if (!(mux->format & enc->muxers) && enc->codec != HB_ACODEC_NONE)
{
grey_builder_combo_box_item(ud->builder, "AudioEncoder",
enc->codec, TRUE);
@@ -1674,7 +1674,8 @@ ghb_audio_encoder_opts_set_with_mask(
for (enc = hb_audio_encoder_get_next(NULL); enc != NULL;
enc = hb_audio_encoder_get_next(enc))
{
- if ((mask & enc->codec) && !(neg_mask & enc->codec))
+ if ((mask & enc->codec) && !(neg_mask & enc->codec) &&
+ enc->codec != HB_ACODEC_AUTO_PASS)
{
gtk_list_store_append(store, &iter);
str = g_strdup_printf("<small>%s</small>", enc->name);
@@ -1689,6 +1690,30 @@ ghb_audio_encoder_opts_set_with_mask(
}
}
+void
+ghb_audio_encoder_opts_add_autopass(GtkComboBox *combo)
+{
+ GtkTreeIter iter;
+ GtkListStore *store;
+ gchar *str;
+ const hb_encoder_t *enc;
+
+ enc = hb_audio_encoder_get_from_codec(HB_ACODEC_AUTO_PASS);
+ if (enc != NULL)
+ {
+ store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
+ gtk_list_store_append(store, &iter);
+ str = g_strdup_printf("<small>%s</small>", enc->name);
+ gtk_list_store_set(store, &iter,
+ 0, str,
+ 1, TRUE,
+ 2, enc->short_name,
+ 3, (gdouble)enc->codec,
+ -1);
+ g_free(str);
+ }
+}
+
const hb_encoder_t*
ghb_lookup_audio_encoder(const char *name)
{
@@ -1743,7 +1768,8 @@ audio_encoder_opts_set_with_mask(
void
ghb_audio_encoder_opts_set(GtkComboBox *combo)
{
- ghb_audio_encoder_opts_set_with_mask(combo, ~0, 0);
+ ghb_audio_encoder_opts_set_with_mask(combo, ~0, HB_ACODEC_NONE);
+ ghb_audio_encoder_opts_add_autopass(combo);
}
static void
@@ -1752,31 +1778,8 @@ audio_encoder_opts_set(signal_user_data_t *ud, const gchar *name,
{
(void)opts; // Silence "unused variable" warning
(void)data; // Silence "unused variable" warning
- GtkTreeIter iter;
- GtkListStore *store;
- gchar *str;
-
GtkComboBox *combo = GTK_COMBO_BOX(GHB_WIDGET(ud->builder, name));
- store = GTK_LIST_STORE(gtk_combo_box_get_model (combo));
- gtk_list_store_clear(store);
-
- const hb_encoder_t *enc;
- for (enc = hb_audio_encoder_get_next(NULL); enc != NULL;
- enc = hb_audio_encoder_get_next(enc))
- {
- if (enc->codec != HB_ACODEC_AUTO_PASS)
- {
- gtk_list_store_append(store, &iter);
- str = g_strdup_printf("<small>%s</small>", enc->name);
- gtk_list_store_set(store, &iter,
- 0, str,
- 1, TRUE,
- 2, enc->short_name,
- 3, (gdouble)enc->codec,
- -1);
- g_free(str);
- }
- }
+ ghb_audio_encoder_opts_set_with_mask(combo, ~0, HB_ACODEC_NONE);
}
static void
diff --git a/libhb/common.c b/libhb/common.c
index ebe51c6e5..08bf0f08d 100644
--- a/libhb/common.c
+++ b/libhb/common.c
@@ -309,6 +309,7 @@ hb_encoder_internal_t hb_audio_encoders[] =
{ { "AAC", "aac", NULL, 0, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, HB_GID_ACODEC_AAC, },
{ { "HE-AAC", "haac", NULL, 0, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 0, HB_GID_ACODEC_AAC_HE, },
// actual encoders
+ { { "None", "none", "None", HB_ACODEC_NONE, 0, }, NULL, 1, HB_GID_NONE, },
{ { "AAC (CoreAudio)", "ca_aac", "AAC (Apple AudioToolbox)", HB_ACODEC_CA_AAC, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_ACODEC_AAC, },
{ { "HE-AAC (CoreAudio)", "ca_haac", "HE-AAC (Apple AudioToolbox)", HB_ACODEC_CA_HAAC, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_ACODEC_AAC_HE, },
{ { "AAC (FDK)", "fdk_aac", "AAC (libfdk_aac)", HB_ACODEC_FDK_AAC, HB_MUX_MASK_MP4|HB_MUX_MASK_MKV, }, NULL, 1, HB_GID_ACODEC_AAC, },
@@ -372,6 +373,7 @@ static int hb_audio_encoder_is_enabled(int encoder)
// the following encoders are always enabled
case HB_ACODEC_LAME:
case HB_ACODEC_VORBIS:
+ case HB_ACODEC_NONE:
return 1;
default:
@@ -2186,7 +2188,7 @@ int hb_audio_encoder_get_fallback_for_passthru(int passthru)
break;
default:
- gid = HB_GID_NONE; // will never match an enabled encoder
+ return HB_ACODEC_INVALID;
break;
}
while ((audio_encoder = hb_audio_encoder_get_next(audio_encoder)) != NULL)
@@ -2355,8 +2357,8 @@ void hb_autopassthru_apply_settings(hb_job_t *job)
job->acodec_copy_mask,
job->acodec_fallback,
job->mux);
- if (!(audio->config.out.codec & HB_ACODEC_PASS_FLAG) &&
- !(audio->config.out.codec & HB_ACODEC_MASK))
+ if (audio->config.out.codec == HB_ACODEC_NONE ||
+ audio->config.out.codec == HB_ACODEC_INVALID)
{
hb_log("Auto Passthru: passthru not possible and no valid fallback specified, dropping track %d",
audio->config.out.track );
@@ -2366,16 +2368,8 @@ void hb_autopassthru_apply_settings(hb_job_t *job)
}
if (!(audio->config.out.codec & HB_ACODEC_PASS_FLAG))
{
- if (audio->config.out.codec == job->acodec_fallback)
- {
- hb_log("Auto Passthru: passthru not possible for track %d, using fallback",
- audio->config.out.track);
- }
- else
- {
- hb_log("Auto Passthru: passthru and fallback not possible for track %d, using default encoder",
- audio->config.out.track);
- }
+ hb_log("Auto Passthru: passthru not possible for track %d, using fallback",
+ audio->config.out.track);
if (audio->config.out.mixdown <= 0)
{
audio->config.out.mixdown =
@@ -2506,31 +2500,36 @@ void hb_autopassthru_print_settings(hb_job_t *job)
int hb_autopassthru_get_encoder(int in_codec, int copy_mask, int fallback,
int muxer)
{
- int i = 0;
+ int out_codec_result_set = 0;
+ int fallback_result_set = 0;
+ int out_codec_result = HB_ACODEC_INVALID;
+ int fallback_result = HB_ACODEC_INVALID;
const hb_encoder_t *audio_encoder = NULL;
int out_codec = (copy_mask & in_codec) | HB_ACODEC_PASS_FLAG;
+
// sanitize fallback encoder and selected passthru
// note: invalid fallbacks are caught in hb_autopassthru_apply_settings
while ((audio_encoder = hb_audio_encoder_get_next(audio_encoder)) != NULL)
{
- if (audio_encoder->codec == out_codec)
+ if (!out_codec_result_set && audio_encoder->codec == out_codec)
{
- i++;
- if (!(audio_encoder->muxers & muxer))
- out_codec = 0;
+ out_codec_result_set = 1;
+ if (audio_encoder->muxers & muxer)
+ out_codec_result = out_codec;
}
- else if (audio_encoder->codec == fallback)
+ else if (!fallback_result_set && audio_encoder->codec == fallback)
{
- i++;
- if (!(audio_encoder->muxers & muxer))
- fallback = hb_audio_encoder_get_default(muxer);
+ fallback_result_set = 1;
+ if ((audio_encoder->muxers & muxer) || fallback == HB_ACODEC_NONE)
+ fallback_result = fallback;
}
- if (i > 1)
+ if (out_codec_result_set && fallback_result_set)
{
break;
}
}
- return (out_codec & HB_ACODEC_PASS_MASK) ? out_codec : fallback;
+ return (out_codec_result != HB_ACODEC_INVALID) ? out_codec_result :
+ fallback_result;
}
hb_container_t* hb_container_get_from_format(int format)
diff --git a/libhb/common.h b/libhb/common.h
index 2edbdc697..6aac0bacd 100644
--- a/libhb/common.h
+++ b/libhb/common.h
@@ -681,7 +681,8 @@ struct hb_job_s
/* Audio starts here */
/* Audio Codecs: Update win/CS/HandBrake.Interop/HandBrakeInterop/HbLib/NativeConstants.cs when changing these consts */
#define HB_ACODEC_INVALID 0x00000000
-#define HB_ACODEC_MASK 0x07FFFF00
+#define HB_ACODEC_NONE 0x00000001
+#define HB_ACODEC_MASK 0x07FFFF01
#define HB_ACODEC_LAME 0x00000200
#define HB_ACODEC_VORBIS 0x00000400
#define HB_ACODEC_AC3 0x00000800
diff --git a/libhb/preset.c b/libhb/preset.c
index 37157e651..5ad3dbf76 100644
--- a/libhb/preset.c
+++ b/libhb/preset.c
@@ -492,7 +492,7 @@ static int sanitize_audio_codec(int in_codec, int out_codec,
!(in_codec & out_codec & HB_ACODEC_PASS_MASK))
{
codec = hb_audio_encoder_get_fallback_for_passthru(out_codec);
- if (codec == 0)
+ if (codec == HB_ACODEC_INVALID)
codec = fallback;
}
@@ -500,14 +500,14 @@ static int sanitize_audio_codec(int in_codec, int out_codec,
const hb_encoder_t *encoder = NULL;
while ((encoder = hb_audio_encoder_get_next(encoder)) != NULL)
{
- if (encoder->codec == codec &&
+ if (encoder->codec == codec && codec != HB_ACODEC_NONE &&
!(encoder->muxers & mux))
{
codec = hb_audio_encoder_get_default(mux);
break;
}
}
- if (codec == 0)
+ if (codec == HB_ACODEC_INVALID)
codec = hb_audio_encoder_get_default(mux);
return codec;
}
@@ -630,7 +630,6 @@ static void add_audio_for_lang(hb_value_array_t *list, const hb_dict_t *preset,
hb_dict_t *used = source_audio_track_used(track_dict, ii);
if (hb_value_get_bool(hb_dict_get(used, key)))
continue;
- hb_dict_set(used, key, hb_value_bool(1));
// Create new audio output track settings
hb_dict_t *audio_dict = hb_dict_init();
@@ -657,6 +656,11 @@ static void add_audio_for_lang(hb_value_array_t *list, const hb_dict_t *preset,
aconfig = hb_list_audio_config_item(title->list_audio, track);
out_codec = sanitize_audio_codec(aconfig->in.codec, out_codec,
copy_mask, fallback, mux);
+ if (out_codec == HB_ACODEC_NONE || HB_ACODEC_INVALID)
+ {
+ hb_value_free(&audio_dict);
+ continue;
+ }
hb_dict_set(audio_dict, "Track", hb_value_int(track));
hb_dict_set(audio_dict, "Encoder", hb_value_string(
hb_audio_encoder_get_short_name(out_codec)));
@@ -730,6 +734,7 @@ static void add_audio_for_lang(hb_value_array_t *list, const hb_dict_t *preset,
hb_sanitize_audio_settings(title, audio_dict);
hb_value_array_append(list, audio_dict);
+ hb_dict_set(used, key, hb_value_bool(1));
}
if (behavior == 2)
track = find_audio_track(title, lang, track + 1, behavior);