Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/apv_parser: use ff_cbs_read_buf()
Date: Thu,  1 May 2025 22:44:14 -0300
Message-ID: <20250502014414.3404-2-jamrial@gmail.com> (raw)
In-Reply-To: <20250502014414.3404-1-jamrial@gmail.com>

Removes an unecessary data copying.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/apv_parser.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/libavcodec/apv_parser.c b/libavcodec/apv_parser.c
index bd1894146c..25b80285a5 100644
--- a/libavcodec/apv_parser.c
+++ b/libavcodec/apv_parser.c
@@ -16,6 +16,9 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avassert.h"
+#include "libavutil/buffer.h"
+
 #include "avcodec.h"
 #include "apv.h"
 #include "cbs.h"
@@ -34,6 +37,11 @@ static const enum AVPixelFormat apv_format_table[5][5] = {
     { AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_YUVA444P16 },
 };
 
+static void dummy_free(void *opaque, uint8_t *data)
+{
+    av_assert0(opaque == data);
+}
+
 static int parse(AVCodecParserContext *s,
                  AVCodecContext *avctx,
                  const uint8_t **poutbuf, int *poutbuf_size,
@@ -41,6 +49,7 @@ static int parse(AVCodecParserContext *s,
 {
     APVParseContext *p = s->priv_data;
     CodedBitstreamFragment *au = &p->au;
+    AVBufferRef *ref = NULL;
     int ret;
 
     *poutbuf      = buf;
@@ -48,7 +57,12 @@ static int parse(AVCodecParserContext *s,
 
     p->cbc->log_ctx = avctx;
 
-    ret = ff_cbs_read(p->cbc, au, buf, buf_size);
+    ref = av_buffer_create((uint8_t *)buf, buf_size, dummy_free,
+                           (void *)buf, AV_BUFFER_FLAG_READONLY);
+    if (!ref)
+        goto end;
+
+    ret = ff_cbs_read_buf(p->cbc, au, ref);
     if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "Failed to parse access unit.\n");
         goto end;
@@ -92,6 +106,9 @@ static int parse(AVCodecParserContext *s,
 
 end:
     ff_cbs_fragment_reset(au);
+    if (ref)
+        av_assert1(av_buffer_get_ref_count(ref) == 1);
+    av_buffer_unref(&ref);
     p->cbc->log_ctx = NULL;
 
     return buf_size;
-- 
2.49.0

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

  reply	other threads:[~2025-05-02  1:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02  1:44 [FFmpeg-devel] [PATCH 1/2] avcodec/cbs: add ff_cbs_read_buf() James Almer
2025-05-02  1:44 ` James Almer [this message]
2025-05-04 13:58 ` James Almer

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=20250502014414.3404-2-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --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