From patchwork Fri Aug 28 01:13:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 21958 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2C9144499CB for ; Fri, 28 Aug 2020 04:13:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0997868921A; Fri, 28 Aug 2020 04:13:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E25ED6881BF for ; Fri, 28 Aug 2020 04:13:11 +0300 (EEST) X-QQ-mid: bizesmtp26t1598577184tbayo759 Received: from localhost (unknown [103.107.216.230]) by esmtp10.qq.com (ESMTP) with id ; Fri, 28 Aug 2020 09:13:04 +0800 (CST) X-QQ-SSF: 01100000002000Z0Z000B00A0000000 X-QQ-FEAT: CtF7S1VT99oCrhKo+eU7BbbNGRjrYHOCnUAMtiFQztE6Dnd50/+zgVchkfPzL bu08IpALpxOuZjwUi3ywZbKQNKNCvjh4LwoNKuwHFAMyPOfqny3LjBWJm8r7dSWyH1RQNnD tHGYRU5xbKLv57gAUf3QjM+A3aCFF8/jfnwnBvluKMCW9NTlXw4jvMdZnwW5vBrX2Nd+FEO XeNH2lIXI4A7ZHwqH7QYtDVgv9Bc0ri9TqnNJA9vrNDTu+TQv+WLM39LMqsFXCiRDP34Gso t/hKhcvgJVrVng5OcnrhEaOcGxyDvN6CO7WsoKcrIf7VT6 X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Fri, 28 Aug 2020 09:13:02 +0800 Message-Id: <20200828011302.78140-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign6 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: move pthread_cond_signal after add buffer to the queue X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu , Tian Qi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Tian Qi 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 --- 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); }