summaryrefslogtreecommitdiffstats
path: root/player/loadfile.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-01-18 17:13:26 +0100
committerwm4 <wm4@nowhere>2017-01-18 17:52:05 +0100
commitc54c3b6991ac0273e6b7a42dc42c5103f87ff9f1 (patch)
tree1b543741e9bf171fa9a77fe90e4df9f62396284d /player/loadfile.c
parent04858c0b83fd6c1fc60519c2034e263d2e7c3977 (diff)
downloadmpv-c54c3b6991ac0273e6b7a42dc42c5103f87ff9f1.tar.bz2
mpv-c54c3b6991ac0273e6b7a42dc42c5103f87ff9f1.tar.xz
player: restructure cancel callback
As preparation for file prefetching, we basically have to get rid of using mpctx->playback_abort for the main demuxer (i.e. the thing that can be prefetched). It can't be changed on a running demuxer, and always using the same cancel handle would either mean aborting playback would also abort prefetching, or that playback can't be aborted anymore. Make this more flexible with some refactoring. Thi is a quite shitty solution if you ask me, but YOLO.
Diffstat (limited to 'player/loadfile.c')
-rw-r--r--player/loadfile.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/player/loadfile.c b/player/loadfile.c
index 872db20399..e59acbc8d4 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -57,6 +57,17 @@
#include "command.h"
#include "libmpv/client.h"
+// Called by foreign threads when playback should be stopped and such.
+void mp_abort_playback_async(struct MPContext *mpctx)
+{
+ mp_cancel_trigger(mpctx->playback_abort);
+
+ pthread_mutex_lock(&mpctx->lock);
+ if (mpctx->demuxer_cancel)
+ mp_cancel_trigger(mpctx->demuxer_cancel);
+ pthread_mutex_unlock(&mpctx->lock);
+}
+
static void uninit_demuxer(struct MPContext *mpctx)
{
for (int r = 0; r < NUM_PTRACKS; r++) {
@@ -80,6 +91,11 @@ static void uninit_demuxer(struct MPContext *mpctx)
free_demuxer_and_stream(mpctx->demuxer);
mpctx->demuxer = NULL;
+
+ pthread_mutex_lock(&mpctx->lock);
+ talloc_free(mpctx->demuxer_cancel);
+ mpctx->demuxer_cancel = NULL;
+ pthread_mutex_unlock(&mpctx->lock);
}
#define APPEND(s, ...) mp_snprintf_cat(s, sizeof(s), __VA_ARGS__)
@@ -808,11 +824,14 @@ static void open_demux_reentrant(struct MPContext *mpctx)
{
struct demux_open_args args = {
.global = mpctx->global,
- .cancel = mpctx->playback_abort,
+ .cancel = mp_cancel_new(NULL),
.log = mpctx->log,
.stream_flags = mpctx->playing->stream_flags,
.url = talloc_strdup(NULL, mpctx->stream_open_filename),
};
+ pthread_mutex_lock(&mpctx->lock);
+ mpctx->demuxer_cancel = args.cancel;
+ pthread_mutex_unlock(&mpctx->lock);
if (mpctx->opts->load_unsafe_playlists)
args.stream_flags = 0;
mpctx_run_reentrant(mpctx, open_demux_thread, &args);
@@ -820,6 +839,10 @@ static void open_demux_reentrant(struct MPContext *mpctx)
mpctx->demuxer = args.demux;
} else {
mpctx->error_playing = args.err;
+ pthread_mutex_lock(&mpctx->lock);
+ talloc_free(mpctx->demuxer_cancel);
+ mpctx->demuxer_cancel = NULL;
+ pthread_mutex_unlock(&mpctx->lock);
}
talloc_free(args.url);
}
@@ -1170,7 +1193,7 @@ terminate_playback:
if (mpctx->step_frames)
opts->pause = 1;
- mp_cancel_trigger(mpctx->playback_abort);
+ mp_abort_playback_async(mpctx);
// time to uninit all, except global stuff:
uninit_complex_filters(mpctx);