From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 6C0AF45435 for <ffmpegdev@gitmailbox.com>; Fri, 21 Mar 2025 19:44:05 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BFE6A687C0B; Fri, 21 Mar 2025 21:44:01 +0200 (EET) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C04D6687AE1 for <ffmpeg-devel@ffmpeg.org>; Fri, 21 Mar 2025 21:43:54 +0200 (EET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-22435603572so46612355ad.1 for <ffmpeg-devel@ffmpeg.org>; Fri, 21 Mar 2025 12:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742586232; x=1743191032; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=zVzH9ZZVQU/Xo3YyLTFo1xo/Q+RQBNGPD+WZn+rVOyY=; b=YKfm6zrGLrfhQsRRE1sk2IKIA8CInvimAY+lTrfa+FFUZj+mwMFgC0t6TF/kzDAFfl s/FgGWwKJE7+qvv4cSNd/UhW8pwXMGu7z+zH4vb8Lj9j6QN0DTM7LiBjVtXr2JHNCCYC rnL4FCbthZLeNwEuSOJnkcQ3zFpltoqYPXkEkqbKw8+0mdR6mB5DwdLmQ+LSD0IVTfoC EfJW94+VwQZ4yMtn8HmcnerrvnyWqym+DRwZB3jAHpz935koBtUJhJh3RFRJXu5KNWoc 8Za+6mJq80IftYh9mF2LdVIzpCOEpp4YoeE1iAKQKREulm509m5wnOi5KGTuPXQqYZTd Rg+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742586232; x=1743191032; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zVzH9ZZVQU/Xo3YyLTFo1xo/Q+RQBNGPD+WZn+rVOyY=; b=IC2OsNpZ1S9687NHhBUnxl/HUuZN/enTnMLSY1pPSrsKBEUFl18GOlnNJJROfLEH8s yogT56InZoBLKthxSfkp+sXHbJFnGL63M08GoTGJrjLbeSQu7r0jwZL/df4jUa15M/nT oJxw4nS43gbwly0Xxmbx7msO7OzzOsbst+ErR45Zar2aFZa0uApCNJIMNeyX16S/ErtM cKy5je8wIVdYWH9IR8WVvbm1W3Q6f0jbYVdyQSOAny0OqbP6y62cFZWA0Uh/aGc7Hu+k UZYZVewRhLCen85DH16po+ReIB4Ak+Ac6yUJddrGzfqYnmXTjBM2VB/0tYCftR/9urus gMtw== X-Gm-Message-State: AOJu0YzZesKan8qoCXtpjld0icpnH+QQZ7ctEuZFTQ0AkkOIRj8kus+V eUzpQHaai6bYIT6+FNFYDas+9lIIBx7H65IyzmFLbt7G92x7yRFrHsmfQA== X-Gm-Gg: ASbGncvfYKFgjDayp4zrsjG2OF6iHiLutgi1+Duy4w3aaYqH5PFo4Xwtrp1e/25jwB1 vBh/zH2imkjSr4zUfc364Zx/RVoQGQz1itTv0iHdW6fTpTyuMuKitj8EShe23gDyuaM94yv0gbJ 7xTia9vC8VSC7BbzoO0o+Ad/rYLAnGM7WE6ufC6jicw8+2qXf4W5ae/NYRUTIN5OaRsBlaDsXh4 MXlNRXAg+57a1pRNWNMGutECchEQ6l9D+FeWiiuQWxILakjcxr0f5jcqRR9I1Cjwh53HqLo3c1d +tmqVW5MEYBjiEdzBYAgJUFIl0KoeGtdPv5MgBJtqcmbGVeSmuhKVrRj2yDQgUsD X-Google-Smtp-Source: AGHT+IGRIyoKdKdFv6W/NO92rZXyPO+sWwLqmlrOpjqIjmlEGMiY+jxTZ+pwYAchS+Fe6KUVDd9sog== X-Received: by 2002:a17:903:98d:b0:220:e362:9b1a with SMTP id d9443c01a7336-22780d83b3emr89410095ad.25.1742586231693; Fri, 21 Mar 2025 12:43:51 -0700 (PDT) Received: from localhost.localdomain ([2800:2121:b000:82e:f5c1:ed73:2406:cc17]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-227811f14dfsm21319925ad.220.2025.03.21.12.43.50 for <ffmpeg-devel@ffmpeg.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Mar 2025 12:43:51 -0700 (PDT) From: James Almer <jamrial@gmail.com> To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Mar 2025 16:42:36 -0300 Message-ID: <20250321194237.20559-1-jamrial@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <DU0P250MB07476C3EDEC5F4849B1102798FDB2@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM> References: <DU0P250MB07476C3EDEC5F4849B1102798FDB2@DU0P250MB0747.EURP250.PROD.OUTLOOK.COM> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avcodec/cbs: allow fine tunning selection of features X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/20250321194237.20559-1-jamrial@gmail.com/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> This will be useful in an upcoming commit, where CBS will be utilized by a module outside libavcodec. Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/cbs.c | 100 ++++++++++++++++++++++----- libavcodec/cbs_av1.c | 64 ++++++++++++++++- libavcodec/cbs_av1.h | 15 ++++ libavcodec/cbs_av1_syntax_template.c | 6 ++ libavcodec/cbs_internal.h | 48 +++++++++++++ 5 files changed, 212 insertions(+), 21 deletions(-) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 01dd916d81..94bf174700 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -18,8 +18,6 @@ #include <string.h> -#include "config.h" - #include "libavutil/avassert.h" #include "libavutil/buffer.h" #include "libavutil/common.h" @@ -33,55 +31,55 @@ static const CodedBitstreamType *const cbs_type_table[] = { -#if CONFIG_CBS_AV1 +#if CBS_AV1 &ff_cbs_type_av1, #endif -#if CONFIG_CBS_H264 +#if CBS_H264 &ff_cbs_type_h264, #endif -#if CONFIG_CBS_H265 +#if CBS_H265 &ff_cbs_type_h265, #endif -#if CONFIG_CBS_H266 +#if CBS_H266 &ff_cbs_type_h266, #endif -#if CONFIG_CBS_JPEG +#if CBS_JPEG &ff_cbs_type_jpeg, #endif -#if CONFIG_CBS_MPEG2 +#if CBS_MPEG2 &ff_cbs_type_mpeg2, #endif -#if CONFIG_CBS_VP8 +#if CBS_VP8 &ff_cbs_type_vp8, #endif -#if CONFIG_CBS_VP9 +#if CBS_VP9 &ff_cbs_type_vp9, #endif }; const enum AVCodecID ff_cbs_all_codec_ids[] = { -#if CONFIG_CBS_AV1 +#if CBS_AV1 AV_CODEC_ID_AV1, #endif -#if CONFIG_CBS_H264 +#if CBS_H264 AV_CODEC_ID_H264, #endif -#if CONFIG_CBS_H265 +#if CBS_H265 AV_CODEC_ID_H265, #endif -#if CONFIG_CBS_H266 +#if CBS_H266 AV_CODEC_ID_H266, #endif -#if CONFIG_CBS_JPEG +#if CBS_JPEG AV_CODEC_ID_MJPEG, #endif -#if CONFIG_CBS_MPEG2 +#if CBS_MPEG2 AV_CODEC_ID_MPEG2VIDEO, #endif -#if CONFIG_CBS_VP8 +#if CBS_VP8 AV_CODEC_ID_VP8, #endif -#if CONFIG_CBS_VP9 +#if CBS_VP9 AV_CODEC_ID_VP9, #endif AV_CODEC_ID_NONE @@ -234,6 +232,7 @@ static int cbs_read_fragment_content(CodedBitstreamContext *ctx, return 0; } +#if CBS_READ static int cbs_fill_fragment_data(CodedBitstreamFragment *frag, const uint8_t *data, size_t size) { @@ -282,37 +281,51 @@ static int cbs_read_data(CodedBitstreamContext *ctx, return cbs_read_fragment_content(ctx, frag); } +#endif int ff_cbs_read_extradata(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecParameters *par) { +#if CBS_READ return cbs_read_data(ctx, frag, NULL, par->extradata, par->extradata_size, 1); +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVCodecContext *avctx) { +#if CBS_READ return cbs_read_data(ctx, frag, NULL, avctx->extradata, avctx->extradata_size, 1); +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_read_packet(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt) { +#if CBS_READ return cbs_read_data(ctx, frag, pkt->buf, pkt->data, pkt->size, 0); +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const AVPacket *pkt) { +#if CBS_READ size_t side_data_size; const uint8_t *side_data = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, @@ -320,16 +333,24 @@ int ff_cbs_read_packet_side_data(CodedBitstreamContext *ctx, return cbs_read_data(ctx, frag, NULL, side_data, side_data_size, 1); +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_read(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const uint8_t *data, size_t size) { +#if CBS_READ return cbs_read_data(ctx, frag, NULL, data, size, 0); +#else + return AVERROR(ENOSYS); +#endif } +#if CBS_WRITE /** * Allocate a new internal data buffer of the given size in the unit. * @@ -405,10 +426,12 @@ static int cbs_write_unit_data(CodedBitstreamContext *ctx, return 0; } +#endif int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag) { +#if CBS_WRITE int err, i; for (i = 0; i < frag->nb_units; i++) { @@ -440,12 +463,16 @@ int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, av_assert0(frag->data && frag->data_ref); return 0; +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag) { +#if CBS_WRITE int err; err = ff_cbs_write_fragment_data(ctx, frag); @@ -469,12 +496,16 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, par->extradata_size = frag->data_size; return 0; +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag) { +#if CBS_WRITE AVBufferRef *buf; int err; @@ -493,16 +524,21 @@ int ff_cbs_write_packet(CodedBitstreamContext *ctx, pkt->size = frag->data_size; return 0; +#else + return AVERROR(ENOSYS); +#endif } void ff_cbs_trace_header(CodedBitstreamContext *ctx, const char *name) { +#if CBS_TRACE if (!ctx->trace_enable) return; av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name); +#endif } void ff_cbs_trace_read_log(void *trace_context, @@ -510,6 +546,7 @@ void ff_cbs_trace_read_log(void *trace_context, const char *str, const int *subscripts, int64_t value) { +#if CBS_TRACE CodedBitstreamContext *ctx = trace_context; char name[256]; char bits[256]; @@ -561,6 +598,7 @@ void ff_cbs_trace_read_log(void *trace_context, av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n", position, name, pad, bits, value); +#endif } void ff_cbs_trace_write_log(void *trace_context, @@ -568,6 +606,7 @@ void ff_cbs_trace_write_log(void *trace_context, const char *str, const int *subscripts, int64_t value) { +#if CBS_TRACE CodedBitstreamContext *ctx = trace_context; // Ensure that the syntax element is written to the output buffer, @@ -591,6 +630,7 @@ void ff_cbs_trace_write_log(void *trace_context, skip_bits_long(&gbc, position - length); ff_cbs_trace_read_log(ctx, &gbc, length, str, subscripts, value); +#endif } static av_always_inline int cbs_read_unsigned(CodedBitstreamContext *ctx, @@ -633,15 +673,23 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, const int *subscripts, uint32_t *write_to, uint32_t range_min, uint32_t range_max) { +#if CBS_READ return cbs_read_unsigned(ctx, gbc, width, name, subscripts, write_to, range_min, range_max); +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_read_simple_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc, int width, const char *name, uint32_t *write_to) { +#if CBS_READ return cbs_read_unsigned(ctx, gbc, width, name, NULL, write_to, 0, UINT32_MAX); +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, @@ -649,6 +697,7 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, const int *subscripts, uint32_t value, uint32_t range_min, uint32_t range_max) { +#if CBS_WRITE CBS_TRACE_WRITE_START(); av_assert0(width > 0 && width <= 32); @@ -671,13 +720,20 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, CBS_TRACE_WRITE_END(); return 0; +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_write_simple_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value) { +#if CBS_WRITE return ff_cbs_write_unsigned(ctx, pbc, width, name, NULL, value, 0, MAX_UINT_BITS(width)); +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc, @@ -685,6 +741,7 @@ int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc, const int *subscripts, int32_t *write_to, int32_t range_min, int32_t range_max) { +#if CBS_READ int32_t value; CBS_TRACE_READ_START(); @@ -710,6 +767,9 @@ int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc, *write_to = value; return 0; +#else + return AVERROR(ENOSYS); +#endif } int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, @@ -717,6 +777,7 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, const int *subscripts, int32_t value, int32_t range_min, int32_t range_max) { +#if CBS_WRITE CBS_TRACE_WRITE_START(); av_assert0(width > 0 && width <= 32); @@ -739,6 +800,9 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, CBS_TRACE_WRITE_END(); return 0; +#else + return AVERROR(ENOSYS); +#endif } diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index d7862a2e48..e0a4eba20f 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -27,6 +27,7 @@ #include "libavutil/refstruct.h" +#if CBS_READ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc, const char *name, uint32_t *write_to, uint32_t range_min, uint32_t range_max) @@ -84,7 +85,9 @@ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc, *write_to = value; return 0; } +#endif +#if CBS_WRITE static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc, const char *name, uint32_t value, uint32_t range_min, uint32_t range_max) @@ -115,7 +118,9 @@ static int cbs_av1_write_uvlc(CodedBitstreamContext *ctx, PutBitContext *pbc, return 0; } +#endif +#if CBS_READ static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc, const char *name, uint64_t *write_to) { @@ -146,7 +151,9 @@ static int cbs_av1_read_leb128(CodedBitstreamContext *ctx, GetBitContext *gbc, *write_to = value; return 0; } +#endif +#if CBS_WRITE static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc, const char *name, uint64_t value, int fixed_length) { @@ -182,7 +189,9 @@ static int cbs_av1_write_leb128(CodedBitstreamContext *ctx, PutBitContext *pbc, return 0; } +#endif +#if CBS_READ static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc, uint32_t n, const char *name, const int *subscripts, uint32_t *write_to) @@ -220,7 +229,9 @@ static int cbs_av1_read_ns(CodedBitstreamContext *ctx, GetBitContext *gbc, *write_to = value; return 0; } +#endif +#if CBS_WRITE static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t n, const char *name, const int *subscripts, uint32_t value) @@ -256,7 +267,9 @@ static int cbs_av1_write_ns(CodedBitstreamContext *ctx, PutBitContext *pbc, return 0; } +#endif +#if CBS_READ static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc, uint32_t range_min, uint32_t range_max, const char *name, uint32_t *write_to) @@ -284,7 +297,9 @@ static int cbs_av1_read_increment(CodedBitstreamContext *ctx, GetBitContext *gbc *write_to = value; return 0; } +#endif +#if CBS_WRITE static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t range_min, uint32_t range_max, const char *name, uint32_t value) @@ -315,7 +330,9 @@ static int cbs_av1_write_increment(CodedBitstreamContext *ctx, PutBitContext *pb return 0; } +#endif +#if CBS_READ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc, uint32_t range_max, const char *name, const int *subscripts, uint32_t *write_to) @@ -360,7 +377,9 @@ static int cbs_av1_read_subexp(CodedBitstreamContext *ctx, GetBitContext *gbc, *write_to = value; return err; } +#endif +#if CBS_WRITE static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc, uint32_t range_max, const char *name, const int *subscripts, uint32_t value) @@ -420,6 +439,7 @@ static int cbs_av1_write_subexp(CodedBitstreamContext *ctx, PutBitContext *pbc, return err; } +#endif static int cbs_av1_tile_log2(int blksize, int target) @@ -441,7 +461,7 @@ static int cbs_av1_get_relative_dist(const AV1RawSequenceHeader *seq, return diff; } -static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) +static av_unused size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) { GetBitContext tmp = *gbc; size_t size = 0; @@ -469,6 +489,7 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL) +#if CBS_READ #define fc(width, name, range_min, range_max) \ xf(width, name, current->name, range_min, range_max, 0, ) #define flag(name) fb(1, name) @@ -584,8 +605,9 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) #undef leb128 #undef infer #undef byte_alignment +#endif // CBS_READ - +#if CBS_WRITE #define WRITE #define READWRITE write #define RWContext PutBitContext @@ -668,12 +690,13 @@ static size_t cbs_av1_get_payload_bytes_left(GetBitContext *gbc) #undef leb128 #undef infer #undef byte_alignment - +#endif // CBS_WRITE static int cbs_av1_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header) { +#if CBS_READ GetBitContext gbc; uint8_t *data; size_t size; @@ -777,6 +800,9 @@ success: fail: ctx->trace_enable = trace; return err; +#else + return AVERROR(ENOSYS); +#endif } static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx, @@ -809,6 +835,7 @@ static int cbs_av1_ref_tile_data(CodedBitstreamContext *ctx, static int cbs_av1_read_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit) { +#if CBS_READ CodedBitstreamAV1Context *priv = ctx->priv_data; AV1RawOBU *obu; GetBitContext gbc; @@ -931,6 +958,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, return err; } break; +#if CBS_OBU_TILE_LIST case AV1_OBU_TILE_LIST: { err = cbs_av1_read_tile_list_obu(ctx, &gbc, @@ -946,6 +974,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, return err; } break; +#endif +#if CBS_OBU_METADATA case AV1_OBU_METADATA: { err = cbs_av1_read_metadata_obu(ctx, &gbc, &obu->obu.metadata); @@ -953,6 +983,8 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, return err; } break; +#endif +#if CBS_OBU_PADDING case AV1_OBU_PADDING: { err = cbs_av1_read_padding_obu(ctx, &gbc, &obu->obu.padding); @@ -960,6 +992,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, return err; } break; +#endif default: return AVERROR(ENOSYS); } @@ -982,12 +1015,16 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, } return 0; +#else + return AVERROR(ENOSYS); +#endif } static int cbs_av1_write_obu(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc) { +#if CBS_WRITE CodedBitstreamAV1Context *priv = ctx->priv_data; AV1RawOBU *obu = unit->content; PutBitContext pbc_tmp; @@ -1087,6 +1124,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, td = &tile_group->tile_data; } break; +#if CBS_OBU_TILE_LIST case AV1_OBU_TILE_LIST: { err = cbs_av1_write_tile_list_obu(ctx, pbc, &obu->obu.tile_list); @@ -1096,6 +1134,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, td = &obu->obu.tile_list.tile_data; } break; +#endif +#if CBS_OBU_METADATA case AV1_OBU_METADATA: { err = cbs_av1_write_metadata_obu(ctx, pbc, &obu->obu.metadata); @@ -1103,6 +1143,8 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, goto error; } break; +#endif +#if CBS_OBU_PADDING case AV1_OBU_PADDING: { err = cbs_av1_write_padding_obu(ctx, pbc, &obu->obu.padding); @@ -1110,6 +1152,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, goto error; } break; +#endif default: err = AVERROR(ENOSYS); goto error; @@ -1182,11 +1225,15 @@ error: av_buffer_unref(&av1ctx.frame_header_ref); return err; +#else + return AVERROR(ENOSYS); +#endif } static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag) { +#if CBS_WRITE size_t size, pos; int i; @@ -1210,6 +1257,9 @@ static int cbs_av1_assemble_fragment(CodedBitstreamContext *ctx, frag->data_size = size; return 0; +#else + return AVERROR(ENOSYS); +#endif } static void cbs_av1_flush(CodedBitstreamContext *ctx) @@ -1234,6 +1284,7 @@ static void cbs_av1_close(CodedBitstreamContext *ctx) av_buffer_unref(&priv->frame_header_ref); } +#if CBS_OBU_METADATA static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content) { AV1RawOBU *obu = content; @@ -1255,6 +1306,7 @@ static void cbs_av1_free_metadata(AVRefStructOpaque unused, void *content) av_buffer_unref(&md->metadata.unknown.payload_ref); } } +#endif static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = { CBS_UNIT_TYPE_POD(AV1_OBU_SEQUENCE_HEADER, AV1RawOBU), @@ -1284,13 +1336,19 @@ static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = { offsetof(AV1RawOBU, obu.frame.tile_group.tile_data.data) } }, }, +#if CBS_OBU_TILE_LIST CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_TILE_LIST, AV1RawOBU, obu.tile_list.tile_data.data), +#endif +#if CBS_OBU_PADDING CBS_UNIT_TYPE_INTERNAL_REF(AV1_OBU_PADDING, AV1RawOBU, obu.padding.payload), +#endif +#if CBS_OBU_METADATA CBS_UNIT_TYPE_COMPLEX(AV1_OBU_METADATA, AV1RawOBU, &cbs_av1_free_metadata), +#endif CBS_UNIT_TYPE_END_OF_LIST }; diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index 62c7720142..0c73e12c84 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -25,6 +25,15 @@ #include "av1.h" #include "cbs.h" +#ifndef CBS_OBU_METADATA +#define CBS_OBU_METADATA 1 +#endif +#ifndef CBS_OBU_TILE_LIST +#define CBS_OBU_TILE_LIST 1 +#endif +#ifndef CBS_OBU_PADDING +#define CBS_OBU_PADDING 1 +#endif typedef struct AV1RawOBUHeader { uint8_t obu_forbidden_bit; @@ -411,9 +420,15 @@ typedef struct AV1RawOBU { AV1RawFrameHeader frame_header; AV1RawFrame frame; AV1RawTileGroup tile_group; +#if CBS_OBU_TILE_LIST AV1RawTileList tile_list; +#endif +#if CBS_OBU_METADATA AV1RawMetadata metadata; +#endif +#if CBS_OBU_PADDING AV1RawPadding padding; +#endif } obu; } AV1RawOBU; diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c index 62a83945ec..b594bfd22b 100644 --- a/libavcodec/cbs_av1_syntax_template.c +++ b/libavcodec/cbs_av1_syntax_template.c @@ -1868,6 +1868,7 @@ static int FUNC(frame_obu)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +#if CBS_OBU_TILE_LIST static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw, AV1RawTileList *current) { @@ -1882,7 +1883,9 @@ static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +#endif +#if CBS_OBU_METADATA static int FUNC(metadata_hdr_cll)(CodedBitstreamContext *ctx, RWContext *rw, AV1RawMetadataHDRCLL *current) { @@ -2101,7 +2104,9 @@ static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +#endif +#if CBS_OBU_PADDING static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw, AV1RawPadding *current) { @@ -2125,3 +2130,4 @@ static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw, return 0; } +#endif diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 80cad2b162..f15ba1ab90 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -22,6 +22,8 @@ #include <stddef.h> #include <stdint.h> +#include "config.h" + #include "libavutil/log.h" #include "cbs.h" @@ -30,6 +32,40 @@ #include "put_bits.h" #include "libavutil/refstruct.h" +#ifndef CBS_READ +#define CBS_READ 1 +#endif +#ifndef CBS_WRITE +#define CBS_WRITE 1 +#endif +#ifndef CBS_TRACE +#define CBS_TRACE 1 +#endif + +#ifndef CBS_AV1 +#define CBS_AV1 CONFIG_CBS_AV1 +#endif +#ifndef CBS_H264 +#define CBS_H264 CONFIG_CBS_H264 +#endif +#ifndef CBS_H265 +#define CBS_H265 CONFIG_CBS_H265 +#endif +#ifndef CBS_H266 +#define CBS_H266 CONFIG_CBS_H266 +#endif +#ifndef CBS_JPEG +#define CBS_JPEG CONFIG_CBS_JPEG +#endif +#ifndef CBS_MPEG2 +#define CBS_MPEG2 CONFIG_CBS_MPEG2 +#endif +#ifndef CBS_VP8 +#define CBS_VP8 CONFIG_CBS_VP8 +#endif +#ifndef CBS_VP9 +#define CBS_VP9 CONFIG_CBS_VP9 +#endif enum CBSContentType { // Unit content may contain some references to other structures, but all @@ -204,6 +240,7 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, #define MIN_INT_BITS(length) (-(INT64_C(1) << ((length) - 1))) +#if CBS_TRACE // Start of a syntax element during read tracing. #define CBS_TRACE_READ_START() \ GetBitContext trace_start; \ @@ -284,6 +321,17 @@ int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc, } \ } while (0) +#else // CBS_TRACE +#define CBS_TRACE_READ_START() do { } while (0) +#define CBS_TRACE_READ_END() do { } while (0) +#define CBS_TRACE_READ_END_NO_SUBSCRIPTS() do { } while (0) +#define CBS_TRACE_READ_END_VALUE_ONLY() do { } while (0) +#define CBS_TRACE_WRITE_START() do { } while (0) +#define CBS_TRACE_WRITE_END() do { } while (0) +#define CBS_TRACE_WRITE_END_NO_SUBSCRIPTS() do { } while (0) +#define CBS_TRACE_WRITE_END_VALUE_ONLY() do { } while (0) +#endif // CBS_TRACE + #define TYPE_LIST(...) { __VA_ARGS__ } #define CBS_UNIT_TYPE_POD(type_, structure) { \ .nb_unit_types = 1, \ -- 2.48.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".