(packetData: Uint8Array)
| 949 | |
| 950 | /** Converts an AVC packet in Annex B format to length-prefixed format. */ |
| 951 | export const transformAnnexBToLengthPrefixed = (packetData: Uint8Array) => { |
| 952 | const NAL_UNIT_LENGTH_SIZE = 4; |
| 953 | |
| 954 | const nalUnits = findNalUnitsInAnnexB(packetData); |
| 955 | |
| 956 | if (nalUnits.length === 0) { |
| 957 | // If no NAL units were found, it's not valid Annex B data |
| 958 | return null; |
| 959 | } |
| 960 | |
| 961 | let totalSize = 0; |
| 962 | for (const nalUnit of nalUnits) { |
| 963 | totalSize += NAL_UNIT_LENGTH_SIZE + nalUnit.byteLength; |
| 964 | } |
| 965 | |
| 966 | const avccData = new Uint8Array(totalSize); |
| 967 | const dataView = new DataView(avccData.buffer); |
| 968 | let offset = 0; |
| 969 | |
| 970 | // Write each NAL unit with its length prefix |
| 971 | for (const nalUnit of nalUnits) { |
| 972 | const length = nalUnit.byteLength; |
| 973 | |
| 974 | dataView.setUint32(offset, length, false); |
| 975 | offset += 4; |
| 976 | |
| 977 | avccData.set(nalUnit, offset); |
| 978 | offset += nalUnit.byteLength; |
| 979 | } |
| 980 | |
| 981 | return avccData; |
| 982 | }; |
| 983 | |
| 984 | // https://en.wikipedia.org/wiki/VP9 |
| 985 | export const VP9_LEVEL_TABLE = [ |
no test coverage detected