1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdint.h>
20
24
25 #include "av1.h"
32 #include "startcode.h"
34 #include "vvc.h"
35
37
40
43
44 /* AV1 specific fields */
46
47 /* H264/HEVC specific fields */
49
50 /* AVOptions */
53
55 {
56 for (
size_t i = 0;
i <
len;
i++)
58 return 1;
59 return 0;
60 }
61
63 {
64 static const int metadata_obu_types[] = {
66 };
68 int metadata_type;
69
71 return 0;
72
74
76 metadata_type);
77 }
78
80 {
81 static const int extradata_obu_types[] = {
83 };
84
87 return 0;
89 return 1;
90
92 }
93
96 {
97
99
100 int extradata_size = 0, filtered_size = 0;
101 int i, has_seq = 0,
ret = 0;
102
106
107 for (
i = 0;
i <
s->av1_pkt.nb_obus;
i++) {
112 has_seq = 1;
113 }
else if (
s->remove) {
115 }
116 }
117
118 if (extradata_size && has_seq) {
121 uint8_t *extradata;
122
125 if (!filtered_buf) {
127 }
129 }
130
132 if (!extradata) {
135 }
136
138 *
size = extradata_size;
139
143
144 for (
i = 0;
i <
s->av1_pkt.nb_obus;
i++) {
148 }
else if (
s->remove) {
150 }
151 }
152
158 }
159 }
160
161 return 0;
162 }
163
166 {
167 static const int extradata_nal_types_vvc[] = {
169 };
170 static const int extradata_nal_types_hevc[] = {
172 };
173 static const int extradata_nal_types_h264[] = {
175 };
176
178
179 int extradata_size = 0, filtered_size = 0;
180 const int *extradata_nal_types;
181 size_t nb_extradata_nal_types;
182 int i, has_sps = 0, has_vps = 0,
ret = 0;
183
185 extradata_nal_types = extradata_nal_types_vvc;
188 extradata_nal_types = extradata_nal_types_hevc;
189 nb_extradata_nal_types =
FF_ARRAY_ELEMS(extradata_nal_types_hevc);
190 } else {
191 extradata_nal_types = extradata_nal_types_h264;
192 nb_extradata_nal_types =
FF_ARRAY_ELEMS(extradata_nal_types_h264);
193 }
194
199
200 for (
i = 0;
i <
s->h2645_pkt.nb_nals;
i++) {
203 extradata_size += nal->
raw_size + 3;
210 } else {
212 }
213 }
else if (
s->remove) {
215 }
216 }
217
218 if (extradata_size &&
224 uint8_t *extradata;
225
228 if (!filtered_buf) {
230 }
232 }
233
235 if (!extradata) {
238 }
239
241 *
size = extradata_size;
242
246
247 for (
i = 0;
i <
s->h2645_pkt.nb_nals;
i++) {
249 if (
val_in_array(extradata_nal_types, nb_extradata_nal_types,
251 bytestream2_put_be24u(&pb_extradata, 1); //startcode
253 }
else if (
s->remove) {
254 bytestream2_put_be24u(&pb_filtered_data, 1); // startcode
256 }
257 }
258
264 }
265 }
266
267 return 0;
268 }
269
272 {
275 uint32_t
state = UINT32_MAX;
276 int has_extradata = 0, extradata_size = 0;
277
278 while (ptr < end) {
281 has_extradata = 1;
283 extradata_size = ptr - 4 -
pkt->
data;
284 break;
285 }
286 }
287
288 if (extradata_size) {
292
294 *
size = extradata_size;
295
299 }
300 }
301
302 return 0;
303 }
304
307 {
309 uint32_t
state = UINT32_MAX;
311
315 found = 1;
316 else if (found &&
state != 0x1B5 && state < 0x200 && state >= 0x100) {
321
323
327 }
328 break;
329 }
330 }
331 return 0;
332 }
333
336 {
339 uint32_t
state = UINT32_MAX;
340
341 while (ptr < end) {
349
351
355 }
356 }
357 break;
358 }
359 }
360 return 0;
361 }
362
363 static const struct {
379 };
380
382 {
385
389 break;
390 }
391 }
394
395 return 0;
396 }
397
399 {
401 uint8_t *extradata =
NULL;
402 int extradata_size;
404
408
409 ret =
s->extract(
ctx,
pkt, &extradata, &extradata_size);
412
413 if (extradata) {
416 extradata, extradata_size);
420 }
421 }
422
423 return 0;
424
428 }
429
431 {
435 }
436
450 };
451
452 #define OFFSET(x) offsetof(ExtractExtradataContext, x)
453 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
456 { .i64 = 0 }, 0, 1,
FLAGS },
458 };
459
465 };
466
468 .
p.
name =
"extract_extradata",
475 };