lavc: shedule old encoding/decoding API for removal

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.
This commit is contained in:
Anton Khirnov 2021-01-25 12:03:44 +01:00
parent 25f4304ebb
commit 9e30859cb6
7 changed files with 46 additions and 5 deletions

View File

@ -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)
@ -2959,6 +2961,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.
*
@ -3065,6 +3068,7 @@ attribute_deprecated
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
int *got_picture_ptr,
const AVPacket *avpkt);
#endif
/**
* Decode a subtitle message.
@ -3602,6 +3606,7 @@ void av_parser_close(AVCodecParserContext *s);
* @{
*/
#if FF_API_OLD_ENCDEC
/**
* Encode a frame of audio.
*
@ -3684,6 +3689,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);

View File

@ -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)
{

View File

@ -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

View File

@ -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;

View File

@ -441,7 +441,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

View File

@ -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,

View File

@ -144,6 +144,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