1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-25 04:38:01 +00:00

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).
This commit is contained in:
wm4 2017-10-20 22:30:59 +02:00
parent f57ff79867
commit 044af63d98
2 changed files with 18 additions and 10 deletions

View File

@ -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);

View File

@ -56,7 +56,6 @@ struct sh_stream {
// Internal to demux.c
struct demux_stream *ds;
bool ignore_eof; // ignore stream in underrun detection
};
struct mp_codec_params {