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