--- /dev/null
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * AV1 common definitions
+ */
+
+#ifndef AVCODEC_AV1_H
+#define AVCODEC_AV1_H
+
+// OBU types (section 6.2.2).
+typedef enum {
+ // 0 reserved.
+ AV1_OBU_SEQUENCE_HEADER = 1,
+ AV1_OBU_TEMPORAL_DELIMITER = 2,
+ AV1_OBU_FRAME_HEADER = 3,
+ AV1_OBU_TILE_GROUP = 4,
+ AV1_OBU_METADATA = 5,
+ AV1_OBU_FRAME = 6,
+ AV1_OBU_REDUNDANT_FRAME_HEADER = 7,
+ AV1_OBU_TILE_LIST = 8,
+ // 9-14 reserved.
+ AV1_OBU_PADDING = 15,
+} AV1_OBU_Type;
+
+#endif /* AVCODEC_AV1_H */
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "av1.h"
+#include "av1_parse.h"
#include "bsf.h"
#include "h2645_parse.h"
#include "h264.h"
int (*extract)(AVBSFContext *ctx, AVPacket *pkt,
uint8_t **data, int *size);
+ /* AV1 specifc fields */
+ AV1Packet av1_pkt;
+
/* H264/HEVC specifc fields */
H2645Packet h2645_pkt;
return 0;
}
+static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
+ uint8_t **data, int *size)
+{
+ static const int extradata_obu_types[] = {
+ AV1_OBU_SEQUENCE_HEADER, AV1_OBU_METADATA,
+ };
+ ExtractExtradataContext *s = ctx->priv_data;
+
+ int extradata_size = 0, filtered_size = 0;
+ int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types);
+ int i, ret = 0;
+
+ ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
+ if (ret < 0)
+ return ret;
+
+ for (i = 0; i < s->av1_pkt.nb_obus; i++) {
+ AV1OBU *obu = &s->av1_pkt.obus[i];
+ if (val_in_array(extradata_obu_types, nb_extradata_obu_types, obu->type)) {
+ extradata_size += obu->raw_size;
+ } else if (s->remove) {
+ filtered_size += obu->raw_size;
+ }
+ }
+
+ if (extradata_size) {
+ AVBufferRef *filtered_buf;
+ uint8_t *extradata, *filtered_data;
+
+ if (s->remove) {
+ filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!filtered_buf) {
+ return AVERROR(ENOMEM);
+ }
+ memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+ filtered_data = filtered_buf->data;
+ }
+
+ extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
+ if (!extradata) {
+ av_buffer_unref(&filtered_buf);
+ return AVERROR(ENOMEM);
+ }
+ memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+ *data = extradata;
+ *size = extradata_size;
+
+ for (i = 0; i < s->av1_pkt.nb_obus; i++) {
+ AV1OBU *obu = &s->av1_pkt.obus[i];
+ if (val_in_array(extradata_obu_types, nb_extradata_obu_types,
+ obu->type)) {
+ memcpy(extradata, obu->raw_data, obu->raw_size);
+ extradata += obu->raw_size;
+ } else if (s->remove) {
+ memcpy(filtered_data, obu->raw_data, obu->raw_size);
+ filtered_data += obu->raw_size;
+ }
+ }
+
+ if (s->remove) {
+ av_buffer_unref(&pkt->buf);
+ pkt->buf = filtered_buf;
+ pkt->data = filtered_buf->data;
+ pkt->size = filtered_size;
+ }
+ }
+
+ return 0;
+}
+
static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt,
uint8_t **data, int *size)
{
int (*extract)(AVBSFContext *ctx, AVPacket *pkt,
uint8_t **data, int *size);
} extract_tab[] = {
+ { AV_CODEC_ID_AV1, extract_extradata_av1 },
{ AV_CODEC_ID_CAVS, extract_extradata_mpeg4 },
{ AV_CODEC_ID_H264, extract_extradata_h2645 },
{ AV_CODEC_ID_HEVC, extract_extradata_h2645 },
static void extract_extradata_close(AVBSFContext *ctx)
{
ExtractExtradataContext *s = ctx->priv_data;
+ ff_av1_packet_uninit(&s->av1_pkt);
ff_h2645_packet_uninit(&s->h2645_pkt);
}
static const enum AVCodecID codec_ids[] = {
+ AV_CODEC_ID_AV1,
AV_CODEC_ID_CAVS,
AV_CODEC_ID_H264,
AV_CODEC_ID_HEVC,