OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
(...skipping 12 matching lines...) Expand all Loading... |
23 rtp_rtcp_module_ = rtp_rtcp_module; | 23 rtp_rtcp_module_ = rtp_rtcp_module; |
24 rtp_payload_registry_ = payload_registry; | 24 rtp_payload_registry_ = payload_registry; |
25 rtp_receiver_ = receiver; | 25 rtp_receiver_ = receiver; |
26 receive_statistics_ = receive_statistics; | 26 receive_statistics_ = receive_statistics; |
27 } | 27 } |
28 | 28 |
29 void LoopBackTransport::DropEveryNthPacket(int n) { | 29 void LoopBackTransport::DropEveryNthPacket(int n) { |
30 packet_loss_ = n; | 30 packet_loss_ = n; |
31 } | 31 } |
32 | 32 |
33 int LoopBackTransport::SendPacket(int channel, const void* data, size_t len) { | 33 int LoopBackTransport::SendPacket(const void* data, size_t len) { |
34 count_++; | 34 count_++; |
35 if (packet_loss_ > 0) { | 35 if (packet_loss_ > 0) { |
36 if ((count_ % packet_loss_) == 0) { | 36 if ((count_ % packet_loss_) == 0) { |
37 return len; | 37 return len; |
38 } | 38 } |
39 } | 39 } |
40 RTPHeader header; | 40 RTPHeader header; |
41 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); | 41 rtc::scoped_ptr<RtpHeaderParser> parser(RtpHeaderParser::Create()); |
42 if (!parser->Parse(static_cast<const uint8_t*>(data), len, &header)) { | 42 if (!parser->Parse(static_cast<const uint8_t*>(data), len, &header)) { |
43 return -1; | 43 return -1; |
44 } | 44 } |
45 PayloadUnion payload_specific; | 45 PayloadUnion payload_specific; |
46 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, | 46 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType, |
47 &payload_specific)) { | 47 &payload_specific)) { |
48 return -1; | 48 return -1; |
49 } | 49 } |
50 receive_statistics_->IncomingPacket(header, len, false); | 50 receive_statistics_->IncomingPacket(header, len, false); |
51 if (!rtp_receiver_->IncomingRtpPacket(header, | 51 if (!rtp_receiver_->IncomingRtpPacket(header, |
52 static_cast<const uint8_t*>(data), len, | 52 static_cast<const uint8_t*>(data), len, |
53 payload_specific, true)) { | 53 payload_specific, true)) { |
54 return -1; | 54 return -1; |
55 } | 55 } |
56 return len; | 56 return len; |
57 } | 57 } |
58 | 58 |
59 int LoopBackTransport::SendRTCPPacket(int channel, | 59 int LoopBackTransport::SendRTCPPacket(const void* data, size_t len) { |
60 const void* data, | |
61 size_t len) { | |
62 if (rtp_rtcp_module_->IncomingRtcpPacket((const uint8_t*)data, len) < 0) { | 60 if (rtp_rtcp_module_->IncomingRtcpPacket((const uint8_t*)data, len) < 0) { |
63 return -1; | 61 return -1; |
64 } | 62 } |
65 return static_cast<int>(len); | 63 return static_cast<int>(len); |
66 } | 64 } |
67 | 65 |
68 int32_t TestRtpReceiver::OnReceivedPayloadData( | 66 int32_t TestRtpReceiver::OnReceivedPayloadData( |
69 const uint8_t* payload_data, | 67 const uint8_t* payload_data, |
70 const size_t payload_size, | 68 const size_t payload_size, |
71 const webrtc::WebRtcRTPHeader* rtp_header) { | 69 const webrtc::WebRtcRTPHeader* rtp_header) { |
72 EXPECT_LE(payload_size, sizeof(payload_data_)); | 70 EXPECT_LE(payload_size, sizeof(payload_data_)); |
73 memcpy(payload_data_, payload_data, payload_size); | 71 memcpy(payload_data_, payload_data, payload_size); |
74 memcpy(&rtp_header_, rtp_header, sizeof(rtp_header_)); | 72 memcpy(&rtp_header_, rtp_header, sizeof(rtp_header_)); |
75 payload_size_ = payload_size; | 73 payload_size_ = payload_size; |
76 return 0; | 74 return 0; |
77 } | 75 } |
78 } // namespace webrtc | 76 } // namespace webrtc |
79 | 77 |
80 class RtpRtcpAPITest : public ::testing::Test { | 78 class RtpRtcpAPITest : public ::testing::Test { |
81 protected: | 79 protected: |
82 RtpRtcpAPITest() : fake_clock_(123456) { | 80 RtpRtcpAPITest() : fake_clock_(123456) { |
83 test_csrcs_.push_back(1234); | 81 test_csrcs_.push_back(1234); |
84 test_csrcs_.push_back(2345); | 82 test_csrcs_.push_back(2345); |
85 test_id = 123; | |
86 test_ssrc_ = 3456; | 83 test_ssrc_ = 3456; |
87 test_timestamp_ = 4567; | 84 test_timestamp_ = 4567; |
88 test_sequence_number_ = 2345; | 85 test_sequence_number_ = 2345; |
89 } | 86 } |
90 ~RtpRtcpAPITest() {} | 87 ~RtpRtcpAPITest() {} |
91 | 88 |
92 void SetUp() override { | 89 void SetUp() override { |
93 RtpRtcp::Configuration configuration; | 90 RtpRtcp::Configuration configuration; |
94 configuration.id = test_id; | |
95 configuration.audio = true; | 91 configuration.audio = true; |
96 configuration.clock = &fake_clock_; | 92 configuration.clock = &fake_clock_; |
97 module_.reset(RtpRtcp::CreateRtpRtcp(configuration)); | 93 module_.reset(RtpRtcp::CreateRtpRtcp(configuration)); |
98 rtp_payload_registry_.reset(new RTPPayloadRegistry( | 94 rtp_payload_registry_.reset(new RTPPayloadRegistry( |
99 RTPPayloadStrategy::CreateStrategy(true))); | 95 RTPPayloadStrategy::CreateStrategy(true))); |
100 rtp_receiver_.reset(RtpReceiver::CreateAudioReceiver( | 96 rtp_receiver_.reset(RtpReceiver::CreateAudioReceiver( |
101 test_id, &fake_clock_, NULL, NULL, NULL, rtp_payload_registry_.get())); | 97 &fake_clock_, NULL, NULL, NULL, rtp_payload_registry_.get())); |
102 } | 98 } |
103 | 99 |
104 int test_id; | |
105 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_; | 100 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_; |
106 rtc::scoped_ptr<RtpReceiver> rtp_receiver_; | 101 rtc::scoped_ptr<RtpReceiver> rtp_receiver_; |
107 rtc::scoped_ptr<RtpRtcp> module_; | 102 rtc::scoped_ptr<RtpRtcp> module_; |
108 uint32_t test_ssrc_; | 103 uint32_t test_ssrc_; |
109 uint32_t test_timestamp_; | 104 uint32_t test_timestamp_; |
110 uint16_t test_sequence_number_; | 105 uint16_t test_sequence_number_; |
111 std::vector<uint32_t> test_csrcs_; | 106 std::vector<uint32_t> test_csrcs_; |
112 SimulatedClock fake_clock_; | 107 SimulatedClock fake_clock_; |
113 }; | 108 }; |
114 | 109 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 RTPHeader rtx_header; | 175 RTPHeader rtx_header; |
181 rtx_header.ssrc = kRtxSsrc; | 176 rtx_header.ssrc = kRtxSsrc; |
182 rtx_header.payloadType = kRtxPayloadType; | 177 rtx_header.payloadType = kRtxPayloadType; |
183 EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header)); | 178 EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header)); |
184 rtx_header.ssrc = 0; | 179 rtx_header.ssrc = 0; |
185 EXPECT_FALSE(rtp_payload_registry_->IsRtx(rtx_header)); | 180 EXPECT_FALSE(rtp_payload_registry_->IsRtx(rtx_header)); |
186 rtx_header.ssrc = kRtxSsrc; | 181 rtx_header.ssrc = kRtxSsrc; |
187 rtx_header.payloadType = 0; | 182 rtx_header.payloadType = 0; |
188 EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header)); | 183 EXPECT_TRUE(rtp_payload_registry_->IsRtx(rtx_header)); |
189 } | 184 } |
OLD | NEW |