( packet: Uint8Array, )
| 1011 | }; |
| 1012 | |
| 1013 | export const extractVp9CodecInfoFromPacket = ( |
| 1014 | packet: Uint8Array, |
| 1015 | ): Vp9CodecInfo | null => { |
| 1016 | // eslint-disable-next-line @stylistic/max-len |
| 1017 | // https://storage.googleapis.com/downloads.webmproject.org/docs/vp9/vp9-bitstream-specification-v0.7-20170222-draft.pdf |
| 1018 | // http://downloads.webmproject.org/docs/vp9/vp9-bitstream_superframe-and-uncompressed-header_v1.0.pdf |
| 1019 | |
| 1020 | const bitstream = new Bitstream(packet); |
| 1021 | |
| 1022 | // Frame marker (0b10) |
| 1023 | const frameMarker = bitstream.readBits(2); |
| 1024 | if (frameMarker !== 2) { |
| 1025 | return null; |
| 1026 | } |
| 1027 | |
| 1028 | // Profile |
| 1029 | const profileLowBit = bitstream.readBits(1); |
| 1030 | const profileHighBit = bitstream.readBits(1); |
| 1031 | const profile = (profileHighBit << 1) + profileLowBit; |
| 1032 | |
| 1033 | // Skip reserved bit for profile 3 |
| 1034 | if (profile === 3) { |
| 1035 | bitstream.skipBits(1); |
| 1036 | } |
| 1037 | |
| 1038 | // show_existing_frame |
| 1039 | const showExistingFrame = bitstream.readBits(1); |
| 1040 | |
| 1041 | if (showExistingFrame === 1) { |
| 1042 | return null; |
| 1043 | } |
| 1044 | |
| 1045 | // frame_type (0 = key frame) |
| 1046 | const frameType = bitstream.readBits(1); |
| 1047 | |
| 1048 | if (frameType !== 0) { |
| 1049 | return null; |
| 1050 | } |
| 1051 | |
| 1052 | // Skip show_frame and error_resilient_mode |
| 1053 | bitstream.skipBits(2); |
| 1054 | |
| 1055 | // Sync code (0x498342) |
| 1056 | const syncCode = bitstream.readBits(24); |
| 1057 | if (syncCode !== 0x498342) { |
| 1058 | return null; |
| 1059 | } |
| 1060 | |
| 1061 | // Color config |
| 1062 | let bitDepth = 8; |
| 1063 | if (profile >= 2) { |
| 1064 | const tenOrTwelveBit = bitstream.readBits(1); |
| 1065 | bitDepth = tenOrTwelveBit ? 12 : 10; |
| 1066 | } |
| 1067 | |
| 1068 | // Color space |
| 1069 | const colorSpace = bitstream.readBits(3); |
| 1070 |
no test coverage detected