summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2019-07-31 10:59:25 -0700
committerJohn Stebbins <[email protected]>2019-08-11 15:36:40 -0700
commitcc33883b8a62e501d33c716f1e805601744d744f (patch)
treeebbec5d763cd5ccb693873d94ff12627eef9c2a2
parent6125d196cacf967e90ab499327dbcb83588778c1 (diff)
libhb: make source audio track name available to frontends
It gets stored in new hb_audio_config_t.in.name field. It is available in the title dict read through hb_title_to_dict() or hb_title_to_json() in AudioList[].Name. When a job is initialized with hb_preset_job_init or hb_preset_job_init_json(), output audio tracks are initialized with the source track name. Also adds output track name initialization to LinGui.
-rw-r--r--gtk/src/audiohandler.c64
-rw-r--r--gtk/src/audiohandler.h2
-rw-r--r--gtk/src/callbacks.c7
-rw-r--r--gtk/src/hb-backend.c8
-rw-r--r--gtk/src/hb-backend.h2
-rw-r--r--gtk/src/queuehandler.c14
-rw-r--r--gtk/src/titledict.c15
-rw-r--r--gtk/src/titledict.h2
-rw-r--r--libhb/common.c5
-rw-r--r--libhb/common.h1
-rw-r--r--libhb/hb_json.c21
-rw-r--r--libhb/hb_json.h2
-rw-r--r--libhb/preset.c4
-rw-r--r--libhb/stream.c9
14 files changed, 109 insertions, 47 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c
index cab1ff0ca..b1cb97c4a 100644
--- a/gtk/src/audiohandler.c
+++ b/gtk/src/audiohandler.c
@@ -27,6 +27,7 @@
#include "hb.h"
#include "settings.h"
#include "jobdict.h"
+#include "titledict.h"
#include "hb-backend.h"
#include "values.h"
#include "callbacks.h"
@@ -61,6 +62,7 @@ ghb_sanitize_audio_settings(GhbValue *settings, GhbValue *asettings)
// Sanitize codec
const char * mux_name;
int title_id, mux, acodec, fallback, copy_mask, track;
+ uint32_t in_codec = 0;
hb_audio_config_t * aconfig;
const hb_title_t * title;
@@ -75,7 +77,11 @@ ghb_sanitize_audio_settings(GhbValue *settings, GhbValue *asettings)
copy_mask = ghb_get_copy_mask(settings);
track = ghb_dict_get_int(asettings, "Track");
aconfig = ghb_get_audio_info(title, track);
- acodec = ghb_select_audio_codec(mux, aconfig, acodec,
+ if (aconfig != NULL)
+ {
+ in_codec = aconfig->in.codec;
+ }
+ acodec = ghb_select_audio_codec(mux, in_codec, acodec,
fallback, copy_mask);
ghb_dict_set_string(asettings, "Encoder",
hb_audio_encoder_get_short_name(acodec));
@@ -115,25 +121,24 @@ ghb_adjust_audio_rate_combos(signal_user_data_t *ud, GhbValue *asettings)
{
ghb_sanitize_audio_settings(ud->settings, asettings);
- int track, title_id, mix, acodec;
- const hb_title_t *title;
- hb_audio_config_t *aconfig;
+ int track, mix, acodec;
+ GhbValue * atrack;
+ uint64_t layout;
- title_id = ghb_dict_get_int(ud->settings, "title");
- title = ghb_lookup_title(title_id, NULL);
track = ghb_dict_get_int(asettings, "Track");
- aconfig = ghb_get_audio_info(title, track);
acodec = ghb_settings_audio_encoder_codec(asettings, "Encoder");
mix = ghb_settings_mixdown_mix(asettings, "Mixdown");
int low, high, sr;
sr = ghb_dict_get_int(asettings, "Samplerate");
- if (sr == 0 && aconfig != NULL)
+ atrack = ghb_get_title_audio_track(ud->settings, track);
+ if (sr == 0)
{
- sr = aconfig->in.samplerate;
+ sr = ghb_dict_get_int(atrack, "SampleRate");
}
- mix = ghb_get_best_mix(aconfig, acodec, mix);
+ layout = ghb_dict_get_int(atrack, "ChannelLayout");
+ mix = ghb_get_best_mix(layout, acodec, mix);
hb_audio_bitrate_get_limits(acodec, sr, mix, &low, &high);
GtkWidget *w = GHB_WIDGET(ud->builder, "AudioBitrate");
@@ -260,10 +265,8 @@ audio_deps(signal_user_data_t *ud, GhbValue *asettings, GtkWidget *widget)
}
gint
-ghb_select_audio_codec(gint mux, hb_audio_config_t *aconfig, gint acodec, gint fallback, gint copy_mask)
+ghb_select_audio_codec(gint mux, guint32 in_codec, gint acodec, gint fallback, gint copy_mask)
{
- guint32 in_codec = aconfig != NULL ? aconfig->in.codec : 0;
-
if (acodec == HB_ACODEC_AUTO_PASS)
{
return hb_autopassthru_get_encoder(in_codec, copy_mask, fallback, mux);
@@ -509,7 +512,6 @@ ghb_get_user_audio_lang(GhbValue *settings, const hb_title_t *title, gint track)
static GhbValue*
audio_add_track(
GhbValue *settings,
- const hb_title_t *title,
int track,
int encoder,
gdouble quality,
@@ -520,9 +522,8 @@ audio_add_track(
gdouble gain)
{
GhbValue *asettings;
- hb_audio_config_t *aconfig = NULL;
+ GhbValue *atrack;
- aconfig = ghb_get_audio_info(title, track);
asettings = ghb_dict_new();
ghb_dict_set_int(asettings, "Track", track);
@@ -532,9 +533,16 @@ audio_add_track(
ghb_dict_set_int(asettings, "Bitrate", bitrate);
ghb_dict_set_int(asettings, "Samplerate", samplerate);
- if (aconfig != NULL)
+ atrack = ghb_get_title_audio_track(settings, track);
+ if (atrack != NULL)
{
- mix = ghb_get_best_mix(aconfig, encoder, mix);
+ int layout = ghb_dict_get_int(atrack, "ChannelLayout");
+ const char * name = ghb_dict_get_string(atrack, "Name");
+ mix = ghb_get_best_mix(layout, encoder, mix);
+ if (name != NULL)
+ {
+ ghb_dict_set_string(asettings, "Name", name);
+ }
}
ghb_dict_set_string(asettings, "Mixdown", hb_mixdown_get_short_name(mix));
ghb_dict_set_double(asettings, "DRC", drc);
@@ -602,9 +610,9 @@ audio_select_and_add_track(
hb_audio_config_t *aconfig;
aconfig = hb_list_audio_config_item(title->list_audio, track);
select_acodec = ghb_select_audio_codec(
- mux->format, aconfig, acodec, fallback, copy_mask);
+ mux->format, aconfig->in.codec, acodec, fallback, copy_mask);
- asettings = audio_add_track(settings, title, track, select_acodec,
+ asettings = audio_add_track(settings, track, select_acodec,
quality, bitrate,
samplerate, mix, drc, gain);
}
@@ -978,14 +986,10 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
{
// Transition from passthru to not, put some audio settings back to
// pref settings
- int title_id;
- const hb_title_t *title;
- gint titleindex;
gint track;
gint br, sr, mix;
-
- title_id = ghb_dict_get_int(ud->settings, "title");
- title = ghb_lookup_title(title_id, &titleindex);
+ uint64_t layout;
+ GhbValue * atrack;
if (asettings != NULL)
{
@@ -1008,13 +1012,13 @@ audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
ghb_ui_update(ud, "AudioSamplerate",
ghb_string_value(ghb_audio_samplerate_get_short_name(sr)));
- hb_audio_config_t *aconfig;
- aconfig = ghb_get_audio_info(title, track);
+ atrack = ghb_get_title_audio_track(ud->settings, track);
if (sr == 0)
{
- sr = aconfig ? aconfig->in.samplerate : 48000;
+ sr = ghb_dict_get_int(atrack, "SampleRate");
}
- mix = ghb_get_best_mix( aconfig, acodec, mix);
+ layout = ghb_dict_get_int(atrack, "ChannelLayout");
+ mix = ghb_get_best_mix(layout, acodec, mix);
br = hb_audio_bitrate_get_best(acodec, br, sr, mix);
ghb_ui_update(ud, "AudioBitrate",
ghb_string_value(ghb_audio_bitrate_get_short_name(br)));
diff --git a/gtk/src/audiohandler.h b/gtk/src/audiohandler.h
index d31c5f000..33353ebaa 100644
--- a/gtk/src/audiohandler.h
+++ b/gtk/src/audiohandler.h
@@ -33,7 +33,7 @@ GhbValue *ghb_get_audio_list(GhbValue *settings);
void ghb_sanitize_audio_track_settings(GhbValue *settings);
const gchar* ghb_get_user_audio_lang(GhbValue *settings, const hb_title_t *title, gint track);
void ghb_audio_list_refresh_selected(signal_user_data_t *ud);
-gint ghb_select_audio_codec(gint mux, hb_audio_config_t *aconfig, gint acodec, gint fallback_acodec, gint copy_mask);
+gint ghb_select_audio_codec(gint mux, guint32 in_codec, gint acodec, gint fallback_acodec, gint copy_mask);
int ghb_select_fallback( GhbValue *settings, int acodec );
int ghb_get_copy_mask(GhbValue *settings);
void ghb_audio_list_refresh_all(signal_user_data_t *ud);
diff --git a/gtk/src/callbacks.c b/gtk/src/callbacks.c
index 366e77460..1d1e64e60 100644
--- a/gtk/src/callbacks.c
+++ b/gtk/src/callbacks.c
@@ -2628,11 +2628,13 @@ ghb_set_title_settings(signal_user_data_t *ud, GhbValue *settings)
ghb_subtitle_set_pref_lang(settings);
if (title != NULL)
{
- GhbValue *job_dict;
+ GhbValue * job_dict, * title_dict;
char * label;
job_dict = hb_preset_job_init(ghb_scan_handle(), title_id, settings);
ghb_dict_set(settings, "Job", job_dict);
+ title_dict = hb_title_to_dict(ghb_scan_handle(), title_id);
+ ghb_dict_set(settings, "Title", title_dict);
gint num_chapters = hb_list_count(title->list_chapter);
@@ -2763,6 +2765,9 @@ load_all_titles(signal_user_data_t *ud, int titleindex)
settings_array = ghb_array_new();
+ // Start with a clean job
+ ghb_dict_remove(ud->settings, "Job");
+
preset = ghb_get_current_preset(ud);
if (preset != NULL)
{
diff --git a/gtk/src/hb-backend.c b/gtk/src/hb-backend.c
index e5d4fe54a..9f842ee89 100644
--- a/gtk/src/hb-backend.c
+++ b/gtk/src/hb-backend.c
@@ -1268,19 +1268,17 @@ ghb_grey_combo_options(signal_user_data_t *ud)
acodec = ghb_settings_audio_encoder_codec(ud->settings, "AudioEncoder");
gint64 layout = aconfig != NULL ? aconfig->in.channel_layout : ~0;
+ guint32 in_codec = aconfig != NULL ? aconfig->in.codec : 0;
fallback = ghb_select_fallback(ud->settings, acodec);
gint copy_mask = ghb_get_copy_mask(ud->settings);
- acodec = ghb_select_audio_codec(mux->format, aconfig, acodec,
+ acodec = ghb_select_audio_codec(mux->format, in_codec, acodec,
fallback, copy_mask);
grey_mix_opts(ud, acodec, layout);
}
gint
-ghb_get_best_mix(hb_audio_config_t *aconfig, gint acodec, gint mix)
+ghb_get_best_mix(uint64_t layout, gint acodec, gint mix)
{
- gint layout;
- layout = aconfig ? aconfig->in.channel_layout : AV_CH_LAYOUT_5POINT1;
-
if (mix == HB_AMIXDOWN_NONE)
mix = HB_INVALID_AMIXDOWN;
diff --git a/gtk/src/hb-backend.h b/gtk/src/hb-backend.h
index 18d2f2199..bd9aabd16 100644
--- a/gtk/src/hb-backend.h
+++ b/gtk/src/hb-backend.h
@@ -133,7 +133,7 @@ gint64 ghb_get_chapter_duration(const hb_title_t *title, gint chap);
gint64 ghb_get_chapter_start(const hb_title_t *title, gint chap);
gint64 ghb_chapter_range_get_duration(const hb_title_t *title,
gint sc, gint ec);
-gint ghb_get_best_mix(hb_audio_config_t *aconfig, gint acodec, gint mix);
+gint ghb_get_best_mix(uint64_t layout, gint acodec, gint mix);
gboolean ghb_audio_is_passthru(gint acodec);
gboolean ghb_audio_can_passthru(gint acodec);
gint ghb_get_default_acodec(void);
diff --git a/gtk/src/queuehandler.c b/gtk/src/queuehandler.c
index 69f0b43b3..5cacf9a8c 100644
--- a/gtk/src/queuehandler.c
+++ b/gtk/src/queuehandler.c
@@ -29,6 +29,7 @@
#include "hb.h"
#include "settings.h"
#include "jobdict.h"
+#include "titledict.h"
#include "hb-backend.h"
#include "values.h"
#include "callbacks.h"
@@ -1915,16 +1916,17 @@ queue_add(signal_user_data_t *ud, GhbValue *settings, gint batch)
ghb_finalize_job(settings);
+ GhbValue *titleDict = ghb_get_title_settings(settings);
GhbValue *jobDict = ghb_get_job_settings(settings);
- GhbValue *sourceDict = ghb_get_job_source_settings(settings);
- GhbValue *queueDict = ghb_dict_new();
GhbValue *uiDict = ghb_value_dup(settings);
+
ghb_dict_remove(uiDict, "Job");
- int title_id = ghb_dict_get_int(sourceDict, "Title");
- GhbValue *titleDict = ghb_get_title_dict(title_id);
+ ghb_dict_remove(uiDict, "Title");
+
+ GhbValue *queueDict = ghb_dict_new();
ghb_dict_set(queueDict, "uiSettings", uiDict);
ghb_dict_set(queueDict, "Job", ghb_value_dup(jobDict));
- ghb_dict_set(queueDict, "Title", titleDict);
+ ghb_dict_set(queueDict, "Title", ghb_value_dup(titleDict));
// Copy current prefs into settings
// The job should run with the preferences that existed
@@ -2560,6 +2562,8 @@ queue_edit_action_cb(GSimpleAction *action, GVariant *param,
ghb_queue_edit_settings = ghb_value_dup(uiDict);
ghb_dict_set(ghb_queue_edit_settings,
"Job", ghb_value_dup(ghb_dict_get(queueDict, "Job")));
+ ghb_dict_set(ghb_queue_edit_settings,
+ "Title", ghb_value_dup(ghb_dict_get(queueDict, "Title")));
status = ghb_dict_get_int(uiDict, "job_status");
if (status == GHB_QUEUE_PENDING)
{
diff --git a/gtk/src/titledict.c b/gtk/src/titledict.c
index 7ad87e6ec..a4d65230c 100644
--- a/gtk/src/titledict.c
+++ b/gtk/src/titledict.c
@@ -39,9 +39,24 @@ GhbValue *ghb_get_title_audio_list(GhbValue *settings)
return audio_list;
}
+GhbValue *ghb_get_title_audio_track(GhbValue *settings, int track)
+{
+ GhbValue *audio_list = ghb_get_title_audio_list(settings);
+ GhbValue *audio_track = ghb_array_get(audio_list, track);
+ return audio_track;
+}
+
GhbValue *ghb_get_title_subtitle_list(GhbValue *settings)
{
GhbValue *title_dict = ghb_get_title_settings(settings);
GhbValue *subtitle_list = ghb_dict_get(title_dict, "SubtitleList");
return subtitle_list;
}
+
+GhbValue *ghb_get_title_subtitle_track(GhbValue *settings, int track)
+{
+ GhbValue *subtitle_list = ghb_get_title_subtitle_list(settings);
+ GhbValue *subtitle_track = ghb_array_get(subtitle_list, track);
+ return subtitle_track;
+}
+
diff --git a/gtk/src/titledict.h b/gtk/src/titledict.h
index 59b5c5506..4d2ed0c6e 100644
--- a/gtk/src/titledict.h
+++ b/gtk/src/titledict.h
@@ -28,6 +28,8 @@
GhbValue* ghb_get_title_settings(GhbValue *settings);
GhbValue* ghb_get_title_audio_list(GhbValue *settings);
+GhbValue *ghb_get_title_audio_track(GhbValue *settings, int track);
GhbValue* ghb_get_title_subtitle_list(GhbValue *settings);
+GhbValue *ghb_get_title_subtitle_track(GhbValue *settings, int track);
#endif // _TITLEDICT_H_
diff --git a/libhb/common.c b/libhb/common.c
index 09dc974c6..1602b4ed0 100644
--- a/libhb/common.c
+++ b/libhb/common.c
@@ -4644,6 +4644,10 @@ hb_audio_t *hb_audio_copy(const hb_audio_t *src)
{
audio->config.out.name = strdup(src->config.out.name);
}
+ if ( src->config.in.name )
+ {
+ audio->config.in.name = strdup(src->config.in.name);
+ }
}
return audio;
}
@@ -4681,6 +4685,7 @@ void hb_audio_close( hb_audio_t **audio )
{
if ( audio && *audio )
{
+ free((*audio)->config.in.name);
free((*audio)->config.out.name);
free(*audio);
*audio = NULL;
diff --git a/libhb/common.h b/libhb/common.h
index 69b285467..098ed78cf 100644
--- a/libhb/common.h
+++ b/libhb/common.h
@@ -857,6 +857,7 @@ struct hb_audio_config_s
* These samples should be dropped
* when decoding */
PRIVATE hb_rational_t timebase;
+ PRIVATE char * name;
} in;
struct
diff --git a/libhb/hb_json.c b/libhb/hb_json.c
index bd1e2f945..f69a1e322 100644
--- a/libhb/hb_json.c
+++ b/libhb/hb_json.c
@@ -397,6 +397,7 @@ static hb_dict_t* hb_title_to_dict_internal( hb_title_t *title )
"LanguageCode", hb_value_string(audio->config.lang.iso639_2),
"Attributes", attributes,
"Codec", hb_value_int(audio->config.in.codec),
+ "CodecParam", hb_value_int(audio->config.in.codec_param),
"CodecName", hb_value_string(codec_name),
"SampleRate", hb_value_int(audio->config.in.samplerate),
"BitRate", hb_value_int(audio->config.in.bitrate),
@@ -409,6 +410,10 @@ static hb_dict_t* hb_title_to_dict_internal( hb_title_t *title )
hb_error("json pack failure: %s", error.text);
return NULL;
}
+ if (audio->config.in.name != NULL)
+ {
+ hb_dict_set_string(audio_dict, "Name", audio->config.in.name);
+ }
hb_value_array_append(audio_list, audio_dict);
}
hb_dict_set(dict, "AudioList", audio_list);
@@ -840,8 +845,7 @@ hb_dict_t* hb_job_to_dict( const hb_job_t * job )
"CompressionLevel", hb_value_double(audio->config.out.compression_level));
if (audio->config.out.name != NULL)
{
- hb_dict_set(audio_dict, "Name",
- hb_value_string(audio->config.out.name));
+ hb_dict_set_string(audio_dict, "Name", audio->config.out.name);
}
hb_value_array_append(audio_list, audio_dict);
@@ -1693,6 +1697,19 @@ char* hb_job_init_json(hb_handle_t *h, int title_index)
return json_job;
}
+char* hb_preset_job_init_json(hb_handle_t *h, int title_index,
+ const char *json_preset)
+{
+ hb_dict_t * preset = hb_value_json(json_preset);
+ hb_dict_t * job = hb_preset_job_init(h, title_index, preset);
+ char * json_job = hb_value_get_json(job);
+
+ hb_value_free(&preset);
+ hb_value_free(&job);
+
+ return json_job;
+}
+
/**
* Add a json string job to the hb queue
* @param h - Pointer to hb_handle_t instance that job is added to
diff --git a/libhb/hb_json.h b/libhb/hb_json.h
index 2cb003aa8..8f8a08cbc 100644
--- a/libhb/hb_json.h
+++ b/libhb/hb_json.h
@@ -24,6 +24,8 @@ hb_dict_t * hb_title_set_to_dict( const hb_title_set_t * title_set );
char * hb_get_title_set_json(hb_handle_t * h);
char * hb_title_to_json( hb_handle_t *h, int title_index );
char * hb_job_init_json(hb_handle_t *h, int title_index);
+char * hb_preset_job_init_json(hb_handle_t *h, int title_index,
+ const char *json_preset);
hb_job_t * hb_dict_to_job( hb_handle_t * h, hb_dict_t *dict );
char * hb_job_to_json(const hb_job_t * job);
hb_job_t * hb_json_to_job(hb_handle_t * h, const char * json_job);
diff --git a/libhb/preset.c b/libhb/preset.c
index 7e87c554f..949b5f4a7 100644
--- a/libhb/preset.c
+++ b/libhb/preset.c
@@ -687,6 +687,10 @@ static void add_audio_for_lang(hb_value_array_t *list, const hb_dict_t *preset,
hb_dict_set(audio_dict, "Name", hb_value_dup(
hb_dict_get(encoder_dict, "AudioTrackName")));
}
+ else if (aconfig->in.name != NULL)
+ {
+ hb_dict_set_string(audio_dict, "Name", aconfig->in.name);
+ }
if (!(out_codec & HB_ACODEC_PASS_FLAG))
{
if (hb_dict_get(encoder_dict, "AudioTrackGainSlider") != NULL)
diff --git a/libhb/stream.c b/libhb/stream.c
index 1e6bf1e0a..1448ac4f0 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -5192,7 +5192,8 @@ static void add_ffmpeg_audio(hb_title_t *title, hb_stream_t *stream, int id)
{
AVStream *st = stream->ffmpeg_ic->streams[id];
AVCodecParameters *codecpar = st->codecpar;
- AVDictionaryEntry *tag = av_dict_get(st->metadata, "language", NULL, 0);
+ AVDictionaryEntry *tag_lang = av_dict_get(st->metadata, "language", NULL, 0);
+ AVDictionaryEntry *tag_name = av_dict_get(st->metadata, "title", NULL, 0);
hb_audio_t *audio = calloc(1, sizeof(*audio));
audio->id = id;
@@ -5274,7 +5275,11 @@ static void add_ffmpeg_audio(hb_title_t *title, hb_stream_t *stream, int id)
}
set_audio_description(audio,
- lang_for_code2(tag != NULL ? tag->value : "und"));
+ lang_for_code2(tag_lang != NULL ? tag_lang->value : "und"));
+ if (tag_name != NULL)
+ {
+ audio->config.in.name = strdup(tag_name->value);
+ }
hb_list_add(title->list_audio, audio);
}