2 * This file is part of FFmpeg.
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.
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.
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
23 #include "libavutil/avassert.h"
24 #include "libavutil/buffer.h"
25 #include "libavutil/common.h"
28 #include "cbs_internal.h"
31 static const CodedBitstreamType *cbs_type_table[] = {
52 const enum AVCodecID ff_cbs_all_codec_ids[] = {
66 AV_CODEC_ID_MPEG2VIDEO,
74 int ff_cbs_init(CodedBitstreamContext **ctx_ptr,
75 enum AVCodecID codec_id, void *log_ctx)
77 CodedBitstreamContext *ctx;
78 const CodedBitstreamType *type;
82 for (i = 0; i < FF_ARRAY_ELEMS(cbs_type_table); i++) {
83 if (cbs_type_table[i]->codec_id == codec_id) {
84 type = cbs_type_table[i];
89 return AVERROR(EINVAL);
91 ctx = av_mallocz(sizeof(*ctx));
93 return AVERROR(ENOMEM);
95 ctx->log_ctx = log_ctx;
98 if (type->priv_data_size) {
99 ctx->priv_data = av_mallocz(ctx->codec->priv_data_size);
100 if (!ctx->priv_data) {
102 return AVERROR(ENOMEM);
106 ctx->decompose_unit_types = NULL;
108 ctx->trace_enable = 0;
109 ctx->trace_level = AV_LOG_TRACE;
115 void ff_cbs_flush(CodedBitstreamContext *ctx)
117 if (ctx->codec && ctx->codec->flush)
118 ctx->codec->flush(ctx);
121 void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
123 CodedBitstreamContext *ctx = *ctx_ptr;
128 if (ctx->codec && ctx->codec->close)
129 ctx->codec->close(ctx);
131 av_freep(&ctx->write_buffer);
132 av_freep(&ctx->priv_data);
136 static void cbs_unit_uninit(CodedBitstreamUnit *unit)
138 av_buffer_unref(&unit->content_ref);
139 unit->content = NULL;
141 av_buffer_unref(&unit->data_ref);
144 unit->data_bit_padding = 0;
147 void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
151 for (i = 0; i < frag->nb_units; i++)
152 cbs_unit_uninit(&frag->units[i]);
155 av_buffer_unref(&frag->data_ref);
158 frag->data_bit_padding = 0;
161 void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
163 ff_cbs_fragment_reset(frag);
165 av_freep(&frag->units);
166 frag->nb_units_allocated = 0;
169 static int cbs_read_fragment_content(CodedBitstreamContext *ctx,
170 CodedBitstreamFragment *frag)
174 for (i = 0; i < frag->nb_units; i++) {
175 CodedBitstreamUnit *unit = &frag->units[i];
177 if (ctx->decompose_unit_types) {
178 for (j = 0; j < ctx->nb_decompose_unit_types; j++) {
179 if (ctx->decompose_unit_types[j] == unit->type)
182 if (j >= ctx->nb_decompose_unit_types)
186 av_buffer_unref(&unit->content_ref);
187 unit->content = NULL;
189 av_assert0(unit->data && unit->data_ref);
191 err = ctx->codec->read_unit(ctx, unit);
192 if (err == AVERROR(ENOSYS)) {
193 av_log(ctx->log_ctx, AV_LOG_VERBOSE,
194 "Decomposition unimplemented for unit %d "
195 "(type %"PRIu32").\n", i, unit->type);
196 } else if (err < 0) {
197 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d "
198 "(type %"PRIu32").\n", i, unit->type);
206 static int cbs_fill_fragment_data(CodedBitstreamFragment *frag,
207 const uint8_t *data, size_t size)
209 av_assert0(!frag->data && !frag->data_ref);
212 av_buffer_alloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
214 return AVERROR(ENOMEM);
216 frag->data = frag->data_ref->data;
217 frag->data_size = size;
219 memcpy(frag->data, data, size);
220 memset(frag->data + size, 0,
221 AV_INPUT_BUFFER_PADDING_SIZE);
226 static int cbs_read_data(CodedBitstreamContext *ctx,
227 CodedBitstreamFragment *frag,
229 const uint8_t *data, size_t size,
235 frag->data_ref = av_buffer_ref(buf);
237 return AVERROR(ENOMEM);
239 frag->data = (uint8_t *)data;
240 frag->data_size = size;
243 err = cbs_fill_fragment_data(frag, data, size);
248 err = ctx->codec->split_fragment(ctx, frag, header);
252 return cbs_read_fragment_content(ctx, frag);
255 int ff_cbs_read_extradata(CodedBitstreamContext *ctx,
256 CodedBitstreamFragment *frag,
257 const AVCodecParameters *par)
259 return cbs_read_data(ctx, frag, NULL,
261 par->extradata_size, 1);
264 int ff_cbs_read_extradata_from_codec(CodedBitstreamContext *ctx,
265 CodedBitstreamFragment *frag,
266 const AVCodecContext *avctx)
268 return cbs_read_data(ctx, frag, NULL,
270 avctx->extradata_size, 1);
273 int ff_cbs_read_packet(CodedBitstreamContext *ctx,
274 CodedBitstreamFragment *frag,
277 return cbs_read_data(ctx, frag, pkt->buf,
278 pkt->data, pkt->size, 0);
281 int ff_cbs_read(CodedBitstreamContext *ctx,
282 CodedBitstreamFragment *frag,
283 const uint8_t *data, size_t size)
285 return cbs_read_data(ctx, frag, NULL,
289 static int cbs_write_unit_data(CodedBitstreamContext *ctx,
290 CodedBitstreamUnit *unit)
295 if (!ctx->write_buffer) {
296 // Initial write buffer size is 1MB.
297 ctx->write_buffer_size = 1024 * 1024;
299 reallocate_and_try_again:
300 ret = av_reallocp(&ctx->write_buffer, ctx->write_buffer_size);
302 av_log(ctx->log_ctx, AV_LOG_ERROR, "Unable to allocate a "
303 "sufficiently large write buffer (last attempt "
304 "%"SIZE_SPECIFIER" bytes).\n", ctx->write_buffer_size);
309 init_put_bits(&pbc, ctx->write_buffer, ctx->write_buffer_size);
311 ret = ctx->codec->write_unit(ctx, unit, &pbc);
313 if (ret == AVERROR(ENOSPC)) {
315 if (ctx->write_buffer_size == INT_MAX / 8)
316 return AVERROR(ENOMEM);
317 ctx->write_buffer_size = FFMIN(2 * ctx->write_buffer_size, INT_MAX / 8);
318 goto reallocate_and_try_again;
320 // Write failed for some other reason.
324 // Overflow but we didn't notice.
325 av_assert0(put_bits_count(&pbc) <= 8 * ctx->write_buffer_size);
327 if (put_bits_count(&pbc) % 8)
328 unit->data_bit_padding = 8 - put_bits_count(&pbc) % 8;
330 unit->data_bit_padding = 0;
332 flush_put_bits(&pbc);
334 ret = ff_cbs_alloc_unit_data(unit, put_bits_count(&pbc) / 8);
338 memcpy(unit->data, ctx->write_buffer, unit->data_size);
343 int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx,
344 CodedBitstreamFragment *frag)
348 for (i = 0; i < frag->nb_units; i++) {
349 CodedBitstreamUnit *unit = &frag->units[i];
354 av_buffer_unref(&unit->data_ref);
357 err = cbs_write_unit_data(ctx, unit);
359 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to write unit %d "
360 "(type %"PRIu32").\n", i, unit->type);
363 av_assert0(unit->data && unit->data_ref);
366 av_buffer_unref(&frag->data_ref);
369 err = ctx->codec->assemble_fragment(ctx, frag);
371 av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to assemble fragment.\n");
374 av_assert0(frag->data && frag->data_ref);
379 int ff_cbs_write_extradata(CodedBitstreamContext *ctx,
380 AVCodecParameters *par,
381 CodedBitstreamFragment *frag)
385 err = ff_cbs_write_fragment_data(ctx, frag);
389 av_freep(&par->extradata);
391 par->extradata = av_malloc(frag->data_size +
392 AV_INPUT_BUFFER_PADDING_SIZE);
394 return AVERROR(ENOMEM);
396 memcpy(par->extradata, frag->data, frag->data_size);
397 memset(par->extradata + frag->data_size, 0,
398 AV_INPUT_BUFFER_PADDING_SIZE);
399 par->extradata_size = frag->data_size;
404 int ff_cbs_write_packet(CodedBitstreamContext *ctx,
406 CodedBitstreamFragment *frag)
411 err = ff_cbs_write_fragment_data(ctx, frag);
415 buf = av_buffer_ref(frag->data_ref);
417 return AVERROR(ENOMEM);
419 av_buffer_unref(&pkt->buf);
422 pkt->data = frag->data;
423 pkt->size = frag->data_size;
429 void ff_cbs_trace_header(CodedBitstreamContext *ctx,
432 if (!ctx->trace_enable)
435 av_log(ctx->log_ctx, ctx->trace_level, "%s\n", name);
438 void ff_cbs_trace_syntax_element(CodedBitstreamContext *ctx, int position,
439 const char *str, const int *subscripts,
440 const char *bits, int64_t value)
443 size_t name_len, bits_len;
444 int pad, subs, i, j, k, n;
446 if (!ctx->trace_enable)
449 av_assert0(value >= INT_MIN && value <= UINT32_MAX);
451 subs = subscripts ? subscripts[0] : 0;
453 for (i = j = 0; str[i];) {
457 k = snprintf(name + j, sizeof(name) - j, "[%d", subscripts[n]);
458 av_assert0(k > 0 && j + k < sizeof(name));
460 for (++i; str[i] && str[i] != ']'; i++);
461 av_assert0(str[i] == ']');
463 while (str[i] && str[i] != ']')
464 name[j++] = str[i++];
465 av_assert0(str[i] == ']');
468 av_assert0(j + 1 < sizeof(name));
469 name[j++] = str[i++];
472 av_assert0(j + 1 < sizeof(name));
474 av_assert0(n == subs);
476 name_len = strlen(name);
477 bits_len = strlen(bits);
479 if (name_len + bits_len > 60)
484 av_log(ctx->log_ctx, ctx->trace_level, "%-10d %s%*s = %"PRId64"\n",
485 position, name, pad, bits, value);
488 int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, GetBitContext *gbc,
489 int width, const char *name,
490 const int *subscripts, uint32_t *write_to,
491 uint32_t range_min, uint32_t range_max)
496 av_assert0(width > 0 && width <= 32);
498 if (get_bits_left(gbc) < width) {
499 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
500 "%s: bitstream ended.\n", name);
501 return AVERROR_INVALIDDATA;
504 if (ctx->trace_enable)
505 position = get_bits_count(gbc);
507 value = get_bits_long(gbc, width);
509 if (ctx->trace_enable) {
512 for (i = 0; i < width; i++)
513 bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
516 ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
520 if (value < range_min || value > range_max) {
521 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
522 "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
523 name, value, range_min, range_max);
524 return AVERROR_INVALIDDATA;
531 int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc,
532 int width, const char *name,
533 const int *subscripts, uint32_t value,
534 uint32_t range_min, uint32_t range_max)
536 av_assert0(width > 0 && width <= 32);
538 if (value < range_min || value > range_max) {
539 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
540 "%"PRIu32", but must be in [%"PRIu32",%"PRIu32"].\n",
541 name, value, range_min, range_max);
542 return AVERROR_INVALIDDATA;
545 if (put_bits_left(pbc) < width)
546 return AVERROR(ENOSPC);
548 if (ctx->trace_enable) {
551 for (i = 0; i < width; i++)
552 bits[i] = value >> (width - i - 1) & 1 ? '1' : '0';
555 ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
556 name, subscripts, bits, value);
560 put_bits(pbc, width, value);
562 put_bits32(pbc, value);
567 int ff_cbs_read_signed(CodedBitstreamContext *ctx, GetBitContext *gbc,
568 int width, const char *name,
569 const int *subscripts, int32_t *write_to,
570 int32_t range_min, int32_t range_max)
575 av_assert0(width > 0 && width <= 32);
577 if (get_bits_left(gbc) < width) {
578 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid value at "
579 "%s: bitstream ended.\n", name);
580 return AVERROR_INVALIDDATA;
583 if (ctx->trace_enable)
584 position = get_bits_count(gbc);
586 value = get_sbits_long(gbc, width);
588 if (ctx->trace_enable) {
591 for (i = 0; i < width; i++)
592 bits[i] = value & (1U << (width - i - 1)) ? '1' : '0';
595 ff_cbs_trace_syntax_element(ctx, position, name, subscripts,
599 if (value < range_min || value > range_max) {
600 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
601 "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
602 name, value, range_min, range_max);
603 return AVERROR_INVALIDDATA;
610 int ff_cbs_write_signed(CodedBitstreamContext *ctx, PutBitContext *pbc,
611 int width, const char *name,
612 const int *subscripts, int32_t value,
613 int32_t range_min, int32_t range_max)
615 av_assert0(width > 0 && width <= 32);
617 if (value < range_min || value > range_max) {
618 av_log(ctx->log_ctx, AV_LOG_ERROR, "%s out of range: "
619 "%"PRId32", but must be in [%"PRId32",%"PRId32"].\n",
620 name, value, range_min, range_max);
621 return AVERROR_INVALIDDATA;
624 if (put_bits_left(pbc) < width)
625 return AVERROR(ENOSPC);
627 if (ctx->trace_enable) {
630 for (i = 0; i < width; i++)
631 bits[i] = value & (1U << (width - i - 1)) ? '1' : '0';
634 ff_cbs_trace_syntax_element(ctx, put_bits_count(pbc),
635 name, subscripts, bits, value);
639 put_sbits(pbc, width, value);
641 put_bits32(pbc, value);
647 int ff_cbs_alloc_unit_content(CodedBitstreamUnit *unit,
649 void (*free)(void *opaque, uint8_t *data))
651 av_assert0(!unit->content && !unit->content_ref);
653 unit->content = av_mallocz(size);
655 return AVERROR(ENOMEM);
657 unit->content_ref = av_buffer_create(unit->content, size,
659 if (!unit->content_ref) {
660 av_freep(&unit->content);
661 return AVERROR(ENOMEM);
667 int ff_cbs_alloc_unit_data(CodedBitstreamUnit *unit,
670 av_assert0(!unit->data && !unit->data_ref);
672 unit->data_ref = av_buffer_alloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
674 return AVERROR(ENOMEM);
676 unit->data = unit->data_ref->data;
677 unit->data_size = size;
679 memset(unit->data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
684 static int cbs_insert_unit(CodedBitstreamFragment *frag,
687 CodedBitstreamUnit *units;
689 if (frag->nb_units < frag->nb_units_allocated) {
692 if (position < frag->nb_units)
693 memmove(units + position + 1, units + position,
694 (frag->nb_units - position) * sizeof(*units));
696 units = av_malloc_array(frag->nb_units*2 + 1, sizeof(*units));
698 return AVERROR(ENOMEM);
700 frag->nb_units_allocated = 2*frag->nb_units_allocated + 1;
703 memcpy(units, frag->units, position * sizeof(*units));
705 if (position < frag->nb_units)
706 memcpy(units + position + 1, frag->units + position,
707 (frag->nb_units - position) * sizeof(*units));
710 memset(units + position, 0, sizeof(*units));
712 if (units != frag->units) {
713 av_free(frag->units);
722 int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag,
724 CodedBitstreamUnitType type,
726 AVBufferRef *content_buf)
728 CodedBitstreamUnit *unit;
729 AVBufferRef *content_ref;
733 position = frag->nb_units;
734 av_assert0(position >= 0 && position <= frag->nb_units);
737 content_ref = av_buffer_ref(content_buf);
739 return AVERROR(ENOMEM);
744 err = cbs_insert_unit(frag, position);
746 av_buffer_unref(&content_ref);
750 unit = &frag->units[position];
752 unit->content = content;
753 unit->content_ref = content_ref;
758 int ff_cbs_insert_unit_data(CodedBitstreamFragment *frag,
760 CodedBitstreamUnitType type,
761 uint8_t *data, size_t data_size,
762 AVBufferRef *data_buf)
764 CodedBitstreamUnit *unit;
765 AVBufferRef *data_ref;
769 position = frag->nb_units;
770 av_assert0(position >= 0 && position <= frag->nb_units);
773 data_ref = av_buffer_ref(data_buf);
775 data_ref = av_buffer_create(data, data_size, NULL, NULL, 0);
779 return AVERROR(ENOMEM);
782 err = cbs_insert_unit(frag, position);
784 av_buffer_unref(&data_ref);
788 unit = &frag->units[position];
791 unit->data_size = data_size;
792 unit->data_ref = data_ref;
797 void ff_cbs_delete_unit(CodedBitstreamFragment *frag,
800 av_assert0(0 <= position && position < frag->nb_units
801 && "Unit to be deleted not in fragment.");
803 cbs_unit_uninit(&frag->units[position]);
807 if (frag->nb_units > 0)
808 memmove(frag->units + position,
809 frag->units + position + 1,
810 (frag->nb_units - position) * sizeof(*frag->units));
813 static void cbs_default_free_unit_content(void *opaque, uint8_t *data)
815 const CodedBitstreamUnitTypeDescriptor *desc = opaque;
816 if (desc->content_type == CBS_CONTENT_TYPE_INTERNAL_REFS) {
818 for (i = 0; i < desc->nb_ref_offsets; i++) {
819 void **ptr = (void**)(data + desc->ref_offsets[i]);
820 av_buffer_unref((AVBufferRef**)(ptr + 1));
826 static const CodedBitstreamUnitTypeDescriptor
827 *cbs_find_unit_type_desc(CodedBitstreamContext *ctx,
828 CodedBitstreamUnit *unit)
830 const CodedBitstreamUnitTypeDescriptor *desc;
833 if (!ctx->codec->unit_types)
837 desc = &ctx->codec->unit_types[i];
838 if (desc->nb_unit_types == 0)
840 if (desc->nb_unit_types == CBS_UNIT_TYPE_RANGE) {
841 if (unit->type >= desc->unit_type_range_start &&
842 unit->type <= desc->unit_type_range_end)
845 for (j = 0; j < desc->nb_unit_types; j++) {
846 if (desc->unit_types[j] == unit->type)
854 int ff_cbs_alloc_unit_content2(CodedBitstreamContext *ctx,
855 CodedBitstreamUnit *unit)
857 const CodedBitstreamUnitTypeDescriptor *desc;
859 av_assert0(!unit->content && !unit->content_ref);
861 desc = cbs_find_unit_type_desc(ctx, unit);
863 return AVERROR(ENOSYS);
865 unit->content = av_mallocz(desc->content_size);
867 return AVERROR(ENOMEM);
870 av_buffer_create(unit->content, desc->content_size,
871 desc->content_free ? desc->content_free
872 : cbs_default_free_unit_content,
874 if (!unit->content_ref) {
875 av_freep(&unit->content);
876 return AVERROR(ENOMEM);
882 static int cbs_clone_unit_content(AVBufferRef **clone_ref,
883 CodedBitstreamUnit *unit,
884 const CodedBitstreamUnitTypeDescriptor *desc)
887 uint8_t **src_ptr, **copy_ptr;
888 AVBufferRef **src_buf, **copy_buf;
891 av_assert0(unit->content);
894 copy = av_memdup(src, desc->content_size);
896 return AVERROR(ENOMEM);
898 for (i = 0; i < desc->nb_ref_offsets; i++) {
899 src_ptr = (uint8_t**)(src + desc->ref_offsets[i]);
900 src_buf = (AVBufferRef**)(src_ptr + 1);
901 copy_ptr = (uint8_t**)(copy + desc->ref_offsets[i]);
902 copy_buf = (AVBufferRef**)(copy_ptr + 1);
905 av_assert0(!*src_buf);
909 // We can't handle a non-refcounted pointer here - we don't
910 // have enough information to handle whatever structure lies
911 // at the other end of it.
912 err = AVERROR(EINVAL);
916 // src_ptr is required to point somewhere inside src_buf. If it
917 // doesn't, there is a bug somewhere.
918 av_assert0(*src_ptr >= (*src_buf)->data &&
919 *src_ptr < (*src_buf)->data + (*src_buf)->size);
921 *copy_buf = av_buffer_ref(*src_buf);
923 err = AVERROR(ENOMEM);
926 *copy_ptr = (*copy_buf)->data + (*src_ptr - (*src_buf)->data);
929 *clone_ref = av_buffer_create(copy, desc->content_size,
930 desc->content_free ? desc->content_free :
931 cbs_default_free_unit_content,
934 err = AVERROR(ENOMEM);
941 for (--i; i >= 0; i--)
942 av_buffer_unref((AVBufferRef**)(copy + desc->ref_offsets[i]));
948 int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx,
949 CodedBitstreamUnit *unit)
951 const CodedBitstreamUnitTypeDescriptor *desc;
955 av_assert0(unit->content);
956 if (unit->content_ref) {
957 // Already refcounted, nothing to do.
961 desc = cbs_find_unit_type_desc(ctx, unit);
963 return AVERROR(ENOSYS);
965 switch (desc->content_type) {
966 case CBS_CONTENT_TYPE_POD:
967 ref = av_buffer_alloc(desc->content_size);
969 return AVERROR(ENOMEM);
970 memcpy(ref->data, unit->content, desc->content_size);
974 case CBS_CONTENT_TYPE_INTERNAL_REFS:
975 err = cbs_clone_unit_content(&ref, unit, desc);
978 case CBS_CONTENT_TYPE_COMPLEX:
979 if (!desc->content_clone)
980 return AVERROR_PATCHWELCOME;
981 err = desc->content_clone(&ref, unit);
985 av_assert0(0 && "Invalid content type.");
991 unit->content_ref = ref;
992 unit->content = ref->data;
996 int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx,
997 CodedBitstreamUnit *unit)
999 const CodedBitstreamUnitTypeDescriptor *desc;
1003 // This can only be applied to refcounted units.
1004 err = ff_cbs_make_unit_refcounted(ctx, unit);
1007 av_assert0(unit->content && unit->content_ref);
1009 if (av_buffer_is_writable(unit->content_ref))
1012 desc = cbs_find_unit_type_desc(ctx, unit);
1014 return AVERROR(ENOSYS);
1016 switch (desc->content_type) {
1017 case CBS_CONTENT_TYPE_POD:
1018 err = av_buffer_make_writable(&unit->content_ref);
1021 case CBS_CONTENT_TYPE_INTERNAL_REFS:
1022 err = cbs_clone_unit_content(&ref, unit, desc);
1025 case CBS_CONTENT_TYPE_COMPLEX:
1026 if (!desc->content_clone)
1027 return AVERROR_PATCHWELCOME;
1028 err = desc->content_clone(&ref, unit);
1032 av_assert0(0 && "Invalid content type.");
1037 if (desc->content_type != CBS_CONTENT_TYPE_POD) {
1038 av_buffer_unref(&unit->content_ref);
1039 unit->content_ref = ref;
1041 unit->content = unit->content_ref->data;