History

avcodec/extract_extradata: filter what Metadata OBUs are included in AV1 extradata

Only those that are relevant for the entire coded stream should be included.

James Almer committed 3 years ago

Commit ac648001 parent abc346d1 file · +34 −6Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/extract_extradata_bsf.c+34−6
@@ -58,16 +58,45 @@ static int val_in_array(const int *arr, int len, int val) · 57 unmodified lines
5858 return 0;
5959 }
6060
61−static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
62− uint8_t **data, int *size)
61+static int metadata_is_global(const AV1OBU *obu)
62+{
63+ static const int metadata_obu_types[] = {
64+ AV1_METADATA_TYPE_HDR_CLL, AV1_METADATA_TYPE_HDR_MDCV,
65+ };
66+ GetBitContext gb;
67+ int metadata_type;
68+
69+ if (init_get_bits(&gb, obu->data, obu->size_bits) < 0)
70+ return 0;
71+
72+ metadata_type = leb128(&gb);
73+
74+ return val_in_array(metadata_obu_types, FF_ARRAY_ELEMS(metadata_obu_types),
75+ metadata_type);
76+}
77+
78+static int obu_is_global(const AV1OBU *obu)
6379 {
6480 static const int extradata_obu_types[] = {
6581 AV1_OBU_SEQUENCE_HEADER, AV1_OBU_METADATA,
6682 };
83+
84+ if (!val_in_array(extradata_obu_types, FF_ARRAY_ELEMS(extradata_obu_types),
85+ obu->type))
86+ return 0;
87+ if (obu->type != AV1_OBU_METADATA)
88+ return 1;
89+
90+ return metadata_is_global(obu);
91+}
92+
93+static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
94+ uint8_t **data, int *size)
95+{
96+
6797 ExtractExtradataContext *s = ctx->priv_data;
6898
6999 int extradata_size = 0, filtered_size = 0;
70− int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types);
71100 int i, has_seq = 0, ret = 0;
72101
73102 ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
@@ -76,7 +105,7 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, · 2 unmodified lines
76105
77106 for (i = 0; i < s->av1_pkt.nb_obus; i++) {
78107 AV1OBU *obu = &s->av1_pkt.obus[i];
79− if (val_in_array(extradata_obu_types, nb_extradata_obu_types, obu->type)) {
108+ if (obu_is_global(obu)) {
80109 extradata_size += obu->raw_size;
81110 if (obu->type == AV1_OBU_SEQUENCE_HEADER)
82111 has_seq = 1;
@@ -113,8 +142,7 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, · 30 unmodified lines
113142
114143 for (i = 0; i < s->av1_pkt.nb_obus; i++) {
115144 AV1OBU *obu = &s->av1_pkt.obus[i];
116− if (val_in_array(extradata_obu_types, nb_extradata_obu_types,
117− obu->type)) {
145+ if (obu_is_global(obu)) {
118146 bytestream2_put_bufferu(&pb_extradata, obu->raw_data, obu->raw_size);
119147 } else if (s->remove) {
120148 bytestream2_put_bufferu(&pb_filtered_data, obu->raw_data, obu->raw_size);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t