From e7e06a47a0b5626c3abe81f3627d10ed58d92d3b Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 16 Apr 2018 22:23:08 +0200 Subject: demux: support for some kinds of timed metadata This makes ICY title changes show up at approximately the correct time, even if the demuxer buffer is huge. (It'll still be wrong if the stream byte cache contains a meaningful amount of data.) It should have the same effect for mid-stream metadata changes in e.g. OGG (untested). This is still somewhat fishy, but in parts due to ICY being fishy, and FFmpeg's metadata change API being somewhat fishy. For example, what happens if you seek? With FFmpeg AVFMT_EVENT_FLAG_METADATA_UPDATED and AVSTREAM_EVENT_FLAG_METADATA_UPDATED we hope that FFmpeg will correctly restore the correct metadata when the first packet is returned. If you seke with ICY, we're out of luck, and some audio will be associated with the wrong tag until we get a new title through ICY metadata update at an essentially random point (it's mostly inherent to ICY). Then the tags will switch back and forth, and this behavior will stick with the data stored in the demuxer cache. Fortunately, this can happen only if the HTTP stream is actually seekable, which it usually is not for ICY things. Seeking doesn't even make sense with ICY, since you can't know the exact metadata location. Basically ICY metsdata sucks. Some complexity is due to a microoptimization: I didn't want additional atomic accesses for each packet if no timed metadata is used. (It probably doesn't matter at all.) --- common/tags.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'common/tags.c') diff --git a/common/tags.c b/common/tags.c index ffedab9b24..f7e85ace3d 100644 --- a/common/tags.c +++ b/common/tags.c @@ -83,19 +83,27 @@ void mp_tags_clear(struct mp_tags *tags) talloc_free_children(tags); } + + struct mp_tags *mp_tags_dup(void *tparent, struct mp_tags *tags) { struct mp_tags *new = talloc_zero(tparent, struct mp_tags); - MP_RESIZE_ARRAY(new, new->keys, tags->num_keys); - MP_RESIZE_ARRAY(new, new->values, tags->num_keys); - new->num_keys = tags->num_keys; - for (int n = 0; n < tags->num_keys; n++) { - new->keys[n] = talloc_strdup(new, tags->keys[n]); - new->values[n] = talloc_strdup(new, tags->values[n]); - } + mp_tags_replace(new, tags); return new; } +void mp_tags_replace(struct mp_tags *dst, struct mp_tags *src) +{ + mp_tags_clear(dst); + MP_RESIZE_ARRAY(dst, dst->keys, src->num_keys); + MP_RESIZE_ARRAY(dst, dst->values, src->num_keys); + dst->num_keys = src->num_keys; + for (int n = 0; n < src->num_keys; n++) { + dst->keys[n] = talloc_strdup(dst, src->keys[n]); + dst->values[n] = talloc_strdup(dst, src->values[n]); + } +} + // Return a copy of the tags, but containing only keys in list. Also forces // the order and casing of the keys (for cosmetic reasons). // A trailing '*' matches the rest. -- cgit v1.2.3