private RtpPacket parseRtpPacket(byte[] data){
  RtpPacket packet=new RtpPacket();
  try {
    packet.length=data.length;
    packet.receivedAt=System.currentTimeMillis();
    packet.extension=(data[0] & 0x10) > 0;
    if ((byte)((data[1] & 0xff) & 0x80) == (byte)0x80) {
      packet.marker=1;
    }
 else {
      packet.marker=0;
    }
    packet.payloadType=(byte)((data[1] & 0xff) & 0x7f);
    packet.seqnum=(char)((data[2] << 8) | (data[3] & 0xff));
    packet.timestamp=(((data[4] & 0xff) << 24) | ((data[5] & 0xff) << 16) | ((data[6] & 0xff) << 8)| (data[7] & 0xff));
    packet.ssrc=(((data[8] & 0xff) << 24) | ((data[9] & 0xff) << 16) | ((data[10] & 0xff) << 8)| (data[11] & 0xff));
    if (packet.extension) {
      int dataId=11;
      int extensionHeaderId=((data[++dataId] & 0xff) << 8) | (data[++dataId] & 0xff);
      int length=((data[++dataId] & 0xff) << 8) | (data[++dataId] & 0xff);
      if (extensionHeaderId == RtpExtensionHeader.RTP_EXTENSION_HEADER_ID) {
        extractExtensionHeader(data,length,dataId,packet);
      }
      packet.payloadoffset=16 + length * 4;
    }
 else {
      packet.payloadoffset=12;
    }
    packet.payloadlength=packet.length - packet.payloadoffset;
    packet.data=new byte[packet.payloadlength];
    System.arraycopy(data,packet.payloadoffset,packet.data,0,packet.payloadlength);
  }
 catch (  Exception e) {
    return null;
  }
  return packet;
}

private RtpPacket parseRtpPacket ( byte [ ] data ) { RtpPacket packet = new RtpPacket ( ) ; try { packet . length = data . length ; packet . receivedAt = System . currentTimeMillis ( ) ; packet . extension = ( data [ 0 ] & 0x10 ) > 0 ; if ( ( byte ) ( ( data [ 1 ] & 0xff ) & 0x80 ) == ( byte ) 0x80 ) { packet . marker = 1 ; } else { packet . marker = 0 ; } packet . payloadType = ( byte ) ( ( data [ 1 ] & 0xff ) & 0x7f ) ; packet . seqnum = ( char ) ( ( data [ 2 ] << 8 ) | ( data [ 3 ] & 0xff ) ) ; packet . timestamp = ( ( ( data [ 4 ] & 0xff ) << 24 ) | ( ( data [ 5 ] & 0xff ) << 16 ) | ( ( data [ 6 ] & 0xff ) << 8 ) | ( data [ 7 ] & 0xff ) ) ; packet . ssrc = ( ( ( data [ 8 ] & 0xff ) << 24 ) | ( ( data [ 9 ] & 0xff ) << 16 ) | ( ( data [ 10 ] & 0xff ) << 8 ) | ( data [ 11 ] & 0xff ) ) ; if ( packet . extension ) { int dataId = 11 ; int extensionHeaderId = ( ( data [ ++ dataId ] & 0xff ) << 8 ) | ( data [ ++ dataId ] & 0xff ) ; int length = ( ( data [ ++ dataId ] & 0xff ) << 8 ) | ( data [ ++ dataId ] & 0xff ) ; if ( extensionHeaderId == RtpExtensionHeader . RTP_EXTENSION_HEADER_ID ) { extractExtensionHeader ( data , length , dataId , packet ) ; } packet . payloadoffset = 16 + length * 4 ; } else { packet . payloadoffset = 12 ; } packet . payloadlength = packet . length - packet . payloadoffset ; packet . data = new byte [ packet . payloadlength ] ; System . arraycopy ( data , packet . payloadoffset , packet . data , 0 , packet . payloadlength ) ; } catch ( Exception e ) { return null ; } return packet ; }
parse the rtp packet
