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  if (bytestream2_get_bytes_left(&gbc) < 2)
712  return AVERROR_INVALIDDATA;
713  size = bytestream2_get_be16(&gbc);
714  if (bytestream2_get_bytes_left(&gbc) < size)
715  return AVERROR_INVALIDDATA;
716  bytestream2_skip(&gbc, size);
717  }
718  end = bytestream2_tell(&gbc);
719 
720  err = ff_h2645_packet_split(&priv->read_packet,
721  frag->data + start, end - start,
722  ctx->log_ctx, 1, 2, AV_CODEC_ID_VVC, 1, 1);
723  if (err < 0) {
724  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
725  "VVCC array %d (%d NAL units of type %d).\n",
726  i, num_nalus, nal_unit_type);
727  return err;
728  }
729  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
730  if (err < 0)
731  return err;
732  }
733  } else {
734  // Annex B, or later MP4 with already-known parameters.
735 
736  err = ff_h2645_packet_split(&priv->read_packet,
737  frag->data, frag->data_size,
738  ctx->log_ctx,
739  priv->mp4, priv->nal_length_size,
740  codec_id, 1, 1);
741  if (err < 0)
742  return err;
743 
744  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
745  if (err < 0)
746  return err;
747  }
748 
749  return 0;
750 }
751 
752 #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
753 static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
754  CodedBitstreamUnit *unit) \
755 { \
756  CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
757  H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
758  unsigned int id = ps_var->id_element; \
759  int err = ff_cbs_make_unit_refcounted(ctx, unit); \
760  if (err < 0) \
761  return err; \
762  if (priv->ps_var[id] == priv->active_ ## ps_var) \
763  priv->active_ ## ps_var = NULL ; \
764  av_assert0(unit->content_ref); \
765  ff_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
766  return 0; \
767 }
768 
769 cbs_h2645_replace_ps(4, SPS, sps, seq_parameter_set_id)
770 cbs_h2645_replace_ps(4, PPS, pps, pic_parameter_set_id)
771 cbs_h2645_replace_ps(5, VPS, vps, vps_video_parameter_set_id)
772 cbs_h2645_replace_ps(5, SPS, sps, sps_seq_parameter_set_id)
773 cbs_h2645_replace_ps(5, PPS, pps, pps_pic_parameter_set_id)
774 
775 #define cbs_h266_replace_ps(h26n, ps_name, ps_var, id_element) \
776 static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
777  CodedBitstreamUnit *unit) \
778 { \
779  CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
780  H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
781  unsigned int id = ps_var->id_element; \
782  int err = ff_cbs_make_unit_refcounted(ctx, unit); \
783  if (err < 0) \
784  return err; \
785  av_assert0(unit->content_ref); \
786  ff_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
787  return 0; \
788 }
789 
790 cbs_h266_replace_ps(6, VPS, vps, vps_video_parameter_set_id)
791 cbs_h266_replace_ps(6, SPS, sps, sps_seq_parameter_set_id)
792 cbs_h266_replace_ps(6, PPS, pps, pps_pic_parameter_set_id)
793 
794 static int cbs_h266_replace_ph(CodedBitstreamContext *ctx,
795  CodedBitstreamUnit *unit,
797 {
799  int err;
800 
801  err = ff_cbs_make_unit_refcounted(ctx, unit);
802  if (err < 0)
803  return err;
804  av_assert0(unit->content_ref);
805  ff_refstruct_replace(&h266->ph_ref, unit->content_ref);
806  h266->ph = ph;
807  return 0;
808 }
809 
811  CodedBitstreamUnit *unit)
812 {
813  GetBitContext gbc;
814  int err;
815 
816  err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
817  if (err < 0)
818  return err;
819 
820  err = ff_cbs_alloc_unit_content(ctx, unit);
821  if (err < 0)
822  return err;
823 
824  switch (unit->type) {
825  case H264_NAL_SPS:
826  {
827  H264RawSPS *sps = unit->content;
828 
829  err = cbs_h264_read_sps(ctx, &gbc, sps);
830  if (err < 0)
831  return err;
832 
833  err = cbs_h264_replace_sps(ctx, unit);
834  if (err < 0)
835  return err;
836  }
837  break;
838 
839  case H264_NAL_SPS_EXT:
840  {
841  err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content);
842  if (err < 0)
843  return err;
844  }
845  break;
846 
847  case H264_NAL_PPS:
848  {
849  H264RawPPS *pps = unit->content;
850 
851  err = cbs_h264_read_pps(ctx, &gbc, pps);
852  if (err < 0)
853  return err;
854 
855  err = cbs_h264_replace_pps(ctx, unit);
856  if (err < 0)
857  return err;
858  }
859  break;
860 
861  case H264_NAL_SLICE:
862  case H264_NAL_IDR_SLICE:
864  {
865  H264RawSlice *slice = unit->content;
866  int pos, len;
867 
868  err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header);
869  if (err < 0)
870  return err;
871 
873  return AVERROR_INVALIDDATA;
874 
875  pos = get_bits_count(&gbc);
876  len = unit->data_size;
877 
878  slice->data_size = len - pos / 8;
879  slice->data_ref = av_buffer_ref(unit->data_ref);
880  if (!slice->data_ref)
881  return AVERROR(ENOMEM);
882  slice->data = unit->data + pos / 8;
883  slice->data_bit_start = pos % 8;
884  }
885  break;
886 
887  case H264_NAL_AUD:
888  {
889  err = cbs_h264_read_aud(ctx, &gbc, unit->content);
890  if (err < 0)
891  return err;
892  }
893  break;
894 
895  case H264_NAL_SEI:
896  {
897  err = cbs_h264_read_sei(ctx, &gbc, unit->content);
898  if (err < 0)
899  return err;
900  }
901  break;
902 
904  {
905  err = cbs_h264_read_filler(ctx, &gbc, unit->content);
906  if (err < 0)
907  return err;
908  }
909  break;
910 
912  case H264_NAL_END_STREAM:
913  {
914  err = (unit->type == H264_NAL_END_SEQUENCE ?
915  cbs_h264_read_end_of_sequence :
916  cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content);
917  if (err < 0)
918  return err;
919  }
920  break;
921 
922  default:
923  return AVERROR(ENOSYS);
924  }
925 
926  return 0;
927 }
928 
930  CodedBitstreamUnit *unit)
931 {
932  GetBitContext gbc;
933  int err;
934 
935  err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
936  if (err < 0)
937  return err;
938 
939  err = ff_cbs_alloc_unit_content(ctx, unit);
940  if (err < 0)
941  return err;
942 
943  switch (unit->type) {
944  case HEVC_NAL_VPS:
945  {
946  H265RawVPS *vps = unit->content;
947 
948  err = cbs_h265_read_vps(ctx, &gbc, vps);
949  if (err < 0)
950  return err;
951 
952  err = cbs_h265_replace_vps(ctx, unit);
953  if (err < 0)
954  return err;
955  }
956  break;
957  case HEVC_NAL_SPS:
958  {
959  H265RawSPS *sps = unit->content;
960 
961  err = cbs_h265_read_sps(ctx, &gbc, sps);
962  if (err < 0)
963  return err;
964 
965  err = cbs_h265_replace_sps(ctx, unit);
966  if (err < 0)
967  return err;
968  }
969  break;
970 
971  case HEVC_NAL_PPS:
972  {
973  H265RawPPS *pps = unit->content;
974 
975  err = cbs_h265_read_pps(ctx, &gbc, pps);
976  if (err < 0)
977  return err;
978 
979  err = cbs_h265_replace_pps(ctx, unit);
980  if (err < 0)
981  return err;
982  }
983  break;
984 
985  case HEVC_NAL_TRAIL_N:
986  case HEVC_NAL_TRAIL_R:
987  case HEVC_NAL_TSA_N:
988  case HEVC_NAL_TSA_R:
989  case HEVC_NAL_STSA_N:
990  case HEVC_NAL_STSA_R:
991  case HEVC_NAL_RADL_N:
992  case HEVC_NAL_RADL_R:
993  case HEVC_NAL_RASL_N:
994  case HEVC_NAL_RASL_R:
995  case HEVC_NAL_BLA_W_LP:
996  case HEVC_NAL_BLA_W_RADL:
997  case HEVC_NAL_BLA_N_LP:
998  case HEVC_NAL_IDR_W_RADL:
999  case HEVC_NAL_IDR_N_LP:
1000  case HEVC_NAL_CRA_NUT:
1001  {
1002  H265RawSlice *slice = unit->content;
1003  int pos, len;
1004 
1005  err = cbs_h265_read_slice_segment_header(ctx, &gbc, &slice->header);
1006  if (err < 0)
1007  return err;
1008 
1009  if (!cbs_h2645_read_more_rbsp_data(&gbc))
1010  return AVERROR_INVALIDDATA;
1011 
1012  pos = get_bits_count(&gbc);
1013  len = unit->data_size;
1014 
1015  slice->data_size = len - pos / 8;
1016  slice->data_ref = av_buffer_ref(unit->data_ref);
1017  if (!slice->data_ref)
1018  return AVERROR(ENOMEM);
1019  slice->data = unit->data + pos / 8;
1020  slice->data_bit_start = pos % 8;
1021  }
1022  break;
1023 
1024  case HEVC_NAL_AUD:
1025  {
1026  err = cbs_h265_read_aud(ctx, &gbc, unit->content);
1027  if (err < 0)
1028  return err;
1029  }
1030  break;
1031 
1032  case HEVC_NAL_SEI_PREFIX:
1033  case HEVC_NAL_SEI_SUFFIX:
1034  {
1035  err = cbs_h265_read_sei(ctx, &gbc, unit->content,
1036  unit->type == HEVC_NAL_SEI_PREFIX);
1037 
1038  if (err < 0)
1039  return err;
1040  }
1041  break;
1042 
1043  default:
1044  return AVERROR(ENOSYS);
1045  }
1046 
1047  return 0;
1048 }
1049 
1051  CodedBitstreamUnit *unit)
1052 {
1053  GetBitContext gbc;
1054  int err;
1055 
1056  err = init_get_bits8(&gbc, unit->data, unit->data_size);
1057  if (err < 0)
1058  return err;
1059 
1060  err = ff_cbs_alloc_unit_content(ctx, unit);
1061  if (err < 0)
1062  return err;
1063 
1064  switch (unit->type) {
1065  case VVC_DCI_NUT:
1066  {
1067  err = cbs_h266_read_dci(ctx, &gbc, unit->content);
1068 
1069  if (err < 0)
1070  return err;
1071  }
1072  break;
1073  case VVC_OPI_NUT:
1074  {
1075  err = cbs_h266_read_opi(ctx, &gbc, unit->content);
1076 
1077  if (err < 0)
1078  return err;
1079  }
1080  break;
1081  case VVC_VPS_NUT:
1082  {
1083  H266RawVPS *vps = unit->content;
1084 
1085  err = cbs_h266_read_vps(ctx, &gbc, vps);
1086  if (err < 0)
1087  return err;
1088 
1089  err = cbs_h266_replace_vps(ctx, unit);
1090  if (err < 0)
1091  return err;
1092  }
1093  break;
1094  case VVC_SPS_NUT:
1095  {
1096  H266RawSPS *sps = unit->content;
1097 
1098  err = cbs_h266_read_sps(ctx, &gbc, sps);
1099  if (err < 0)
1100  return err;
1101 
1102  err = cbs_h266_replace_sps(ctx, unit);
1103  if (err < 0)
1104  return err;
1105  }
1106  break;
1107 
1108  case VVC_PPS_NUT:
1109  {
1110  H266RawPPS *pps = unit->content;
1111 
1112  err = cbs_h266_read_pps(ctx, &gbc, pps);
1113  if (err < 0)
1114  return err;
1115 
1116  err = cbs_h266_replace_pps(ctx, unit);
1117  if (err < 0)
1118  return err;
1119  }
1120  break;
1121 
1122  case VVC_PREFIX_APS_NUT:
1123  case VVC_SUFFIX_APS_NUT:
1124  {
1125  err = cbs_h266_read_aps(ctx, &gbc, unit->content,
1126  unit->type == VVC_PREFIX_APS_NUT);
1127 
1128  if (err < 0)
1129  return err;
1130  }
1131  break;
1132  case VVC_PH_NUT:
1133  {
1134  H266RawPH *ph = unit->content;
1135  err = cbs_h266_read_ph(ctx, &gbc, ph);
1136  if (err < 0)
1137  return err;
1138  err = cbs_h266_replace_ph(ctx, unit, &ph->ph_picture_header);
1139  if (err < 0)
1140  return err;
1141  }
1142  break;
1143 
1144  case VVC_TRAIL_NUT:
1145  case VVC_STSA_NUT:
1146  case VVC_RADL_NUT:
1147  case VVC_RASL_NUT:
1148  case VVC_IDR_W_RADL:
1149  case VVC_IDR_N_LP:
1150  case VVC_CRA_NUT:
1151  case VVC_GDR_NUT:
1152  {
1153  H266RawSlice *slice = unit->content;
1154  int pos, len;
1155 
1156  err = cbs_h266_read_slice_header(ctx, &gbc, &slice->header);
1157  if (err < 0)
1158  return err;
1159 
1160  if (!cbs_h2645_read_more_rbsp_data(&gbc))
1161  return AVERROR_INVALIDDATA;
1162 
1163  pos = get_bits_count(&gbc);
1164  len = unit->data_size;
1165 
1167  err = cbs_h266_replace_ph(ctx, unit, &slice->header.sh_picture_header);
1168  if (err < 0)
1169  return err;
1170  }
1171 
1172  slice->header_size = pos / 8;
1173  slice->data_size = len - pos / 8;
1174  slice->data_ref = av_buffer_ref(unit->data_ref);
1175  if (!slice->data_ref)
1176  return AVERROR(ENOMEM);
1177  slice->data = unit->data + pos / 8;
1178  slice->data_bit_start = pos % 8;
1179  }
1180  break;
1181 
1182  case VVC_AUD_NUT:
1183  {
1184  err = cbs_h266_read_aud(ctx, &gbc, unit->content);
1185  if (err < 0)
1186  return err;
1187  }
1188  break;
1189 
1190  case VVC_PREFIX_SEI_NUT:
1191  case VVC_SUFFIX_SEI_NUT:
1192  {
1193  err = cbs_h266_read_sei(ctx, &gbc, unit->content,
1194  unit->type == VVC_PREFIX_SEI_NUT);
1195 
1196  if (err < 0)
1197  return err;
1198  }
1199  break;
1200 
1201  default:
1202  return AVERROR(ENOSYS);
1203  }
1204  return 0;
1205 }
1206 
1208  PutBitContext *pbc, const uint8_t *data,
1209  size_t data_size, int data_bit_start)
1210 {
1211  size_t rest = data_size - (data_bit_start + 7) / 8;
1212  const uint8_t *pos = data + data_bit_start / 8;
1213 
1214  av_assert0(data_bit_start >= 0 &&
1215  data_size > data_bit_start / 8);
1216 
1217  if (data_size * 8 + 8 > put_bits_left(pbc))
1218  return AVERROR(ENOSPC);
1219 
1220  if (!rest)
1221  goto rbsp_stop_one_bit;
1222 
1223  // First copy the remaining bits of the first byte
1224  // The above check ensures that we do not accidentally
1225  // copy beyond the rbsp_stop_one_bit.
1226  if (data_bit_start % 8)
1227  put_bits(pbc, 8 - data_bit_start % 8,
1228  *pos++ & MAX_UINT_BITS(8 - data_bit_start % 8));
1229 
1230  if (put_bits_count(pbc) % 8 == 0) {
1231  // If the writer is aligned at this point,
1232  // memcpy can be used to improve performance.
1233  // This happens normally for CABAC.
1234  flush_put_bits(pbc);
1235  memcpy(put_bits_ptr(pbc), pos, rest);
1236  skip_put_bytes(pbc, rest);
1237  } else {
1238  // If not, we have to copy manually.
1239  // rbsp_stop_one_bit forces us to special-case
1240  // the last byte.
1241  uint8_t temp;
1242  int i;
1243 
1244  for (; rest > 4; rest -= 4, pos += 4)
1245  put_bits32(pbc, AV_RB32(pos));
1246 
1247  for (; rest > 1; rest--, pos++)
1248  put_bits(pbc, 8, *pos);
1249 
1250  rbsp_stop_one_bit:
1251  temp = rest ? *pos : *pos & MAX_UINT_BITS(8 - data_bit_start % 8);
1252 
1253  av_assert0(temp);
1254  i = ff_ctz(*pos);
1255  temp = temp >> i;
1256  i = rest ? (8 - i) : (8 - i - data_bit_start % 8);
1257  put_bits(pbc, i, temp);
1258  if (put_bits_count(pbc) % 8)
1259  put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0);
1260  }
1261 
1262  return 0;
1263 }
1264 
1266  CodedBitstreamUnit *unit,
1267  PutBitContext *pbc)
1268 {
1269  int err;
1270 
1271  switch (unit->type) {
1272  case H264_NAL_SPS:
1273  {
1274  H264RawSPS *sps = unit->content;
1275 
1276  err = cbs_h264_write_sps(ctx, pbc, sps);
1277  if (err < 0)
1278  return err;
1279 
1280  err = cbs_h264_replace_sps(ctx, unit);
1281  if (err < 0)
1282  return err;
1283  }
1284  break;
1285 
1286  case H264_NAL_SPS_EXT:
1287  {
1288  H264RawSPSExtension *sps_ext = unit->content;
1289 
1290  err = cbs_h264_write_sps_extension(ctx, pbc, sps_ext);
1291  if (err < 0)
1292  return err;
1293  }
1294  break;
1295 
1296  case H264_NAL_PPS:
1297  {
1298  H264RawPPS *pps = unit->content;
1299 
1300  err = cbs_h264_write_pps(ctx, pbc, pps);
1301  if (err < 0)
1302  return err;
1303 
1304  err = cbs_h264_replace_pps(ctx, unit);
1305  if (err < 0)
1306  return err;
1307  }
1308  break;
1309 
1310  case H264_NAL_SLICE:
1311  case H264_NAL_IDR_SLICE:
1313  {
1314  H264RawSlice *slice = unit->content;
1315 
1316  err = cbs_h264_write_slice_header(ctx, pbc, &slice->header);
1317  if (err < 0)
1318  return err;
1319 
1320  if (slice->data) {
1321  err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
1322  slice->data_size,
1323  slice->data_bit_start);
1324  if (err < 0)
1325  return err;
1326  } else {
1327  // No slice data - that was just the header.
1328  // (Bitstream may be unaligned!)
1329  }
1330  }
1331  break;
1332 
1333  case H264_NAL_AUD:
1334  {
1335  err = cbs_h264_write_aud(ctx, pbc, unit->content);
1336  if (err < 0)
1337  return err;
1338  }
1339  break;
1340 
1341  case H264_NAL_SEI:
1342  {
1343  err = cbs_h264_write_sei(ctx, pbc, unit->content);
1344  if (err < 0)
1345  return err;
1346  }
1347  break;
1348 
1349  case H264_NAL_FILLER_DATA:
1350  {
1351  err = cbs_h264_write_filler(ctx, pbc, unit->content);
1352  if (err < 0)
1353  return err;
1354  }
1355  break;
1356 
1357  case H264_NAL_END_SEQUENCE:
1358  {
1359  err = cbs_h264_write_end_of_sequence(ctx, pbc, unit->content);
1360  if (err < 0)
1361  return err;
1362  }
1363  break;
1364 
1365  case H264_NAL_END_STREAM:
1366  {
1367  err = cbs_h264_write_end_of_stream(ctx, pbc, unit->content);
1368  if (err < 0)
1369  return err;
1370  }
1371  break;
1372 
1373  default:
1374  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
1375  "NAL unit type %"PRIu32".\n", unit->type);
1376  return AVERROR_PATCHWELCOME;
1377  }
1378 
1379  return 0;
1380 }
1381 
1383  CodedBitstreamUnit *unit,
1384  PutBitContext *pbc)
1385 {
1386  int err;
1387 
1388  switch (unit->type) {
1389  case HEVC_NAL_VPS:
1390  {
1391  H265RawVPS *vps = unit->content;
1392 
1393  err = cbs_h265_write_vps(ctx, pbc, vps);
1394  if (err < 0)
1395  return err;
1396 
1397  err = cbs_h265_replace_vps(ctx, unit);
1398  if (err < 0)
1399  return err;
1400  }
1401  break;
1402 
1403  case HEVC_NAL_SPS:
1404  {
1405  H265RawSPS *sps = unit->content;
1406 
1407  err = cbs_h265_write_sps(ctx, pbc, sps);
1408  if (err < 0)
1409  return err;
1410 
1411  err = cbs_h265_replace_sps(ctx, unit);
1412  if (err < 0)
1413  return err;
1414  }
1415  break;
1416 
1417  case HEVC_NAL_PPS:
1418  {
1419  H265RawPPS *pps = unit->content;
1420 
1421  err = cbs_h265_write_pps(ctx, pbc, pps);
1422  if (err < 0)
1423  return err;
1424 
1425  err = cbs_h265_replace_pps(ctx, unit);
1426  if (err < 0)
1427  return err;
1428  }
1429  break;
1430 
1431  case HEVC_NAL_TRAIL_N:
1432  case HEVC_NAL_TRAIL_R:
1433  case HEVC_NAL_TSA_N:
1434  case HEVC_NAL_TSA_R:
1435  case HEVC_NAL_STSA_N:
1436  case HEVC_NAL_STSA_R:
1437  case HEVC_NAL_RADL_N:
1438  case HEVC_NAL_RADL_R:
1439  case HEVC_NAL_RASL_N:
1440  case HEVC_NAL_RASL_R:
1441  case HEVC_NAL_BLA_W_LP:
1442  case HEVC_NAL_BLA_W_RADL:
1443  case HEVC_NAL_BLA_N_LP:
1444  case HEVC_NAL_IDR_W_RADL:
1445  case HEVC_NAL_IDR_N_LP:
1446  case HEVC_NAL_CRA_NUT:
1447  {
1448  H265RawSlice *slice = unit->content;
1449 
1450  err = cbs_h265_write_slice_segment_header(ctx, pbc, &slice->header);
1451  if (err < 0)
1452  return err;
1453 
1454  if (slice->data) {
1455  err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
1456  slice->data_size,
1457  slice->data_bit_start);
1458  if (err < 0)
1459  return err;
1460  } else {
1461  // No slice data - that was just the header.
1462  }
1463  }
1464  break;
1465 
1466  case HEVC_NAL_AUD:
1467  {
1468  err = cbs_h265_write_aud(ctx, pbc, unit->content);
1469  if (err < 0)
1470  return err;
1471  }
1472  break;
1473 
1474  case HEVC_NAL_SEI_PREFIX:
1475  case HEVC_NAL_SEI_SUFFIX:
1476  {
1477  err = cbs_h265_write_sei(ctx, pbc, unit->content,
1478  unit->type == HEVC_NAL_SEI_PREFIX);
1479 
1480  if (err < 0)
1481  return err;
1482  }
1483  break;
1484 
1485  default:
1486  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
1487  "NAL unit type %"PRIu32".\n", unit->type);
1488  return AVERROR_PATCHWELCOME;
1489  }
1490 
1491  return 0;
1492 }
1493 
1495  const CodedBitstreamUnit *unit,
1496  enum AVDiscard skip)
1497 {
1499  H264RawSliceHeader *slice;
1500  int slice_type_i, slice_type_b, slice_type_si;
1501 
1502  if (skip <= AVDISCARD_DEFAULT)
1503  return 0;
1504 
1505  // keep non-VCL
1506  if (unit->type != H264_NAL_SLICE &&
1507  unit->type != H264_NAL_IDR_SLICE &&
1508  unit->type != H264_NAL_AUXILIARY_SLICE)
1509  return 0;
1510 
1511  if (skip >= AVDISCARD_ALL)
1512  return 1;
1513 
1514  if (skip >= AVDISCARD_NONKEY && unit->type != H264_NAL_IDR_SLICE)
1515  return 1;
1516 
1517  header = (H264RawNALUnitHeader *)unit->content;
1518  if (!header) {
1519  av_log(ctx->log_ctx, AV_LOG_WARNING,
1520  "h264 nal unit header is null, missing decompose?\n");
1521  return 0;
1522  }
1523 
1524  if (skip >= AVDISCARD_NONREF && !header->nal_ref_idc)
1525  return 1;
1526 
1527  slice = (H264RawSliceHeader *)unit->content;
1528  if (!slice) {
1529  av_log(ctx->log_ctx, AV_LOG_WARNING,
1530  "h264 slice header is null, missing decompose?\n");
1531  return 0;
1532  }
1533 
1534  slice_type_i = slice->slice_type % 5 == 2;
1535  slice_type_b = slice->slice_type % 5 == 1;
1536  slice_type_si = slice->slice_type % 5 == 4;
1537 
1538  if (skip >= AVDISCARD_BIDIR && slice_type_b)
1539  return 1;
1540  if (skip >= AVDISCARD_NONINTRA && !slice_type_i && !slice_type_si)
1541  return 1;
1542 
1543  return 0;
1544 }
1545 
1547  const CodedBitstreamUnit *unit,
1548  enum AVDiscard skip)
1549 {
1550  H265RawSliceHeader *slice;
1551 
1552  if (skip <= AVDISCARD_DEFAULT)
1553  return 0;
1554 
1555  switch (unit->type) {
1556  case HEVC_NAL_BLA_W_LP:
1557  case HEVC_NAL_BLA_W_RADL:
1558  case HEVC_NAL_BLA_N_LP:
1559  case HEVC_NAL_IDR_W_RADL:
1560  case HEVC_NAL_IDR_N_LP:
1561  case HEVC_NAL_CRA_NUT:
1562  // IRAP slice
1563  if (skip < AVDISCARD_ALL)
1564  return 0;
1565  break;
1566 
1567  case HEVC_NAL_TRAIL_R:
1568  case HEVC_NAL_TRAIL_N:
1569  case HEVC_NAL_TSA_N:
1570  case HEVC_NAL_TSA_R:
1571  case HEVC_NAL_STSA_N:
1572  case HEVC_NAL_STSA_R:
1573  case HEVC_NAL_RADL_N:
1574  case HEVC_NAL_RADL_R:
1575  case HEVC_NAL_RASL_N:
1576  case HEVC_NAL_RASL_R:
1577  // Slice
1578  break;
1579  default:
1580  // Don't discard non-slice nal.
1581  return 0;
1582  }
1583 
1584  if (skip >= AVDISCARD_NONKEY)
1585  return 1;
1586 
1587  slice = (H265RawSliceHeader *)unit->content;
1588  if (!slice) {
1589  av_log(ctx->log_ctx, AV_LOG_WARNING,
1590  "h265 slice header is null, missing decompose?\n");
1591  return 0;
1592  }
1593 
1594  if (skip >= AVDISCARD_NONINTRA && slice->slice_type != HEVC_SLICE_I)
1595  return 1;
1596  if (skip >= AVDISCARD_BIDIR && slice->slice_type == HEVC_SLICE_B)
1597  return 1;
1598 
1599  if (skip >= AVDISCARD_NONREF) {
1600  switch (unit->type) {
1601  case HEVC_NAL_TRAIL_N:
1602  case HEVC_NAL_TSA_N:
1603  case HEVC_NAL_STSA_N:
1604  case HEVC_NAL_RADL_N:
1605  case HEVC_NAL_RASL_N:
1606  case HEVC_NAL_VCL_N10:
1607  case HEVC_NAL_VCL_N12:
1608  case HEVC_NAL_VCL_N14:
1609  // non-ref
1610  return 1;
1611  default:
1612  break;
1613  }
1614  }
1615 
1616  return 0;
1617 }
1618 
1620  CodedBitstreamUnit *unit,
1621  PutBitContext *pbc)
1622 {
1623  int err;
1624 
1625  switch (unit->type) {
1626  case VVC_DCI_NUT:
1627  {
1628  H266RawDCI *dci = unit->content;
1629 
1630  err = cbs_h266_write_dci(ctx, pbc, dci);
1631  if (err < 0)
1632  return err;
1633  }
1634  break;
1635  case VVC_OPI_NUT:
1636  {
1637  H266RawOPI *opi = unit->content;
1638 
1639  err = cbs_h266_write_opi(ctx, pbc, opi);
1640  if (err < 0)
1641  return err;
1642  }
1643  break;
1644  case VVC_VPS_NUT:
1645  {
1646  H266RawVPS *vps = unit->content;
1647 
1648  err = cbs_h266_write_vps(ctx, pbc, vps);
1649  if (err < 0)
1650  return err;
1651 
1652  err = cbs_h266_replace_vps(ctx, unit);
1653  if (err < 0)
1654  return err;
1655  }
1656  break;
1657  case VVC_SPS_NUT:
1658  {
1659  H266RawSPS *sps = unit->content;
1660 
1661  err = cbs_h266_write_sps(ctx, pbc, sps);
1662  if (err < 0)
1663  return err;
1664 
1665  err = cbs_h266_replace_sps(ctx, unit);
1666  if (err < 0)
1667  return err;
1668  }
1669  break;
1670 
1671  case VVC_PPS_NUT:
1672  {
1673  H266RawPPS *pps = unit->content;
1674 
1675  err = cbs_h266_write_pps(ctx, pbc, pps);
1676  if (err < 0)
1677  return err;
1678 
1679  err = cbs_h266_replace_pps(ctx, unit);
1680  if (err < 0)
1681  return err;
1682  }
1683  break;
1684 
1685  case VVC_PREFIX_APS_NUT:
1686  case VVC_SUFFIX_APS_NUT:
1687  {
1688  err = cbs_h266_write_aps(ctx, pbc, unit->content,
1689  unit->type == VVC_PREFIX_APS_NUT);
1690  if (err < 0)
1691  return err;
1692  }
1693  break;
1694  case VVC_PH_NUT:
1695  {
1696  H266RawPH *ph = unit->content;
1697  err = cbs_h266_write_ph(ctx, pbc, ph);
1698  if (err < 0)
1699  return err;
1700 
1701  err = cbs_h266_replace_ph(ctx, unit, &ph->ph_picture_header);
1702  if (err < 0)
1703  return err;
1704  }
1705  break;
1706 
1707  case VVC_TRAIL_NUT:
1708  case VVC_STSA_NUT:
1709  case VVC_RADL_NUT:
1710  case VVC_RASL_NUT:
1711  case VVC_IDR_W_RADL:
1712  case VVC_IDR_N_LP:
1713  case VVC_CRA_NUT:
1714  case VVC_GDR_NUT:
1715  {
1716  H266RawSlice *slice = unit->content;
1717 
1718  err = cbs_h266_write_slice_header(ctx, pbc, &slice->header);
1719  if (err < 0)
1720  return err;
1721 
1723  err = cbs_h266_replace_ph(ctx, unit, &slice->header.sh_picture_header);
1724  if (err < 0)
1725  return err;
1726  }
1727 
1728  if (slice->data) {
1729  err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
1730  slice->data_size,
1731  slice->data_bit_start);
1732  if (err < 0)
1733  return err;
1734  } else {
1735  // No slice data - that was just the header.
1736  }
1737  }
1738  break;
1739 
1740  case VVC_AUD_NUT:
1741  {
1742  err = cbs_h266_write_aud(ctx, pbc, unit->content);
1743  if (err < 0)
1744  return err;
1745  }
1746  break;
1747 
1748  case VVC_PREFIX_SEI_NUT:
1749  case VVC_SUFFIX_SEI_NUT:
1750  {
1751  err = cbs_h266_write_sei(ctx, pbc, unit->content,
1752  unit->type == VVC_PREFIX_SEI_NUT);
1753 
1754  if (err < 0)
1755  return err;
1756  }
1757  break;
1758 
1759  default:
1760  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
1761  "NAL unit type %"PRIu32".\n", unit->type);
1762  return AVERROR_PATCHWELCOME;
1763  }
1764 
1765  return 0;
1766 }
1767 
1770  int nal_unit_index)
1771 {
1772  // Section B.1.2 in H.264, section B.2.2 in H.265, H.266.
1773  if (nal_unit_index == 0) {
1774  // Assume that this is the first NAL unit in an access unit.
1775  return 1;
1776  }
1777  if (codec_id == AV_CODEC_ID_H264)
1778  return type == H264_NAL_SPS || type == H264_NAL_PPS;
1779  if (codec_id == AV_CODEC_ID_HEVC)
1780  return type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS;
1781  if (codec_id == AV_CODEC_ID_VVC)
1782  return type >= VVC_OPI_NUT && type <= VVC_SUFFIX_APS_NUT;
1783  return 0;
1784 }
1785 
1787  CodedBitstreamFragment *frag)
1788 {
1789  uint8_t *data;
1790  size_t max_size, dp, sp;
1791  int err, i, zero_run;
1792 
1793  for (i = 0; i < frag->nb_units; i++) {
1794  // Data should already all have been written when we get here.
1795  av_assert0(frag->units[i].data);
1796  }
1797 
1798  max_size = 0;
1799  for (i = 0; i < frag->nb_units; i++) {
1800  // Start code + content with worst-case emulation prevention.
1801  max_size += 4 + frag->units[i].data_size * 3 / 2;
1802  }
1803 
1805  if (!data)
1806  return AVERROR(ENOMEM);
1807 
1808  dp = 0;
1809  for (i = 0; i < frag->nb_units; i++) {
1810  CodedBitstreamUnit *unit = &frag->units[i];
1811 
1812  if (unit->data_bit_padding > 0) {
1813  if (i < frag->nb_units - 1)
1814  av_log(ctx->log_ctx, AV_LOG_WARNING, "Probably invalid "
1815  "unaligned padding on non-final NAL unit.\n");
1816  else
1817  frag->data_bit_padding = unit->data_bit_padding;
1818  }
1819 
1820  if (cbs_h2645_unit_requires_zero_byte(ctx->codec->codec_id, unit->type, i)) {
1821  // zero_byte
1822  data[dp++] = 0;
1823  }
1824  // start_code_prefix_one_3bytes
1825  data[dp++] = 0;
1826  data[dp++] = 0;
1827  data[dp++] = 1;
1828 
1829  zero_run = 0;
1830  for (sp = 0; sp < unit->data_size; sp++) {
1831  if (zero_run < 2) {
1832  if (unit->data[sp] == 0)
1833  ++zero_run;
1834  else
1835  zero_run = 0;
1836  } else {
1837  if ((unit->data[sp] & ~3) == 0) {
1838  // emulation_prevention_three_byte
1839  data[dp++] = 3;
1840  }
1841  zero_run = unit->data[sp] == 0;
1842  }
1843  data[dp++] = unit->data[sp];
1844  }
1845  }
1846 
1847  av_assert0(dp <= max_size);
1849  if (err)
1850  return err;
1851  memset(data + dp, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1852 
1854  NULL, NULL, 0);
1855  if (!frag->data_ref) {
1856  av_freep(&data);
1857  return AVERROR(ENOMEM);
1858  }
1859 
1860  frag->data = data;
1861  frag->data_size = dp;
1862 
1863  return 0;
1864 }
1865 
1867 {
1869 
1870  for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++)
1871  ff_refstruct_unref(&h264->sps[i]);
1872  for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++)
1873  ff_refstruct_unref(&h264->pps[i]);
1874 
1875  h264->active_sps = NULL;
1876  h264->active_pps = NULL;
1877  h264->last_slice_nal_unit_type = 0;
1878 }
1879 
1881 {
1883  int i;
1884 
1886 
1887  for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++)
1888  ff_refstruct_unref(&h264->sps[i]);
1889  for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++)
1890  ff_refstruct_unref(&h264->pps[i]);
1891 }
1892 
1894 {
1896 
1897  for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
1898  ff_refstruct_unref(&h265->vps[i]);
1899  for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
1900  ff_refstruct_unref(&h265->sps[i]);
1901  for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
1902  ff_refstruct_unref(&h265->pps[i]);
1903 
1904  h265->active_vps = NULL;
1905  h265->active_sps = NULL;
1906  h265->active_pps = NULL;
1907 }
1908 
1910 {
1912  int i;
1913 
1915 
1916  for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
1917  ff_refstruct_unref(&h265->vps[i]);
1918  for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
1919  ff_refstruct_unref(&h265->sps[i]);
1920  for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
1921  ff_refstruct_unref(&h265->pps[i]);
1922 }
1923 
1925 {
1927 
1928  for (int i = 0; i < FF_ARRAY_ELEMS(h266->vps); i++)
1929  ff_refstruct_unref(&h266->vps[i]);
1930  for (int i = 0; i < FF_ARRAY_ELEMS(h266->sps); i++)
1931  ff_refstruct_unref(&h266->sps[i]);
1932  for (int i = 0; i < FF_ARRAY_ELEMS(h266->pps); i++)
1933  ff_refstruct_unref(&h266->pps[i]);
1934  ff_refstruct_unref(&h266->ph_ref);
1935 }
1936 
1938 {
1940 
1943  }
1944 
1945 static void cbs_h264_free_sei(FFRefStructOpaque unused, void *content)
1946 {
1947  H264RawSEI *sei = content;
1948  ff_cbs_sei_free_message_list(&sei->message_list);
1949 }
1950 
1954 
1956 
1960 
1965 
1967 
1969 };
1970 
1971 static void cbs_h265_free_sei(FFRefStructOpaque unused, void *content)
1972 {
1973  H265RawSEI *sei = content;
1974  ff_cbs_sei_free_message_list(&sei->message_list);
1975 }
1976 
1981 
1983 
1984  // Slices of non-IRAP pictures.
1986  H265RawSlice, data),
1987  // Slices of IRAP pictures.
1989  H265RawSlice, data),
1990 
1993 
1995 };
1996 
1997 static void cbs_h266_free_sei(FFRefStructOpaque unused, void *content)
1998 {
1999  H266RawSEI *sei = content;
2000  ff_cbs_sei_free_message_list(&sei->message_list);
2001 }
2002 
2007  {
2008  .nb_unit_types = 1,
2009  .unit_type.list[0] = VVC_SPS_NUT,
2010  .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
2011  .content_size = sizeof(H266RawSPS),
2012  .type.ref = {
2013  .nb_offsets = 2,
2014  .offsets = { offsetof(H266RawSPS, extension_data.data),
2015  offsetof(H266RawSPS, vui.extension_data.data) }
2016  },
2017  },
2021 
2024 
2026  H266RawSlice, data),
2027 
2029  H266RawSlice, data),
2030 
2033 
2035 };
2036 
2039 
2040  .priv_data_size = sizeof(CodedBitstreamH264Context),
2041 
2042  .unit_types = cbs_h264_unit_types,
2043 
2044  .split_fragment = &cbs_h2645_split_fragment,
2045  .read_unit = &cbs_h264_read_nal_unit,
2046  .write_unit = &cbs_h264_write_nal_unit,
2047  .discarded_unit = &cbs_h264_discarded_nal_unit,
2048  .assemble_fragment = &cbs_h2645_assemble_fragment,
2049 
2050  .flush = &cbs_h264_flush,
2051  .close = &cbs_h264_close,
2052 };
2053 
2056 
2057  .priv_data_size = sizeof(CodedBitstreamH265Context),
2058 
2059  .unit_types = cbs_h265_unit_types,
2060 
2061  .split_fragment = &cbs_h2645_split_fragment,
2062  .read_unit = &cbs_h265_read_nal_unit,
2063  .write_unit = &cbs_h265_write_nal_unit,
2064  .discarded_unit = &cbs_h265_discarded_nal_unit,
2065  .assemble_fragment = &cbs_h2645_assemble_fragment,
2066 
2067  .flush = &cbs_h265_flush,
2068  .close = &cbs_h265_close,
2069 };
2070 
2073 
2074  .priv_data_size = sizeof(CodedBitstreamH266Context),
2075 
2076  .unit_types = cbs_h266_unit_types,
2077 
2078  .split_fragment = &cbs_h2645_split_fragment,
2079  .read_unit = &cbs_h266_read_nal_unit,
2080  .write_unit = &cbs_h266_write_nal_unit,
2081  .assemble_fragment = &cbs_h2645_assemble_fragment,
2082 
2083  .flush = &cbs_h266_flush,
2084  .close = &cbs_h266_close,
2085 };
2086 
2087 // Macro for the read/write pair.
2088 #define SEI_MESSAGE_RW(codec, name) \
2089  .read = cbs_ ## codec ## _read_ ## name ## _internal, \
2090  .write = cbs_ ## codec ## _write_ ## name ## _internal
2091 
2093  {
2095  1, 1,
2096  sizeof(SEIRawFillerPayload),
2097  SEI_MESSAGE_RW(sei, filler_payload),
2098  },
2099  {
2101  1, 1,
2102  sizeof(SEIRawUserDataRegistered),
2103  SEI_MESSAGE_RW(sei, user_data_registered),
2104  },
2105  {
2107  1, 1,
2109  SEI_MESSAGE_RW(sei, user_data_unregistered),
2110  },
2111  {
2113  1, 0,
2115  SEI_MESSAGE_RW(sei, mastering_display_colour_volume),
2116  },
2117  {
2119  1, 0,
2121  SEI_MESSAGE_RW(sei, content_light_level_info),
2122  },
2123  {
2125  1, 0,
2127  SEI_MESSAGE_RW(sei, alternative_transfer_characteristics),
2128  },
2129  {
2131  1, 0,
2133  SEI_MESSAGE_RW(sei, ambient_viewing_environment),
2134  },
2136 };
2137 
2139  {
2141  1, 0,
2142  sizeof(H264RawSEIBufferingPeriod),
2143  SEI_MESSAGE_RW(h264, sei_buffering_period),
2144  },
2145  {
2147  1, 0,
2148  sizeof(H264RawSEIPicTiming),
2149  SEI_MESSAGE_RW(h264, sei_pic_timing),
2150  },
2151  {
2153  1, 0,
2154  sizeof(H264RawSEIPanScanRect),
2155  SEI_MESSAGE_RW(h264, sei_pan_scan_rect),
2156  },
2157  {
2159  1, 0,
2160  sizeof(H264RawSEIRecoveryPoint),
2161  SEI_MESSAGE_RW(h264, sei_recovery_point),
2162  },
2163  {
2165  1, 0,
2167  SEI_MESSAGE_RW(h264, film_grain_characteristics),
2168  },
2169  {
2171  1, 0,
2173  SEI_MESSAGE_RW(h264, sei_display_orientation),
2174  },
2176 };
2177 
2179  {
2181  1, 0,
2182  sizeof(H265RawSEIBufferingPeriod),
2183  SEI_MESSAGE_RW(h265, sei_buffering_period),
2184  },
2185  {
2187  1, 0,
2188  sizeof(H265RawSEIPicTiming),
2189  SEI_MESSAGE_RW(h265, sei_pic_timing),
2190  },
2191  {
2193  1, 0,
2194  sizeof(H265RawSEIPanScanRect),
2195  SEI_MESSAGE_RW(h265, sei_pan_scan_rect),
2196  },
2197  {
2199  1, 0,
2200  sizeof(H265RawSEIRecoveryPoint),
2201  SEI_MESSAGE_RW(h265, sei_recovery_point),
2202  },
2203  {
2205  1, 0,
2207  SEI_MESSAGE_RW(h265, film_grain_characteristics),
2208  },
2209  {
2211  1, 0,
2213  SEI_MESSAGE_RW(h265, sei_display_orientation),
2214  },
2215  {
2217  1, 0,
2219  SEI_MESSAGE_RW(h265, sei_active_parameter_sets),
2220  },
2221  {
2223  0, 1,
2225  SEI_MESSAGE_RW(h265, sei_decoded_picture_hash),
2226  },
2227  {
2229  1, 0,
2230  sizeof(H265RawSEITimeCode),
2231  SEI_MESSAGE_RW(h265, sei_time_code),
2232  },
2233  {
2235  1, 0,
2237  SEI_MESSAGE_RW(h265, sei_alpha_channel_info),
2238  },
2240 };
2241 
2243  {
2245  0, 1,
2247  SEI_MESSAGE_RW(h266, sei_decoded_picture_hash),
2248  },
2250 };
2251 
2253  int payload_type)
2254 {
2256  int i;
2257 
2258  for (i = 0; cbs_sei_common_types[i].type >= 0; i++) {
2259  if (cbs_sei_common_types[i].type == payload_type)
2260  return &cbs_sei_common_types[i];
2261  }
2262 
2263  switch (ctx->codec->codec_id) {
2264  case AV_CODEC_ID_H264:
2266  break;
2267  case AV_CODEC_ID_H265:
2269  break;
2270  case AV_CODEC_ID_H266:
2272  break;
2273  default:
2274  return NULL;
2275  }
2276 
2277  for (i = 0; codec_list[i].type >= 0; i++) {
2278  if (codec_list[i].type == payload_type)
2279  return &codec_list[i];
2280  }
2281 
2282  return NULL;
2283 }
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: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
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:3002
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:2003
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:1768
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:1893
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:2178
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:1866
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:2092
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:2242
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:1971
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:752
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: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:1050
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:1382
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:1937
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:1951
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:1494
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:1909
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:2252
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:1924
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:1381
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:2088
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:1880
cbs_h264_free_sei
static void cbs_h264_free_sei(FFRefStructOpaque unused, void *content)
Definition: cbs_h2645.c:1945
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:1997
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:1546
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:2071
cbs_h265_read_nal_unit
static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_h2645.c:929
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:1207
cbs_h265_unit_types
static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[]
Definition: cbs_h2645.c:1977
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:2037
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:810
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:2054
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:1265
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:2138
H265RawSEIAlphaChannelInfo
Definition: cbs_h265.h:662
cbs_h2645_assemble_fragment
static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs_h2645.c:1786
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:1619
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