mirror of
https://github.com/mpv-player/mpv
synced 2025-03-22 03:08:33 +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);
|
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)
|
static int demux_info_print(demuxer_t *demuxer)
|
||||||
{
|
{
|
||||||
struct mp_tags *info = demuxer->metadata;
|
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_tags_set_bstr(new.metadata, bstr0("TITLE"), name);
|
||||||
MP_TARRAY_APPEND(demuxer, demuxer->chapters, demuxer->num_chapters, new);
|
MP_TARRAY_APPEND(demuxer, demuxer->chapters, demuxer->num_chapters, new);
|
||||||
return 0;
|
return demuxer->num_chapters - 1;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_stream_chapters(struct demuxer *demuxer)
|
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);
|
void demux_flush(struct demuxer *demuxer);
|
||||||
int demux_seek(struct demuxer *demuxer, float rel_seek_secs, int flags);
|
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);
|
char *demux_info_get(struct demuxer *demuxer, const char *opt);
|
||||||
void demux_info_update(struct demuxer *demuxer);
|
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);
|
struct bstr type, struct bstr data);
|
||||||
int demuxer_add_chapter(struct demuxer *demuxer, struct bstr name,
|
int demuxer_add_chapter(struct demuxer *demuxer, struct bstr name,
|
||||||
uint64_t start, uint64_t end, uint64_t demuxer_id);
|
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,
|
int demuxer_seek_chapter(struct demuxer *demuxer, int chapter,
|
||||||
double *seek_pts);
|
double *seek_pts);
|
||||||
void demuxer_sort_chapters(demuxer_t *demuxer);
|
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);
|
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;
|
AVDictionaryEntry *t = NULL;
|
||||||
while ((t = av_dict_get(metadata, "", t, AV_DICT_IGNORE_SUFFIX)))
|
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)
|
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);
|
av_packet_unpack_dictionary(md, md_size, &dict);
|
||||||
if (dict) {
|
if (dict) {
|
||||||
mp_tags_clear(demuxer->metadata);
|
mp_tags_clear(demuxer->metadata);
|
||||||
add_metadata(demuxer, dict);
|
add_metadata(demuxer->metadata, dict);
|
||||||
av_dict_free(&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,
|
uint64_t end = av_rescale_q(c->end, c->time_base,
|
||||||
(AVRational){1, 1000000000});
|
(AVRational){1, 1000000000});
|
||||||
t = av_dict_get(c->metadata, "title", NULL, 0);
|
t = av_dict_get(c->metadata, "title", NULL, 0);
|
||||||
demuxer_add_chapter(demuxer, t ? bstr0(t->value) : bstr0(NULL),
|
int index = demuxer_add_chapter(demuxer, t ? bstr0(t->value) : bstr0(""),
|
||||||
start, end, i);
|
start, end, i);
|
||||||
t = NULL;
|
add_metadata(demuxer->chapters[index].metadata, c->metadata);
|
||||||
while ((t = av_dict_get(c->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) {
|
|
||||||
demuxer_add_chapter_info(demuxer, i, bstr0(t->key),
|
|
||||||
bstr0(t->value));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_new_streams(demuxer);
|
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
|
// Often useful with OGG audio-only files, which have metadata in the audio
|
||||||
// track metadata instead of the main metadata.
|
// track metadata instead of the main metadata.
|
||||||
if (demuxer->num_streams == 1) {
|
if (demuxer->num_streams == 1) {
|
||||||
for (int n = 0; n < priv->num_streams; n++) {
|
for (int n = 0; n < priv->num_streams; n++) {
|
||||||
if (priv->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);
|
mkv_d->duration);
|
||||||
}
|
}
|
||||||
if (info.n_title) {
|
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) {
|
if (info.n_segment_uid) {
|
||||||
int len = info.segment_uid.len;
|
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)
|
if (tag.targets.target_track_uid || tag.targets.target_attachment_uid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
struct mp_tags *dst = NULL;
|
||||||
|
|
||||||
if (tag.targets.target_chapter_uid) {
|
if (tag.targets.target_chapter_uid) {
|
||||||
for (int j = 0; j < tag.n_simple_tag; j++) {
|
for (int n = 0; n < demuxer->num_chapters; n++) {
|
||||||
demuxer_add_chapter_info(demuxer, tag.targets.target_chapter_uid,
|
if (demuxer->chapters[n].demuxer_id ==
|
||||||
tag.simple_tag[j].tag_name,
|
tag.targets.target_chapter_uid)
|
||||||
tag.simple_tag[j].tag_string);
|
{
|
||||||
|
dst = demuxer->chapters[n].metadata;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (tag.targets.target_edition_uid) {
|
} else if (tag.targets.target_edition_uid) {
|
||||||
struct demux_edition *edition = NULL;
|
|
||||||
for (int n = 0; n < demuxer->num_editions; n++) {
|
for (int n = 0; n < demuxer->num_editions; n++) {
|
||||||
if (demuxer->editions[n].demuxer_id ==
|
if (demuxer->editions[n].demuxer_id ==
|
||||||
tag.targets.target_edition_uid)
|
tag.targets.target_edition_uid)
|
||||||
{
|
{
|
||||||
edition = &demuxer->editions[n];
|
dst = demuxer->editions[n].metadata;
|
||||||
break;
|
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 {
|
} else {
|
||||||
|
dst = demuxer->metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dst) {
|
||||||
for (int j = 0; j < tag.n_simple_tag; j++) {
|
for (int j = 0; j < tag.n_simple_tag; j++) {
|
||||||
demux_info_add_bstr(demuxer, tag.simple_tag[j].tag_name,
|
mp_tags_set_bstr(dst, tag.simple_tag[j].tag_name,
|
||||||
tag.simple_tag[j].tag_string);
|
tag.simple_tag[j].tag_string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user