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

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
58 return 0;58 return 0;
59}59}
60 60
61static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,61static int metadata_is_global(const AV1OBU *obu)
62 uint8_t **data, int *size)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
78static int obu_is_global(const AV1OBU *obu)
63{79{
64 static const int extradata_obu_types[] = {80 static const int extradata_obu_types[] = {
65 AV1_OBU_SEQUENCE_HEADER, AV1_OBU_METADATA,81 AV1_OBU_SEQUENCE_HEADER, AV1_OBU_METADATA,
66 };82 };
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
93static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt,
94 uint8_t **data, int *size)
95{
96
67 ExtractExtradataContext *s = ctx->priv_data;97 ExtractExtradataContext *s = ctx->priv_data;
68 98
69 int extradata_size = 0, filtered_size = 0;99 int extradata_size = 0, filtered_size = 0;
70 int nb_extradata_obu_types = FF_ARRAY_ELEMS(extradata_obu_types);
71 int i, has_seq = 0, ret = 0;100 int i, has_seq = 0, ret = 0;
72 101
73 ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);102 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
76 105
77 for (i = 0; i < s->av1_pkt.nb_obus; i++) {106 for (i = 0; i < s->av1_pkt.nb_obus; i++) {
78 AV1OBU *obu = &s->av1_pkt.obus[i];107 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)) {
80 extradata_size += obu->raw_size;109 extradata_size += obu->raw_size;
81 if (obu->type == AV1_OBU_SEQUENCE_HEADER)110 if (obu->type == AV1_OBU_SEQUENCE_HEADER)
82 has_seq = 1;111 has_seq = 1;
@@ -113,8 +142,7 @@ static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, · 30 unmodified lines
113 142
114 for (i = 0; i < s->av1_pkt.nb_obus; i++) {143 for (i = 0; i < s->av1_pkt.nb_obus; i++) {
115 AV1OBU *obu = &s->av1_pkt.obus[i];144 AV1OBU *obu = &s->av1_pkt.obus[i];
116 if (val_in_array(extradata_obu_types, nb_extradata_obu_types,145 if (obu_is_global(obu)) {
117 obu->type)) {
118 bytestream2_put_bufferu(&pb_extradata, obu->raw_data, obu->raw_size);146 bytestream2_put_bufferu(&pb_extradata, obu->raw_data, obu->raw_size);
119 } else if (s->remove) {147 } else if (s->remove) {
120 bytestream2_put_bufferu(&pb_filtered_data, obu->raw_data, obu->raw_size);148 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