diff options
author | wm4 <wm4@nowhere> | 2015-12-23 21:44:53 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-12-23 21:52:16 +0100 |
commit | f9ba1a3ddf5186cb31c2715e3293eef70575a9ee (patch) | |
tree | d74fc10c76c95d05220a5c379e25333031642d2d /demux/demux_disc.c | |
parent | b0381d27eb19d8f70f4f711d41dd342c616ae843 (diff) | |
download | mpv-f9ba1a3ddf5186cb31c2715e3293eef70575a9ee.tar.bz2 mpv-f9ba1a3ddf5186cb31c2715e3293eef70575a9ee.tar.xz |
demux: remove weird tripple-buffering for the sh_stream list
The demuxer infrastructure was originally single-threaded. To make it
suitable for multithreading (specifically, demuxing and decoding on
separate threads), some sort of tripple-buffering was introduced. There
are separate "struct demuxer" allocations. The demuxer thread sets the
state on d_thread. If anything changes, the state is copied to d_buffer
(the copy is protected by a lock), and the decoder thread is notified.
Then the decoder thread copies the state from d_buffer to d_user (again
while holding a lock). This avoids the need for locking in the
demuxer/decoder code itself (only demux.c needs an internal, "invisible"
lock.)
Remove the streams/num_streams fields from this tripple-buffering
schema. Move them to the internal struct, and protect them with the
internal lock. Use accessors for read access outside of demux.c.
Other than replacing all field accesses with accessors, this separates
allocating and adding sh_streams. This is needed to avoid race
conditions. Before this change, this was awkwardly handled by first
initializing the sh_stream, and then sending a stream change event. Now
the stream is allocated, then initialized, and then declared as
immutable and added (at which point it becomes visible to the decoder
thread immediately).
This change is useful for PR #2626. And eventually, we should probably
get entirely of the tripple buffering, and this makes a nice first step.
Diffstat (limited to 'demux/demux_disc.c')
-rw-r--r-- | demux/demux_disc.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/demux/demux_disc.c b/demux/demux_disc.c index 1abae38d35..90c276b414 100644 --- a/demux/demux_disc.c +++ b/demux/demux_disc.c @@ -54,9 +54,10 @@ struct priv { static void reselect_streams(demuxer_t *demuxer) { struct priv *p = demuxer->priv; - for (int n = 0; n < MPMIN(p->slave->num_streams, p->num_streams); n++) { + int num_slave = demux_get_num_stream(p->slave); + for (int n = 0; n < MPMIN(num_slave, p->num_streams); n++) { if (p->streams[n]) { - demuxer_select_track(p->slave, p->slave->streams[n], + demuxer_select_track(p->slave, demux_get_stream(p->slave, n), demux_stream_is_selected(p->streams[n])); } } @@ -81,9 +82,7 @@ static void add_dvd_streams(demuxer_t *demuxer) struct stream_dvd_info_req info; if (stream_control(stream, STREAM_CTRL_GET_DVD_INFO, &info) > 0) { for (int n = 0; n < MPMIN(32, info.num_subs); n++) { - struct sh_stream *sh = new_sh_stream(demuxer, STREAM_SUB); - if (!sh) - break; + struct sh_stream *sh = demux_alloc_sh_stream(STREAM_SUB); sh->demuxer_id = n + 0x20; sh->codec = "dvd_subtitle"; get_disc_lang(stream, sh); @@ -114,6 +113,8 @@ static void add_dvd_streams(demuxer_t *demuxer) sh->extradata = s; sh->extradata_size = strlen(s); + + demux_add_sh_stream(demuxer, sh); } } } @@ -122,8 +123,8 @@ static void add_streams(demuxer_t *demuxer) { struct priv *p = demuxer->priv; - for (int n = p->num_streams; n < p->slave->num_streams; n++) { - struct sh_stream *src = p->slave->streams[n]; + for (int n = p->num_streams; n < demux_get_num_stream(p->slave); n++) { + struct sh_stream *src = demux_get_stream(p->slave, n); if (src->sub) { struct sh_stream *sub = NULL; if (src->demuxer_id >= 0x20 && src->demuxer_id <= 0x3F) @@ -134,9 +135,7 @@ static void add_streams(demuxer_t *demuxer) continue; } } - struct sh_stream *sh = new_sh_stream(demuxer, src->type); - if (!sh) - break; + struct sh_stream *sh = demux_alloc_sh_stream(src->type); assert(p->num_streams == n); // directly mapped MP_TARRAY_APPEND(p, p->streams, p->num_streams, sh); // Copy all stream fields that might be relevant @@ -159,6 +158,7 @@ static void add_streams(demuxer_t *demuxer) if (src->audio) sh->audio = src->audio; get_disc_lang(demuxer->stream, sh); + demux_add_sh_stream(demuxer, sh); } reselect_streams(demuxer); } |