From patchwork Tue Feb 28 12:01:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 40544 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp1540844pzb; Tue, 28 Feb 2023 04:02:09 -0800 (PST) X-Google-Smtp-Source: AK7set/QdZVG2khQgOo5x6kidYxBw/S+jm2MKb5CPnU9kPwSIvLDLU9t6OvLCfVUKFDff0Lhcgsm X-Received: by 2002:a17:907:1c98:b0:8e5:2b62:c3ac with SMTP id nb24-20020a1709071c9800b008e52b62c3acmr3071474ejc.77.1677585729481; Tue, 28 Feb 2023 04:02:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677585729; cv=none; d=google.com; s=arc-20160816; b=0dKi9L3tmpZgxL7GBzgrXCSaj/asNMKVWQXFhUsztP5wTaqgFQd7s28kbCJXYr1ZG/ tgGB6IaZKjEuxf9BvTEI44sPjBeCtsy5cebm1kJHu51oXw2oMm8A9LSgTFdYQEyBRz0d s/ffP0/YJW69GMGUEIHkSF7J94imRB+AZDGAUjzQOCWLTLEeVGhgG6dibYGxacKyKpxR EEAEcGGGA+x5ZxM4+yNTZzFMgbpmn2HRSkiFmlBcJooMplmfjsQsWZq9Zx2EYwHU4Js9 0dJ2X/CaysWAYUbVb8Qqq/lFpG5Mnq1UKdaX6iWdiHFdNRX3IlqPvogkuSmuSkDYzEnO TbRQ== 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=k/BMrjdyPdfvhiNck2m9uwaPGsu2K5X6MpfE2tRY834=; b=eC4dT+4a2dx0RzArTWru8j0sCoqT7emJKeuTLgDQLcFnS/5E56IdUYv6y0vzXn3omu gnm7MgRKy1UOUYZh02XxhprM6THx3WpRhBZ1iWKcPgrdPXHadObw+Oi6Wge0sSI1z6e7 5cfImEx6egTD9cOxVp5vgK+rkZgroHaQCjQ+8rsN6mhnDwDLe53Q9Vl6Kb8deTGojcZC TVCZb+HkwbZewzSklntn9RUaqqFkyxtCABzyZEY8tbUPfq9ltiSW9R7IACy3Qcue3Ihm YJS4JHoyAA9mRmaT4Yk5xuf29VasQI+Mdsv7PH+3J/CsEHdYzeQlmWtmYPFwbCBvR1DM 4BqA== 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 ay7-20020a056402202700b004ada70cf9e2si11723571edb.58.2023.02.28.04.02.03; Tue, 28 Feb 2023 04:02:09 -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 D37E668A971; Tue, 28 Feb 2023 14:01:31 +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 12BA868AA0F for ; Tue, 28 Feb 2023 14:01:24 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C2D262404F5 for ; Tue, 28 Feb 2023 13:01:23 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NlAtNN1lBIg3 for ; Tue, 28 Feb 2023 13:01:23 +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 B9D782404F8 for ; Tue, 28 Feb 2023 13:01:20 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 476B23A03E5 for ; Tue, 28 Feb 2023 13:01:14 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Feb 2023 13:01:00 +0100 Message-Id: <20230228120104.2347-4-anton@khirnov.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230228120104.2347-1-anton@khirnov.net> References: <20230228120104.2347-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/8] lavc/libvpxenc: rename hdr10_plus_fifo and related objects 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: Z175SymXGou0 This AVFifo is used to propagate HDR metadata from input frames to output packets, since libvpx does not allow passing through arbitrary user data. It will be extended to pass through other kinds of data in future commits, so give it a more generic name. --- libavcodec/libvpxenc.c | 51 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index abaa8c3513..77921badba 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -66,10 +66,10 @@ struct FrameListData { struct FrameListData *next; }; -typedef struct FrameHDR10Plus { +typedef struct FrameData { int64_t pts; AVBufferRef *hdr10_plus; -} FrameHDR10Plus; +} FrameData; typedef struct VPxEncoderContext { AVClass *class; @@ -130,7 +130,9 @@ typedef struct VPxEncoderContext { int corpus_complexity; int tpl_model; int min_gf_interval; - AVFifo *hdr10_plus_fifo; + + // This FIFO is used to propagate various properties from frames to packets. + AVFifo *fifo; /** * If the driver does not support ROI then warn the first time we * encounter a frame with ROI side data. @@ -327,32 +329,32 @@ static av_cold void free_frame_list(struct FrameListData *list) } } -static av_cold void free_hdr10_plus_fifo(AVFifo **fifo) +static av_cold void fifo_free(AVFifo **fifo) { - FrameHDR10Plus frame_hdr10_plus; - while (av_fifo_read(*fifo, &frame_hdr10_plus, 1) >= 0) - av_buffer_unref(&frame_hdr10_plus.hdr10_plus); + FrameData fd; + while (av_fifo_read(*fifo, &fd, 1) >= 0) + av_buffer_unref(&fd.hdr10_plus); av_fifo_freep2(fifo); } -static int copy_hdr10_plus_to_pkt(AVFifo *fifo, AVPacket *pkt) +static int frame_data_apply(AVFifo *fifo, AVPacket *pkt) { - FrameHDR10Plus frame_hdr10_plus; + FrameData fd; uint8_t *data; - if (!pkt || av_fifo_peek(fifo, &frame_hdr10_plus, 1, 0) < 0) + if (!pkt || av_fifo_peek(fifo, &fd, 1, 0) < 0) return 0; - if (!frame_hdr10_plus.hdr10_plus || frame_hdr10_plus.pts != pkt->pts) + if (!fd.hdr10_plus || fd.pts != pkt->pts) 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); + data = av_packet_new_side_data(pkt, AV_PKT_DATA_DYNAMIC_HDR10_PLUS, fd.hdr10_plus->size); if (!data) { - av_buffer_unref(&frame_hdr10_plus.hdr10_plus); + av_buffer_unref(&fd.hdr10_plus); return AVERROR(ENOMEM); } - memcpy(data, frame_hdr10_plus.hdr10_plus->data, frame_hdr10_plus.hdr10_plus->size); - av_buffer_unref(&frame_hdr10_plus.hdr10_plus); + memcpy(data, fd.hdr10_plus->data, fd.hdr10_plus->size); + av_buffer_unref(&fd.hdr10_plus); return 0; } @@ -447,8 +449,8 @@ static av_cold int vpx_free(AVCodecContext *avctx) av_freep(&avctx->stats_out); free_frame_list(ctx->coded_frame_list); free_frame_list(ctx->alpha_coded_frame_list); - if (ctx->hdr10_plus_fifo) - free_hdr10_plus_fifo(&ctx->hdr10_plus_fifo); + if (ctx->fifo) + fifo_free(&ctx->fifo); return 0; } @@ -919,9 +921,8 @@ static av_cold int vpx_init(AVCodecContext *avctx, // Keep HDR10+ if it has bit depth higher than 8 and // it has PQ trc (SMPTE2084). if (enccfg.g_bit_depth > 8 && avctx->color_trc == AVCOL_TRC_SMPTE2084) { - ctx->hdr10_plus_fifo = av_fifo_alloc2(1, sizeof(FrameHDR10Plus), - AV_FIFO_FLAG_AUTO_GROW); - if (!ctx->hdr10_plus_fifo) + ctx->fifo = av_fifo_alloc2(1, sizeof(FrameData), AV_FIFO_FLAG_AUTO_GROW); + if (!ctx->fifo) return AVERROR(ENOMEM); } } @@ -1284,8 +1285,8 @@ static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, AV_WB64(side_data, 1); memcpy(side_data + 8, alpha_cx_frame->buf, alpha_cx_frame->sz); } - if (ctx->hdr10_plus_fifo) { - int err = copy_hdr10_plus_to_pkt(ctx->hdr10_plus_fifo, pkt); + if (ctx->fifo) { + int err = frame_data_apply(ctx->fifo, pkt); if (err < 0) return err; } @@ -1702,18 +1703,18 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, } } - if (ctx->hdr10_plus_fifo) { + if (ctx->fifo) { AVFrameSideData *hdr10_plus_metadata; // Add HDR10+ metadata to queue. hdr10_plus_metadata = av_frame_get_side_data(frame, AV_FRAME_DATA_DYNAMIC_HDR_PLUS); if (hdr10_plus_metadata) { int err; - struct FrameHDR10Plus data; + FrameData data; data.pts = frame->pts; data.hdr10_plus = av_buffer_ref(hdr10_plus_metadata->buf); if (!data.hdr10_plus) return AVERROR(ENOMEM); - err = av_fifo_write(ctx->hdr10_plus_fifo, &data, 1); + err = av_fifo_write(ctx->fifo, &data, 1); if (err < 0) { av_buffer_unref(&data.hdr10_plus); return err;