summaryrefslogtreecommitdiffstats
path: root/demux/demux_lavf.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-04-16 22:23:08 +0200
committerJan Ekström <jeebjp@gmail.com>2018-04-18 01:17:42 +0300
commite7e06a47a0b5626c3abe81f3627d10ed58d92d3b (patch)
tree96384e5dca32219b722aa5f717a716be1010c32e /demux/demux_lavf.c
parent020730da0bcc467afee8ff9861fcc9116372003b (diff)
downloadmpv-e7e06a47a0b5626c3abe81f3627d10ed58d92d3b.tar.bz2
mpv-e7e06a47a0b5626c3abe81f3627d10ed58d92d3b.tar.xz
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.)
Diffstat (limited to 'demux/demux_lavf.c')
-rw-r--r--demux/demux_lavf.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index 0b74c84471..dd98fc0c8d 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -748,13 +748,13 @@ static void add_new_streams(demuxer_t *demuxer)
handle_new_stream(demuxer, priv->num_streams);
}
-static void update_metadata(demuxer_t *demuxer, AVPacket *pkt)
+static void update_metadata(demuxer_t *demuxer)
{
lavf_priv_t *priv = demuxer->priv;
if (priv->avfc->event_flags & AVFMT_EVENT_FLAG_METADATA_UPDATED) {
mp_tags_copy_from_av_dictionary(demuxer->metadata, priv->avfc->metadata);
priv->avfc->event_flags = 0;
- demux_changed(demuxer, DEMUX_EVENT_METADATA);
+ demux_metadata_changed(demuxer);
}
for (int n = 0; n < priv->num_streams; n++) {
@@ -923,7 +923,6 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check)
add_new_streams(demuxer);
mp_tags_copy_from_av_dictionary(demuxer->metadata, avfc->metadata);
- update_metadata(demuxer, NULL);
demuxer->ts_resets_possible =
priv->avif_flags & (AVFMT_TS_DISCONT | AVFMT_NOTIMESTAMPS);
@@ -994,7 +993,7 @@ static int demux_lavf_fill_buffer(demuxer_t *demux)
}
add_new_streams(demux);
- update_metadata(demux, pkt);
+ update_metadata(demux);
assert(pkt->stream_index >= 0 && pkt->stream_index < priv->num_streams);
struct sh_stream *stream = priv->streams[pkt->stream_index];
@@ -1143,9 +1142,9 @@ redo:
priv->cur_program = prog->progid = program->id;
mp_tags_copy_from_av_dictionary(demuxer->metadata, priv->avfc->programs[p]->metadata);
- update_metadata(demuxer, NULL);
+ update_metadata(demuxer);
// Enforce metadata update even if no explicit METADATA_UPDATED since we switched program.
- demux_changed(demuxer, DEMUX_EVENT_METADATA);
+ demux_metadata_changed(demuxer);
return CONTROL_OK;
}