[FFmpeg-cvslog] fftools/thread_queue: do not return elements for receive-finished streams
Anton Khirnov
git at videolan.org
Tue Nov 14 19:19:56 EET 2023
ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Oct 18 11:45:06 2023 +0200| [4f7b91a6980d4d593ce0bf5ae398996f878a18e2] | committer: Anton Khirnov
fftools/thread_queue: do not return elements for receive-finished streams
It does not cause any issues in current callers, but still should not
happen.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4f7b91a6980d4d593ce0bf5ae398996f878a18e2
---
fftools/thread_queue.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/fftools/thread_queue.c b/fftools/thread_queue.c
index a1ab4ce92e..feac6a7748 100644
--- a/fftools/thread_queue.c
+++ b/fftools/thread_queue.c
@@ -164,7 +164,12 @@ static int receive_locked(ThreadQueue *tq, int *stream_idx,
FifoElem elem;
unsigned int nb_finished = 0;
- if (av_fifo_read(tq->fifo, &elem, 1) >= 0) {
+ while (av_fifo_read(tq->fifo, &elem, 1) >= 0) {
+ if (tq->finished[elem.stream_idx] & FINISHED_RECV) {
+ objpool_release(tq->obj_pool, &elem.obj);
+ continue;
+ }
+
tq->obj_move(data, elem.obj);
objpool_release(tq->obj_pool, &elem.obj);
*stream_idx = elem.stream_idx;
@@ -197,7 +202,14 @@ int tq_receive(ThreadQueue *tq, int *stream_idx, void *data)
pthread_mutex_lock(&tq->lock);
while (1) {
+ size_t can_read = av_fifo_can_read(tq->fifo);
+
ret = receive_locked(tq, stream_idx, data);
+
+ // signal other threads if the fifo state changed
+ if (can_read != av_fifo_can_read(tq->fifo))
+ pthread_cond_broadcast(&tq->cond);
+
if (ret == AVERROR(EAGAIN)) {
pthread_cond_wait(&tq->cond, &tq->lock);
continue;
@@ -206,9 +218,6 @@ int tq_receive(ThreadQueue *tq, int *stream_idx, void *data)
break;
}
- if (ret == 0)
- pthread_cond_broadcast(&tq->cond);
-
pthread_mutex_unlock(&tq->lock);
return ret;
More information about the ffmpeg-cvslog
mailing list