pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 07c68b9 | 2012-02-29 16:09:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 11 | #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" |
| 12 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 13 | #include <algorithm> |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 14 | #include <memory> |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 15 | #include <vector> |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 16 | |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 17 | #include "webrtc/rtc_base/checks.h" |
| 18 | #include "webrtc/rtc_base/rate_limiter.h" |
danilchap | b8b6fbb | 2015-12-10 05:05:27 -0800 | [diff] [blame] | 19 | #include "webrtc/test/null_transport.h" |
| 20 | |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 21 | namespace webrtc { |
danilchap | 6a6f089 | 2015-12-10 12:39:08 -0800 | [diff] [blame] | 22 | |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 23 | void LoopBackTransport::SetSendModule(RtpRtcp* rtp_rtcp_module, |
| 24 | RTPPayloadRegistry* payload_registry, |
| 25 | RtpReceiver* receiver, |
| 26 | ReceiveStatistics* receive_statistics) { |
| 27 | rtp_rtcp_module_ = rtp_rtcp_module; |
| 28 | rtp_payload_registry_ = payload_registry; |
| 29 | rtp_receiver_ = receiver; |
| 30 | receive_statistics_ = receive_statistics; |
| 31 | } |
| 32 | |
| 33 | void LoopBackTransport::DropEveryNthPacket(int n) { |
| 34 | packet_loss_ = n; |
| 35 | } |
| 36 | |
stefan | 1d8a506 | 2015-10-02 03:39:33 -0700 | [diff] [blame] | 37 | bool LoopBackTransport::SendRtp(const uint8_t* data, |
| 38 | size_t len, |
| 39 | const PacketOptions& options) { |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 40 | count_++; |
| 41 | if (packet_loss_ > 0) { |
| 42 | if ((count_ % packet_loss_) == 0) { |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 43 | return true; |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | RTPHeader header; |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 47 | std::unique_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); |
ossu | b2d1e0d | 2016-10-05 07:51:44 -0700 | [diff] [blame] | 48 | if (!parser->Parse(data, len, &header)) { |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 49 | return false; |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 50 | } |
| 51 | PayloadUnion payload_specific; |
| 52 | if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, |
| 53 | &payload_specific)) { |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 54 | return false; |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 55 | } |
ossu | b2d1e0d | 2016-10-05 07:51:44 -0700 | [diff] [blame] | 56 | const uint8_t* payload = data + header.headerLength; |
| 57 | RTC_CHECK_GE(len, header.headerLength); |
| 58 | const size_t payload_length = len - header.headerLength; |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 59 | receive_statistics_->IncomingPacket(header, len, false); |
nisse | be3e539 | 2017-05-31 07:35:16 -0700 | [diff] [blame] | 60 | return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length, |
| 61 | payload_specific, true); |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 62 | } |
| 63 | |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 64 | bool LoopBackTransport::SendRtcp(const uint8_t* data, size_t len) { |
nisse | 479d3d7 | 2017-09-13 07:53:37 -0700 | [diff] [blame] | 65 | rtp_rtcp_module_->IncomingRtcpPacket((const uint8_t*)data, len); |
pbos | 2d56668 | 2015-09-28 09:59:31 -0700 | [diff] [blame] | 66 | return true; |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | int32_t TestRtpReceiver::OnReceivedPayloadData( |
| 70 | const uint8_t* payload_data, |
Peter Boström | 0208322 | 2016-06-14 12:52:54 +0200 | [diff] [blame] | 71 | size_t payload_size, |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 72 | const webrtc::WebRtcRTPHeader* rtp_header) { |
| 73 | EXPECT_LE(payload_size, sizeof(payload_data_)); |
| 74 | memcpy(payload_data_, payload_data, payload_size); |
| 75 | memcpy(&rtp_header_, rtp_header, sizeof(rtp_header_)); |
| 76 | payload_size_ = payload_size; |
| 77 | return 0; |
| 78 | } |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 79 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 80 | class RtpRtcpAPITest : public ::testing::Test { |
| 81 | protected: |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 82 | RtpRtcpAPITest() |
| 83 | : fake_clock_(123456), retransmission_rate_limiter_(&fake_clock_, 1000) { |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 84 | test_csrcs_.push_back(1234); |
| 85 | test_csrcs_.push_back(2345); |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 86 | test_ssrc_ = 3456; |
| 87 | test_timestamp_ = 4567; |
| 88 | test_sequence_number_ = 2345; |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 89 | } |
| 90 | ~RtpRtcpAPITest() {} |
| 91 | |
nisse | 7d59f6b | 2017-02-21 03:40:24 -0800 | [diff] [blame] | 92 | const uint32_t initial_ssrc = 8888; |
| 93 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 94 | void SetUp() override { |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 95 | RtpRtcp::Configuration configuration; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 96 | configuration.audio = true; |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 97 | configuration.clock = &fake_clock_; |
sprang | 86fd9ed | 2015-09-29 04:45:43 -0700 | [diff] [blame] | 98 | configuration.outgoing_transport = &null_transport_; |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 99 | configuration.retransmission_rate_limiter = &retransmission_rate_limiter_; |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 100 | module_.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
nisse | 7d59f6b | 2017-02-21 03:40:24 -0800 | [diff] [blame] | 101 | module_->SetSSRC(initial_ssrc); |
magjed | f3feeff | 2016-11-25 06:40:25 -0800 | [diff] [blame] | 102 | rtp_payload_registry_.reset(new RTPPayloadRegistry()); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 103 | } |
| 104 | |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 105 | std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_; |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 106 | std::unique_ptr<RtpRtcp> module_; |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 107 | uint32_t test_ssrc_; |
| 108 | uint32_t test_timestamp_; |
| 109 | uint16_t test_sequence_number_; |
| 110 | std::vector<uint32_t> test_csrcs_; |
| 111 | SimulatedClock fake_clock_; |
sprang | 86fd9ed | 2015-09-29 04:45:43 -0700 | [diff] [blame] | 112 | test::NullTransport null_transport_; |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 113 | RateLimiter retransmission_rate_limiter_; |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | TEST_F(RtpRtcpAPITest, Basic) { |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 117 | module_->SetSequenceNumber(test_sequence_number_); |
| 118 | EXPECT_EQ(test_sequence_number_, module_->SequenceNumber()); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 119 | |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 120 | module_->SetStartTimestamp(test_timestamp_); |
| 121 | EXPECT_EQ(test_timestamp_, module_->StartTimestamp()); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 122 | |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 123 | EXPECT_FALSE(module_->Sending()); |
| 124 | EXPECT_EQ(0, module_->SetSendingStatus(true)); |
| 125 | EXPECT_TRUE(module_->Sending()); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 126 | } |
| 127 | |
nisse | 284542b | 2017-01-10 08:58:32 -0800 | [diff] [blame] | 128 | TEST_F(RtpRtcpAPITest, PacketSize) { |
| 129 | module_->SetMaxRtpPacketSize(1234); |
| 130 | EXPECT_EQ(1234u, module_->MaxRtpPacketSize()); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | TEST_F(RtpRtcpAPITest, SSRC) { |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 134 | module_->SetSSRC(test_ssrc_); |
| 135 | EXPECT_EQ(test_ssrc_, module_->SSRC()); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 136 | } |
| 137 | |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 138 | TEST_F(RtpRtcpAPITest, RTCP) { |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 139 | EXPECT_EQ(RtcpMode::kOff, module_->RTCP()); |
| 140 | module_->SetRTCPStatus(RtcpMode::kCompound); |
| 141 | EXPECT_EQ(RtcpMode::kCompound, module_->RTCP()); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 142 | |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 143 | EXPECT_EQ(0, module_->SetCNAME("john.doe@test.test")); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 144 | |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 145 | EXPECT_FALSE(module_->TMMBR()); |
| 146 | module_->SetTMMBRStatus(true); |
| 147 | EXPECT_TRUE(module_->TMMBR()); |
| 148 | module_->SetTMMBRStatus(false); |
| 149 | EXPECT_FALSE(module_->TMMBR()); |
pwestin@webrtc.org | 8281e7d | 2012-01-10 14:09:18 +0000 | [diff] [blame] | 150 | } |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 151 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 152 | TEST_F(RtpRtcpAPITest, RtxSender) { |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 153 | module_->SetRtxSendStatus(kRtxRetransmitted); |
| 154 | EXPECT_EQ(kRtxRetransmitted, module_->RtxSendStatus()); |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 +0000 | [diff] [blame] | 155 | |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 156 | module_->SetRtxSendStatus(kRtxOff); |
| 157 | EXPECT_EQ(kRtxOff, module_->RtxSendStatus()); |
pbos@webrtc.org | 0b0c241 | 2015-01-13 14:15:15 +0000 | [diff] [blame] | 158 | |
changbin.shao@intel.com | 9691b36 | 2015-01-20 05:42:52 +0000 | [diff] [blame] | 159 | module_->SetRtxSendStatus(kRtxRetransmitted); |
| 160 | EXPECT_EQ(kRtxRetransmitted, module_->RtxSendStatus()); |
mikhal@webrtc.org | bda7f30 | 2013-03-15 23:21:52 +0000 | [diff] [blame] | 161 | } |
| 162 | |
danilchap | 6a6f089 | 2015-12-10 12:39:08 -0800 | [diff] [blame] | 163 | } // namespace webrtc |