summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-02-06 13:43:01 +0100
committerwm4 <wm4@nowhere>2014-02-06 13:43:01 +0100
commitbc35d4fcb4398e09c7787c1e0b5ce98934c5e89d (patch)
tree50f3c1011f5cbb731e040579d237ddaf9d8464a0
parent39b932042bfbff91006675a8366afe7789c985a1 (diff)
downloadmpv-bc35d4fcb4398e09c7787c1e0b5ce98934c5e89d.tar.bz2
mpv-bc35d4fcb4398e09c7787c1e0b5ce98934c5e89d.tar.xz
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.
-rw-r--r--demux/demux.c25
-rw-r--r--demux/demux.h5
-rw-r--r--demux/demux_lavf.c20
-rw-r--r--demux/demux_mkv.c33
4 files changed, 26 insertions, 57 deletions
diff --git a/demux/demux.c b/demux/demux.c
index 63a1c16690..519391a9d0 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -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)
diff --git a/demux/demux.h b/demux/demux.h
index 928a5e7d3e..6b5f43e67d 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -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);
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index ee78575de6..cda0d07485 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -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);
}
}
diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c
index 5a5e82ea52..dac134e4ec 100644
--- a/demux/demux_mkv.c
+++ b/demux/demux_mkv.c
@@ -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);
}
}
}