X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fasync.c;h=60ea14c9e0e85e21e59ff83f2ce50972c4098ccd;hb=3240e69de6d37155bfdaf61a9828bfa0a296c326;hp=54021e71435f0781ab1f7ae39cc4b0c291c92280;hpb=5e2098d9064e130e603018c8185f591fbcfd5873;p=ffmpeg diff --git a/libavformat/async.c b/libavformat/async.c index 54021e71435..60ea14c9e0e 100644 --- a/libavformat/async.c +++ b/libavformat/async.c @@ -71,7 +71,7 @@ typedef struct Context { AVIOInterruptCB interrupt_callback; } Context; -static int async_interrupt_callback(void *arg) +static int async_check_interrupt(void *arg) { URLContext *h = arg; Context *c = h->priv_data; @@ -95,15 +95,16 @@ static void *async_buffer_task(void *arg) while (1) { int fifo_space, to_copy; - if (async_interrupt_callback(h)) { + pthread_mutex_lock(&c->mutex); + if (async_check_interrupt(h)) { c->io_eof_reached = 1; c->io_error = AVERROR_EXIT; + pthread_cond_signal(&c->cond_wakeup_main); + pthread_mutex_unlock(&c->mutex); break; } if (c->seek_request) { - pthread_mutex_lock(&c->mutex); - ret = ffurl_seek(c->inner, c->seek_pos, c->seek_whence); if (ret < 0) { c->io_eof_reached = 1; @@ -126,15 +127,17 @@ static void *async_buffer_task(void *arg) fifo_space = av_fifo_space(fifo); if (c->io_eof_reached || fifo_space <= 0) { - pthread_mutex_lock(&c->mutex); pthread_cond_signal(&c->cond_wakeup_main); pthread_cond_wait(&c->cond_wakeup_background, &c->mutex); pthread_mutex_unlock(&c->mutex); continue; } + pthread_mutex_unlock(&c->mutex); to_copy = FFMIN(4096, fifo_space); ret = av_fifo_generic_write(fifo, c->inner, to_copy, (void *)ffurl_read); + + pthread_mutex_lock(&c->mutex); if (ret <= 0) { c->io_eof_reached = 1; if (ret < 0) { @@ -142,7 +145,6 @@ static void *async_buffer_task(void *arg) } } - pthread_mutex_lock(&c->mutex); pthread_cond_signal(&c->cond_wakeup_main); pthread_mutex_unlock(&c->mutex); } @@ -154,7 +156,7 @@ static int async_open(URLContext *h, const char *arg, int flags, AVDictionary ** { Context *c = h->priv_data; int ret; - AVIOInterruptCB interrupt_callback = {.callback = async_interrupt_callback, .opaque = h}; + AVIOInterruptCB interrupt_callback = {.callback = async_check_interrupt, .opaque = h}; av_strstart(arg, "async:", &arg); @@ -250,7 +252,7 @@ static int async_read_internal(URLContext *h, void *dest, int size, int read_com while (to_read > 0) { int fifo_size, to_copy; - if (async_interrupt_callback(h)) { + if (async_check_interrupt(h)) { ret = AVERROR_EXIT; break; } @@ -342,7 +344,7 @@ static int64_t async_seek(URLContext *h, int64_t pos, int whence) c->seek_ret = 0; while (1) { - if (async_interrupt_callback(h)) { + if (async_check_interrupt(h)) { ret = AVERROR_EXIT; break; }