@@ -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;
@@ -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
@@ -33,6 +33,15 @@
#include "frame_thread_encoder.h"
#include "internal.h"
+struct EncodeContext {
+ /**
+ * 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;
+};
+
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
{
if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
@@ -372,7 +381,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 |= avci->e->intra_only_flag;
if (ret == AVERROR_EOF)
avci->draining_done = 1;
@@ -710,7 +719,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;
+ avctx->internal->e->intra_only_flag = AV_PKT_FLAG_KEY;
if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_ENCODE) {
avci->in_frame = av_frame_alloc();
@@ -803,3 +812,16 @@ void ff_encode_flush_buffers(AVCodecContext *avctx)
if (avci->recon_frame)
av_frame_unref(avci->recon_frame);
}
+
+AVCodecInternal *ff_encode_internal_alloc(void)
+{
+ struct Dummy {
+ AVCodecInternal i;
+ EncodeContext e;
+ } *dummy = av_mallocz(sizeof(*dummy));
+ if (!dummy)
+ return NULL;
+ dummy->i.e = &dummy->e;
+
+ return &dummy->i;
+}
@@ -50,6 +50,7 @@
#endif
typedef struct DecodeContext DecodeContext;
+typedef struct EncodeContext EncodeContext;
typedef struct AVCodecInternal {
/**
@@ -57,6 +58,11 @@ typedef struct AVCodecInternal {
*/
DecodeContext *d;
+ /**
+ * Generic decoding private data.
+ */
+ EncodeContext *e;
+
/**
* When using frame-threaded decoding, this field is set for the first
* worker thread (e.g. to decode extradata just once).
@@ -102,13 +108,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;
/**