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// PicWidthInCtbsY and PicHeightInCtbsY (7.4.3.2.1).
31 unsigned int *width, unsigned int *height)
32{
33 unsigned int ctb_log2_size_y = sps->log2_min_luma_coding_block_size_minus3 + 3 +
34 sps->log2_diff_max_min_luma_coding_block_size;
35 *width = AV_CEIL_RSHIFT(sps->pic_width_in_luma_samples, ctb_log2_size_y);
36 *height = AV_CEIL_RSHIFT(sps->pic_height_in_luma_samples, ctb_log2_size_y);
37}
38
39#define HEADER(name) do { \
40 ff_cbs_trace_header(ctx, name); \
41 } while (0)
42
43#define CHECK(call) do { \
44 err = (call); \
45 if (err < 0) \
46 return err; \
47 } while (0)
48
49#define FUNC_NAME2(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
50#define FUNC_NAME1(rw, codec, name) FUNC_NAME2(rw, codec, name)
51#define FUNC_H265(name) FUNC_NAME1(READWRITE, h265, name)
52#define FUNC_NAME2_EXPORT(rw, codec, name) ff_cbs_ ## codec ## _ ## rw ## _ ## name
53#define FUNC_NAME1_EXPORT(rw, codec, name) FUNC_NAME2_EXPORT(rw, codec, name)
54#define FUNC_SEI(name) FUNC_NAME1_EXPORT(READWRITE, sei, name)
55
56#define SEI_FUNC(name, args) \
57static int FUNC_H265(name) args; \
58static int FUNC_H265(name ## _internal)(CodedBitstreamContext *ctx, \
59 RWContext *rw, void *cur, \
60 SEIMessageState *state) \
61{ \
62 return FUNC_H265(name)(ctx, rw, cur, state); \
63} \
64static int FUNC_H265(name) args
65
66#define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
67
68#define u(width, name, range_min, range_max) \
69 xu(width, name, current->name, range_min, range_max, 0, )
70#define flag(name) ub(1, name)
71#define ue(name, range_min, range_max) \
72 xue(name, current->name, range_min, range_max, 0, )
73#define i(width, name, range_min, range_max) \
74 xi(width, name, current->name, range_min, range_max, 0, )
75#define ib(width, name) \
76 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), 0, )
77#define se(name, range_min, range_max) \
78 xse(name, current->name, range_min, range_max, 0, )
79
80#define us(width, name, range_min, range_max, subs, ...) \
81 xu(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
82#define ubs(width, name, subs, ...) \
83 xu(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
84#define flags(name, subs, ...) \
85 xu(1, name, current->name, 0, 1, subs, __VA_ARGS__)
86#define ues(name, range_min, range_max, subs, ...) \
87 xue(name, current->name, range_min, range_max, subs, __VA_ARGS__)
88#define is(width, name, range_min, range_max, subs, ...) \
89 xi(width, name, current->name, range_min, range_max, subs, __VA_ARGS__)
90#define ibs(width, name, subs, ...) \
91 xi(width, name, current->name, MIN_INT_BITS(width), MAX_INT_BITS(width), subs, __VA_ARGS__)
92#define ses(name, range_min, range_max, subs, ...) \
93 xse(name, current->name, range_min, range_max, subs, __VA_ARGS__)
94
95#define fixed(width, name, value) do { \
96 av_unused uint32_t fixed_value = value; \
97 xu(width, name, fixed_value, value, value, 0, ); \
98 } while (0)
99
100
101#define READ
102#define READWRITE read
103#define RWContext GetBitContext
104
105#define ub(width, name) do { \
106 uint32_t value; \
107 CHECK(ff_cbs_read_simple_unsigned(ctx, rw, width, #name, \
108 &value)); \
109 current->name = value; \
110 } while (0)
111#define xu(width, name, var, range_min, range_max, subs, ...) do { \
112 uint32_t value; \
113 CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
114 SUBSCRIPTS(subs, __VA_ARGS__), \
115 &value, range_min, range_max)); \
116 var = value; \
117 } while (0)
118#define xue(name, var, range_min, range_max, subs, ...) do { \
119 uint32_t value; \
120 CHECK(ff_cbs_read_ue_golomb(ctx, rw, #name, \
121 SUBSCRIPTS(subs, __VA_ARGS__), \
122 &value, range_min, range_max)); \
123 var = value; \
124 } while (0)
125#define xi(width, name, var, range_min, range_max, subs, ...) do { \
126 int32_t value; \
127 CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
128 SUBSCRIPTS(subs, __VA_ARGS__), \
129 &value, range_min, range_max)); \
130 var = value; \
131 } while (0)
132#define xse(name, var, range_min, range_max, subs, ...) do { \
133 int32_t value; \
134 CHECK(ff_cbs_read_se_golomb(ctx, rw, #name, \
135 SUBSCRIPTS(subs, __VA_ARGS__), \
136 &value, range_min, range_max)); \
137 var = value; \
138 } while (0)
139
140
141#define infer(name, value) do { \
142 current->name = value; \
143 } while (0)
144
145#define more_rbsp_data(var) ((var) = ff_cbs_h2645_read_more_rbsp_data(rw))
146
147#define bit_position(rw) (get_bits_count(rw))
148#define byte_alignment(rw) (get_bits_count(rw) % 8)
149
150#define allocate(name, size) do { \
151 name ## _ref = av_buffer_allocz(size + \
152 AV_INPUT_BUFFER_PADDING_SIZE); \
153 if (!name ## _ref) \
154 return AVERROR(ENOMEM); \
155 name = (void *)name ## _ref->data; \
156 } while (0)
157
158#define FUNC(name) FUNC_H265(name)
160#undef FUNC
161
162
163#undef READ
164#undef READWRITE
165#undef RWContext
166#undef ub
167#undef xu
168#undef xi
169#undef xue
170#undef xse
171#undef infer
172#undef more_rbsp_data
173#undef bit_position
174#undef byte_alignment
175#undef allocate
176#undef allocate_struct
177
178
179#define WRITE
180#define READWRITE write
181#define RWContext PutBitContext
182
183#define ub(width, name) do { \
184 uint32_t value = current->name; \
185 CHECK(ff_cbs_write_simple_unsigned(ctx, rw, width, #name, \
186 value)); \
187 } while (0)
188#define xu(width, name, var, range_min, range_max, subs, ...) do { \
189 uint32_t value = var; \
190 CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
191 SUBSCRIPTS(subs, __VA_ARGS__), \
192 value, range_min, range_max)); \
193 } while (0)
194#define xue(name, var, range_min, range_max, subs, ...) do { \
195 uint32_t value = var; \
196 CHECK(ff_cbs_write_ue_golomb(ctx, rw, #name, \
197 SUBSCRIPTS(subs, __VA_ARGS__), \
198 value, range_min, range_max)); \
199 } while (0)
200#define xi(width, name, var, range_min, range_max, subs, ...) do { \
201 int32_t value = var; \
202 CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
203 SUBSCRIPTS(subs, __VA_ARGS__), \
204 value, range_min, range_max)); \
205 } while (0)
206#define xse(name, var, range_min, range_max, subs, ...) do { \
207 int32_t value = var; \
208 CHECK(ff_cbs_write_se_golomb(ctx, rw, #name, \
209 SUBSCRIPTS(subs, __VA_ARGS__), \
210 value, range_min, range_max)); \
211 } while (0)
212
213#define infer(name, value) do { \
214 if (current->name != (value)) { \
215 av_log(ctx->log_ctx, AV_LOG_ERROR, \
216 "%s does not match inferred value: " \
217 "%"PRId64", but should be %"PRId64".\n", \
218 #name, (int64_t)current->name, (int64_t)(value)); \
219 return AVERROR_INVALIDDATA; \
220 } \
221 } while (0)
222
223#define more_rbsp_data(var) (var)
224
225#define bit_position(rw) (put_bits_count(rw))
226#define byte_alignment(rw) (put_bits_count(rw) % 8)
227
228#define allocate(name, size) do { \
229 if (!name) { \
230 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s must be set " \
231 "for writing.\n", #name); \
232 return AVERROR_INVALIDDATA; \
233 } \
234 } while (0)
235
236#define FUNC(name) FUNC_H265(name)
238#undef FUNC
239
240#undef WRITE
241#undef READWRITE
242#undef RWContext
243#undef ub
244#undef xu
245#undef xi
246#undef xue
247#undef xse
248#undef u
249#undef i
250#undef flag
251#undef ue
252#undef se
253#undef infer
254#undef more_rbsp_data
255#undef bit_position
256#undef byte_alignment
257#undef allocate
258
259
260
263 int header)
264{
265 enum AVCodecID codec_id = ctx->codec->codec_id;
266 CodedBitstreamH265Context *priv = ctx->priv_data;
267 CodedBitstreamH2645Context *h2645 = &priv->common;
268 GetByteContext gbc;
269 int err;
270
271 av_assert0(frag->data && frag->nb_units == 0);
272 if (frag->data_size == 0)
273 return 0;
274
275 if (header && frag->data[0]) {
276 // HVCC header.
277 size_t size, start, end;
278 int i, j, nb_arrays, nal_unit_type, nb_nals, version;
279
280 h2645->mp4 = 1;
281
282 bytestream2_init(&gbc, frag->data, frag->data_size);
283
284 if (bytestream2_get_bytes_left(&gbc) < 23)
285 return AVERROR_INVALIDDATA;
286
287 version = bytestream2_get_byte(&gbc);
288 if (version != 1) {
289 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid HVCC header: "
290 "first byte %u.\n", version);
291 return AVERROR_INVALIDDATA;
292 }
293
294 bytestream2_skip(&gbc, 20);
295 h2645->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1;
296
297 nb_arrays = bytestream2_get_byte(&gbc);
298 for (i = 0; i < nb_arrays; i++) {
299 nal_unit_type = bytestream2_get_byte(&gbc) & 0x3f;
300 nb_nals = bytestream2_get_be16(&gbc);
301
302 start = bytestream2_tell(&gbc);
303 for (j = 0; j < nb_nals; j++) {
304 if (bytestream2_get_bytes_left(&gbc) < 2)
305 return AVERROR_INVALIDDATA;
306 size = bytestream2_get_be16(&gbc);
308 return AVERROR_INVALIDDATA;
309 bytestream2_skip(&gbc, size);
310 }
311 end = bytestream2_tell(&gbc);
312
314 frag->data + start, end - start,
315 ctx->log_ctx, 2, AV_CODEC_ID_HEVC,
317 if (err < 0) {
318 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
319 "HVCC array %d (%d NAL units of type %d).\n",
320 i, nb_nals, nal_unit_type);
321 return err;
322 }
323 err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
324 if (err < 0)
325 return err;
326 }
327 } else {
329 // Annex B, or later MP4 with already-known parameters.
330
332 frag->data, frag->data_size,
333 ctx->log_ctx,
334 h2645->nal_length_size,
335 codec_id, flags);
336 if (err < 0)
337 return err;
338
339 err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
340 if (err < 0)
341 return err;
342 }
343
344 return 0;
345}
346
347#define cbs_h2645_replace_ps(ps_name, ps_var, id_element) \
348static int cbs_h265_replace_ ## ps_var(CodedBitstreamContext *ctx, \
349 CodedBitstreamUnit *unit) \
350{ \
351 CodedBitstreamH265Context *priv = ctx->priv_data; \
352 H265Raw## ps_name *ps_var = unit->content; \
353 unsigned int id = ps_var->id_element; \
354 int err = ff_cbs_make_unit_refcounted(ctx, unit); \
355 if (err < 0) \
356 return err; \
357 if (priv->ps_var[id] == priv->active_ ## ps_var) \
358 priv->active_ ## ps_var = NULL ; \
359 av_assert0(unit->content_ref); \
360 av_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
361 return 0; \
362}
363
364cbs_h2645_replace_ps(VPS, vps, vps_video_parameter_set_id)
365cbs_h2645_replace_ps(SPS, sps, sps_seq_parameter_set_id)
366cbs_h2645_replace_ps(PPS, pps, pps_pic_parameter_set_id)
367
368static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx,
369 CodedBitstreamUnit *unit)
370{
371 GetBitContext gbc;
372 int err;
373
374 err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
375 if (err < 0)
376 return err;
377
378 err = ff_cbs_alloc_unit_content(ctx, unit);
379 if (err < 0)
380 return err;
381
382 switch (unit->type) {
383 case HEVC_NAL_VPS:
384 {
385 H265RawVPS *vps = unit->content;
386
387 err = cbs_h265_read_vps(ctx, &gbc, vps);
388 if (err < 0)
389 return err;
390
391 err = cbs_h265_replace_vps(ctx, unit);
392 if (err < 0)
393 return err;
394 }
395 break;
396 case HEVC_NAL_SPS:
397 {
398 H265RawSPS *sps = unit->content;
399
400 err = cbs_h265_read_sps(ctx, &gbc, sps);
401 if (err < 0)
402 return err;
403
404 err = cbs_h265_replace_sps(ctx, unit);
405 if (err < 0)
406 return err;
407 }
408 break;
409
410 case HEVC_NAL_PPS:
411 {
412 H265RawPPS *pps = unit->content;
413
414 err = cbs_h265_read_pps(ctx, &gbc, pps);
415 if (err < 0)
416 return err;
417
418 err = cbs_h265_replace_pps(ctx, unit);
419 if (err < 0)
420 return err;
421 }
422 break;
423
424 case HEVC_NAL_TRAIL_N:
425 case HEVC_NAL_TRAIL_R:
426 case HEVC_NAL_TSA_N:
427 case HEVC_NAL_TSA_R:
428 case HEVC_NAL_STSA_N:
429 case HEVC_NAL_STSA_R:
430 case HEVC_NAL_RADL_N:
431 case HEVC_NAL_RADL_R:
432 case HEVC_NAL_RASL_N:
433 case HEVC_NAL_RASL_R:
439 case HEVC_NAL_CRA_NUT:
440 {
441 H265RawSlice *slice = unit->content;
442 int pos, len;
443
444 err = cbs_h265_read_slice_segment_header(ctx, &gbc, &slice->header);
445 if (err < 0)
446 return err;
447
449 return AVERROR_INVALIDDATA;
450
451 pos = get_bits_count(&gbc);
452 len = unit->data_size;
453
454 slice->data_size = len - pos / 8;
455 slice->data_ref = av_buffer_ref(unit->data_ref);
456 if (!slice->data_ref)
457 return AVERROR(ENOMEM);
458 slice->data = unit->data + pos / 8;
459 slice->data_bit_start = pos % 8;
460 }
461 break;
462
463 case HEVC_NAL_AUD:
464 {
465 err = cbs_h265_read_aud(ctx, &gbc, unit->content);
466 if (err < 0)
467 return err;
468 }
469 break;
470
471 case HEVC_NAL_FD_NUT:
472 {
473 err = cbs_h265_read_filler(ctx, &gbc, unit->content);
474 if (err < 0)
475 return err;
476 }
477 break;
478
481 {
482 err = cbs_h265_read_sei(ctx, &gbc, unit->content,
483 unit->type == HEVC_NAL_SEI_PREFIX);
484
485 if (err < 0)
486 return err;
487 }
488 break;
489
490 default:
491 return AVERROR(ENOSYS);
492 }
493
494 return 0;
495}
496
498 CodedBitstreamUnit *unit,
499 PutBitContext *pbc)
500{
501 int err;
502
503 switch (unit->type) {
504 case HEVC_NAL_VPS:
505 {
506 H265RawVPS *vps = unit->content;
507
508 err = cbs_h265_write_vps(ctx, pbc, vps);
509 if (err < 0)
510 return err;
511
512 err = cbs_h265_replace_vps(ctx, unit);
513 if (err < 0)
514 return err;
515 }
516 break;
517
518 case HEVC_NAL_SPS:
519 {
520 H265RawSPS *sps = unit->content;
521
522 err = cbs_h265_write_sps(ctx, pbc, sps);
523 if (err < 0)
524 return err;
525
526 err = cbs_h265_replace_sps(ctx, unit);
527 if (err < 0)
528 return err;
529 }
530 break;
531
532 case HEVC_NAL_PPS:
533 {
534 H265RawPPS *pps = unit->content;
535
536 err = cbs_h265_write_pps(ctx, pbc, pps);
537 if (err < 0)
538 return err;
539
540 err = cbs_h265_replace_pps(ctx, unit);
541 if (err < 0)
542 return err;
543 }
544 break;
545
546 case HEVC_NAL_TRAIL_N:
547 case HEVC_NAL_TRAIL_R:
548 case HEVC_NAL_TSA_N:
549 case HEVC_NAL_TSA_R:
550 case HEVC_NAL_STSA_N:
551 case HEVC_NAL_STSA_R:
552 case HEVC_NAL_RADL_N:
553 case HEVC_NAL_RADL_R:
554 case HEVC_NAL_RASL_N:
555 case HEVC_NAL_RASL_R:
561 case HEVC_NAL_CRA_NUT:
562 {
563 H265RawSlice *slice = unit->content;
564
565 err = cbs_h265_write_slice_segment_header(ctx, pbc, &slice->header);
566 if (err < 0)
567 return err;
568
569 if (slice->data) {
570 err = ff_cbs_h2645_write_slice_data(ctx, pbc, slice->data,
571 slice->data_size,
572 slice->data_bit_start);
573 if (err < 0)
574 return err;
575 } else {
576 // No slice data - that was just the header.
577 }
578 }
579 break;
580
581 case HEVC_NAL_AUD:
582 {
583 err = cbs_h265_write_aud(ctx, pbc, unit->content);
584 if (err < 0)
585 return err;
586 }
587 break;
588
589 case HEVC_NAL_FD_NUT:
590 {
591 err = cbs_h265_write_filler(ctx, pbc, unit->content);
592 if (err < 0)
593 return err;
594 }
595 break;
596
599 {
600 err = cbs_h265_write_sei(ctx, pbc, unit->content,
601 unit->type == HEVC_NAL_SEI_PREFIX);
602
603 if (err < 0)
604 return err;
605 }
606 break;
607
608 default:
609 av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
610 "NAL unit type %"PRIu32".\n", unit->type);
612 }
613
614 return 0;
615}
616
618 const CodedBitstreamUnit *unit,
619 enum AVDiscard skip)
620{
621 H265RawSliceHeader *slice;
622
623 if (skip <= AVDISCARD_DEFAULT)
624 return 0;
625
626 switch (unit->type) {
632 case HEVC_NAL_CRA_NUT:
633 // IRAP slice
634 if (skip < AVDISCARD_ALL)
635 return 0;
636 break;
637
638 case HEVC_NAL_TRAIL_R:
639 case HEVC_NAL_TRAIL_N:
640 case HEVC_NAL_TSA_N:
641 case HEVC_NAL_TSA_R:
642 case HEVC_NAL_STSA_N:
643 case HEVC_NAL_STSA_R:
644 case HEVC_NAL_RADL_N:
645 case HEVC_NAL_RADL_R:
646 case HEVC_NAL_RASL_N:
647 case HEVC_NAL_RASL_R:
648 // Slice
649 break;
650 default:
651 // Don't discard non-slice nal.
652 return 0;
653 }
654
655 if (skip >= AVDISCARD_NONKEY)
656 return 1;
657
658 slice = (H265RawSliceHeader *)unit->content;
659 if (!slice) {
660 av_log(ctx->log_ctx, AV_LOG_WARNING,
661 "h265 slice header is null, missing decompose?\n");
662 return 0;
663 }
664
666 return 1;
667 if (skip >= AVDISCARD_BIDIR && slice->slice_type == HEVC_SLICE_B)
668 return 1;
669
670 if (skip >= AVDISCARD_NONREF) {
671 switch (unit->type) {
672 case HEVC_NAL_TRAIL_N:
673 case HEVC_NAL_TSA_N:
674 case HEVC_NAL_STSA_N:
675 case HEVC_NAL_RADL_N:
676 case HEVC_NAL_RASL_N:
677 case HEVC_NAL_VCL_N10:
678 case HEVC_NAL_VCL_N12:
679 case HEVC_NAL_VCL_N14:
680 // non-ref
681 return 1;
682 default:
683 break;
684 }
685 }
686
687 return 0;
688}
689
691{
692 CodedBitstreamH265Context *h265 = ctx->priv_data;
693
694 for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
695 av_refstruct_unref(&h265->vps[i]);
696 for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
697 av_refstruct_unref(&h265->sps[i]);
698 for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
699 av_refstruct_unref(&h265->pps[i]);
700
701 h265->active_vps = NULL;
702 h265->active_sps = NULL;
703 h265->active_pps = NULL;
704}
705
707{
708 CodedBitstreamH265Context *h265 = ctx->priv_data;
709 int i;
710
712
713 for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++)
714 av_refstruct_unref(&h265->vps[i]);
715 for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++)
716 av_refstruct_unref(&h265->sps[i]);
717 for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++)
718 av_refstruct_unref(&h265->pps[i]);
719}
720
721static void cbs_h265_free_sei(AVRefStructOpaque unused, void *content)
722{
723 H265RawSEI *sei = content;
724 ff_cbs_sei_free_message_list(&sei->message_list);
725}
726
728 {
729 .nb_unit_types = 1,
730 .unit_type.list = { HEVC_NAL_VPS },
731 .content_type = CBS_CONTENT_TYPE_INTERNAL_REFS,
732 .content_size = sizeof(H265RawVPS),
733 .type.ref = {
734 .nb_offsets = 2,
735 .offsets = { offsetof(H265RawVPS, extension_data.data),
736 offsetof(H265RawVPS, hrd_parameters) }
737 },
738 },
739
742
745
746 // Slices of non-IRAP pictures.
749 // Slices of IRAP pictures.
752
755
757};
758
759// Macro for the read/write pair.
760#define SEI_MESSAGE_RW(codec, name) \
761 .read = cbs_ ## codec ## _read_ ## name ## _internal, \
762 .write = cbs_ ## codec ## _write_ ## name ## _internal
763
765 {
767 1, 0,
769 SEI_MESSAGE_RW(h265, sei_buffering_period),
770 },
771 {
773 1, 0,
774 sizeof(H265RawSEIPicTiming),
775 SEI_MESSAGE_RW(h265, sei_pic_timing),
776 },
777 {
779 1, 0,
780 sizeof(H265RawSEIPanScanRect),
781 SEI_MESSAGE_RW(h265, sei_pan_scan_rect),
782 },
783 {
785 1, 0,
787 SEI_MESSAGE_RW(h265, sei_recovery_point),
788 },
789 {
791 1, 0,
793 SEI_MESSAGE_RW(h265, film_grain_characteristics),
794 },
795 {
797 1, 0,
799 SEI_MESSAGE_RW(h265, sei_display_orientation),
800 },
801 {
803 1, 0,
805 SEI_MESSAGE_RW(h265, sei_active_parameter_sets),
806 },
807 {
809 0, 1,
811 SEI_MESSAGE_RW(h265, sei_decoded_picture_hash),
812 },
813 {
815 1, 0,
816 sizeof(H265RawSEITimeCode),
817 SEI_MESSAGE_RW(h265, sei_time_code),
818 },
819 {
821 1, 0,
823 SEI_MESSAGE_RW(h265, sei_alpha_channel_info),
824 },
825 {
827 1, 0,
829 SEI_MESSAGE_RW(h265, sei_3d_reference_displays_info),
830 },
832};
833
835 .codec_id = AV_CODEC_ID_HEVC,
836
837 .priv_data_size = sizeof(CodedBitstreamH265Context),
838
839 .unit_types = cbs_h265_unit_types,
840
841 .split_fragment = &cbs_h265_split_fragment,
842 .read_unit = &cbs_h265_read_nal_unit,
843 .write_unit = &cbs_h265_write_nal_unit,
844 .discarded_unit = &cbs_h265_discarded_nal_unit,
845 .assemble_fragment = &ff_cbs_h2645_assemble_fragment,
846
849};
static AVFormatContext * ctx
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:760
static av_cold void cbs_h265_flush(CodedBitstreamContext *ctx)
Definition cbs_h265.c:690
static CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[]
Definition cbs_h265.c:727
static av_cold void cbs_h265_close(CodedBitstreamContext *ctx)
Definition cbs_h265.c:706
const CodedBitstreamType ff_cbs_type_h265
Definition cbs_h265.c:834
const SEIMessageTypeDescriptor ff_cbs_sei_h265_types[]
Definition cbs_h265.c:764
static void cbs_h265_pic_size_in_ctbs(const H265RawSPS *sps, unsigned int *width, unsigned int *height)
Definition cbs_h265.c:30
static int cbs_h265_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition cbs_h265.c:261
static int cbs_h265_discarded_nal_unit(CodedBitstreamContext *ctx, const CodedBitstreamUnit *unit, enum AVDiscard skip)
Definition cbs_h265.c:617
static void cbs_h265_free_sei(AVRefStructOpaque unused, void *content)
Definition cbs_h265.c:721
#define cbs_h2645_replace_ps(ps_name, ps_var, id_element)
Definition cbs_h265.c:347
static int cbs_h265_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition cbs_h265.c:497
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 AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#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:232
@ AVDISCARD_ALL
discard all
Definition defs.h:241
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition defs.h:240
@ AVDISCARD_BIDIR
discard all bidirectional frames
Definition defs.h:238
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
Definition defs.h:236
@ AVDISCARD_NONINTRA
discard all non intra frames
Definition defs.h:239
@ AVDISCARD_NONREF
discard all non reference
Definition defs.h:237
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
#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:121
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,...)
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
int size
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition refstruct.h:58
enum AVCodecID codec_id
int len