import { getBit , paddingByte } from "../../../common/src" ; import { RtpHeader } from "../rtp/rtp" ; import { DePacketizerBase } from "./base" ; export class Vp8RtpPayload implements DePacketizerBase { xBit ! : number ; nBit ! : number ; sBit ! : number ; pid ! : number ; iBit ? : number ; lBit ? : number ; tBit ? : number ; kBit ? : number ; mBit ? : number ; pictureId ? : number ; payload ! : Buffer ; size0 ? : number ; hBit ? : number ; ver ? : number ; pBit ? : number ; size1 ? : number ; size2 ? : number ; static deSerialize ( buf ) { const p = new Vp8RtpPayload ( ) ; let offset = 0 ; p . xBit = getBit ( buf [ offset ] , 0 ) ; p . nBit = getBit ( buf [ offset ] , 2 ) ; p . sBit = getBit ( buf [ offset ] , 3 ) ; p . pid = getBit ( buf [ offset ] , 5 , 3 ) ; offset ++ ; if ( p . xBit ) { p . iBit = getBit ( buf [ offset ] , 0 ) ; p . lBit = getBit ( buf [ offset ] , 1 ) ; p . tBit = getBit ( buf [ offset ] , 2 ) ; p . kBit = getBit ( buf [ offset ] , 3 ) ; offset ++ ; } if ( p . iBit ) { p . mBit = getBit ( buf [ offset ] , 0 ) ; if ( p . mBit ) { const _7 = paddingByte ( getBit ( buf [ offset ] , 1 , 7 ) ) ; const _8 = paddingByte ( buf [ offset + 1 ] ) ; p . pictureId = parseInt ( _7 + _8 , 2 ) ; offset += 2 ; } else { p . pictureId = getBit ( buf [ offset ] , 1 , 7 ) ; offset ++ ; } } if ( p . lBit ) { offset ++ ; } if ( p . lBit || p . kBit ) { if ( p . tBit ) { } if ( p . kBit ) { } offset ++ ; } p . payload = buf . slice ( offset ) ; if ( p . sBit === 1 && p . pid === 0 ) { p . size0 = getBit ( buf [ offset ] , 0 , 3 ) ; p . hBit = getBit ( buf [ offset ] , 3 ) ; p . ver = getBit ( buf [ offset ] , 4 , 3 ) ; p . pBit = getBit ( buf [ offset ] , 7 ) ; offset ++ ; } p . size1 = buf [ offset ] ; offset ++ ; p . size2 = buf [ offset ] ; offset ++ ; return p ; } static isDetectedFinalPacketInSequence ( header ) { return header . marker ; } get isKeyframe ( ) { return this . pBit === 0 ; } get isPartitionHead ( ) { return this . sBit === 1 ; } }