From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id F400940D0D for ; Mon, 28 Aug 2023 12:38:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD09468C6E2; Mon, 28 Aug 2023 15:37:01 +0300 (EEST) Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 334AD68C6C1 for ; Mon, 28 Aug 2023 15:36:57 +0300 (EEST) Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-1a28de15c8aso2225468fac.2 for ; Mon, 28 Aug 2023 05:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693226216; x=1693831016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zvoy2kFRimyBAyYIs1FZTauKctmS+N4Tcn14MxpdBm8=; b=iQhw5oB6lWfHotQi6ma3UwuaKTHJ9su4oHo78r6DsTe/c7s/C3ueNkJbfvMZzWZVUS 8f5qB/xZtxGdezk3FQyFL2O4XTRhiwo9gTAR9su2gZyV/oVzG+zbIsGNdxBy/RWECkS7 gI+vLAO8YGZRxf2RqwBLBRRoaWh/Vupo582ne3QhmvS5W2jvuDEwQyficgs+QEU3L940 UNP3EcQeHtfcGkYMWd2k1UrF3AJUQ//5f/3HzWUd4a2mi5Q/r+xYtn0dfmFYYigpOo4F 75blyJjWBwOQO8II01QDe4c18XcjCgoi+zuUqyjiYdrrNgMui6TnzQzqdKWo71XqS/hu ajyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693226216; x=1693831016; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zvoy2kFRimyBAyYIs1FZTauKctmS+N4Tcn14MxpdBm8=; b=RP7ZLf8yJXmREIrN4xZzIeYd0muT5r79PiicliTPLF+/AnZjM2DnLLg69OWb2qT7Z5 5T0fp2eoYhGCAgDtQYrfuzDrRffIZV0vZCMW98qxSOsHck4/CZfUUYACjDricirCwGJk //T1uUZPuN5CqJpSDi44XpMpgJoGeOxFMI8pKWby+0JNbAUoyEMQd0FXBHCELkMnCUKp x20DdPfenIQ1b2/auz39IYM32RzsAhBT4EQmFVwVvd4H0b9qTrmWhxDcG+9PPovsyg+V 4VJERF5dINziZDm14NTOIisM6VTglDlEHdlPYc7pyx+yBLuSBr3jN1WMD5NZ9Mk73x78 VJDg== X-Gm-Message-State: AOJu0YwU06amc4UIitUsse0c6MMn5aKXtPf5nduXiKKyVVoO3RzuQBBT btFSayPaAa8m4Iihk2XJ4dS4hwHBQTU= X-Google-Smtp-Source: AGHT+IGnAASVHviz9P33Kx+MQHQBVXvEtdZgV3FnC2Rv4BTPozvRq1eYMJHF9FDK4yvLo1wt/3N/fw== X-Received: by 2002:a05:6870:fba9:b0:1be:cc86:8a40 with SMTP id kv41-20020a056870fba900b001becc868a40mr12529203oab.18.1693226215683; Mon, 28 Aug 2023 05:36:55 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id b15-20020a056830104f00b006b9a98b9659sm3404615otp.19.2023.08.28.05.36.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Aug 2023 05:36:55 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 28 Aug 2023 09:35:03 -0300 Message-ID: <20230828123617.57535-12-jamrial@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230828123617.57535-1-jamrial@gmail.com> References: <20230828123617.57535-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/12] avcodec/avcodec: deprecate coded_side_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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: In favor of AVCodecContext.packet_sd Also reflect the fact the field has been used during decoding for some time now. Signed-off-by: James Almer --- libavcodec/avcodec.c | 28 ++++++++++++++++++++++++++++ libavcodec/avcodec.h | 7 ++++--- libavcodec/decode.c | 31 +++++++++++++++++++++++++++++++ libavcodec/decode.h | 5 +++++ libavcodec/encode.c | 25 +++++++++++++++++++++++++ libavcodec/encode.h | 5 +++++ libavcodec/internal.h | 5 ----- libavcodec/libaomenc.c | 2 +- libavcodec/libopenh264enc.c | 2 +- libavcodec/libsvtav1.c | 2 +- libavcodec/libvpxenc.c | 2 +- libavcodec/libx264.c | 2 +- libavcodec/libx265.c | 2 +- libavcodec/mpeg12dec.c | 2 +- libavcodec/mpegvideo_enc.c | 2 +- libavcodec/nvenc.c | 2 +- libavcodec/qsvenc.c | 2 +- libavcodec/utils.c | 31 ------------------------------- libavcodec/version_major.h | 1 + 19 files changed, 109 insertions(+), 49 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index c811d1f7c4..374831fa07 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -341,6 +341,34 @@ FF_ENABLE_DEPRECATION_WARNINGS avci->needs_close = 1; } +#if FF_API_CODED_SIDE_DATA + if (av_codec_is_encoder(avctx->codec)) { + const AVPacketSideData *sd = + av_packet_side_data_set_get(&avctx->packet_side_data, AV_PKT_DATA_CPB_PROPERTIES); + if (sd) { + uint8_t *data; + AVPacketSideData *tmp = av_realloc_array(avctx->coded_side_data, + avctx->nb_coded_side_data + 1U, + sizeof(*tmp)); + if (!tmp) { + ret = AVERROR(ENOMEM); + goto free_and_end; + } + avctx->coded_side_data = tmp; + + data = av_memdup(sd->data, sd->size); + if (!data) { + ret = AVERROR(ENOMEM); + goto free_and_end; + } + + avctx->coded_side_data[avctx->nb_coded_side_data].data = data; + avctx->coded_side_data[avctx->nb_coded_side_data].size = sd->size; + avctx->coded_side_data[avctx->nb_coded_side_data++].type = AV_PKT_DATA_CPB_PROPERTIES; + } + } +#endif + ret=0; if (av_codec_is_decoder(avctx->codec)) { diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index dda8a2412b..6ffb6b78d8 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1893,8 +1893,9 @@ typedef struct AVCodecContext { /** * Additional data associated with the entire coded stream. * - * - decoding: unused - * - encoding: may be set by libavcodec after avcodec_open2(). + * - decoding: set by libavcodec + * - encoding: the use of this field for encoding is deprecated. + * Use packet_side_data instead. */ AVPacketSideData *coded_side_data; int nb_coded_side_data; @@ -2105,7 +2106,7 @@ typedef struct AVCodecContext { * Additional data associated with the entire stream. * * - decoding: set by user - * - encoding: unused + * - encoding: may be set by libavcodec after avcodec_open2(). */ AVPacketSideDataSet packet_side_data; } AVCodecContext; diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 4b8c1bc74d..7afec14c4d 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1878,3 +1878,34 @@ AVCodecInternal *ff_decode_internal_alloc(void) { return av_mallocz(sizeof(DecodeContext)); } + +AVCPBProperties *ff_decode_add_cpb_side_data(AVCodecContext *avctx) +{ + AVPacketSideData *tmp; + AVCPBProperties *props; + size_t size; + int i; + + for (i = 0; i < avctx->nb_coded_side_data; i++) + if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES) + return (AVCPBProperties *)avctx->coded_side_data[i].data; + + props = av_cpb_properties_alloc(&size); + if (!props) + return NULL; + + tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp)); + if (!tmp) { + av_freep(&props); + return NULL; + } + + avctx->coded_side_data = tmp; + avctx->nb_coded_side_data++; + + avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES; + avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props; + avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size; + + return props; +} diff --git a/libavcodec/decode.h b/libavcodec/decode.h index 52e5aafc34..cb07ab318b 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -153,4 +153,9 @@ int ff_side_data_update_matrix_encoding(AVFrame *frame, int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private, AVBufferRef **hwaccel_priv_buf); +/** + * Add a CPB properties side data to an decoding context. + */ +AVCPBProperties *ff_decode_add_cpb_side_data(AVCodecContext *avctx); + #endif /* AVCODEC_DECODE_H */ diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 32cc903b1f..854cfd59d2 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -864,3 +864,28 @@ AVCodecInternal *ff_encode_internal_alloc(void) { return av_mallocz(sizeof(EncodeContext)); } + +AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx) +{ + AVPacketSideData *sd; + AVCPBProperties *props; + size_t size; + int ret; + + sd = av_packet_side_data_set_get(&avctx->packet_side_data, AV_PKT_DATA_CPB_PROPERTIES); + if (sd) + return (AVCPBProperties *)sd->data; + + props = av_cpb_properties_alloc(&size); + if (!props) + return NULL; + + ret = av_packet_side_data_set_add(&avctx->packet_side_data, AV_PKT_DATA_CPB_PROPERTIES, + (uint8_t *)props, size); + if (ret < 0) { + av_free(props); + return NULL; + } + + return props; +} diff --git a/libavcodec/encode.h b/libavcodec/encode.h index dfaab7c976..e019cd7702 100644 --- a/libavcodec/encode.h +++ b/libavcodec/encode.h @@ -73,6 +73,11 @@ int ff_encode_reordered_opaque(AVCodecContext *avctx, int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, AVFrame *frame, int *got_packet); +/** + * Add a CPB properties side data to an encoding context. + */ +AVCPBProperties *ff_encode_add_cpb_side_data(AVCodecContext *avctx); + /** * Rescale from sample rate to AVCodecContext.time_base. */ diff --git a/libavcodec/internal.h b/libavcodec/internal.h index a67cf713ca..83e0bc3fb2 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -180,11 +180,6 @@ int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx); int avpriv_codec_get_cap_skip_frame_fill_param(const AVCodec *codec); -/** - * Add a CPB properties side data to an encoding context. - */ -AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx); - /** * Check AVFrame for S12M timecode side data and allocate and fill TC SEI message with timecode info * diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index f29cb0784a..53a1159b75 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -1018,7 +1018,7 @@ static av_cold int aom_init(AVCodecContext *avctx, if (codec_caps & AOM_CODEC_CAP_HIGHBITDEPTH) ctx->rawimg.bit_depth = enccfg.g_bit_depth; - cpb_props = ff_add_cpb_side_data(avctx); + cpb_props = ff_encode_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c index 5b59af6f94..433accba22 100644 --- a/libavcodec/libopenh264enc.c +++ b/libavcodec/libopenh264enc.c @@ -353,7 +353,7 @@ FF_ENABLE_DEPRECATION_WARNINGS memcpy(avctx->extradata, fbi.sLayerInfo[0].pBsBuf, size); } - props = ff_add_cpb_side_data(avctx); + props = ff_encode_add_cpb_side_data(avctx); if (!props) return AVERROR(ENOMEM); props->max_bitrate = param.iMaxBitrate; diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index f2b73361d8..a8b3b62b96 100644 --- a/libavcodec/libsvtav1.c +++ b/libavcodec/libsvtav1.c @@ -325,7 +325,7 @@ FF_ENABLE_DEPRECATION_WARNINGS FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL; if (avctx->bit_rate || avctx->rc_max_rate || avctx->rc_buffer_size) { - AVCPBProperties *cpb_props = ff_add_cpb_side_data(avctx); + AVCPBProperties *cpb_props = ff_encode_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 7a545527a9..0f6f4e785c 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -1273,7 +1273,7 @@ static av_cold int vpx_init(AVCodecContext *avctx, ctx->rawimg.bit_depth = enccfg.g_bit_depth; #endif - cpb_props = ff_add_cpb_side_data(avctx); + cpb_props = ff_encode_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 1a7dc7bdd5..5c1dc5f8b8 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -1231,7 +1231,7 @@ FF_ENABLE_DEPRECATION_WARNINGS avctx->extradata_size = p - avctx->extradata; } - cpb_props = ff_add_cpb_side_data(avctx); + cpb_props = ff_encode_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); cpb_props->buffer_size = x4->params.rc.i_vbv_buffer_size * 1000; diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 873b3021ee..447e6da25f 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -395,7 +395,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ctx->params->rc.vbvBufferSize = avctx->rc_buffer_size / 1000; ctx->params->rc.vbvMaxBitrate = avctx->rc_max_rate / 1000; - cpb_props = ff_add_cpb_side_data(avctx); + cpb_props = ff_encode_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); cpb_props->buffer_size = ctx->params->rc.vbvBufferSize * 1000; diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index e645b8e24a..4c9ed76964 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1403,7 +1403,7 @@ static void mpeg_decode_sequence_extension(Mpeg1Context *s1) ff_dlog(s->avctx, "sequence extension\n"); s->codec_id = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO; - if (cpb_props = ff_add_cpb_side_data(s->avctx)) { + if (cpb_props = ff_decode_add_cpb_side_data(s->avctx)) { cpb_props->buffer_size = s1->rc_buffer_size; if (s->bit_rate != 0x3FFFF*400) cpb_props->max_bitrate = s->bit_rate; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 64e66ae958..9b3bf0bda0 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -972,7 +972,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) } } - cpb_props = ff_add_cpb_side_data(avctx); + cpb_props = ff_encode_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); cpb_props->max_bitrate = avctx->rc_max_rate; diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 1e83ea9734..4249ff7188 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1666,7 +1666,7 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ctx->encode_config.rcParams.averageBitRate > 0) avctx->bit_rate = ctx->encode_config.rcParams.averageBitRate; - cpb_props = ff_add_cpb_side_data(avctx); + cpb_props = ff_encode_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); cpb_props->max_bitrate = ctx->encode_config.rcParams.maxBitRate; diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index b3b7475b0f..ac7364f61f 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -1504,7 +1504,7 @@ static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) } memset(avctx->extradata + avctx->extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); - cpb_props = ff_add_cpb_side_data(avctx); + cpb_props = ff_encode_add_cpb_side_data(avctx); if (!cpb_props) return AVERROR(ENOMEM); cpb_props->max_bitrate = avctx->rc_max_rate; diff --git a/libavcodec/utils.c b/libavcodec/utils.c index bd4131db62..d54e050848 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1018,37 +1018,6 @@ AVCPBProperties *av_cpb_properties_alloc(size_t *size) return props; } -AVCPBProperties *ff_add_cpb_side_data(AVCodecContext *avctx) -{ - AVPacketSideData *tmp; - AVCPBProperties *props; - size_t size; - int i; - - for (i = 0; i < avctx->nb_coded_side_data; i++) - if (avctx->coded_side_data[i].type == AV_PKT_DATA_CPB_PROPERTIES) - return (AVCPBProperties *)avctx->coded_side_data[i].data; - - props = av_cpb_properties_alloc(&size); - if (!props) - return NULL; - - tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp)); - if (!tmp) { - av_freep(&props); - return NULL; - } - - avctx->coded_side_data = tmp; - avctx->nb_coded_side_data++; - - avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_CPB_PROPERTIES; - avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props; - avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size; - - return props; -} - static unsigned bcd2uint(uint8_t bcd) { unsigned low = bcd & 0xf; diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h index 95c5aec0c5..7b01300c4a 100644 --- a/libavcodec/version_major.h +++ b/libavcodec/version_major.h @@ -49,6 +49,7 @@ #define FF_API_SUBFRAMES (LIBAVCODEC_VERSION_MAJOR < 61) #define FF_API_TICKS_PER_FRAME (LIBAVCODEC_VERSION_MAJOR < 61) #define FF_API_DROPCHANGED (LIBAVCODEC_VERSION_MAJOR < 61) +#define FF_API_CODED_SIDE_DATA (LIBAVCODEC_VERSION_MAJOR < 61) // reminder to remove CrystalHD decoders on next major bump #define FF_CODEC_CRYSTAL_HD (LIBAVCODEC_VERSION_MAJOR < 61) -- 2.41.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".