Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 5/9] lavc: add generic-encode-layer private data
Date: Tue, 20 Jun 2023 16:16:04 +0200
Message-ID: <20230620141608.31759-5-anton@khirnov.net> (raw)
In-Reply-To: <20230620141608.31759-1-anton@khirnov.net>

Move AVCodecInternal.intra_only_flag to it, should should not be visible
outside of encode.c.
---
 libavcodec/avcodec.c          |  2 +-
 libavcodec/avcodec_internal.h |  1 +
 libavcodec/encode.c           | 26 ++++++++++++++++++++++++--
 libavcodec/internal.h         | 13 ++++++-------
 4 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index ff251d2dae..21d1e42c10 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 6d0ef2be10..4273dceb31 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -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;
+}
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index b672092ac4..2f4aee8ecc 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -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;
 
     /**
-- 
2.40.1

_______________________________________________
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".

  parent reply	other threads:[~2023-06-20 14:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20 14:16 [FFmpeg-devel] [PATCH 1/9] lavc: add a header for internal generic-layer APIs Anton Khirnov
2023-06-20 14:16 ` [FFmpeg-devel] [PATCH 2/9] lavc/avcodec: split flushing into decode- and encode-specific functions Anton Khirnov
2023-06-24 18:53   ` Andreas Rheinhardt
2023-06-20 14:16 ` [FFmpeg-devel] [PATCH 3/9] lavc: reindent after previous commit Anton Khirnov
2023-06-20 14:16 ` [FFmpeg-devel] [PATCH 4/9] lavc: add generic-decode-layer private data Anton Khirnov
2023-06-24 19:34   ` Andreas Rheinhardt
2023-07-03 19:24   ` Anton Khirnov
2023-06-20 14:16 ` Anton Khirnov [this message]
2023-06-20 14:16 ` [FFmpeg-devel] [PATCH 6/9] lavc: move AVCodecInternal.last_audio_frame to EncodeContext Anton Khirnov
2023-06-20 14:16 ` [FFmpeg-devel] [PATCH 7/9] lavc/decode: track whether the caller started draining with a separate flag Anton Khirnov
2023-06-20 14:16 ` [FFmpeg-devel] [PATCH 8/9] lavc/decode: move submitting input packets to bitstream filters Anton Khirnov
2023-06-20 17:48   ` James Almer
2023-06-20 14:16 ` [FFmpeg-devel] [PATCH 9/9] lavc/decode: do not perform decoding when sending draining packets Anton Khirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230620141608.31759-5-anton@khirnov.net \
    --to=anton@khirnov.net \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git