-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
417 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include <cstring> | ||
|
||
#include "RtpPacketQueue.h" | ||
#include "../../MediaDefinitions.h" | ||
#include "RtpHeader.h" | ||
|
||
|
||
namespace erizo{ | ||
|
||
DEFINE_LOGGER(RtpPacketQueue, "RtpPacketQueue"); | ||
|
||
RtpPacketQueue::RtpPacketQueue() | ||
: lastNseq_(0), lastTs_(0) | ||
{ | ||
} | ||
|
||
RtpPacketQueue::~RtpPacketQueue(void) | ||
{ | ||
cleanQueue(); | ||
} | ||
|
||
void RtpPacketQueue::pushPacket(const char *data, int length) | ||
{ | ||
|
||
const RTPHeader *header = reinterpret_cast<const RTPHeader*>(data); | ||
uint16_t nseq = header->getSeqNumber(); | ||
uint32_t ts = header->getTimestamp(); | ||
|
||
long long int ltsdiff = (long long int)ts - (long long int)lastTs_; | ||
int tsdiff = (int)ltsdiff; | ||
int nseqdiff = nseq - lastNseq_; | ||
/* | ||
// nseq sequence cicle test | ||
if ( abs(nseqdiff) > ( USHRT_MAX - MAX_DIFF ) ) | ||
{ | ||
NOTIFY("Vuelta del NSeq ns=%d last=%d\n", nseq, lastNseq_); | ||
if (nseqdiff > 0) | ||
nseqdiff-= (USHRT_MAX + 1); | ||
else | ||
nseqdiff+= (USHRT_MAX + 1); | ||
} | ||
*/ | ||
|
||
if (abs(tsdiff) > MAX_DIFF_TS || abs(nseqdiff) > MAX_DIFF ) | ||
{ | ||
// new flow, process and clean queue | ||
ELOG_DEBUG("Max diff reached, new Flow? nsqediff %d , tsdiff %d", nseqdiff, tsdiff); | ||
ELOG_DEBUG("PT %d", header->getPayloadType()); | ||
lastNseq_ = nseq; | ||
lastTs_ = ts; | ||
cleanQueue(); | ||
} | ||
else if (nseqdiff > 1) | ||
{ | ||
// Jump in nseq, enqueue | ||
ELOG_DEBUG("Jump in nseq"); | ||
enqueuePacket(data, length, nseq); | ||
} | ||
else if (nseqdiff == 1) | ||
{ | ||
// next packet, process | ||
lastNseq_ = nseq; | ||
lastTs_ = ts; | ||
enqueuePacket(data, length, nseq); | ||
} | ||
else if (nseqdiff < 0) | ||
{ | ||
ELOG_DEBUG("Old Packet Received"); | ||
// old packet, discard? | ||
// stats? | ||
} | ||
else if (nseqdiff == 0) | ||
{ | ||
ELOG_DEBUG("Duplicate Packet received"); | ||
//duplicate packet, process (for stats)? | ||
} | ||
} | ||
|
||
void RtpPacketQueue::enqueuePacket(const char *data, int length, uint16_t nseq) | ||
{ | ||
if (queue_.size() > MAX_SIZE) { // if queue is growing too much, we start again | ||
cleanQueue(); | ||
} | ||
|
||
boost::shared_ptr<dataPacket> packet(new dataPacket()); | ||
memcpy(packet->data, data, length); | ||
packet->length = length; | ||
queue_.insert(std::map< int, boost::shared_ptr<dataPacket>>::value_type(nseq,packet)); | ||
|
||
} | ||
|
||
void RtpPacketQueue::cleanQueue() | ||
{ | ||
queue_.clear(); | ||
} | ||
|
||
boost::shared_ptr<dataPacket> RtpPacketQueue::popPacket() | ||
{ | ||
boost::shared_ptr<dataPacket> packet = queue_.begin()->second; | ||
if (packet.get() == NULL){ | ||
return packet; | ||
} | ||
const RTPHeader *header = reinterpret_cast<const RTPHeader*>(packet->data); | ||
lastNseq_ = queue_.begin()->first; | ||
lastTs_ = header->getTimestamp(); | ||
queue_.erase(queue_.begin()); | ||
return packet; | ||
} | ||
|
||
int RtpPacketQueue::getSize(){ | ||
uint16_t size = queue_.size(); | ||
return size; | ||
} | ||
} /* namespace erizo */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef __RTPPACKETQUEUE_H__ | ||
#define __RTPPACKETQUEUE_H__ | ||
|
||
#include <map> | ||
#include <boost/shared_ptr.hpp> | ||
|
||
#include "logger.h" | ||
|
||
namespace erizo{ | ||
//forward declaration | ||
class dataPacket; | ||
|
||
class RtpPacketQueue | ||
{ | ||
DECLARE_LOGGER(); | ||
|
||
public: | ||
RtpPacketQueue(); | ||
virtual ~RtpPacketQueue(void); | ||
|
||
void pushPacket(const char *data, int length); | ||
boost::shared_ptr<dataPacket> popPacket(); | ||
int getSize(); | ||
|
||
private: | ||
static const int MAX_DIFF = 50; | ||
static const int MAX_DIFF_TS = 50000; | ||
static const unsigned int MAX_SIZE = 10; | ||
std::map< int, boost::shared_ptr<dataPacket>> queue_; | ||
uint16_t lastNseq_; | ||
uint32_t lastTs_; | ||
|
||
void enqueuePacket(const char *data, int length, uint16_t nseq); | ||
void cleanQueue(void); | ||
|
||
}; | ||
} /* namespace erizo */ | ||
|
||
#endif /* RTPPACKETQUEUE*/ | ||
|
Oops, something went wrong.