From patchwork Sat Nov 4 07:56:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 44508 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3aa6:b0:181:818d:5e7f with SMTP id d38csp336316pzh; Sat, 4 Nov 2023 02:22:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSzLfihLnaMI+lQatNa/+WqagSd/bXaqVjipTcVw010WVddDgORTI9s8IRbwxCB+shY/Bx X-Received: by 2002:aa7:d54b:0:b0:53d:d9d1:7029 with SMTP id u11-20020aa7d54b000000b0053dd9d17029mr18015438edr.15.1699089778066; Sat, 04 Nov 2023 02:22:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699089778; cv=none; d=google.com; s=arc-20160816; b=tshHta17W0GvPHs7lHYFQXuhecIBFBD2tub/Jn+ZKUBpgiYk9NGz7fvsFa9RqleTeo HRPNxARPf0Ap7EiytMVc2Uv4aYl2y+ZjcuVKoqJUFIw1pLsamvfjqUX9zpSAWMiDe0qy 6uJooSkGaK+Lza2LIIfoR5x5hQHBpICyglXU8b8WPVuByL9qqUm2pR04pPuLwzK3dYzw PpiFIeFqYsnc2qPMQ0MAzG1IDK7dmn7jIzDsyqQR2v50X+ZPras/gWockU76LrGH8wx5 VwWp5dPuYZcm25JROx4Ijb0cSE8u9ktmFTB/atVYQZvg75LMEpJNJawNOVPXWpsVB74J F6XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=9cJju95HXR/lMB65eG2nER4RImk42U3A7pAKOlCTPE4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=AKNui3qPTLKpaIPzBVOwcukaxdoI0yOZJg/EnGq8mxAUJVGKfZEy6zEiPERP3E4t1C 3mg0PNcwu2kwTjXLe7ZJE9Fh7CXpr9Y9sMR8RpP70RdMZ1YyreGHusLbdskbtvpwwoMd qfjru551n5ulj5wzZzW+wmbBNizePZZjBgzLUQ+a6PIcBe/5IA8DnCSvRsJVjlwzr//r B0gFLY/W+g0aFJZOkjpkT23sekafpggE8Z4As0XhgNSFTxRbCZP18pKpliQNXBzuiwSw jnuB6IXDfAj7HPGV1PnEsvtkzJeBz080AeSF4vtLRQ8hfiZDgoykiXcj3brtZWR4JeAt 6chQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t8-20020aa7d4c8000000b005406db37c82si1955270edr.681.2023.11.04.02.22.57; Sat, 04 Nov 2023 02:22:58 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2824B68CE46; Sat, 4 Nov 2023 11:22:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 32D4F68CE46 for ; Sat, 4 Nov 2023 11:21:55 +0200 (EET) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 9D0381114 for ; Sat, 4 Nov 2023 10:21:50 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id YSgdwqzhQJXa for ; Sat, 4 Nov 2023 10:21:50 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 9B56E1049 for ; Sat, 4 Nov 2023 10:21:47 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 46E4A3A0DF8 for ; Sat, 4 Nov 2023 10:21:40 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Nov 2023 08:56:14 +0100 Message-ID: <20231104092125.10213-6-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231104092125.10213-1-anton@khirnov.net> References: <20231104092125.10213-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/24] fftools/thread_queue: do not return elements for receive-finished streams X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 72Wwq0MVmxju It does not cause any issues in current callers, but still should not happen. --- 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;