FFmpeg
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 "av1.h"
26 #include "av1_parse.h"
27 #include "bsf.h"
28 #include "bsf_internal.h"
29 #include "bytestream.h"
30 #include "h2645_parse.h"
31 #include "h264.h"
32 #include "lcevc.h"
33 #include "lcevc_parse.h"
34 #include "startcode.h"
35 #include "vc1_common.h"
36 #include "vvc.h"
37 
38 #include "hevc/hevc.h"
39 
40 typedef struct ExtractExtradataContext {
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 
56 static 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 
64 static int metadata_is_global(const AV1OBU *obu)
65 {
66  static const int metadata_obu_types[] = {
68  };
69  GetBitContext gb;
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 
81 static 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 
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) {
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 
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) {
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 
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);
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 {
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 {
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 {
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 
584 static const struct {
585  enum AVCodecID id;
587  uint8_t **data, int *size);
588 } extract_tab[] = {
601 };
602 
604 {
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 {
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 
647 fail:
649  return ret;
650 }
651 
653 {
655  ff_av1_packet_uninit(&s->av1_pkt);
656  ff_h2645_packet_uninit(&s->h2645_pkt);
657 }
658 
659 static const enum AVCodecID codec_ids[] = {
673 };
674 
675 #define OFFSET(x) offsetof(ExtractExtradataContext, x)
676 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
677 static 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 };
H264_NAL_PPS
@ H264_NAL_PPS
Definition: h264.h:42
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: packet.c:432
ExtractExtradataContext::h2645_pkt
H2645Packet h2645_pkt
Definition: extract_extradata.c:50
h2645_parse.h
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
bsf_internal.h
opt.h
extract_extradata_lcevc
static int extract_extradata_lcevc(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:383
extract_extradata_h2645
static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:166
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition: bytestream.h:158
OFFSET
#define OFFSET(x)
Definition: extract_extradata.c:675
GetByteContext
Definition: bytestream.h:33
bytestream2_tell
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition: bytestream.h:192
AV_PKT_DATA_NEW_EXTRADATA
@ 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
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO
@ LCEVC_PAYLOAD_TYPE_ADDITIONAL_INFO
Definition: lcevc.h:75
extract_extradata_vc1
static int extract_extradata_vc1(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:491
bytestream2_skipu
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
ff_h2645_packet_split
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.
Definition: h2645_parse.c:527
AVBitStreamFilter::name
const char * name
Definition: bsf.h:112
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:254
av_unused
#define av_unused
Definition: attributes.h:156
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
extract_extradata_class
static const AVClass extract_extradata_class
Definition: extract_extradata.c:683
AVPacket::data
uint8_t * data
Definition: packet.h:588
AVOption
AVOption.
Definition: opt.h:429
AV_CODEC_ID_AVS2
@ AV_CODEC_ID_AVS2
Definition: codec_id.h:248
data
const char data[16]
Definition: mxf.c:149
AV1OBU
Definition: av1_parse.h:38
id
enum AVCodecID id
Definition: extract_extradata.c:585
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
extract_extradata_mpeg12
static int extract_extradata_mpeg12(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:526
ExtractExtradataContext::av1_pkt
AV1Packet av1_pkt
Definition: extract_extradata.c:47
lcevc_parse.h
obu_is_global
static int obu_is_global(const AV1OBU *obu)
Definition: extract_extradata.c:81
extract
int(* extract)(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:586
ExtractExtradataContext::remove
int remove
Definition: extract_extradata.c:53
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:517
get_mb
static uint64_t get_mb(GetBitContext *s)
Definition: lcevc_parse.h:26
AVBSFContext
The bitstream filter state.
Definition: bsf.h:68
AV1OBU::data
const uint8_t * data
Definition: av1_parse.h:41
ff_av1_packet_split
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
close
static av_cold void close(AVCodecParserContext *s)
Definition: apv_parser.c:197
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:337
av1_parse.h
bsf.h
av_packet_add_side_data
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
AV1Packet
An input packet split into OBUs.
Definition: av1_parse.h:60
fail
#define fail()
Definition: checkasm.h:221
ExtractExtradataContext::extract
int(* extract)(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:43
dummy
int dummy
Definition: motion.c:64
extract_extradata_close
static void extract_extradata_close(AVBSFContext *ctx)
Definition: extract_extradata.c:652
GetBitContext
Definition: get_bits.h:109
val
static double val(void *priv, double ch)
Definition: aeval.c:77
LCEVC_NON_IDR_NUT
@ LCEVC_NON_IDR_NUT
Definition: lcevc.h:60
extract_extradata_mpeg4
static int extract_extradata_mpeg4(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:555
ff_h2645_packet_uninit
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
Definition: h2645_parse.c:685
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:544
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:147
s
#define s(width, name)
Definition: cbs_vp9.c:198
bytestream2_tell_p
static av_always_inline int bytestream2_tell_p(const PutByteContext *p)
Definition: bytestream.h:197
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
HEVC_NAL_VPS
@ HEVC_NAL_VPS
Definition: hevc.h:61
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
hevc.h
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
AV1_METADATA_TYPE_HDR_MDCV
@ AV1_METADATA_TYPE_HDR_MDCV
Definition: av1.h:45
if
if(ret)
Definition: filter_design.txt:179
AV_CODEC_ID_AVS3
@ AV_CODEC_ID_AVS3
Definition: codec_id.h:250
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:571
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
get_leb
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
FFBitStreamFilter
Definition: bsf_internal.h:27
av_buffer_unref
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
AV_CODEC_ID_AV1
@ AV_CODEC_ID_AV1
Definition: codec_id.h:284
VC1_CODE_SEQHDR
@ VC1_CODE_SEQHDR
Definition: vc1_common.h:40
codec_ids
static enum AVCodecID codec_ids[]
Definition: extract_extradata.c:659
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:242
IS_MARKER
#define IS_MARKER(state)
Definition: dca_parser.c:52
options
Definition: swscale.c:44
VC1_CODE_ENTRYPOINT
@ VC1_CODE_ENTRYPOINT
Definition: vc1_common.h:39
extract_extradata_filter
static int extract_extradata_filter(AVBSFContext *ctx, AVPacket *pkt)
Definition: extract_extradata.c:620
avpriv_find_start_code
const uint8_t * avpriv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
ff_extract_extradata_bsf
const FFBitStreamFilter ff_extract_extradata_bsf
Definition: extract_extradata.c:690
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:53
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
PutByteContext
Definition: bytestream.h:37
FFBitStreamFilter::p
AVBitStreamFilter p
The public AVBitStreamFilter.
Definition: bsf_internal.h:31
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:550
extract_extradata_init
static int extract_extradata_init(AVBSFContext *ctx)
Definition: extract_extradata.c:603
AVPacket::size
int size
Definition: packet.h:589
VVC_VPS_NUT
@ VVC_VPS_NUT
Definition: vvc.h:43
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
size
int size
Definition: twinvq_data.h:10344
H2645NAL
Definition: h2645_parse.h:34
state
static struct @559 state
AV1_OBU_SEQUENCE_HEADER
@ AV1_OBU_SEQUENCE_HEADER
Definition: av1.h:30
options
static const AVOption options[]
Definition: extract_extradata.c:677
val_in_array
static int val_in_array(const int *arr, size_t len, int val)
Definition: extract_extradata.c:56
HEVC_NAL_PPS
@ HEVC_NAL_PPS
Definition: hevc.h:63
AV_CODEC_ID_VVC
@ AV_CODEC_ID_VVC
Definition: codec_id.h:252
AV1OBU::raw_size
int raw_size
Size of entire OBU, including header.
Definition: av1_parse.h:50
AV_CODEC_ID_LCEVC
@ AV_CODEC_ID_LCEVC
Definition: codec_id.h:615
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:77
VVC_SPS_NUT
@ VVC_SPS_NUT
Definition: vvc.h:44
vc1_common.h
AV1OBU::size_bits
int size_bits
Size, in bits, of just the data, excluding the trailing_one_bit and any trailing padding.
Definition: av1_parse.h:47
process_lcevc_nalu
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.
Definition: extract_extradata.c:283
H2645_FLAG_SMALL_PADDING
@ H2645_FLAG_SMALL_PADDING
Definition: h2645_parse.h:98
FLAGS
#define FLAGS
Definition: extract_extradata.c:676
log.h
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:50
nal
static int FUNC() nal(CodedBitstreamContext *ctx, RWContext *rw, LCEVCRawNAL *current, int nal_unit_type)
Definition: cbs_lcevc_syntax_template.c:657
extract_tab
static const struct @73 extract_tab[]
AV_CODEC_ID_CAVS
@ AV_CODEC_ID_CAVS
Definition: codec_id.h:139
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:58
AV1OBU::raw_data
const uint8_t * raw_data
Definition: av1_parse.h:51
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
AV1_METADATA_TYPE_HDR_CLL
@ AV1_METADATA_TYPE_HDR_CLL
Definition: av1.h:44
ff_av1_packet_uninit
void ff_av1_packet_uninit(AV1Packet *pkt)
Free all the allocated memory in the packet.
Definition: av1_parse.c:104
AV_CODEC_ID_VC1
@ AV_CODEC_ID_VC1
Definition: codec_id.h:122
len
int len
Definition: vorbis_enc_data.h:426
extract_extradata_av1
static int extract_extradata_av1(AVBSFContext *ctx, AVPacket *pkt, uint8_t **data, int *size)
Definition: extract_extradata.c:96
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
av_malloc
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:98
VVC_PPS_NUT
@ VVC_PPS_NUT
Definition: vvc.h:45
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
H264_NAL_SPS
@ H264_NAL_SPS
Definition: h264.h:41
ExtractExtradataContext
Definition: extract_extradata.c:40
LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG
@ LCEVC_PAYLOAD_TYPE_SEQUENCE_CONFIG
Definition: lcevc.h:70
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AV1OBU::type
int type
Definition: av1_parse.h:53
av_buffer_realloc
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
Definition: buffer.c:183
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
bytestream2_put_bufferu
static av_always_inline unsigned int bytestream2_put_bufferu(PutByteContext *p, const uint8_t *src, unsigned int size)
Definition: bytestream.h:301
AVPacket
This structure stores compressed data.
Definition: packet.h:565
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
ff_h2645_unit_requires_zero_byte
int ff_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, unsigned int type, int nal_unit_index)
Definition: h2645_parse.c:667
LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG
@ LCEVC_PAYLOAD_TYPE_GLOBAL_CONFIG
Definition: lcevc.h:71
bytestream.h
h264.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
metadata_is_global
static int metadata_is_global(const AV1OBU *obu)
Definition: extract_extradata.c:64
ff_bsf_get_packet_ref
int ff_bsf_get_packet_ref(AVBSFContext *ctx, AVPacket *pkt)
Called by bitstream filters to get packet for filtering.
Definition: bsf.c:256
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
pkt
static AVPacket * pkt
Definition: demux_decode.c:55
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
LCEVC_IDR_NUT
@ LCEVC_IDR_NUT
Definition: lcevc.h:61
H2645Packet
Definition: h2645_parse.h:82
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1291
AV1_OBU_METADATA
@ AV1_OBU_METADATA
Definition: av1.h:34