MCPcopy Create free account
hub / github.com/Vanilagy/webcodecs-polyfill / serializeHevcDecoderConfigurationRecord

Function serializeHevcDecoderConfigurationRecord

src/codec_data.ts:884–948  ·  view source on GitHub ↗
(record: HevcDecoderConfigurationRecord)

Source from the content-addressed store, hash-verified

882
883/** Serializes an HevcDecoderConfigurationRecord into the format specified in Section 8.3.3.1 of ISO 14496-15. */
884export const serializeHevcDecoderConfigurationRecord = (record: HevcDecoderConfigurationRecord) => {
885 const bytes: number[] = [];
886
887 bytes.push(record.configurationVersion);
888
889 bytes.push(
890 ((record.generalProfileSpace & 0x3) << 6)
891 | ((record.generalTierFlag & 0x1) << 5)
892 | (record.generalProfileIdc & 0x1F),
893 );
894
895 bytes.push((record.generalProfileCompatibilityFlags >>> 24) & 0xFF);
896 bytes.push((record.generalProfileCompatibilityFlags >>> 16) & 0xFF);
897 bytes.push((record.generalProfileCompatibilityFlags >>> 8) & 0xFF);
898 bytes.push(record.generalProfileCompatibilityFlags & 0xFF);
899
900 bytes.push(...record.generalConstraintIndicatorFlags);
901
902 bytes.push(record.generalLevelIdc & 0xFF);
903
904 bytes.push(0xF0 | ((record.minSpatialSegmentationIdc >> 8) & 0x0F)); // Reserved + high nibble
905 bytes.push(record.minSpatialSegmentationIdc & 0xFF); // Low byte
906
907 bytes.push(0xFC | (record.parallelismType & 0x03));
908
909 bytes.push(0xFC | (record.chromaFormatIdc & 0x03));
910
911 bytes.push(0xF8 | (record.bitDepthLumaMinus8 & 0x07));
912
913 bytes.push(0xF8 | (record.bitDepthChromaMinus8 & 0x07));
914
915 bytes.push((record.avgFrameRate >> 8) & 0xFF); // High byte
916 bytes.push(record.avgFrameRate & 0xFF); // Low byte
917
918 bytes.push(
919 ((record.constantFrameRate & 0x03) << 6)
920 | ((record.numTemporalLayers & 0x07) << 3)
921 | ((record.temporalIdNested & 0x01) << 2)
922 | (record.lengthSizeMinusOne & 0x03),
923 );
924
925 bytes.push(record.arrays.length & 0xFF);
926
927 for (const arr of record.arrays) {
928 bytes.push(
929 ((arr.arrayCompleteness & 0x01) << 7)
930 | (0 << 6)
931 | (arr.nalUnitType & 0x3F),
932 );
933
934 bytes.push((arr.nalUnits.length >> 8) & 0xFF); // High byte
935 bytes.push(arr.nalUnits.length & 0xFF); // Low byte
936
937 for (const nal of arr.nalUnits) {
938 bytes.push((nal.length >> 8) & 0xFF); // High byte
939 bytes.push(nal.length & 0xFF); // Low byte
940
941 for (let i = 0; i < nal.length; i++) {

Callers 1

outputChunkMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected