From 1c2c09adf75dea75c0471e765b955f5dfb7092b2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 25 Apr 2014 19:13:12 +0200 Subject: [PATCH] stream: use libavformat interrupt callback This will allow to cancel opening slow/stuck network streams faster. How well his work probably depends on the protocol implementation in libavformat. --- stream/stream_lavf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/stream/stream_lavf.c b/stream/stream_lavf.c index ec46c862f6..c9e714fce4 100644 --- a/stream/stream_lavf.c +++ b/stream/stream_lavf.c @@ -119,6 +119,12 @@ static int control(stream_t *s, int cmd, void *arg) return STREAM_UNSUPPORTED; } +static int interrupt_cb(void *ctx) +{ + struct stream *stream = ctx; + return stream_check_interrupt(stream); +} + static const char * const prefix[] = { "lavf://", "ffmpeg://" }; static int open_f(stream_t *stream, int mode) @@ -200,7 +206,12 @@ static int open_f(stream_t *stream, int mode) av_dict_set(&dict, "headers", cust_headers, 0); av_dict_set(&dict, "icy", "1", 0); - int err = avio_open2(&avio, filename, flags, NULL, &dict); + AVIOInterruptCB cb = { + .callback = interrupt_cb, + .opaque = stream, + }; + + int err = avio_open2(&avio, filename, flags, &cb, &dict); if (err < 0) { if (err == AVERROR_PROTOCOL_NOT_FOUND) MP_ERR(stream, "[ffmpeg] Protocol not found. Make sure"