MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / avifParseSampleDescriptionBox

Function avifParseSampleDescriptionBox

src/read.c:3717–3766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3715}
3716
3717static avifResult avifParseSampleDescriptionBox(avifSampleTable * sampleTable,
3718 uint64_t rawOffset,
3719 const uint8_t * raw,
3720 size_t rawLen,
3721 avifDiagnostics * diag)
3722{
3723 BEGIN_STREAM(s, raw, rawLen, diag, "Box[stsd]");
3724
3725 uint8_t version;
3726 AVIF_CHECKERR(avifROStreamReadVersionAndFlags(&s, &version, NULL), AVIF_RESULT_BMFF_PARSE_FAILED);
3727
3728 // Section 8.5.2.3 of ISO/IEC 14496-12:
3729 // version is set to zero. A version number of 1 shall be treated as a version of 0.
3730 if (version != 0 && version != 1) {
3731 avifDiagnosticsPrintf(diag, "Box[stsd]: Expecting box version 0 or 1, got version %u", version);
3732 return AVIF_RESULT_BMFF_PARSE_FAILED;
3733 }
3734
3735 uint32_t entryCount;
3736 AVIF_CHECKERR(avifROStreamReadU32(&s, &entryCount), AVIF_RESULT_BMFF_PARSE_FAILED); // unsigned int(32) entry_count;
3737
3738 for (uint32_t i = 0; i < entryCount; ++i) {
3739 avifBoxHeader sampleEntryHeader;
3740 AVIF_CHECKERR(avifROStreamReadBoxHeader(&s, &sampleEntryHeader), AVIF_RESULT_BMFF_PARSE_FAILED);
3741
3742 avifSampleDescription * description = (avifSampleDescription *)avifArrayPush(&sampleTable->sampleDescriptions);
3743 AVIF_CHECKERR(description != NULL, AVIF_RESULT_OUT_OF_MEMORY);
3744 if (!avifArrayCreate(&description->properties, sizeof(avifProperty), 16)) {
3745 avifArrayPop(&sampleTable->sampleDescriptions);
3746 return AVIF_RESULT_OUT_OF_MEMORY;
3747 }
3748 memcpy(description->format, sampleEntryHeader.type, sizeof(description->format));
3749 const size_t sampleEntryBytes = sampleEntryHeader.size;
3750 if (avifGetCodecType(description->format) != AVIF_CODEC_TYPE_UNKNOWN) {
3751 if (sampleEntryBytes < VISUALSAMPLEENTRY_SIZE) {
3752 avifDiagnosticsPrintf(diag, "Not enough bytes to parse VisualSampleEntry");
3753 return AVIF_RESULT_BMFF_PARSE_FAILED;
3754 }
3755 AVIF_CHECKRES(avifParseItemPropertyContainerBox(&description->properties,
3756 rawOffset + avifROStreamOffset(&s) + VISUALSAMPLEENTRY_SIZE,
3757 avifROStreamCurrent(&s) + VISUALSAMPLEENTRY_SIZE,
3758 sampleEntryBytes - VISUALSAMPLEENTRY_SIZE,
3759 /*isTrack=*/AVIF_TRUE,
3760 diag));
3761 }
3762
3763 AVIF_CHECKERR(avifROStreamSkip(&s, sampleEntryBytes), AVIF_RESULT_BMFF_PARSE_FAILED);
3764 }
3765 return AVIF_RESULT_OK;
3766}
3767
3768static avifResult avifParseSampleTableBox(avifTrack * track, uint64_t rawOffset, const uint8_t * raw, size_t rawLen, avifDiagnostics * diag)
3769{

Callers 1

avifParseSampleTableBoxFunction · 0.85

Calls 12

avifDiagnosticsPrintfFunction · 0.85
avifROStreamReadU32Function · 0.85
avifArrayPushFunction · 0.85
avifArrayCreateFunction · 0.85
avifArrayPopFunction · 0.85
avifGetCodecTypeFunction · 0.85
avifROStreamOffsetFunction · 0.85
avifROStreamCurrentFunction · 0.85
avifROStreamSkipFunction · 0.85

Tested by

no test coverage detected