*/
#include "libavutil/avassert.h"
+#include "libavutil/opt.h"
#include "libavutil/pixfmt.h"
#include "cbs.h"
goto fail;
}
+ if (header && size && data[0] & 0x80) {
+ // first bit is nonzero, the extradata does not consist purely of
+ // OBUs. Expect MP4/Matroska AV1CodecConfigurationRecord
+ int config_record_version = data[0] & 0x7f;
+
+ if (config_record_version != 1) {
+ av_log(ctx->log_ctx, AV_LOG_ERROR,
+ "Unknown version %d of AV1CodecConfigurationRecord "
+ "found!\n",
+ config_record_version);
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+
+ if (size <= 4) {
+ if (size < 4) {
+ av_log(ctx->log_ctx, AV_LOG_WARNING,
+ "Undersized AV1CodecConfigurationRecord v%d found!\n",
+ config_record_version);
+ err = AVERROR_INVALIDDATA;
+ goto fail;
+ }
+
+ goto success;
+ }
+
+ // In AV1CodecConfigurationRecord v1, actual OBUs start after
+ // four bytes. Thus set the offset as required for properly
+ // parsing them.
+ data += 4;
+ size -= 4;
+ }
+
while (size > 0) {
AV1RawOBUHeader header;
uint64_t obu_size;
size -= obu_length;
}
+success:
err = 0;
fail:
ctx->trace_enable = trace;
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()
}
}
}
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;
av_buffer_unref(&priv->sequence_header_ref);
priv->sequence_header = NULL;
+ err = ff_cbs_make_unit_refcounted(ctx, unit);
+ if (err < 0)
+ return err;
+
priv->sequence_header_ref = av_buffer_ref(unit->content_ref);
if (!priv->sequence_header_ref)
return AVERROR(ENOMEM);
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,