Commit c0a4af40 authored by Zhang Rui's avatar Zhang Rui Committed by Michael Niedermayer

avformat/async: move more code into locked area in background thread

Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent dee551bb
...@@ -95,15 +95,15 @@ static void *async_buffer_task(void *arg) ...@@ -95,15 +95,15 @@ static void *async_buffer_task(void *arg)
while (1) { while (1) {
int fifo_space, to_copy; int fifo_space, to_copy;
pthread_mutex_lock(&c->mutex);
if (async_check_interrupt(h)) { if (async_check_interrupt(h)) {
c->io_eof_reached = 1; c->io_eof_reached = 1;
c->io_error = AVERROR_EXIT; c->io_error = AVERROR_EXIT;
pthread_mutex_unlock(&c->mutex);
break; break;
} }
if (c->seek_request) { if (c->seek_request) {
pthread_mutex_lock(&c->mutex);
ret = ffurl_seek(c->inner, c->seek_pos, c->seek_whence); ret = ffurl_seek(c->inner, c->seek_pos, c->seek_whence);
if (ret < 0) { if (ret < 0) {
c->io_eof_reached = 1; c->io_eof_reached = 1;
...@@ -126,15 +126,17 @@ static void *async_buffer_task(void *arg) ...@@ -126,15 +126,17 @@ static void *async_buffer_task(void *arg)
fifo_space = av_fifo_space(fifo); fifo_space = av_fifo_space(fifo);
if (c->io_eof_reached || fifo_space <= 0) { if (c->io_eof_reached || fifo_space <= 0) {
pthread_mutex_lock(&c->mutex);
pthread_cond_signal(&c->cond_wakeup_main); pthread_cond_signal(&c->cond_wakeup_main);
pthread_cond_wait(&c->cond_wakeup_background, &c->mutex); pthread_cond_wait(&c->cond_wakeup_background, &c->mutex);
pthread_mutex_unlock(&c->mutex); pthread_mutex_unlock(&c->mutex);
continue; continue;
} }
pthread_mutex_unlock(&c->mutex);
to_copy = FFMIN(4096, fifo_space); to_copy = FFMIN(4096, fifo_space);
ret = av_fifo_generic_write(fifo, c->inner, to_copy, (void *)ffurl_read); ret = av_fifo_generic_write(fifo, c->inner, to_copy, (void *)ffurl_read);
pthread_mutex_lock(&c->mutex);
if (ret <= 0) { if (ret <= 0) {
c->io_eof_reached = 1; c->io_eof_reached = 1;
if (ret < 0) { if (ret < 0) {
...@@ -142,7 +144,6 @@ static void *async_buffer_task(void *arg) ...@@ -142,7 +144,6 @@ static void *async_buffer_task(void *arg)
} }
} }
pthread_mutex_lock(&c->mutex);
pthread_cond_signal(&c->cond_wakeup_main); pthread_cond_signal(&c->cond_wakeup_main);
pthread_mutex_unlock(&c->mutex); pthread_mutex_unlock(&c->mutex);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment