MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / cbs_clone_noncomplex_unit_content

Function cbs_clone_noncomplex_unit_content

libavcodec/cbs.c:964–1016  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

962}
963
964static int cbs_clone_noncomplex_unit_content(void **clonep,
965 const CodedBitstreamUnit *unit,
966 CodedBitstreamUnitTypeDescriptor *desc)
967{
968 const uint8_t *src;
969 uint8_t *copy;
970 int err, i;
971
972 av_assert0(unit->content);
973 src = unit->content;
974
975 copy = cbs_alloc_content(desc);
976 if (!copy)
977 return AVERROR(ENOMEM);
978 memcpy(copy, src, desc->content_size);
979 for (int i = 0; i < desc->type.ref.nb_offsets; i++) {
980 void **ptr = (void**)(copy + desc->type.ref.offsets[i]);
981 /* Zero all the AVBufferRefs as they are owned by src. */
982 *(ptr + 1) = NULL;
983 }
984
985 for (i = 0; i < desc->type.ref.nb_offsets; i++) {
986 const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->type.ref.offsets[i]);
987 const AVBufferRef *src_buf = *(AVBufferRef**)(src_ptr + 1);
988 uint8_t **copy_ptr = (uint8_t**)(copy + desc->type.ref.offsets[i]);
989 AVBufferRef **copy_buf = (AVBufferRef**)(copy_ptr + 1);
990
991 if (!*src_ptr) {
992 av_assert0(!src_buf);
993 continue;
994 }
995 if (!src_buf) {
996 // We can't handle a non-refcounted pointer here - we don't
997 // have enough information to handle whatever structure lies
998 // at the other end of it.
999 err = AVERROR(EINVAL);
1000 goto fail;
1001 }
1002
1003 *copy_buf = av_buffer_ref(src_buf);
1004 if (!*copy_buf) {
1005 err = AVERROR(ENOMEM);
1006 goto fail;
1007 }
1008 }
1009 *clonep = copy;
1010
1011 return 0;
1012
1013fail:
1014 av_refstruct_unref(&copy);
1015 return err;
1016}
1017
1018/*
1019 * On success, unit->content and unit->content_ref are updated with

Callers 1

cbs_clone_unit_contentFunction · 0.85

Calls 3

cbs_alloc_contentFunction · 0.85
av_buffer_refFunction · 0.85
av_refstruct_unrefFunction · 0.85

Tested by

no test coverage detected