FFmpeg  4.4.9
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 "h264.h"
28 #include "h264_sei.h"
29 #include "h2645_parse.h"
30 #include "hevc.h"
31 #include "hevc_sei.h"
32 
33 
35  const char *name, const int *subscripts,
36  uint32_t *write_to,
37  uint32_t range_min, uint32_t range_max)
38 {
39  uint32_t value;
40  int position, i, j;
41  unsigned int k;
42  char bits[65];
43 
44  position = get_bits_count(gbc);
45 
46  for (i = 0; i < 32; i++) {
47  if (get_bits_left(gbc) < i + 1) {
48  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at "
49  "%s: bitstream ended.\n", name);
50  return AVERROR_INVALIDDATA;
51  }
52  k = get_bits1(gbc);
53  bits[i] = k ? '1' : '0';
54  if (k)
55  break;
56  }
57  if (i >= 32) {
58  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid ue-golomb code at "
59  "%s: more than 31 zeroes.\n", name);
60  return AVERROR_INVALIDDATA;
61  }
62  value = 1;
63  for (j = 0; j < i; j++) {
64  k = get_bits1(gbc);
65  bits[i + j + 1] = k ? '1' : '0';
66  value = value << 1 | k;
67  }
68  bits[i + j + 1] = 0;
69  --value;
70 
71  if (ctx->trace_enable)
72  ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
73  bits, value);
74 
75  if (value < range_min || value > range_max) {
76  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
77  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
78  name, value, range_min, range_max);
79  return AVERROR_INVALIDDATA;
80  }
81 
82  *write_to = value;
83  return 0;
84 }
85 
87  const char *name, const int *subscripts,
88  int32_t *write_to,
89  int32_t range_min, int32_t range_max)
90 {
91  int32_t value;
92  int position, i, j;
93  unsigned int k;
94  uint32_t v;
95  char bits[65];
96 
97  position = get_bits_count(gbc);
98 
99  for (i = 0; i < 32; i++) {
100  if (get_bits_left(gbc) < i + 1) {
101  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at "
102  "%s: bitstream ended.\n", name);
103  return AVERROR_INVALIDDATA;
104  }
105  k = get_bits1(gbc);
106  bits[i] = k ? '1' : '0';
107  if (k)
108  break;
109  }
110  if (i >= 32) {
111  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid se-golomb code at "
112  "%s: more than 31 zeroes.\n", name);
113  return AVERROR_INVALIDDATA;
114  }
115  v = 1;
116  for (j = 0; j < i; j++) {
117  k = get_bits1(gbc);
118  bits[i + j + 1] = k ? '1' : '0';
119  v = v << 1 | k;
120  }
121  bits[i + j + 1] = 0;
122  if (v & 1)
123  value = -(int32_t)(v / 2);
124  else
125  value = v / 2;
126 
127  if (ctx->trace_enable)
128  ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
129  bits, value);
130 
131  if (value < range_min || value > range_max) {
132  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
133  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
134  name, value, range_min, range_max);
135  return AVERROR_INVALIDDATA;
136  }
137 
138  *write_to = value;
139  return 0;
140 }
141 
143  const char *name, const int *subscripts,
144  uint32_t value,
145  uint32_t range_min, uint32_t range_max)
146 {
147  int len;
148 
149  if (value < range_min || value > range_max) {
150  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
151  "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
152  name, value, range_min, range_max);
153  return AVERROR_INVALIDDATA;
154  }
155  av_assert0(value != UINT32_MAX);
156 
157  len = av_log2(value + 1);
158  if (put_bits_left(pbc) < 2 * len + 1)
159  return AVERROR(ENOSPC);
160 
161  if (ctx->trace_enable) {
162  char bits[65];
163  int i;
164 
165  for (i = 0; i < len; i++)
166  bits[i] = '0';
167  bits[len] = '1';
168  for (i = 0; i < len; i++)
169  bits[len + i + 1] = (value + 1) >> (len - i - 1) & 1 ? '1' : '0';
170  bits[len + len + 1] = 0;
171 
173  name, subscripts, bits, value);
174  }
175 
176  put_bits(pbc, len, 0);
177  if (len + 1 < 32)
178  put_bits(pbc, len + 1, value + 1);
179  else
180  put_bits32(pbc, value + 1);
181 
182  return 0;
183 }
184 
186  const char *name, const int *subscripts,
187  int32_t value,
188  int32_t range_min, int32_t range_max)
189 {
190  int len;
191  uint32_t uvalue;
192 
193  if (value < range_min || value > range_max) {
194  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
195  "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
196  name, value, range_min, range_max);
197  return AVERROR_INVALIDDATA;
198  }
199  av_assert0(value != INT32_MIN);
200 
201  if (value == 0)
202  uvalue = 0;
203  else if (value > 0)
204  uvalue = 2 * (uint32_t)value - 1;
205  else
206  uvalue = 2 * (uint32_t)-value;
207 
208  len = av_log2(uvalue + 1);
209  if (put_bits_left(pbc) < 2 * len + 1)
210  return AVERROR(ENOSPC);
211 
212  if (ctx->trace_enable) {
213  char bits[65];
214  int i;
215 
216  for (i = 0; i < len; i++)
217  bits[i] = '0';
218  bits[len] = '1';
219  for (i = 0; i < len; i++)
220  bits[len + i + 1] = (uvalue + 1) >> (len - i - 1) & 1 ? '1' : '0';
221  bits[len + len + 1] = 0;
222 
224  name, subscripts, bits, value);
225  }
226 
227  put_bits(pbc, len, 0);
228  if (len + 1 < 32)
229  put_bits(pbc, len + 1, uvalue + 1);
230  else
231  put_bits32(pbc, uvalue + 1);
232 
233  return 0;
234 }
235 
236 // payload_extension_present() - true if we are before the last 1-bit
237 // in the payload structure, which must be in the last byte.
238 static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t payload_size,
239  int cur_pos)
240 {
241  int bits_left = payload_size * 8 - cur_pos;
242  return (bits_left > 0 &&
243  (bits_left > 7 || show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1)));
244 }
245 
246 // PicWidthInCtbsY and PicHeightInCtbsY (7.4.3.2.1).
248  unsigned int *width, unsigned int *height)
249 {
250  unsigned int ctb_log2_size_y = sps->log2_min_luma_coding_block_size_minus3 + 3 +
251  sps->log2_diff_max_min_luma_coding_block_size;
252  *width = AV_CEIL_RSHIFT(sps->pic_width_in_luma_samples, ctb_log2_size_y);
253  *height = AV_CEIL_RSHIFT(sps->pic_height_in_luma_samples, ctb_log2_size_y);
254 }
255 
256 #define HEADER(name) do { \
257  ff_cbs_trace_header(ctx, name); \
258  } while (0)
259 
260 #define CHECK(call) do { \
261  err = (call); \
262  if (err < 0) \
263  return err; \
264  } while (0)
265 
266 #define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
267 #define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
268 #define FUNC_H264(name) FUNC_NAME1(READWRITE, h264, name)
269 #define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name)
270 #define FUNC_SEI(name) FUNC_NAME1(READWRITE, sei, name)
271 
272 #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
273 
274 #define u(width, name, range_min, range_max) \
275  xu(width, name, current->name, range_min, range_max, 0, )
276 #define ub(width, name) \
277  xu(width, name, current->name, 0, MAX_UINT_BITS(width), 0, )
278 #define flag(name) ub(1, name)
279 #define ue(name, range_min, range_max) \
280  xue(name, current->name, range_min, range_max, 0, )
281 #define i(width, name, range_min, range_max) \
282  xi(width, name, current->name, range_min, range_max, 0, )
283 #define ib(width, name) \
284  xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, )
285 #define se(name, range_min, range_max) \
286  xse(name, current->name, range_min, range_max, 0, )
287 
288 #define us(width, name, range_min, range_max, subs, ...) \
289  xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
290 #define ubs(width, name, subs, ...) \
291  xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
292 #define flags(name, subs, ...) \
293  xu(1, name, current->name, 0, 1, subs, __VA_ARGS__)
294 #define ues(name, range_min, range_max, subs, ...) \
295  xue(name, current->name, range_min, range_max, subs, __VA_ARGS__)
296 #define is(width, name, range_min, range_max, subs, ...) \
297  xi(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
298 #define ibs(width, name, subs, ...) \
299  xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), subs, __VA_ARGS__)
300 #define ses(name, range_min, range_max, subs, ...) \
301  xse(name, current->name, range_min, range_max, subs, __VA_ARGS__)
302 
303 #define fixed(width, name, value) do { \
304  av_unused uint32_t fixed_value = value; \
305  xu(width, name, fixed_value, value, value, 0, ); \
306  } while (0)
307 
308 
309 #define READ
310 #define READWRITE read
311 #define RWContext GetBitContext
312 
313 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
314  uint32_t value; \
315  CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
316  SUBSCRIPTS(subs, __VA_ARGS__), \
317  &value, range_min, range_max)); \
318  var = value; \
319  } while (0)
320 #define xue(name, var, range_min, range_max, subs, ...) do { \
321  uint32_t value; \
322  CHECK(cbs_read_ue_golomb(ctx, rw, #name, \
323  SUBSCRIPTS(subs, __VA_ARGS__), \
324  &value, range_min, range_max)); \
325  var = value; \
326  } while (0)
327 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
328  int32_t value; \
329  CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
330  SUBSCRIPTS(subs, __VA_ARGS__), \
331  &value, range_min, range_max)); \
332  var = value; \
333  } while (0)
334 #define xse(name, var, range_min, range_max, subs, ...) do { \
335  int32_t value; \
336  CHECK(cbs_read_se_golomb(ctx, rw, #name, \
337  SUBSCRIPTS(subs, __VA_ARGS__), \
338  &value, range_min, range_max)); \
339  var = value; \
340  } while (0)
341 
342 
343 #define infer(name, value) do { \
344  current->name = value; \
345  } while (0)
346 
348 {
349  int bits_left = get_bits_left(gbc);
350  if (bits_left > 8)
351  return 1;
352  if (bits_left == 0)
353  return 0;
354  if (show_bits(gbc, bits_left) & MAX_UINT_BITS(bits_left - 1))
355  return 1;
356  return 0;
357 }
358 
359 #define more_rbsp_data(var) ((var) = cbs_h2645_read_more_rbsp_data(rw))
360 
361 #define bit_position(rw) (get_bits_count(rw))
362 #define byte_alignment(rw) (get_bits_count(rw) % 8)
363 
364 #define allocate(name, size) do { \
365  name ## _ref = av_buffer_allocz(size + \
366  AV_INPUT_BUFFER_PADDING_SIZE); \
367  if (!name ## _ref) \
368  return AVERROR(ENOMEM); \
369  name = name ## _ref->data; \
370  } while (0)
371 
372 #define FUNC(name) FUNC_SEI(name)
373 #include "cbs_sei_syntax_template.c"
374 #undef FUNC
375 
376 #define FUNC(name) FUNC_H264(name)
378 #undef FUNC
379 
380 #define FUNC(name) FUNC_H265(name)
382 #undef FUNC
383 
384 #undef READ
385 #undef READWRITE
386 #undef RWContext
387 #undef xu
388 #undef xi
389 #undef xue
390 #undef xse
391 #undef infer
392 #undef more_rbsp_data
393 #undef bit_position
394 #undef byte_alignment
395 #undef allocate
396 
397 
398 #define WRITE
399 #define READWRITE write
400 #define RWContext PutBitContext
401 
402 #define xu(width, name, var, range_min, range_max, subs, ...) do { \
403  uint32_t value = var; \
404  CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
405  SUBSCRIPTS(subs, __VA_ARGS__), \
406  value, range_min, range_max)); \
407  } while (0)
408 #define xue(name, var, range_min, range_max, subs, ...) do { \
409  uint32_t value = var; \
410  CHECK(cbs_write_ue_golomb(ctx, rw, #name, \
411  SUBSCRIPTS(subs, __VA_ARGS__), \
412  value, range_min, range_max)); \
413  } while (0)
414 #define xi(width, name, var, range_min, range_max, subs, ...) do { \
415  int32_t value = var; \
416  CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
417  SUBSCRIPTS(subs, __VA_ARGS__), \
418  value, range_min, range_max)); \
419  } while (0)
420 #define xse(name, var, range_min, range_max, subs, ...) do { \
421  int32_t value = var; \
422  CHECK(cbs_write_se_golomb(ctx, rw, #name, \
423  SUBSCRIPTS(subs, __VA_ARGS__), \
424  value, range_min, range_max)); \
425  } while (0)
426 
427 #define infer(name, value) do { \
428  if (current->name != (value)) { \
429  av_log(ctx->log_ctx, AV_LOG_ERROR, \
430  "%s does not match inferred value: " \
431  "%"PRId64", but should be %"PRId64".\n", \
432  #name, (int64_t)current->name, (int64_t)(value)); \
433  return AVERROR_INVALIDDATA; \
434  } \
435  } while (0)
436 
437 #define more_rbsp_data(var) (var)
438 
439 #define bit_position(rw) (put_bits_count(rw))
440 #define byte_alignment(rw) (put_bits_count(rw) % 8)
441 
442 #define allocate(name, size) do { \
443  if (!name) { \
444  av_log(ctx->log_ctx, AV_LOG_ERROR, "%s must be set " \
445  "for writing.\n", #name); \
446  return AVERROR_INVALIDDATA; \
447  } \
448  } while (0)
449 
450 #define FUNC(name) FUNC_SEI(name)
451 #include "cbs_sei_syntax_template.c"
452 #undef FUNC
453 
454 #define FUNC(name) FUNC_H264(name)
456 #undef FUNC
457 
458 #define FUNC(name) FUNC_H265(name)
460 #undef FUNC
461 
462 #undef WRITE
463 #undef READWRITE
464 #undef RWContext
465 #undef xu
466 #undef xi
467 #undef xue
468 #undef xse
469 #undef u
470 #undef i
471 #undef flag
472 #undef ue
473 #undef se
474 #undef infer
475 #undef more_rbsp_data
476 #undef bit_position
477 #undef byte_alignment
478 #undef allocate
479 
480 
483  const H2645Packet *packet)
484 {
485  int err, i;
486 
487  for (i = 0; i < packet->nb_nals; i++) {
488  const H2645NAL *nal = &packet->nals[i];
489  AVBufferRef *ref;
490  size_t size = nal->size;
491 
492  if (nal->nuh_layer_id > 0)
493  continue;
494 
495  // Remove trailing zeroes.
496  while (size > 0 && nal->data[size - 1] == 0)
497  --size;
498  if (size == 0) {
499  av_log(ctx->log_ctx, AV_LOG_VERBOSE, "Discarding empty 0 NAL unit\n");
500  continue;
501  }
502 
503  ref = (nal->data == nal->raw_data) ? frag->data_ref
504  : packet->rbsp.rbsp_buffer_ref;
505 
506  err = ff_cbs_insert_unit_data(frag, -1, nal->type,
507  (uint8_t*)nal->data, size, ref);
508  if (err < 0)
509  return err;
510  }
511 
512  return 0;
513 }
514 
517  int header)
518 {
519  enum AVCodecID codec_id = ctx->codec->codec_id;
521  GetByteContext gbc;
522  int err;
523 
524  av_assert0(frag->data && frag->nb_units == 0);
525  if (frag->data_size == 0)
526  return 0;
527 
528  if (header && frag->data[0] && codec_id == AV_CODEC_ID_H264) {
529  // AVCC header.
530  size_t size, start, end;
531  int i, count, version;
532 
533  priv->mp4 = 1;
534 
535  bytestream2_init(&gbc, frag->data, frag->data_size);
536 
537  if (bytestream2_get_bytes_left(&gbc) < 6)
538  return AVERROR_INVALIDDATA;
539 
540  version = bytestream2_get_byte(&gbc);
541  if (version != 1) {
542  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid AVCC header: "
543  "first byte %u.\n", version);
544  return AVERROR_INVALIDDATA;
545  }
546 
547  bytestream2_skip(&gbc, 3);
548  priv->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1;
549 
550  // SPS array.
551  count = bytestream2_get_byte(&gbc) & 0x1f;
552  start = bytestream2_tell(&gbc);
553  for (i = 0; i < count; i++) {
554  if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i))
555  return AVERROR_INVALIDDATA;
556  size = bytestream2_get_be16(&gbc);
557  if (bytestream2_get_bytes_left(&gbc) < size)
558  return AVERROR_INVALIDDATA;
559  bytestream2_skip(&gbc, size);
560  }
561  end = bytestream2_tell(&gbc);
562 
563  err = ff_h2645_packet_split(&priv->read_packet,
564  frag->data + start, end - start,
565  ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1);
566  if (err < 0) {
567  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n");
568  return err;
569  }
570  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
571  if (err < 0)
572  return err;
573 
574  // PPS array.
575  count = bytestream2_get_byte(&gbc);
576  start = bytestream2_tell(&gbc);
577  for (i = 0; i < count; i++) {
578  if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i))
579  return AVERROR_INVALIDDATA;
580  size = bytestream2_get_be16(&gbc);
581  if (bytestream2_get_bytes_left(&gbc) < size)
582  return AVERROR_INVALIDDATA;
583  bytestream2_skip(&gbc, size);
584  }
585  end = bytestream2_tell(&gbc);
586 
587  err = ff_h2645_packet_split(&priv->read_packet,
588  frag->data + start, end - start,
589  ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1);
590  if (err < 0) {
591  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n");
592  return err;
593  }
594  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
595  if (err < 0)
596  return err;
597 
598  if (bytestream2_get_bytes_left(&gbc) > 0) {
599  av_log(ctx->log_ctx, AV_LOG_WARNING, "%u bytes left at end of AVCC "
600  "header.\n", bytestream2_get_bytes_left(&gbc));
601  }
602 
603  } else if (header && frag->data[0] && codec_id == AV_CODEC_ID_HEVC) {
604  // HVCC header.
605  size_t size, start, end;
606  int i, j, nb_arrays, nal_unit_type, nb_nals, version;
607 
608  priv->mp4 = 1;
609 
610  bytestream2_init(&gbc, frag->data, frag->data_size);
611 
612  if (bytestream2_get_bytes_left(&gbc) < 23)
613  return AVERROR_INVALIDDATA;
614 
615  version = bytestream2_get_byte(&gbc);
616  if (version != 1) {
617  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid HVCC header: "
618  "first byte %u.\n", version);
619  return AVERROR_INVALIDDATA;
620  }
621 
622  bytestream2_skip(&gbc, 20);
623  priv->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1;
624 
625  nb_arrays = bytestream2_get_byte(&gbc);
626  for (i = 0; i < nb_arrays; i++) {
627  nal_unit_type = bytestream2_get_byte(&gbc) & 0x3f;
628  nb_nals = bytestream2_get_be16(&gbc);
629 
630  start = bytestream2_tell(&gbc);
631  for (j = 0; j < nb_nals; j++) {
632  if (bytestream2_get_bytes_left(&gbc) < 2)
633  return AVERROR_INVALIDDATA;
634  size = bytestream2_get_be16(&gbc);
635  if (bytestream2_get_bytes_left(&gbc) < size)
636  return AVERROR_INVALIDDATA;
637  bytestream2_skip(&gbc, size);
638  }
639  end = bytestream2_tell(&gbc);
640 
641  err = ff_h2645_packet_split(&priv->read_packet,
642  frag->data + start, end - start,
643  ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 1);
644  if (err < 0) {
645  av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
646  "HVCC array %d (%d NAL units of type %d).\n",
647  i, nb_nals, nal_unit_type);
648  return err;
649  }
650  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
651  if (err < 0)
652  return err;
653  }
654 
655  } else {
656  // Annex B, or later MP4 with already-known parameters.
657 
658  err = ff_h2645_packet_split(&priv->read_packet,
659  frag->data, frag->data_size,
660  ctx->log_ctx,
661  priv->mp4, priv->nal_length_size,
662  codec_id, 1, 1);
663  if (err < 0)
664  return err;
665 
666  err = cbs_h2645_fragment_add_nals(ctx, frag, &priv->read_packet);
667  if (err < 0)
668  return err;
669  }
670 
671  return 0;
672 }
673 
674 #define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element) \
675 static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \
676  CodedBitstreamUnit *unit) \
677 { \
678  CodedBitstreamH26 ## h26n ## Context *priv = ctx->priv_data; \
679  H26 ## h26n ## Raw ## ps_name *ps_var = unit->content; \
680  unsigned int id = ps_var->id_element; \
681  int err; \
682  if (id >= FF_ARRAY_ELEMS(priv->ps_var)) { \
683  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid " #ps_name \
684  " id : %d.\n", id); \
685  return AVERROR_INVALIDDATA; \
686  } \
687  err = ff_cbs_make_unit_refcounted(ctx, unit); \
688  if (err < 0) \
689  return err; \
690  if (priv->ps_var[id] == priv->active_ ## ps_var) \
691  priv->active_ ## ps_var = NULL ; \
692  av_buffer_unref(&priv->ps_var ## _ref[id]); \
693  av_assert0(unit->content_ref); \
694  priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \
695  if (!priv->ps_var ## _ref[id]) \
696  return AVERROR(ENOMEM); \
697  priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \
698  return 0; \
699 }
700 
701 cbs_h2645_replace_ps(4, SPS, sps, seq_parameter_set_id)
702 cbs_h2645_replace_ps(4, PPS, pps, pic_parameter_set_id)
703 cbs_h2645_replace_ps(5, VPS, vps, vps_video_parameter_set_id)
704 cbs_h2645_replace_ps(5, SPS, sps, sps_seq_parameter_set_id)
705 cbs_h2645_replace_ps(5, PPS, pps, pps_pic_parameter_set_id)
706 
707 static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx,
708  CodedBitstreamUnit *unit)
709 {
710  GetBitContext gbc;
711  int err;
712 
713  err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
714  if (err < 0)
715  return err;
716 
717  err = ff_cbs_alloc_unit_content2(ctx, unit);
718  if (err < 0)
719  return err;
720 
721  switch (unit->type) {
722  case H264_NAL_SPS:
723  {
724  H264RawSPS *sps = unit->content;
725 
726  err = cbs_h264_read_sps(ctx, &gbc, sps);
727  if (err < 0)
728  return err;
729 
730  err = cbs_h264_replace_sps(ctx, unit);
731  if (err < 0)
732  return err;
733  }
734  break;
735 
736  case H264_NAL_SPS_EXT:
737  {
738  err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content);
739  if (err < 0)
740  return err;
741  }
742  break;
743 
744  case H264_NAL_PPS:
745  {
746  H264RawPPS *pps = unit->content;
747 
748  err = cbs_h264_read_pps(ctx, &gbc, pps);
749  if (err < 0)
750  return err;
751 
752  err = cbs_h264_replace_pps(ctx, unit);
753  if (err < 0)
754  return err;
755  }
756  break;
757 
758  case H264_NAL_SLICE:
759  case H264_NAL_IDR_SLICE:
761  {
762  H264RawSlice *slice = unit->content;
763  int pos, len;
764 
765  err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header);
766  if (err < 0)
767  return err;
768 
770  return AVERROR_INVALIDDATA;
771 
772  pos = get_bits_count(&gbc);
773  len = unit->data_size;
774 
775  slice->data_size = len - pos / 8;
776  slice->data_ref = av_buffer_ref(unit->data_ref);
777  if (!slice->data_ref)
778  return AVERROR(ENOMEM);
779  slice->data = unit->data + pos / 8;
780  slice->data_bit_start = pos % 8;
781  }
782  break;
783 
784  case H264_NAL_AUD:
785  {
786  err = cbs_h264_read_aud(ctx, &gbc, unit->content);
787  if (err < 0)
788  return err;
789  }
790  break;
791 
792  case H264_NAL_SEI:
793  {
794  err = cbs_h264_read_sei(ctx, &gbc, unit->content);
795  if (err < 0)
796  return err;
797  }
798  break;
799 
801  {
802  err = cbs_h264_read_filler(ctx, &gbc, unit->content);
803  if (err < 0)
804  return err;
805  }
806  break;
807 
809  case H264_NAL_END_STREAM:
810  {
811  err = (unit->type == H264_NAL_END_SEQUENCE ?
812  cbs_h264_read_end_of_sequence :
813  cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content);
814  if (err < 0)
815  return err;
816  }
817  break;
818 
819  default:
820  return AVERROR(ENOSYS);
821  }
822 
823  return 0;
824 }
825 
827  CodedBitstreamUnit *unit)
828 {
829  GetBitContext gbc;
830  int err;
831 
832  err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
833  if (err < 0)
834  return err;
835 
836  err = ff_cbs_alloc_unit_content2(ctx, unit);
837  if (err < 0)
838  return err;
839 
840  switch (unit->type) {
841  case HEVC_NAL_VPS:
842  {
843  H265RawVPS *vps = unit->content;
844 
845  err = cbs_h265_read_vps(ctx, &gbc, vps);
846  if (err < 0)
847  return err;
848 
849  err = cbs_h265_replace_vps(ctx, unit);
850  if (err < 0)
851  return err;
852  }
853  break;
854  case HEVC_NAL_SPS:
855  {
856  H265RawSPS *sps = unit->content;
857 
858  err = cbs_h265_read_sps(ctx, &gbc, sps);
859  if (err < 0)
860  return err;
861 
862  err = cbs_h265_replace_sps(ctx, unit);
863  if (err < 0)
864  return err;
865  }
866  break;
867 
868  case HEVC_NAL_PPS:
869  {
870  H265RawPPS *pps = unit->content;
871 
872  err = cbs_h265_read_pps(ctx, &gbc, pps);
873  if (err < 0)
874  return err;
875 
876  err = cbs_h265_replace_pps(ctx, unit);
877  if (err < 0)
878  return err;
879  }
880  break;
881 
882  case HEVC_NAL_TRAIL_N:
883  case HEVC_NAL_TRAIL_R:
884  case HEVC_NAL_TSA_N:
885  case HEVC_NAL_TSA_R:
886  case HEVC_NAL_STSA_N:
887  case HEVC_NAL_STSA_R:
888  case HEVC_NAL_RADL_N:
889  case HEVC_NAL_RADL_R:
890  case HEVC_NAL_RASL_N:
891  case HEVC_NAL_RASL_R:
892  case HEVC_NAL_BLA_W_LP:
893  case HEVC_NAL_BLA_W_RADL:
894  case HEVC_NAL_BLA_N_LP:
895  case HEVC_NAL_IDR_W_RADL:
896  case HEVC_NAL_IDR_N_LP:
897  case HEVC_NAL_CRA_NUT:
898  {
899  H265RawSlice *slice = unit->content;
900  int pos, len;
901 
902  err = cbs_h265_read_slice_segment_header(ctx, &gbc, &slice->header);
903  if (err < 0)
904  return err;
905 
907  return AVERROR_INVALIDDATA;
908 
909  pos = get_bits_count(&gbc);
910  len = unit->data_size;
911 
912  slice->data_size = len - pos / 8;
913  slice->data_ref = av_buffer_ref(unit->data_ref);
914  if (!slice->data_ref)
915  return AVERROR(ENOMEM);
916  slice->data = unit->data + pos / 8;
917  slice->data_bit_start = pos % 8;
918  }
919  break;
920 
921  case HEVC_NAL_AUD:
922  {
923  err = cbs_h265_read_aud(ctx, &gbc, unit->content);
924  if (err < 0)
925  return err;
926  }
927  break;
928 
929  case HEVC_NAL_SEI_PREFIX:
930  case HEVC_NAL_SEI_SUFFIX:
931  {
932  err = cbs_h265_read_sei(ctx, &gbc, unit->content,
933  unit->type == HEVC_NAL_SEI_PREFIX);
934 
935  if (err < 0)
936  return err;
937  }
938  break;
939 
940  default:
941  return AVERROR(ENOSYS);
942  }
943 
944  return 0;
945 }
946 
948  PutBitContext *pbc, const uint8_t *data,
949  size_t data_size, int data_bit_start)
950 {
951  size_t rest = data_size - (data_bit_start + 7) / 8;
952  const uint8_t *pos = data + data_bit_start / 8;
953 
954  av_assert0(data_bit_start >= 0 &&
955  data_size > data_bit_start / 8);
956 
957  if (data_size + 1 > put_bits_left(pbc) / 8)
958  return AVERROR(ENOSPC);
959 
960  if (!rest)
961  goto rbsp_stop_one_bit;
962 
963  // First copy the remaining bits of the first byte
964  // The above check ensures that we do not accidentally
965  // copy beyond the rbsp_stop_one_bit.
966  if (data_bit_start % 8)
967  put_bits(pbc, 8 - data_bit_start % 8,
968  *pos++ & MAX_UINT_BITS(8 - data_bit_start % 8));
969 
970  if (put_bits_count(pbc) % 8 == 0) {
971  // If the writer is aligned at this point,
972  // memcpy can be used to improve performance.
973  // This happens normally for CABAC.
974  flush_put_bits(pbc);
975  memcpy(put_bits_ptr(pbc), pos, rest);
976  skip_put_bytes(pbc, rest);
977  } else {
978  // If not, we have to copy manually.
979  // rbsp_stop_one_bit forces us to special-case
980  // the last byte.
981  uint8_t temp;
982  int i;
983 
984  for (; rest > 4; rest -= 4, pos += 4)
985  put_bits32(pbc, AV_RB32(pos));
986 
987  for (; rest > 1; rest--, pos++)
988  put_bits(pbc, 8, *pos);
989 
990  rbsp_stop_one_bit:
991  temp = rest ? *pos : *pos & MAX_UINT_BITS(8 - data_bit_start % 8);
992 
993  av_assert0(temp);
994  i = ff_ctz(*pos);
995  temp = temp >> i;
996  i = rest ? (8 - i) : (8 - i - data_bit_start % 8);
997  put_bits(pbc, i, temp);
998  if (put_bits_count(pbc) % 8)
999  put_bits(pbc, 8 - put_bits_count(pbc) % 8, 0);
1000  }
1001 
1002  return 0;
1003 }
1004 
1006  CodedBitstreamUnit *unit,
1007  PutBitContext *pbc)
1008 {
1009  int err;
1010 
1011  switch (unit->type) {
1012  case H264_NAL_SPS:
1013  {
1014  H264RawSPS *sps = unit->content;
1015 
1016  err = cbs_h264_write_sps(ctx, pbc, sps);
1017  if (err < 0)
1018  return err;
1019 
1020  err = cbs_h264_replace_sps(ctx, unit);
1021  if (err < 0)
1022  return err;
1023  }
1024  break;
1025 
1026  case H264_NAL_SPS_EXT:
1027  {
1028  H264RawSPSExtension *sps_ext = unit->content;
1029 
1030  err = cbs_h264_write_sps_extension(ctx, pbc, sps_ext);
1031  if (err < 0)
1032  return err;
1033  }
1034  break;
1035 
1036  case H264_NAL_PPS:
1037  {
1038  H264RawPPS *pps = unit->content;
1039 
1040  err = cbs_h264_write_pps(ctx, pbc, pps);
1041  if (err < 0)
1042  return err;
1043 
1044  err = cbs_h264_replace_pps(ctx, unit);
1045  if (err < 0)
1046  return err;
1047  }
1048  break;
1049 
1050  case H264_NAL_SLICE:
1051  case H264_NAL_IDR_SLICE:
1053  {
1054  H264RawSlice *slice = unit->content;
1055 
1056  err = cbs_h264_write_slice_header(ctx, pbc, &slice->header);
1057  if (err < 0)
1058  return err;
1059 
1060  if (slice->data) {
1061  err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
1062  slice->data_size,
1063  slice->data_bit_start);
1064  if (err < 0)
1065  return err;
1066  } else {
1067  // No slice data - that was just the header.
1068  // (Bitstream may be unaligned!)
1069  }
1070  }
1071  break;
1072 
1073  case H264_NAL_AUD:
1074  {
1075  err = cbs_h264_write_aud(ctx, pbc, unit->content);
1076  if (err < 0)
1077  return err;
1078  }
1079  break;
1080 
1081  case H264_NAL_SEI:
1082  {
1083  err = cbs_h264_write_sei(ctx, pbc, unit->content);
1084  if (err < 0)
1085  return err;
1086  }
1087  break;
1088 
1089  case H264_NAL_FILLER_DATA:
1090  {
1091  err = cbs_h264_write_filler(ctx, pbc, unit->content);
1092  if (err < 0)
1093  return err;
1094  }
1095  break;
1096 
1097  case H264_NAL_END_SEQUENCE:
1098  {
1099  err = cbs_h264_write_end_of_sequence(ctx, pbc, unit->content);
1100  if (err < 0)
1101  return err;
1102  }
1103  break;
1104 
1105  case H264_NAL_END_STREAM:
1106  {
1107  err = cbs_h264_write_end_of_stream(ctx, pbc, unit->content);
1108  if (err < 0)
1109  return err;
1110  }
1111  break;
1112 
1113  default:
1114  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
1115  "NAL unit type %"PRIu32".\n", unit->type);
1116  return AVERROR_PATCHWELCOME;
1117  }
1118 
1119  return 0;
1120 }
1121 
1123  CodedBitstreamUnit *unit,
1124  PutBitContext *pbc)
1125 {
1126  int err;
1127 
1128  switch (unit->type) {
1129  case HEVC_NAL_VPS:
1130  {
1131  H265RawVPS *vps = unit->content;
1132 
1133  err = cbs_h265_write_vps(ctx, pbc, vps);
1134  if (err < 0)
1135  return err;
1136 
1137  err = cbs_h265_replace_vps(ctx, unit);
1138  if (err < 0)
1139  return err;
1140  }
1141  break;
1142 
1143  case HEVC_NAL_SPS:
1144  {
1145  H265RawSPS *sps = unit->content;
1146 
1147  err = cbs_h265_write_sps(ctx, pbc, sps);
1148  if (err < 0)
1149  return err;
1150 
1151  err = cbs_h265_replace_sps(ctx, unit);
1152  if (err < 0)
1153  return err;
1154  }
1155  break;
1156 
1157  case HEVC_NAL_PPS:
1158  {
1159  H265RawPPS *pps = unit->content;
1160 
1161  err = cbs_h265_write_pps(ctx, pbc, pps);
1162  if (err < 0)
1163  return err;
1164 
1165  err = cbs_h265_replace_pps(ctx, unit);
1166  if (err < 0)
1167  return err;
1168  }
1169  break;
1170 
1171  case HEVC_NAL_TRAIL_N:
1172  case HEVC_NAL_TRAIL_R:
1173  case HEVC_NAL_TSA_N:
1174  case HEVC_NAL_TSA_R:
1175  case HEVC_NAL_STSA_N:
1176  case HEVC_NAL_STSA_R:
1177  case HEVC_NAL_RADL_N:
1178  case HEVC_NAL_RADL_R:
1179  case HEVC_NAL_RASL_N:
1180  case HEVC_NAL_RASL_R:
1181  case HEVC_NAL_BLA_W_LP:
1182  case HEVC_NAL_BLA_W_RADL:
1183  case HEVC_NAL_BLA_N_LP:
1184  case HEVC_NAL_IDR_W_RADL:
1185  case HEVC_NAL_IDR_N_LP:
1186  case HEVC_NAL_CRA_NUT:
1187  {
1188  H265RawSlice *slice = unit->content;
1189 
1190  err = cbs_h265_write_slice_segment_header(ctx, pbc, &slice->header);
1191  if (err < 0)
1192  return err;
1193 
1194  if (slice->data) {
1195  err = cbs_h2645_write_slice_data(ctx, pbc, slice->data,
1196  slice->data_size,
1197  slice->data_bit_start);
1198  if (err < 0)
1199  return err;
1200  } else {
1201  // No slice data - that was just the header.
1202  }
1203  }
1204  break;
1205 
1206  case HEVC_NAL_AUD:
1207  {
1208  err = cbs_h265_write_aud(ctx, pbc, unit->content);
1209  if (err < 0)
1210  return err;
1211  }
1212  break;
1213 
1214  case HEVC_NAL_SEI_PREFIX:
1215  case HEVC_NAL_SEI_SUFFIX:
1216  {
1217  err = cbs_h265_write_sei(ctx, pbc, unit->content,
1218  unit->type == HEVC_NAL_SEI_PREFIX);
1219 
1220  if (err < 0)
1221  return err;
1222  }
1223  break;
1224 
1225  default:
1226  av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
1227  "NAL unit type %"PRIu32".\n", unit->type);
1228  return AVERROR_PATCHWELCOME;
1229  }
1230 
1231  return 0;
1232 }
1233 
1236  int nal_unit_index)
1237 {
1238  // Section B.1.2 in H.264, section B.2.2 in H.265.
1239  if (nal_unit_index == 0) {
1240  // Assume that this is the first NAL unit in an access unit.
1241  return 1;
1242  }
1243  if (codec_id == AV_CODEC_ID_H264)
1244  return type == H264_NAL_SPS || type == H264_NAL_PPS;
1245  if (codec_id == AV_CODEC_ID_HEVC)
1246  return type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS;
1247  return 0;
1248 }
1249 
1251  CodedBitstreamFragment *frag)
1252 {
1253  uint8_t *data;
1254  uint64_t max_size;
1255  size_t dp, sp;
1256  int err, i, zero_run;
1257 
1258  for (i = 0; i < frag->nb_units; i++) {
1259  // Data should already all have been written when we get here.
1260  av_assert0(frag->units[i].data);
1261  }
1262 
1263  max_size = 0;
1264  for (i = 0; i < frag->nb_units; i++) {
1265  // Start code + content with worst-case emulation prevention.
1266  max_size += 4 + frag->units[i].data_size * UINT64_C(3) / 2;
1267  }
1268  if (max_size > SIZE_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
1269  return AVERROR(ENOMEM);
1270 
1272  if (!data)
1273  return AVERROR(ENOMEM);
1274 
1275  dp = 0;
1276  for (i = 0; i < frag->nb_units; i++) {
1277  CodedBitstreamUnit *unit = &frag->units[i];
1278 
1279  if (unit->data_bit_padding > 0) {
1280  if (i < frag->nb_units - 1)
1281  av_log(ctx->log_ctx, AV_LOG_WARNING, "Probably invalid "
1282  "unaligned padding on non-final NAL unit.\n");
1283  else
1284  frag->data_bit_padding = unit->data_bit_padding;
1285  }
1286 
1287  if (cbs_h2645_unit_requires_zero_byte(ctx->codec->codec_id, unit->type, i)) {
1288  // zero_byte
1289  data[dp++] = 0;
1290  }
1291  // start_code_prefix_one_3bytes
1292  data[dp++] = 0;
1293  data[dp++] = 0;
1294  data[dp++] = 1;
1295 
1296  zero_run = 0;
1297  for (sp = 0; sp < unit->data_size; sp++) {
1298  if (zero_run < 2) {
1299  if (unit->data[sp] == 0)
1300  ++zero_run;
1301  else
1302  zero_run = 0;
1303  } else {
1304  if ((unit->data[sp] & ~3) == 0) {
1305  // emulation_prevention_three_byte
1306  data[dp++] = 3;
1307  }
1308  zero_run = unit->data[sp] == 0;
1309  }
1310  data[dp++] = unit->data[sp];
1311  }
1312  }
1313 
1314  av_assert0(dp <= max_size);
1316  if (err)
1317  return err;
1318  memset(data + dp, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1319 
1321  NULL, NULL, 0);
1322  if (!frag->data_ref) {
1323  av_freep(&data);
1324  return AVERROR(ENOMEM);
1325  }
1326 
1327  frag->data = data;
1328  frag->data_size = dp;
1329 
1330  return 0;
1331 }
1332 
1334 {
1336 
1337  for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) {
1338  av_buffer_unref(&h264->sps_ref[i]);
1339  h264->sps[i] = NULL;
1340  }
1341  for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) {
1342  av_buffer_unref(&h264->pps_ref[i]);
1343  h264->pps[i] = NULL;
1344  }
1345 
1346  h264->active_sps = NULL;
1347  h264->active_pps = NULL;
1348  h264->last_slice_nal_unit_type = 0;
1349 }
1350 
1352 {
1354  int i;
1355 
1357 
1358  for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++)
1359  av_buffer_unref(&h264->sps_ref[i]);
1360  for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++)
1361  av_buffer_unref(&h264->pps_ref[i]);
1362 }
1363 
1365 {
1367 
1368  for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) {
1369  av_buffer_unref(&h265->vps_ref[i]);
1370  h265->vps[i] = NULL;
1371  }
1372  for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) {
1373  av_buffer_unref(&h265->sps_ref[i]);
1374  h265->sps[i] = NULL;
1375  }
1376  for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) {
1377  av_buffer_unref(&h265->pps_ref[i]);
1378  h265->pps[i] = NULL;
1379  }
1380 
1381  h265->active_vps = NULL;
1382  h265->active_sps = NULL;
1383  h265->active_pps = NULL;
1384 }
1385 
1387 {
1389  int i;
1390 
1392 
1393  for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
1394  av_buffer_unref(&h265->vps_ref[i]);
1395  for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
1396  av_buffer_unref(&h265->sps_ref[i]);
1397  for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
1398  av_buffer_unref(&h265->pps_ref[i]);
1399 }
1400 
1401 static void cbs_h264_free_sei(void *opaque, uint8_t *content)
1402 {
1403  H264RawSEI *sei = (H264RawSEI*)content;
1404  ff_cbs_sei_free_message_list(&sei->message_list);
1405  av_free(content);
1406 }
1407 
1411 
1413 
1414  {
1415  .nb_unit_types = 3,
1416  .unit_types = {
1420  },
1421  .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
1422  .content_size = sizeof(H264RawSlice),
1423  .nb_ref_offsets = 1,
1424  .ref_offsets = { offsetof(H264RawSlice, data) },
1425  },
1426 
1431 
1433 
1435 };
1436 
1437 static void cbs_h265_free_sei(void *opaque, uint8_t *content)
1438 {
1439  H265RawSEI *sei = (H265RawSEI*)content;
1440  ff_cbs_sei_free_message_list(&sei->message_list);
1441  av_free(content);
1442 }
1443 
1448 
1450 
1451  {
1452  // Slices of non-IRAP pictures.
1453  .nb_unit_types = CBS_UNIT_TYPE_RANGE,
1454  .unit_type_range_start = HEVC_NAL_TRAIL_N,
1455  .unit_type_range_end = HEVC_NAL_RASL_R,
1456 
1457  .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
1458  .content_size = sizeof(H265RawSlice),
1459  .nb_ref_offsets = 1,
1460  .ref_offsets = { offsetof(H265RawSlice, data) },
1461  },
1462 
1463  {
1464  // Slices of IRAP pictures.
1465  .nb_unit_types = CBS_UNIT_TYPE_RANGE,
1466  .unit_type_range_start = HEVC_NAL_BLA_W_LP,
1467  .unit_type_range_end = HEVC_NAL_CRA_NUT,
1468 
1469  .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
1470  .content_size = sizeof(H265RawSlice),
1471  .nb_ref_offsets = 1,
1472  .ref_offsets = { offsetof(H265RawSlice, data) },
1473  },
1474 
1475  {
1476  .nb_unit_types = 2,
1477  .unit_types = {
1480  },
1481  .content_type = CBS_CONTENT_TYPE_COMPLEX,
1482  .content_size = sizeof(H265RawSEI),
1483  .content_free = &cbs_h265_free_sei,
1484  },
1485 
1487 };
1488 
1491 
1492  .priv_data_size = sizeof(CodedBitstreamH264Context),
1493 
1494  .unit_types = cbs_h264_unit_types,
1495 
1496  .split_fragment = &cbs_h2645_split_fragment,
1497  .read_unit = &cbs_h264_read_nal_unit,
1498  .write_unit = &cbs_h264_write_nal_unit,
1499  .assemble_fragment = &cbs_h2645_assemble_fragment,
1500 
1501  .flush = &cbs_h264_flush,
1502  .close = &cbs_h264_close,
1503 };
1504 
1507 
1508  .priv_data_size = sizeof(CodedBitstreamH265Context),
1509 
1510  .unit_types = cbs_h265_unit_types,
1511 
1512  .split_fragment = &cbs_h2645_split_fragment,
1513  .read_unit = &cbs_h265_read_nal_unit,
1514  .write_unit = &cbs_h265_write_nal_unit,
1515  .assemble_fragment = &cbs_h2645_assemble_fragment,
1516 
1517  .flush = &cbs_h265_flush,
1518  .close = &cbs_h265_close,
1519 };
1520 
1522  {
1524  1, 1,
1525  sizeof(SEIRawFillerPayload),
1527  },
1528  {
1530  1, 1,
1531  sizeof(SEIRawUserDataRegistered),
1533  },
1534  {
1536  1, 1,
1539  },
1540  {
1542  1, 0,
1545  },
1546  {
1548  1, 0,
1551  },
1552  {
1554  1, 0,
1557  },
1559 };
1560 
1562  {
1564  1, 0,
1565  sizeof(H264RawSEIBufferingPeriod),
1567  },
1568  {
1570  1, 0,
1571  sizeof(H264RawSEIPicTiming),
1573  },
1574  {
1576  1, 0,
1577  sizeof(H264RawSEIPanScanRect),
1579  },
1580  {
1582  1, 0,
1583  sizeof(H264RawSEIRecoveryPoint),
1585  },
1586  {
1588  1, 0,
1591  },
1593 };
1594 
1596  {
1598  1, 0,
1599  sizeof(H265RawSEIBufferingPeriod),
1601  },
1602  {
1604  1, 0,
1605  sizeof(H265RawSEIPicTiming),
1607  },
1608  {
1610  1, 0,
1611  sizeof(H265RawSEIPanScanRect),
1613  },
1614  {
1616  1, 0,
1617  sizeof(H265RawSEIRecoveryPoint),
1619  },
1620  {
1622  1, 0,
1625  },
1626  {
1628  1, 0,
1631  },
1632  {
1634  0, 1,
1637  },
1638  {
1640  1, 0,
1641  sizeof(H265RawSEITimeCode),
1643  },
1644  {
1646  1, 0,
1649  },
1651 };
1652 
1654  int payload_type)
1655 {
1657  int i;
1658 
1659  for (i = 0; cbs_sei_common_types[i].type >= 0; i++) {
1660  if (cbs_sei_common_types[i].type == payload_type)
1661  return &cbs_sei_common_types[i];
1662  }
1663 
1664  switch (ctx->codec->codec_id) {
1665  case AV_CODEC_ID_H264:
1667  break;
1668  case AV_CODEC_ID_H265:
1670  break;
1671  default:
1672  return NULL;
1673  }
1674 
1675  for (i = 0; codec_list[i].type >= 0; i++) {
1676  if (codec_list[i].type == payload_type)
1677  return &codec_list[i];
1678  }
1679 
1680  return NULL;
1681 }
static void flush(AVCodecContext *avctx)
Macro definitions for various function/variable attributes.
uint8_t
int32_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define AV_RB32
Definition: intreadwrite.h:130
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:192
int ff_cbs_insert_unit_data(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, uint8_t *data, size_t data_size, AVBufferRef *data_buf)
Insert a new unit into a fragment with the given data bitstream.
Definition: cbs.c:773
void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position, const char *str, const int *subscripts, const char *bits, int64_t value)
Definition: cbs.c:453
int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Allocate a new internal content buffer matching the type of the unit.
Definition: cbs.c:869
uint32_t CodedBitstreamUnitType
The codec-specific type of a bitstream unit.
Definition: cbs.h:43
static void cbs_h264_close(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1351
static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit)
Definition: cbs_h2645.c:826
static void cbs_h264_flush(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1333
static void cbs_h265_flush(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1364
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:142
const CodedBitstreamType ff_cbs_type_h265
Definition: cbs_h2645.c:1505
static int cbs_h265_payload_extension_present(GetBitContext *gbc, uint32_t payload_size, int cur_pos)
Definition: cbs_h2645.c:238
static void cbs_h265_pic_size_in_ctbs(const H265RawSPS *sps, unsigned int *width, unsigned int *height)
Definition: cbs_h2645.c:247
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:947
static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const H2645Packet *packet)
Definition: cbs_h2645.c:481
static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[]
Definition: cbs_h2645.c:1444
static int cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition: cbs_h2645.c:1250
static void cbs_h264_free_sei(void *opaque, uint8_t *content)
Definition: cbs_h2645.c:1401
static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition: cbs_h2645.c:1005
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:1653
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:185
static const SEIMessageTypeDescriptor cbs_sei_h264_types[]
Definition: cbs_h2645.c:1561
static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition: cbs_h2645.c:515
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:281
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:86
static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition: cbs_h2645.c:347
static int cbs_h2645_unit_requires_zero_byte(enum AVCodecID codec_id, CodedBitstreamUnitType type, int nal_unit_index)
Definition: cbs_h2645.c:1234
const CodedBitstreamType ff_cbs_type_h264
Definition: cbs_h2645.c:1489
static void cbs_h265_free_sei(void *opaque, uint8_t *content)
Definition: cbs_h2645.c:1437
static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[]
Definition: cbs_h2645.c:1408
#define cbs_h2645_replace_ps(h26n, ps_name, ps_var, id_element)
Definition: cbs_h2645.c:674
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:34
static const SEIMessageTypeDescriptor cbs_sei_common_types[]
Definition: cbs_h2645.c:1521
static void cbs_h265_close(CodedBitstreamContext *ctx)
Definition: cbs_h2645.c:1386
static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition: cbs_h2645.c:1122
static const SEIMessageTypeDescriptor cbs_sei_h265_types[]
Definition: cbs_h2645.c:1595
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC() sei_buffering_period(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIBufferingPeriod *current, SEIMessageState *sei)
static int FUNC() sei_pic_timing(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIPicTiming *current, SEIMessageState *sei)
static int FUNC() sei_pan_scan_rect(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIPanScanRect *current, SEIMessageState *sei)
static int FUNC() sei_recovery_point(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIRecoveryPoint *current, SEIMessageState *sei)
static int FUNC() sei_display_orientation(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIDisplayOrientation *current, SEIMessageState *sei)
static int FUNC() sei_decoded_picture_hash(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIDecodedPictureHash *current, SEIMessageState *sei)
static int FUNC() sei_active_parameter_sets(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIActiveParameterSets *current, SEIMessageState *sei)
static int FUNC() sei_alpha_channel_info(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEIAlphaChannelInfo *current, SEIMessageState *sei)
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static int FUNC() extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *current)
static int FUNC() sei_time_code(CodedBitstreamContext *ctx, RWContext *rw, H265RawSEITimeCode *current, SEIMessageState *sei)
@ CBS_UNIT_TYPE_RANGE
Definition: cbs_internal.h:49
#define CBS_UNIT_TYPE_END_OF_LIST
Definition: cbs_internal.h:201
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
Definition: cbs_internal.h:186
@ CBS_CONTENT_TYPE_INTERNAL_REFS
Definition: cbs_internal.h:34
@ CBS_CONTENT_TYPE_COMPLEX
Definition: cbs_internal.h:37
#define CBS_UNIT_TYPE_POD(type, structure)
Definition: cbs_internal.h:180
#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func)
Definition: cbs_internal.h:194
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:169
void ff_cbs_sei_free_message_list(SEIRawMessageList *list)
Free all SEI messages in a message list.
Definition: cbs_sei.c:96
#define SEI_MESSAGE_RW(codec, name)
Definition: cbs_sei.h:131
#define SEI_MESSAGE_TYPE_END
Definition: cbs_sei.h:136
static int FUNC() alternative_transfer_characteristics(CodedBitstreamContext *ctx, RWContext *rw, SEIRawAlternativeTransferCharacteristics *current, SEIMessageState *state)
static int FUNC() user_data_unregistered(CodedBitstreamContext *ctx, RWContext *rw, SEIRawUserDataUnregistered *current, SEIMessageState *state)
static int FUNC() filler_payload(CodedBitstreamContext *ctx, RWContext *rw, SEIRawFillerPayload *current, SEIMessageState *state)
static int FUNC() user_data_registered(CodedBitstreamContext *ctx, RWContext *rw, SEIRawUserDataRegistered *current, SEIMessageState *state)
static int FUNC() mastering_display_colour_volume(CodedBitstreamContext *ctx, RWContext *rw, SEIRawMasteringDisplayColourVolume *current, SEIMessageState *state)
static int FUNC() content_light_level_info(CodedBitstreamContext *ctx, RWContext *rw, SEIRawContentLightLevelInfo *current, SEIMessageState *state)
#define AV_CODEC_ID_H265
Definition: codec_id.h:224
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define NULL
Definition: coverity.c:32
double value
Definition: eval.c:100
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:446
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:46
@ AV_CODEC_ID_H264
Definition: codec_id.h:76
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:223
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition: avcodec.h:215
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:125
AVBufferRef * av_buffer_create(uint8_t *data, buffer_size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:29
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
#define ff_ctz
Definition: intmath.h:106
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:134
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:161
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:392
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
Definition: h2645_parse.c:525
H.264 common definitions.
@ H264_NAL_END_STREAM
Definition: h264.h:45
@ H264_NAL_END_SEQUENCE
Definition: h264.h:44
@ H264_NAL_AUXILIARY_SLICE
Definition: h264.h:53
@ H264_NAL_PPS
Definition: h264.h:42
@ H264_NAL_SPS
Definition: h264.h:41
@ H264_NAL_SLICE
Definition: h264.h:35
@ H264_NAL_FILLER_DATA
Definition: h264.h:46
@ H264_NAL_SPS_EXT
Definition: h264.h:47
@ H264_NAL_SEI
Definition: h264.h:40
@ H264_NAL_AUD
Definition: h264.h:43
@ H264_NAL_IDR_SLICE
Definition: h264.h:39
cl_device_type type
#define av_log2
Definition: intmath.h:83
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:218
@ HEVC_NAL_RASL_N
Definition: hevc.h:37
@ HEVC_NAL_CRA_NUT
Definition: hevc.h:50
@ HEVC_NAL_TRAIL_N
Definition: hevc.h:29
@ HEVC_NAL_BLA_W_LP
Definition: hevc.h:45
@ HEVC_NAL_BLA_N_LP
Definition: hevc.h:47
@ HEVC_NAL_BLA_W_RADL
Definition: hevc.h:46
@ HEVC_NAL_TSA_R
Definition: hevc.h:32
@ HEVC_NAL_AUD
Definition: hevc.h:64
@ HEVC_NAL_IDR_W_RADL
Definition: hevc.h:48
@ HEVC_NAL_IDR_N_LP
Definition: hevc.h:49
@ HEVC_NAL_SEI_SUFFIX
Definition: hevc.h:69
@ HEVC_NAL_TSA_N
Definition: hevc.h:31
@ HEVC_NAL_SEI_PREFIX
Definition: hevc.h:68
@ HEVC_NAL_PPS
Definition: hevc.h:63
@ HEVC_NAL_VPS
Definition: hevc.h:61
@ HEVC_NAL_TRAIL_R
Definition: hevc.h:30
@ HEVC_NAL_STSA_N
Definition: hevc.h:33
@ HEVC_NAL_STSA_R
Definition: hevc.h:34
@ HEVC_NAL_RASL_R
Definition: hevc.h:38
@ HEVC_NAL_RADL_R
Definition: hevc.h:36
@ HEVC_NAL_SPS
Definition: hevc.h:62
@ HEVC_NAL_RADL_N
Definition: hevc.h:35
internal header for HEVC (de)muxer utilities
version
Definition: libkvazaar.c:326
const char data[16]
Definition: mxf.c:142
static void av_unused put_bits32(PutBitContext *s, uint32_t value)
Write exactly 32 bits into a bitstream.
Definition: put_bits.h:263
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:342
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:76
static int put_bits_left(PutBitContext *s)
Definition: put_bits.h:102
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:110
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
Definition: put_bits.h:351
const char * name
Definition: qsvenc.c:46
#define sp
Definition: regdef.h:63
static const uint8_t header[24]
Definition: sdr2.c:67
@ SEI_TYPE_ALPHA_CHANNEL_INFO
Definition: sei.h:123
@ SEI_TYPE_DECODED_PICTURE_HASH
Definition: sei.h:91
@ SEI_TYPE_RECOVERY_POINT
Definition: sei.h:36
@ SEI_TYPE_PIC_TIMING
Definition: sei.h:31
@ SEI_TYPE_FILLER_PAYLOAD
Definition: sei.h:33
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition: sei.h:34
@ SEI_TYPE_ACTIVE_PARAMETER_SETS
Definition: sei.h:87
@ SEI_TYPE_DISPLAY_ORIENTATION
Definition: sei.h:77
@ SEI_TYPE_ALTERNATIVE_TRANSFER_CHARACTERISTICS
Definition: sei.h:106
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition: sei.h:35
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition: sei.h:103
@ SEI_TYPE_TIME_CODE
Definition: sei.h:95
@ SEI_TYPE_PAN_SCAN_RECT
Definition: sei.h:32
@ SEI_TYPE_BUFFERING_PERIOD
Definition: sei.h:30
@ SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
Definition: sei.h:96
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition: spdifenc.c:412
A reference to a data buffer.
Definition: buffer.h:84
enum AVMediaType type
Definition: codec.h:210
void * priv_data
Format private data.
Definition: avformat.h:1260
Context structure for coded bitstream operations.
Definition: cbs.h:170
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:118
CodedBitstreamUnit * units
Pointer to an array of units of length nb_units_allocated.
Definition: cbs.h:164
int nb_units
Number of units in this fragment.
Definition: cbs.h:149
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:135
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:131
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:124
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:141
uint8_t last_slice_nal_unit_type
Definition: cbs_h264.h:403
const H264RawPPS * active_pps
Definition: cbs_h264.h:398
AVBufferRef * sps_ref[H264_MAX_SPS_COUNT]
Definition: cbs_h264.h:389
const H264RawSPS * active_sps
Definition: cbs_h264.h:397
AVBufferRef * pps_ref[H264_MAX_PPS_COUNT]
Definition: cbs_h264.h:390
H264RawSPS * sps[H264_MAX_SPS_COUNT]
Definition: cbs_h264.h:391
H264RawPPS * pps[H264_MAX_PPS_COUNT]
Definition: cbs_h264.h:392
CodedBitstreamH2645Context common
Definition: cbs_h264.h:385
const H265RawVPS * active_vps
Definition: cbs_h265.h:673
AVBufferRef * vps_ref[HEVC_MAX_VPS_COUNT]
Definition: cbs_h265.h:663
const H265RawSPS * active_sps
Definition: cbs_h265.h:674
H265RawVPS * vps[HEVC_MAX_VPS_COUNT]
Definition: cbs_h265.h:666
CodedBitstreamH2645Context common
Definition: cbs_h265.h:659
AVBufferRef * pps_ref[HEVC_MAX_PPS_COUNT]
Definition: cbs_h265.h:665
H265RawSPS * sps[HEVC_MAX_SPS_COUNT]
Definition: cbs_h265.h:667
const H265RawPPS * active_pps
Definition: cbs_h265.h:675
AVBufferRef * sps_ref[HEVC_MAX_SPS_COUNT]
Definition: cbs_h265.h:664
H265RawPPS * pps[HEVC_MAX_PPS_COUNT]
Definition: cbs_h265.h:668
enum AVCodecID codec_id
Definition: cbs_internal.h:87
Coded bitstream unit structure.
Definition: cbs.h:66
void * content
Pointer to the decomposed form of this unit.
Definition: cbs.h:103
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition: cbs.h:77
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:88
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition: cbs.h:70
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition: cbs.h:82
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition: cbs.h:94
const uint8_t * data
Definition: h2645_parse.h:36
int size
Definition: h2645_parse.h:35
int nuh_layer_id
Definition: h2645_parse.h:62
int type
NAL unit type.
Definition: h2645_parse.h:52
const uint8_t * raw_data
Definition: h2645_parse.h:45
H2645NAL * nals
Definition: h2645_parse.h:82
H2645RBSP rbsp
Definition: h2645_parse.h:83
AVBufferRef * rbsp_buffer_ref
Definition: h2645_parse.h:75
AVBufferRef * data_ref
Definition: cbs_h264.h:371
size_t data_size
Definition: cbs_h264.h:372
int data_bit_start
Definition: cbs_h264.h:373
H264RawSliceHeader header
Definition: cbs_h264.h:368
uint8_t * data
Definition: cbs_h264.h:370
int data_bit_start
Definition: cbs_h265.h:539
H265RawSliceHeader header
Definition: cbs_h265.h:534
AVBufferRef * data_ref
Definition: cbs_h265.h:537
uint8_t * data
Definition: cbs_h265.h:536
size_t data_size
Definition: cbs_h265.h:538
Picture parameter set.
Definition: h264_ps.h:111
Sequence parameter set.
Definition: h264_ps.h:44
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
AVCodec * codec_list[]
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AVFormatContext * ctx
Definition: movenc.c:48
#define height
#define width
int size
enum AVCodecID codec_id
Definition: vaapi_decode.c:374
else temp
Definition: vf_mcdeint.c:259
int len
uint8_t bits
Definition: vp3data.h:141