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