]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/videotoolboxenc: move pthread_cond_signal after add buffer to the queue
authorTian Qi <tianqi@kuaishou.com>
Fri, 28 Aug 2020 01:13:02 +0000 (09:13 +0800)
committerRick Kern <kernrj@gmail.com>
Tue, 29 Sep 2020 01:46:40 +0000 (21:46 -0400)
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@chinaffmpeg.org>
Signed-off-by: Rick Kern <kernrj@gmail.com>
libavcodec/videotoolboxenc.c

index a99a224bfc2ad60cf2a798ffac2eaf09be5269a0..ec445de7c2c7cb1caf123d115bbdffc15c13da17 100644 (file)
@@ -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);
 }