FFmpeg
cbs_h2645.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 "libavutil/attributes.h"
20 #include "libavutil/avassert.h"
21 
22 #include "bytestream.h"
23 #include "cbs.h"
24 #include "cbs_internal.h"
25 #include "cbs_h264.h"
26 #include "cbs_h265.h"
27 #include "cbs_h266.h"
28 #include "h264.h"
29 #include "h2645_parse.h"
30 #include "hevc.h"
31 #include "vvc.h"
32 
33 
35  const char *name, const int *subscripts,
36  uint32_t *write_to,
37  uint32_t range_min, uint32_t range_max)
38 {
39  uint32_t leading_bits, value;
40  int max_length, leading_zeroes;
41 
43 
44  max_length = FFMIN(get_bits_left(gbc), 32);
45 
46  leading_bits = show_bits_long(gbc, max_length);
47  if (leading_bits == 0) {
48  if (max_length >= 32) {
49  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at "
50  "%s: more than 31 zeroes.\n", name);
51  return AVERROR_INVALIDDATA;
52  } else {
53  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at "
54  "%s: bitstream ended.\n", name);
55  return AVERROR_INVALIDDATA;
56  }
57  }
58 
59  leading_zeroes = max_length - 1 - av_log2(leading_bits);
60  skip_bits_long(gbc, leading_zeroes);
61 
62  if (get_bits_left(gbc) < leading_zeroes + 1) {
63  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at "
64  "%s: bitstream ended.\n", name);
65  return AVERROR_INVALIDDATA;
66  }
67 
68  value = get_bits_long(gbc, leading_zeroes + 1) - 1;
69 
71 
72  if (value < range_min || value > range_max) {
73  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
74  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
75  name, value, range_min, range_max);
76  return AVERROR_INVALIDDATA;
77  }
78 
79  *write_to = value;
80  return 0;
81 }
82 
84  const char *name, const int *subscripts,
85  int32_t *write_to,
86  int32_t range_min, int32_t range_max)
87 {
88  uint32_t leading_bits, unsigned_value;
89  int max_length, leading_zeroes;
90  int32_t value;
91 
93 
94  max_length = FFMIN(get_bits_left(gbc), 32);
95 
96  leading_bits = show_bits_long(gbc, max_length);
97  if (leading_bits == 0) {
98  if (max_length >= 32) {
99  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at "
100  "%s: more than 31 zeroes.\n", name);
101  return AVERROR_INVALIDDATA;
102  } else {
103  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at "
104  "%s: bitstream ended.\n", name);
105  return AVERROR_INVALIDDATA;
106  }
107  }
108 
109  leading_zeroes = max_length - 1 - av_log2(leading_bits);
110  skip_bits_long(gbc, leading_zeroes);
111 
112  if (get_bits_left(gbc) < leading_zeroes + 1) {
113  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at "
114  "%s: bitstream ended.\n", name);
115  return AVERROR_INVALIDDATA;
116  }
117 
118  unsigned_value = get_bits_long(gbc, leading_zeroes + 1);
119 
120  if (unsigned_value & 1)
121  value = -(int32_t)(unsigned_value / 2);
122  else
123  value = unsigned_value / 2;
124 
126 
127  if (value < range_min || value > range_max) {
128  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
129  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
130  name, value, range_min, range_max);
131  return AVERROR_INVALIDDATA;
132  }
133 
134  *write_to = value;
135  return 0;
136 }
137 
139  const char *name, const int *subscripts,
140  uint32_t value,
141  uint32_t range_min, uint32_t range_max)
142 {
143  int len;
144 
146 
147  if (value < range_min || value > range_max) {
148  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
149  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
150  name, value, range_min, range_max);
151  return AVERROR_INVALIDDATA;
152  }
153  av_assert0(value != UINT32_MAX);
154 
155  len = av_log2(value + 1);
156  if (put_bits_left(pbc) < 2 * len + 1)
157  return AVERROR(ENOSPC);
158 
159  put_bits(pbc, len, 0);
160  if (len + 1 < 32)
161  put_bits(pbc, len + 1, value + 1);
162  else
163  put_bits32(pbc, value + 1);
164 
166 
167  return 0;
168 }
169 
171  const char *name, const int *subscripts,
172  int32_t value,
173  int32_t range_min, int32_t range_max)
174 {
175  int len;
176  uint32_t uvalue;
177 
179 
180  if (value < range_min || value > range_max) {
181  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
182  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
183  name, value, range_min, range_max);
184  return AVERROR_INVALIDDATA;
185  }
186  av_assert0(value != INT32_MIN);
187 
188  if (value == 0)
189  uvalue = 0;
190  else if (value > 0)
191  uvalue = 2 * (uint32_t)value - 1;
192  else
193  uvalue = 2 * (uint32_t)-value;
194 
195  len = av_log2(uvalue + 1);
196  if (put_bits_left(pbc) < 2 * len + 1)
197  return AVERROR(ENOSPC);
198 
199  put_bits(pbc, len, 0);
200  if (len + 1 < 32)
201  put_bits(pbc, len + 1, uvalue + 1);
202  else
203  put_bits32(pbc, uvalue + 1);
204 
206 
207  return 0;
208 }
209 
210 // payload_extension_present() - true if we are before the last 1-bit
211 // in the payload structure, which must be in the last byte.
212 static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t payload_size,
213  int cur_pos)
214 {
215  int bits_left = payload_size * 8 - cur_pos;
216  return (bits_left > 0 &&
217  (bits_left > 7 || show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1)));
218 }
219 
220 #define HEADER(name) do { \
221  ff_cbs_trace_header(ctx, name); \
222  } while (0)
223 
224 #define CHECK(call) do { \
225  err = (call); \
226  if (err < 0) \
227  return err; \
228  } while (0)
229 
230 #define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
231 #define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
232 #define FUNC_H264(name) FUNC_NAME1(READWRITE, h264, name)
233 #define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name)
234 #define FUNC_H266(name) FUNC_NAME1(READWRITE, h266, name)
235 #define FUNC_SEI(name) FUNC_NAME1(READWRITE, sei, name)
236 
237 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
238 
239 #define u(width, name, range_min, range_max) \
240  xu(width, name, current->name, range_min, range_max, 0, )
241 #define flag(name) ub(1, name)
242 #define ue(name, range_min, range_max) \
243  xue(name, current->name, range_min, range_max, 0, )
244 #define i(width, name, range_min, range_max) \
245  xi(width, name, current->name, range_min, range_max, 0, )
246 #define ib(width, name) \
247  xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, )
248 #define se(name, range_min, range_max) \
249  xse(name, current->name, range_min, range_max, 0, )
250 
251 #define us(width, name, range_min, range_max, subs, ...) \
252  xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
253 #define ubs(width, name, subs, ...) \
254  xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
255 #define flags(name, subs, ...) \
256  xu(1, name, current->name, 0, 1, subs, __VA_ARGS__)
257 #define ues(name, range_min, range_max, subs, ...) \
258  xue(name, current->name, range_min, range_max, subs, __VA_ARGS__)
259 #define is(width, name, range_min, range_max, subs, ...) \
260  xi(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
261 #define ibs(width, name, subs, ...) \
262  xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), subs, __VA_ARGS__)
263 #define ses(name, range_min, range_max, subs, ...) \
264  xse(name, current->name, range_min, range_max, subs, __VA_ARGS__)
265 
266 #define fixed(width, name, value) do { \
267  av_unused uint32_t fixed_value = value; \
268  xu(width, name, fixed_value, value, value, 0, ); \
269  } while (0)
270 
271 
272 #define READ
273 #define READWRITE read
274 #define RWContext GetBitContext
275 
276 #define ub(width, name) do { \
277  uint32_t value; \
278  CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
279  &value)); \
280  current->name = value; \
281  } while (0)
282 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
283  uint32_t value; \
284  CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
285  SUBSCRIPTS(subs, __VA_ARGS__), \
286  &value, range_min, range_max)); \
287  var = value; \
288  } while (0)
289 #define xue(name, var, range_min, range_max, subs, ...) do { \
290  uint32_t value; \
291  CHECK(cbs_read_ue_golomb(ctx, rw, #name, \
292  SUBSCRIPTS(subs, __VA_ARGS__), \
293  &value, range_min, range_max)); \
294  var = value; \
295  } while (0)
296 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
297  int32_t value; \
298  CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
299  SUBSCRIPTS(subs, __VA_ARGS__), \
300  &value, range_min, range_max)); \
301  var = value; \
302  } while (0)
303 #define xse(name, var, range_min, range_max, subs, ...) do { \
304  int32_t value; \
305  CHECK(cbs_read_se_golomb(ctx, rw, #name, \
306  SUBSCRIPTS(subs, __VA_ARGS__), \
307  &value, range_min, range_max)); \
308  var = value; \
309  } while (0)
310 
311 
312 #define infer(name, value) do { \
313  current->name = value; \
314  } while (0)
315 
317 {
318  int bits_left = get_bits_left(gbc);
319  if (bits_left > 8)
320  return 1;
321  if (bits_left == 0)
322  return 0;
323  if (show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1))
324  return 1;
325  return 0;
326 }
327 
328 #define more_rbsp_data(var) ((var) = cbs_h2645_read_more_rbsp_data(rw))
329 
330 #define bit_position(rw) (get_bits_count(rw))
331 #define byte_alignment(rw) (get_bits_count(rw) % 8)
332 
333 #define allocate(name, size) do { \
334  name ## _ref = av_buffer_allocz(size + \
335  AV_INPUT_BUFFER_PADDING_SIZE); \
336  if (!name ## _ref) \
337  return AVERROR(ENOMEM); \
338  name = name ## _ref->data; \
339  } while (0)
340 
341 #define FUNC(name) FUNC_SEI(name)
342 #include "cbs_sei_syntax_template.c"
343 #undef FUNC
344 
345 #define FUNC(name) FUNC_H264(name)
347 #undef FUNC
348 
349 #define FUNC(name) FUNC_H265(name)
351 #undef FUNC
352 
353 #define FUNC(name) FUNC_H266(name)
355 #undef FUNC
356 
357 #undef READ
358 #undef READWRITE
359 #undef RWContext
360 #undef ub
361 #undef xu
362 #undef xi
363 #undef xue
364 #undef xse
365 #undef infer
366 #undef more_rbsp_data
367 #undef bit_position
368 #undef byte_alignment
369 #undef allocate
370 
371 
372 #define WRITE
373 #define READWRITE write
374 #define RWContext PutBitContext
375 
376 #define ub(width, name) do { \
377  uint32_t value = current->name; \
378  CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
379  value)); \
380  } while (0)
381 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
382  uint32_t value = var; \
383  CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
384  SUBSCRIPTS(subs, __VA_ARGS__), \
385  value, range_min, range_max)); \
386  } while (0)
387 #define xue(name, var, range_min, range_max, subs, ...) do { \
388  uint32_t value = var; \
389  CHECK(cbs_write_ue_golomb(ctx, rw, #name, \
390  SUBSCRIPTS(subs, __VA_ARGS__), \
391  value, range_min, range_max)); \
392  } while (0)
393 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
394  int32_t value = var; \
395  CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
396  SUBSCRIPTS(subs, __VA_ARGS__), \
397  value, range_min, range_max)); \
398  } while (0)
399 #define xse(name, var, range_min, range_max, subs, ...) do { \
400  int32_t value = var; \
401  CHECK(cbs_write_se_golomb(ctx, rw, #name, \
402  SUBSCRIPTS(subs, __VA_ARGS__), \
403  value, range_min, range_max)); \
404  } while (0)
405 
406 #define infer(name, value) do { \
407  if (current->name != (value)) { \
408  av_log(ctx->log_ctx, AV_LOG_ERROR, \
409  "%s does not match inferred value: " \
410  "%"PRId64", but should be %"PRId64".\n", \
411  #name, (int64_t)current->name, (int64_t)(value)); \
412  return AVERROR_INVALIDDATA; \
413  } \
414  } while (0)
415 
416 #define more_rbsp_data(var) (var)
417 
418 #define bit_position(rw) (put_bits_count(rw))
419 #define byte_alignment(rw) (put_bits_count(rw) % 8)
420 
421 #define allocate(name, size) do { \
422  if (!name) { \
423  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s must be set " \
424  "for writing.\n", #name); \
425  return AVERROR_INVALIDDATA; \
426  } \
427  } while (0)
428 
429 #define FUNC(name) FUNC_SEI(name)
430 #include "cbs_sei_syntax_template.c"
431 #undef FUNC
432 
433 #define FUNC(name) FUNC_H264(name)
435 #undef FUNC
436 
437 #define FUNC(name) FUNC_H265(name)
439 #undef FUNC
440 
441 #define FUNC(name) FUNC_H266(name)
443 #undef FUNC
444 
445 #undef WRITE
446 #undef READWRITE
447 #undef RWContext
448 #undef ub
449 #undef xu
450 #undef xi
451 #undef xue
452 #undef xse
453 #undef u
454 #undef i
455 #undef flag
456 #undef ue
457 #undef se
458 #undef infer
459 #undef more_rbsp_data
460 #undef bit_position
461 #undef byte_alignment
462 #undef allocate
463 
464 
467  const H2645Packet *packet)
468 {
469  int err, i;
470 
471  for (i = 0; i < packet->nb_nals; i++) {
472  const H2645NAL *nal = &packet->nals[i];
473  AVBufferRef *ref;
474  size_t size = nal->size;
475  enum AVCodecID codec_id = ctx->codec->codec_id;
476 
477  if (codec_id != AV_CODEC_ID_VVC && nal->nuh_layer_id > 0)
478  continue;
479 
480  // Remove trailing zeroes.
481  while (size > 0 && nal->data[size - 1] == 0)
482  --size;
483  if (size == 0) {
484  av_log(ctx->log_ctx, AV_LOG_VERBOSE, "Discarding empty 0 NAL unit\n");
485  continue;
486  }
487 
488  ref = (nal->data == nal->raw_data) ? frag->data_ref
489  : packet->rbsp.rbsp_buffer_ref;
490 
491  err = ff_cbs_append_unit_data(frag, nal->type,
492  (uint8_t*)nal->data, size, ref);
493  if (err < 0)
494  return err;
495  }
496 
497  return 0;
498 }
499 
502  int header)
503 {
504  enum AVCodecID codec_id = ctx->codec->codec_id;
506  GetByteContext gbc;
507  int err;
508 
509  av_assert0(frag->data && frag->nb_units == 0);
510  if (frag->data_size == 0)
511  return 0;
512 
513  if (header && frag->data[0] && codec_id == AV_CODEC_ID_H264) {
514  // AVCC header.
515  size_t size, start, end;
516  int i, count, version;
517 
518  priv->mp4 = 1;
519 
520  bytestream2_init(&gbc, frag->data, frag->data_size);
521 
522  if (bytestream2_get_bytes_left(&gbc) < 6)
523  return AVERROR_INVALIDDATA;
524 
525  version = bytestream2_get_byte(&gbc);
526  if (version != 1) {
527  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid AVCC header: "
528  "first byte %u.\n", version);
529  return AVERROR_INVALIDDATA;
530  }
531 
532  bytestream2_skip(&gbc, 3);
533  priv->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1;
534 
535  // SPS array.
536  count = bytestream2_get_byte(&gbc) & 0x1f;
537  start = bytestream2_tell(&gbc);
538  for (i = 0; i < count; i++) {
539  if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i))
540  return AVERROR_INVALIDDATA;
541  size = bytestream2_get_be16(&gbc);
542  if (bytestream2_get_bytes_left(&gbc) < size)
543  return AVERROR_INVALIDDATA;
544  bytestream2_skip(&gbc, size);
545  }
546  end = bytestream2_tell(&gbc);
547 
548  err = ff_h2645_packet_split(&priv->read_packet,
549  frag->data + start, end - start,
550  ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1);
551  if (err < 0) {
552  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n");
553  return err;
554  }
555  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
556  if (err < 0)
557  return err;
558 
559  // PPS array.
560  count = bytestream2_get_byte(&gbc);
561  start = bytestream2_tell(&gbc);
562  for (i = 0; i < count; i++) {
563  if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i))
564  return AVERROR_INVALIDDATA;
565  size = bytestream2_get_be16(&gbc);
566  if (bytestream2_get_bytes_left(&gbc) < size)
567  return AVERROR_INVALIDDATA;
568  bytestream2_skip(&gbc, size);
569  }
570  end = bytestream2_tell(&gbc);
571 
572  err = ff_h2645_packet_split(&priv->read_packet,
573  frag->data + start, end - start,
574  ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1);
575  if (err < 0) {
576  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n");
577  return err;
578  }
579  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
580  if (err < 0)
581  return err;
582 
583  if (bytestream2_get_bytes_left(&gbc) > 0) {
584  av_log(ctx->log_ctx, AV_LOG_WARNING, "%u bytes left at end of AVCC "
585  "header.\n", bytestream2_get_bytes_left(&gbc));
586  }
587 
588  } else if (header && frag->data[0] && codec_id == AV_CODEC_ID_HEVC) {
589  // HVCC header.
590  size_t size, start, end;
591  int i, j, nb_arrays, nal_unit_type, nb_nals, version;
592 
593  priv->mp4 = 1;
594 
595  bytestream2_init(&gbc, frag->data, frag->data_size);
596 
597  if (bytestream2_get_bytes_left(&gbc) < 23)
598  return AVERROR_INVALIDDATA;
599 
600  version = bytestream2_get_byte(&gbc);
601  if (version != 1) {
602  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid HVCC header: "
603  "first byte %u.\n", version);
604  return AVERROR_INVALIDDATA;
605  }
606 
607  bytestream2_skip(&gbc, 20);
608  priv->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1;
609 
610  nb_arrays = bytestream2_get_byte(&gbc);
611  for (i = 0; i < nb_arrays; i++) {
612  nal_unit_type = bytestream2_get_byte(&gbc) & 0x3f;
613  nb_nals = bytestream2_get_be16(&gbc);
614 
615  start = bytestream2_tell(&gbc);
616  for (j = 0; j < nb_nals; j++) {
617  if (bytestream2_get_bytes_left(&gbc) < 2)
618  return AVERROR_INVALIDDATA;
619  size = bytestream2_get_be16(&gbc);
620  if (bytestream2_get_bytes_left(&gbc) < size)
621  return AVERROR_INVALIDDATA;
622  bytestream2_skip(&gbc, size);
623  }
624  end = bytestream2_tell(&gbc);
625 
626  err = ff_h2645_packet_split(&priv->read_packet,
627  frag->data + start, end - start,
628  ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 1);
629  if (err < 0) {
630  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
631  "HVCC array %d (%d NAL units of type %d).\n",
632  i, nb_nals, nal_unit_type);
633  return err;
634  }
635  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
636  if (err < 0)
637  return err;
638  }
639 
640  } else if(header && frag->data[0] && codec_id == AV_CODEC_ID_VVC) {
641  // VVCC header.
642  int ptl_present_flag, num_arrays;
643  int b, i, j;
644 
645  priv->mp4 = 1;
646 
647  bytestream2_init(&gbc, frag->data, frag->data_size);
648 
649  b = bytestream2_get_byte(&gbc);
650  priv->nal_length_size = ((b >> 1) & 3) + 1;
651  ptl_present_flag = b & 1;
652 
653  if(ptl_present_flag) {
654  int num_sublayers, num_bytes_constraint_info, num_sub_profiles;
655  num_sublayers = (bytestream2_get_be16u(&gbc) >> 4) & 7;
656  bytestream2_skip(&gbc, 1);
657 
658  // begin VvcPTLRecord(num_sublayers);
659  num_bytes_constraint_info = bytestream2_get_byte(&gbc) & 0x3f;
660  bytestream2_skip(&gbc, 2 + num_bytes_constraint_info);
661  if(num_sublayers > 1) {
662  int count_present_flags = 0;
663  b = bytestream2_get_byte(&gbc);
664  for(i = num_sublayers - 2; i >= 0; i--) {
665  if((b >> (7 - (num_sublayers - 2 - i))) & 0x01)
666  count_present_flags++;
667  }
668  bytestream2_skip(&gbc, count_present_flags);
669  }
670  num_sub_profiles = bytestream2_get_byte(&gbc);
671  bytestream2_skip(&gbc, num_sub_profiles * 4);
672  // end VvcPTLRecord(num_sublayers);
673 
674  bytestream2_skip(&gbc, 3 * 2);
675  }
676 
677  num_arrays = bytestream2_get_byte(&gbc);
678  for(j = 0; j < num_arrays; j++) {
679  size_t start, end, size;
680  int nal_unit_type = bytestream2_get_byte(&gbc) & 0x1f;
681  unsigned int num_nalus = 1;
682  if(nal_unit_type != VVC_DCI_NUT && nal_unit_type != VVC_OPI_NUT)
683  num_nalus = bytestream2_get_be16(&gbc);
684 
685  start = bytestream2_tell(&gbc);
686  for(i = 0; i < num_nalus; i++) {
687  size = bytestream2_get_be16(&gbc);
688  bytestream2_skip(&gbc, size);
689  }
690  end = bytestream2_tell(&gbc);
691 
692  err = ff_h2645_packet_split(&priv->read_packet,
693  frag->data + start, end - start,
694  ctx->log_ctx, 1, 2, AV_CODEC_ID_VVC, 1, 1);
695  if (err < 0) {
696  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
697  "VVCC array %d (%d NAL units of type %d).\n",
698  i, num_nalus, nal_unit_type);
699  return err;
700  }
701  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
702  if (err < 0)
703  return err;
704  }
705  } else {
706  // Annex B, or later MP4 with already-known parameters.
707 
708  err = ff_h2645_packet_split(&priv->read_packet,
709  frag->data, frag->data_size,
710  ctx->log_ctx,
711  priv->mp4, priv->nal_length_size,
712  codec_id, 1, 1);
713  if (err < 0)
714  return err;
715 
716  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
717  if (err < 0)
718  return err;
719  }
720 
721  return 0;
722 }
723 
724 #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
725 static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
726  CodedBitstreamUnit *unit) \
727 { \
728  CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
729  H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
730  unsigned int id = ps_var->id_element; \
731  int err = ff_cbs_make_unit_refcounted(ctx, unit); \
732  if (err < 0) \
733  return err; \
734  if (priv->ps_var[id] == priv->active_ ## ps_var) \
735  priv->active_ ## ps_var = NULL ; \
736  av_buffer_unref(&priv->ps_var ## _ref[id]); \
737  av_assert0(unit->content_ref); \
738  priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
739  if (!priv->ps_var ## _ref[id]) \
740  return AVERROR(ENOMEM); \
741  priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \
742  return 0; \
743 }
744 
745 cbs_h2645_replace_ps(4, SPS, sps, seq_parameter_set_id)
746 cbs_h2645_replace_ps(4, PPS, pps, pic_parameter_set_id)
747 cbs_h2645_replace_ps(5, VPS, vps, vps_video_parameter_set_id)
748 cbs_h2645_replace_ps(5, SPS, sps, sps_seq_parameter_set_id)
749 cbs_h2645_replace_ps(5, PPS, pps, pps_pic_parameter_set_id)
750 
751 #define cbs_h266_replace_ps(h26n, ps_name, ps_var, id_element) \
752 static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
753  CodedBitstreamUnit *unit) \
754 { \
755  CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
756  H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
757  unsigned int id = ps_var->id_element; \
758  int err = ff_cbs_make_unit_refcounted(ctx, unit); \
759  if (err < 0) \
760  return err; \
761  av_buffer_unref(&priv->ps_var ## _ref[id]); \
762  av_assert0(unit->content_ref); \
763  priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
764  if (!priv->ps_var ## _ref[id]) \
765  return AVERROR(ENOMEM); \
766  priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \
767  return 0; \
768 }
769 
770 cbs_h266_replace_ps(6, VPS, vps, vps_video_parameter_set_id)
771 cbs_h266_replace_ps(6, SPS, sps, sps_seq_parameter_set_id)
772 cbs_h266_replace_ps(6, PPS, pps, pps_pic_parameter_set_id)
773 
774 static int cbs_h266_replace_ph(CodedBitstreamContext *ctx,
775  CodedBitstreamUnit *unit,
777 {
779  int err;
780 
781  err = ff_cbs_make_unit_refcounted(ctx, unit);
782  if (err < 0)
783  return err;
784  av_assert0(unit->content_ref);
785  err = av_buffer_replace(&h266->ph_ref, unit->content_ref);
786  if (err < 0)
787  return err;
788  h266->ph = ph;
789  return 0;
790 }
791 
793  CodedBitstreamUnit *unit)
794 {
795  GetBitContext gbc;
796  int err;
797 
798  err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
799  if (err < 0)
800  return err;
801 
802  err = ff_cbs_alloc_unit_content(ctx, unit);
803  if (err < 0)
804  return err;
805 
806  switch (unit->type) {
807  case H264_NAL_SPS:
808  {
809  H264RawSPS *sps = unit->content;
810 
811  err = cbs_h264_read_sps(ctx, &gbc, sps);
812  if (err < 0)
813  return err;
814 
815  err = cbs_h264_replace_sps(ctx, unit);
816  if (err < 0)
817  return err;
818  }
819  break;
820 
821  case H264_NAL_SPS_EXT:
822  {
823  err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content);
824  if (err < 0)
825  return err;
826  }
827  break;
828 
829  case H264_NAL_PPS:
830  {
831  H264RawPPS *pps = unit->content;
832 
833  err = cbs_h264_read_pps(ctx, &gbc, pps);
834  if (err < 0)
835  return err;
836 
837  err = cbs_h264_replace_pps(ctx, unit);
838  if (err < 0)
839  return err;
840  }
841  break;
842 
843  case H264_NAL_SLICE:
844  case H264_NAL_IDR_SLICE:
846  {
847  H264RawSlice *slice = unit->content;
848  int pos, len;
849 
850  err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header);
851  if (err < 0)
852  return err;
853 
855  return AVERROR_INVALIDDATA;
856 
857  pos = get_bits_count(&gbc);
858  len = unit->data_size;
859 
860  slice->data_size = len - pos / 8;
861  slice->data_ref = av_buffer_ref(unit->data_ref);
862  if (!slice->data_ref)
863  return AVERROR(ENOMEM);
864  slice->data = unit->data + pos / 8;
865  slice->data_bit_start = pos % 8;
866  }
867  break;
868 
869  case H264_NAL_AUD:
870  {
871  err = cbs_h264_read_aud(ctx, &gbc, unit->content);
872  if (err < 0)
873  return err;
874  }
875  break;
876 
877  case H264_NAL_SEI:
878  {
879  err = cbs_h264_read_sei(ctx, &gbc, unit->content);
880  if (err < 0)
881  return err;
882  }
883  break;
884 
886  {
887  err = cbs_h264_read_filler(ctx, &gbc, unit->content);
888  if (err < 0)
889  return err;
890  }
891  break;
892 
894  case H264_NAL_END_STREAM:
895  {
896  err = (unit->type == H264_NAL_END_SEQUENCE ?
897  cbs_h264_read_end_of_sequence :
898  cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content);
899  if (err < 0)
900  return err;
901  }
902  break;
903 
904  default:
905  return AVERROR(ENOSYS);
906  }
907 
908  return 0;
909 }
910 
912  CodedBitstreamUnit *unit)
913 {
914  GetBitContext gbc;
915  int err;
916 
917  err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
918  if (err < 0)
919  return err;
920 
921  err = ff_cbs_alloc_unit_content(ctx, unit);
922  if (err < 0)
923  return err;
924 
925  switch (unit->type) {
926  case HEVC_NAL_VPS:
927  {
928  H265RawVPS *vps = unit->content;
929 
930  err = cbs_h265_read_vps(ctx, &gbc, vps);
931  if (err < 0)
932  return err;
933 
934  err = cbs_h265_replace_vps(ctx, unit);
935  if (err < 0)
936  return err;
937  }
938  break;
939  case HEVC_NAL_SPS:
940  {
941  H265RawSPS *sps = unit->content;
942 
943  err = cbs_h265_read_sps(ctx, &gbc, sps);
944  if (err < 0)
945  return err;
946 
947  err = cbs_h265_replace_sps(ctx, unit);
948  if (err < 0)
949  return err;
950  }
951  break;
952 
953  case HEVC_NAL_PPS:
954  {
955  H265RawPPS *pps = unit->content;
956 
957  err = cbs_h265_read_pps(ctx, &gbc, pps);
958  if (err < 0)
959  return err;
960 
961  err = cbs_h265_replace_pps(ctx, unit);
962  if (err < 0)
963  return err;
964  }
965  break;
966 
967  case HEVC_NAL_TRAIL_N:
968  case HEVC_NAL_TRAIL_R:
969  case HEVC_NAL_TSA_N:
970  case HEVC_NAL_TSA_R:
971  case HEVC_NAL_STSA_N:
972  case HEVC_NAL_STSA_R:
973  case HEVC_NAL_RADL_N:
974  case HEVC_NAL_RADL_R:
975  case HEVC_NAL_RASL_N:
976  case HEVC_NAL_RASL_R:
977  case HEVC_NAL_BLA_W_LP:
978  case HEVC_NAL_BLA_W_RADL:
979  case HEVC_NAL_BLA_N_LP:
980  case HEVC_NAL_IDR_W_RADL:
981  case HEVC_NAL_IDR_N_LP:
982  case HEVC_NAL_CRA_NUT:
983  {
984  H265RawSlice *slice = unit->content;
985  int pos, len;
986 
987  err = cbs_h265_read_slice_segment_header(ctx, &gbc, &slice->header);
988  if (err < 0)
989  return err;
990 
992  return AVERROR_INVALIDDATA;
993 
994  pos = get_bits_count(&gbc);
995  len = unit->data_size;
996 
997  slice->data_size = len - pos / 8;
998  slice->data_ref = av_buffer_ref(unit->data_ref);
999  if (!slice->data_ref)
1000  return AVERROR(ENOMEM);
1001  slice->data = unit->data + pos / 8;
1002  slice->data_bit_start = pos % 8;
1003  }
1004  break;
1005 
1006  case HEVC_NAL_AUD:
1007  {
1008  err = cbs_h265_read_aud(ctx, &gbc, unit->content);
1009  if (err < 0)
1010  return err;
1011  }
1012  break;
1013 
1014  case HEVC_NAL_SEI_PREFIX:
1015  case HEVC_NAL_SEI_SUFFIX:
1016  {
1017  err = cbs_h265_read_sei(ctx, &gbc, unit->content,
1018  unit->type == HEVC_NAL_SEI_PREFIX);
1019 
1020  if (err < 0)
1021  return err;
1022  }
1023  break;
1024 
1025  default:
1026  return AVERROR(ENOSYS);
1027  }
1028 
1029  return 0;
1030 }
1031 
1033  CodedBitstreamUnit *unit)
1034 {
1035  GetBitContext gbc;
1036  int err;
1037 
1038  err = init_get_bits8(&gbc, unit->data, unit->data_size);
1039  if (err < 0)
1040  return err;
1041 
1042  err = ff_cbs_alloc_unit_content(ctx, unit);
1043  if (err < 0)
1044  return err;
1045 
1046  switch (unit->type) {
1047  case VVC_DCI_NUT:
1048  {
1049  err = cbs_h266_read_dci(ctx, &gbc, unit->content);
1050 
1051  if (err < 0)
1052  return err;
1053  }
1054  break;
1055  case VVC_OPI_NUT:
1056  {
1057  err = cbs_h266_read_opi(ctx, &gbc, unit->content);
1058 
1059  if (err < 0)
1060  return err;
1061  }
1062  break;
1063  case VVC_VPS_NUT:
1064  {
1065  H266RawVPS *vps = unit->content;
1066 
1067  err = cbs_h266_read_vps(ctx, &gbc, vps);
1068  if (err < 0)
1069  return err;
1070 
1071  err = cbs_h266_replace_vps(ctx, unit);
1072  if (err < 0)
1073  return err;
1074  }
1075  break;
1076  case VVC_SPS_NUT:
1077  {
1078  H266RawSPS *sps = unit->content;
1079 
1080  err = cbs_h266_read_sps(ctx, &gbc, sps);
1081  if (err < 0)
1082  return err;
1083 
1084  err = cbs_h266_replace_sps(ctx, unit);
1085  if (err < 0)
1086  return err;
1087  }
1088  break;
1089 
1090  case VVC_PPS_NUT:
1091  {
1092  H266RawPPS *pps = unit->content;
1093 
1094  err = cbs_h266_read_pps(ctx, &gbc, pps);
1095  if (err < 0)
1096  return err;
1097 
1098  err = cbs_h266_replace_pps(ctx, unit);
1099  if (err < 0)
1100  return err;
1101  }
1102  break;
1103 
1104  case VVC_PREFIX_APS_NUT:
1105  case VVC_SUFFIX_APS_NUT:
1106  {
1107  err = cbs_h266_read_aps(ctx, &gbc, unit->content,
1108  unit->type == VVC_PREFIX_APS_NUT);
1109 
1110  if (err < 0)
1111  return err;
1112  }
1113  break;
1114  case VVC_PH_NUT:
1115  {
1116  H266RawPH *ph = unit->content;
1117  err = cbs_h266_read_ph(ctx, &gbc, ph);
1118  if (err < 0)
1119  return err;
1120  err = cbs_h266_replace_ph(ctx, unit, &ph->ph_picture_header);
1121  if (err < 0)
1122  return err;
1123  }
1124  break;
1125 
1126  case VVC_TRAIL_NUT:
1127  case VVC_STSA_NUT:
1128  case VVC_RADL_NUT:
1129  case VVC_RASL_NUT:
1130  case VVC_IDR_W_RADL:
1131  case VVC_IDR_N_LP:
1132  case VVC_CRA_NUT:
1133  case VVC_GDR_NUT:
1134  {
1135  H266RawSlice *slice = unit->content;
1136  int pos, len;
1137 
1138  err = cbs_h266_read_slice_header(ctx, &gbc, &slice->header);
1139  if (err < 0)
1140  return err;
1141 
1142  if (!cbs_h2645_read_more_rbsp_data(&gbc))
1143  return AVERROR_INVALIDDATA;
1144 
1145  pos = get_bits_count(&gbc);
1146  len = unit->data_size;
1147 
1149  err = cbs_h266_replace_ph(ctx, unit, &slice->header.sh_picture_header);
1150  if (err < 0)
1151  return err;
1152  }
1153 
1154  slice->data_size = len - pos / 8;
1155  slice->data_ref = av_buffer_ref(unit->data_ref);
1156  if (!slice->data_ref)
1157  return AVERROR(ENOMEM);
1158  slice->data = unit->data + pos / 8;
1159  slice->data_bit_start = pos % 8;
1160  }
1161  break;
1162 
1163  case VVC_AUD_NUT:
1164  {
1165  err = cbs_h266_read_aud(ctx, &gbc, unit->content);
1166  if (err < 0)
1167  return err;
1168  }
1169  break;
1170 
1171  case VVC_PREFIX_SEI_NUT:
1172  case VVC_SUFFIX_SEI_NUT:
1173  {
1174  err = cbs_h266_read_sei(ctx, &gbc, unit->content,
1175  unit->type == VVC_PREFIX_SEI_NUT);
1176 
1177  if (err < 0)
1178  return err;
1179  }
1180  break;
1181 
1182  default:
1183  return AVERROR(ENOSYS);
1184  }
1185  return 0;
1186 }
1187 
1189  PutBitContext *pbc, const uint8_t *data,
1190  size_t data_size, int data_bit_start)
1191 {
1192  size_t rest = data_size - (data_bit_start + 7) / 8;
1193  const uint8_t *pos = data + data_bit_start / 8;
1194 
1195  av_assert0(data_bit_start >= 0 &&
1196  data_size > data_bit_start / 8);
1197 
1198  if (data_size * 8 + 8 > put_bits_left(pbc))
1199  return AVERROR(ENOSPC);
1200 
1201  if (!rest)
1202  goto rbsp_stop_one_bit;
1203 
1204  // First copy the remaining bits of the first byte
1205  // The above check ensures that we do not accidentally
1206  // copy beyond the rbsp_stop_one_bit.
1207  if (data_bit_start % 8)
1208  put_bits(pbc, 8 - data_bit_start % 8,
1209  *pos++ & MAX_UINT_BITS(8 - data_bit_start % 8));
1210 
1211  if (put_bits_count(pbc) % 8 == 0) {
1212  // If the writer is aligned at this point,
1213  // memcpy can be used to improve performance.
1214  // This happens normally for CABAC.
1215  flush_put_bits(pbc);
1216  memcpy(put_bits_ptr(pbc), pos, rest);
1217  skip_put_bytes(pbc, rest);
1218  } else {
1219  // If not, we have to copy manually.
1220  // rbsp_stop_one_bit forces us to special-case
1221  // the last byte.
1222  uint8_t temp;
1223  int i;
1224 
1225  for (; rest > 4; rest -= 4, pos += 4)
1226  put_bits32(pbc, AV_RB32(pos));
1227 
1228  for (; rest > 1; rest--, pos++)
1229  put_bits(pbc, 8, *pos);
1230 
1231  rbsp_stop_one_bit:
1232  temp = rest ? *pos : *pos & MAX_UINT_BITS(8 - data_bit_start % 8);
1233 
1234  av_assert0(temp);
1235  i = ff_ctz(*pos);
1236  temp = temp >> i;
1237  i = rest ? (8 - i) : (8 - i - data_bit_start % 8);
1238  put_bits(pbc, i, temp);
1239  if (put_bits_count(pbc) % 8)
1240  put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0);
1241  }
1242 
1243  return 0;
1244 }
1245 
1247  CodedBitstreamUnit *unit,
1248  PutBitContext *pbc)
1249 {
1250  int err;
1251 
1252  switch (unit->type) {
1253  case H264_NAL_SPS:
1254  {
1255  H264RawSPS *sps = unit->content;
1256 
1257  err = cbs_h264_write_sps(ctx, pbc, sps);
1258  if (err < 0)
1259  return err;
1260 
1261  err = cbs_h264_replace_sps(ctx, unit);
1262  if (err < 0)
1263  return err;
1264  }
1265  break;
1266 
1267  case H264_NAL_SPS_EXT:
1268  {
1269  H264RawSPSExtension *sps_ext = unit->content;
1270 
1271  err = cbs_h264_write_sps_extension(ctx, pbc, sps_ext);
1272  if (err < 0)
1273  return err;
1274  }
1275  break;
1276 
1277  case H264_NAL_PPS:
1278  {
1279  H264RawPPS *pps = unit->content;
1280 
1281  err = cbs_h264_write_pps(ctx, pbc, pps);
1282  if (err < 0)
1283  return err;
1284 
1285  err = cbs_h264_replace_pps(ctx, unit);
1286  if (err < 0)
1287  return err;
1288  }
1289  break;
1290 
1291  case H264_NAL_SLICE:
1292  case H264_NAL_IDR_SLICE:
1294  {
1295  H264RawSlice *slice = unit->content;
1296 
1297  err = cbs_h264_write_slice_header(ctx, pbc, &slice->header);
1298  if (err < 0)
1299  return err;
1300 
1301  if (slice->data) {
1302  err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
1303  slice->data_size,
1304  slice->data_bit_start);
1305  if (err < 0)
1306  return err;
1307  } else {
1308  // No slice data - that was just the header.
1309  // (Bitstream may be unaligned!)
1310  }
1311  }
1312  break;
1313 
1314  case H264_NAL_AUD:
1315  {
1316  err = cbs_h264_write_aud(ctx, pbc, unit->content);
1317  if (err < 0)
1318  return err;
1319  }
1320  break;
1321 
1322  case H264_NAL_SEI:
1323  {
1324  err = cbs_h264_write_sei(ctx, pbc, unit->content);
1325  if (err < 0)
1326  return err;
1327  }
1328  break;
1329 
1330  case H264_NAL_FILLER_DATA:
1331  {
1332  err = cbs_h264_write_filler(ctx, pbc, unit->content);
1333  if (err < 0)
1334  return err;
1335  }
1336  break;
1337 
1338  case H264_NAL_END_SEQUENCE:
1339  {
1340  err = cbs_h264_write_end_of_sequence(ctx, pbc, unit->content);
1341  if (err < 0)
1342  return err;
1343  }
1344  break;
1345 
1346  case H264_NAL_END_STREAM:
1347  {
1348  err = cbs_h264_write_end_of_stream(ctx, pbc, unit->content);
1349  if (err < 0)
1350  return err;
1351  }
1352  break;
1353 
1354  default:
1355  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
1356  "NAL unit type %"PRIu32".\n", unit->type);
1357  return AVERROR_PATCHWELCOME;
1358  }
1359 
1360  return 0;
1361 }
1362 
1364  CodedBitstreamUnit *unit,
1365  PutBitContext *pbc)
1366 {
1367  int err;
1368 
1369  switch (unit->type) {
1370  case HEVC_NAL_VPS:
1371  {
1372  H265RawVPS *vps = unit->content;
1373 
1374  err = cbs_h265_write_vps(ctx, pbc, vps);
1375  if (err < 0)
1376  return err;
1377 
1378  err = cbs_h265_replace_vps(ctx, unit);
1379  if (err < 0)
1380  return err;
1381  }
1382  break;
1383 
1384  case HEVC_NAL_SPS:
1385  {
1386  H265RawSPS *sps = unit->content;
1387 
1388  err = cbs_h265_write_sps(ctx, pbc, sps);
1389  if (err < 0)
1390  return err;
1391 
1392  err = cbs_h265_replace_sps(ctx, unit);
1393  if (err < 0)
1394  return err;
1395  }
1396  break;
1397 
1398  case HEVC_NAL_PPS:
1399  {
1400  H265RawPPS *pps = unit->content;
1401 
1402  err = cbs_h265_write_pps(ctx, pbc, pps);
1403  if (err < 0)
1404  return err;
1405 
1406  err = cbs_h265_replace_pps(ctx, unit);
1407  if (err < 0)
1408  return err;
1409  }
1410  break;
1411 
1412  case HEVC_NAL_TRAIL_N:
1413  case HEVC_NAL_TRAIL_R:
1414  case HEVC_NAL_TSA_N:
1415  case HEVC_NAL_TSA_R:
1416  case HEVC_NAL_STSA_N:
1417  case HEVC_NAL_STSA_R:
1418  case HEVC_NAL_RADL_N:
1419  case HEVC_NAL_RADL_R:
1420  case HEVC_NAL_RASL_N:
1421  case HEVC_NAL_RASL_R:
1422  case HEVC_NAL_BLA_W_LP:
1423  case HEVC_NAL_BLA_W_RADL:
1424  case HEVC_NAL_BLA_N_LP:
1425  case HEVC_NAL_IDR_W_RADL:
1426  case HEVC_NAL_IDR_N_LP:
1427  case HEVC_NAL_CRA_NUT:
1428  {
1429  H265RawSlice *slice = unit->content;
1430 
1431  err = cbs_h265_write_slice_segment_header(ctx, pbc, &slice->header);
1432  if (err < 0)
1433  return err;
1434 
1435  if (slice->data) {
1436  err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
1437  slice->data_size,
1438  slice->data_bit_start);
1439  if (err < 0)
1440  return err;
1441  } else {
1442  // No slice data - that was just the header.
1443  }
1444  }
1445  break;
1446 
1447  case HEVC_NAL_AUD:
1448  {
1449  err = cbs_h265_write_aud(ctx, pbc, unit->content);
1450  if (err < 0)
1451  return err;
1452  }
1453  break;
1454 
1455  case HEVC_NAL_SEI_PREFIX:
1456  case HEVC_NAL_SEI_SUFFIX:
1457  {
1458  err = cbs_h265_write_sei(ctx, pbc, unit->content,
1459  unit->type == HEVC_NAL_SEI_PREFIX);
1460 
1461  if (err < 0)
1462  return err;
1463  }
1464  break;
1465 
1466  default:
1467  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
1468  "NAL unit type %"PRIu32".\n", unit->type);
1469  return AVERROR_PATCHWELCOME;
1470  }
1471 
1472  return 0;
1473 }
1474 
1476  const CodedBitstreamUnit *unit,
1477  enum AVDiscard skip)
1478 {
1480  H264RawSliceHeader *slice;
1481  int slice_type_i, slice_type_b, slice_type_si;
1482 
1483  if (skip <= AVDISCARD_DEFAULT)
1484  return 0;
1485 
1486  // keep non-VCL
1487  if (unit->type != H264_NAL_SLICE &&
1488  unit->type != H264_NAL_IDR_SLICE &&
1489  unit->type != H264_NAL_AUXILIARY_SLICE)
1490  return 0;
1491 
1492  if (skip >= AVDISCARD_ALL)
1493  return 1;
1494 
1495  if (skip >= AVDISCARD_NONKEY && unit->type != H264_NAL_IDR_SLICE)
1496  return 1;
1497 
1498  header = (H264RawNALUnitHeader *)unit->content;
1499  if (!header) {
1500  av_log(ctx->log_ctx, AV_LOG_WARNING,
1501  "h264 nal unit header is null, missing decompose?\n");
1502  return 0;
1503  }
1504 
1505  if (skip >= AVDISCARD_NONREF && !header->nal_ref_idc)
1506  return 1;
1507 
1508  slice = (H264RawSliceHeader *)unit->content;
1509  if (!slice) {
1510  av_log(ctx->log_ctx, AV_LOG_WARNING,
1511  "h264 slice header is null, missing decompose?\n");
1512  return 0;
1513  }
1514 
1515  slice_type_i = slice->slice_type % 5 == 2;
1516  slice_type_b = slice->slice_type % 5 == 1;
1517  slice_type_si = slice->slice_type % 5 == 4;
1518 
1519  if (skip >= AVDISCARD_BIDIR && slice_type_b)
1520  return 1;
1521  if (skip >= AVDISCARD_NONINTRA && !slice_type_i && !slice_type_si)
1522  return 1;
1523 
1524  return 0;
1525 }
1526 
1528  const CodedBitstreamUnit *unit,
1529  enum AVDiscard skip)
1530 {
1531  H265RawSliceHeader *slice;
1532 
1533  if (skip <= AVDISCARD_DEFAULT)
1534  return 0;
1535 
1536  switch (unit->type) {
1537  case HEVC_NAL_BLA_W_LP:
1538  case HEVC_NAL_BLA_W_RADL:
1539  case HEVC_NAL_BLA_N_LP:
1540  case HEVC_NAL_IDR_W_RADL:
1541  case HEVC_NAL_IDR_N_LP:
1542  case HEVC_NAL_CRA_NUT:
1543  // IRAP slice
1544  if (skip < AVDISCARD_ALL)
1545  return 0;
1546  break;
1547 
1548  case HEVC_NAL_TRAIL_R:
1549  case HEVC_NAL_TRAIL_N:
1550  case HEVC_NAL_TSA_N:
1551  case HEVC_NAL_TSA_R:
1552  case HEVC_NAL_STSA_N:
1553  case HEVC_NAL_STSA_R:
1554  case HEVC_NAL_RADL_N:
1555  case HEVC_NAL_RADL_R:
1556  case HEVC_NAL_RASL_N:
1557  case HEVC_NAL_RASL_R:
1558  // Slice
1559  break;
1560  default:
1561  // Don't discard non-slice nal.
1562  return 0;
1563  }
1564 
1565  if (skip >= AVDISCARD_NONKEY)
1566  return 1;
1567 
1568  slice = (H265RawSliceHeader *)unit->content;
1569  if (!slice) {
1570  av_log(ctx->log_ctx, AV_LOG_WARNING,
1571  "h265 slice header is null, missing decompose?\n");
1572  return 0;
1573  }
1574 
1575  if (skip >= AVDISCARD_NONINTRA && slice->slice_type != HEVC_SLICE_I)
1576  return 1;
1577  if (skip >= AVDISCARD_BIDIR && slice->slice_type == HEVC_SLICE_B)
1578  return 1;
1579 
1580  if (skip >= AVDISCARD_NONREF) {
1581  switch (unit->type) {
1582  case HEVC_NAL_TRAIL_N:
1583  case HEVC_NAL_TSA_N:
1584  case HEVC_NAL_STSA_N:
1585  case HEVC_NAL_RADL_N:
1586  case HEVC_NAL_RASL_N:
1587  case HEVC_NAL_VCL_N10:
1588  case HEVC_NAL_VCL_N12:
1589  case HEVC_NAL_VCL_N14:
1590  // non-ref
1591  return 1;
1592  default:
1593  break;
1594  }
1595  }
1596 
1597  return 0;
1598 }
1599 
1601  CodedBitstreamUnit *unit,
1602  PutBitContext *pbc)
1603 {
1604  int err;
1605 
1606  switch (unit->type) {
1607  case VVC_DCI_NUT:
1608  {
1609  H266RawDCI *dci = unit->content;
1610 
1611  err = cbs_h266_write_dci(ctx, pbc, dci);
1612  if (err < 0)
1613  return err;
1614  }
1615  break;
1616  case VVC_OPI_NUT:
1617  {
1618  H266RawOPI *opi = unit->content;
1619 
1620  err = cbs_h266_write_opi(ctx, pbc, opi);
1621  if (err < 0)
1622  return err;
1623  }
1624  break;
1625  case VVC_VPS_NUT:
1626  {
1627  H266RawVPS *vps = unit->content;
1628 
1629  err = cbs_h266_write_vps(ctx, pbc, vps);
1630  if (err < 0)
1631  return err;
1632 
1633  err = cbs_h266_replace_vps(ctx, unit);
1634  if (err < 0)
1635  return err;
1636  }
1637  break;
1638  case VVC_SPS_NUT:
1639  {
1640  H266RawSPS *sps = unit->content;
1641 
1642  err = cbs_h266_write_sps(ctx, pbc, sps);
1643  if (err < 0)
1644  return err;
1645 
1646  err = cbs_h266_replace_sps(ctx, unit);
1647  if (err < 0)
1648  return err;
1649  }
1650  break;
1651 
1652  case VVC_PPS_NUT:
1653  {
1654  H266RawPPS *pps = unit->content;
1655 
1656  err = cbs_h266_write_pps(ctx, pbc, pps);
1657  if (err < 0)
1658  return err;
1659 
1660  err = cbs_h266_replace_pps(ctx, unit);
1661  if (err < 0)
1662  return err;
1663  }
1664  break;
1665 
1666  case VVC_PREFIX_APS_NUT:
1667  case VVC_SUFFIX_APS_NUT:
1668  {
1669  err = cbs_h266_write_aps(ctx, pbc, unit->content,
1670  unit->type == VVC_PREFIX_APS_NUT);
1671  if (err < 0)
1672  return err;
1673  }
1674  break;
1675  case VVC_PH_NUT:
1676  {
1677  H266RawPH *ph = unit->content;
1678  err = cbs_h266_write_ph(ctx, pbc, ph);
1679  if (err < 0)
1680  return err;
1681 
1682  err = cbs_h266_replace_ph(ctx, unit, &ph->ph_picture_header);
1683  if (err < 0)
1684  return err;
1685  }
1686  break;
1687 
1688  case VVC_TRAIL_NUT:
1689  case VVC_STSA_NUT:
1690  case VVC_RADL_NUT:
1691  case VVC_RASL_NUT:
1692  case VVC_IDR_W_RADL:
1693  case VVC_IDR_N_LP:
1694  case VVC_CRA_NUT:
1695  case VVC_GDR_NUT:
1696  {
1697  H266RawSlice *slice = unit->content;
1698 
1699  err = cbs_h266_write_slice_header(ctx, pbc, &slice->header);
1700  if (err < 0)
1701  return err;
1702 
1704  err = cbs_h266_replace_ph(ctx, unit, &slice->header.sh_picture_header);
1705  if (err < 0)
1706  return err;
1707  }
1708 
1709  if (slice->data) {
1710  err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
1711  slice->data_size,
1712  slice->data_bit_start);
1713  if (err < 0)
1714  return err;
1715  } else {
1716  // No slice data - that was just the header.
1717  }
1718  }
1719  break;
1720 
1721  case VVC_AUD_NUT:
1722  {
1723  err = cbs_h266_write_aud(ctx, pbc, unit->content);
1724  if (err < 0)
1725  return err;
1726  }
1727  break;
1728 
1729  case VVC_PREFIX_SEI_NUT:
1730  case VVC_SUFFIX_SEI_NUT:
1731  {
1732  err = cbs_h266_write_sei(ctx, pbc, unit->content,
1733  unit->type == VVC_PREFIX_SEI_NUT);
1734 
1735  if (err < 0)
1736  return err;
1737  }
1738  break;
1739 
1740  default:
1741  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
1742  "NAL unit type %"PRIu32".\n", unit->type);
1743  return AVERROR_PATCHWELCOME;
1744  }
1745 
1746  return 0;
1747 }
1748 
1751  int nal_unit_index)
1752 {
1753  // Section B.1.2 in H.264, section B.2.2 in H.265, H.266.
1754  if (nal_unit_index == 0) {
1755  // Assume that this is the first NAL unit in an access unit.
1756  return 1;
1757  }
1758  if (codec_id == AV_CODEC_ID_H264)
1759  return type == H264_NAL_SPS || type == H264_NAL_PPS;
1760  if (codec_id == AV_CODEC_ID_HEVC)
1761  return type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS;
1762  if (codec_id == AV_CODEC_ID_VVC)
1763  return type >= VVC_OPI_NUT && type <= VVC_SUFFIX_APS_NUT;
1764  return 0;
1765 }
1766 
1768  CodedBitstreamFragment *frag)
1769 {
1770  uint8_t *data;
1771  size_t max_size, dp, sp;
1772  int err, i, zero_run;
1773 
1774  for (i = 0; i < frag->nb_units; i++) {
1775  // Data should already all have been written when we get here.
1776  av_assert0(frag->units[i].data);
1777  }
1778 
1779  max_size = 0;
1780  for (i = 0; i < frag->nb_units; i++) {
1781  // Start code + content with worst-case emulation prevention.
1782  max_size += 4 + frag->units[i].data_size * 3 / 2;
1783  }
1784 
1786  if (!data)
1787  return AVERROR(ENOMEM);
1788 
1789  dp = 0;
1790  for (i = 0; i < frag->nb_units; i++) {
1791  CodedBitstreamUnit *unit = &frag->units[i];
1792 
1793  if (unit->data_bit_padding > 0) {
1794  if (i < frag->nb_units - 1)
1795  av_log(ctx->log_ctx, AV_LOG_WARNING, "Probably invalid "
1796  "unaligned padding on non-final NAL unit.\n");
1797  else
1798  frag->data_bit_padding = unit->data_bit_padding;
1799  }
1800 
1801  if (cbs_h2645_unit_requires_zero_byte(ctx->codec->codec_id, unit->type, i)) {
1802  // zero_byte
1803  data[dp++] = 0;
1804  }
1805  // start_code_prefix_one_3bytes
1806  data[dp++] = 0;
1807  data[dp++] = 0;
1808  data[dp++] = 1;
1809 
1810  zero_run = 0;
1811  for (sp = 0; sp < unit->data_size; sp++) {
1812  if (zero_run < 2) {
1813  if (unit->data[sp] == 0)
1814  ++zero_run;
1815  else
1816  zero_run = 0;
1817  } else {
1818  if ((unit->data[sp] & ~3) == 0) {
1819  // emulation_prevention_three_byte
1820  data[dp++] = 3;
1821  }
1822  zero_run = unit->data[sp] == 0;
1823  }
1824  data[dp++] = unit->data[sp];
1825  }
1826  }
1827 
1828  av_assert0(dp <= max_size);
1830  if (err)
1831  return err;
1832  memset(data + dp, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1833 
1835  NULL, NULL, 0);
1836  if (!frag->data_ref) {
1837  av_freep(&data);
1838  return AVERROR(ENOMEM);
1839  }
1840 
1841  frag->data = data;
1842  frag->data_size = dp;
1843 
1844  return 0;
1845 }
1846 
1848 {
1850 
1851  for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) {
1852  av_buffer_unref(&h264->sps_ref[i]);
1853  h264->sps[i] = NULL;
1854  }
1855  for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) {
1856  av_buffer_unref(&h264->pps_ref[i]);
1857  h264->pps[i] = NULL;
1858  }
1859 
1860  h264->active_sps = NULL;
1861  h264->active_pps = NULL;
1862  h264->last_slice_nal_unit_type = 0;
1863 }
1864 
1866 {
1868  int i;
1869 
1871 
1872  for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++)
1873  av_buffer_unref(&h264->sps_ref[i]);
1874  for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++)
1875  av_buffer_unref(&h264->pps_ref[i]);
1876 }
1877 
1879 {
1881 
1882  for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) {
1883  av_buffer_unref(&h265->vps_ref[i]);
1884  h265->vps[i] = NULL;
1885  }
1886  for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) {
1887  av_buffer_unref(&h265->sps_ref[i]);
1888  h265->sps[i] = NULL;
1889  }
1890  for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) {
1891  av_buffer_unref(&h265->pps_ref[i]);
1892  h265->pps[i] = NULL;
1893  }
1894 
1895  h265->active_vps = NULL;
1896  h265->active_sps = NULL;
1897  h265->active_pps = NULL;
1898 }
1899 
1901 {
1903  int i;
1904 
1906 
1907  for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
1908  av_buffer_unref(&h265->vps_ref[i]);
1909  for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
1910  av_buffer_unref(&h265->sps_ref[i]);
1911  for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
1912  av_buffer_unref(&h265->pps_ref[i]);
1913 }
1914 
1916 {
1918 
1919  for (int i = 0; i < FF_ARRAY_ELEMS(h266->vps); i++) {
1920  av_buffer_unref(&h266->vps_ref[i]);
1921  h266->vps[i] = NULL;
1922  }
1923 
1924  for (int i = 0; i < FF_ARRAY_ELEMS(h266->sps); i++) {
1925  av_buffer_unref(&h266->sps_ref[i]);
1926  h266->sps[i] = NULL;
1927  }
1928  for (int i = 0; i < FF_ARRAY_ELEMS(h266->pps); i++) {
1929  av_buffer_unref(&h266->pps_ref[i]);
1930  h266->pps[i] = NULL;
1931  }
1932  av_buffer_unref(&h266->ph_ref);
1933  h266->ph = NULL;
1934 }
1935 
1937 {
1939 
1942  }
1943 
1944 static void cbs_h264_free_sei(void *opaque, uint8_t *content)
1945 {
1946  H264RawSEI *sei = (H264RawSEI*)content;
1947  ff_cbs_sei_free_message_list(&sei->message_list);
1948  av_free(content);
1949 }
1950 
1954 
1956 
1960 
1965 
1967 
1969 };
1970 
1971 static void cbs_h265_free_sei(void *opaque, uint8_t *content)
1972 {
1973  H265RawSEI *sei = (H265RawSEI*)content;
1974  ff_cbs_sei_free_message_list(&sei->message_list);
1975  av_free(content);
1976 }
1977 
1982 
1984 
1985  // Slices of non-IRAP pictures.
1987  H265RawSlice, data),
1988  // Slices of IRAP pictures.
1990  H265RawSlice, data),
1991 
1994 
1996 };
1997 
1998 static void cbs_h266_free_sei(void *opaque, uint8_t *content)
1999 {
2000  H266RawSEI *sei = (H266RawSEI*)content;
2001  ff_cbs_sei_free_message_list(&sei->message_list);
2002  av_free(content);
2003 }
2004 
2013 
2016 
2018  H266RawSlice, data),
2019 
2021  H266RawSlice, data),
2022 
2025 
2027 };
2028 
2031 
2032  .priv_data_size = sizeof(CodedBitstreamH264Context),
2033 
2034  .unit_types = cbs_h264_unit_types,
2035 
2036  .split_fragment = &cbs_h2645_split_fragment,
2037  .read_unit = &cbs_h264_read_nal_unit,
2038  .write_unit = &cbs_h264_write_nal_unit,
2039  .discarded_unit = &cbs_h264_discarded_nal_unit,
2040  .assemble_fragment = &cbs_h2645_assemble_fragment,
2041 
2042  .flush = &cbs_h264_flush,
2043  .close = &cbs_h264_close,
2044 };
2045 
2048 
2049  .priv_data_size = sizeof(CodedBitstreamH265Context),
2050 
2051  .unit_types = cbs_h265_unit_types,
2052 
2053  .split_fragment = &cbs_h2645_split_fragment,
2054  .read_unit = &cbs_h265_read_nal_unit,
2055  .write_unit = &cbs_h265_write_nal_unit,
2056  .discarded_unit = &cbs_h265_discarded_nal_unit,
2057  .assemble_fragment = &cbs_h2645_assemble_fragment,
2058 
2059  .flush = &cbs_h265_flush,
2060  .close = &cbs_h265_close,
2061 };
2062 
2065 
2066  .priv_data_size = sizeof(CodedBitstreamH266Context),
2067 
2068  .unit_types = cbs_h266_unit_types,
2069 
2070  .split_fragment = &cbs_h2645_split_fragment,
2071  .read_unit = &cbs_h266_read_nal_unit,
2072  .write_unit = &cbs_h266_write_nal_unit,
2073  .assemble_fragment = &cbs_h2645_assemble_fragment,
2074 
2075  .flush = &cbs_h266_flush,
2076  .close = &cbs_h266_close,
2077 };
2078 
2080  {
2082  1, 1,
2083  sizeof(SEIRawFillerPayload),
2085  },
2086  {
2088  1, 1,
2089  sizeof(SEIRawUserDataRegistered),
2091  },
2092  {
2094  1, 1,
2097  },
2098  {
2100  1, 0,
2103  },
2104  {
2106  1, 0,
2109  },
2110  {
2112  1, 0,
2115  },
2116  {
2118  1, 0,
2121  },
2123 };
2124 
2126  {
2128  1, 0,
2129  sizeof(H264RawSEIBufferingPeriod),
2131  },
2132  {
2134  1, 0,
2135  sizeof(H264RawSEIPicTiming),
2137  },
2138  {
2140  1, 0,
2141  sizeof(H264RawSEIPanScanRect),
2143  },
2144  {
2146  1, 0,
2147  sizeof(H264RawSEIRecoveryPoint),
2149  },
2150  {
2152  1, 0,
2155  },
2156  {
2158  1, 0,
2161  },
2163 };
2164 
2166  {
2168  1, 0,
2169  sizeof(H265RawSEIBufferingPeriod),
2171  },
2172  {
2174  1, 0,
2175  sizeof(H265RawSEIPicTiming),
2177  },
2178  {
2180  1, 0,
2181  sizeof(H265RawSEIPanScanRect),
2183  },
2184  {
2186  1, 0,
2187  sizeof(H265RawSEIRecoveryPoint),
2189  },
2190  {
2192  1, 0,
2195  },
2196  {
2198  1, 0,
2201  },
2202  {
2204  1, 0,
2207  },
2208  {
2210  0, 1,
2213  },
2214  {
2216  1, 0,
2217  sizeof(H265RawSEITimeCode),
2219  },
2220  {
2222  1, 0,
2225  },
2227 };
2228 
2230  {
2232  0, 1,
2235  },
2237 };
2238 
2240  int payload_type)
2241 {
2243  int i;
2244 
2245  for (i = 0; cbs_sei_common_types[i].type >= 0; i++) {
2246  if (cbs_sei_common_types[i].type == payload_type)
2247  return &cbs_sei_common_types[i];
2248  }
2249 
2250  switch (ctx->codec->codec_id) {
2251  case AV_CODEC_ID_H264:
2253  break;
2254  case AV_CODEC_ID_H265:
2256  break;
2257  case AV_CODEC_ID_H266:
2259  break;
2260  default:
2261  return NULL;
2262  }
2263 
2264  for (i = 0; codec_list[i].type >= 0; i++) {
2265  if (codec_list[i].type == payload_type)
2266  return &codec_list[i];
2267  }
2268 
2269  return NULL;
2270 }
H264_NAL_AUD
@ H264_NAL_AUD
Definition: h264.h:43
SEI_TYPE_ALPHA_CHANNEL_INFO
@ SEI_TYPE_ALPHA_CHANNEL_INFO
Definition: sei.h:123
HEVC_NAL_RADL_N
@ HEVC_NAL_RADL_N
Definition: hevc.h:35
CodedBitstreamH265Context::vps
H265RawVPS * vps[HEVC_MAX_VPS_COUNT]
Definition: cbs_h265.h:687
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
H265RawSlice::data_bit_start
int data_bit_start
Definition: cbs_h265.h:539
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
CBS_UNIT_TYPE_COMPLEX
#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func)
Definition: cbs_internal.h:331
H264_NAL_END_SEQUENCE
@ H264_NAL_END_SEQUENCE
Definition: h264.h:44
show_bits_long
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
Definition: get_bits.h:495
h2645_parse.h
CodedBitstreamH265Context::pps_ref
AVBufferRef * pps_ref[HEVC_MAX_PPS_COUNT]
Definition: cbs_h265.h:686
cbs_h266.h
filler_payload
static int FUNC() filler_payload(CodedBitstreamContext *ctx, RWContext *rw, SEIRawFillerPayload *current, SEIMessageState *state)
Definition: cbs_sei_syntax_template.c:20
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
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
CodedBitstreamH265Context::sps_ref
AVBufferRef * sps_ref[HEVC_MAX_SPS_COUNT]
Definition: cbs_h265.h:685
put_bits32
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:291
cbs_h264_syntax_template.c
H265RawSEITimeCode
Definition: cbs_h265.h:643
SEIRawUserDataRegistered
Definition: cbs_sei.h:35
H266RawDCI
Definition: cbs_h266.h:252
H264_NAL_PPS
@ H264_NAL_PPS
Definition: h264.h:42
ff_ctz
#define ff_ctz
Definition: intmath.h:107
SEIRawAmbientViewingEnvironment
Definition: cbs_sei.h:68
GetByteContext
Definition: bytestream.h:33
VVC_PPS_NUT
@ VVC_PPS_NUT
Definition: vvc.h:45
CodedBitstreamH264Context::common
CodedBitstreamH2645Context common
Definition: cbs_h264.h:406
cbs_h265_syntax_template.c
cbs_h266_replace_ps
#define cbs_h266_replace_ps(h26n, ps_name, ps_var, id_element)
H265RawSlice::data_ref
AVBufferRef * data_ref
Definition: cbs_h265.h:537
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
cbs_h264.h
CodedBitstreamUnit::content
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:107
H265RawSEIActiveParameterSets
Definition: cbs_h265.h:627
H265RawSlice::header
H265RawSliceHeader header
Definition: cbs_h265.h:534
HEVC_NAL_STSA_N
@ HEVC_NAL_STSA_N
Definition: hevc.h:33
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
CodedBitstreamH266Context::sps_ref
AVBufferRef * sps_ref[VVC_MAX_SPS_COUNT]
Definition: cbs_h266.h:871
SEI_TYPE_PAN_SCAN_RECT
@ SEI_TYPE_PAN_SCAN_RECT
Definition: sei.h:32
CodedBitstreamH264Context::pps
H264RawPPS * pps[H264_MAX_PPS_COUNT]
Definition: cbs_h264.h:413
ph
static int FUNC() ph(CodedBitstreamContext *ctx, RWContext *rw, H266RawPH *current)
Definition: cbs_h266_syntax_template.c:2992
H2645NAL::nuh_layer_id
int nuh_layer_id
Definition: h2645_parse.h:67
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:222
H265RawSEI
Definition: cbs_h265.h:673
HEVC_NAL_TSA_N
@ HEVC_NAL_TSA_N
Definition: hevc.h:31
cbs_h266_unit_types
static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[]
Definition: cbs_h2645.c:2005
CodedBitstreamH265Context::sps
H265RawSPS * sps[HEVC_MAX_SPS_COUNT]
Definition: cbs_h265.h:688
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
ff_h2645_packet_uninit
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
Definition: h2645_parse.c:597
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:148
H265RawSEIPanScanRect
Definition: cbs_h265.h:580
SEIRawAlternativeTransferCharacteristics
Definition: cbs_sei.h:64
HEVC_NAL_RASL_N
@ HEVC_NAL_RASL_N
Definition: hevc.h:37
HEVC_NAL_STSA_R
@ HEVC_NAL_STSA_R
Definition: hevc.h:34
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
CodedBitstreamUnit::type
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:74
cbs.h
H265RawSEIDecodedPictureHash
Definition: cbs_h265.h:636
HEVC_NAL_BLA_W_RADL
@ HEVC_NAL_BLA_W_RADL
Definition: hevc.h:46
cbs_h2645_split_fragment
static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition: cbs_h2645.c:500
cbs_h265.h
ambient_viewing_environment
static int FUNC() ambient_viewing_environment(CodedBitstreamContext *ctx, RWContext *rw, SEIRawAmbientViewingEnvironment *current, SEIMessageState *state)
Definition: cbs_sei_syntax_template.c:148
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
CodedBitstreamH264Context::sps_ref
AVBufferRef * sps_ref[H264_MAX_SPS_COUNT]
Definition: cbs_h264.h:410
CodedBitstreamH265Context::common
CodedBitstreamH2645Context common
Definition: cbs_h265.h:680
VVC_CRA_NUT
@ VVC_CRA_NUT
Definition: vvc.h:38
H2645Packet::nb_nals
int nb_nals
Definition: h2645_parse.h:85
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:514
cbs_h2645_unit_requires_zero_byte
static int cbs_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, CodedBitstreamUnitType type, int nal_unit_index)
Definition: cbs_h2645.c:1749
CodedBitstreamUnit
Coded bitstream unit structure.
Definition: cbs.h:70
H265RawSPS
Definition: cbs_h265.h:244
H265RawVPS
Definition: cbs_h265.h:183
H265RawPPS
Definition: cbs_h265.h:346
SEIRawContentLightLevelInfo
Definition: cbs_sei.h:59
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
VVC_AUD_NUT
@ VVC_AUD_NUT
Definition: vvc.h:49
CodedBitstreamH266Context::pps
H266RawPPS * pps[VVC_MAX_PPS_COUNT]
Definition: cbs_h266.h:876
cbs_h265_flush
static void cbs_h265_flush(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1878
CodedBitstreamH266Context::vps
H266RawVPS * vps[VVC_MAX_VPS_COUNT]
Definition: cbs_h266.h:874
H264RawSEIPicTiming
Definition: cbs_h264.h:249
H266RawAUD
Definition: cbs_h266.h:644
VVC_SUFFIX_SEI_NUT
@ VVC_SUFFIX_SEI_NUT
Definition: vvc.h:53
cbs_sei_h265_types
static const SEIMessageTypeDescriptor cbs_sei_h265_types[]
Definition: cbs_h2645.c:2165
CodedBitstreamH264Context::active_sps
const H264RawSPS * active_sps
Definition: cbs_h264.h:418
cbs_h2645_fragment_add_nals
static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const H2645Packet *packet)
Definition: cbs_h2645.c:465
CBS_UNIT_TYPE_INTERNAL_REF
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
Definition: cbs_internal.h:311
cbs_h264_flush
static void cbs_h264_flush(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1847
H265RawSEIPicTiming
Definition: cbs_h265.h:564
GetBitContext
Definition: get_bits.h:108
H266RawAPS
Definition: cbs_h266.h:598
VVC_VPS_NUT
@ VVC_VPS_NUT
Definition: vvc.h:43
put_bits_left
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:125
SEIRawUserDataUnregistered
Definition: cbs_sei.h:43
H266RawSliceHeader::sh_picture_header_in_slice_header_flag
uint8_t sh_picture_header_in_slice_header_flag
Definition: cbs_h266.h:771
H2645Packet::rbsp
H2645RBSP rbsp
Definition: h2645_parse.h:84
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT
@ SEI_TYPE_AMBIENT_VIEWING_ENVIRONMENT
Definition: sei.h:107
CodedBitstreamUnit::data
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:81
alternative_transfer_characteristics
static int FUNC() alternative_transfer_characteristics(CodedBitstreamContext *ctx, RWContext *rw, SEIRawAlternativeTransferCharacteristics *current, SEIMessageState *state)
Definition: cbs_sei_syntax_template.c:134
mastering_display_colour_volume
static int FUNC() mastering_display_colour_volume(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMasteringDisplayColourVolume *current, SEIMessageState *state)
Definition: cbs_sei_syntax_template.c:98
SEI_TYPE_FILLER_PAYLOAD
@ SEI_TYPE_FILLER_PAYLOAD
Definition: sei.h:33
cbs_sei_common_types
static const SEIMessageTypeDescriptor cbs_sei_common_types[]
Definition: cbs_h2645.c:2079
CodedBitstreamFragment::units
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:168
avassert.h
CodedBitstreamUnitTypeDescriptor
Definition: cbs_internal.h:55
VVC_PREFIX_SEI_NUT
@ VVC_PREFIX_SEI_NUT
Definition: vvc.h:52
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
CodedBitstreamH2645Context
Definition: cbs_h2645.h:25
H266RawSlice::data
uint8_t * data
Definition: cbs_h266.h:843
HEVC_NAL_BLA_N_LP
@ HEVC_NAL_BLA_N_LP
Definition: hevc.h:47
cbs_h265_free_sei
static void cbs_h265_free_sei(void *opaque, uint8_t *content)
Definition: cbs_h2645.c:1971
extension_data
static int FUNC() extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *current)
Definition: cbs_h265_syntax_template.c:61
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:545
HEVC_NAL_RADL_R
@ HEVC_NAL_RADL_R
Definition: hevc.h:36
CodedBitstreamH2645Context::nal_length_size
int nal_length_size
Definition: cbs_h2645.h:30
H266RawSEI
Definition: cbs_h266.h:859
sei_alpha_channel_info
static int FUNC() sei_alpha_channel_info(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIAlphaChannelInfo *current, SEIMessageState *sei)
Definition: cbs_h265_syntax_template.c:2055
H2645NAL::size
int size
Definition: h2645_parse.h:36
cbs_read_ue_golomb
static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc, const char *name, const int *subscripts, uint32_t *write_to, uint32_t range_min, uint32_t range_max)
Definition: cbs_h2645.c:34
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
SEIRawFillerPayload
Definition: cbs_sei.h:31
VVC_GDR_NUT
@ VVC_GDR_NUT
Definition: vvc.h:39
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:135
HEVC_NAL_VCL_N14
@ HEVC_NAL_VCL_N14
Definition: hevc.h:43
cbs_sei_h266_types
static const SEIMessageTypeDescriptor cbs_sei_h266_types[]
Definition: cbs_h2645.c:2229
HEVC_NAL_VCL_N12
@ HEVC_NAL_VCL_N12
Definition: hevc.h:41
SEI_MESSAGE_RW
#define SEI_MESSAGE_RW(codec, name)
Definition: cbs_sei.h:137
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
ctx
AVFormatContext * ctx
Definition: movenc.c:48
SEI_MESSAGE_TYPE_END
#define SEI_MESSAGE_TYPE_END
Definition: cbs_sei.h:142
SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition: sei.h:34
ff_cbs_append_unit_data
int ff_cbs_append_unit_data(CodedBitstreamFragment *frag, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Add a new unit to a fragment with the given data bitstream.
Definition: cbs.c:848
H2645NAL::data
const uint8_t * data
Definition: h2645_parse.h:35
CodedBitstreamH2645Context::mp4
int mp4
Definition: cbs_h2645.h:28
H265RawSEIDisplayOrientation
Definition: cbs_h265.h:618
cbs_internal.h
cbs_h2645_replace_ps
#define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element)
Definition: cbs_h2645.c:724
H264RawSlice::data_ref
AVBufferRef * data_ref
Definition: cbs_h264.h:392
HEVC_SLICE_I
@ HEVC_SLICE_I
Definition: hevc.h:98
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:388
CodedBitstreamFragment::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:139
CodedBitstreamType::codec_id
enum AVCodecID codec_id
Definition: cbs_internal.h:102
H264_NAL_FILLER_DATA
@ H264_NAL_FILLER_DATA
Definition: h264.h:46
MAX_UINT_BITS
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:195
sei_display_orientation
static int FUNC() sei_display_orientation(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIDisplayOrientation *current, SEIMessageState *sei)
Definition: cbs_h264_syntax_template.c:805
AVDISCARD_BIDIR
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition: defs.h:208
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
H2645NAL::type
int type
NAL unit type.
Definition: h2645_parse.h:52
PutBitContext
Definition: put_bits.h:50
CBS_TRACE_WRITE_END
#define CBS_TRACE_WRITE_END()
Definition: cbs_internal.h:253
H265RawSEIRecoveryPoint
Definition: cbs_h265.h:591
HEVC_NAL_VCL_N10
@ HEVC_NAL_VCL_N10
Definition: hevc.h:39
if
if(ret)
Definition: filter_design.txt:179
cbs_h265_payload_extension_present
static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t payload_size, int cur_pos)
Definition: cbs_h2645.c:212
HEVC_NAL_IDR_N_LP
@ HEVC_NAL_IDR_N_LP
Definition: hevc.h:49
cbs_sei_syntax_template.c
H266RawSPS
Definition: cbs_h266.h:308
H266RawVPS
Definition: cbs_h266.h:262
H264_NAL_END_STREAM
@ H264_NAL_END_STREAM
Definition: h264.h:45
H266RawPPS
Definition: cbs_h266.h:496
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:211
cbs_h266_read_nal_unit
static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_h2645.c:1032
H266RawOPI
Definition: cbs_h266.h:241
HEVC_SLICE_B
@ HEVC_SLICE_B
Definition: hevc.h:96
VVC_DCI_NUT
@ VVC_DCI_NUT
Definition: vvc.h:42
NULL
#define NULL
Definition: coverity.c:32
H266RawPictureHeader
Definition: cbs_h266.h:674
bits_left
#define bits_left
Definition: bitstream.h:114
H265RawAUD
Definition: cbs_h265.h:437
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
VVC_RADL_NUT
@ VVC_RADL_NUT
Definition: vvc.h:31
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
film_grain_characteristics
static int FUNC() film_grain_characteristics(CodedBitstreamContext *ctx, RWContext *rw, H264RawFilmGrainCharacteristics *current, SEIMessageState *state)
Definition: cbs_h264_syntax_template.c:722
SEI_TYPE_TIME_CODE
@ SEI_TYPE_TIME_CODE
Definition: sei.h:95
HEVC_NAL_PPS
@ HEVC_NAL_PPS
Definition: hevc.h:63
AV_CODEC_ID_H266
#define AV_CODEC_ID_H266
Definition: codec_id.h:251
sei_decoded_picture_hash
static int FUNC() sei_decoded_picture_hash(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIDecodedPictureHash *current, SEIMessageState *sei)
Definition: cbs_h265_syntax_template.c:1972
cbs_h265_write_nal_unit
static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition: cbs_h2645.c:1363
SPS
Sequence parameter set.
Definition: h264_ps.h:45
SEIMessageTypeDescriptor
Definition: cbs_sei.h:119
SEIRawMasteringDisplayColourVolume
Definition: cbs_sei.h:50
user_data_unregistered
static int FUNC() user_data_unregistered(CodedBitstreamContext *ctx, RWContext *rw, SEIRawUserDataUnregistered *current, SEIMessageState *state)
Definition: cbs_sei_syntax_template.c:70
H264RawNALUnitHeader
Definition: cbs_h264.h:31
cbs_h266_close
static void cbs_h266_close(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1936
CodedBitstreamUnit::data_size
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition: cbs.h:86
PPS
Picture parameter set.
Definition: h264_ps.h:111
H264_NAL_SEI
@ H264_NAL_SEI
Definition: h264.h:40
opi
static int FUNC() opi(CodedBitstreamContext *ctx, RWContext *rw, H266RawOPI *current)
Definition: cbs_h266_syntax_template.c:643
HEVC_NAL_SEI_SUFFIX
@ HEVC_NAL_SEI_SUFFIX
Definition: hevc.h:69
H264RawSEIPanScanRect
Definition: cbs_h264.h:257
HEVC_NAL_CRA_NUT
@ HEVC_NAL_CRA_NUT
Definition: hevc.h:50
VVC_SUFFIX_APS_NUT
@ VVC_SUFFIX_APS_NUT
Definition: vvc.h:47
CodedBitstreamH266Context::common
CodedBitstreamH2645Context common
Definition: cbs_h266.h:866
CodedBitstreamH2645Context::read_packet
H2645Packet read_packet
Definition: cbs_h2645.h:32
CBS_UNIT_RANGE_INTERNAL_REF
#define CBS_UNIT_RANGE_INTERNAL_REF(range_start, range_end, structure, ref_field)
Definition: cbs_internal.h:314
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
H265RawSliceHeader::slice_type
uint8_t slice_type
Definition: cbs_h265.h:454
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:825
VVC_PH_NUT
@ VVC_PH_NUT
Definition: vvc.h:48
HEVC_NAL_RASL_R
@ HEVC_NAL_RASL_R
Definition: hevc.h:38
H264_NAL_SPS_EXT
@ H264_NAL_SPS_EXT
Definition: h264.h:47
H264_NAL_SPS
@ H264_NAL_SPS
Definition: h264.h:41
cbs_h264_unit_types
static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[]
Definition: cbs_h2645.c:1951
CodedBitstreamH266Context::ph_ref
AVBufferRef * ph_ref
Definition: cbs_h266.h:873
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
bytestream2_tell
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
CodedBitstreamH264Context
Definition: cbs_h264.h:404
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:210
VVC_IDR_W_RADL
@ VVC_IDR_W_RADL
Definition: vvc.h:36
H266RawSlice::data_bit_start
int data_bit_start
Definition: cbs_h266.h:846
CodedBitstreamH265Context::vps_ref
AVBufferRef * vps_ref[HEVC_MAX_VPS_COUNT]
Definition: cbs_h265.h:684
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
AVDISCARD_DEFAULT
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition: defs.h:206
H266RawSliceHeader::sh_picture_header
H266RawPictureHeader sh_picture_header
Definition: cbs_h266.h:772
H264RawFilmGrainCharacteristics
Definition: cbs_h264.h:275
H264RawSliceHeader::slice_type
uint8_t slice_type
Definition: cbs_h264.h:314
H264_NAL_IDR_SLICE
@ H264_NAL_IDR_SLICE
Definition: h264.h:39
codec_list
const FFCodec * codec_list[]
sp
#define sp
Definition: regdef.h:63
CodedBitstreamH264Context::pps_ref
AVBufferRef * pps_ref[H264_MAX_PPS_COUNT]
Definition: cbs_h264.h:411
H266RawSlice::data_ref
AVBufferRef * data_ref
Definition: cbs_h266.h:844
CodedBitstreamH266Context::ph
H266RawPictureHeader * ph
Definition: cbs_h266.h:877
size
int size
Definition: twinvq_data.h:10344
HEVC_NAL_BLA_W_LP
@ HEVC_NAL_BLA_W_LP
Definition: hevc.h:45
SEIMessageTypeDescriptor::type
int type
Definition: cbs_sei.h:121
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:128
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:186
CodedBitstreamUnit::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:92
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:96
H2645NAL
Definition: h2645_parse.h:34
H264RawSEIDisplayOrientation
Definition: cbs_h264.h:296
cbs_h264_free_sei
static void cbs_h264_free_sei(void *opaque, uint8_t *content)
Definition: cbs_h2645.c:1944
header
static const uint8_t header[24]
Definition: sdr2.c:67
ff_h2645_packet_split
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int is_nalff, int nal_length_size, enum AVCodecID codec_id, int small_padding, int use_ref)
Split an input packet into NAL units.
Definition: h2645_parse.c:463
SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
@ SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
Definition: sei.h:96
CBS_UNIT_TYPE_POD
#define CBS_UNIT_TYPE_POD(type_, structure)
Definition: cbs_internal.h:287
CodedBitstreamH266Context
Definition: cbs_h266.h:864
AV_CODEC_ID_VVC
@ AV_CODEC_ID_VVC
Definition: codec_id.h:250
sei_active_parameter_sets
static int FUNC() sei_active_parameter_sets(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIActiveParameterSets *current, SEIMessageState *sei)
Definition: cbs_h265_syntax_template.c:1935
CodedBitstreamType
Definition: cbs_internal.h:101
SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS
@ SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS
Definition: sei.h:106
attributes.h
cbs_h264_discarded_nal_unit
static int cbs_h264_discarded_nal_unit(CodedBitstreamContext *ctx, const CodedBitstreamUnit *unit, enum AVDiscard skip)
Definition: cbs_h2645.c:1475
version
version
Definition: libkvazaar.c:314
H265RawFilmGrainCharacteristics
Definition: cbs_h265.h:597
cbs_h265_close
static void cbs_h265_close(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1900
CodedBitstreamH264Context::active_pps
const H264RawPPS * active_pps
Definition: cbs_h264.h:419
H264RawSlice::data_bit_start
int data_bit_start
Definition: cbs_h264.h:394
H264RawSliceHeader
Definition: cbs_h264.h:310
sei_time_code
static int FUNC() sei_time_code(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEITimeCode *current, SEIMessageState *sei)
Definition: cbs_h265_syntax_template.c:2004
H2645Packet::nals
H2645NAL * nals
Definition: h2645_parse.h:83
H265RawSliceHeader
Definition: cbs_h265.h:443
ff_cbs_sei_find_type
const SEIMessageTypeDescriptor * ff_cbs_sei_find_type(CodedBitstreamContext *ctx, int payload_type)
Find the type descriptor for the given payload type.
Definition: cbs_h2645.c:2239
H264RawSlice::header
H264RawSliceHeader header
Definition: cbs_h264.h:389
HEVC_NAL_TRAIL_R
@ HEVC_NAL_TRAIL_R
Definition: hevc.h:30
CodedBitstreamH264Context::last_slice_nal_unit_type
uint8_t last_slice_nal_unit_type
Definition: cbs_h264.h:424
AVDISCARD_NONINTRA
@ AVDISCARD_NONINTRA
discard all non intra frames
Definition: defs.h:209
CodedBitstreamUnit::data_ref
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:98
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:244
put_bits_count
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:80
CBS_UNIT_TYPES_COMPLEX
#define CBS_UNIT_TYPES_COMPLEX(types, structure, free_func)
Definition: cbs_internal.h:324
VVC_OPI_NUT
@ VVC_OPI_NUT
Definition: vvc.h:41
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:371
cbs_h266_flush
static void cbs_h266_flush(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1915
H265RawSlice::data_size
size_t data_size
Definition: cbs_h265.h:538
CodedBitstreamH266Context::sps
H266RawSPS * sps[VVC_MAX_SPS_COUNT]
Definition: cbs_h266.h:875
SEI_TYPE_PIC_TIMING
@ SEI_TYPE_PIC_TIMING
Definition: sei.h:31
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
H266RawSlice::data_size
size_t data_size
Definition: cbs_h266.h:845
SEI_TYPE_DISPLAY_ORIENTATION
@ SEI_TYPE_DISPLAY_ORIENTATION
Definition: sei.h:77
CodedBitstreamH266Context::vps_ref
AVBufferRef * vps_ref[VVC_MAX_VPS_COUNT]
Definition: cbs_h266.h:870
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
H264RawSlice::data
uint8_t * data
Definition: cbs_h264.h:391
H2645RBSP::rbsp_buffer_ref
AVBufferRef * rbsp_buffer_ref
Definition: h2645_parse.h:76
cbs_write_se_golomb
static int cbs_write_se_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, const char *name, const int *subscripts, int32_t value, int32_t range_min, int32_t range_max)
Definition: cbs_h2645.c:170
len
int len
Definition: vorbis_enc_data.h:426
HEVC_NAL_TSA_R
@ HEVC_NAL_TSA_R
Definition: hevc.h:32
ff_cbs_make_unit_refcounted
int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Make the content of a unit refcounted.
Definition: cbs.c:1039
CodedBitstreamH265Context::active_sps
const H265RawSPS * active_sps
Definition: cbs_h265.h:695
hevc.h
CBS_UNIT_TYPE_END_OF_LIST
#define CBS_UNIT_TYPE_END_OF_LIST
Definition: cbs_internal.h:334
HEVC_NAL_VPS
@ HEVC_NAL_VPS
Definition: hevc.h:61
HEVC_NAL_IDR_W_RADL
@ HEVC_NAL_IDR_W_RADL
Definition: hevc.h:48
CodedBitstreamUnit::content_ref
AVBufferRef * content_ref
If content is reference counted, a reference to the buffer containing content.
Definition: cbs.h:112
cbs_read_se_golomb
static int cbs_read_se_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc, const char *name, const int *subscripts, int32_t *write_to, int32_t range_min, int32_t range_max)
Definition: cbs_h2645.c:83
H2645NAL::raw_data
const uint8_t * raw_data
Definition: h2645_parse.h:45
H264RawSEI
Definition: cbs_h264.h:305
cbs_h264_close
static void cbs_h264_close(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1865
CodedBitstreamH265Context::pps
H265RawPPS * pps[HEVC_MAX_PPS_COUNT]
Definition: cbs_h265.h:689
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
H264_NAL_AUXILIARY_SLICE
@ H264_NAL_AUXILIARY_SLICE
Definition: h264.h:53
H266RawSlice::header
H266RawSliceHeader header
Definition: cbs_h266.h:841
pos
unsigned int pos
Definition: spdifenc.c:413
ff_cbs_alloc_unit_content
int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
Definition: cbs.c:913
VVC_SPS_NUT
@ VVC_SPS_NUT
Definition: vvc.h:44
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
HEVC_NAL_TRAIL_N
@ HEVC_NAL_TRAIL_N
Definition: hevc.h:29
CodedBitstreamH265Context::active_pps
const H265RawPPS * active_pps
Definition: cbs_h265.h:696
HEVC_NAL_AUD
@ HEVC_NAL_AUD
Definition: hevc.h:64
H264RawAUD
Definition: cbs_h264.h:218
H266RawPH
Definition: cbs_h266.h:764
put_bits_ptr
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:377
SEI_TYPE_BUFFERING_PERIOD
@ SEI_TYPE_BUFFERING_PERIOD
Definition: sei.h:30
CodedBitstreamUnitType
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:47
vvc.h
SEI_TYPE_USER_DATA_UNREGISTERED
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition: sei.h:35
sei_pan_scan_rect
static int FUNC() sei_pan_scan_rect(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIPanScanRect *current, SEIMessageState *sei)
Definition: cbs_h264_syntax_template.c:679
skip_put_bytes
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
Definition: put_bits.h:386
AV_CODEC_ID_H265
#define AV_CODEC_ID_H265
Definition: codec_id.h:227
CodedBitstreamH265Context::active_vps
const H265RawVPS * active_vps
Definition: cbs_h265.h:694
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
temp
else temp
Definition: vf_mcdeint.c:263
content_light_level_info
static int FUNC() content_light_level_info(CodedBitstreamContext *ctx, RWContext *rw, SEIRawContentLightLevelInfo *current, SEIMessageState *state)
Definition: cbs_sei_syntax_template.c:120
cbs_write_ue_golomb
static int cbs_write_ue_golomb(CodedBitstreamContext *ctx, PutBitContext *pbc, const char *name, const int *subscripts, uint32_t value, uint32_t range_min, uint32_t range_max)
Definition: cbs_h2645.c:138
VVC_RASL_NUT
@ VVC_RASL_NUT
Definition: vvc.h:32
cbs_h266_free_sei
static void cbs_h266_free_sei(void *opaque, uint8_t *content)
Definition: cbs_h2645.c:1998
sei_buffering_period
static int FUNC() sei_buffering_period(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIBufferingPeriod *current, SEIMessageState *sei)
Definition: cbs_h264_syntax_template.c:513
SEI_TYPE_RECOVERY_POINT
@ SEI_TYPE_RECOVERY_POINT
Definition: sei.h:36
dci
static int FUNC() dci(CodedBitstreamContext *ctx, RWContext *rw, H266RawDCI *current)
Definition: cbs_h266_syntax_template.c:670
SEI_TYPE_DECODED_PICTURE_HASH
@ SEI_TYPE_DECODED_PICTURE_HASH
Definition: sei.h:91
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
cbs_h265_discarded_nal_unit
static int cbs_h265_discarded_nal_unit(CodedBitstreamContext *ctx, const CodedBitstreamUnit *unit, enum AVDiscard skip)
Definition: cbs_h2645.c:1527
H264RawSEIRecoveryPoint
Definition: cbs_h264.h:268
flush
void(* flush)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:367
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
cbs_h266_syntax_template.c
ff_cbs_type_h266
const CodedBitstreamType ff_cbs_type_h266
Definition: cbs_h2645.c:2063
H264_NAL_SLICE
@ H264_NAL_SLICE
Definition: h264.h:35
cbs_h265_read_nal_unit
static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_h2645.c:911
H265RawSlice::data
uint8_t * data
Definition: cbs_h265.h:536
CBS_UNIT_TYPES_INTERNAL_REF
#define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field)
Definition: cbs_internal.h:303
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
cbs_h2645_write_slice_data
static int cbs_h2645_write_slice_data(CodedBitstreamContext *ctx, PutBitContext *pbc, const uint8_t *data, size_t data_size, int data_bit_start)
Definition: cbs_h2645.c:1188
cbs_h265_unit_types
static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[]
Definition: cbs_h2645.c:1978
VVC_IDR_N_LP
@ VVC_IDR_N_LP
Definition: vvc.h:37
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
h264.h
VVC_PREFIX_APS_NUT
@ VVC_PREFIX_APS_NUT
Definition: vvc.h:46
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
H264RawFiller
Definition: cbs_h264.h:397
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
sei_recovery_point
static int FUNC() sei_recovery_point(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIRecoveryPoint *current, SEIMessageState *sei)
Definition: cbs_h264_syntax_template.c:706
ff_cbs_type_h264
const CodedBitstreamType ff_cbs_type_h264
Definition: cbs_h2645.c:2029
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition: sei.h:103
CodedBitstreamFragment::data_ref
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:145
cbs_h264_read_nal_unit
static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_h2645.c:792
H264RawSPSExtension
Definition: cbs_h264.h:157
H264RawSEIBufferingPeriod
Definition: cbs_h264.h:224
ff_cbs_sei_free_message_list
void ff_cbs_sei_free_message_list(SEIRawMessageList *list)
Free all SEI messages in a message list.
Definition: cbs_sei.c:100
H266RawSEIDecodedPictureHash
Definition: cbs_h266.h:849
AVDiscard
AVDiscard
Definition: defs.h:202
CodedBitstreamH266Context::pps_ref
AVBufferRef * pps_ref[VVC_MAX_PPS_COUNT]
Definition: cbs_h266.h:872
AVDISCARD_NONREF
@ AVDISCARD_NONREF
discard all non reference
Definition: defs.h:207
sei_pic_timing
static int FUNC() sei_pic_timing(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIPicTiming *current, SEIMessageState *sei)
Definition: cbs_h264_syntax_template.c:607
HEVC_NAL_SEI_PREFIX
@ HEVC_NAL_SEI_PREFIX
Definition: hevc.h:68
CodedBitstreamH264Context::sps
H264RawSPS * sps[H264_MAX_SPS_COUNT]
Definition: cbs_h264.h:412
SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
@ SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
Definition: sei.h:49
ff_cbs_type_h265
const CodedBitstreamType ff_cbs_type_h265
Definition: cbs_h2645.c:2046
CBS_TRACE_READ_START
#define CBS_TRACE_READ_START()
Definition: cbs_internal.h:207
H2645Packet
Definition: h2645_parse.h:82
SEI_TYPE_ACTIVE_PARAMETER_SETS
@ SEI_TYPE_ACTIVE_PARAMETER_SETS
Definition: sei.h:87
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1133
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
VVC_STSA_NUT
@ VVC_STSA_NUT
Definition: vvc.h:30
cbs_h264_write_nal_unit
static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition: cbs_h2645.c:1246
H264RawSlice::data_size
size_t data_size
Definition: cbs_h264.h:393
H265RawSEIBufferingPeriod
Definition: cbs_h265.h:543
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
cbs_sei_h264_types
static const SEIMessageTypeDescriptor cbs_sei_h264_types[]
Definition: cbs_h2645.c:2125
H265RawSEIAlphaChannelInfo
Definition: cbs_h265.h:662
cbs_h2645_assemble_fragment
static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs_h2645.c:1767
CodedBitstreamFragment::nb_units
int nb_units
Number of units in this fragment.
Definition: cbs.h:153
cbs_h2645_read_more_rbsp_data
static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition: cbs_h2645.c:316
user_data_registered
static int FUNC() user_data_registered(CodedBitstreamContext *ctx, RWContext *rw, SEIRawUserDataRegistered *current, SEIMessageState *state)
Definition: cbs_sei_syntax_template.c:38
CodedBitstreamH265Context
Definition: cbs_h265.h:678
H266RawSlice
Definition: cbs_h266.h:840
H265RawSlice
Definition: cbs_h265.h:533
H264RawSlice
Definition: cbs_h264.h:388
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:153
cbs_h266_write_nal_unit
static int cbs_h266_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition: cbs_h2645.c:1600
CBS_TRACE_READ_END
#define CBS_TRACE_READ_END()
Definition: cbs_internal.h:215
H264RawSPS
Definition: cbs_h264.h:102
CBS_TRACE_WRITE_START
#define CBS_TRACE_WRITE_START()
Definition: cbs_internal.h:245
VVC_TRAIL_NUT
@ VVC_TRAIL_NUT
Definition: vvc.h:29
H264RawPPS
Definition: cbs_h264.h:171