diff options
author | wm4 <wm4@nowhere> | 2017-10-20 22:30:59 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-10-20 22:30:59 +0200 |
commit | 044af63d98b926fc6d4dd32068476707fd0bce88 (patch) | |
tree | b14b5542cfffb3bce1e1a2ecce31b3ca6eb98d29 /demux/demux.c | |
parent | f57ff798670af4cbb1d8fc357b40adeaf90f9696 (diff) | |
download | mpv-044af63d98b926fc6d4dd32068476707fd0bce88.tar.bz2 mpv-044af63d98b926fc6d4dd32068476707fd0bce88.tar.xz |
demux: improvements to previous commits
More the ignore_eof field to the internal demux_stream struct. This is
relatively messy, because the internal struct exists only once the
stream is created, and after that setting the ignore_eof flag is a race
condition. We could bother with adding demux_add_sh_stream() parameters
for this, but let's not. So in theory a tiny race condition is
introduced, which can never be triggered since all demux API functions
are called by the playback thread only anyway.
Fix that ts_offset is accessed without log (this was introduced much
earlier by myself).
Introduce an alternative way of avoiding the annoying EOF reached
messages by not resetting the EOF flags for CC streams when a CC packet
is added. This makes the second commit in the PR which added the
original fix unnecessary.
As another cosmetic change merge the check in cached_demux_control()
into a single if().
In the future, the CC pseudo-stream should probably be replaced with an
entire pseudo-demuxer or such, which would avoid some of the messiness
(or maybe not, we don't know yet).
Diffstat (limited to 'demux/demux.c')
-rw-r--r-- | demux/demux.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/demux/demux.c b/demux/demux.c index 2356d0ad3f..fe7e434ec6 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -208,6 +208,8 @@ struct demux_stream { struct demux_packet *attached_picture; bool attached_picture_added; + bool ignore_eof; // ignore stream in underrun detection + // for closed captions (demuxer_feed_caption) struct sh_stream *cc; }; @@ -448,6 +450,7 @@ const char *stream_type_name(enum stream_type type) void demuxer_feed_caption(struct sh_stream *stream, demux_packet_t *dp) { struct demuxer *demuxer = stream->ds->in->d_thread; + struct demux_internal *in = demuxer->in; struct sh_stream *sh = stream->ds->cc; if (!sh) { @@ -457,13 +460,19 @@ void demuxer_feed_caption(struct sh_stream *stream, demux_packet_t *dp) return; } sh->codec->codec = "eia_608"; - sh->ignore_eof = true; stream->ds->cc = sh; demux_add_sh_stream(demuxer, sh); } - dp->pts = MP_ADD_PTS(dp->pts, -stream->ds->in->ts_offset); - dp->dts = MP_ADD_PTS(dp->dts, -stream->ds->in->ts_offset); + pthread_mutex_lock(&in->lock); + + sh->ds->ignore_eof = true; + + dp->pts = MP_ADD_PTS(dp->pts, -in->ts_offset); + dp->dts = MP_ADD_PTS(dp->dts, -in->ts_offset); + + pthread_mutex_unlock(&in->lock); + demux_add_packet(sh, dp); } @@ -569,9 +578,11 @@ void demux_add_packet(struct sh_stream *stream, demux_packet_t *dp) ds->head = ds->tail = dp; } - // obviously not true anymore - ds->eof = false; - in->last_eof = in->eof = false; + if (!ds->ignore_eof) { + // obviously not true anymore + ds->eof = false; + in->last_eof = in->eof = false; + } // For video, PTS determination is not trivial, but for other media types // distinguishing PTS and DTS is not useful. @@ -1660,9 +1671,7 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg) int num_packets = 0; for (int n = 0; n < in->num_streams; n++) { struct demux_stream *ds = in->streams[n]->ds; - if (in->streams[n]->ignore_eof) - continue; - if (ds->active && !(!ds->head && ds->eof)) { + if (ds->active && !(!ds->head && ds->eof) && !ds->ignore_eof) { r->underrun |= !ds->head && !ds->eof; r->ts_range[0] = MP_PTS_MAX(r->ts_range[0], ds->base_ts); r->ts_range[1] = MP_PTS_MIN(r->ts_range[1], ds->last_ts); |