Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: fei.w.wang-at-intel.com@ffmpeg.org
To: ffmpeg-devel@ffmpeg.org
Cc: fei.w.wang@intel.com
Subject: [FFmpeg-devel] [PATCH v4 3/8] avcodec/cbs_av1: Allow specifying obu size byte length
Date: Thu, 31 Aug 2023 15:21:02 +0800
Message-ID: <20230831072107.1051955-3-fei.w.wang@intel.com> (raw)
In-Reply-To: <20230831072107.1051955-1-fei.w.wang@intel.com>

From: Fei Wang <fei.w.wang@intel.com>

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
 libavcodec/cbs_av1.c | 30 +++++++++++++++++++++---------
 libavcodec/cbs_av1.h |  1 +
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index aa92639235..0c08256cc8 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -138,15 +138,19 @@ static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc,
     return 0;
 }
 
+/** Minimum byte length will be used to indicate the len128 of value if byte_len is 0. */
 static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc,
-                                const char *name, uint64_t value)
+                                const char *name, uint64_t value, uint8_t byte_len)
 {
     int len, i;
     uint8_t byte;
 
     CBS_TRACE_WRITE_START();
 
-    len = (av_log2(value) + 7) / 7;
+    if (byte_len)
+        av_assert0(byte_len >= (av_log2(value) + 7) / 7);
+
+    len = byte_len ? byte_len : (av_log2(value) + 7) / 7;
 
     for (i = 0; i < len; i++) {
         if (put_bits_left(pbc) < 8)
@@ -618,7 +622,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc)
     } while (0)
 
 #define leb128(name) do { \
-        CHECK(cbs_av1_write_leb128(ctx, rw, #name, current->name)); \
+        CHECK(cbs_av1_write_leb128(ctx, rw, #name, current->name, 0)); \
     } while (0)
 
 #define infer(name, value) do { \
@@ -1002,9 +1006,14 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
 
     if (obu->header.obu_has_size_field) {
         pbc_tmp = *pbc;
-        // Add space for the size field to fill later.
-        put_bits32(pbc, 0);
-        put_bits32(pbc, 0);
+        if (obu->obu_size_byte_len) {
+            for (int i = 0; i < obu->obu_size_byte_len; i++)
+                put_bits(pbc, 8, 0);
+        } else {
+            // Add space for the size field to fill later.
+            put_bits32(pbc, 0);
+            put_bits32(pbc, 0);
+        }
     }
 
     td = NULL;
@@ -1124,7 +1133,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
     end_pos   /= 8;
 
     *pbc = pbc_tmp;
-    err = cbs_av1_write_leb128(ctx, pbc, "obu_size", obu->obu_size);
+    err = cbs_av1_write_leb128(ctx, pbc, "obu_size", obu->obu_size, obu->obu_size_byte_len);
     if (err < 0)
         goto error;
 
@@ -1141,8 +1150,11 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
     }
 
     if (obu->obu_size > 0) {
-        memmove(pbc->buf + data_pos,
-                pbc->buf + start_pos, header_size);
+        if (!obu->obu_size_byte_len) {
+            obu->obu_size_byte_len = start_pos - data_pos;
+            memmove(pbc->buf + data_pos,
+                    pbc->buf + start_pos, header_size);
+        }
         skip_put_bytes(pbc, header_size);
 
         if (td) {
diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index 64dfdce9c4..a9e2d2284f 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -401,6 +401,7 @@ typedef struct AV1RawOBU {
     AV1RawOBUHeader header;
 
     size_t obu_size;
+    uint8_t obu_size_byte_len;
 
     union {
         AV1RawSequenceHeader sequence_header;
-- 
2.25.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-08-31  7:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-31  7:21 [FFmpeg-devel] [PATCH v4 1/8] avcodec/cbs_av1: Add tx mode enum values fei.w.wang-at-intel.com
2023-08-31  7:21 ` [FFmpeg-devel] [PATCH v4 2/8] cbs: Make tracing more general fei.w.wang-at-intel.com
2023-08-31  7:21 ` fei.w.wang-at-intel.com [this message]
2023-08-31  7:21 ` [FFmpeg-devel] [PATCH v4 4/8] lavc/vaapi_encode: Init pic at the beginning of API fei.w.wang-at-intel.com
2023-08-31  7:21 ` [FFmpeg-devel] [PATCH v4 5/8] lavc/vaapi_encode: Extract set output pkt property function fei.w.wang-at-intel.com
2023-08-31  7:21 ` [FFmpeg-devel] [PATCH v4 6/8] lavc/vaapi_encode: Separate reference frame into previous/future list fei.w.wang-at-intel.com
2023-08-31  7:21 ` [FFmpeg-devel] [PATCH v4 7/8] lavc/vaapi_encode: Add VAAPI AV1 encoder fei.w.wang-at-intel.com
2023-09-05  5:08   ` Wang, Fei W
2023-09-08  6:31   ` Xiang, Haihao
2023-08-31  7:21 ` [FFmpeg-devel] [PATCH v4 8/8] lavc/av1: Add unit test for level handling fei.w.wang-at-intel.com

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=20230831072107.1051955-3-fei.w.wang@intel.com \
    --to=fei.w.wang-at-intel.com@ffmpeg.org \
    --cc=fei.w.wang@intel.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