FFmpeg
Loading...
Searching...
No Matches
cbs_h265.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/mem.h"
20#include "libavutil/refstruct.h"
21#include "bytestream.h"
22#include "cbs.h"
23#include "cbs_internal.h"
24#include "cbs_h2645.h"
25#include "cbs_h265.h"
26#include "cbs_sei.h"
27#include "get_bits.h"
28
29#define HEADER(name) do { \
30 ff_cbs_trace_header(ctx, name); \
31 } while (0)
32
33#define CHECK(call) do { \
34 err = (call); \
35 if (err < 0) \
36 return err; \
37 } while (0)
38
39#define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
40#define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
41#define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name)
42#define FUNC_NAME2_EXPORT(rw, codec, name) ff_cbs_ ## codec ## _ ## rw ## _ ## name
43#define FUNC_NAME1_EXPORT(rw, codec, name) FUNC_NAME2_EXPORT(rw, codec, name)
44#define FUNC_SEI(name) FUNC_NAME1_EXPORT(READWRITE, sei, name)
45
46#define SEI_FUNC(name, args) \
47static int FUNC_H265(name) args; \
48static int FUNC_H265(name ## _internal)(CodedBitstreamContext *ctx, \
49 RWContext *rw, void *cur, \
50 SEIMessageState *state) \
51{ \
52 return FUNC_H265(name)(ctx, rw, cur, state); \
53} \
54static int FUNC_H265(name) args
55
56#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
57
58#define u(width, name, range_min, range_max) \
59 xu(width, name, current->name, range_min, range_max, 0, )
60#define flag(name) ub(1, name)
61#define ue(name, range_min, range_max) \
62 xue(name, current->name, range_min, range_max, 0, )
63#define i(width, name, range_min, range_max) \
64 xi(width, name, current->name, range_min, range_max, 0, )
65#define ib(width, name) \
66 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, )
67#define se(name, range_min, range_max) \
68 xse(name, current->name, range_min, range_max, 0, )
69
70#define us(width, name, range_min, range_max, subs, ...) \
71 xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
72#define ubs(width, name, subs, ...) \
73 xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
74#define flags(name, subs, ...) \
75 xu(1, name, current->name, 0, 1, subs, __VA_ARGS__)
76#define ues(name, range_min, range_max, subs, ...) \
77 xue(name, current->name, range_min, range_max, subs, __VA_ARGS__)
78#define is(width, name, range_min, range_max, subs, ...) \
79 xi(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
80#define ibs(width, name, subs, ...) \
81 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), subs, __VA_ARGS__)
82#define ses(name, range_min, range_max, subs, ...) \
83 xse(name, current->name, range_min, range_max, subs, __VA_ARGS__)
84
85#define fixed(width, name, value) do { \
86 av_unused uint32_t fixed_value = value; \
87 xu(width, name, fixed_value, value, value, 0, ); \
88 } while (0)
89
90
91#define READ
92#define READWRITE read
93#define RWContext GetBitContext
94
95#define ub(width, name) do { \
96 uint32_t value; \
97 CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
98 &value)); \
99 current->name = value; \
100 } while (0)
101#define xu(width, name, var, range_min, range_max, subs, ...) do { \
102 uint32_t value; \
103 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
104 SUBSCRIPTS(subs, __VA_ARGS__), \
105 &value, range_min, range_max)); \
106 var = value; \
107 } while (0)
108#define xue(name, var, range_min, range_max, subs, ...) do { \
109 uint32_t value; \
110 CHECK(ff_cbs_read_ue_golomb(ctx, rw, #name, \
111 SUBSCRIPTS(subs, __VA_ARGS__), \
112 &value, range_min, range_max)); \
113 var = value; \
114 } while (0)
115#define xi(width, name, var, range_min, range_max, subs, ...) do { \
116 int32_t value; \
117 CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
118 SUBSCRIPTS(subs, __VA_ARGS__), \
119 &value, range_min, range_max)); \
120 var = value; \
121 } while (0)
122#define xse(name, var, range_min, range_max, subs, ...) do { \
123 int32_t value; \
124 CHECK(ff_cbs_read_se_golomb(ctx, rw, #name, \
125 SUBSCRIPTS(subs, __VA_ARGS__), \
126 &value, range_min, range_max)); \
127 var = value; \
128 } while (0)
129
130
131#define infer(name, value) do { \
132 current->name = value; \
133 } while (0)
134
135#define more_rbsp_data(var) ((var) = ff_cbs_h2645_read_more_rbsp_data(rw))
136
137#define bit_position(rw) (get_bits_count(rw))
138#define byte_alignment(rw) (get_bits_count(rw) % 8)
139
140#define allocate(name, size) do { \
141 name ## _ref = av_buffer_allocz(size + \
142 AV_INPUT_BUFFER_PADDING_SIZE); \
143 if (!name ## _ref) \
144 return AVERROR(ENOMEM); \
145 name = (void *)name ## _ref->data; \
146 } while (0)
147
148#define FUNC(name) FUNC_H265(name)
150#undef FUNC
151
152
153#undef READ
154#undef READWRITE
155#undef RWContext
156#undef ub
157#undef xu
158#undef xi
159#undef xue
160#undef xse
161#undef infer
162#undef more_rbsp_data
163#undef bit_position
164#undef byte_alignment
165#undef allocate
166#undef allocate_struct
167
168
169#define WRITE
170#define READWRITE write
171#define RWContext PutBitContext
172
173#define ub(width, name) do { \
174 uint32_t value = current->name; \
175 CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
176 value)); \
177 } while (0)
178#define xu(width, name, var, range_min, range_max, subs, ...) do { \
179 uint32_t value = var; \
180 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
181 SUBSCRIPTS(subs, __VA_ARGS__), \
182 value, range_min, range_max)); \
183 } while (0)
184#define xue(name, var, range_min, range_max, subs, ...) do { \
185 uint32_t value = var; \
186 CHECK(ff_cbs_write_ue_golomb(ctx, rw, #name, \
187 SUBSCRIPTS(subs, __VA_ARGS__), \
188 value, range_min, range_max)); \
189 } while (0)
190#define xi(width, name, var, range_min, range_max, subs, ...) do { \
191 int32_t value = var; \
192 CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
193 SUBSCRIPTS(subs, __VA_ARGS__), \
194 value, range_min, range_max)); \
195 } while (0)
196#define xse(name, var, range_min, range_max, subs, ...) do { \
197 int32_t value = var; \
198 CHECK(ff_cbs_write_se_golomb(ctx, rw, #name, \
199 SUBSCRIPTS(subs, __VA_ARGS__), \
200 value, range_min, range_max)); \
201 } while (0)
202
203#define infer(name, value) do { \
204 if (current->name != (value)) { \
205 av_log(ctx->log_ctx, AV_LOG_ERROR, \
206 "%s does not match inferred value: " \
207 "%"PRId64", but should be %"PRId64".\n", \
208 #name, (int64_t)current->name, (int64_t)(value)); \
209 return AVERROR_INVALIDDATA; \
210 } \
211 } while (0)
212
213#define more_rbsp_data(var) (var)
214
215#define bit_position(rw) (put_bits_count(rw))
216#define byte_alignment(rw) (put_bits_count(rw) % 8)
217
218#define allocate(name, size) do { \
219 if (!name) { \
220 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s must be set " \
221 "for writing.\n", #name); \
222 return AVERROR_INVALIDDATA; \
223 } \
224 } while (0)
225
226#define FUNC(name) FUNC_H265(name)
228#undef FUNC
229
230#undef WRITE
231#undef READWRITE
232#undef RWContext
233#undef ub
234#undef xu
235#undef xi
236#undef xue
237#undef xse
238#undef u
239#undef i
240#undef flag
241#undef ue
242#undef se
243#undef infer
244#undef more_rbsp_data
245#undef bit_position
246#undef byte_alignment
247#undef allocate
248
249
250
253 int header)
254{
255 enum AVCodecID codec_id = ctx->codec->codec_id;
256 CodedBitstreamH265Context *priv = ctx->priv_data;
257 CodedBitstreamH2645Context *h2645 = &priv->common;
258 GetByteContext gbc;
259 int err;
260
261 av_assert0(frag->data && frag->nb_units == 0);
262 if (frag->data_size == 0)
263 return 0;
264
265 if (header && frag->data[0]) {
266 // HVCC header.
267 size_t size, start, end;
268 int i, j, nb_arrays, nal_unit_type, nb_nals, version;
269
270 h2645->mp4 = 1;
271
272 bytestream2_init(&gbc, frag->data, frag->data_size);
273
274 if (bytestream2_get_bytes_left(&gbc) < 23)
275 return AVERROR_INVALIDDATA;
276
277 version = bytestream2_get_byte(&gbc);
278 if (version != 1) {
279 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid HVCC header: "
280 "first byte %u.\n", version);
281 return AVERROR_INVALIDDATA;
282 }
283
284 bytestream2_skip(&gbc, 20);
285 h2645->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1;
286
287 nb_arrays = bytestream2_get_byte(&gbc);
288 for (i = 0; i < nb_arrays; i++) {
289 nal_unit_type = bytestream2_get_byte(&gbc) & 0x3f;
290 nb_nals = bytestream2_get_be16(&gbc);
291
292 start = bytestream2_tell(&gbc);
293 for (j = 0; j < nb_nals; j++) {
294 if (bytestream2_get_bytes_left(&gbc) < 2)
295 return AVERROR_INVALIDDATA;
296 size = bytestream2_get_be16(&gbc);
298 return AVERROR_INVALIDDATA;
299 bytestream2_skip(&gbc, size);
300 }
301 end = bytestream2_tell(&gbc);
302
304 frag->data + start, end - start,
305 ctx->log_ctx, 2, AV_CODEC_ID_HEVC,
307 if (err < 0) {
308 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
309 "HVCC array %d (%d NAL units of type %d).\n",
310 i, nb_nals, nal_unit_type);
311 return err;
312 }
313 err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
314 if (err < 0)
315 return err;
316 }
317 } else {
319 // Annex B, or later MP4 with already-known parameters.
320
322 frag->data, frag->data_size,
323 ctx->log_ctx,
324 h2645->nal_length_size,
325 codec_id, flags);
326 if (err < 0)
327 return err;
328
329 err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
330 if (err < 0)
331 return err;
332 }
333
334 return 0;
335}
336
337#define cbs_h2645_replace_ps(ps_name, ps_var, id_element) \
338static int cbs_h265_replace_ ## ps_var(CodedBitstreamContext *ctx, \
339 CodedBitstreamUnit *unit) \
340{ \
341 CodedBitstreamH265Context *priv = ctx->priv_data; \
342 H265Raw## ps_name *ps_var = unit->content; \
343 unsigned int id = ps_var->id_element; \
344 int err = ff_cbs_make_unit_refcounted(ctx, unit); \
345 if (err < 0) \
346 return err; \
347 if (priv->ps_var[id] == priv->active_ ## ps_var) \
348 priv->active_ ## ps_var = NULL ; \
349 av_assert0(unit->content_ref); \
350 av_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
351 return 0; \
352}
353
354cbs_h2645_replace_ps(VPS, vps, vps_video_parameter_set_id)
355cbs_h2645_replace_ps(SPS, sps, sps_seq_parameter_set_id)
356cbs_h2645_replace_ps(PPS, pps, pps_pic_parameter_set_id)
357
358static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx,
359 CodedBitstreamUnit *unit)
360{
361 GetBitContext gbc;
362 int err;
363
364 err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
365 if (err < 0)
366 return err;
367
368 err = ff_cbs_alloc_unit_content(ctx, unit);
369 if (err < 0)
370 return err;
371
372 switch (unit->type) {
373 case HEVC_NAL_VPS:
374 {
375 H265RawVPS *vps = unit->content;
376
377 err = cbs_h265_read_vps(ctx, &gbc, vps);
378 if (err < 0)
379 return err;
380
381 err = cbs_h265_replace_vps(ctx, unit);
382 if (err < 0)
383 return err;
384 }
385 break;
386 case HEVC_NAL_SPS:
387 {
388 H265RawSPS *sps = unit->content;
389
390 err = cbs_h265_read_sps(ctx, &gbc, sps);
391 if (err < 0)
392 return err;
393
394 err = cbs_h265_replace_sps(ctx, unit);
395 if (err < 0)
396 return err;
397 }
398 break;
399
400 case HEVC_NAL_PPS:
401 {
402 H265RawPPS *pps = unit->content;
403
404 err = cbs_h265_read_pps(ctx, &gbc, pps);
405 if (err < 0)
406 return err;
407
408 err = cbs_h265_replace_pps(ctx, unit);
409 if (err < 0)
410 return err;
411 }
412 break;
413
414 case HEVC_NAL_TRAIL_N:
415 case HEVC_NAL_TRAIL_R:
416 case HEVC_NAL_TSA_N:
417 case HEVC_NAL_TSA_R:
418 case HEVC_NAL_STSA_N:
419 case HEVC_NAL_STSA_R:
420 case HEVC_NAL_RADL_N:
421 case HEVC_NAL_RADL_R:
422 case HEVC_NAL_RASL_N:
423 case HEVC_NAL_RASL_R:
429 case HEVC_NAL_CRA_NUT:
430 {
431 H265RawSlice *slice = unit->content;
432 int pos, len;
433
434 err = cbs_h265_read_slice_segment_header(ctx, &gbc, &slice->header);
435 if (err < 0)
436 return err;
437
439 return AVERROR_INVALIDDATA;
440
441 pos = get_bits_count(&gbc);
442 len = unit->data_size;
443
444 slice->data_size = len - pos / 8;
445 slice->data_ref = av_buffer_ref(unit->data_ref);
446 if (!slice->data_ref)
447 return AVERROR(ENOMEM);
448 slice->data = unit->data + pos / 8;
449 slice->data_bit_start = pos % 8;
450 }
451 break;
452
453 case HEVC_NAL_AUD:
454 {
455 err = cbs_h265_read_aud(ctx, &gbc, unit->content);
456 if (err < 0)
457 return err;
458 }
459 break;
460
461 case HEVC_NAL_FD_NUT:
462 {
463 err = cbs_h265_read_filler(ctx, &gbc, unit->content);
464 if (err < 0)
465 return err;
466 }
467 break;
468
471 {
472 err = cbs_h265_read_sei(ctx, &gbc, unit->content,
473 unit->type == HEVC_NAL_SEI_PREFIX);
474
475 if (err < 0)
476 return err;
477 }
478 break;
479
480 default:
481 return AVERROR(ENOSYS);
482 }
483
484 return 0;
485}
486
488 CodedBitstreamUnit *unit,
489 PutBitContext *pbc)
490{
491 int err;
492
493 switch (unit->type) {
494 case HEVC_NAL_VPS:
495 {
496 H265RawVPS *vps = unit->content;
497
498 err = cbs_h265_write_vps(ctx, pbc, vps);
499 if (err < 0)
500 return err;
501
502 err = cbs_h265_replace_vps(ctx, unit);
503 if (err < 0)
504 return err;
505 }
506 break;
507
508 case HEVC_NAL_SPS:
509 {
510 H265RawSPS *sps = unit->content;
511
512 err = cbs_h265_write_sps(ctx, pbc, sps);
513 if (err < 0)
514 return err;
515
516 err = cbs_h265_replace_sps(ctx, unit);
517 if (err < 0)
518 return err;
519 }
520 break;
521
522 case HEVC_NAL_PPS:
523 {
524 H265RawPPS *pps = unit->content;
525
526 err = cbs_h265_write_pps(ctx, pbc, pps);
527 if (err < 0)
528 return err;
529
530 err = cbs_h265_replace_pps(ctx, unit);
531 if (err < 0)
532 return err;
533 }
534 break;
535
536 case HEVC_NAL_TRAIL_N:
537 case HEVC_NAL_TRAIL_R:
538 case HEVC_NAL_TSA_N:
539 case HEVC_NAL_TSA_R:
540 case HEVC_NAL_STSA_N:
541 case HEVC_NAL_STSA_R:
542 case HEVC_NAL_RADL_N:
543 case HEVC_NAL_RADL_R:
544 case HEVC_NAL_RASL_N:
545 case HEVC_NAL_RASL_R:
551 case HEVC_NAL_CRA_NUT:
552 {
553 H265RawSlice *slice = unit->content;
554
555 err = cbs_h265_write_slice_segment_header(ctx, pbc, &slice->header);
556 if (err < 0)
557 return err;
558
559 if (slice->data) {
560 err = ff_cbs_h2645_write_slice_data(ctx, pbc, slice->data,
561 slice->data_size,
562 slice->data_bit_start);
563 if (err < 0)
564 return err;
565 } else {
566 // No slice data - that was just the header.
567 }
568 }
569 break;
570
571 case HEVC_NAL_AUD:
572 {
573 err = cbs_h265_write_aud(ctx, pbc, unit->content);
574 if (err < 0)
575 return err;
576 }
577 break;
578
579 case HEVC_NAL_FD_NUT:
580 {
581 err = cbs_h265_write_filler(ctx, pbc, unit->content);
582 if (err < 0)
583 return err;
584 }
585 break;
586
589 {
590 err = cbs_h265_write_sei(ctx, pbc, unit->content,
591 unit->type == HEVC_NAL_SEI_PREFIX);
592
593 if (err < 0)
594 return err;
595 }
596 break;
597
598 default:
599 av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
600 "NAL unit type %"PRIu32".\n", unit->type);
602 }
603
604 return 0;
605}
606
608 const CodedBitstreamUnit *unit,
609 enum AVDiscard skip)
610{
611 H265RawSliceHeader *slice;
612
613 if (skip <= AVDISCARD_DEFAULT)
614 return 0;
615
616 switch (unit->type) {
622 case HEVC_NAL_CRA_NUT:
623 // IRAP slice
624 if (skip < AVDISCARD_ALL)
625 return 0;
626 break;
627
628 case HEVC_NAL_TRAIL_R:
629 case HEVC_NAL_TRAIL_N:
630 case HEVC_NAL_TSA_N:
631 case HEVC_NAL_TSA_R:
632 case HEVC_NAL_STSA_N:
633 case HEVC_NAL_STSA_R:
634 case HEVC_NAL_RADL_N:
635 case HEVC_NAL_RADL_R:
636 case HEVC_NAL_RASL_N:
637 case HEVC_NAL_RASL_R:
638 // Slice
639 break;
640 default:
641 // Don't discard non-slice nal.
642 return 0;
643 }
644
645 if (skip >= AVDISCARD_NONKEY)
646 return 1;
647
648 slice = (H265RawSliceHeader *)unit->content;
649 if (!slice) {
650 av_log(ctx->log_ctx, AV_LOG_WARNING,
651 "h265 slice header is null, missing decompose?\n");
652 return 0;
653 }
654
656 return 1;
657 if (skip >= AVDISCARD_BIDIR && slice->slice_type == HEVC_SLICE_B)
658 return 1;
659
660 if (skip >= AVDISCARD_NONREF) {
661 switch (unit->type) {
662 case HEVC_NAL_TRAIL_N:
663 case HEVC_NAL_TSA_N:
664 case HEVC_NAL_STSA_N:
665 case HEVC_NAL_RADL_N:
666 case HEVC_NAL_RASL_N:
667 case HEVC_NAL_VCL_N10:
668 case HEVC_NAL_VCL_N12:
669 case HEVC_NAL_VCL_N14:
670 // non-ref
671 return 1;
672 default:
673 break;
674 }
675 }
676
677 return 0;
678}
679
681{
682 CodedBitstreamH265Context *h265 = ctx->priv_data;
683
684 for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
685 av_refstruct_unref(&h265->vps[i]);
686 for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
687 av_refstruct_unref(&h265->sps[i]);
688 for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
689 av_refstruct_unref(&h265->pps[i]);
690
691 h265->active_vps = NULL;
692 h265->active_sps = NULL;
693 h265->active_pps = NULL;
694}
695
697{
698 CodedBitstreamH265Context *h265 = ctx->priv_data;
699 int i;
700
702
703 for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
704 av_refstruct_unref(&h265->vps[i]);
705 for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
706 av_refstruct_unref(&h265->sps[i]);
707 for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
708 av_refstruct_unref(&h265->pps[i]);
709}
710
711static void cbs_h265_free_sei(AVRefStructOpaque unused, void *content)
712{
713 H265RawSEI *sei = content;
714 ff_cbs_sei_free_message_list(&sei->message_list);
715}
716
718 {
719 .nb_unit_types = 1,
720 .unit_type.list = { HEVC_NAL_VPS },
721 .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
722 .content_size = sizeof(H265RawVPS),
723 .type.ref = {
724 .nb_offsets = 2,
725 .offsets = { offsetof(H265RawVPS, extension_data.data),
726 offsetof(H265RawVPS, hrd_parameters) }
727 },
728 },
729
732
735
736 // Slices of non-IRAP pictures.
739 // Slices of IRAP pictures.
742
745
747};
748
749// Macro for the read/write pair.
750#define SEI_MESSAGE_RW(codec, name) \
751 .read = cbs_ ## codec ## _read_ ## name ## _internal, \
752 .write = cbs_ ## codec ## _write_ ## name ## _internal
753
755 {
757 1, 0,
759 SEI_MESSAGE_RW(h265, sei_buffering_period),
760 },
761 {
763 1, 0,
764 sizeof(H265RawSEIPicTiming),
765 SEI_MESSAGE_RW(h265, sei_pic_timing),
766 },
767 {
769 1, 0,
770 sizeof(H265RawSEIPanScanRect),
771 SEI_MESSAGE_RW(h265, sei_pan_scan_rect),
772 },
773 {
775 1, 0,
777 SEI_MESSAGE_RW(h265, sei_recovery_point),
778 },
779 {
781 1, 0,
783 SEI_MESSAGE_RW(h265, film_grain_characteristics),
784 },
785 {
787 1, 0,
789 SEI_MESSAGE_RW(h265, sei_display_orientation),
790 },
791 {
793 1, 0,
795 SEI_MESSAGE_RW(h265, sei_active_parameter_sets),
796 },
797 {
799 0, 1,
801 SEI_MESSAGE_RW(h265, sei_decoded_picture_hash),
802 },
803 {
805 1, 0,
806 sizeof(H265RawSEITimeCode),
807 SEI_MESSAGE_RW(h265, sei_time_code),
808 },
809 {
811 1, 0,
813 SEI_MESSAGE_RW(h265, sei_alpha_channel_info),
814 },
815 {
817 1, 0,
819 SEI_MESSAGE_RW(h265, sei_3d_reference_displays_info),
820 },
822};
823
825 .codec_id = AV_CODEC_ID_HEVC,
826
827 .priv_data_size = sizeof(CodedBitstreamH265Context),
828
829 .unit_types = cbs_h265_unit_types,
830
831 .split_fragment = &cbs_h265_split_fragment,
832 .read_unit = &cbs_h265_read_nal_unit,
833 .write_unit = &cbs_h265_write_nal_unit,
834 .discarded_unit = &cbs_h265_discarded_nal_unit,
835 .assemble_fragment = &ff_cbs_h2645_assemble_fragment,
836
839};
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition bytestream.h:168
static av_always_inline int bytestream2_tell(const GetByteContext *g)
Definition bytestream.h:192
int ff_cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, const H2645Packet *packet)
Definition cbs_h2645.c:229
int ff_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:265
int ff_cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition cbs_h2645.c:217
int ff_cbs_h2645_assemble_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Definition cbs_h2645.c:323
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H264RawHRD *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
#define SEI_MESSAGE_RW(codec, name)
Definition cbs_h265.c:750
static av_cold void cbs_h265_flush(CodedBitstreamContext *ctx)
Definition cbs_h265.c:680
static CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[]
Definition cbs_h265.c:717
static av_cold void cbs_h265_close(CodedBitstreamContext *ctx)
Definition cbs_h265.c:696
const CodedBitstreamType ff_cbs_type_h265
Definition cbs_h265.c:824
const SEIMessageTypeDescriptor ff_cbs_sei_h265_types[]
Definition cbs_h265.c:754
static int cbs_h265_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition cbs_h265.c:251
static int cbs_h265_discarded_nal_unit(CodedBitstreamContext *ctx, const CodedBitstreamUnit *unit, enum AVDiscard skip)
Definition cbs_h265.c:607
static void cbs_h265_free_sei(AVRefStructOpaque unused, void *content)
Definition cbs_h265.c:711
#define cbs_h2645_replace_ps(ps_name, ps_var, id_element)
Definition cbs_h265.c:337
static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition cbs_h265.c:487
static int FUNC vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
static int FUNC extension_data(CodedBitstreamContext *ctx, RWContext *rw, H265RawExtensionData *current)
#define CBS_UNIT_TYPE_POD(type_, structure)
#define CBS_UNIT_TYPE_END_OF_LIST
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
@ CBS_CONTENT_TYPE_INTERNAL_REFS
#define CBS_UNIT_TYPES_COMPLEX(types, structure, free_func)
#define CBS_UNIT_RANGE_INTERNAL_REF(range_start, range_end, structure, ref_field)
void ff_cbs_sei_free_message_list(SEIRawMessageList *list)
Free all SEI messages in a message list.
Definition cbs_sei.c:291
#define SEI_MESSAGE_TYPE_END
Definition cbs_sei.h:202
#define NULL
Definition coverity.c:32
uint64_t pps
Definition dovi_rpuenc.c:36
void(* flush)(AVBSFContext *ctx)
Definition dts2pts.c:610
bitstream reader API header.
static int get_bits_count(const GetBitContext *s)
Definition get_bits.h:254
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition get_bits.h:517
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition codec_id.h:47
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
AVDiscard
Definition defs.h:223
@ AVDISCARD_ALL
discard all
Definition defs.h:232
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition defs.h:231
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition defs.h:229
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition defs.h:227
@ AVDISCARD_NONINTRA
discard all non intra frames
Definition defs.h:230
@ AVDISCARD_NONREF
discard all non reference
Definition defs.h:228
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:103
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ H2645_FLAG_USE_REF
Definition h2645_parse.h:99
@ H2645_FLAG_SMALL_PADDING
Definition h2645_parse.h:98
@ H2645_FLAG_IS_NALFF
Definition h2645_parse.h:97
cl_device_type type
void ff_h2645_packet_uninit(H2645Packet *pkt)
Free all the allocated memory in the packet.
int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length, void *logctx, int nal_length_size, enum AVCodecID codec_id, int flags)
Split an input packet into NAL units.
@ HEVC_NAL_RASL_N
Definition hevc.h:37
@ HEVC_NAL_CRA_NUT
Definition hevc.h:50
@ HEVC_NAL_TRAIL_N
Definition hevc.h:29
@ HEVC_NAL_BLA_W_LP
Definition hevc.h:45
@ HEVC_NAL_BLA_N_LP
Definition hevc.h:47
@ HEVC_NAL_BLA_W_RADL
Definition hevc.h:46
@ HEVC_NAL_TSA_R
Definition hevc.h:32
@ HEVC_NAL_AUD
Definition hevc.h:64
@ HEVC_NAL_IDR_W_RADL
Definition hevc.h:48
@ HEVC_NAL_VCL_N14
Definition hevc.h:43
@ HEVC_NAL_IDR_N_LP
Definition hevc.h:49
@ HEVC_NAL_SEI_SUFFIX
Definition hevc.h:69
@ HEVC_NAL_VCL_N12
Definition hevc.h:41
@ HEVC_NAL_TSA_N
Definition hevc.h:31
@ HEVC_NAL_SEI_PREFIX
Definition hevc.h:68
@ HEVC_NAL_VCL_N10
Definition hevc.h:39
@ HEVC_NAL_PPS
Definition hevc.h:63
@ HEVC_NAL_VPS
Definition hevc.h:61
@ HEVC_NAL_FD_NUT
Definition hevc.h:67
@ HEVC_NAL_TRAIL_R
Definition hevc.h:30
@ HEVC_NAL_STSA_N
Definition hevc.h:33
@ HEVC_NAL_STSA_R
Definition hevc.h:34
@ HEVC_NAL_RASL_R
Definition hevc.h:38
@ HEVC_NAL_RADL_R
Definition hevc.h:36
@ HEVC_NAL_SPS
Definition hevc.h:62
@ HEVC_NAL_RADL_N
Definition hevc.h:35
@ HEVC_SLICE_I
Definition hevc.h:98
@ HEVC_SLICE_B
Definition hevc.h:96
#define av_cold
Definition attributes.h:117
version
Definition libkvazaar.c:313
Memory handling functions.
const char data[16]
Definition mxf.c:149
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:120
static const uint8_t header[24]
Definition sdr2.c:68
@ SEI_TYPE_ALPHA_CHANNEL_INFO
Definition sei.h:123
@ SEI_TYPE_DECODED_PICTURE_HASH
Definition sei.h:91
@ SEI_TYPE_RECOVERY_POINT
Definition sei.h:36
@ SEI_TYPE_PIC_TIMING
Definition sei.h:31
@ SEI_TYPE_ACTIVE_PARAMETER_SETS
Definition sei.h:87
@ SEI_TYPE_DISPLAY_ORIENTATION
Definition sei.h:77
@ SEI_TYPE_THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO
Definition sei.h:127
@ SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
Definition sei.h:49
@ SEI_TYPE_TIME_CODE
Definition sei.h:95
@ SEI_TYPE_PAN_SCAN_RECT
Definition sei.h:32
@ SEI_TYPE_BUFFERING_PERIOD
Definition sei.h:30
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition spdifenc.c:431
Context structure for coded bitstream operations.
Definition cbs.h:226
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
int nb_units
Number of units in this fragment.
Definition cbs.h:160
size_t data_size
The number of bytes in the bitstream.
Definition cbs.h:142
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition cbs.h:135
const H265RawVPS * active_vps
Definition cbs_h265.h:764
const H265RawSPS * active_sps
Definition cbs_h265.h:765
H265RawVPS * vps[HEVC_MAX_VPS_COUNT]
RefStruct references.
Definition cbs_h265.h:757
CodedBitstreamH2645Context common
Definition cbs_h265.h:753
H265RawSPS * sps[HEVC_MAX_SPS_COUNT]
RefStruct references.
Definition cbs_h265.h:758
const H265RawPPS * active_pps
Definition cbs_h265.h:766
H265RawPPS * pps[HEVC_MAX_PPS_COUNT]
RefStruct references.
Definition cbs_h265.h:759
Coded bitstream unit structure.
Definition cbs.h:77
void * content
Pointer to the decomposed form of this unit.
Definition cbs.h:114
uint8_t * data
Pointer to the directly-parsable bitstream form of this unit.
Definition cbs.h:88
CodedBitstreamUnitType type
Codec-specific type of this unit.
Definition cbs.h:81
size_t data_size
The number of bytes in the bitstream (including any padding bits in the final byte).
Definition cbs.h:93
AVBufferRef * data_ref
A reference to the buffer containing data.
Definition cbs.h:105
int data_bit_start
Definition cbs_h265.h:590
H265RawSliceHeader header
Definition cbs_h265.h:585
AVBufferRef * data_ref
Definition cbs_h265.h:588
uint8_t * data
Definition cbs_h265.h:587
size_t data_size
Definition cbs_h265.h:589
Picture parameter set.
Definition h264_ps.h:110
Sequence parameter set.
Definition h264_ps.h:44
#define av_log(a,...)
static AVFormatContext * ctx
Definition movenc.c:49
int size
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition refstruct.h:58
enum AVCodecID codec_id
int len