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

Function avifParseCodecConfiguration

src/read.c:2651–2699  ·  view source on GitHub ↗

Implementation of section 2.3.3 of AV1 Codec ISO Media File Format Binding specification v1.2.0. See https://aomediacodec.github.io/av1-isobmff/v1.2.0.html#av1codecconfigurationbox-syntax.

Source from the content-addressed store, hash-verified

2649// Implementation of section 2.3.3 of AV1 Codec ISO Media File Format Binding specification v1.2.0.
2650// See https://aomediacodec.github.io/av1-isobmff/v1.2.0.html#av1codecconfigurationbox-syntax.
2651static avifBool avifParseCodecConfiguration(avifROStream * s, avifCodecConfigurationBox * config, const char * configPropName, avifDiagnostics * diag)
2652{
2653 const size_t av1COffset = avifROStreamOffset(s);
2654
2655 uint32_t marker, version;
2656 AVIF_CHECK(avifROStreamReadBitsU32(s, &marker, /*bitCount=*/1)); // unsigned int (1) marker = 1;
2657 if (!marker) {
2658 avifDiagnosticsPrintf(diag, "%.4s contains illegal marker: [%u]", configPropName, marker);
2659 return AVIF_FALSE;
2660 }
2661 AVIF_CHECK(avifROStreamReadBitsU32(s, &version, /*bitCount=*/7)); // unsigned int (7) version = 1;
2662 if (version != 1) {
2663 avifDiagnosticsPrintf(diag, "%.4s contains illegal version: [%u]", configPropName, version);
2664 return AVIF_FALSE;
2665 }
2666
2667 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->seqProfile, /*bitCount=*/3)); // unsigned int (3) seq_profile;
2668 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->seqLevelIdx0, /*bitCount=*/5)); // unsigned int (5) seq_level_idx_0;
2669 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->seqTier0, /*bitCount=*/1)); // unsigned int (1) seq_tier_0;
2670 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->highBitdepth, /*bitCount=*/1)); // unsigned int (1) high_bitdepth;
2671 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->twelveBit, /*bitCount=*/1)); // unsigned int (1) twelve_bit;
2672 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->monochrome, /*bitCount=*/1)); // unsigned int (1) monochrome;
2673 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->chromaSubsamplingX, /*bitCount=*/1)); // unsigned int (1) chroma_subsampling_x;
2674 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->chromaSubsamplingY, /*bitCount=*/1)); // unsigned int (1) chroma_subsampling_y;
2675 AVIF_CHECK(avifROStreamReadBitsU8(s, &config->chromaSamplePosition, /*bitCount=*/2)); // unsigned int (2) chroma_sample_position;
2676
2677 // unsigned int (3) reserved = 0;
2678 // unsigned int (1) initial_presentation_delay_present;
2679 // if (initial_presentation_delay_present) {
2680 // unsigned int (4) initial_presentation_delay_minus_one;
2681 // } else {
2682 // unsigned int (4) reserved = 0;
2683 // }
2684 AVIF_CHECK(avifROStreamSkip(s, /*byteCount=*/1));
2685
2686 // According to section 2.2.1 of AV1 Image File Format specification v1.1.0:
2687 // - Sequence Header OBUs should not be present in the AV1CodecConfigurationBox.
2688 // - If a Sequence Header OBU is present in the AV1CodecConfigurationBox,
2689 // it shall match the Sequence Header OBU in the AV1 Image Item Data.
2690 // - Metadata OBUs, if present, shall match the values given in other item properties,
2691 // such as the PixelInformationProperty or ColourInformationBox.
2692 // See https://aomediacodec.github.io/av1-avif/v1.1.0.html#av1-configuration-item-property.
2693 // For simplicity, the constraints above are not enforced.
2694 // The following is skipped by avifParseItemPropertyContainerBox().
2695 // unsigned int (8) configOBUs[];
2696
2697 AVIF_CHECK(avifROStreamOffset(s) - av1COffset == 4); // Make sure avifParseCodecConfiguration() reads exactly 4 bytes.
2698 return AVIF_TRUE;
2699}
2700
2701static avifBool avifParseCodecConfigurationBoxProperty(avifProperty * prop,
2702 const uint8_t * raw,

Calls 5

avifROStreamOffsetFunction · 0.85
avifROStreamReadBitsU32Function · 0.85
avifDiagnosticsPrintfFunction · 0.85
avifROStreamReadBitsU8Function · 0.85
avifROStreamSkipFunction · 0.85

Tested by

no test coverage detected