summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorAman Gupta <aman@tmm1.net>2019-09-26 16:11:48 -0700
committerAman Gupta <aman@tmm1.net>2019-09-27 13:00:45 -0700
commitc7d0a8f58e536b22db88a229dc2f53daf0f02951 (patch)
tree4518a47c07041c33943d8ffe48f470cd8826936b /stream
parent4fdd0940ed2228665d5c6d99f4c024dcfa9bc4ad (diff)
downloadmpv-c7d0a8f58e536b22db88a229dc2f53daf0f02951.tar.bz2
mpv-c7d0a8f58e536b22db88a229dc2f53daf0f02951.tar.xz
stream_cb: add cancel_fn callback
This allows stream_cb backends to implement blocking behavior inside read_fn, and still get notified when the user wants to cancel and stop playback. Signed-off-by: Aman Gupta <aman@tmm1.net>
Diffstat (limited to 'stream')
-rw-r--r--stream/stream_cb.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/stream/stream_cb.c b/stream/stream_cb.c
index fa8871ddf6..fa52935a4b 100644
--- a/stream/stream_cb.c
+++ b/stream/stream_cb.c
@@ -17,9 +17,11 @@
#include "options/path.h"
#include "player/client.h"
#include "libmpv/stream_cb.h"
+#include "misc/thread_tools.h"
struct priv {
mpv_stream_cb_info info;
+ struct mp_cancel *cancel;
};
static int fill_buffer(stream_t *s, char *buffer, int max_len)
@@ -98,6 +100,12 @@ static int open_cb(stream_t *stream)
stream->read_chunk = 64 * 1024;
stream->close = s_close;
+ if (p->info.cancel_fn && stream->cancel) {
+ p->cancel = mp_cancel_new(p);
+ mp_cancel_set_parent(p->cancel, stream->cancel);
+ mp_cancel_set_cb(p->cancel, p->info.cancel_fn, p->info.cookie);
+ }
+
return STREAM_OK;
}