FFmpeg
Loading...
Searching...
No Matches
cbs_h264.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_h264.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_H264(name) FUNC_NAME1(READWRITE, h264, 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_H264(name) args; \
48static int FUNC_H264(name ## _internal)(CodedBitstreamContext *ctx, \
49 RWContext *rw, void *cur, \
50 SEIMessageState *state) \
51{ \
52 return FUNC_H264(name)(ctx, rw, cur, state); \
53} \
54static int FUNC_H264(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 = name ## _ref->data; \
146 } while (0)
147
148#define FUNC(name) FUNC_H264(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_H264(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 CodedBitstreamH264Context *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 // AVCC header.
267 size_t size, start, end;
268 int i, count, version;
269
270 h2645->mp4 = 1;
271
272 bytestream2_init(&gbc, frag->data, frag->data_size);
273
274 if (bytestream2_get_bytes_left(&gbc) < 6)
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 AVCC header: "
280 "first byte %u.\n", version);
281 return AVERROR_INVALIDDATA;
282 }
283
284 bytestream2_skip(&gbc, 3);
285 h2645->nal_length_size = (bytestream2_get_byte(&gbc) & 3) + 1;
286
287 // SPS array.
288 count = bytestream2_get_byte(&gbc) & 0x1f;
289 start = bytestream2_tell(&gbc);
290 for (i = 0; i < count; i++) {
291 if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i))
292 return AVERROR_INVALIDDATA;
293 size = bytestream2_get_be16(&gbc);
295 return AVERROR_INVALIDDATA;
296 bytestream2_skip(&gbc, size);
297 }
298 end = bytestream2_tell(&gbc);
299
301 frag->data + start, end - start,
302 ctx->log_ctx, 2, AV_CODEC_ID_H264,
304 if (err < 0) {
305 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n");
306 return err;
307 }
308 err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
309 if (err < 0)
310 return err;
311
312 // PPS array.
313 count = bytestream2_get_byte(&gbc);
314 start = bytestream2_tell(&gbc);
315 for (i = 0; i < count; i++) {
316 if (bytestream2_get_bytes_left(&gbc) < 2 * (count - i))
317 return AVERROR_INVALIDDATA;
318 size = bytestream2_get_be16(&gbc);
320 return AVERROR_INVALIDDATA;
321 bytestream2_skip(&gbc, size);
322 }
323 end = bytestream2_tell(&gbc);
324
326 frag->data + start, end - start,
327 ctx->log_ctx, 2, AV_CODEC_ID_H264,
329 if (err < 0) {
330 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n");
331 return err;
332 }
333 err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
334 if (err < 0)
335 return err;
336
337 if (bytestream2_get_bytes_left(&gbc) > 0) {
338 av_log(ctx->log_ctx, AV_LOG_WARNING, "%u bytes left at end of AVCC "
339 "header.\n", bytestream2_get_bytes_left(&gbc));
340 }
341 } else {
343 // Annex B, or later MP4 with already-known parameters.
344
346 frag->data, frag->data_size,
347 ctx->log_ctx,
348 h2645->nal_length_size,
349 codec_id, flags);
350 if (err < 0)
351 return err;
352
353 err = ff_cbs_h2645_fragment_add_nals(ctx, frag, &h2645->read_packet);
354 if (err < 0)
355 return err;
356 }
357
358 return 0;
359}
360
361#define cbs_h2645_replace_ps(ps_name, ps_var, id_element) \
362static int cbs_h264_replace_ ## ps_var(CodedBitstreamContext *ctx, \
363 CodedBitstreamUnit *unit) \
364{ \
365 CodedBitstreamH264Context *priv = ctx->priv_data; \
366 H264Raw ## ps_name *ps_var = unit->content; \
367 unsigned int id = ps_var->id_element; \
368 int err = ff_cbs_make_unit_refcounted(ctx, unit); \
369 if (err < 0) \
370 return err; \
371 if (priv->ps_var[id] == priv->active_ ## ps_var) \
372 priv->active_ ## ps_var = NULL ; \
373 av_assert0(unit->content_ref); \
374 av_refstruct_replace(&priv->ps_var[id], unit->content_ref); \
375 return 0; \
376}
377
378cbs_h2645_replace_ps(SPS, sps, seq_parameter_set_id)
379cbs_h2645_replace_ps(PPS, pps, pic_parameter_set_id)
380
381static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx,
382 CodedBitstreamUnit *unit)
383{
384 GetBitContext gbc;
385 int err;
386
387 err = init_get_bits(&gbc, unit->data, 8 * unit->data_size);
388 if (err < 0)
389 return err;
390
391 err = ff_cbs_alloc_unit_content(ctx, unit);
392 if (err < 0)
393 return err;
394
395 switch (unit->type) {
396 case H264_NAL_SPS:
397 {
398 H264RawSPS *sps = unit->content;
399
400 err = cbs_h264_read_sps(ctx, &gbc, sps);
401 if (err < 0)
402 return err;
403
404 err = cbs_h264_replace_sps(ctx, unit);
405 if (err < 0)
406 return err;
407 }
408 break;
409
410 case H264_NAL_SPS_EXT:
411 {
412 err = cbs_h264_read_sps_extension(ctx, &gbc, unit->content);
413 if (err < 0)
414 return err;
415 }
416 break;
417
418 case H264_NAL_PPS:
419 {
420 H264RawPPS *pps = unit->content;
421
422 err = cbs_h264_read_pps(ctx, &gbc, pps);
423 if (err < 0)
424 return err;
425
426 err = cbs_h264_replace_pps(ctx, unit);
427 if (err < 0)
428 return err;
429 }
430 break;
431
432 case H264_NAL_SLICE:
435 {
436 H264RawSlice *slice = unit->content;
437 int pos, len;
438
439 err = cbs_h264_read_slice_header(ctx, &gbc, &slice->header);
440 if (err < 0)
441 return err;
442
444 return AVERROR_INVALIDDATA;
445
446 pos = get_bits_count(&gbc);
447 len = unit->data_size;
448
449 slice->data_size = len - pos / 8;
450 slice->data_ref = av_buffer_ref(unit->data_ref);
451 if (!slice->data_ref)
452 return AVERROR(ENOMEM);
453 slice->data = unit->data + pos / 8;
454 slice->data_bit_start = pos % 8;
455 }
456 break;
457
458 case H264_NAL_AUD:
459 {
460 err = cbs_h264_read_aud(ctx, &gbc, unit->content);
461 if (err < 0)
462 return err;
463 }
464 break;
465
466 case H264_NAL_SEI:
467 {
468 err = cbs_h264_read_sei(ctx, &gbc, unit->content);
469 if (err < 0)
470 return err;
471 }
472 break;
473
475 {
476 err = cbs_h264_read_filler(ctx, &gbc, unit->content);
477 if (err < 0)
478 return err;
479 }
480 break;
481
484 {
485 err = (unit->type == H264_NAL_END_SEQUENCE ?
486 cbs_h264_read_end_of_sequence :
487 cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content);
488 if (err < 0)
489 return err;
490 }
491 break;
492
493 default:
494 return AVERROR(ENOSYS);
495 }
496
497 return 0;
498}
499
501 CodedBitstreamUnit *unit,
502 PutBitContext *pbc)
503{
504 int err;
505
506 switch (unit->type) {
507 case H264_NAL_SPS:
508 {
509 H264RawSPS *sps = unit->content;
510
511 err = cbs_h264_write_sps(ctx, pbc, sps);
512 if (err < 0)
513 return err;
514
515 err = cbs_h264_replace_sps(ctx, unit);
516 if (err < 0)
517 return err;
518 }
519 break;
520
521 case H264_NAL_SPS_EXT:
522 {
523 H264RawSPSExtension *sps_ext = unit->content;
524
525 err = cbs_h264_write_sps_extension(ctx, pbc, sps_ext);
526 if (err < 0)
527 return err;
528 }
529 break;
530
531 case H264_NAL_PPS:
532 {
533 H264RawPPS *pps = unit->content;
534
535 err = cbs_h264_write_pps(ctx, pbc, pps);
536 if (err < 0)
537 return err;
538
539 err = cbs_h264_replace_pps(ctx, unit);
540 if (err < 0)
541 return err;
542 }
543 break;
544
545 case H264_NAL_SLICE:
548 {
549 H264RawSlice *slice = unit->content;
550
551 err = cbs_h264_write_slice_header(ctx, pbc, &slice->header);
552 if (err < 0)
553 return err;
554
555 if (slice->data) {
556 err = ff_cbs_h2645_write_slice_data(ctx, pbc, slice->data,
557 slice->data_size,
558 slice->data_bit_start);
559 if (err < 0)
560 return err;
561 } else {
562 // No slice data - that was just the header.
563 // (Bitstream may be unaligned!)
564 }
565 }
566 break;
567
568 case H264_NAL_AUD:
569 {
570 err = cbs_h264_write_aud(ctx, pbc, unit->content);
571 if (err < 0)
572 return err;
573 }
574 break;
575
576 case H264_NAL_SEI:
577 {
578 err = cbs_h264_write_sei(ctx, pbc, unit->content);
579 if (err < 0)
580 return err;
581 }
582 break;
583
585 {
586 err = cbs_h264_write_filler(ctx, pbc, unit->content);
587 if (err < 0)
588 return err;
589 }
590 break;
591
593 {
594 err = cbs_h264_write_end_of_sequence(ctx, pbc, unit->content);
595 if (err < 0)
596 return err;
597 }
598 break;
599
601 {
602 err = cbs_h264_write_end_of_stream(ctx, pbc, unit->content);
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{
622 H264RawSliceHeader *slice;
623 int slice_type_i, slice_type_b, slice_type_si;
624
625 if (skip <= AVDISCARD_DEFAULT)
626 return 0;
627
628 // keep non-VCL
629 if (unit->type != H264_NAL_SLICE &&
630 unit->type != H264_NAL_IDR_SLICE &&
632 return 0;
633
634 if (skip >= AVDISCARD_ALL)
635 return 1;
636
637 if (skip >= AVDISCARD_NONKEY && unit->type != H264_NAL_IDR_SLICE)
638 return 1;
639
641 if (!header) {
642 av_log(ctx->log_ctx, AV_LOG_WARNING,
643 "h264 nal unit header is null, missing decompose?\n");
644 return 0;
645 }
646
647 if (skip >= AVDISCARD_NONREF && !header->nal_ref_idc)
648 return 1;
649
650 slice = (H264RawSliceHeader *)unit->content;
651 if (!slice) {
652 av_log(ctx->log_ctx, AV_LOG_WARNING,
653 "h264 slice header is null, missing decompose?\n");
654 return 0;
655 }
656
657 slice_type_i = slice->slice_type % 5 == 2;
658 slice_type_b = slice->slice_type % 5 == 1;
659 slice_type_si = slice->slice_type % 5 == 4;
660
661 if (skip >= AVDISCARD_BIDIR && slice_type_b)
662 return 1;
663 if (skip >= AVDISCARD_NONINTRA && !slice_type_i && !slice_type_si)
664 return 1;
665
666 return 0;
667}
668
670{
671 CodedBitstreamH264Context *h264 = ctx->priv_data;
672
673 for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++)
674 av_refstruct_unref(&h264->sps[i]);
675 for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++)
676 av_refstruct_unref(&h264->pps[i]);
677
678 h264->active_sps = NULL;
679 h264->active_pps = NULL;
680 h264->last_slice_nal_unit_type = 0;
681}
682
684{
685 CodedBitstreamH264Context *h264 = ctx->priv_data;
686 int i;
687
689
690 for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++)
691 av_refstruct_unref(&h264->sps[i]);
692 for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++)
693 av_refstruct_unref(&h264->pps[i]);
694}
695
696static void cbs_h264_free_sei(AVRefStructOpaque unused, void *content)
697{
698 H264RawSEI *sei = content;
699 ff_cbs_sei_free_message_list(&sei->message_list);
700}
701
721
723 .codec_id = AV_CODEC_ID_H264,
724
725 .priv_data_size = sizeof(CodedBitstreamH264Context),
726
727 .unit_types = cbs_h264_unit_types,
728
729 .split_fragment = &cbs_h264_split_fragment,
730 .read_unit = &cbs_h264_read_nal_unit,
731 .write_unit = &cbs_h264_write_nal_unit,
732 .discarded_unit = &cbs_h264_discarded_nal_unit,
733 .assemble_fragment = &ff_cbs_h2645_assemble_fragment,
734
737};
738
739// Macro for the read/write pair.
740#define SEI_MESSAGE_RW(codec, name) \
741 .read = cbs_ ## codec ## _read_ ## name ## _internal, \
742 .write = cbs_ ## codec ## _write_ ## name ## _internal
743
745 {
747 1, 0,
749 SEI_MESSAGE_RW(h264, sei_buffering_period),
750 },
751 {
753 1, 0,
754 sizeof(H264RawSEIPicTiming),
755 SEI_MESSAGE_RW(h264, sei_pic_timing),
756 },
757 {
759 1, 0,
760 sizeof(H264RawSEIPanScanRect),
761 SEI_MESSAGE_RW(h264, sei_pan_scan_rect),
762 },
763 {
765 1, 0,
767 SEI_MESSAGE_RW(h264, sei_recovery_point),
768 },
769 {
771 1, 0,
773 SEI_MESSAGE_RW(h264, film_grain_characteristics),
774 },
775 {
777 1, 0,
779 SEI_MESSAGE_RW(h264, sei_frame_packing_arrangement),
780 },
781 {
783 1, 0,
785 SEI_MESSAGE_RW(h264, sei_display_orientation),
786 },
788};
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 SEI_MESSAGE_RW(codec, name)
Definition cbs_h264.c:740
#define flags(name, subs,...)
Definition cbs_h264.c:74
const SEIMessageTypeDescriptor ff_cbs_sei_h264_types[]
Definition cbs_h264.c:744
static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit, PutBitContext *pbc)
Definition cbs_h264.c:500
static av_cold void cbs_h264_close(CodedBitstreamContext *ctx)
Definition cbs_h264.c:683
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define cbs_h2645_replace_ps(ps_name, ps_var, id_element)
Definition cbs_h264.c:361
static av_cold void cbs_h264_flush(CodedBitstreamContext *ctx)
Definition cbs_h264.c:669
static void cbs_h264_free_sei(AVRefStructOpaque unused, void *content)
Definition cbs_h264.c:696
const CodedBitstreamType ff_cbs_type_h264
Definition cbs_h264.c:722
static int cbs_h264_discarded_nal_unit(CodedBitstreamContext *ctx, const CodedBitstreamUnit *unit, enum AVDiscard skip)
Definition cbs_h264.c:617
static int cbs_h264_split_fragment(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int header)
Definition cbs_h264.c:251
static CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[]
Definition cbs_h264.c:702
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
#define CBS_UNIT_TYPE_POD(type_, structure)
#define CBS_UNIT_TYPES_INTERNAL_REF(types, structure, ref_field)
#define CBS_UNIT_TYPE_END_OF_LIST
#define CBS_UNIT_TYPE_INTERNAL_REF(type, structure, ref_field)
#define CBS_UNIT_TYPE_COMPLEX(type, structure, free_func)
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_H264
Definition codec_id.h:77
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
@ H264_NAL_END_STREAM
Definition h264.h:45
@ H264_NAL_END_SEQUENCE
Definition h264.h:44
@ H264_NAL_AUXILIARY_SLICE
Definition h264.h:53
@ H264_NAL_PPS
Definition h264.h:42
@ H264_NAL_SPS
Definition h264.h:41
@ H264_NAL_SLICE
Definition h264.h:35
@ H264_NAL_FILLER_DATA
Definition h264.h:46
@ H264_NAL_SPS_EXT
Definition h264.h:47
@ H264_NAL_SEI
Definition h264.h:40
@ H264_NAL_AUD
Definition h264.h:43
@ H264_NAL_IDR_SLICE
Definition h264.h:39
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.
#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_RECOVERY_POINT
Definition sei.h:36
@ SEI_TYPE_PIC_TIMING
Definition sei.h:31
@ SEI_TYPE_DISPLAY_ORIENTATION
Definition sei.h:77
@ SEI_TYPE_FRAME_PACKING_ARRANGEMENT
Definition sei.h:75
@ SEI_TYPE_FILM_GRAIN_CHARACTERISTICS
Definition sei.h:49
@ 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 H264RawPPS * active_pps
Definition cbs_h264.h:437
const H264RawSPS * active_sps
Definition cbs_h264.h:436
H264RawSPS * sps[H264_MAX_SPS_COUNT]
RefStruct references.
Definition cbs_h264.h:430
H264RawPPS * pps[H264_MAX_PPS_COUNT]
RefStruct references.
Definition cbs_h264.h:431
CodedBitstreamH2645Context common
Definition cbs_h264.h:426
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
AVBufferRef * data_ref
Definition cbs_h264.h:412
size_t data_size
Definition cbs_h264.h:413
int data_bit_start
Definition cbs_h264.h:414
H264RawSliceHeader header
Definition cbs_h264.h:409
uint8_t * data
Definition cbs_h264.h:411
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