diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-06-20 13:24:49 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-07-07 12:07:23 +0200 |
commit | 232700154cad24f110cd4fb6ac3b2d3c254e4512 (patch) | |
tree | ac3b153935611e52920d93dbf5f38708e7a04173 | |
parent | f2fb882b3f0046493e40306724a6d855b12e2121 (diff) | |
download | ffmpeg-232700154cad24f110cd4fb6ac3b2d3c254e4512.tar.gz |
lavc: add generic-encode-layer private data
Move AVCodecInternal.intra_only_flag to it, should should not be visible
outside of encode.c.
-rw-r--r-- | libavcodec/avcodec.c | 2 | ||||
-rw-r--r-- | libavcodec/avcodec_internal.h | 1 | ||||
-rw-r--r-- | libavcodec/encode.c | 26 | ||||
-rw-r--r-- | 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; /** |