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