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