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

zhilizhao quinkblack at foxmail.com
Thu Aug 27 18:00:44 EEST 2020



> On Aug 28, 2020, at 9:13 AM, Steven Liu <lq at chinaffmpeg.org> wrote:
> 
> From: Tian Qi <tianqi at kuaishou.com>
> 
> 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.

The patch makes the code more logical, although it’s not a real issue. So LGTM.

> 
> Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
> ---
> libavcodec/videotoolboxenc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index e89cfaeed8..62ed86fc04 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -338,7 +338,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;
> @@ -348,6 +347,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);
> }
> 
> -- 
> 2.25.0
> 
> 
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-devel mailing list