bool RtpSource::RemoveInternalRtpPacket(RtpPacket *rtpPacket) { bool result = false; if (rtpPacket != NULL) { RtpPacket *previousRtpPacket = rtpPacket->GetPreviousPacket();; RtpPacket *nextRtpPacket = rtpPacket->GetNextPacket(); if (previousRtpPacket != NULL) { // next RTP packet can be NULL, in that case previous RTP packet will be last previousRtpPacket->SetNextPacket(nextRtpPacket); } else { // first packet will be deleted, first packet need to be moved to next packet // if next RTP packet is NULL then packet to delete was one and only and this->firstRtpPacket will be set to NULL this->firstRtpPacket = nextRtpPacket; } if (nextRtpPacket != NULL) { // previous RTP packet can be NULL, in that case next RTP packet will be first nextRtpPacket->SetPreviousPacket(previousRtpPacket); } delete rtpPacket; result = true; } return result; }
bool RtpSource::AddPacket(RtpPacket *rtpPacket) { bool result = (rtpPacket != NULL); if (result) { result &= rtpPacket->IsRtpPacket(); } if (result) { this->logger->Log(LOGGER_DATA, _T("%s: %s: sequence number: %u"), PROTOCOL_IMPLEMENTATION_NAME, METHOD_ADD_PACKET_NAME, rtpPacket->GetSequenceNumber()); // check where packet need to be inserted if (this->firstRtpPacket == NULL) { this->firstRtpPacket = rtpPacket; } else { unsigned int rtpPacketSequenceNumber = rtpPacket->GetSequenceNumber(); // in RTP packets chain cannot be wrong packets RtpPacket *firstPacket = NULL; RtpPacket *secondPacket = this->firstRtpPacket; // go to the end of chain while (secondPacket != NULL) { firstPacket = secondPacket; secondPacket = secondPacket->GetNextPacket(); } // now go from end of chain to start of chain while (1) { bool between = true; if ((firstPacket != NULL) && (secondPacket != NULL)) { between &= this->IsPacketBetween(rtpPacket, firstPacket, secondPacket); } else if (firstPacket != NULL) { // rtpPacket is after first packet ? between &= (this->PacketSequenceNumberDifference(firstPacket, rtpPacket) >= 0); } else if (secondPacket != NULL) { // rtpPacket is before second packet ? between &= (this->PacketSequenceNumberDifference(rtpPacket, secondPacket) <= 0); } if (between) { // got combination of two packets break; } secondPacket = firstPacket; if (firstPacket != NULL) { firstPacket = firstPacket->GetPreviousPacket(); } } if ((firstPacket == NULL) && (secondPacket != NULL)) { // packet have to be added before this->firstRtpPacket this->firstRtpPacket->SetPreviousPacket(rtpPacket); rtpPacket->SetNextPacket(this->firstRtpPacket); rtpPacket->SetPreviousPacket(NULL); this->firstRtpPacket = rtpPacket; } else if ((firstPacket != NULL) && (secondPacket != NULL)) { // packet have to be added between first and second packet firstPacket->SetNextPacket(rtpPacket); secondPacket->SetPreviousPacket(rtpPacket); rtpPacket->SetPreviousPacket(firstPacket); rtpPacket->SetNextPacket(secondPacket); } else if ((firstPacket != NULL) && (secondPacket == NULL)) { // packet have to be added at the end (after first packet) firstPacket->SetNextPacket(rtpPacket); rtpPacket->SetPreviousPacket(firstPacket); rtpPacket->SetNextPacket(NULL); } } } return result; }