diff options
author | wm4 <wm4@nowhere> | 2014-08-06 19:25:37 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-08-06 20:30:47 +0200 |
commit | 64e1132d39c7124d1f7376e49a311d34a636cb26 (patch) | |
tree | 3e26ff19a5c04e166185a3b982c587378069aa07 /demux | |
parent | b38ac38aec46dc6f36d928731ba138a1d4347c7f (diff) |
demux: make track switching asynchronous
Because why not.
This can lead to reordering of operations between seeking and track
switching (happens when the demuxer wakes up after seek and track
switching operations were queued). Do the track switching strictly
before seeks if there is a chance of reordering, which guarantees that
the seek position will always start with key frames. The reverse
(seeking, then switching) does not really have any advantages.
(Not sure if the player relies on this behavior.)
Diffstat (limited to 'demux')
-rw-r--r-- | demux/demux.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/demux/demux.c b/demux/demux.c index 72023ad14d..6af7976759 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -113,6 +113,8 @@ struct demux_internal { int min_packs; int min_bytes; + bool tracks_switched; // thread needs to inform demuxer of this + bool seeking; // there's a seek queued int seek_flags; // flags for next seek (if seeking==true) double seek_pts; @@ -404,6 +406,18 @@ static void ds_get_packets(struct demux_stream *ds) } } +static void execute_trackswitch(struct demux_internal *in) +{ + in->tracks_switched = false; + + pthread_mutex_unlock(&in->lock); + + if (in->d_thread->desc->control) + in->d_thread->desc->control(in->d_thread, DEMUXER_CTRL_SWITCHED_TRACKS, 0); + + pthread_mutex_lock(&in->lock); +} + static void execute_seek(struct demux_internal *in) { int flags = in->seek_flags; @@ -429,6 +443,10 @@ static void *demux_thread(void *pctx) pthread_cond_wait(&in->wakeup, &in->lock); continue; } + if (in->tracks_switched) { + execute_trackswitch(in); + continue; + } if (in->seeking) { execute_seek(in); continue; @@ -1128,6 +1146,9 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg) c->res = r; return DEMUXER_CTRL_OK; } + case DEMUXER_CTRL_SWITCHED_TRACKS: + in->tracks_switched = true; + return DEMUXER_CTRL_OK; } return DEMUXER_CTRL_DONTKNOW; } |