diff options
-rw-r--r-- | common/global.h | 3 | ||||
-rw-r--r-- | input/input.c | 7 | ||||
-rw-r--r-- | input/input.h | 2 | ||||
-rw-r--r-- | player/main.c | 9 | ||||
-rw-r--r-- | stream/cache.c | 4 | ||||
-rw-r--r-- | stream/stream.c | 23 | ||||
-rw-r--r-- | stream/stream.h | 9 |
7 files changed, 22 insertions, 35 deletions
diff --git a/common/global.h b/common/global.h index 546c585294..e49169bebb 100644 --- a/common/global.h +++ b/common/global.h @@ -7,6 +7,9 @@ struct mpv_global { struct MPOpts *opts; struct mp_log *log; + + int (*stream_interrupt_cb)(void *ctx); + void *stream_interrupt_cb_ctx; }; #endif diff --git a/input/input.c b/input/input.c index 5245fd8b63..3ab6089de3 100644 --- a/input/input.c +++ b/input/input.c @@ -1640,15 +1640,12 @@ static bool test_abort(struct input_ctx *ictx) return false; } -/** - * \param time time to wait for an interruption in milliseconds - */ -int mp_input_check_interrupt(struct input_ctx *ictx, int time) +bool mp_input_check_interrupt(struct input_ctx *ictx) { input_lock(ictx); bool res = test_abort(ictx); if (!res) { - read_events(ictx, time); + read_events(ictx, 0); res = test_abort(ictx); } input_unlock(ictx); diff --git a/input/input.h b/input/input.h index 512d0457bf..8f46b0fd9a 100644 --- a/input/input.h +++ b/input/input.h @@ -209,7 +209,7 @@ void mp_input_wakeup(struct input_ctx *ictx); void mp_input_wakeup_nolock(struct input_ctx *ictx); // Interruptible usleep: (used by demux) -int mp_input_check_interrupt(struct input_ctx *ictx, int time); +bool mp_input_check_interrupt(struct input_ctx *ictx); // If this returns true, use Right Alt key as Alt Gr to produce special // characters. If false, count Right Alt as the modifier Alt key. diff --git a/player/main.c b/player/main.c index 1cec6a0324..3522e12b0e 100644 --- a/player/main.c +++ b/player/main.c @@ -347,6 +347,12 @@ struct MPContext *mp_create(void) return mpctx; } +static int check_stream_interrupt(void *ctx) +{ + struct MPContext *mpctx = ctx; + return mp_input_check_interrupt(mpctx->input); +} + static void wakeup_playloop(void *ctx) { struct MPContext *mpctx = ctx; @@ -376,7 +382,8 @@ int mp_initialize(struct MPContext *mpctx) } mpctx->input = mp_input_init(mpctx->global); - stream_set_interrupt_callback(mp_input_check_interrupt, mpctx->input); + mpctx->global->stream_interrupt_cb = check_stream_interrupt; + mpctx->global->stream_interrupt_cb_ctx = mpctx; mp_dispatch_set_wakeup_fn(mpctx->dispatch, wakeup_playloop, mpctx); diff --git a/stream/cache.c b/stream/cache.c index a261a0ecf2..f0d132ad64 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -150,7 +150,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(0)) + if (stream_check_interrupt(s->cache)) return CACHE_INTERRUPTED; double start = mp_time_sec(); @@ -702,7 +702,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size, // wait until cache is filled at least prefill_init % for (;;) { - if (stream_check_interrupt(0)) + if (stream_check_interrupt(cache)) return 0; int64_t fill; int idle; diff --git a/stream/stream.c b/stream/stream.c index 5eee953bf6..59cd2f7763 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -56,10 +56,6 @@ char *cdrom_device = NULL; char *dvd_device = NULL; int dvd_title = 0; -struct input_ctx; -static int (*stream_check_interrupt_cb)(struct input_ctx *ctx, int time); -static struct input_ctx *stream_check_interrupt_ctx; - extern const stream_info_t stream_info_vcd; extern const stream_info_t stream_info_cdda; extern const stream_info_t stream_info_dvb; @@ -409,7 +405,7 @@ static int stream_reconnect(stream_t *s) sleep_ms = MPMIN(sleep_ms * 2, RECONNECT_SLEEP_MAX_MS); } - if (stream_check_interrupt(0)) + if (stream_check_interrupt(s)) return 0; s->eof = 1; @@ -757,20 +753,11 @@ void free_stream(stream_t *s) talloc_free(s); } -void stream_set_interrupt_callback(int (*cb)(struct input_ctx *, int), - struct input_ctx *ctx) -{ - stream_check_interrupt_cb = cb; - stream_check_interrupt_ctx = ctx; -} - -int stream_check_interrupt(int time) +bool stream_check_interrupt(struct stream *s) { - if (!stream_check_interrupt_cb) { - mp_sleep_us(time * 1000); - return 0; - } - return stream_check_interrupt_cb(stream_check_interrupt_ctx, time); + if (!s->global || !s->global->stream_interrupt_cb) + return false; + return s->global->stream_interrupt_cb(s->global->stream_interrupt_cb_ctx); } stream_t *open_memory_stream(void *data, int len) diff --git a/stream/stream.h b/stream/stream.h index d51a26f61c..0fabd62b1f 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -227,14 +227,7 @@ struct stream *stream_open(const char *filename, struct mpv_global *global); stream_t *open_output_stream(const char *filename, struct mpv_global *global); stream_t *open_memory_stream(void *data, int len); -/// Set the callback to be used by libstream to check for user -/// interruption during long blocking operations (cache filling, etc). -struct input_ctx; -void stream_set_interrupt_callback(int (*cb)(struct input_ctx *, int), - struct input_ctx *ctx); -/// Call the interrupt checking callback if there is one and -/// wait for time milliseconds -int stream_check_interrupt(int time); +bool stream_check_interrupt(struct stream *s); bool stream_manages_timeline(stream_t *s); |