summaryrefslogtreecommitdiffstats
path: root/player/loadfile.c
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 /player/loadfile.c
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 'player/loadfile.c')
-rw-r--r--player/loadfile.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/player/loadfile.c b/player/loadfile.c
index 07a32c307a..af60aed3e0 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -212,8 +212,8 @@ void update_demuxer_properties(struct MPContext *mpctx)
static bool need_init_seek(struct demuxer *demux)
{
- for (int n = 0; n < demux->num_streams; n++) {
- struct sh_stream *stream = demux->streams[n];
+ for (int n = 0; n < demux_get_num_stream(demux); n++) {
+ struct sh_stream *stream = demux_get_stream(demux, n);
// Subtitle streams are not properly interleaved -> force init. seek.
if (stream->type != STREAM_SUB && demux_stream_is_selected(stream))
return false;
@@ -250,8 +250,8 @@ static struct sh_stream *select_fallback_stream(struct demuxer *d,
int index)
{
struct sh_stream *best_stream = NULL;
- for (int n = 0; n < d->num_streams; n++) {
- struct sh_stream *s = d->streams[n];
+ for (int n = 0; n < demux_get_num_stream(d); n++) {
+ struct sh_stream *s = demux_get_stream(d, n);
if (s->type == type) {
best_stream = s;
if (index == 0)
@@ -396,8 +396,10 @@ static struct track *add_stream_track(struct MPContext *mpctx,
void add_demuxer_tracks(struct MPContext *mpctx, struct demuxer *demuxer)
{
- for (int n = 0; n < demuxer->num_streams; n++)
- add_stream_track(mpctx, demuxer, demuxer->streams[n], !!mpctx->timeline);
+ for (int n = 0; n < demux_get_num_stream(demuxer); n++) {
+ add_stream_track(mpctx, demuxer, demux_get_stream(demuxer, n),
+ !!mpctx->timeline);
+ }
}
// Result numerically higher => better match. 0 == no match.
@@ -708,8 +710,8 @@ struct track *mp_add_external_file(struct MPContext *mpctx, char *filename,
demux_set_ts_offset(demuxer, -demuxer->start_time);
struct track *first = NULL;
- for (int n = 0; n < demuxer->num_streams; n++) {
- struct sh_stream *sh = demuxer->streams[n];
+ for (int n = 0; n < demux_get_num_stream(demuxer); n++) {
+ struct sh_stream *sh = demux_get_stream(demuxer, n);
if (sh->type == filter) {
struct track *t = add_stream_track(mpctx, demuxer, sh, false);
t->is_external = true;