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