[FFmpeg-cvslog] avcodec/videotoolboxenc: move pthread_cond_signal after add buffer to the queue

Tian Qi git at videolan.org
Tue Sep 29 04:50:45 EEST 2020


ffmpeg | branch: master | Tian Qi <tianqi at kuaishou.com> | Fri Aug 28 09:13:02 2020 +0800| [9837f5a64322e89f825a99f14c1a0d27b17b183c] | committer: Rick Kern

avcodec/videotoolboxenc: move pthread_cond_signal after add buffer to the queue

In the VT encoding insertion by FFmpeg,
and vtenc_q_push is callback to add the encoded data
to the singly linked list group in VTEncContext,
and consumers are notified to fetch it.
However, because it first informs consumers of pthread_cond_signal,
and then inserts the data into the tail,
there is a multi-thread safety hazard.

Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
Signed-off-by: Rick Kern <kernrj at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9837f5a64322e89f825a99f14c1a0d27b17b183c
---

 libavcodec/videotoolboxenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index a99a224bfc..ec445de7c2 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -340,7 +340,6 @@ static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, ExtraSEI
     info->next = NULL;
 
     pthread_mutex_lock(&vtctx->lock);
-    pthread_cond_signal(&vtctx->cv_sample_sent);
 
     if (!vtctx->q_head) {
         vtctx->q_head = info;
@@ -350,6 +349,7 @@ static void vtenc_q_push(VTEncContext *vtctx, CMSampleBufferRef buffer, ExtraSEI
 
     vtctx->q_tail = info;
 
+    pthread_cond_signal(&vtctx->cv_sample_sent);
     pthread_mutex_unlock(&vtctx->lock);
 }
 



More information about the ffmpeg-cvslog mailing list