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.
This commit is contained in:
wm4 2014-04-25 19:13:12 +02:00
parent 93de4c81b9
commit 1c2c09adf7
1 changed files with 12 additions and 1 deletions

View File

@ -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"