mirror of
https://github.com/mpv-player/mpv
synced 2025-03-20 18:28:01 +00:00
demux: fill metadata directly, instead of using wrapper functions
Get rid of demux_info_add[_bstr] and demuxer_add_chapter_info. Make demuxer_add_chapter_info return the chapter index for convenience.
This commit is contained in:
parent
39b932042b
commit
bc35d4fcb4
@ -719,17 +719,6 @@ void mp_tags_clear(struct mp_tags *tags)
|
||||
talloc_free_children(tags);
|
||||
}
|
||||
|
||||
int demux_info_add(demuxer_t *demuxer, const char *opt, const char *param)
|
||||
{
|
||||
return demux_info_add_bstr(demuxer, bstr0(opt), bstr0(param));
|
||||
}
|
||||
|
||||
int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param)
|
||||
{
|
||||
mp_tags_set_bstr(demuxer->metadata, opt, param);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int demux_info_print(demuxer_t *demuxer)
|
||||
{
|
||||
struct mp_tags *info = demuxer->metadata;
|
||||
@ -886,19 +875,7 @@ int demuxer_add_chapter(demuxer_t *demuxer, struct bstr name,
|
||||
};
|
||||
mp_tags_set_bstr(new.metadata, bstr0("TITLE"), name);
|
||||
MP_TARRAY_APPEND(demuxer, demuxer->chapters, demuxer->num_chapters, new);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void demuxer_add_chapter_info(struct demuxer *demuxer, uint64_t demuxer_id,
|
||||
bstr key, bstr value)
|
||||
{
|
||||
for (int n = 0; n < demuxer->num_chapters; n++) {
|
||||
struct demux_chapter *ch = &demuxer->chapters[n];
|
||||
if (ch->demuxer_id == demuxer_id) {
|
||||
mp_tags_set_bstr(ch->metadata, key, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return demuxer->num_chapters - 1;
|
||||
}
|
||||
|
||||
static void add_stream_chapters(struct demuxer *demuxer)
|
||||
|
@ -243,9 +243,6 @@ struct demuxer *demux_open(struct stream *stream, char *force_format,
|
||||
void demux_flush(struct demuxer *demuxer);
|
||||
int demux_seek(struct demuxer *demuxer, float rel_seek_secs, int flags);
|
||||
|
||||
int demux_info_add(struct demuxer *demuxer, const char *opt, const char *param);
|
||||
int demux_info_add_bstr(struct demuxer *demuxer, struct bstr opt,
|
||||
struct bstr param);
|
||||
char *demux_info_get(struct demuxer *demuxer, const char *opt);
|
||||
void demux_info_update(struct demuxer *demuxer);
|
||||
|
||||
@ -263,8 +260,6 @@ int demuxer_add_attachment(struct demuxer *demuxer, struct bstr name,
|
||||
struct bstr type, struct bstr data);
|
||||
int demuxer_add_chapter(struct demuxer *demuxer, struct bstr name,
|
||||
uint64_t start, uint64_t end, uint64_t demuxer_id);
|
||||
void demuxer_add_chapter_info(struct demuxer *demuxer, uint64_t demuxer_id,
|
||||
bstr key, bstr value);
|
||||
int demuxer_seek_chapter(struct demuxer *demuxer, int chapter,
|
||||
double *seek_pts);
|
||||
void demuxer_sort_chapters(demuxer_t *demuxer);
|
||||
|
@ -511,11 +511,11 @@ static void add_new_streams(demuxer_t *demuxer)
|
||||
handle_stream(demuxer, priv->num_streams);
|
||||
}
|
||||
|
||||
static void add_metadata(demuxer_t *demuxer, AVDictionary *metadata)
|
||||
static void add_metadata(struct mp_tags *tags, AVDictionary *metadata)
|
||||
{
|
||||
AVDictionaryEntry *t = NULL;
|
||||
while ((t = av_dict_get(metadata, "", t, AV_DICT_IGNORE_SUFFIX)))
|
||||
demux_info_add(demuxer, t->key, t->value);
|
||||
mp_tags_set_str(tags, t->key, t->value);
|
||||
}
|
||||
|
||||
static void update_metadata(demuxer_t *demuxer, AVPacket *pkt)
|
||||
@ -529,7 +529,7 @@ static void update_metadata(demuxer_t *demuxer, AVPacket *pkt)
|
||||
av_packet_unpack_dictionary(md, md_size, &dict);
|
||||
if (dict) {
|
||||
mp_tags_clear(demuxer->metadata);
|
||||
add_metadata(demuxer, dict);
|
||||
add_metadata(demuxer->metadata, dict);
|
||||
av_dict_free(&dict);
|
||||
}
|
||||
}
|
||||
@ -654,25 +654,21 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
|
||||
uint64_t end = av_rescale_q(c->end, c->time_base,
|
||||
(AVRational){1, 1000000000});
|
||||
t = av_dict_get(c->metadata, "title", NULL, 0);
|
||||
demuxer_add_chapter(demuxer, t ? bstr0(t->value) : bstr0(NULL),
|
||||
start, end, i);
|
||||
t = NULL;
|
||||
while ((t = av_dict_get(c->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
|
||||
demuxer_add_chapter_info(demuxer, i, bstr0(t->key),
|
||||
bstr0(t->value));
|
||||
}
|
||||
int index = demuxer_add_chapter(demuxer, t ? bstr0(t->value) : bstr0(""),
|
||||
start, end, i);
|
||||
add_metadata(demuxer->chapters[index].metadata, c->metadata);
|
||||
}
|
||||
|
||||
add_new_streams(demuxer);
|
||||
|
||||
add_metadata(demuxer, avfc->metadata);
|
||||
add_metadata(demuxer->metadata, avfc->metadata);
|
||||
|
||||
// Often useful with OGG audio-only files, which have metadata in the audio
|
||||
// track metadata instead of the main metadata.
|
||||
if (demuxer->num_streams == 1) {
|
||||
for (int n = 0; n < priv->num_streams; n++) {
|
||||
if (priv->streams[n])
|
||||
add_metadata(demuxer, avfc->streams[n]->metadata);
|
||||
add_metadata(demuxer->metadata, avfc->streams[n]->metadata);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -351,7 +351,7 @@ static int demux_mkv_read_info(demuxer_t *demuxer)
|
||||
mkv_d->duration);
|
||||
}
|
||||
if (info.n_title) {
|
||||
demux_info_add_bstr(demuxer, bstr0("TITLE"), info.title);
|
||||
mp_tags_set_bstr(demuxer->metadata, bstr0("TITLE"), info.title);
|
||||
}
|
||||
if (info.n_segment_uid) {
|
||||
int len = info.segment_uid.len;
|
||||
@ -938,33 +938,34 @@ static void process_tags(demuxer_t *demuxer)
|
||||
if (tag.targets.target_track_uid || tag.targets.target_attachment_uid)
|
||||
continue;
|
||||
|
||||
struct mp_tags *dst = NULL;
|
||||
|
||||
if (tag.targets.target_chapter_uid) {
|
||||
for (int j = 0; j < tag.n_simple_tag; j++) {
|
||||
demuxer_add_chapter_info(demuxer, tag.targets.target_chapter_uid,
|
||||
tag.simple_tag[j].tag_name,
|
||||
tag.simple_tag[j].tag_string);
|
||||
for (int n = 0; n < demuxer->num_chapters; n++) {
|
||||
if (demuxer->chapters[n].demuxer_id ==
|
||||
tag.targets.target_chapter_uid)
|
||||
{
|
||||
dst = demuxer->chapters[n].metadata;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (tag.targets.target_edition_uid) {
|
||||
struct demux_edition *edition = NULL;
|
||||
for (int n = 0; n < demuxer->num_editions; n++) {
|
||||
if (demuxer->editions[n].demuxer_id ==
|
||||
tag.targets.target_edition_uid)
|
||||
{
|
||||
edition = &demuxer->editions[n];
|
||||
dst = demuxer->editions[n].metadata;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (edition) {
|
||||
for (int j = 0; j < tag.n_simple_tag; j++) {
|
||||
mp_tags_set_bstr(edition->metadata,
|
||||
tag.simple_tag[j].tag_name,
|
||||
tag.simple_tag[j].tag_string);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dst = demuxer->metadata;
|
||||
}
|
||||
|
||||
if (dst) {
|
||||
for (int j = 0; j < tag.n_simple_tag; j++) {
|
||||
demux_info_add_bstr(demuxer, tag.simple_tag[j].tag_name,
|
||||
tag.simple_tag[j].tag_string);
|
||||
mp_tags_set_bstr(dst, tag.simple_tag[j].tag_name,
|
||||
tag.simple_tag[j].tag_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user