From: Mark Thompson <sw@jkqxz.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2] cbs_av1: Make fake OBU size length field a write option Date: Tue, 26 Sep 2023 21:30:51 +0100 Message-ID: <82270518-8c7a-d360-ba1a-e2ceca913302@jkqxz.net> (raw) In-Reply-To: <a28bb1739f0d7709b5daf390aebfcb3cc10586c7.camel@intel.com> This is an option to modify the behaviour of the writer, not a syntax field. --- On 26/09/2023 03:34, Wang, Fei W wrote: > On Mon, 2023-09-25 at 14:53 +0100, Mark Thompson wrote: >> ... >> diff --git a/libavcodec/vaapi_encode_av1.c >> b/libavcodec/vaapi_encode_av1.c >> index 3ff1c47b53..861bf4a13b 100644 >> --- a/libavcodec/vaapi_encode_av1.c >> +++ b/libavcodec/vaapi_encode_av1.c >> @@ -133,6 +133,9 @@ static av_cold int >> vaapi_encode_av1_configure(AVCodecContext *avctx) >> priv->cbc->trace_context = ctx; >> priv->cbc->trace_write_callback = >> vaapi_encode_av1_trace_write_log; >> >> + av_opt_set_int(priv->cbc->priv_data, "fixed_obu_size_length", >> + priv->attr_ext2.bits.obu_size_bytes_minus1 + 1, >> 0); >> + > > This should be put after querying priv.attr_ext2 in > vaapi_encode_av1_init(). Ah, true - I got my init and configure mixed up, but don't have convenient hardware to test. Fixed in this version. Thanks, - Mark libavcodec/cbs_av1.c | 31 +++++++++++++++++++++---------- libavcodec/cbs_av1.h | 5 ++++- libavcodec/vaapi_encode_av1.c | 4 +++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index 4e687ace79..ed9a7b80d4 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -138,19 +138,25 @@ 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, uint8_t byte_len) + const char *name, uint64_t value, int fixed_length) { int len, i; uint8_t byte; CBS_TRACE_WRITE_START(); - if (byte_len) - av_assert0(byte_len >= (av_log2(value) + 7) / 7); + len = (av_log2(value) + 7) / 7; - len = byte_len ? byte_len : (av_log2(value) + 7) / 7; + if (fixed_length) { + if (fixed_length < len) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "OBU is too large for " + "fixed length size field (%d > %d).\n", + len, fixed_length); + return AVERROR(EINVAL); + } + len = fixed_length; + } for (i = 0; i < len; i++) { if (put_bits_left(pbc) < 8) @@ -1006,8 +1012,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, if (obu->header.obu_has_size_field) { pbc_tmp = *pbc; - if (obu->obu_size_byte_len) { - for (int i = 0; i < obu->obu_size_byte_len; i++) + if (priv->fixed_obu_size_length) { + for (int i = 0; i < priv->fixed_obu_size_length; i++) put_bits(pbc, 8, 0); } else { // Add space for the size field to fill later. @@ -1133,7 +1139,8 @@ 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, obu->obu_size_byte_len); + err = cbs_av1_write_leb128(ctx, pbc, "obu_size", obu->obu_size, + priv->fixed_obu_size_length); if (err < 0) goto error; @@ -1150,10 +1157,12 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, } if (obu->obu_size > 0) { - if (!obu->obu_size_byte_len) { - obu->obu_size_byte_len = start_pos - data_pos; + if (!priv->fixed_obu_size_length) { memmove(pbc->buf + data_pos, pbc->buf + start_pos, header_size); + } else { + // The size was fixed so the following data was + // already written in the correct place. } skip_put_bytes(pbc, header_size); @@ -1273,6 +1282,8 @@ static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = { static const AVOption cbs_av1_options[] = { { "operating_point", "Set operating point to select layers to parse from a scalable bitstream", OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AV1_MAX_OPERATING_POINTS - 1, 0 }, + { "fixed_obu_size_length", "Set fixed length of the obu_size field", + OFFSET(fixed_obu_size_length), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8, 0 }, { NULL } }; diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index a9e2d2284f..7924257164 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -401,7 +401,6 @@ typedef struct AV1RawOBU { AV1RawOBUHeader header; size_t obu_size; - uint8_t obu_size_byte_len; union { AV1RawSequenceHeader sequence_header; @@ -468,6 +467,10 @@ typedef struct CodedBitstreamAV1Context { // AVOptions int operating_point; + // When writing, fix the length in bytes of the obu_size field. + // Writing will fail with an error if an OBU larger than can be + // represented by the fixed size is encountered. + int fixed_obu_size_length; } CodedBitstreamAV1Context; diff --git a/libavcodec/vaapi_encode_av1.c b/libavcodec/vaapi_encode_av1.c index 3ff1c47b53..5a9ff0f798 100644 --- a/libavcodec/vaapi_encode_av1.c +++ b/libavcodec/vaapi_encode_av1.c @@ -634,7 +634,6 @@ static int vaapi_encode_av1_init_picture_params(AVCodecContext *avctx, } } - fh_obu->obu_size_byte_len = priv->attr_ext2.bits.obu_size_bytes_minus1 + 1; ret = vaapi_encode_av1_add_obu(avctx, obu, AV1_OBU_FRAME_HEADER, &priv->fh); if (ret < 0) goto end; @@ -839,6 +838,9 @@ static av_cold int vaapi_encode_av1_init(AVCodecContext *avctx) priv->attr_ext2.value = attr.value; } + av_opt_set_int(priv->cbc->priv_data, "fixed_obu_size_length", + priv->attr_ext2.bits.obu_size_bytes_minus1 + 1, 0); + ret = vaapi_encode_av1_set_tile(avctx); if (ret < 0) return ret; -- 2.39.2 _______________________________________________ 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".
next prev parent reply other threads:[~2023-09-26 20:30 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-09-25 13:53 [FFmpeg-devel] [PATCH] " Mark Thompson 2023-09-26 2:34 ` Wang, Fei W 2023-09-26 20:30 ` Mark Thompson [this message] 2023-09-27 2:16 ` [FFmpeg-devel] [PATCH v2] " Wang, Fei W 2023-10-02 19:42 ` Mark Thompson 2023-09-26 9:19 ` [FFmpeg-devel] [PATCH] " Andreas Rheinhardt 2023-09-26 20:05 ` Mark Thompson
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=82270518-8c7a-d360-ba1a-e2ceca913302@jkqxz.net \ --to=sw@jkqxz.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