FFmpeg
Loading...
Searching...
No Matches
extract_extradata.c
Go to the documentation of this file.
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
21#include "libavutil/log.h"
22#include "libavutil/mem.h"
23#include "libavutil/opt.h"
24
25#include "libavcodec/av1.h"
27#include "libavcodec/bsf.h"
31#include "libavcodec/h264.h"
32#include "libavcodec/lcevc.h"
36#include "libavcodec/vvc.h"
37
39
41 const AVClass *class;
42
44 uint8_t **data, int *size);
45
46 /* AV1 specific fields */
48
49 /* H264/HEVC specific fields */
51
52 /* AVOptions */
53 int remove;
55
56static int val_in_array(const int *arr, size_t len, int val)
57{
58 for (size_t i = 0; i < len; i++)
59 if (arr[i] == val)
60 return 1;
61 return 0;
62}
63
64static int metadata_is_global(const AV1OBU *obu)
65{
66 static const int metadata_obu_types[] = {
68 };
70 int metadata_type;
71
72 if (init_get_bits(&gb, obu->data, obu->size_bits) < 0)
73 return 0;
74
75 metadata_type = get_leb(&gb);
76
77 return val_in_array(metadata_obu_types, FF_ARRAY_ELEMS(metadata_obu_types),
78 metadata_type);
79}
80
81static int obu_is_global(const AV1OBU *obu)
82{
83 static const int extradata_obu_types[] = {
85 };
86
87 if (!val_in_array(extradata_obu_types, FF_ARRAY_ELEMS(extradata_obu_types),
88 obu->type))
89 return 0;
90 if (obu->type != AV1_OBU_METADATA)
91 return 1;
92
93 return metadata_is_global(obu);
94}
95
97 uint8_t **data, int *size)
98{
99
100 ExtractExtradataContext *s = ctx->priv_data;
101
102 int extradata_size = 0, filtered_size = 0;
103 int i, has_seq = 0, ret = 0;
104
105 ret = ff_av1_packet_split(&s->av1_pkt, pkt->data, pkt->size, ctx);
106 if (ret < 0)
107 return ret;
108
109 for (i = 0; i < s->av1_pkt.nb_obus; i++) {
110 AV1OBU *obu = &s->av1_pkt.obus[i];
111 if (obu_is_global(obu)) {
112 extradata_size += obu->raw_size;
113 if (obu->type == AV1_OBU_SEQUENCE_HEADER)
114 has_seq = 1;
115 } else {
116 filtered_size += obu->raw_size;
117 }
118 }
119
120 if (extradata_size && has_seq) {
121 AVBufferRef *filtered_buf = NULL;
122 PutByteContext pb_filtered_data, pb_extradata;
123 uint8_t *extradata;
124
125 if (s->remove) {
126 filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
127 if (!filtered_buf) {
128 return AVERROR(ENOMEM);
129 }
130 memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
131 }
132
133 extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
134 if (!extradata) {
135 av_buffer_unref(&filtered_buf);
136 return AVERROR(ENOMEM);
137 }
138
139 *data = extradata;
140 *size = extradata_size;
141
142 bytestream2_init_writer(&pb_extradata, extradata, extradata_size);
143 if (s->remove)
144 bytestream2_init_writer(&pb_filtered_data, filtered_buf->data, filtered_size);
145
146 for (i = 0; i < s->av1_pkt.nb_obus; i++) {
147 AV1OBU *obu = &s->av1_pkt.obus[i];
148 if (obu_is_global(obu)) {
149 bytestream2_put_bufferu(&pb_extradata, obu->raw_data, obu->raw_size);
150 } else if (s->remove) {
151 bytestream2_put_bufferu(&pb_filtered_data, obu->raw_data, obu->raw_size);
152 }
153 }
154
155 if (s->remove) {
156 av_buffer_unref(&pkt->buf);
157 pkt->buf = filtered_buf;
158 pkt->data = filtered_buf->data;
159 pkt->size = filtered_size;
160 }
161 }
162
163 return 0;
164}
165
167 uint8_t **data, int *size)
168{
169 static const int extradata_nal_types_vvc[] = {
171 };
172 static const int extradata_nal_types_hevc[] = {
174 };
175 static const int extradata_nal_types_h264[] = {
177 };
178
179 ExtractExtradataContext *s = ctx->priv_data;
180
181 int extradata_size = 0, filtered_size = 0;
182 const int *extradata_nal_types;
183 size_t nb_extradata_nal_types;
184 int filtered_nb_nals = 0;
185 int i, has_sps = 0, has_vps = 0, ret = 0;
186
187 if (ctx->par_in->codec_id == AV_CODEC_ID_VVC) {
188 extradata_nal_types = extradata_nal_types_vvc;
189 nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_vvc);
190 } else if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {
191 extradata_nal_types = extradata_nal_types_hevc;
192 nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_hevc);
193 } else {
194 extradata_nal_types = extradata_nal_types_h264;
195 nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_h264);
196 }
197
198 ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size,
199 ctx, 0, ctx->par_in->codec_id, H2645_FLAG_SMALL_PADDING);
200 if (ret < 0)
201 return ret;
202
203 for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
204 H2645NAL *nal = &s->h2645_pkt.nals[i];
205 if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) {
206 extradata_size += nal->raw_size + 4;
207 if (ctx->par_in->codec_id == AV_CODEC_ID_VVC) {
208 if (nal->type == VVC_SPS_NUT) has_sps = 1;
209 if (nal->type == VVC_VPS_NUT) has_vps = 1;
210 } else if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) {
211 if (nal->type == HEVC_NAL_SPS) has_sps = 1;
212 if (nal->type == HEVC_NAL_VPS) has_vps = 1;
213 } else {
214 if (nal->type == H264_NAL_SPS) has_sps = 1;
215 }
216 } else {
217 filtered_size += nal->raw_size + 3 +
218 ff_h2645_unit_requires_zero_byte(ctx->par_in->codec_id, nal->type, filtered_nb_nals++);
219 }
220 }
221
222 if (extradata_size &&
223 ((ctx->par_in->codec_id == AV_CODEC_ID_VVC && has_sps) ||
224 (ctx->par_in->codec_id == AV_CODEC_ID_HEVC && has_sps && has_vps) ||
225 (ctx->par_in->codec_id == AV_CODEC_ID_H264 && has_sps))) {
226 AVBufferRef *filtered_buf = NULL;
227 PutByteContext pb_filtered_data, pb_extradata;
228 uint8_t *extradata;
229
230 if (s->remove) {
231 filtered_buf = av_buffer_alloc(filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
232 if (!filtered_buf) {
233 return AVERROR(ENOMEM);
234 }
235 memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
236 }
237
238 extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
239 if (!extradata) {
240 av_buffer_unref(&filtered_buf);
241 return AVERROR(ENOMEM);
242 }
243
244 *data = extradata;
245 *size = extradata_size;
246
247 bytestream2_init_writer(&pb_extradata, extradata, extradata_size);
248 if (s->remove)
249 bytestream2_init_writer(&pb_filtered_data, filtered_buf->data, filtered_size);
250
251 filtered_nb_nals = 0;
252 for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
253 H2645NAL *nal = &s->h2645_pkt.nals[i];
254 if (val_in_array(extradata_nal_types, nb_extradata_nal_types,
255 nal->type)) {
256 bytestream2_put_be32u(&pb_extradata, 1); //startcode
257 bytestream2_put_bufferu(&pb_extradata, nal->raw_data, nal->raw_size);
258 } else if (s->remove) {
259 if (ff_h2645_unit_requires_zero_byte(ctx->par_in->codec_id, nal->type, filtered_nb_nals++))
260 bytestream2_put_byteu(&pb_filtered_data, 0); // zero_byte
261 bytestream2_put_be24u(&pb_filtered_data, 1); // startcode
262 bytestream2_put_bufferu(&pb_filtered_data, nal->raw_data, nal->raw_size);
263 }
264 }
265
266 if (s->remove) {
267 av_buffer_unref(&pkt->buf);
268 pkt->buf = filtered_buf;
269 pkt->data = filtered_buf->data;
270 pkt->size = filtered_size;
271 }
272 }
273
274 return 0;
275}
276
277/**
278 * Rewrite the NALu stripping the unneeded blocks.
279 * Given that length fields coded inside the NALu are not aware of any emulation_3bytes
280 * present in the bitstream, we need to keep track of the raw buffer as we navigate
281 * the stripped buffer.
282 */
284 int *extradata_sizep, int *data_sizep, const H2645NAL *nal)
285{
286 GetByteContext gbc, raw_gbc;
287 int sc = 0, gc = 0;
288 int skipped_byte_pos = 0;
289 int extradata_size = 0, data_size = 0;
290
291 if (nal->size < 2)
292 return AVERROR_INVALIDDATA;
293
294 bytestream2_init(&gbc, nal->data, nal->size);
295 bytestream2_init(&raw_gbc, nal->raw_data, nal->raw_size);
296
297 unsigned nalu_header = bytestream2_get_be16u(&gbc);
298
299 if (data)
300 bytestream2_put_be16u(data, nalu_header);
301 data_size += 2;
302 bytestream2_skipu(&raw_gbc, 2);
303
304 while (bytestream2_get_bytes_left(&gbc) > 1) {
305 GetBitContext gb;
306 int payload_size_type, payload_type;
307 uint64_t payload_size;
308 int block_size, raw_block_size, block_end;
309
311 av_assert1(ret >= 0); // h2645_parse already opened a GetBitContext with this data
312
313 payload_size_type = get_bits(&gb, 3);
314 payload_type = get_bits(&gb, 5);
315 payload_size = payload_size_type;
316 if (payload_size_type == 6)
317 return AVERROR_INVALIDDATA;
318 if (payload_size_type == 7)
319 payload_size = get_mb(&gb);
320
321 if (payload_size > INT_MAX - (get_bits_count(&gb) >> 3))
322 return AVERROR_INVALIDDATA;
323
324 block_size = raw_block_size = payload_size + (get_bits_count(&gb) >> 3);
325 if (block_size >= bytestream2_get_bytes_left(&gbc))
326 return AVERROR_INVALIDDATA;
327
328 block_end = bytestream2_tell(&gbc) + block_size;
329 // Take into account removed emulation 3bytes, as payload_size in
330 // the bitstream is not aware of them.
331 for (; skipped_byte_pos < nal->skipped_bytes; skipped_byte_pos++) {
332 if (nal->skipped_bytes_pos[skipped_byte_pos] >= block_end)
333 break;
334 raw_block_size++;
335 }
336 if (raw_block_size > bytestream2_get_bytes_left(&raw_gbc))
337 return AVERROR_INVALIDDATA;
338
339 switch (payload_type) {
343 if (!extradata_size) {
344 extradata_size = 2;
345 if (extradata)
346 bytestream2_put_be16u(extradata, nalu_header);
347 }
348 if (extradata)
349 bytestream2_put_bufferu(extradata, raw_gbc.buffer, raw_block_size);
350 extradata_size += raw_block_size;
351 sc |= payload_type == LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG;
352 gc |= payload_type == LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG;
353 break;
354 default:
355 if (data)
356 bytestream2_put_bufferu(data, raw_gbc.buffer, raw_block_size);
357 data_size += raw_block_size;
358 break;
359 }
360
361 bytestream2_skip(&gbc, block_size);
362 bytestream2_skip(&raw_gbc, raw_block_size);
363 }
364
365 ++data_size;
366 *data_sizep = data_size;
367 if (data)
368 bytestream2_put_byteu(data, 0x80); // rbsp_alignment bits
369 if (extradata_size > 0) {
370 if (!sc && !gc)
371 return AVERROR_INVALIDDATA;
372
373 ++extradata_size;
374 if (extradata) {
375 bytestream2_put_byteu(extradata, 0x80); // rbsp_alignment bits
376 } else
377 *extradata_sizep = extradata_size;
378 return 1; // has extradata
379 }
380 return 0; // no extradata
381}
382
384 uint8_t **data, int *size)
385{
386 static const int extradata_nal_types[] = {
388 };
389
390 ExtractExtradataContext *s = ctx->priv_data;
391 unsigned extradata_size = 0, filtered_size = 0;
392 size_t nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types);
393 int i, ret = 0;
394
395 ret = ff_h2645_packet_split(&s->h2645_pkt, pkt->data, pkt->size,
397 if (ret < 0)
398 return ret;
399
400 for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
401 H2645NAL *nal = &s->h2645_pkt.nals[i];
402 unsigned start_code_size = 3 + !filtered_size;
403
404 if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) {
405 int extra_size, data_size;
406 ret = process_lcevc_nalu(NULL, NULL, &extra_size, &data_size, nal);
407 if (ret < 0)
408 return ret;
409 if (ret > 0) { // has extradata
410 unsigned extra_start_code_size = 3 + !extradata_size;
411 extradata_size += extra_start_code_size + extra_size;
412 if (extradata_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
413 return AVERROR_INVALIDDATA;
414 }
415 filtered_size += start_code_size + data_size;
416 } else
417 filtered_size += start_code_size + nal->raw_size;
418 if (filtered_size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
419 return AVERROR_INVALIDDATA;
420 }
421
422 if (extradata_size) {
423 AVBufferRef *filtered_buf = NULL;
424 PutByteContext pb_extradata;
425 PutByteContext pb_filtered_data;
426 uint8_t *extradata;
427
428 if (s->remove) {
429 ret = av_buffer_realloc(&filtered_buf, filtered_size + AV_INPUT_BUFFER_PADDING_SIZE);
430 if (ret < 0)
431 return ret;
432 bytestream2_init_writer(&pb_filtered_data, filtered_buf->data, filtered_size);
433 // this is the first byte of a four-byte startcode; we write it here
434 // so that we only need to write three-byte startcodes below
435 bytestream2_put_byteu(&pb_filtered_data, 0x00);
436 }
437
438 extradata = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
439 if (!extradata) {
440 av_buffer_unref(&filtered_buf);
441 return AVERROR(ENOMEM);
442 }
443
444 *data = extradata;
445 *size = extradata_size;
446
447 bytestream2_init_writer(&pb_extradata, extradata, extradata_size);
448 // We write the startcodes before the actual units because we do not
449 // know in advance whether a given unit will contribute to extradata,
450 // but we know when we have encountered the last unit containing
451 // extradata. (The alternative is writing it and then undoing this
452 // if the NALU did not contain extradata.)
453 bytestream2_put_be32u(&pb_extradata, 0x00000001);
454
455 for (i = 0; i < s->h2645_pkt.nb_nals; i++) {
456 H2645NAL *nal = &s->h2645_pkt.nals[i];
457 if (s->remove)
458 bytestream2_put_be24u(&pb_filtered_data, 0x000001);
459 if (val_in_array(extradata_nal_types, nb_extradata_nal_types,
460 nal->type)) {
461 int dummy;
462 ret = process_lcevc_nalu(&pb_extradata, s->remove ? &pb_filtered_data : NULL,
463 NULL, &dummy, nal);
464 av_assert1(ret >= 0); // already checked in the first pass
465 if (ret > 0) {// NALU contained extradata
466 if (extradata_size != bytestream2_tell_p(&pb_extradata)) {
467 // There will be another NALU containing extradata.
468 // Already write the next start code.
469 bytestream2_put_be24u(&pb_extradata, 0x000001);
470 }
471 }
472 } else if (s->remove) {
473 bytestream2_put_bufferu(&pb_filtered_data, nal->raw_data, nal->raw_size);
474 }
475 }
476 av_assert1(bytestream2_tell_p(&pb_extradata) == extradata_size);
477
478 if (s->remove) {
479 av_assert1(bytestream2_tell_p(&pb_filtered_data) == filtered_size);
480 memset(filtered_buf->data + filtered_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
481 av_buffer_unref(&pkt->buf);
482 pkt->buf = filtered_buf;
483 pkt->data = filtered_buf->data;
484 pkt->size = filtered_size;
485 }
486 }
487
488 return 0;
489}
490
492 uint8_t **data, int *size)
493{
494 ExtractExtradataContext *s = ctx->priv_data;
495 const uint8_t *ptr = pkt->data, *end = pkt->data + pkt->size;
496 uint32_t state = UINT32_MAX;
497 int has_extradata = 0, extradata_size = 0;
498
499 while (ptr < end) {
500 ptr = avpriv_find_start_code(ptr, end, &state);
502 has_extradata = 1;
503 } else if (has_extradata && IS_MARKER(state)) {
504 extradata_size = ptr - 4 - pkt->data;
505 break;
506 }
507 }
508
509 if (extradata_size) {
510 *data = av_malloc(extradata_size + AV_INPUT_BUFFER_PADDING_SIZE);
511 if (!*data)
512 return AVERROR(ENOMEM);
513
514 memcpy(*data, pkt->data, extradata_size);
515 *size = extradata_size;
516
517 if (s->remove) {
518 pkt->data += extradata_size;
519 pkt->size -= extradata_size;
520 }
521 }
522
523 return 0;
524}
525
527 uint8_t **data, int *size)
528{
529 ExtractExtradataContext *s = ctx->priv_data;
530 uint32_t state = UINT32_MAX;
531 int i, found = 0;
532
533 for (i = 0; i < pkt->size; i++) {
534 state = (state << 8) | pkt->data[i];
535 if (state == 0x1B3)
536 found = 1;
537 else if (found && state != 0x1B5 && state < 0x200 && state >= 0x100) {
538 *size = i - 3;
540 if (!*data)
541 return AVERROR(ENOMEM);
542
543 memcpy(*data, pkt->data, *size);
544
545 if (s->remove) {
546 pkt->data += *size;
547 pkt->size -= *size;
548 }
549 break;
550 }
551 }
552 return 0;
553}
554
556 uint8_t **data, int *size)
557{
558 ExtractExtradataContext *s = ctx->priv_data;
559 const uint8_t *ptr = pkt->data, *end = pkt->data + pkt->size;
560 uint32_t state = UINT32_MAX;
561
562 while (ptr < end) {
563 ptr = avpriv_find_start_code(ptr, end, &state);
564 if (state == 0x1B3 || state == 0x1B6) {
565 if (ptr - pkt->data > 4) {
566 *size = ptr - 4 - pkt->data;
568 if (!*data)
569 return AVERROR(ENOMEM);
570
571 memcpy(*data, pkt->data, *size);
572
573 if (s->remove) {
574 pkt->data += *size;
575 pkt->size -= *size;
576 }
577 }
578 break;
579 }
580 }
581 return 0;
582}
583
584static const struct {
587 uint8_t **data, int *size);
588} extract_tab[] = {
602
604{
605 ExtractExtradataContext *s = ctx->priv_data;
606 int i;
607
608 for (i = 0; i < FF_ARRAY_ELEMS(extract_tab); i++) {
609 if (extract_tab[i].id == ctx->par_in->codec_id) {
610 s->extract = extract_tab[i].extract;
611 break;
612 }
613 }
614 if (!s->extract)
615 return AVERROR_BUG;
616
617 return 0;
618}
619
621{
622 ExtractExtradataContext *s = ctx->priv_data;
623 uint8_t *extradata = NULL;
624 int extradata_size;
625 int ret = 0;
626
628 if (ret < 0)
629 return ret;
630
631 ret = s->extract(ctx, pkt, &extradata, &extradata_size);
632 if (ret < 0)
633 goto fail;
634
635 if (extradata) {
636 memset(extradata + extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
638 extradata, extradata_size);
639 if (ret < 0) {
640 av_freep(&extradata);
641 goto fail;
642 }
643 }
644
645 return 0;
646
647fail:
649 return ret;
650}
651
653{
654 ExtractExtradataContext *s = ctx->priv_data;
655 ff_av1_packet_uninit(&s->av1_pkt);
656 ff_h2645_packet_uninit(&s->h2645_pkt);
657}
658
674
675#define OFFSET(x) offsetof(ExtractExtradataContext, x)
676#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
677static const AVOption options[] = {
678 { "remove", "remove the extradata from the bitstream", OFFSET(remove), AV_OPT_TYPE_INT,
679 { .i64 = 0 }, 0, 1, FLAGS },
680 { NULL },
681};
682
684 .class_name = "extract_extradata",
685 .item_name = av_default_item_name,
686 .option = options,
687 .version = LIBAVUTIL_VERSION_INT,
688};
689
691 .p.name = "extract_extradata",
692 .p.codec_ids = codec_ids,
693 .p.priv_class = &extract_extradata_class,
694 .priv_data_size = sizeof(ExtractExtradataContext),
698};
static enum AVCodecID codec_ids[]
static double val(void *priv, double ch)
Definition aeval.c:77
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
void ff_av1_packet_uninit(AV1Packet *pkt)
Free all the allocated memory in the packet.
Definition av1_parse.c:104
int ff_av1_packet_split(AV1Packet *pkt, const uint8_t *buf, int length, void *logctx)
Split an input packet into OBUs.
Definition av1_parse.c:56
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
const FFBitStreamFilter ff_extract_extradata_bsf
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition bsf.c:254
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
Definition bytestream.h:197
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition bytestream.h:147
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition bytestream.h:174
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
static av_always_inline unsigned int bytestream2_put_bufferu(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition bytestream.h:301
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition bytestream.h:168
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition bytestream.h:192
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
#define IS_MARKER(state)
Definition dca_parser.c:52
static AVPacket * pkt
enum AVCodecID id
Definition dts2pts.c:607
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static struct @346255127015250356166251341105367306144006377143 state
static int process_lcevc_nalu(PutByteContext *extradata, PutByteContext *data, int *extradata_sizep, int *data_sizep, const H2645NAL *nal)
Rewrite the NALu stripping the unneeded blocks.
static int val_in_array(const int *arr, size_t len, int val)
static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
static int obu_is_global(const AV1OBU *obu)
static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
int(* extract)(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
static const AVClass extract_extradata_class
static void extract_extradata_close(AVBSFContext *ctx)
static int extract_extradata_init(AVBSFContext *ctx)
static int extract_extradata_lcevc(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
static int metadata_is_global(const AV1OBU *obu)
static int extract_extradata_filter(AVBSFContext *ctx, AVPacket *pkt)
static int extract_extradata_mpeg4(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
static const struct @141020031372067255335240224214247101260310362216 extract_tab[]
static int extract_extradata_mpeg12(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
#define OFFSET(x)
static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
static int dummy
Definition ffplay.c:3754
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static int get_bits_count(const GetBitContext *s)
Definition get_bits.h:254
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition get_bits.h:517
#define fail
Definition test.h:479
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_AVS3
Definition codec_id.h:245
@ AV_CODEC_ID_LCEVC
Definition codec_id.h:609
@ AV_CODEC_ID_H264
Definition codec_id.h:77
@ AV_CODEC_ID_NONE
Definition codec_id.h:48
@ AV_CODEC_ID_VVC
Definition codec_id.h:247
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
@ AV_CODEC_ID_VC1
Definition codec_id.h:120
@ AV_CODEC_ID_CAVS
Definition codec_id.h:137
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
@ AV_CODEC_ID_AVS2
Definition codec_id.h:243
@ AV_CODEC_ID_MPEG1VIDEO
Definition codec_id.h:51
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition codec_id.h:52
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
Definition packet.h:56
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition packet.c:434
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
Definition packet.c:197
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:139
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
Definition buffer.c:183
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition buffer.c:77
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
@ H2645_FLAG_SMALL_PADDING
Definition h2645_parse.h:98
H.264 common definitions.
@ H264_NAL_PPS
Definition h264.h:42
@ H264_NAL_SPS
Definition h264.h:41
static uint64_t get_mb(GetBitContext *s)
Definition lcevc_parse.h:26
static unsigned get_leb(GetBitContext *s)
Read a unsigned integer coded as a variable number of up to eight little-endian bytes,...
Definition leb.h:35
AV1 common definitions.
@ AV1_METADATA_TYPE_HDR_MDCV
Definition av1.h:45
@ AV1_METADATA_TYPE_HDR_CLL
Definition av1.h:44
@ AV1_OBU_METADATA
Definition av1.h:34
@ AV1_OBU_SEQUENCE_HEADER
Definition av1.h:30
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int nal_length_size, enum AVCodecID codec_id, int flags)
Split an input packet into NAL units.
int ff_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, unsigned int type, int nal_unit_index)
@ HEVC_NAL_PPS
Definition hevc.h:63
@ HEVC_NAL_VPS
Definition hevc.h:61
@ HEVC_NAL_SPS
Definition hevc.h:62
LCEVC common definitions.
@ LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO
Definition lcevc.h:75
@ LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG
Definition lcevc.h:71
@ LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG
Definition lcevc.h:70
@ LCEVC_NON_IDR_NUT
Definition lcevc.h:60
@ LCEVC_IDR_NUT
Definition lcevc.h:61
@ VVC_SPS_NUT
Definition vvc.h:44
@ VVC_VPS_NUT
Definition vvc.h:43
@ VVC_PPS_NUT
Definition vvc.h:45
#define av_unused
Definition attributes.h:164
Memory handling functions.
const char data[16]
Definition mxf.c:149
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
#define FF_ARRAY_ELEMS(a)
Accelerated start code search function for start codes common to MPEG-1/2/4 video,...
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
int size_bits
Size, in bits, of just the data, excluding the trailing_one_bit and any trailing padding.
Definition av1_parse.h:47
const uint8_t * data
Definition av1_parse.h:41
int type
Definition av1_parse.h:53
int raw_size
Size of entire OBU, including header.
Definition av1_parse.h:50
const uint8_t * raw_data
Definition av1_parse.h:51
An input packet split into OBUs.
Definition av1_parse.h:60
The bitstream filter state.
Definition bsf.h:68
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Describe the class of an AVClass context structure.
Definition log.h:76
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
int(* extract)(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
const uint8_t * buffer
Definition bytestream.h:34
#define av_freep(p)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
Definition h263dsp.c:29
int size
@ VC1_CODE_SEQHDR
Definition vc1_common.h:40
@ VC1_CODE_ENTRYPOINT
Definition vc1_common.h:39
int len