From patchwork Mon Jul 3 19:32:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42413 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp4589308pzh; Mon, 3 Jul 2023 12:33:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlH55zUtLzP4tak4n5wAllLotQARUgnRML+QwazEEGSYpMqLleShP4nNHzkgs9sHq30IdF8E X-Received: by 2002:a50:ec8b:0:b0:51d:d1af:df15 with SMTP id e11-20020a50ec8b000000b0051dd1afdf15mr7791954edr.23.1688412825702; Mon, 03 Jul 2023 12:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688412825; cv=none; d=google.com; s=arc-20160816; b=WeOI7vtN7YR3VvJfE1i7HNK7hH5UaMv+/0F03zpSBhUha2Wa77NIjs2daMEJ+r/oTQ bcPOqaT6rYfr2ADGzwo9y7YaJnvy/iEqAxzOCnV6JlIHI+m7I1elAdua8vyqvZG/upE7 W87hhREIE43VcqwBNBMNG9X/P9m94DlBCGleUgra9CCN1mijeC8+iaXnAWSGlbui78hb 00Tzj8i7INqhSZZ+bPWuy1oX6ZxVePLcEVoAA1yuuMS5AAbhZ/b9k32ptOA3NbBAypxS 1mIXSnK6wNRz9HUckH9AOe2KAioBQI1qVJ1ZqqHVgwWKoO7YBF6mD8BzLnNbdnveyaBD ltSg== 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=6INE6icxmY34gAR9hqyQ7VxqrPGe6hL9MO0HWyl88Fc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=0t7E0XwcAY8KITJUl9SF6OS9M1M/kbd2yEswC59MwKCUJeaOy/VrW3NoXZ0xZltMqb A3w2eCt9XJ4xVLqLz5DNL1CYAfCW/45jVYsr6ZyK28c4Hjx6w0S2J77Wv7yyFs4TmTGM te65/VQ6kkAR1R5iieyHb4tYZSC7eXz2gW19NrOUAE6zzRHBjkYUCZCzyh3kU7rs4frG dGZlYGP+sUVlb1wOVE1hzpNGlmkaPuPktTUwLOWqzDeiL9pUb+IQ5XE5WBkyFXKz+dtB PeygRCrGsNaSxRN0aLe3fhxPIYgb2m1jg+C8J1qer+QSZicTZmQeZh1mlge2hcwimK3S UVsw== 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 j13-20020aa7c0cd000000b0051e0d8c614fsi2048395edp.567.2023.07.03.12.33.45; Mon, 03 Jul 2023 12:33:45 -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 1660F68C5B2; Mon, 3 Jul 2023 22:33:04 +0300 (EEST) 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 C7B3C68C5B0 for ; Mon, 3 Jul 2023 22:32:57 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 276AD240591 for ; Mon, 3 Jul 2023 21:32:54 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id mBW2dsbFBh32 for ; Mon, 3 Jul 2023 21:32:53 +0200 (CEST) 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 E22012405B5 for ; Mon, 3 Jul 2023 21:32:51 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A26703A12EC for ; Mon, 3 Jul 2023 21:32:45 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Jul 2023 21:32:24 +0200 Message-Id: <20230703193229.8593-6-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230703193229.8593-1-anton@khirnov.net> References: <20230703193229.8593-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 05/10] lavc: add generic-encode-layer private data 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: 8Gfvzxb/+ofx Move AVCodecInternal.intra_only_flag to it, should should not be visible outside of encode.c. --- libavcodec/avcodec.c | 2 +- libavcodec/avcodec_internal.h | 1 + libavcodec/encode.c | 26 ++++++++++++++++++++++++-- libavcodec/internal.h | 7 ------- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index aef2edce32..8ccc610227 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -152,7 +152,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci = av_codec_is_decoder(codec) ? ff_decode_internal_alloc() : - av_mallocz(sizeof(AVCodecInternal)); + ff_encode_internal_alloc(); if (!avci) { ret = AVERROR(ENOMEM); goto end; diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h index f52f91e07c..9b93ff3d81 100644 --- a/libavcodec/avcodec_internal.h +++ b/libavcodec/avcodec_internal.h @@ -54,5 +54,6 @@ void ff_decode_flush_buffers(struct AVCodecContext *avctx); void ff_encode_flush_buffers(struct AVCodecContext *avctx); struct AVCodecInternal *ff_decode_internal_alloc(void); +struct AVCodecInternal *ff_encode_internal_alloc(void); #endif // AVCODEC_AVCODEC_INTERNAL_H diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 2620810476..6da5d86ea0 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -33,6 +33,22 @@ #include "frame_thread_encoder.h" #include "internal.h" +typedef struct EncodeContext { + AVCodecInternal avci; + + /** + * This is set to AV_PKT_FLAG_KEY for encoders that encode intra-only + * formats (i.e. whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set). + * This is used to set said flag generically for said encoders. + */ + int intra_only_flag; +} EncodeContext; + +static EncodeContext *encode_ctx(AVCodecInternal *avci) +{ + return (EncodeContext*)avci; +} + int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size) { if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) { @@ -372,7 +388,7 @@ static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt } else ret = encode_simple_receive_packet(avctx, avpkt); if (ret >= 0) - avpkt->flags |= avci->intra_only_flag; + avpkt->flags |= encode_ctx(avci)->intra_only_flag; if (ret == AVERROR_EOF) avci->draining_done = 1; @@ -680,6 +696,7 @@ static int encode_preinit_audio(AVCodecContext *avctx) int ff_encode_preinit(AVCodecContext *avctx) { AVCodecInternal *avci = avctx->internal; + EncodeContext *ec = encode_ctx(avci); int ret = 0; if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { @@ -710,7 +727,7 @@ int ff_encode_preinit(AVCodecContext *avctx) avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4; if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) - avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY; + ec->intra_only_flag = AV_PKT_FLAG_KEY; if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_ENCODE) { avci->in_frame = av_frame_alloc(); @@ -795,3 +812,8 @@ void ff_encode_flush_buffers(AVCodecContext *avctx) if (avci->recon_frame) av_frame_unref(avci->recon_frame); } + +AVCodecInternal *ff_encode_internal_alloc(void) +{ + return av_mallocz(sizeof(EncodeContext)); +} diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 0c1f0b82ea..497cd77f23 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -95,13 +95,6 @@ typedef struct AVCodecInternal { uint8_t *byte_buffer; unsigned int byte_buffer_size; - /** - * This is set to AV_PKT_FLAG_KEY for encoders that encode intra-only - * formats (i.e. whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set). - * This is used to set said flag generically for said encoders. - */ - int intra_only_flag; - void *frame_thread_encoder; /**