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