summaryrefslogtreecommitdiffstats
path: root/stream/cache.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-09-13 14:23:08 +0200
committerwm4 <wm4@nowhere>2014-09-13 16:09:51 +0200
commit2e91d44e2031c299de0d879e2656024d701c27da (patch)
treefdbe4903705bff3d6a21c42f08eb7e4b31e5cf07 /stream/cache.c
parent2dd819705dcbeb4a20c0d6123082f9662cfa2ae4 (diff)
downloadmpv-2e91d44e2031c299de0d879e2656024d701c27da.tar.bz2
mpv-2e91d44e2031c299de0d879e2656024d701c27da.tar.xz
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking network, but it's still useful. On opening and closing, mpv waits for network synchronously, and also some obscure commands and use-cases can lead to such blocking. In these situations, the stream is asynchronously forced to stop by "interrupting" it. The old design interrupting I/O was a bit broken: polling with a callback, instead of actively interrupting it. Change the direction of this. There is no callback anymore, and the player calls mp_cancel_trigger() to force the stream to return. libavformat (via stream_lavf.c) has the old broken design, and fixing it would require fixing libavformat, which won't happen so quickly. So we have to keep that part. But everything above the stream layer is prepared for a better design, and more sophisticated methods than mp_cancel_test() could be easily introduced. There's still one problem: commands are still run in the central playback loop, which we assume can block on I/O in the worst case. That's not a problem yet, because we simply mark some commands as being able to stop playback of the current file ("quit" etc.), so input.c could abort playback as soon as such a command is queued. But there are also commands abort playback only conditionally, and the logic for that is in the playback core and thus "unreachable". For example, "playlist_next" aborts playback only if there's a next file. We don't want it to always abort playback. As a quite ugly hack, abort playback only if at least 2 abort commands are queued - this pretty much happens only if the core is frozen and doesn't react to input.
Diffstat (limited to 'stream/cache.c')
-rw-r--r--stream/cache.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/stream/cache.c b/stream/cache.c
index 81408e098b..a5ac1c2995 100644
--- a/stream/cache.c
+++ b/stream/cache.c
@@ -138,7 +138,7 @@ static int64_t mp_clipi64(int64_t val, int64_t min, int64_t max)
// Returns CACHE_INTERRUPTED if the caller is supposed to abort.
static int cache_wakeup_and_wait(struct priv *s, double *retry_time)
{
- if (stream_check_interrupt(s->cache))
+ if (mp_cancel_test(s->cache->cancel))
return CACHE_INTERRUPTED;
double start = mp_time_sec();
@@ -652,7 +652,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream,
if (min < 1)
return 1;
for (;;) {
- if (stream_check_interrupt(cache))
+ if (mp_cancel_test(cache->cancel))
return -1;
int64_t fill;
int idle;