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 |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 | 13 |
13 #include "webrtc/base/buffer.h" | 14 #include "webrtc/base/buffer.h" |
14 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
15 #include "webrtc/base/helpers.h" | 16 #include "webrtc/base/helpers.h" |
16 #include "webrtc/base/scoped_ptr.h" | |
17 #include "webrtc/base/ssladapter.h" | 17 #include "webrtc/base/ssladapter.h" |
18 #include "webrtc/base/timing.h" | 18 #include "webrtc/base/timing.h" |
19 #include "webrtc/media/base/constants.h" | 19 #include "webrtc/media/base/constants.h" |
20 #include "webrtc/media/base/fakenetworkinterface.h" | 20 #include "webrtc/media/base/fakenetworkinterface.h" |
21 #include "webrtc/media/base/rtpdataengine.h" | 21 #include "webrtc/media/base/rtpdataengine.h" |
22 #include "webrtc/media/base/rtputils.h" | 22 #include "webrtc/media/base/rtputils.h" |
23 | 23 |
24 class FakeTiming : public rtc::Timing { | 24 class FakeTiming : public rtc::Timing { |
25 public: | 25 public: |
26 FakeTiming() : now_(0.0) {} | 26 FakeTiming() : now_(0.0) {} |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 cricket::ReceiveDataParams GetReceivedDataParams() { | 117 cricket::ReceiveDataParams GetReceivedDataParams() { |
118 return receiver_->last_received_data_params(); | 118 return receiver_->last_received_data_params(); |
119 } | 119 } |
120 | 120 |
121 bool HasSentData(int count) { | 121 bool HasSentData(int count) { |
122 return (iface_->NumRtpPackets() > count); | 122 return (iface_->NumRtpPackets() > count); |
123 } | 123 } |
124 | 124 |
125 std::string GetSentData(int index) { | 125 std::string GetSentData(int index) { |
126 // Assume RTP header of length 12 | 126 // Assume RTP header of length 12 |
127 rtc::scoped_ptr<const rtc::Buffer> packet( | 127 std::unique_ptr<const rtc::Buffer> packet( |
128 iface_->GetRtpPacket(index)); | 128 iface_->GetRtpPacket(index)); |
129 if (packet->size() > 12) { | 129 if (packet->size() > 12) { |
130 return std::string(packet->data<char>() + 12, packet->size() - 12); | 130 return std::string(packet->data<char>() + 12, packet->size() - 12); |
131 } else { | 131 } else { |
132 return ""; | 132 return ""; |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 cricket::RtpHeader GetSentDataHeader(int index) { | 136 cricket::RtpHeader GetSentDataHeader(int index) { |
137 rtc::scoped_ptr<const rtc::Buffer> packet( | 137 std::unique_ptr<const rtc::Buffer> packet( |
138 iface_->GetRtpPacket(index)); | 138 iface_->GetRtpPacket(index)); |
139 cricket::RtpHeader header; | 139 cricket::RtpHeader header; |
140 GetRtpHeader(packet->data(), packet->size(), &header); | 140 GetRtpHeader(packet->data(), packet->size(), &header); |
141 return header; | 141 return header; |
142 } | 142 } |
143 | 143 |
144 private: | 144 private: |
145 rtc::scoped_ptr<cricket::RtpDataEngine> dme_; | 145 std::unique_ptr<cricket::RtpDataEngine> dme_; |
146 // Timing passed into dme_. Owned by dme_; | 146 // Timing passed into dme_. Owned by dme_; |
147 FakeTiming* timing_; | 147 FakeTiming* timing_; |
148 rtc::scoped_ptr<cricket::FakeNetworkInterface> iface_; | 148 std::unique_ptr<cricket::FakeNetworkInterface> iface_; |
149 rtc::scoped_ptr<FakeDataReceiver> receiver_; | 149 std::unique_ptr<FakeDataReceiver> receiver_; |
150 }; | 150 }; |
151 | 151 |
152 TEST_F(RtpDataMediaChannelTest, SetUnknownCodecs) { | 152 TEST_F(RtpDataMediaChannelTest, SetUnknownCodecs) { |
153 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 153 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
154 | 154 |
155 cricket::DataCodec known_codec; | 155 cricket::DataCodec known_codec; |
156 known_codec.id = 103; | 156 known_codec.id = 103; |
157 known_codec.name = "google-data"; | 157 known_codec.name = "google-data"; |
158 cricket::DataCodec unknown_codec; | 158 cricket::DataCodec unknown_codec; |
159 unknown_codec.id = 104; | 159 unknown_codec.id = 104; |
160 unknown_codec.name = "unknown-data"; | 160 unknown_codec.name = "unknown-data"; |
161 | 161 |
162 cricket::DataSendParameters send_parameters_known; | 162 cricket::DataSendParameters send_parameters_known; |
163 send_parameters_known.codecs.push_back(known_codec); | 163 send_parameters_known.codecs.push_back(known_codec); |
(...skipping 14 matching lines...) Expand all Loading... |
178 | 178 |
179 EXPECT_TRUE(dmc->SetSendParameters(send_parameters_known)); | 179 EXPECT_TRUE(dmc->SetSendParameters(send_parameters_known)); |
180 EXPECT_FALSE(dmc->SetSendParameters(send_parameters_unknown)); | 180 EXPECT_FALSE(dmc->SetSendParameters(send_parameters_unknown)); |
181 EXPECT_TRUE(dmc->SetSendParameters(send_parameters_mixed)); | 181 EXPECT_TRUE(dmc->SetSendParameters(send_parameters_mixed)); |
182 EXPECT_TRUE(dmc->SetRecvParameters(recv_parameters_known)); | 182 EXPECT_TRUE(dmc->SetRecvParameters(recv_parameters_known)); |
183 EXPECT_FALSE(dmc->SetRecvParameters(recv_parameters_unknown)); | 183 EXPECT_FALSE(dmc->SetRecvParameters(recv_parameters_unknown)); |
184 EXPECT_FALSE(dmc->SetRecvParameters(recv_parameters_mixed)); | 184 EXPECT_FALSE(dmc->SetRecvParameters(recv_parameters_mixed)); |
185 } | 185 } |
186 | 186 |
187 TEST_F(RtpDataMediaChannelTest, AddRemoveSendStream) { | 187 TEST_F(RtpDataMediaChannelTest, AddRemoveSendStream) { |
188 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 188 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
189 | 189 |
190 cricket::StreamParams stream1; | 190 cricket::StreamParams stream1; |
191 stream1.add_ssrc(41); | 191 stream1.add_ssrc(41); |
192 EXPECT_TRUE(dmc->AddSendStream(stream1)); | 192 EXPECT_TRUE(dmc->AddSendStream(stream1)); |
193 cricket::StreamParams stream2; | 193 cricket::StreamParams stream2; |
194 stream2.add_ssrc(42); | 194 stream2.add_ssrc(42); |
195 EXPECT_TRUE(dmc->AddSendStream(stream2)); | 195 EXPECT_TRUE(dmc->AddSendStream(stream2)); |
196 | 196 |
197 EXPECT_TRUE(dmc->RemoveSendStream(41)); | 197 EXPECT_TRUE(dmc->RemoveSendStream(41)); |
198 EXPECT_TRUE(dmc->RemoveSendStream(42)); | 198 EXPECT_TRUE(dmc->RemoveSendStream(42)); |
199 EXPECT_FALSE(dmc->RemoveSendStream(43)); | 199 EXPECT_FALSE(dmc->RemoveSendStream(43)); |
200 } | 200 } |
201 | 201 |
202 TEST_F(RtpDataMediaChannelTest, AddRemoveRecvStream) { | 202 TEST_F(RtpDataMediaChannelTest, AddRemoveRecvStream) { |
203 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 203 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
204 | 204 |
205 cricket::StreamParams stream1; | 205 cricket::StreamParams stream1; |
206 stream1.add_ssrc(41); | 206 stream1.add_ssrc(41); |
207 EXPECT_TRUE(dmc->AddRecvStream(stream1)); | 207 EXPECT_TRUE(dmc->AddRecvStream(stream1)); |
208 cricket::StreamParams stream2; | 208 cricket::StreamParams stream2; |
209 stream2.add_ssrc(42); | 209 stream2.add_ssrc(42); |
210 EXPECT_TRUE(dmc->AddRecvStream(stream2)); | 210 EXPECT_TRUE(dmc->AddRecvStream(stream2)); |
211 EXPECT_FALSE(dmc->AddRecvStream(stream2)); | 211 EXPECT_FALSE(dmc->AddRecvStream(stream2)); |
212 | 212 |
213 EXPECT_TRUE(dmc->RemoveRecvStream(41)); | 213 EXPECT_TRUE(dmc->RemoveRecvStream(41)); |
214 EXPECT_TRUE(dmc->RemoveRecvStream(42)); | 214 EXPECT_TRUE(dmc->RemoveRecvStream(42)); |
215 } | 215 } |
216 | 216 |
217 TEST_F(RtpDataMediaChannelTest, SendData) { | 217 TEST_F(RtpDataMediaChannelTest, SendData) { |
218 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 218 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
219 | 219 |
220 cricket::SendDataParams params; | 220 cricket::SendDataParams params; |
221 params.ssrc = 42; | 221 params.ssrc = 42; |
222 unsigned char data[] = "food"; | 222 unsigned char data[] = "food"; |
223 rtc::Buffer payload(data, 4); | 223 rtc::Buffer payload(data, 4); |
224 unsigned char padded_data[] = { | 224 unsigned char padded_data[] = { |
225 0x00, 0x00, 0x00, 0x00, | 225 0x00, 0x00, 0x00, 0x00, |
226 'f', 'o', 'o', 'd', | 226 'f', 'o', 'o', 'd', |
227 }; | 227 }; |
228 cricket::SendDataResult result; | 228 cricket::SendDataResult result; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 EXPECT_EQ(header1.ssrc, 42U); | 286 EXPECT_EQ(header1.ssrc, 42U); |
287 EXPECT_EQ(header1.payload_type, 103); | 287 EXPECT_EQ(header1.payload_type, 103); |
288 EXPECT_EQ(static_cast<uint16_t>(header0.seq_num + 1), | 288 EXPECT_EQ(static_cast<uint16_t>(header0.seq_num + 1), |
289 static_cast<uint16_t>(header1.seq_num)); | 289 static_cast<uint16_t>(header1.seq_num)); |
290 EXPECT_EQ(header0.timestamp + 180000, header1.timestamp); | 290 EXPECT_EQ(header0.timestamp + 180000, header1.timestamp); |
291 } | 291 } |
292 | 292 |
293 TEST_F(RtpDataMediaChannelTest, SendDataMultipleClocks) { | 293 TEST_F(RtpDataMediaChannelTest, SendDataMultipleClocks) { |
294 // Timings owned by RtpDataEngines. | 294 // Timings owned by RtpDataEngines. |
295 FakeTiming* timing1 = new FakeTiming(); | 295 FakeTiming* timing1 = new FakeTiming(); |
296 rtc::scoped_ptr<cricket::RtpDataEngine> dme1(CreateEngine(timing1)); | 296 std::unique_ptr<cricket::RtpDataEngine> dme1(CreateEngine(timing1)); |
297 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc1( | 297 std::unique_ptr<cricket::RtpDataMediaChannel> dmc1( |
298 CreateChannel(dme1.get())); | 298 CreateChannel(dme1.get())); |
299 FakeTiming* timing2 = new FakeTiming(); | 299 FakeTiming* timing2 = new FakeTiming(); |
300 rtc::scoped_ptr<cricket::RtpDataEngine> dme2(CreateEngine(timing2)); | 300 std::unique_ptr<cricket::RtpDataEngine> dme2(CreateEngine(timing2)); |
301 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc2( | 301 std::unique_ptr<cricket::RtpDataMediaChannel> dmc2( |
302 CreateChannel(dme2.get())); | 302 CreateChannel(dme2.get())); |
303 | 303 |
304 ASSERT_TRUE(dmc1->SetSend(true)); | 304 ASSERT_TRUE(dmc1->SetSend(true)); |
305 ASSERT_TRUE(dmc2->SetSend(true)); | 305 ASSERT_TRUE(dmc2->SetSend(true)); |
306 | 306 |
307 cricket::StreamParams stream1; | 307 cricket::StreamParams stream1; |
308 stream1.add_ssrc(41); | 308 stream1.add_ssrc(41); |
309 ASSERT_TRUE(dmc1->AddSendStream(stream1)); | 309 ASSERT_TRUE(dmc1->AddSendStream(stream1)); |
310 cricket::StreamParams stream2; | 310 cricket::StreamParams stream2; |
311 stream2.add_ssrc(42); | 311 stream2.add_ssrc(42); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 347 |
348 EXPECT_EQ(static_cast<uint16_t>(header1a.seq_num + 1), | 348 EXPECT_EQ(static_cast<uint16_t>(header1a.seq_num + 1), |
349 static_cast<uint16_t>(header1b.seq_num)); | 349 static_cast<uint16_t>(header1b.seq_num)); |
350 EXPECT_EQ(header1a.timestamp + 90000, header1b.timestamp); | 350 EXPECT_EQ(header1a.timestamp + 90000, header1b.timestamp); |
351 EXPECT_EQ(static_cast<uint16_t>(header2a.seq_num + 1), | 351 EXPECT_EQ(static_cast<uint16_t>(header2a.seq_num + 1), |
352 static_cast<uint16_t>(header2b.seq_num)); | 352 static_cast<uint16_t>(header2b.seq_num)); |
353 EXPECT_EQ(header2a.timestamp + 180000, header2b.timestamp); | 353 EXPECT_EQ(header2a.timestamp + 180000, header2b.timestamp); |
354 } | 354 } |
355 | 355 |
356 TEST_F(RtpDataMediaChannelTest, SendDataRate) { | 356 TEST_F(RtpDataMediaChannelTest, SendDataRate) { |
357 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 357 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
358 | 358 |
359 ASSERT_TRUE(dmc->SetSend(true)); | 359 ASSERT_TRUE(dmc->SetSend(true)); |
360 | 360 |
361 cricket::DataCodec codec; | 361 cricket::DataCodec codec; |
362 codec.id = 103; | 362 codec.id = 103; |
363 codec.name = cricket::kGoogleRtpDataCodecName; | 363 codec.name = cricket::kGoogleRtpDataCodecName; |
364 cricket::DataSendParameters parameters; | 364 cricket::DataSendParameters parameters; |
365 parameters.codecs.push_back(codec); | 365 parameters.codecs.push_back(codec); |
366 ASSERT_TRUE(dmc->SetSendParameters(parameters)); | 366 ASSERT_TRUE(dmc->SetSendParameters(parameters)); |
367 | 367 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 405 |
406 TEST_F(RtpDataMediaChannelTest, ReceiveData) { | 406 TEST_F(RtpDataMediaChannelTest, ReceiveData) { |
407 // PT= 103, SN=2, TS=3, SSRC = 4, data = "abcde" | 407 // PT= 103, SN=2, TS=3, SSRC = 4, data = "abcde" |
408 unsigned char data[] = { | 408 unsigned char data[] = { |
409 0x80, 0x67, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2A, | 409 0x80, 0x67, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2A, |
410 0x00, 0x00, 0x00, 0x00, | 410 0x00, 0x00, 0x00, 0x00, |
411 'a', 'b', 'c', 'd', 'e' | 411 'a', 'b', 'c', 'd', 'e' |
412 }; | 412 }; |
413 rtc::Buffer packet(data, sizeof(data)); | 413 rtc::Buffer packet(data, sizeof(data)); |
414 | 414 |
415 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 415 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
416 | 416 |
417 // SetReceived not called. | 417 // SetReceived not called. |
418 dmc->OnPacketReceived(&packet, rtc::PacketTime()); | 418 dmc->OnPacketReceived(&packet, rtc::PacketTime()); |
419 EXPECT_FALSE(HasReceivedData()); | 419 EXPECT_FALSE(HasReceivedData()); |
420 | 420 |
421 dmc->SetReceive(true); | 421 dmc->SetReceive(true); |
422 | 422 |
423 // Unknown payload id | 423 // Unknown payload id |
424 dmc->OnPacketReceived(&packet, rtc::PacketTime()); | 424 dmc->OnPacketReceived(&packet, rtc::PacketTime()); |
425 EXPECT_FALSE(HasReceivedData()); | 425 EXPECT_FALSE(HasReceivedData()); |
(...skipping 19 matching lines...) Expand all Loading... |
445 EXPECT_EQ("abcde", GetReceivedData()); | 445 EXPECT_EQ("abcde", GetReceivedData()); |
446 EXPECT_EQ(5U, GetReceivedDataLen()); | 446 EXPECT_EQ(5U, GetReceivedDataLen()); |
447 } | 447 } |
448 | 448 |
449 TEST_F(RtpDataMediaChannelTest, InvalidRtpPackets) { | 449 TEST_F(RtpDataMediaChannelTest, InvalidRtpPackets) { |
450 unsigned char data[] = { | 450 unsigned char data[] = { |
451 0x80, 0x65, 0x00, 0x02 | 451 0x80, 0x65, 0x00, 0x02 |
452 }; | 452 }; |
453 rtc::Buffer packet(data, sizeof(data)); | 453 rtc::Buffer packet(data, sizeof(data)); |
454 | 454 |
455 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 455 std::unique_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
456 | 456 |
457 // Too short | 457 // Too short |
458 dmc->OnPacketReceived(&packet, rtc::PacketTime()); | 458 dmc->OnPacketReceived(&packet, rtc::PacketTime()); |
459 EXPECT_FALSE(HasReceivedData()); | 459 EXPECT_FALSE(HasReceivedData()); |
460 } | 460 } |
OLD | NEW |