From patchwork Tue Jan 11 20:45:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 33243 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp4048356iog; Tue, 11 Jan 2022 12:49:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzIlTEK1Da/eSPsTi9weK0e5ELS9gGpXLbo1eQoNdLPv72TPfaZ4ear85oKPwwfrr9ebJl1 X-Received: by 2002:a17:907:9810:: with SMTP id ji16mr2722870ejc.202.1641934141909; Tue, 11 Jan 2022 12:49:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641934141; cv=none; d=google.com; s=arc-20160816; b=iLU6y14xhL7BYGSolz+YW22QMB2g+8GHULwpjQtgPxuNwlhHli3PYJipt8cpWMO024 q9qeM+8dicaLqQhEvLqXa7p4MQSzbgdtDwgQKTMUl5Mz8bFyOuAhhYeBlCyhXLS3+CMm LTJnDCyuMrqOgufZ0tzygSlwxw916UVADp8kTRV3a98+z4ebn6cL5EzFI5nSPmFefc7E 3x4xoNyq7511zZe8p4N9ZnJ66dtvUJ3tMHCRyAToFGXg54Mg9OQros0iW1pYe03Y5Y32 oYjEmFt0JGY43rU26FR7zcvrbrWQfdefMQt6Xt24GySvsYvVz1qtssERdrmaupjimtiB 5lWQ== 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=VfygAAls869d9n6nTRFJPeYqm/UJu7lXhXpWM9iae58=; b=Kovv29D0cXfgdfPYhox2xpq2d+cWAirpsx+PqbdWY+55FPjn7HhC5qMLtkHuI2Fvll 1gnFWiPME5vtWELTzBn/Jt0QhigWbsPRfdrIkDGlEh0/3V6XcacHCEskr4h+sT9yPkcc ZUofBUesYzcyVSd8sE4ROlLiRPrac7XYuw+BPIfOgparBBrmMMed8stBRgh92DE0i/ud b1gT6VJTUI53iYy1pD/Y2t6uOZ/Enyl7JfIbeuw/dCuKfveYyjn7xZgrNCGhb6tN/kSr un00aCu01+0nZfjgIFqXdnS2iyxX97Guf/zFmczV7r7gIHpXTvB0frBagjisYwVd2X8X 6LeA== 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 p14si5605884edy.524.2022.01.11.12.49.01; Tue, 11 Jan 2022 12:49:01 -0800 (PST) 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 F2ED868AF86; Tue, 11 Jan 2022 22:47:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A24868AEAF for ; Tue, 11 Jan 2022 22:47:34 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 77BB52404FE for ; Tue, 11 Jan 2022 21:47:33 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id g-NVOgpIH7Jg for ; Tue, 11 Jan 2022 21:47:32 +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 mail0.khirnov.net (Postfix) with ESMTPS id 3B164240593 for ; Tue, 11 Jan 2022 21:47:26 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 2F1B03A0BC7; Tue, 11 Jan 2022 21:47:25 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 21:45:52 +0100 Message-Id: <20220111204610.14262-17-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220111204610.14262-1-anton@khirnov.net> References: <20220111204610.14262-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/35] lavc/libvpxenc: switch to the new FIFO API 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: lU6R1uDEIS/C --- libavcodec/libvpxenc.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 10e5a22fa9..55f587c490 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -324,20 +324,11 @@ static av_cold void free_frame_list(struct FrameListData *list) } } -static av_cold int add_hdr10_plus(AVFifoBuffer *fifo, struct FrameHDR10Plus *data) -{ - int err = av_fifo_grow(fifo, sizeof(*data)); - if (err < 0) - return err; - av_fifo_generic_write(fifo, data, sizeof(*data), NULL); - return 0; -} - static av_cold void free_hdr10_plus_fifo(AVFifoBuffer **fifo) { FrameHDR10Plus frame_hdr10_plus; - while (av_fifo_size(*fifo) >= sizeof(frame_hdr10_plus)) { - av_fifo_generic_read(*fifo, &frame_hdr10_plus, sizeof(frame_hdr10_plus), NULL); + while (av_fifo_can_read(*fifo)) { + av_fifo_read(*fifo, &frame_hdr10_plus, 1); av_buffer_unref(&frame_hdr10_plus.hdr10_plus); } av_fifo_freep(fifo); @@ -347,16 +338,12 @@ static int copy_hdr10_plus_to_pkt(AVFifoBuffer *fifo, AVPacket *pkt) { FrameHDR10Plus frame_hdr10_plus; uint8_t *data; - if (!pkt) - return 0; - if (av_fifo_size(fifo) < sizeof(frame_hdr10_plus)) + if (!pkt || !av_fifo_can_read(fifo)) return 0; - av_fifo_generic_peek(fifo, &frame_hdr10_plus, sizeof(frame_hdr10_plus), NULL); + av_fifo_peek(fifo, &frame_hdr10_plus, 1, 0); if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts) return 0; - av_fifo_generic_read(fifo, &frame_hdr10_plus, sizeof(frame_hdr10_plus), NULL); - if (!frame_hdr10_plus.hdr10_plus) - return 0; + av_fifo_drain2(fifo, 1); data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, frame_hdr10_plus.hdr10_plus->size); if (!data) { @@ -933,7 +920,8 @@ static av_cold int vpx_init(AVCodecContext *avctx, // it has PQ trc (SMPTE2084). if (enccfg.g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) { ctx->discard_hdr10_plus = 0; - ctx->hdr10_plus_fifo = av_fifo_alloc(sizeof(FrameHDR10Plus)); + ctx->hdr10_plus_fifo = av_fifo_alloc2(1, sizeof(FrameHDR10Plus), + AV_FIFO_FLAG_AUTO_GROW); if (!ctx->hdr10_plus_fifo) return AVERROR(ENOMEM); } @@ -1727,7 +1715,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, data.hdr10_plus = av_buffer_ref(hdr10_plus_metadata->buf); if (!data.hdr10_plus) return AVERROR(ENOMEM); - err = add_hdr10_plus(ctx->hdr10_plus_fifo, &data); + err = av_fifo_write(ctx->hdr10_plus_fifo, &data, 1); if (err < 0) { av_buffer_unref(&data.hdr10_plus); return err;