[FFmpeg-devel] [PATCH] udp: do not wait for data from the receiving thread.
Nicolas George
nicolas.george at normalesup.org
Wed Mar 14 21:21:19 CET 2012
Lowest-level read protocols are supposed to be always
non-blocking: blocking, if requested, is done by
retry_transfer_wrapper, which also handles interrupting.
Fixes interrupting UDP reads.
Bug reported by Andrey Utkin.
Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
libavformat/udp.c | 18 +-----------------
1 files changed, 1 insertions(+), 17 deletions(-)
As a side note, stores to s->exit_thread and s->circular_buffer_error are
not protected by a mutex: theoretically that is a bug.
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 17bf434..835bc1a 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -71,7 +71,6 @@ typedef struct {
#if HAVE_PTHREADS
pthread_t circular_buffer_thread;
pthread_mutex_t mutex;
- pthread_cond_t cond;
int thread_started;
volatile int exit_thread;
#endif
@@ -385,14 +384,10 @@ static void *circular_buffer_task( void *_URLContext)
}
pthread_mutex_lock(&s->mutex);
av_fifo_generic_write(s->fifo, s->tmp, len+4, NULL);
- pthread_cond_signal(&s->cond);
pthread_mutex_unlock(&s->mutex);
}
end:
- pthread_mutex_lock(&s->mutex);
- pthread_cond_signal(&s->cond);
- pthread_mutex_unlock(&s->mutex);
return NULL;
}
#endif
@@ -558,11 +553,6 @@ static int udp_open(URLContext *h, const char *uri, int flags)
av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret));
goto fail;
}
- ret = pthread_cond_init(&s->cond, NULL);
- if (ret != 0) {
- av_log(h, AV_LOG_ERROR, "pthread_cond_init failed : %s\n", strerror(ret));
- goto cond_fail;
- }
ret = pthread_create(&s->circular_buffer_thread, NULL, circular_buffer_task, h);
if (ret != 0) {
av_log(h, AV_LOG_ERROR, "pthread_create failed : %s\n", strerror(ret));
@@ -575,8 +565,6 @@ static int udp_open(URLContext *h, const char *uri, int flags)
return 0;
#if HAVE_PTHREADS
thread_fail:
- pthread_cond_destroy(&s->cond);
- cond_fail:
pthread_mutex_destroy(&s->mutex);
#endif
fail:
@@ -614,13 +602,10 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
} else if(s->circular_buffer_error){
pthread_mutex_unlock(&s->mutex);
return s->circular_buffer_error;
- } else if(h->flags & AVIO_FLAG_NONBLOCK) {
+ } else {
pthread_mutex_unlock(&s->mutex);
return AVERROR(EAGAIN);
}
- else {
- pthread_cond_wait(&s->cond, &s->mutex);
- }
} while( 1);
}
#endif
@@ -674,7 +659,6 @@ static int udp_close(URLContext *h)
}
pthread_mutex_destroy(&s->mutex);
- pthread_cond_destroy(&s->cond);
#endif
return 0;
}
--
1.7.9.1
More information about the ffmpeg-devel
mailing list