//Add a buffer containing an incoming RTP packet to the dejitter pool OsStatus MprDejitter::pushPacket(MpBufPtr pRtp) { int index; MpBuf_touch(pRtp); mRtpLock.acquire(); index = getSeqNum(pRtp) % MAX_RTP_PACKETS; if (NULL != mpPackets[index]) { mNumDiscarded++; #ifdef MP_STREAM_DEBUG /* [ */ if (mNumDiscarded < 40) { osPrintf("Dej: discard#%d Seq: %d -> %d at 0x%X\n", mNumDiscarded, getSeqNum(mpPackets[index]), getSeqNum(pRtp), *pOsTC); } #endif /* MP_STREAM_DEBUG ] */ MpBuf_delRef(mpPackets[index]); mpPackets[index] = NULL; mNumPackets--; } mpPackets[index] = pRtp; mNumPackets++; mRtpLock.release(); return OS_SUCCESS; }
// jbodah void printPacketContents( packet *newPacket ) { char dstString[30] ; bufFlush( dstString ) ; getVerboseFrameKind(newPacket, dstString) ; printf( "\tseqNum\t\t'%c' %d \n\tframeKind\t%s \n\tpayload\t\t%s \n\tCRC\t\t'%c' %d\n", getSeqNum(newPacket), (int)getSeqNum(newPacket), dstString, getPayload(newPacket), getCRC(newPacket), (int)getCRC(newPacket) ) ; }
Reliapack::Reliapack(char *buf, int length, struct sockaddr_in paddr) { int totalLen = getTotalLength(buf); //printf("received new packet of length %d\n", totalLen); //if this is already a complete packet /* if(totalLen == length - HEADER_LENGTH) { packets = new char * [1]; lengths = new int[1]; *packets = buf; *lengths = totalLength; numPackets = 1; }else {*/ numPackets = (totalLen + MAX_DATA_LENGTH - 1) / MAX_DATA_LENGTH; numPackets = numPackets ? numPackets : 1; packets = new char * [numPackets]; lengths = new int[numPackets]; for(int i=0; i<numPackets; i++) { packets[i] = NULL; lengths[i] = 0; } addPacket(buf, length); //} sequenceNum = getSeqNum(buf); memcpy(&address, &paddr, sizeof(struct sockaddr_in)); ftime(&lastEventTime); //reset the last event time }
void OutgoingRTPPkt::protect(uint32 ssrc, CryptoContext* pcc) { /* Encrypt the packet */ uint64 index = ((uint64)pcc->getRoc() << 16) | (uint64)getSeqNum(); pcc->srtpEncrypt(this, index, ssrc); // NO MKI support yet - here we assume MKI is zero. To build in MKI // take MKI length into account when storing the authentication tag. /* Compute MAC */ pcc->srtpAuthenticate(this, pcc->getRoc(), const_cast<uint8*>(getRawPacket()+srtpDataOffset) ); /* Update the ROC if necessary */ if (getSeqNum() == 0xFFFF ) { pcc->setRoc(pcc->getRoc() + 1); } }
uint16_t Packet::getExpectedAckNumber(int maxSeqNum) { uint16_t seqNum = getSeqNum((struct TCPHeader *)&m_header); uint16_t payloadSize = m_size - sizeof(struct TCPHeader); uint16_t expectedAckNum = seqNum + payloadSize; if (expectedAckNum > maxSeqNum) { expectedAckNum -= maxSeqNum; } return expectedAckNum; }
char * Reliapack::getAckPacket(char *packet) { char * buf = new char[HEADER_LENGTH]; //copy the sequence number and retry number into new packet. for(int i=0; i<4; i++) { //buf[i+4] = packet[i]; buf[i] = 0; } for(int i=8; i<HEADER_LENGTH; i++) buf[i] = packet[i]; setResponseSeqNum(buf, getSeqNum(packet)); setResponseRetryNum(buf, getRetryNum(packet)); return buf; }
MpBufPtr MprDejitter::pullPacket(void) { MpBufPtr found = NULL; MpBufPtr cur; int curSeq; int first = -1; int firstSeq = 0; // dummy value int i; mRtpLock.acquire(); // Find smallest seq number for (i=0; i<MAX_RTP_PACKETS; i++) { cur = mpPackets[i]; if (cur != NULL) { curSeq = getSeqNum(mpPackets[i]); if (first == -1 || curSeq < firstSeq) { first = i; firstSeq = curSeq; } } } if (-1 != first) { found = mpPackets[first]; mpPackets[first] = NULL; mNumPackets--; MpBuf_touch(found); } mRtpLock.release(); return found; }
uint16_t Packet::getSeqNumber() { return getSeqNum((struct TCPHeader *)&m_header); }