| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <iterator> | 12 #include <iterator> |
| 13 #include <list> | 13 #include <list> |
| 14 #include <set> | 14 #include <set> |
| 15 | 15 |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
| 18 #include "webrtc/common_types.h" | 18 #include "webrtc/common_types.h" |
| 19 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" | 19 #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" |
| 20 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" | 20 #include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h" |
| 21 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" | 21 #include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h" |
| 22 #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h" | 22 #include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h" |
| 23 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" | 23 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h" |
| 24 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" | 24 #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
| 25 #include "webrtc/transport.h" |
| 25 | 26 |
| 26 using namespace webrtc; | 27 using namespace webrtc; |
| 27 | 28 |
| 28 const int kVideoNackListSize = 30; | 29 const int kVideoNackListSize = 30; |
| 29 const uint32_t kTestSsrc = 3456; | 30 const uint32_t kTestSsrc = 3456; |
| 30 const uint16_t kTestSequenceNumber = 2345; | 31 const uint16_t kTestSequenceNumber = 2345; |
| 31 const uint32_t kTestNumberOfPackets = 1350; | 32 const uint32_t kTestNumberOfPackets = 1350; |
| 32 const int kTestNumberOfRtxPackets = 149; | 33 const int kTestNumberOfRtxPackets = 149; |
| 33 const int kNumFrames = 30; | 34 const int kNumFrames = 30; |
| 34 const int kPayloadType = 123; | 35 const int kPayloadType = 123; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 void DropEveryNthPacket(int n) { | 89 void DropEveryNthPacket(int n) { |
| 89 packet_loss_ = n; | 90 packet_loss_ = n; |
| 90 } | 91 } |
| 91 | 92 |
| 92 void DropConsecutivePackets(int start, int total) { | 93 void DropConsecutivePackets(int start, int total) { |
| 93 consecutive_drop_start_ = start; | 94 consecutive_drop_start_ = start; |
| 94 consecutive_drop_end_ = start + total; | 95 consecutive_drop_end_ = start + total; |
| 95 packet_loss_ = 0; | 96 packet_loss_ = 0; |
| 96 } | 97 } |
| 97 | 98 |
| 98 int SendPacket(const void* data, size_t len) override { | 99 bool SendRtp(const uint8_t* data, size_t len) override { |
| 99 count_++; | 100 count_++; |
| 100 const unsigned char* ptr = static_cast<const unsigned char*>(data); | 101 const unsigned char* ptr = static_cast<const unsigned char*>(data); |
| 101 uint32_t ssrc = (ptr[8] << 24) + (ptr[9] << 16) + (ptr[10] << 8) + ptr[11]; | 102 uint32_t ssrc = (ptr[8] << 24) + (ptr[9] << 16) + (ptr[10] << 8) + ptr[11]; |
| 102 if (ssrc == rtx_ssrc_) count_rtx_ssrc_++; | 103 if (ssrc == rtx_ssrc_) count_rtx_ssrc_++; |
| 103 uint16_t sequence_number = (ptr[2] << 8) + ptr[3]; | 104 uint16_t sequence_number = (ptr[2] << 8) + ptr[3]; |
| 104 size_t packet_length = len; | 105 size_t packet_length = len; |
| 105 // TODO(pbos): Figure out why this needs to be initialized. Likely this | 106 // TODO(pbos): Figure out why this needs to be initialized. Likely this |
| 106 // is hiding a bug either in test setup or other code. | 107 // is hiding a bug either in test setup or other code. |
| 107 // https://code.google.com/p/webrtc/issues/detail?id=3183 | 108 // https://code.google.com/p/webrtc/issues/detail?id=3183 |
| 108 uint8_t restored_packet[1500] = {0}; | 109 uint8_t restored_packet[1500] = {0}; |
| 109 uint8_t* restored_packet_ptr = restored_packet; | 110 uint8_t* restored_packet_ptr = restored_packet; |
| 110 RTPHeader header; | 111 RTPHeader header; |
| 111 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); | 112 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); |
| 112 if (!parser->Parse(ptr, len, &header)) { | 113 if (!parser->Parse(ptr, len, &header)) { |
| 113 return -1; | 114 return false; |
| 114 } | 115 } |
| 115 | 116 |
| 116 if (!rtp_payload_registry_->IsRtx(header)) { | 117 if (!rtp_payload_registry_->IsRtx(header)) { |
| 117 // Don't store retransmitted packets since we compare it to the list | 118 // Don't store retransmitted packets since we compare it to the list |
| 118 // created by the receiver. | 119 // created by the receiver. |
| 119 expected_sequence_numbers_.insert(expected_sequence_numbers_.end(), | 120 expected_sequence_numbers_.insert(expected_sequence_numbers_.end(), |
| 120 sequence_number); | 121 sequence_number); |
| 121 } | 122 } |
| 122 if (packet_loss_ > 0) { | 123 if (packet_loss_ > 0) { |
| 123 if ((count_ % packet_loss_) == 0) { | 124 if ((count_ % packet_loss_) == 0) { |
| 124 return static_cast<int>(len); | 125 return true; |
| 125 } | 126 } |
| 126 } else if (count_ >= consecutive_drop_start_ && | 127 } else if (count_ >= consecutive_drop_start_ && |
| 127 count_ < consecutive_drop_end_) { | 128 count_ < consecutive_drop_end_) { |
| 128 return static_cast<int>(len); | 129 return true; |
| 129 } | 130 } |
| 130 if (rtp_payload_registry_->IsRtx(header)) { | 131 if (rtp_payload_registry_->IsRtx(header)) { |
| 131 // Remove the RTX header and parse the original RTP header. | 132 // Remove the RTX header and parse the original RTP header. |
| 132 EXPECT_TRUE(rtp_payload_registry_->RestoreOriginalPacket( | 133 EXPECT_TRUE(rtp_payload_registry_->RestoreOriginalPacket( |
| 133 &restored_packet_ptr, ptr, &packet_length, rtp_receiver_->SSRC(), | 134 &restored_packet_ptr, ptr, &packet_length, rtp_receiver_->SSRC(), |
| 134 header)); | 135 header)); |
| 135 if (!parser->Parse(restored_packet_ptr, packet_length, &header)) { | 136 if (!parser->Parse(restored_packet_ptr, packet_length, &header)) { |
| 136 return -1; | 137 return false; |
| 137 } | 138 } |
| 138 } else { | 139 } else { |
| 139 rtp_payload_registry_->SetIncomingPayloadType(header); | 140 rtp_payload_registry_->SetIncomingPayloadType(header); |
| 140 } | 141 } |
| 141 | 142 |
| 142 restored_packet_ptr += header.headerLength; | 143 restored_packet_ptr += header.headerLength; |
| 143 packet_length -= header.headerLength; | 144 packet_length -= header.headerLength; |
| 144 PayloadUnion payload_specific; | 145 PayloadUnion payload_specific; |
| 145 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, | 146 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, |
| 146 &payload_specific)) { | 147 &payload_specific)) { |
| 147 return -1; | 148 return false; |
| 148 } | 149 } |
| 149 if (!rtp_receiver_->IncomingRtpPacket(header, restored_packet_ptr, | 150 if (!rtp_receiver_->IncomingRtpPacket(header, restored_packet_ptr, |
| 150 packet_length, payload_specific, | 151 packet_length, payload_specific, |
| 151 true)) { | 152 true)) { |
| 152 return -1; | 153 return false; |
| 153 } | 154 } |
| 154 return static_cast<int>(len); | 155 return true; |
| 155 } | 156 } |
| 156 | 157 |
| 157 int SendRTCPPacket(const void* data, size_t len) override { | 158 bool SendRtcp(const uint8_t* data, size_t len) override { |
| 158 if (module_->IncomingRtcpPacket((const uint8_t*)data, len) == 0) { | 159 return module_->IncomingRtcpPacket((const uint8_t*)data, len) == 0; |
| 159 return static_cast<int>(len); | |
| 160 } | |
| 161 return -1; | |
| 162 } | 160 } |
| 163 int count_; | 161 int count_; |
| 164 int packet_loss_; | 162 int packet_loss_; |
| 165 int consecutive_drop_start_; | 163 int consecutive_drop_start_; |
| 166 int consecutive_drop_end_; | 164 int consecutive_drop_end_; |
| 167 uint32_t rtx_ssrc_; | 165 uint32_t rtx_ssrc_; |
| 168 int count_rtx_ssrc_; | 166 int count_rtx_ssrc_; |
| 169 RTPPayloadRegistry* rtp_payload_registry_; | 167 RTPPayloadRegistry* rtp_payload_registry_; |
| 170 RtpReceiver* rtp_receiver_; | 168 RtpReceiver* rtp_receiver_; |
| 171 RtpRtcp* module_; | 169 RtpRtcp* module_; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 342 |
| 345 TEST_F(RtpRtcpRtxNackTest, RtxNack) { | 343 TEST_F(RtpRtcpRtxNackTest, RtxNack) { |
| 346 RunRtxTest(kRtxRetransmitted, 10); | 344 RunRtxTest(kRtxRetransmitted, 10); |
| 347 EXPECT_EQ(kTestSequenceNumber, *(receiver_.sequence_numbers_.begin())); | 345 EXPECT_EQ(kTestSequenceNumber, *(receiver_.sequence_numbers_.begin())); |
| 348 EXPECT_EQ(kTestSequenceNumber + kTestNumberOfPackets - 1, | 346 EXPECT_EQ(kTestSequenceNumber + kTestNumberOfPackets - 1, |
| 349 *(receiver_.sequence_numbers_.rbegin())); | 347 *(receiver_.sequence_numbers_.rbegin())); |
| 350 EXPECT_EQ(kTestNumberOfPackets, receiver_.sequence_numbers_.size()); | 348 EXPECT_EQ(kTestNumberOfPackets, receiver_.sequence_numbers_.size()); |
| 351 EXPECT_EQ(kTestNumberOfRtxPackets, transport_.count_rtx_ssrc_); | 349 EXPECT_EQ(kTestNumberOfRtxPackets, transport_.count_rtx_ssrc_); |
| 352 EXPECT_TRUE(ExpectedPacketsReceived()); | 350 EXPECT_TRUE(ExpectedPacketsReceived()); |
| 353 } | 351 } |
| OLD | NEW |