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