diff options
author | Rodeo <[email protected]> | 2013-05-30 13:57:37 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2013-05-30 13:57:37 +0000 |
commit | 93117add4ed41f9f87d1da16ca339b2efad6767d (patch) | |
tree | 755030aca2bd309d9a47f6748adc70a7ff4e839f /gtk/src | |
parent | bf0fe59e97a4fc22b0800191407cdeb758ed20fa (diff) |
Don't expose rate, mixdown, dither and encoder arrays to the UIs.
- instead, make these lists available through enumerators:
--> hb_*_get_next(<type> *last);
- this should give us more flexibility to populate the lists at runtime, using the implementation(s) of our choice, whether they use arrays or not, without requiring UI modifications
- use consistent naming for getters
--> hb_get_best_foo() becomes hb_foo_get_best(), and so on
- hb_*_get_from_name() and hb_*_ sanitize_name() sanitize the requested value to a supported one if it's unavailable
- adds an additional, passthru-specific fallback mechanism
- adds a list of video containers
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5526 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src')
-rw-r--r-- | gtk/src/audiohandler.c | 42 | ||||
-rw-r--r-- | gtk/src/hb-backend.c | 1029 | ||||
-rw-r--r-- | gtk/src/hb-backend.h | 4 | ||||
-rw-r--r-- | gtk/src/presets.c | 126 |
4 files changed, 675 insertions, 526 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c index 2a7b619e4..72f58bfa7 100644 --- a/gtk/src/audiohandler.c +++ b/gtk/src/audiohandler.c @@ -63,12 +63,13 @@ ghb_select_audio_codec(gint mux, hb_audio_config_t *aconfig, gint acodec, gint f return hb_autopassthru_get_encoder(in_codec, copy_mask, fallback, mux); } - gint ii; // Sanitize fallback - for (ii = 0; ii < hb_audio_encoders_count; ii++) + const hb_encoder_t *enc; + for (enc = hb_audio_encoder_get_next(NULL); enc != NULL; + enc = hb_audio_encoder_get_next(enc)) { - if (hb_audio_encoders[ii].encoder == fallback && - !(hb_audio_encoders[ii].muxers & mux)) + if (enc->codec == fallback && + !(enc->muxers & mux)) { if ( mux == HB_MUX_MKV ) fallback = HB_ACODEC_LAME; @@ -82,10 +83,11 @@ ghb_select_audio_codec(gint mux, hb_audio_config_t *aconfig, gint acodec, gint f { return fallback; } - for (ii = 0; ii < hb_audio_encoders_count; ii++) + for (enc = hb_audio_encoder_get_next(NULL); enc != NULL; + enc = hb_audio_encoder_get_next(enc)) { - if (hb_audio_encoders[ii].encoder == acodec && - !(hb_audio_encoders[ii].muxers & mux)) + if (enc->codec == acodec && + !(enc->muxers & mux)) { return fallback; } @@ -198,7 +200,7 @@ ghb_sanitize_audio(GValue *settings, GValue *asettings) { if (mix == 0) mix = ghb_get_best_mix( aconfig, select_acodec, 0); - bitrate = hb_get_best_audio_bitrate(select_acodec, bitrate, sr, mix); + bitrate = hb_audio_bitrate_get_best(select_acodec, bitrate, sr, mix); ghb_settings_set_string(asettings, "AudioMixdown", ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); } @@ -206,7 +208,7 @@ ghb_sanitize_audio(GValue *settings, GValue *asettings) ghb_lookup_combo_string("AudioBitrate", ghb_int_value(bitrate))); ghb_settings_take_value(asettings, "AudioEncoderActual", - ghb_lookup_acodec_value(select_acodec)); + ghb_lookup_audio_encoder_value(select_acodec)); } void @@ -283,25 +285,25 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud) { if (mix == 0) mix = ghb_get_best_mix( aconfig, select_acodec, 0); - bitrate = hb_get_best_audio_bitrate(select_acodec, bitrate, sr, mix); + bitrate = hb_audio_bitrate_get_best(select_acodec, bitrate, sr, mix); ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix)); } if (!codec_defined_bitrate) { int low, high; mix = ghb_get_best_mix( aconfig, select_acodec, mix); - hb_get_audio_bitrate_limits(select_acodec, sr, mix, &low, &high); + hb_audio_bitrate_get_limits(select_acodec, sr, mix, &low, &high); ghb_set_bitrate_opts (ud->builder, low, high, -1); } ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate)); ghb_settings_take_value(ud->settings, "AudioEncoderActual", - ghb_lookup_acodec_value(select_acodec)); + ghb_lookup_audio_encoder_value(select_acodec)); GValue *asettings = get_selected_asettings(ud); if (asettings) { ghb_settings_take_value(asettings, "AudioEncoderActual", - ghb_lookup_acodec_value(select_acodec)); + ghb_lookup_audio_encoder_value(select_acodec)); } ghb_audio_list_refresh_selected(ud); ghb_check_dependency(ud, NULL, "AudioEncoderActual"); @@ -423,7 +425,7 @@ ghb_set_pref_audio_settings(gint titleindex, GValue *settings) ghb_settings_set_string(asettings, "AudioEncoder", ghb_lookup_combo_string("AudioEncoder", ghb_int_value(acodec))); ghb_settings_set_value(asettings, "AudioEncoderActual", - ghb_lookup_acodec_value(select_acodec)); + ghb_lookup_audio_encoder_value(select_acodec)); ghb_settings_set_value(asettings, "AudioTrackQualityEnable", enable_qual); ghb_settings_set_double(asettings, "AudioTrackQuality", quality); @@ -687,7 +689,7 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) track = ghb_settings_combo_int(ud->settings, "AudioTrack"); if (sr) { - sr = ghb_find_closest_audio_rate(sr); + sr = ghb_find_closest_audio_samplerate(sr); } ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(sr)); @@ -698,7 +700,7 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) sr = aconfig ? aconfig->in.samplerate : 48000; } mix_code = ghb_get_best_mix( aconfig, acodec_code, mix_code); - br = hb_get_best_audio_bitrate(acodec_code, br, sr, mix_code); + br = hb_audio_bitrate_get_best(acodec_code, br, sr, mix_code); ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(br)); ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix_code)); @@ -717,8 +719,8 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) float low, high, gran, defval; int dir; - hb_get_audio_quality_limits(acodec_code, &low, &high, &gran, &dir); - defval = hb_get_default_audio_quality(acodec_code); + hb_audio_quality_get_limits(acodec_code, &low, &high, &gran, &dir); + defval = hb_audio_quality_get_default(acodec_code); GtkScaleButton *sb; GtkAdjustment *adj; sb = GTK_SCALE_BUTTON(GHB_WIDGET(ud->builder, "AudioTrackQuality")); @@ -843,7 +845,7 @@ char * ghb_format_quality( const char *prefix, int codec, double quality ) { float low, high, gran; int dir; - hb_get_audio_quality_limits(codec, &low, &high, &gran, &dir); + hb_audio_quality_get_limits(codec, &low, &high, &gran, &dir); int digits = 0; float tmp = gran; @@ -868,7 +870,7 @@ quality_widget_changed_cb(GtkWidget *widget, gdouble quality, signal_user_data_t float low, high, gran; int dir; int codec = ghb_settings_combo_int(ud->settings, "AudioEncoderActual"); - hb_get_audio_quality_limits(codec, &low, &high, &gran, &dir); + hb_audio_quality_get_limits(codec, &low, &high, &gran, &dir); if (dir) { // Quality values are inverted diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c index 689c3b7e0..b3f82067c 100644 --- a/gtk/src/hb-backend.c +++ b/gtk/src/hb-backend.c @@ -173,17 +173,6 @@ combo_opts_t vqual_granularity_opts = d_vqual_granularity_opts }; -static options_map_t d_container_opts[] = -{ - {"MKV", "mkv", HB_MUX_MKV, "mkv"}, - {"MP4", "mp4", HB_MUX_MP4, "mp4"}, -}; -combo_opts_t container_opts = -{ - sizeof(d_container_opts)/sizeof(options_map_t), - d_container_opts -}; - static options_map_t d_detel_opts[] = { {"Off", "off", 0, ""}, @@ -383,7 +372,6 @@ combo_name_map_t combo_name_map[] = {"LogLongevity", &log_longevity_opts}, {"check_updates", &appcast_update_opts}, {"VideoQualityGranularity", &vqual_granularity_opts}, - {"FileFormat", &container_opts}, {"PictureDeinterlace", &deint_opts}, {"PictureDecomb", &decomb_opts}, {"PictureDetelecine", &detel_opts}, @@ -842,529 +830,532 @@ lookup_generic_option(combo_opts_t *opts, const GValue *gval) return result; } -static gint -lookup_mix_int(const GValue *mix) +static const hb_mixdown_t * +lookup_mixdown_by_int(int imix) { - gint ii; - gint result = 0; - - - if (G_VALUE_TYPE(mix) == G_TYPE_STRING) + const hb_mixdown_t *mix; + for (mix = hb_mixdown_get_next(NULL); mix != NULL; + mix = hb_mixdown_get_next(mix)) { - gchar * str = ghb_value_string(mix); - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) + if (mix->amixdown == imix) { - if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0) - { - result = hb_audio_mixdowns[ii].amixdown; - break; - } - } - g_free(str); - } - else if (G_VALUE_TYPE(mix) == G_TYPE_INT || - G_VALUE_TYPE(mix) == G_TYPE_INT64 || - G_VALUE_TYPE(mix) == G_TYPE_DOUBLE) - { - gint val = ghb_value_int(mix); - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) - { - if (hb_audio_mixdowns[ii].amixdown == val) - { - result = hb_audio_mixdowns[ii].amixdown; - break; - } + return mix; } } - return result; + return NULL; } -static const gchar* -lookup_mix_option(const GValue *mix) +static const hb_mixdown_t * +lookup_mixdown(const GValue *gmix) { - gint ii; - const gchar *result = "None"; + const hb_mixdown_t *mix; - - if (G_VALUE_TYPE(mix) == G_TYPE_STRING) + if (G_VALUE_TYPE(gmix) == G_TYPE_STRING) { - gchar *str = ghb_value_string(mix); - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) + gchar * str = ghb_value_string(gmix); + for (mix = hb_mixdown_get_next(NULL); mix != NULL; + mix = hb_mixdown_get_next(mix)) { - if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0) + if (strcmp(mix->short_name, str) == 0) { - result = hb_audio_mixdowns[ii].human_readable_name; - break; + g_free(str); + return mix; } } g_free(str); } - else if (G_VALUE_TYPE(mix) == G_TYPE_INT || - G_VALUE_TYPE(mix) == G_TYPE_INT64 || - G_VALUE_TYPE(mix) == G_TYPE_DOUBLE) + else if (G_VALUE_TYPE(gmix) == G_TYPE_INT || + G_VALUE_TYPE(gmix) == G_TYPE_INT64 || + G_VALUE_TYPE(gmix) == G_TYPE_DOUBLE) { - gint val = ghb_value_int(mix); - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) - { - if (hb_audio_mixdowns[ii].amixdown == val) - { - result = hb_audio_mixdowns[ii].human_readable_name; - break; - } - } + return lookup_mixdown_by_int(ghb_value_int(gmix)); } - return result; + return NULL; } -static const gchar* -lookup_mix_string(const GValue *mix) +static gint +lookup_mixdown_int(const GValue *gmix) { - gint ii; - const gchar *result = "none"; + const hb_mixdown_t *mix = lookup_mixdown(gmix); + if (mix != NULL) + return mix->amixdown; + return 0; +} +static const gchar* +lookup_mixdown_option(const GValue *gmix) +{ + const hb_mixdown_t *mix = lookup_mixdown(gmix); + if (mix != NULL) + return mix->name; + return "None"; +} - if (G_VALUE_TYPE(mix) == G_TYPE_STRING) - { - gchar *str = ghb_value_string(mix); - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) - { - if (strcmp(hb_audio_mixdowns[ii].short_name, str) == 0) - { - result = hb_audio_mixdowns[ii].short_name; - break; - } - } - g_free(str); - } - else if (G_VALUE_TYPE(mix) == G_TYPE_INT || - G_VALUE_TYPE(mix) == G_TYPE_INT64 || - G_VALUE_TYPE(mix) == G_TYPE_DOUBLE) - { - gint val = ghb_value_int(mix); - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) - { - if (hb_audio_mixdowns[ii].amixdown == val) - { - result = hb_audio_mixdowns[ii].short_name; - break; - } - } - } - return result; +static const gchar* +lookup_mixdown_string(const GValue *gmix) +{ + const hb_mixdown_t *mix = lookup_mixdown(gmix); + if (mix != NULL) + return mix->short_name; + return "none"; } -static gint -lookup_video_rate_int(const GValue *vrate) +static const hb_rate_t * +lookup_video_framerate(const GValue *grate) { - gint ii; gchar *str; - gint result = 0; + const hb_rate_t *rate; - str = ghb_value_string(vrate); - for (ii = 0; ii < hb_video_rates_count; ii++) + str = ghb_value_string(grate); + for (rate = hb_video_framerate_get_next(NULL); rate != NULL; + rate = hb_video_framerate_get_next(rate)) { - if (strcmp(hb_video_rates[ii].string, str) == 0) + if (strcmp(rate->name, str) == 0) { - result = hb_video_rates[ii].rate; - break; + g_free(str); + return rate; } } g_free(str); // Default to "same as source" - return result; + return NULL; } -static const gchar* -lookup_video_rate_option(const GValue *vrate) +static gint +lookup_video_framerate_int(const GValue *grate) { - gint ii; - gchar *str; - const gchar *result = "Same as source"; + const hb_rate_t *rate = lookup_video_framerate(grate); + if (rate != NULL) + return rate->rate; + return 0; +} - str = ghb_value_string(vrate); - for (ii = 0; ii < hb_video_rates_count; ii++) - { - if (strcmp(hb_video_rates[ii].string, str) == 0) - { - result = hb_video_rates[ii].string; - break; - } - } - g_free(str); - // Default to "same as source" - return result; +static const gchar* +lookup_video_framerate_option(const GValue *grate) +{ + const hb_rate_t *rate = lookup_video_framerate(grate); + if (rate != NULL) + return rate->name; + return "Same as source"; } -static gint -lookup_audio_rate_int(const GValue *rate) +static const hb_rate_t * +lookup_audio_samplerate(const GValue *grate) { - gint ii; - gint result = 0; + const hb_rate_t *rate; - if (G_VALUE_TYPE(rate) == G_TYPE_STRING) + if (G_VALUE_TYPE(grate) == G_TYPE_STRING) { // Coincidentally, the string "source" will return 0 // which is our flag to use "same as source" - gchar * str = ghb_value_string(rate); - for (ii = 0; ii < hb_audio_rates_count; ii++) + gchar * str = ghb_value_string(grate); + for (rate = hb_audio_samplerate_get_next(NULL); rate != NULL; + rate = hb_audio_samplerate_get_next(rate)) { - if (strcmp(hb_audio_rates[ii].string, str) == 0) + if (strcmp(rate->name, str) == 0) { - result = hb_audio_rates[ii].rate; - break; + g_free(str); + return rate; } } g_free(str); } - else if (G_VALUE_TYPE(rate) == G_TYPE_INT || - G_VALUE_TYPE(rate) == G_TYPE_INT64 || - G_VALUE_TYPE(rate) == G_TYPE_DOUBLE) + else if (G_VALUE_TYPE(grate) == G_TYPE_INT || + G_VALUE_TYPE(grate) == G_TYPE_INT64 || + G_VALUE_TYPE(grate) == G_TYPE_DOUBLE) { - for (ii = 0; ii < hb_audio_rates_count; ii++) + gint val = ghb_value_int(grate); + for (rate = hb_audio_samplerate_get_next(NULL); rate != NULL; + rate = hb_audio_samplerate_get_next(rate)) { - gint val = ghb_value_int(rate); - if (val == hb_audio_rates[ii].rate) + if (val == rate->rate) { - result = hb_audio_rates[ii].rate; - break; + return rate; } } } - return result; + return NULL; +} + +static gint +lookup_audio_samplerate_int(const GValue *grate) +{ + const hb_rate_t *rate = lookup_audio_samplerate(grate); + if (rate != NULL) + return rate->rate; + return 0; } static const gchar* -lookup_audio_rate(const GValue *rate, const char *def) +lookup_audio_samplerate_def(const GValue *grate, const char *def) { - gint ii; const gchar *result = def; - - if (G_VALUE_TYPE(rate) == G_TYPE_STRING) - { - // Coincidentally, the string "source" will return 0 - // which is our flag to use "same as source" - gchar *str = ghb_value_string(rate); - for (ii = 0; ii < hb_audio_rates_count; ii++) - { - if (strcmp(hb_audio_rates[ii].string, str) == 0) - { - result = hb_audio_rates[ii].string; - break; - } - } - g_free(str); - } - else if (G_VALUE_TYPE(rate) == G_TYPE_INT || - G_VALUE_TYPE(rate) == G_TYPE_INT64 || - G_VALUE_TYPE(rate) == G_TYPE_DOUBLE) - { - for (ii = 0; ii < hb_audio_rates_count; ii++) - { - gint val = ghb_value_int(rate); - if (val == hb_audio_rates[ii].rate) - { - result = hb_audio_rates[ii].string; - break; - } - } - } + const hb_rate_t *rate = lookup_audio_samplerate(grate); + if (rate != NULL) + return rate->name; return result; } static const gchar* -lookup_audio_rate_option(const GValue *rate) +lookup_audio_samplerate_option(const GValue *grate) { - return lookup_audio_rate(rate, "Same as Source"); + return lookup_audio_samplerate_def(grate, "Same as Source"); } static const gchar* -lookup_audio_rate_string(const GValue *rate) +lookup_audio_samplerate_string(const GValue *grate) { - return lookup_audio_rate(rate, "source"); + return lookup_audio_samplerate_def(grate, "source"); } gint -ghb_find_closest_audio_rate(gint rate) +ghb_find_closest_audio_samplerate(gint irate) { - gint ii; gint result; + const hb_rate_t *rate; result = 0; - for (ii = 0; ii < hb_audio_rates_count; ii++) + for (rate = hb_audio_samplerate_get_next(NULL); rate != NULL; + rate = hb_audio_samplerate_get_next(rate)) { - if (rate <= hb_audio_rates[ii].rate) + if (irate <= rate->rate) { - result = hb_audio_rates[ii].rate; + result = rate->rate; break; } } return result; } -hb_rate_t *ghb_audio_bitrates; -int ghb_audio_bitrates_count; +hb_rate_t *ghb_audio_bitrates = NULL; +int ghb_audio_bitrates_count = 0; +int ghb_abr_count = 0; -static gint -lookup_audio_bitrate_int(const GValue *rate) +static const hb_rate_t * +lookup_audio_bitrate(const GValue *grate) { gint ii; - gint result = 160; + const hb_rate_t *result = NULL; - if (G_VALUE_TYPE(rate) == G_TYPE_STRING) + if (G_VALUE_TYPE(grate) == G_TYPE_STRING) { // Coincidentally, the string "source" will return 0 // which is our flag to use "same as source" - gchar *str = ghb_value_string(rate); + gchar *str = ghb_value_string(grate); for (ii = 0; ii < ghb_audio_bitrates_count; ii++) { - if (strcmp(ghb_audio_bitrates[ii].string, str) == 0) + if (strcmp(ghb_audio_bitrates[ii].name, str) == 0) { - result = ghb_audio_bitrates[ii].rate; - break; + g_free(str); + return &ghb_audio_bitrates[ii]; } } g_free(str); } - else if (G_VALUE_TYPE(rate) == G_TYPE_INT || - G_VALUE_TYPE(rate) == G_TYPE_INT64 || - G_VALUE_TYPE(rate) == G_TYPE_DOUBLE) + else if (G_VALUE_TYPE(grate) == G_TYPE_INT || + G_VALUE_TYPE(grate) == G_TYPE_INT64 || + G_VALUE_TYPE(grate) == G_TYPE_DOUBLE) { - gint val = ghb_value_int(rate); + gint val = ghb_value_int(grate); for (ii = 0; ii < ghb_audio_bitrates_count; ii++) { if (ghb_audio_bitrates[ii].rate == val) { - result = ghb_audio_bitrates[ii].rate; - break; + return &ghb_audio_bitrates[ii]; } } } return result; } +static gint +lookup_audio_bitrate_int(const GValue *grate) +{ + const hb_rate_t *rate = lookup_audio_bitrate(grate); + if (rate != NULL) + return rate->rate; + return 160; +} + static const gchar* -lookup_audio_bitrate_option(const GValue *rate) +lookup_audio_bitrate_option(const GValue *grate) { - gint ii; - const gchar *result = "160"; + const hb_rate_t *rate = lookup_audio_bitrate(grate); + if (rate != NULL) + return rate->name; + return "160"; +} - if (G_VALUE_TYPE(rate) == G_TYPE_STRING) - { - // Coincidentally, the string "source" will return 0 - // which is our flag to use "same as source" - gchar *str = ghb_value_string(rate); - for (ii = 0; ii < ghb_audio_bitrates_count; ii++) - { - if (strcmp(ghb_audio_bitrates[ii].string, str) == 0) - { - result = ghb_audio_bitrates[ii].string; - break; - } - } - g_free(str); - } - else if (G_VALUE_TYPE(rate) == G_TYPE_INT || - G_VALUE_TYPE(rate) == G_TYPE_INT64 || - G_VALUE_TYPE(rate) == G_TYPE_DOUBLE) +static const hb_encoder_t * +lookup_audio_encoder_by_int(int ienc) +{ + const hb_encoder_t *enc; + for (enc = hb_audio_encoder_get_next(NULL); enc != NULL; + enc = hb_audio_encoder_get_next(enc)) { - gint val = ghb_value_int(rate); - for (ii = 0; ii < ghb_audio_bitrates_count; ii++) + if (enc->codec == ienc) { - if (ghb_audio_bitrates[ii].rate == val) - { - result = ghb_audio_bitrates[ii].string; - break; - } + return enc; } } - return result; + return NULL; } -static gint -lookup_hb_encoder_int(const GValue *enc, hb_encoder_t *encoders, int len) +static const hb_encoder_t * +lookup_audio_encoder(const GValue *genc) { - gint ii; + const hb_encoder_t *enc; - if (G_VALUE_TYPE(enc) == G_TYPE_STRING) + if (G_VALUE_TYPE(genc) == G_TYPE_STRING) { - gchar *str = ghb_value_string(enc); - for (ii = 0; ii < len; ii++) + gchar *str = ghb_value_string(genc); + for (enc = hb_audio_encoder_get_next(NULL); enc != NULL; + enc = hb_audio_encoder_get_next(enc)) { - if (strcmp(encoders[ii].human_readable_name, str) == 0 || - strcmp(encoders[ii].short_name, str) == 0) + if (strcmp(enc->name, str) == 0 || + strcmp(enc->short_name, str) == 0) { g_free(str); - return encoders[ii].encoder; + return enc; } } g_free(str); } - else if (G_VALUE_TYPE(enc) == G_TYPE_INT || - G_VALUE_TYPE(enc) == G_TYPE_INT64 || - G_VALUE_TYPE(enc) == G_TYPE_DOUBLE) + else if (G_VALUE_TYPE(genc) == G_TYPE_INT || + G_VALUE_TYPE(genc) == G_TYPE_INT64 || + G_VALUE_TYPE(genc) == G_TYPE_DOUBLE) { - int val = ghb_value_int(enc); - for (ii = 0; ii < len; ii++) - { - if (encoders[ii].encoder == val) - { - return encoders[ii].encoder; - } - } + return lookup_audio_encoder_by_int(ghb_value_int(genc)); } - return 0; + return NULL; } -static const gchar* -lookup_hb_encoder_option(const GValue *enc, hb_encoder_t *encoders, int len) +static const hb_encoder_t * +lookup_video_encoder_by_int(int ienc) { - gint ii; - - if (G_VALUE_TYPE(enc) == G_TYPE_STRING) + const hb_encoder_t *enc; + for (enc = hb_video_encoder_get_next(NULL); enc != NULL; + enc = hb_video_encoder_get_next(enc)) { - gchar *str = ghb_value_string(enc); - for (ii = 0; ii < len; ii++) + if (enc->codec == ienc) { - if (strcmp(encoders[ii].human_readable_name, str) == 0 || - strcmp(encoders[ii].short_name, str) == 0) - { - g_free(str); - return encoders[ii].human_readable_name; - } + return enc; } - g_free(str); } - else if (G_VALUE_TYPE(enc) == G_TYPE_INT || - G_VALUE_TYPE(enc) == G_TYPE_INT64 || - G_VALUE_TYPE(enc) == G_TYPE_DOUBLE) - { - int val = ghb_value_int(enc); - for (ii = 0; ii < len; ii++) - { - if (encoders[ii].encoder == val) - { - return encoders[ii].human_readable_name; - } - } - } - return 0; + return NULL; } -static const gchar* -lookup_hb_encoder_string(const GValue *enc, hb_encoder_t *encoders, int len) +static const hb_encoder_t * +lookup_video_encoder(const GValue *genc) { - gint ii; + const hb_encoder_t *enc; - if (G_VALUE_TYPE(enc) == G_TYPE_STRING) + if (G_VALUE_TYPE(genc) == G_TYPE_STRING) { - gchar *str = ghb_value_string(enc); - for (ii = 0; ii < len; ii++) + gchar *str = ghb_value_string(genc); + for (enc = hb_video_encoder_get_next(NULL); enc != NULL; + enc = hb_video_encoder_get_next(enc)) { - if (strcmp(encoders[ii].human_readable_name, str) == 0 || - strcmp(encoders[ii].short_name, str) == 0) + if (strcmp(enc->name, str) == 0 || + strcmp(enc->short_name, str) == 0) { g_free(str); - return encoders[ii].short_name; + return enc; } } g_free(str); } - else if (G_VALUE_TYPE(enc) == G_TYPE_INT || - G_VALUE_TYPE(enc) == G_TYPE_INT64 || - G_VALUE_TYPE(enc) == G_TYPE_DOUBLE) + else if (G_VALUE_TYPE(genc) == G_TYPE_INT || + G_VALUE_TYPE(genc) == G_TYPE_INT64 || + G_VALUE_TYPE(genc) == G_TYPE_DOUBLE) { - int val = ghb_value_int(enc); - for (ii = 0; ii < len; ii++) - { - if (encoders[ii].encoder == val) - { - return encoders[ii].short_name; - } - } + return lookup_video_encoder_by_int(ghb_value_int(genc)); } + return NULL; +} + +static gint +lookup_audio_encoder_int(const GValue *genc) +{ + const hb_encoder_t *enc = lookup_audio_encoder(genc); + if (enc != NULL) + return enc->codec; return 0; } static gint -lookup_audio_lang_int(const GValue *rate) +lookup_video_encoder_int(const GValue *genc) +{ + const hb_encoder_t *enc = lookup_video_encoder(genc); + if (enc != NULL) + return enc->codec; + return 0; +} + +static const gchar* +lookup_audio_encoder_option(const GValue *genc) +{ + const hb_encoder_t *enc = lookup_audio_encoder(genc); + if (enc != NULL) + return enc->name; + return NULL; +} + +static const gchar* +lookup_video_encoder_option(const GValue *genc) +{ + const hb_encoder_t *enc = lookup_video_encoder(genc); + if (enc != NULL) + return enc->name; + return NULL; +} + +static const gchar* +lookup_audio_encoder_string(const GValue *genc) +{ + const hb_encoder_t *enc = lookup_audio_encoder(genc); + if (enc != NULL) + return enc->short_name; + return NULL; +} + +static const gchar* +lookup_video_encoder_string(const GValue *genc) +{ + const hb_encoder_t *enc = lookup_video_encoder(genc); + if (enc != NULL) + return enc->short_name; + return NULL; +} + +static int +lookup_audio_lang(const GValue *glang) { gint ii; gchar *str; - gint result = 0; - // Coincidentally, the string "source" will return 0 - // which is our flag to use "same as source" - str = ghb_value_string(rate); + str = ghb_value_string(glang); for (ii = 0; ii < LANG_TABLE_SIZE; ii++) { if (strcmp(ghb_language_table[ii].iso639_2, str) == 0) { - result = ii; - break; + g_free(str); + return ii; } } g_free(str); - return result; + return -1; } -static const gchar* -lookup_audio_lang_option(const GValue *rate) +static int +lookup_audio_lang_int(const GValue *glang) { - gint ii; - gchar *str; - const gchar *result = "Same as source"; + gint ii = lookup_audio_lang(glang); + if (ii >= 0) + return ii; + return 0; +} - // Coincidentally, the string "source" will return 0 - // which is our flag to use "same as source" - str = ghb_value_string(rate); - for (ii = 0; ii < LANG_TABLE_SIZE; ii++) +static const gchar* +lookup_audio_lang_option(const GValue *glang) +{ + gint ii = lookup_audio_lang(glang); + if (ii >= 0) { - if (strcmp(ghb_language_table[ii].iso639_2, str) == 0) - { - if (ghb_language_table[ii].native_name[0] != 0) - result = ghb_language_table[ii].native_name; - else - result = ghb_language_table[ii].eng_name; - break; - } + if (ghb_language_table[ii].native_name[0] != 0) + return ghb_language_table[ii].native_name; + else + return ghb_language_table[ii].eng_name; } - g_free(str); - return result; + return "Same as source"; } GValue* -ghb_lookup_acodec_value(gint val) +ghb_lookup_audio_encoder_value(gint ienc) { - GValue *value = NULL; - gint ii; + const hb_encoder_t *enc = lookup_audio_encoder_by_int(ienc); + if (enc != NULL) + return ghb_string_value_new(enc->short_name); + return ghb_string_value_new("copy"); +} - for (ii = 0; ii < hb_audio_encoders_count; ii++) +static GValue* +lookup_mixdown_value(gint imix) +{ + const hb_mixdown_t *mix = lookup_mixdown_by_int(imix); + if (mix != NULL) + return ghb_string_value_new(mix->short_name); + return NULL; +} +static const hb_container_t * +lookup_container_by_int(int imux) +{ + const hb_container_t *mux; + for (mux = hb_container_get_next(NULL); mux != NULL; + mux = hb_container_get_next(mux)) { - if ((int)hb_audio_encoders[ii].encoder == val) + if (mux->format == imux) { - value = ghb_string_value_new(hb_audio_encoders[ii].short_name); - return value; + return mux; } } - value = ghb_string_value_new("copy"); - return value; + return NULL; } -static GValue* -get_amix_value(gint val) +static const hb_container_t * +lookup_container(const GValue *gmux) { - GValue *value = NULL; - gint ii; + const hb_container_t *mux; - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) + if (G_VALUE_TYPE(gmux) == G_TYPE_STRING) { - if (hb_audio_mixdowns[ii].amixdown == val) + gchar *str = ghb_value_string(gmux); + for (mux = hb_container_get_next(NULL); mux != NULL; + mux = hb_container_get_next(mux)) { - value = ghb_string_value_new(hb_audio_mixdowns[ii].short_name); - break; + if (strcmp(mux->name, str) == 0 || + strcmp(mux->short_name, str) == 0) + { + g_free(str); + return mux; + } } + g_free(str); + } + else if (G_VALUE_TYPE(gmux) == G_TYPE_INT || + G_VALUE_TYPE(gmux) == G_TYPE_INT64 || + G_VALUE_TYPE(gmux) == G_TYPE_DOUBLE) + { + return lookup_container_by_int(ghb_value_int(gmux)); } - return value; + return NULL; +} + +static gint +lookup_container_int(const GValue *gmux) +{ + const hb_container_t *mux = lookup_container(gmux); + if (mux != NULL) + return mux->format; + return 0; +} + +static const gchar* +lookup_container_option(const GValue *gmux) +{ + const hb_container_t *mux = lookup_container(gmux); + if (mux != NULL) + return mux->name; + return 0; +} + +static const gchar* +lookup_container_string(const GValue *gmux) +{ + const hb_container_t *mux = lookup_container(gmux); + if (mux != NULL) + return mux->short_name; + return 0; } // Handle for libhb. Gets set by ghb_backend_init() @@ -1561,15 +1552,14 @@ grey_combo_box_item(GtkBuilder *builder, const gchar *name, gint value, gboolean static void grey_mix_opts(signal_user_data_t *ud, gint acodec, gint64 layout) { - gint ii; - g_debug("grey_mix_opts()\n"); - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) + + const hb_mixdown_t *mix; + for (mix = hb_mixdown_get_next(NULL); mix != NULL; + mix = hb_mixdown_get_next(mix)) { - grey_combo_box_item(ud->builder, "AudioMixdown", - hb_audio_mixdowns[ii].amixdown, - !hb_mixdown_is_supported(hb_audio_mixdowns[ii].amixdown, - acodec, layout)); + grey_combo_box_item(ud->builder, "AudioMixdown", mix->amixdown, + !hb_mixdown_is_supported(mix->amixdown, acodec, layout)); } } @@ -1580,7 +1570,6 @@ ghb_grey_combo_options(signal_user_data_t *ud) gint mux, track, titleindex, acodec, fallback; hb_audio_config_t *aconfig = NULL; GValue *gval; - int ii; widget = GHB_WIDGET (ud->builder, "title"); gval = ghb_widget_value(widget); @@ -1597,34 +1586,38 @@ ghb_grey_combo_options(signal_user_data_t *ud) ghb_value_free(gval); grey_combo_box_item(ud->builder, "x264_analyse", 4, TRUE); - for (ii = 0; ii < hb_audio_encoders_count; ii++) + + const hb_encoder_t *enc; + for (enc = hb_audio_encoder_get_next(NULL); enc != NULL; + enc = hb_audio_encoder_get_next(enc)) { - if (!(mux & hb_audio_encoders[ii].muxers)) + if (!(mux & enc->muxers)) { grey_combo_box_item(ud->builder, "AudioEncoder", - hb_audio_encoders[ii].encoder, TRUE); + enc->codec, TRUE); grey_combo_box_item(ud->builder, "AudioEncoderFallback", - hb_audio_encoders[ii].encoder, TRUE); + enc->codec, TRUE); } else { grey_combo_box_item(ud->builder, "AudioEncoder", - hb_audio_encoders[ii].encoder, FALSE); + enc->codec, FALSE); grey_combo_box_item(ud->builder, "AudioEncoderFallback", - hb_audio_encoders[ii].encoder, FALSE); + enc->codec, FALSE); } } - for (ii = 0; ii < hb_video_encoders_count; ii++) + for (enc = hb_video_encoder_get_next(NULL); enc != NULL; + enc = hb_video_encoder_get_next(enc)) { - if (!(mux & hb_video_encoders[ii].muxers)) + if (!(mux & enc->muxers)) { grey_combo_box_item(ud->builder, "VideoEncoder", - hb_video_encoders[ii].encoder, TRUE); + enc->codec, TRUE); } else { grey_combo_box_item(ud->builder, "VideoEncoder", - hb_video_encoders[ii].encoder, FALSE); + enc->codec, FALSE); } } @@ -1668,9 +1661,9 @@ ghb_get_best_mix(hb_audio_config_t *aconfig, gint acodec, gint mix) layout = aconfig ? aconfig->in.channel_layout : AV_CH_LAYOUT_5POINT1; if (mix == HB_AMIXDOWN_NONE) - mix = hb_audio_mixdowns[hb_audio_mixdowns_count-1].amixdown; + mix = HB_INVALID_AMIXDOWN; - return hb_get_best_mixdown( acodec, layout, mix ); + return hb_mixdown_get_best( acodec, layout, mix ); } // Set up the model for the combo box @@ -1711,11 +1704,10 @@ init_combo_box(GtkBuilder *builder, const gchar *name) } static void -audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count) +audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name) { GtkTreeIter iter; GtkListStore *store; - gint ii; gchar *str; g_debug("audio_samplerate_opts_set ()\n"); @@ -1730,29 +1722,31 @@ audio_samplerate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rat 3, 0.0, 4, "source", -1); - for (ii = 0; ii < count; ii++) + + const hb_rate_t *rate; + for (rate = hb_audio_samplerate_get_next(NULL); rate != NULL; + rate = hb_audio_samplerate_get_next(rate)) { gtk_list_store_append(store, &iter); - str = g_strdup_printf("<small>%s</small>", rates[ii].string); + str = g_strdup_printf("<small>%s</small>", rate->name); gtk_list_store_set(store, &iter, 0, str, 1, TRUE, - 2, rates[ii].string, - 3, (gdouble)rates[ii].rate, - 4, rates[ii].string, + 2, rate->name, + 3, (gdouble)rate->rate, + 4, rate->name, -1); g_free(str); } } static void -video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gint count) +video_framerate_opts_set(GtkBuilder *builder, const gchar *name) { GtkTreeIter iter; GtkListStore *store; - gint ii; - g_debug("video_rate_opts_set ()\n"); + g_debug("video_framerate_opts_set ()\n"); store = get_combo_box_store(builder, name); gtk_list_store_clear(store); // Add an item for "Same As Source" @@ -1764,66 +1758,97 @@ video_rate_opts_set(GtkBuilder *builder, const gchar *name, hb_rate_t *rates, gi 3, 0.0, 4, "source", -1); - for (ii = 0; ii < count; ii++) + + const hb_rate_t *rate; + for (rate = hb_video_framerate_get_next(NULL); rate != NULL; + rate = hb_video_framerate_get_next(rate)) { gchar *desc = ""; gchar *option; - if (strcmp(rates[ii].string, "23.976") == 0) + if (strcmp(rate->name, "23.976") == 0) { desc = "(NTSC Film)"; } - else if (strcmp(rates[ii].string, "25") == 0) + else if (strcmp(rate->name, "25") == 0) { desc = "(PAL Film/Video)"; } - else if (strcmp(rates[ii].string, "29.97") == 0) + else if (strcmp(rate->name, "29.97") == 0) { desc = "(NTSC Video)"; } - option = g_strdup_printf ("%s %s", rates[ii].string, desc); + option = g_strdup_printf ("%s %s", rate->name, desc); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, option, 1, TRUE, - 2, rates[ii].string, - 3, (gdouble)rates[ii].rate, - 4, rates[ii].string, + 2, rate->name, + 3, (gdouble)rate->rate, + 4, rate->name, -1); g_free(option); } } static void -hb_encoder_opts_set_with_mask( +video_encoder_opts_set( + GtkBuilder *builder, + const gchar *name) +{ + GtkTreeIter iter; + GtkListStore *store; + gchar *str; + + g_debug("video_encoder_opts_set ()\n"); + store = get_combo_box_store(builder, name); + gtk_list_store_clear(store); + + const hb_encoder_t *enc; + for (enc = hb_video_encoder_get_next(NULL); enc != NULL; + enc = hb_video_encoder_get_next(enc)) + { + 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, + 4, enc->short_name, + -1); + g_free(str); + } +} + +static void +audio_encoder_opts_set_with_mask( GtkBuilder *builder, const gchar *name, - hb_encoder_t *encoders, - int len, int mask, int neg_mask) { GtkTreeIter iter; GtkListStore *store; - gint ii; gchar *str; - g_debug("hb_encoder_opts_set ()\n"); + g_debug("audio_encoder_opts_set ()\n"); store = get_combo_box_store(builder, name); gtk_list_store_clear(store); - for (ii = 0; ii < len; ii++) + + const hb_encoder_t *enc; + for (enc = hb_audio_encoder_get_next(NULL); enc != NULL; + enc = hb_audio_encoder_get_next(enc)) { - if ((mask & encoders[ii].encoder) && - !(neg_mask & encoders[ii].encoder)) + if ((mask & enc->codec) && !(neg_mask & enc->codec)) { gtk_list_store_append(store, &iter); - str = g_strdup_printf("<small>%s</small>", - encoders[ii].human_readable_name); + str = g_strdup_printf("<small>%s</small>", enc->name); gtk_list_store_set(store, &iter, 0, str, 1, TRUE, - 2, encoders[ii].short_name, - 3, (gdouble)encoders[ii].encoder, - 4, encoders[ii].short_name, + 2, enc->short_name, + 3, (gdouble)enc->codec, + 4, enc->short_name, -1); g_free(str); } @@ -1831,20 +1856,17 @@ hb_encoder_opts_set_with_mask( } static void -hb_encoder_opts_set( +audio_encoder_opts_set( GtkBuilder *builder, - const gchar *name, - hb_encoder_t *encoders, - int len) + const gchar *name) { - hb_encoder_opts_set_with_mask(builder, name, encoders, len, ~0, 0); + audio_encoder_opts_set_with_mask(builder, name, ~0, 0); } static void acodec_fallback_opts_set(GtkBuilder *builder, const gchar *name) { - hb_encoder_opts_set_with_mask(builder, name, hb_audio_encoders, - hb_audio_encoders_count, ~0, HB_ACODEC_PASS_FLAG); + audio_encoder_opts_set_with_mask(builder, name, ~0, HB_ACODEC_PASS_FLAG); } static void @@ -1852,23 +1874,54 @@ mix_opts_set(GtkBuilder *builder, const gchar *name) { GtkTreeIter iter; GtkListStore *store; - gint ii; gchar *str; g_debug("mix_opts_set ()\n"); store = get_combo_box_store(builder, name); gtk_list_store_clear(store); - for (ii = 0; ii < hb_audio_mixdowns_count; ii++) + + const hb_mixdown_t *mix; + for (mix = hb_mixdown_get_next(NULL); mix != NULL; + mix = hb_mixdown_get_next(mix)) { gtk_list_store_append(store, &iter); - str = g_strdup_printf("<small>%s</small>", - hb_audio_mixdowns[ii].human_readable_name); + str = g_strdup_printf("<small>%s</small>", mix->name); gtk_list_store_set(store, &iter, 0, str, 1, TRUE, - 2, hb_audio_mixdowns[ii].short_name, - 3, (gdouble)hb_audio_mixdowns[ii].amixdown, - 4, hb_audio_mixdowns[ii].internal_name, + 2, mix->short_name, + 3, (gdouble)mix->amixdown, + 4, mix->internal_name, + -1); + g_free(str); + } +} + +static void +container_opts_set( + GtkBuilder *builder, + const gchar *name) +{ + GtkTreeIter iter; + GtkListStore *store; + gchar *str; + + g_debug("hb_container_opts_set ()\n"); + store = get_combo_box_store(builder, name); + gtk_list_store_clear(store); + + const hb_container_t *mux; + for (mux = hb_container_get_next(NULL); mux != NULL; + mux = hb_container_get_next(mux)) + { + gtk_list_store_append(store, &iter); + str = g_strdup_printf("<small>%s</small>", mux->name); + gtk_list_store_set(store, &iter, + 0, str, + 1, TRUE, + 2, mux->short_name, + 3, (gdouble)mux->format, + 4, mux->short_name, -1); g_free(str); } @@ -2821,23 +2874,25 @@ ghb_lookup_combo_int(const gchar *name, const GValue *gval) if (strcmp(name, "AudioBitrate") == 0) return lookup_audio_bitrate_int(gval); else if (strcmp(name, "AudioSamplerate") == 0) - return lookup_audio_rate_int(gval); + return lookup_audio_samplerate_int(gval); else if (strcmp(name, "VideoFramerate") == 0) - return lookup_video_rate_int(gval); + return lookup_video_framerate_int(gval); else if (strcmp(name, "AudioMixdown") == 0) - return lookup_mix_int(gval); + return lookup_mixdown_int(gval); else if (strcmp(name, "SrtLanguage") == 0) return lookup_audio_lang_int(gval); else if (strcmp(name, "PreferredLanguage") == 0) return lookup_audio_lang_int(gval); else if (strcmp(name, "VideoEncoder") == 0) - return lookup_hb_encoder_int(gval, hb_video_encoders, hb_video_encoders_count); + return lookup_video_encoder_int(gval); else if (strcmp(name, "AudioEncoder") == 0) - return lookup_hb_encoder_int(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_int(gval); else if (strcmp(name, "AudioEncoderFallback") == 0) - return lookup_hb_encoder_int(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_int(gval); else if (strcmp(name, "AudioEncoderActual") == 0) - return lookup_hb_encoder_int(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_int(gval); + else if (strcmp(name, "FileFormat") == 0) + return lookup_container_int(gval); else { return lookup_generic_int(find_combo_table(name), gval); @@ -2854,23 +2909,25 @@ ghb_lookup_combo_double(const gchar *name, const GValue *gval) if (strcmp(name, "AudioBitrate") == 0) return lookup_audio_bitrate_int(gval); else if (strcmp(name, "AudioSamplerate") == 0) - return lookup_audio_rate_int(gval); + return lookup_audio_samplerate_int(gval); else if (strcmp(name, "VideoFramerate") == 0) - return lookup_video_rate_int(gval); + return lookup_video_framerate_int(gval); else if (strcmp(name, "AudioMixdown") == 0) - return lookup_mix_int(gval); + return lookup_mixdown_int(gval); else if (strcmp(name, "SrtLanguage") == 0) return lookup_audio_lang_int(gval); else if (strcmp(name, "PreferredLanguage") == 0) return lookup_audio_lang_int(gval); else if (strcmp(name, "VideoEncoder") == 0) - return lookup_hb_encoder_int(gval, hb_video_encoders, hb_video_encoders_count); + return lookup_video_encoder_int(gval); else if (strcmp(name, "AudioEncoder") == 0) - return lookup_hb_encoder_int(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_int(gval); else if (strcmp(name, "AudioEncoderFallback") == 0) - return lookup_hb_encoder_int(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_int(gval); else if (strcmp(name, "AudioEncoderActual") == 0) - return lookup_hb_encoder_int(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_int(gval); + else if (strcmp(name, "FileFormat") == 0) + return lookup_container_int(gval); else { return lookup_generic_double(find_combo_table(name), gval); @@ -2887,23 +2944,25 @@ ghb_lookup_combo_option(const gchar *name, const GValue *gval) if (strcmp(name, "AudioBitrate") == 0) return lookup_audio_bitrate_option(gval); else if (strcmp(name, "AudioSamplerate") == 0) - return lookup_audio_rate_option(gval); + return lookup_audio_samplerate_option(gval); else if (strcmp(name, "VideoFramerate") == 0) - return lookup_video_rate_option(gval); + return lookup_video_framerate_option(gval); else if (strcmp(name, "AudioMixdown") == 0) - return lookup_mix_option(gval); + return lookup_mixdown_option(gval); else if (strcmp(name, "SrtLanguage") == 0) return lookup_audio_lang_option(gval); else if (strcmp(name, "PreferredLanguage") == 0) return lookup_audio_lang_option(gval); else if (strcmp(name, "VideoEncoder") == 0) - return lookup_hb_encoder_option(gval, hb_video_encoders, hb_video_encoders_count); + return lookup_video_encoder_option(gval); else if (strcmp(name, "AudioEncoder") == 0) - return lookup_hb_encoder_option(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_option(gval); else if (strcmp(name, "AudioEncoderFallback") == 0) - return lookup_hb_encoder_option(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_option(gval); else if (strcmp(name, "AudioEncoderActual") == 0) - return lookup_hb_encoder_option(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_option(gval); + else if (strcmp(name, "FileFormat") == 0) + return lookup_container_option(gval); else { return lookup_generic_option(find_combo_table(name), gval); @@ -2920,23 +2979,25 @@ ghb_lookup_combo_string(const gchar *name, const GValue *gval) if (strcmp(name, "AudioBitrate") == 0) return lookup_audio_bitrate_option(gval); else if (strcmp(name, "AudioSamplerate") == 0) - return lookup_audio_rate_string(gval); + return lookup_audio_samplerate_string(gval); else if (strcmp(name, "VideoFramerate") == 0) - return lookup_video_rate_option(gval); + return lookup_video_framerate_option(gval); else if (strcmp(name, "AudioMixdown") == 0) - return lookup_mix_string(gval); + return lookup_mixdown_string(gval); else if (strcmp(name, "SrtLanguage") == 0) return lookup_audio_lang_option(gval); else if (strcmp(name, "PreferredLanguage") == 0) return lookup_audio_lang_option(gval); else if (strcmp(name, "VideoEncoder") == 0) - return lookup_hb_encoder_string(gval, hb_video_encoders, hb_video_encoders_count); + return lookup_video_encoder_string(gval); else if (strcmp(name, "AudioEncoder") == 0) - return lookup_hb_encoder_string(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_string(gval); else if (strcmp(name, "AudioEncoderFallback") == 0) - return lookup_hb_encoder_string(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_string(gval); else if (strcmp(name, "AudioEncoderActual") == 0) - return lookup_hb_encoder_string(gval, hb_audio_encoders, hb_audio_encoders_count); + return lookup_audio_encoder_string(gval); + else if (strcmp(name, "FileFormat") == 0) + return lookup_container_string(gval); else { return lookup_generic_string(find_combo_table(name), gval); @@ -2979,11 +3040,11 @@ ghb_update_ui_combo_box( if (all) { audio_bitrate_opts_set(ud->builder, "AudioBitrate"); - audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count); - video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count); + audio_samplerate_opts_set(ud->builder, "AudioSamplerate"); + video_framerate_opts_set(ud->builder, "VideoFramerate"); mix_opts_set(ud->builder, "AudioMixdown"); - hb_encoder_opts_set(ud->builder, "VideoEncoder", hb_video_encoders, hb_video_encoders_count); - hb_encoder_opts_set(ud->builder, "AudioEncoder", hb_audio_encoders, hb_audio_encoders_count); + video_encoder_opts_set(ud->builder, "VideoEncoder"); + audio_encoder_opts_set(ud->builder, "AudioEncoder"); acodec_fallback_opts_set(ud->builder, "AudioEncoderFallback"); language_opts_set(ud->builder, "SrtLanguage"); language_opts_set(ud->builder, "PreferredLanguage"); @@ -2999,7 +3060,6 @@ ghb_update_ui_combo_box( generic_opts_set(ud->builder, "LoggingLevel", &logging_opts); generic_opts_set(ud->builder, "LogLongevity", &log_longevity_opts); generic_opts_set(ud->builder, "check_updates", &appcast_update_opts); - generic_opts_set(ud->builder, "FileFormat", &container_opts); generic_opts_set(ud->builder, "PictureDeinterlace", &deint_opts); generic_opts_set(ud->builder, "PictureDetelecine", &detel_opts); generic_opts_set(ud->builder, "PictureDecomb", &decomb_opts); @@ -3015,21 +3075,22 @@ ghb_update_ui_combo_box( x264_tune_opts_set(ud->builder, "x264Tune"); h264_profile_opts_set(ud->builder, "h264Profile"); h264_level_opts_set(ud->builder, "h264Level"); + container_opts_set(ud->builder, "FileFormat"); } else { if (strcmp(name, "AudioBitrate") == 0) audio_bitrate_opts_set(ud->builder, "AudioBitrate"); else if (strcmp(name, "AudioSamplerate") == 0) - audio_samplerate_opts_set(ud->builder, "AudioSamplerate", hb_audio_rates, hb_audio_rates_count); + audio_samplerate_opts_set(ud->builder, "AudioSamplerate"); else if (strcmp(name, "VideoFramerate") == 0) - video_rate_opts_set(ud->builder, "VideoFramerate", hb_video_rates, hb_video_rates_count); + video_framerate_opts_set(ud->builder, "VideoFramerate"); else if (strcmp(name, "AudioMixdown") == 0) mix_opts_set(ud->builder, "AudioMixdown"); else if (strcmp(name, "VideoEncoder") == 0) - hb_encoder_opts_set(ud->builder, "VideoEncoder", hb_video_encoders, hb_video_encoders_count); + video_encoder_opts_set(ud->builder, "VideoEncoder"); else if (strcmp(name, "AudioEncoder") == 0) - hb_encoder_opts_set(ud->builder, "AudioEncoder", hb_audio_encoders, hb_audio_encoders_count); + audio_encoder_opts_set(ud->builder, "AudioEncoder"); else if (strcmp(name, "AudioEncoderFallback") == 0) acodec_fallback_opts_set(ud->builder, "AudioEncoderFallback"); else if (strcmp(name, "SrtLanguage") == 0) @@ -3050,6 +3111,8 @@ ghb_update_ui_combo_box( h264_profile_opts_set(ud->builder, "h264Profile"); else if (strcmp(name, "h264Level") == 0) h264_level_opts_set(ud->builder, "h264Level"); + else if (strcmp(name, "FileFormat") == 0) + container_opts_set(ud->builder, "FileFormat"); else generic_opts_set(ud->builder, name, find_combo_table(name)); } @@ -3079,6 +3142,7 @@ init_ui_combo_boxes(GtkBuilder *builder) init_combo_box(builder, "x264Tune"); init_combo_box(builder, "h264Profile"); init_combo_box(builder, "h264Level"); + init_combo_box(builder, "FileFormat"); for (ii = 0; combo_name_map[ii].name != NULL; ii++) { init_combo_box(builder, combo_name_map[ii].name); @@ -3325,35 +3389,33 @@ audio_bitrate_opts_add(GtkBuilder *builder, const gchar *name, gint rate) if (rate >= 0 && rate < 8) return; - if (ghb_audio_bitrates[hb_audio_bitrates_count].string) + if (ghb_audio_bitrates[ghb_abr_count].name) { - g_free((char*)ghb_audio_bitrates[hb_audio_bitrates_count].string); + g_free((char*)ghb_audio_bitrates[ghb_abr_count].name); } - ghb_audio_bitrates[hb_audio_bitrates_count].rate = rate; + ghb_audio_bitrates[ghb_abr_count].rate = rate; if (rate < 0) { - ghb_audio_bitrates[hb_audio_bitrates_count].string = - g_strdup_printf("N/A"); + ghb_audio_bitrates[ghb_abr_count].name = g_strdup_printf("N/A"); } else { - ghb_audio_bitrates[hb_audio_bitrates_count].string = - g_strdup_printf("%d", rate); + ghb_audio_bitrates[ghb_abr_count].name = g_strdup_printf("%d", rate); } - ghb_audio_bitrates_count = hb_audio_bitrates_count + 1; + ghb_audio_bitrates_count = ghb_abr_count + 1; store = get_combo_box_store(builder, name); if (!find_combo_item_by_int(GTK_TREE_MODEL(store), rate, &iter)) { str = g_strdup_printf ("<small>%s</small>", - ghb_audio_bitrates[hb_audio_bitrates_count].string); + ghb_audio_bitrates[ghb_abr_count].name); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, str, 1, TRUE, - 2, ghb_audio_bitrates[hb_audio_bitrates_count].string, + 2, ghb_audio_bitrates[ghb_abr_count].name, 3, (gdouble)rate, - 4, ghb_audio_bitrates[hb_audio_bitrates_count].string, + 4, ghb_audio_bitrates[ghb_abr_count].name, -1); g_free(str); } @@ -3375,7 +3437,7 @@ audio_bitrate_opts_update( guint last = (guint)last_rate; guint first = (guint)first_rate; - ghb_audio_bitrates_count = hb_audio_bitrates_count; + ghb_audio_bitrates_count = ghb_abr_count; g_debug("audio_bitrate_opts_clean ()\n"); store = get_combo_box_store(builder, name); @@ -3414,15 +3476,29 @@ audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name) { GtkTreeIter iter; GtkListStore *store; - gint ii; + gint count = 0; gchar *str; + int ii; - ghb_audio_bitrates_count = hb_audio_bitrates_count; - ghb_audio_bitrates = calloc(hb_audio_bitrates_count+1, sizeof(hb_rate_t)); + const hb_rate_t *rate; - for (ii = 0; ii < hb_audio_bitrates_count; ii++) + if (ghb_audio_bitrates == NULL) { - ghb_audio_bitrates[ii] = hb_audio_bitrates[ii]; + // Count rates + for (rate = hb_audio_bitrate_get_next(NULL); rate != NULL; + rate = hb_audio_bitrate_get_next(rate)) + { + count++; + } + + ghb_audio_bitrates_count = ghb_abr_count = count; + ghb_audio_bitrates = calloc(count+1, sizeof(hb_rate_t)); + + for (ii = 0, rate = hb_audio_bitrate_get_next(NULL); rate != NULL; + ii++, rate = hb_audio_bitrate_get_next(rate)) + { + ghb_audio_bitrates[ii] = *rate; + } } g_debug("audio_bitrate_opts_set ()\n"); @@ -3432,13 +3508,13 @@ audio_bitrate_opts_set(GtkBuilder *builder, const gchar *name) { gtk_list_store_append(store, &iter); str = g_strdup_printf ("<small>%s</small>", - ghb_audio_bitrates[ii].string); + ghb_audio_bitrates[ii].name); gtk_list_store_set(store, &iter, 0, str, 1, TRUE, - 2, ghb_audio_bitrates[ii].string, + 2, ghb_audio_bitrates[ii].name, 3, (gdouble)ghb_audio_bitrates[ii].rate, - 4, ghb_audio_bitrates[ii].string, + 4, ghb_audio_bitrates[ii].name, -1); g_free(str); } @@ -4513,7 +4589,7 @@ ghb_validate_audio(GValue *settings) { codec = HB_ACODEC_FAAC; } - value = ghb_lookup_acodec_value(codec); + value = ghb_lookup_audio_encoder_value(codec); ghb_settings_take_value(asettings, "AudioEncoder", value); } gchar *a_unsup = NULL; @@ -4540,25 +4616,18 @@ ghb_validate_audio(GValue *settings) return FALSE; } g_free(message); - value = ghb_lookup_acodec_value(codec); + value = ghb_lookup_audio_encoder_value(codec); ghb_settings_take_value(asettings, "AudioEncoder", value); } gint mix = ghb_settings_combo_int (asettings, "AudioMixdown"); - gint jj; const gchar *mix_unsup = NULL; if (!hb_mixdown_is_supported(mix, codec, aconfig->in.channel_layout)) { - for (jj = 0; jj < hb_audio_mixdowns_count; jj++) - { - if (mix == hb_audio_mixdowns[jj].amixdown) - { - { - mix_unsup = hb_audio_mixdowns[jj].human_readable_name; - } - } - } + const hb_mixdown_t *hb_mix = lookup_mixdown_by_int(mix); + if (hb_mix != NULL) + mix_unsup = hb_mix->name; } if (mix_unsup) { @@ -4573,7 +4642,7 @@ ghb_validate_audio(GValue *settings) } g_free(message); mix = ghb_get_best_mix(aconfig, codec, mix); - value = get_amix_value(mix); + value = lookup_mixdown_value(mix); ghb_settings_take_value(asettings, "AudioMixdown", value); } } @@ -5017,7 +5086,7 @@ add_job(hb_handle_t *h, GValue *js, gint unique_id, gint titleindex) audio.out.bitrate = ghb_settings_combo_int(asettings, "AudioBitrate"); - audio.out.bitrate = hb_get_best_audio_bitrate( + audio.out.bitrate = hb_audio_bitrate_get_best( audio.out.codec, audio.out.bitrate, audio.out.samplerate, audio.out.mixdown); } diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h index 242a3e3b7..03d0ce4ed 100644 --- a/gtk/src/hb-backend.h +++ b/gtk/src/hb-backend.h @@ -156,7 +156,7 @@ gdouble ghb_lookup_combo_double(const gchar *name, const GValue *gval); const gchar* ghb_lookup_combo_option(const gchar *name, const GValue *gval); const gchar* ghb_lookup_combo_string(const gchar *name, const GValue *gval); gchar* ghb_get_tmp_dir(); -gint ghb_find_closest_audio_rate(gint rate); -GValue* ghb_lookup_acodec_value(gint val); +gint ghb_find_closest_audio_samplerate(gint rate); +GValue* ghb_lookup_audio_encoder_value(gint val); #endif // _HBBACKEND_H_ diff --git a/gtk/src/presets.c b/gtk/src/presets.c index d76d5d280..12fdfbd67 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -2044,19 +2044,26 @@ static value_map_t acodec_xlat_compat[] = static value_map_t *acodec_xlat; -static value_map_t * create_encoder_xlat_tbl(value_map_t *compat, hb_encoder_t *enc, int size) +static value_map_t * create_video_encoder_xlat_tbl(value_map_t *compat) { value_map_t *out; - int cc, ii; + int cc, ii, size = 0; for (cc = 0; compat[cc].mac_val != NULL; cc++); + const hb_encoder_t *enc; + for (enc = hb_video_encoder_get_next(NULL); enc != NULL; + enc = hb_video_encoder_get_next(enc)) + { + size++; + } out = calloc(cc + size + 1, sizeof(value_map_t)); - for (ii = 0; ii < size; ii++) + for (ii = 0, enc = hb_video_encoder_get_next(NULL); enc != NULL; + ii++, enc = hb_video_encoder_get_next(enc)) { - out[ii].mac_val = enc[ii].human_readable_name; - out[ii].lin_val = enc[ii].short_name; + out[ii].mac_val = enc->name; + out[ii].lin_val = enc->short_name; } for (ii = 0; ii < cc; ii++) @@ -2065,19 +2072,26 @@ static value_map_t * create_encoder_xlat_tbl(value_map_t *compat, hb_encoder_t * return out; } -static value_map_t * create_mix_xlat_tbl(value_map_t *compat, hb_mixdown_t * mix, int size) +static value_map_t * create_audio_encoder_xlat_tbl(value_map_t *compat) { value_map_t *out; - int cc, ii; + int cc, ii, size = 0; for (cc = 0; compat[cc].mac_val != NULL; cc++); - + + const hb_encoder_t *enc; + for (enc = hb_audio_encoder_get_next(NULL); enc != NULL; + enc = hb_audio_encoder_get_next(enc)) + { + size++; + } out = calloc(cc + size + 1, sizeof(value_map_t)); - for (ii = 0; ii < size; ii++) + for (ii = 0, enc = hb_audio_encoder_get_next(NULL); enc != NULL; + ii++, enc = hb_audio_encoder_get_next(enc)) { - out[ii].mac_val = mix[ii].human_readable_name; - out[ii].lin_val = mix[ii].short_name; + out[ii].mac_val = enc->name; + out[ii].lin_val = enc->short_name; } for (ii = 0; ii < cc; ii++) @@ -2086,15 +2100,33 @@ static value_map_t * create_mix_xlat_tbl(value_map_t *compat, hb_mixdown_t * mix return out; } -value_map_t container_xlat[] = +static value_map_t * create_mix_xlat_tbl(value_map_t *compat) { - {"MP4 file", "mp4"}, - {"M4V file", "mp4"}, - {"MKV file", "mkv"}, - {"AVI file", "mkv"}, - {"OGM file", "mkv"}, - {NULL, NULL} -}; + value_map_t *out; + int cc, ii, size = 0;; + + for (cc = 0; compat[cc].mac_val != NULL; cc++); + + const hb_mixdown_t *mix; + for (mix = hb_mixdown_get_next(NULL); mix != NULL; + mix = hb_mixdown_get_next(mix)) + { + size++; + } + out = calloc(cc + size + 1, sizeof(value_map_t)); + + for (ii = 0, mix = hb_mixdown_get_next(NULL); mix != NULL; + ii++, mix = hb_mixdown_get_next(mix)) + { + out[ii].mac_val = mix->name; + out[ii].lin_val = mix->short_name; + } + + for (ii = 0; ii < cc; ii++) + out[ii+size] = compat[ii]; + + return out; +} value_map_t framerate_xlat[] = { @@ -2361,6 +2393,24 @@ export_value_xlat2(value_map_t *value_map, GValue *lin_val, GType mac_type) return NULL; } +static GValue* +export_value_xlat_container(GValue *lin_val) +{ + GValue *sval = NULL; + gchar *str; + const gchar *mux; + int imux; + + str = ghb_value_string(lin_val); + imux = hb_container_get_from_name(str); + g_free(str); + mux = hb_container_get_name(imux); + if (mux != NULL) + sval = ghb_string_value_new(mux); + + return sval; +} + static void export_value_xlat(GValue *dict) { @@ -2374,7 +2424,7 @@ export_value_xlat(GValue *dict) ghb_dict_insert(dict, g_strdup(key), gval); key = "FileFormat"; lin_val = ghb_dict_lookup(dict, key); - gval = export_value_xlat2(container_xlat, lin_val, G_TYPE_STRING); + gval = export_value_xlat_container(lin_val); if (gval) ghb_dict_insert(dict, g_strdup(key), gval); key = "VideoFramerate"; @@ -2528,6 +2578,34 @@ import_value_xlat2( return NULL; } +static GValue* +import_value_xlat_container(GValue *mac_val) +{ + GValue *sval = NULL; + gchar *str; + const gchar *mux; + int imux; + + str = ghb_value_string(mac_val); + mux = hb_container_sanitize_name(str); + g_free(str); + + if (mux == NULL) + { + imux = hb_container_get_from_extension("mp4"); + } + else + { + imux = hb_container_get_from_name(mux); + } + mux = hb_container_get_short_name(imux); + + if (mux != NULL) + sval = ghb_string_value_new(mux); + + return sval; +} + static void import_value_xlat(GValue *dict) { @@ -2542,7 +2620,7 @@ import_value_xlat(GValue *dict) ghb_dict_insert(dict, g_strdup(key), gval); key = "FileFormat"; mac_val = ghb_dict_lookup(dict, key); - gval = import_value_xlat2(defaults, container_xlat, key, mac_val); + gval = import_value_xlat_container(mac_val); if (gval) ghb_dict_insert(dict, g_strdup(key), gval); key = "VideoFramerate"; @@ -3304,9 +3382,9 @@ void ghb_presets_load(signal_user_data_t *ud) { // Create translation tables from libhb tables - mix_xlat = create_mix_xlat_tbl(mix_xlat_compat, hb_audio_mixdowns, hb_audio_mixdowns_count); - acodec_xlat = create_encoder_xlat_tbl(acodec_xlat_compat, hb_audio_encoders, hb_audio_encoders_count); - vcodec_xlat = create_encoder_xlat_tbl(vcodec_xlat_compat, hb_video_encoders, hb_video_encoders_count); + mix_xlat = create_mix_xlat_tbl(mix_xlat_compat); + acodec_xlat = create_audio_encoder_xlat_tbl(acodec_xlat_compat); + vcodec_xlat = create_video_encoder_xlat_tbl(vcodec_xlat_compat); presetsPlist = load_plist("presets"); if (presetsPlist == NULL) |