summaryrefslogtreecommitdiffstats
path: root/remoting/protocol/rtp_reader.cc
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-24 04:20:48 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-24 04:20:48 +0000
commit8e88605290262afe6291f997abc0d5ff9197c595 (patch)
treea358863f248c784aef39bd0b7b3e47295384f5d2 /remoting/protocol/rtp_reader.cc
parent629a837754b10e7a08a7f85838d3271f96e68f2f (diff)
downloadchromium_src-8e88605290262afe6291f997abc0d5ff9197c595.zip
chromium_src-8e88605290262afe6291f997abc0d5ff9197c595.tar.gz
chromium_src-8e88605290262afe6291f997abc0d5ff9197c595.tar.bz2
Refactoring in RTP reader code: sequence number wrapping logic moved to
RtpReader BUG=None TEST=Unittests Review URL: http://codereview.chromium.org/5110008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67212 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/rtp_reader.cc')
-rw-r--r--remoting/protocol/rtp_reader.cc47
1 files changed, 43 insertions, 4 deletions
diff --git a/remoting/protocol/rtp_reader.cc b/remoting/protocol/rtp_reader.cc
index 7e21250..f36dc8b 100644
--- a/remoting/protocol/rtp_reader.cc
+++ b/remoting/protocol/rtp_reader.cc
@@ -10,12 +10,25 @@
namespace remoting {
namespace protocol {
-RtpPacket::RtpPacket() {}
-RtpPacket::~RtpPacket() {}
+namespace {
+// Recomended values from RTP spec.
+const int kMaxDropout = 3000;
+const int kMaxMisorder = 100;
+} // namespace
+
+RtpPacket::RtpPacket() { }
+
+RtpPacket::~RtpPacket() { }
// RtpReader class.
-RtpReader::RtpReader() {}
-RtpReader::~RtpReader() {}
+RtpReader::RtpReader()
+ : max_sequence_number_(0),
+ wrap_around_count_(0),
+ started_(false) {
+}
+
+RtpReader::~RtpReader() {
+}
void RtpReader::Init(net::Socket* socket,
OnMessageCallback* on_message_callback) {
@@ -44,6 +57,32 @@ void RtpReader::OnDataReceived(net::IOBuffer* buffer, int data_size) {
buffer, buffer->data() + header_size + descriptor_size,
data_size - header_size - descriptor_size);
+ uint16 sequence_number = packet->header().sequence_number;
+
+ // Reset |max_sequence_number_| after we've received first packet.
+ if (!started_) {
+ started_ = true;
+ max_sequence_number_ = sequence_number;
+ }
+
+ int16 delta = sequence_number - max_sequence_number_;
+ if (delta <= -kMaxMisorder || delta > kMaxDropout) {
+ // TODO(sergeyu): Do we need to handle restarted trasmission?
+ LOG(WARNING) << "Received RTP packet with invalid sequence number.";
+ delete packet;
+ return;
+ }
+
+ packet->set_extended_sequence_number(
+ (wrap_around_count_ << 16) + max_sequence_number_ + delta);
+
+ if (delta > 0 && delta < kMaxDropout) {
+ if (sequence_number < max_sequence_number_) {
+ wrap_around_count_++;
+ }
+ max_sequence_number_ = sequence_number;
+ }
+
on_message_callback_->Run(packet);
}