path: root/player/sub.c
diff options
authorwm4 <wm4@nowhere>2015-12-23 21:44:53 +0100
committerwm4 <wm4@nowhere>2015-12-23 21:52:16 +0100
commitf9ba1a3ddf5186cb31c2715e3293eef70575a9ee (patch)
treed74fc10c76c95d05220a5c379e25333031642d2d /player/sub.c
parentb0381d27eb19d8f70f4f711d41dd342c616ae843 (diff)
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 'player/sub.c')
1 files changed, 2 insertions, 2 deletions
diff --git a/player/sub.c b/player/sub.c
index 9ec7ba5e7b..df84e910af 100644
--- a/player/sub.c
+++ b/player/sub.c
@@ -146,8 +146,8 @@ void reset_subtitle_state(struct MPContext *mpctx)
void uninit_stream_sub_decoders(struct demuxer *demuxer)
- for (int i = 0; i < demuxer->num_streams; i++) {
- struct sh_stream *sh = demuxer->streams[i];
+ for (int i = 0; i < demux_get_num_stream(demuxer); i++) {
+ struct sh_stream *sh = demux_get_stream(demuxer, i);
if (sh->sub) {
sh->sub->dec_sub = NULL;