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
23
34
37
40
41 /* AV1 specific fields */
43
44 /* H264/HEVC specific fields */
46
47 /* AVOptions */
50
52 {
56 return 1;
57 return 0;
58 }
59
62 {
63 static const int extradata_obu_types[] = {
65 };
67
68 int extradata_size = 0, filtered_size = 0;
70 int i, has_seq = 0,
ret = 0;
71
75
76 for (
i = 0;
i <
s->av1_pkt.nb_obus;
i++) {
81 has_seq = 1;
82 }
else if (
s->remove) {
84 }
85 }
86
87 if (extradata_size && has_seq) {
90 uint8_t *extradata;
91
94 if (!filtered_buf) {
96 }
98 }
99
101 if (!extradata) {
104 }
105
107 *
size = extradata_size;
108
112
113 for (
i = 0;
i <
s->av1_pkt.nb_obus;
i++) {
115 if (
val_in_array(extradata_obu_types, nb_extradata_obu_types,
118 }
else if (
s->remove) {
120 }
121 }
122
128 }
129 }
130
131 return 0;
132 }
133
136 {
137 static const int extradata_nal_types_hevc[] = {
139 };
140 static const int extradata_nal_types_h264[] = {
142 };
143
145
146 int extradata_size = 0, filtered_size = 0;
147 const int *extradata_nal_types;
148 int nb_extradata_nal_types;
149 int i, has_sps = 0, has_vps = 0,
ret = 0;
150
152 extradata_nal_types = extradata_nal_types_hevc;
153 nb_extradata_nal_types =
FF_ARRAY_ELEMS(extradata_nal_types_hevc);
154 } else {
155 extradata_nal_types = extradata_nal_types_h264;
156 nb_extradata_nal_types =
FF_ARRAY_ELEMS(extradata_nal_types_h264);
157 }
158
160 ctx, 0, 0,
ctx->par_in->codec_id, 1, 0);
163
164 for (
i = 0;
i <
s->h2645_pkt.nb_nals;
i++) {
167 extradata_size += nal->
raw_size + 3;
171 } else {
173 }
174 }
else if (
s->remove) {
176 }
177 }
178
179 if (extradata_size &&
184 uint8_t *extradata;
185
188 if (!filtered_buf) {
190 }
192 }
193
195 if (!extradata) {
198 }
199
201 *
size = extradata_size;
202
206
207 for (
i = 0;
i <
s->h2645_pkt.nb_nals;
i++) {
209 if (
val_in_array(extradata_nal_types, nb_extradata_nal_types,
211 bytestream2_put_be24u(&pb_extradata, 1); //startcode
213 }
else if (
s->remove) {
214 bytestream2_put_be24u(&pb_filtered_data, 1); // startcode
216 }
217 }
218
224 }
225 }
226
227 return 0;
228 }
229
232 {
235 uint32_t
state = UINT32_MAX;
236 int has_extradata = 0, extradata_size = 0;
237
238 while (ptr < end) {
241 has_extradata = 1;
243 extradata_size = ptr - 4 -
pkt->
data;
244 break;
245 }
246 }
247
248 if (extradata_size) {
252
254 *
size = extradata_size;
255
259 }
260 }
261
262 return 0;
263 }
264
267 {
269 uint32_t
state = UINT32_MAX;
271
275 found = 1;
276 else if (found &&
state != 0x1B5 && state < 0x200 && state >= 0x100) {
281
283
287 }
288 break;
289 }
290 }
291 return 0;
292 }
293
296 {
299 uint32_t
state = UINT32_MAX;
300
301 while (ptr < end) {
309
311
315 }
316 }
317 break;
318 }
319 }
320 return 0;
321 }
322
323 static const struct {
338 };
339
341 {
344
348 break;
349 }
350 }
353
354 return 0;
355 }
356
358 {
360 uint8_t *extradata =
NULL;
361 int extradata_size;
363
367
368 ret =
s->extract(
ctx,
pkt, &extradata, &extradata_size);
371
372 if (extradata) {
375 extradata, extradata_size);
379 }
380 }
381
382 return 0;
383
387 }
388
390 {
394 }
395
408 };
409
410 #define OFFSET(x) offsetof(ExtractExtradataContext, x)
411 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
414 { .i64 = 0 }, 0, 1,
FLAGS },
416 };
417
423 };
424
426 .
p.
name =
"extract_extradata",
433 };