summaryrefslogtreecommitdiffstats
path: root/demux/demux.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-12-23 21:44:53 +0100
committerwm4 <wm4@nowhere>2015-12-23 21:52:16 +0100
commitf9ba1a3ddf5186cb31c2715e3293eef70575a9ee (patch)
treed74fc10c76c95d05220a5c379e25333031642d2d /demux/demux.h
parentb0381d27eb19d8f70f4f711d41dd342c616ae843 (diff)
downloadmpv-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.h')
-rw-r--r--demux/demux.h11
1 files changed, 5 insertions, 6 deletions
diff --git a/demux/demux.h b/demux/demux.h
index 96717d5eeb..db3b504c39 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -86,8 +86,6 @@ enum demux_event {
DEMUX_EVENT_ALL = 0xFFFF,
};
-#define MAX_SH_STREAMS 256
-
struct demuxer;
struct timeline;
@@ -199,9 +197,6 @@ typedef struct demuxer {
// Bitmask of DEMUX_EVENT_*
int events;
- struct sh_stream **streams;
- int num_streams;
-
struct demux_edition *editions;
int num_editions;
int edition;
@@ -251,7 +246,11 @@ double demux_get_next_pts(struct sh_stream *sh);
bool demux_has_packet(struct sh_stream *sh);
struct demux_packet *demux_read_any_packet(struct demuxer *demuxer);
-struct sh_stream *new_sh_stream(struct demuxer *demuxer, enum stream_type type);
+struct sh_stream *demux_get_stream(struct demuxer *demuxer, int index);
+int demux_get_num_stream(struct demuxer *demuxer);
+
+struct sh_stream *demux_alloc_sh_stream(enum stream_type type);
+void demux_add_sh_stream(struct demuxer *demuxer, struct sh_stream *sh);
struct demuxer *demux_open(struct stream *stream, struct demuxer_params *params,
struct mpv_global *global);