import { payloadType } from '../../utils/protocols/rtp' ; import { Tube } from '../component' ; import { Message , MessageType } from '../message' ; import { parse } from './parser' ; import { createTransform } from '../messageStreams' ; export class AACDepay extends Tube { constructor ( ) { let AACPayloadType ; let hasHeader ; const incoming = createTransform ( function ( msg , encoding , callback ) { if ( msg . type === MessageType . SDP ) { let validMedia ; for ( const media of msg . sdp . media ) { if ( media . type === 'audio' && media . fmtp && media . fmtp . parameters && media . fmtp . parameters . mode === 'AAC-hbr' ) { validMedia = media ; } } if ( validMedia && validMedia . rtpmap !== undefined ) { AACPayloadType = Number ( validMedia . rtpmap . payloadType ) ; const parameters = validMedia . fmtp . parameters ; const sizeLength = Number ( parameters . sizelength ) || 0 ; const indexLength = Number ( parameters . indexlength ) || 0 ; const indexDeltaLength = Number ( parameters . indexdeltalength ) || 0 ; const CTSDeltaLength = Number ( parameters . ctsdeltalength ) || 0 ; const DTSDeltaLength = Number ( parameters . dtsdeltalength ) || 0 ; const RandomAccessIndication = Number ( parameters . randomaccessindication ) || 0 ; const StreamStateIndication = Number ( parameters . streamstateindication ) || 0 ; const AuxiliaryDataSizeLength = Number ( parameters . auxiliarydatasizelength ) || 0 ; hasHeader = sizeLength + Math . max ( indexLength , indexDeltaLength ) + CTSDeltaLength + DTSDeltaLength + RandomAccessIndication + StreamStateIndication + AuxiliaryDataSizeLength > 0 ; } callback ( undefined , msg ) ; } else if ( msg . type === MessageType . RTP && payloadType ( msg . data ) === AACPayloadType ) { parse ( msg , hasHeader , this . push . bind ( this ) ) ; callback ( ) ; } else { callback ( undefined , msg ) ; } } ) ; super ( incoming ) ; } }