public static RTPPacket BuildPacket(byte[] bRecvData, int nOffset, int nLength) { RTPPacket packet = new RTPPacket(); if (nLength < 12) return null; byte[] bRTPData = new byte[nLength]; Array.Copy(bRecvData, nOffset, bRTPData, 0, nLength); packet.VersionPaddingHeaderCRSCCountByte = bRTPData[0]; packet.MarkerPayloadByte = bRTPData[1]; packet.SequenceNumber = (ushort)((bRTPData[2] << 8) | bRTPData[3]); packet.TimeStamp = (uint)((bRTPData[4] << 24) | (bRTPData[5] << 16) | (bRTPData[6] << 8) | (bRTPData[7])); packet.SSRC = (uint)((bRTPData[8] << 24) | (bRTPData[9] << 16) | (bRTPData[10] << 8) | (bRTPData[11])); int nByteAt = 12; for (int i = 0; i < packet.CRSCCount; i++) { if (bRTPData.Length < (nByteAt + 4)) return null; packet.CSRCList.Add((uint)((bRTPData[nByteAt++] << 24) | (bRTPData[nByteAt++] << 16) | (bRTPData[nByteAt++] << 8) | (bRTPData[nByteAt++]))); } int nExtensionLen = 0; /// Read in extension data, if there if (packet.Extension == true) { /// ignore this for now, just copy to the data //nExtensionLen = pRTPHeader. } int nDataStartAt = 12 + 4 * packet.CRSCCount + nExtensionLen; int nBytesLeft = bRTPData.Length - nDataStartAt; /// Finally, let's find out what is next and add that as data if (nBytesLeft > 0) { packet.PayloadData = new byte[nBytesLeft]; Array.Copy(bRTPData, nDataStartAt, packet.PayloadData, 0, nBytesLeft); } return packet; }