From patchwork Mon Jan 25 12:40:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 25159 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 7F870449F60 for ; Mon, 25 Jan 2021 14:40:47 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 540ED6882A6; Mon, 25 Jan 2021 14:40:47 +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 90AC56881BE for ; Mon, 25 Jan 2021 14:40:41 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 38087240684 for ; Mon, 25 Jan 2021 13:40:41 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id zf2LAwyjf_wa for ; Mon, 25 Jan 2021 13:40:38 +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 81DE2240621 for ; Mon, 25 Jan 2021 13:40:38 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 48A103A02BB; Mon, 25 Jan 2021 13:40:38 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 25 Jan 2021 13:40:30 +0100 Message-Id: <20210125124030.30559-1-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc: shedule old encoding/decoding API for removal X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" It has been deprecated for 4 years and certain new codecs do not work with it. Also include AVCodecContext.refcounted_frames, as it has no effect with the new API. --- libavcodec/avcodec.h | 6 ++++++ libavcodec/decode.c | 8 ++++++++ libavcodec/encode.c | 2 ++ libavcodec/internal.h | 5 +++++ libavcodec/options_table.h | 2 ++ libavcodec/utils.c | 25 ++++++++++++++++++++----- libavcodec/version.h | 3 +++ 7 files changed, 46 insertions(+), 5 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index fdb4276260..595bd0e54c 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1345,6 +1345,7 @@ typedef struct AVCodecContext { */ int (*get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags); +#if FF_API_OLD_ENCDEC /** * If non-zero, the decoded audio and video frames returned from * avcodec_decode_video2() and avcodec_decode_audio4() are reference-counted @@ -1360,6 +1361,7 @@ typedef struct AVCodecContext { */ attribute_deprecated int refcounted_frames; +#endif /* - encoding parameters */ float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0) @@ -2982,6 +2984,7 @@ int avcodec_enum_to_chroma_pos(int *xpos, int *ypos, enum AVChromaLocation pos); */ enum AVChromaLocation avcodec_chroma_pos_to_enum(int xpos, int ypos); +#if FF_API_OLD_ENCDEC /** * Decode the audio frame of size avpkt->size from avpkt->data into frame. * @@ -3088,6 +3091,7 @@ attribute_deprecated int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt); +#endif /** * Decode a subtitle message. @@ -3625,6 +3629,7 @@ void av_parser_close(AVCodecParserContext *s); * @{ */ +#if FF_API_OLD_ENCDEC /** * Encode a frame of audio. * @@ -3707,6 +3712,7 @@ int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, attribute_deprecated int avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr); +#endif int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub); diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 9861ead073..8086362eb2 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -221,8 +221,10 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt) if (ret < 0) goto finish; +#if FF_API_OLD_ENCDEC if (avctx->codec->receive_frame) avci->compat_decode_consumed += pkt->size; +#endif return 0; finish: @@ -469,7 +471,9 @@ FF_ENABLE_DEPRECATION_WARNINGS } } +#if FF_API_OLD_ENCDEC avci->compat_decode_consumed += ret; +#endif if (ret >= pkt->size || ret < 0) { av_packet_unref(pkt); @@ -693,6 +697,8 @@ int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *fr return 0; } +#if FF_API_OLD_ENCDEC +FF_DISABLE_DEPRECATION_WARNINGS static int unrefcount_frame(AVCodecInternal *avci, AVFrame *frame) { int ret; @@ -834,6 +840,8 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, { return compat_decode(avctx, frame, got_frame_ptr, avpkt); } +FF_ENABLE_DEPRECATION_WARNINGS +#endif static void get_subtitle_defaults(AVSubtitle *sub) { diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 2e540baf37..29f41c3f92 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -356,6 +356,7 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * return 0; } +#if FF_API_OLD_ENCDEC static int compat_encode(AVCodecContext *avctx, AVPacket *avpkt, int *got_packet, const AVFrame *frame) { @@ -456,3 +457,4 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, return ret; } +#endif diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 141f3fb88e..65760368d6 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -131,7 +131,9 @@ typedef struct AVCodecInternal { */ int last_audio_frame; +#if FF_API_OLD_ENCDEC AVFrame *to_free; +#endif AVBufferRef *pool; @@ -179,6 +181,8 @@ typedef struct AVCodecInternal { AVPacket *buffer_pkt; AVFrame *buffer_frame; int draining_done; + +#if FF_API_OLD_ENCDEC int compat_decode_warned; /* this variable is set by the decoder internals to signal to the old * API compat wrappers the amount of data consumed from the last packet */ @@ -188,6 +192,7 @@ typedef struct AVCodecInternal { size_t compat_decode_partial_size; AVFrame *compat_decode_frame; AVPacket *compat_encode_packet; +#endif int showed_multi_packet_warning; diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index 1b9d39a3a7..53fa065fc1 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -448,7 +448,9 @@ static const AVOption avcodec_options[] = { #if FF_API_ASS_TIMING {"ass_with_timings", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS}, INT_MIN, INT_MAX, S|D, "sub_text_format"}, #endif +#if FF_API_OLD_ENCDEC {"refcounted_frames", NULL, OFFSET(refcounted_frames), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A|V|D }, +#endif #if FF_API_SIDEDATA_ONLY_PKT {"side_data_only_packets", NULL, OFFSET(side_data_only_packets), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, A|V|E }, #endif diff --git a/libavcodec/utils.c b/libavcodec/utils.c index aeb9c6de72..a1ae9cab18 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -580,18 +580,23 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code } avctx->internal = avci; +#if FF_API_OLD_ENCDEC avci->to_free = av_frame_alloc(); avci->compat_decode_frame = av_frame_alloc(); avci->compat_encode_packet = av_packet_alloc(); + if (!avci->to_free || !avci->compat_decode_frame || !avci->compat_encode_packet) { + ret = AVERROR(ENOMEM); + goto free_and_end; + } +#endif avci->buffer_frame = av_frame_alloc(); avci->buffer_pkt = av_packet_alloc(); avci->es.in_frame = av_frame_alloc(); avci->ds.in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); - if (!avci->compat_decode_frame || !avci->compat_encode_packet || - !avci->buffer_frame || !avci->buffer_pkt || + if (!avci->buffer_frame || !avci->buffer_pkt || !avci->es.in_frame || !avci->ds.in_pkt || - !avci->to_free || !avci->last_pkt_props) { + !avci->last_pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; } @@ -1065,10 +1070,12 @@ FF_ENABLE_DEPRECATION_WARNINGS av_freep(&avctx->priv_data); av_freep(&avctx->subtitle_header); +#if FF_API_OLD_ENCDEC av_frame_free(&avci->to_free); av_frame_free(&avci->compat_decode_frame); - av_frame_free(&avci->buffer_frame); av_packet_free(&avci->compat_encode_packet); +#endif + av_frame_free(&avci->buffer_frame); av_packet_free(&avci->buffer_pkt); av_packet_free(&avci->last_pkt_props); @@ -1106,8 +1113,10 @@ void avcodec_flush_buffers(AVCodecContext *avctx) avci->draining_done = 0; avci->nb_draining_errors = 0; av_frame_unref(avci->buffer_frame); +#if FF_API_OLD_ENCDEC av_frame_unref(avci->compat_decode_frame); av_packet_unref(avci->compat_encode_packet); +#endif av_packet_unref(avci->buffer_pkt); av_packet_unref(avci->last_pkt_props); @@ -1128,8 +1137,12 @@ void avcodec_flush_buffers(AVCodecContext *avctx) if (av_codec_is_decoder(avctx->codec)) av_bsf_flush(avci->bsf); +#if FF_API_OLD_ENCDEC +FF_DISABLE_DEPRECATION_WARNINGS if (!avctx->refcounted_frames) av_frame_unref(avci->to_free); +FF_ENABLE_DEPRECATION_WARNINGS +#endif } void avsubtitle_free(AVSubtitle *sub) @@ -1169,10 +1182,12 @@ av_cold int avcodec_close(AVCodecContext *avctx) avctx->codec->close(avctx); avctx->internal->byte_buffer_size = 0; av_freep(&avctx->internal->byte_buffer); +#if FF_API_OLD_ENCDEC av_frame_free(&avctx->internal->to_free); av_frame_free(&avctx->internal->compat_decode_frame); - av_frame_free(&avctx->internal->buffer_frame); av_packet_free(&avctx->internal->compat_encode_packet); +#endif + av_frame_free(&avctx->internal->buffer_frame); av_packet_free(&avctx->internal->buffer_pkt); av_packet_free(&avctx->internal->last_pkt_props); avpriv_packet_list_free(&avctx->internal->pkt_props, diff --git a/libavcodec/version.h b/libavcodec/version.h index 50ad2671af..7a37890f9e 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -147,6 +147,9 @@ #ifndef FF_API_AVPRIV_PUT_BITS #define FF_API_AVPRIV_PUT_BITS (LIBAVCODEC_VERSION_MAJOR < 59) #endif +#ifndef FF_API_OLD_ENCDEC +#define FF_API_OLD_ENCDEC (LIBAVCODEC_VERSION_MAJOR < 59) +#endif #ifndef FF_API_THREAD_SAFE_CALLBACKS #define FF_API_THREAD_SAFE_CALLBACKS (LIBAVCODEC_VERSION_MAJOR < 60) #endif