import { payload , payloadType , timestamp } from '../../utils/protocols/rtp' ; import { ElementaryMessage , MessageType , RtpMessage } from '../message' ; export function parse ( rtp , hasHeader , callback ) { const buffer = payload ( rtp . data ) ; let headerLength = 0 ; if ( hasHeader ) { const auHeaderLengthInBits = buffer . readUInt16BE ( 0 ) ; headerLength = 2 + ( auHeaderLengthInBits + ( auHeaderLengthInBits % 8 ) ) / 8 ; } const packet = { type : MessageType . ELEMENTARY , data : buffer . slice ( headerLength ) , payloadType : payloadType ( rtp . data ) , timestamp : timestamp ( rtp . data ) , ntpTimestamp : rtp . ntpTimestamp , } ; callback ( packet ) ; }