[FFmpeg-devel] [PATCH 3/4 v3] avcodec/cbs_av1: add an option to select an operating point

James Almer jamrial at gmail.com
Sun Nov 15 23:55:40 EET 2020


This implements the function drop_obu() as defined in Setion 6.2.1 from the
spec.
In a reading only scenario, units that belong to an operating point the
caller doesn't want should not be parsed.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/cbs_av1.c | 30 +++++++++++++++++++++++++++++-
 libavcodec/cbs_av1.h |  5 +++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 9badfe31e4..81662114a1 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -17,6 +17,7 @@
  */
 
 #include "libavutil/avassert.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixfmt.h"
 
 #include "cbs.h"
@@ -883,7 +884,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
             int in_spatial_layer  =
                 (priv->operating_point_idc >> (priv->spatial_id + 8)) & 1;
             if (!in_temporal_layer || !in_spatial_layer) {
-                // Decoding will drop this OBU at this operating point.
+                return AVERROR(EAGAIN); // drop_obu()
             }
         }
     }
@@ -896,6 +897,18 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx,
             if (err < 0)
                 return err;
 
+            if (priv->operating_point >= 0) {
+                AV1RawSequenceHeader *sequence_header = &obu->obu.sequence_header;
+
+                if (priv->operating_point > sequence_header->operating_points_cnt_minus_1) {
+                    av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid Operating Point %d requested. "
+                                                       "Must not be higher than %u.\n",
+                           priv->operating_point, sequence_header->operating_points_cnt_minus_1);
+                    return AVERROR(EINVAL);
+                }
+                priv->operating_point_idc = sequence_header->operating_point_idc[priv->operating_point];
+            }
+
             av_buffer_unref(&priv->sequence_header_ref);
             priv->sequence_header = NULL;
 
@@ -1253,9 +1266,24 @@ static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = {
     CBS_UNIT_TYPE_END_OF_LIST
 };
 
+#define OFFSET(x) offsetof(CodedBitstreamAV1Context, x)
+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 },
+    { NULL }
+};
+
+static const AVClass cbs_av1_class = {
+    .class_name = "cbs_av1",
+    .item_name  = av_default_item_name,
+    .option     = cbs_av1_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 const CodedBitstreamType ff_cbs_type_av1 = {
     .codec_id          = AV_CODEC_ID_AV1,
 
+    .priv_class        = &cbs_av1_class,
     .priv_data_size    = sizeof(CodedBitstreamAV1Context),
 
     .unit_types        = cbs_av1_unit_types,
diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index 386774750a..e4e0a8ba40 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -421,6 +421,8 @@ typedef struct AV1ReferenceFrameState {
 } AV1ReferenceFrameState;
 
 typedef struct CodedBitstreamAV1Context {
+    const AVClass *class;
+
     AV1RawSequenceHeader *sequence_header;
     AVBufferRef          *sequence_header_ref;
 
@@ -449,6 +451,9 @@ typedef struct CodedBitstreamAV1Context {
     int tile_num;
 
     AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES];
+
+    // AVOptions
+    int operating_point;
 } CodedBitstreamAV1Context;
 
 
-- 
2.29.2



More information about the ffmpeg-devel mailing list