OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2009 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 "webrtc/base/arraysize.h" | 11 #include "webrtc/base/arraysize.h" |
| 12 #include "webrtc/base/criticalsection.h" |
12 #include "webrtc/base/fileutils.h" | 13 #include "webrtc/base/fileutils.h" |
13 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
14 #include "webrtc/base/helpers.h" | 15 #include "webrtc/base/helpers.h" |
15 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
16 #include "webrtc/base/pathutils.h" | 17 #include "webrtc/base/pathutils.h" |
17 #include "webrtc/base/signalthread.h" | 18 #include "webrtc/base/signalthread.h" |
18 #include "webrtc/base/ssladapter.h" | 19 #include "webrtc/base/ssladapter.h" |
19 #include "webrtc/base/sslidentity.h" | 20 #include "webrtc/base/sslidentity.h" |
20 #include "webrtc/base/window.h" | 21 #include "webrtc/base/window.h" |
21 #include "webrtc/media/base/fakemediaengine.h" | 22 #include "webrtc/media/base/fakemediaengine.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content); | 402 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content); |
402 AddLegacyStreamInContent(ssrc, 0, &content); | 403 AddLegacyStreamInContent(ssrc, 0, &content); |
403 sdesc->AddContent("DUMMY_CONTENT_NAME", | 404 sdesc->AddContent("DUMMY_CONTENT_NAME", |
404 cricket::NS_JINGLE_RTP, content.Copy()); | 405 cricket::NS_JINGLE_RTP, content.Copy()); |
405 return sdesc; | 406 return sdesc; |
406 } | 407 } |
407 | 408 |
408 class CallThread : public rtc::SignalThread { | 409 class CallThread : public rtc::SignalThread { |
409 public: | 410 public: |
410 typedef bool (ChannelTest<T>::*Method)(); | 411 typedef bool (ChannelTest<T>::*Method)(); |
411 CallThread(ChannelTest<T>* obj, Method method, bool* result) | 412 CallThread(ChannelTest<T>* obj, Method method, bool* result = nullptr) |
412 : obj_(obj), | 413 : obj_(obj), |
413 method_(method), | 414 method_(method), |
414 result_(result) { | 415 result_(false), |
415 *result = false; | 416 result_ptr_(result) { |
| 417 if (result_ptr_) |
| 418 *result_ptr_ = false; |
416 } | 419 } |
417 virtual void DoWork() { | 420 |
418 bool result = (*obj_.*method_)(); | 421 ~CallThread() { |
419 if (result_) { | 422 if (result_ptr_) { |
420 *result_ = result; | 423 rtc::CritScope cs(&result_lock_); |
| 424 *result_ptr_ = result_; |
421 } | 425 } |
422 } | 426 } |
| 427 |
| 428 virtual void DoWork() { |
| 429 SetResult((*obj_.*method_)()); |
| 430 } |
| 431 |
| 432 bool result() { |
| 433 rtc::CritScope cs(&result_lock_); |
| 434 return result_; |
| 435 } |
| 436 |
423 private: | 437 private: |
| 438 void SetResult(const bool& result) { |
| 439 rtc::CritScope cs(&result_lock_); |
| 440 result_ = result; |
| 441 } |
| 442 |
424 ChannelTest<T>* obj_; | 443 ChannelTest<T>* obj_; |
425 Method method_; | 444 Method method_; |
426 bool* result_; | 445 rtc::CriticalSection result_lock_; |
| 446 bool result_ GUARDED_BY(result_lock_); |
| 447 bool* result_ptr_; |
427 }; | 448 }; |
428 void CallOnThread(typename CallThread::Method method, bool* result) { | 449 |
429 CallThread* thread = new CallThread(this, method, result); | 450 // Will manage the lifetime of a CallThread, making sure it's |
430 thread->Start(); | 451 // destroyed before this object goes out of scope. |
431 thread->Release(); | 452 class ScopedCallThread { |
432 } | 453 public: |
| 454 using Method = typename CallThread::Method; |
| 455 |
| 456 ScopedCallThread(ChannelTest<T>* obj, Method method) |
| 457 : thread_(new CallThread(obj, method)) { |
| 458 thread_->Start(); |
| 459 } |
| 460 |
| 461 ~ScopedCallThread() { |
| 462 thread_->Destroy(true); |
| 463 } |
| 464 |
| 465 bool result() const { return thread_->result(); } |
| 466 |
| 467 private: |
| 468 CallThread* thread_; |
| 469 }; |
433 | 470 |
434 void CallOnThreadAndWaitForDone(typename CallThread::Method method, | 471 void CallOnThreadAndWaitForDone(typename CallThread::Method method, |
435 bool* result) { | 472 bool* result) { |
436 CallThread* thread = new CallThread(this, method, result); | 473 CallThread* thread = new CallThread(this, method, result); |
437 thread->Start(); | 474 thread->Start(); |
438 thread->Destroy(true); | 475 thread->Destroy(true); |
439 } | 476 } |
440 | 477 |
441 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) { | 478 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) { |
442 return false; // overridden in specialized classes | 479 return false; // overridden in specialized classes |
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1)); | 1356 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1)); |
1320 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); | 1357 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); |
1321 EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); | 1358 EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); |
1322 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); | 1359 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); |
1323 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2)); | 1360 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2)); |
1324 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); | 1361 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); |
1325 } | 1362 } |
1326 | 1363 |
1327 // Test that we properly send RTP without SRTP from a thread. | 1364 // Test that we properly send RTP without SRTP from a thread. |
1328 void SendRtpToRtpOnThread() { | 1365 void SendRtpToRtpOnThread() { |
1329 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2; | |
1330 CreateChannels(RTCP, RTCP); | 1366 CreateChannels(RTCP, RTCP); |
1331 EXPECT_TRUE(SendInitiate()); | 1367 EXPECT_TRUE(SendInitiate()); |
1332 EXPECT_TRUE(SendAccept()); | 1368 EXPECT_TRUE(SendAccept()); |
1333 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1); | 1369 ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1); |
1334 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2); | 1370 ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2); |
1335 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1); | 1371 ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1); |
1336 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2); | 1372 ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2); |
1337 EXPECT_TRUE_WAIT(CheckRtp1(), 1000); | 1373 EXPECT_TRUE_WAIT(CheckRtp1(), 1000); |
1338 EXPECT_TRUE_WAIT(CheckRtp2(), 1000); | 1374 EXPECT_TRUE_WAIT(CheckRtp2(), 1000); |
1339 EXPECT_TRUE_WAIT(sent_rtp1, 1000); | 1375 EXPECT_TRUE_WAIT(send_rtp1.result(), 1000); |
1340 EXPECT_TRUE_WAIT(sent_rtp2, 1000); | 1376 EXPECT_TRUE_WAIT(send_rtp2.result(), 1000); |
1341 EXPECT_TRUE(CheckNoRtp1()); | 1377 EXPECT_TRUE(CheckNoRtp1()); |
1342 EXPECT_TRUE(CheckNoRtp2()); | 1378 EXPECT_TRUE(CheckNoRtp2()); |
1343 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000); | 1379 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000); |
1344 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000); | 1380 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000); |
1345 EXPECT_TRUE_WAIT(sent_rtcp1, 1000); | 1381 EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000); |
1346 EXPECT_TRUE_WAIT(sent_rtcp2, 1000); | 1382 EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000); |
1347 EXPECT_TRUE(CheckNoRtcp1()); | 1383 EXPECT_TRUE(CheckNoRtcp1()); |
1348 EXPECT_TRUE(CheckNoRtcp2()); | 1384 EXPECT_TRUE(CheckNoRtcp2()); |
1349 } | 1385 } |
1350 | 1386 |
1351 // Test that we properly send SRTP with RTCP from a thread. | 1387 // Test that we properly send SRTP with RTCP from a thread. |
1352 void SendSrtpToSrtpOnThread() { | 1388 void SendSrtpToSrtpOnThread() { |
1353 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2; | |
1354 CreateChannels(RTCP | SECURE, RTCP | SECURE); | 1389 CreateChannels(RTCP | SECURE, RTCP | SECURE); |
1355 EXPECT_TRUE(SendInitiate()); | 1390 EXPECT_TRUE(SendInitiate()); |
1356 EXPECT_TRUE(SendAccept()); | 1391 EXPECT_TRUE(SendAccept()); |
1357 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1); | 1392 ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1); |
1358 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2); | 1393 ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2); |
1359 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1); | 1394 ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1); |
1360 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2); | 1395 ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2); |
1361 EXPECT_TRUE_WAIT(CheckRtp1(), 1000); | 1396 EXPECT_TRUE_WAIT(CheckRtp1(), 1000); |
1362 EXPECT_TRUE_WAIT(CheckRtp2(), 1000); | 1397 EXPECT_TRUE_WAIT(CheckRtp2(), 1000); |
1363 EXPECT_TRUE_WAIT(sent_rtp1, 1000); | 1398 EXPECT_TRUE_WAIT(send_rtp1.result(), 1000); |
1364 EXPECT_TRUE_WAIT(sent_rtp2, 1000); | 1399 EXPECT_TRUE_WAIT(send_rtp2.result(), 1000); |
1365 EXPECT_TRUE(CheckNoRtp1()); | 1400 EXPECT_TRUE(CheckNoRtp1()); |
1366 EXPECT_TRUE(CheckNoRtp2()); | 1401 EXPECT_TRUE(CheckNoRtp2()); |
1367 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000); | 1402 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000); |
1368 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000); | 1403 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000); |
1369 EXPECT_TRUE_WAIT(sent_rtcp1, 1000); | 1404 EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000); |
1370 EXPECT_TRUE_WAIT(sent_rtcp2, 1000); | 1405 EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000); |
1371 EXPECT_TRUE(CheckNoRtcp1()); | 1406 EXPECT_TRUE(CheckNoRtcp1()); |
1372 EXPECT_TRUE(CheckNoRtcp2()); | 1407 EXPECT_TRUE(CheckNoRtcp2()); |
1373 } | 1408 } |
1374 | 1409 |
1375 // Test that the mediachannel retains its sending state after the transport | 1410 // Test that the mediachannel retains its sending state after the transport |
1376 // becomes non-writable. | 1411 // becomes non-writable. |
1377 void SendWithWritabilityLoss() { | 1412 void SendWithWritabilityLoss() { |
1378 CreateChannels(0, 0); | 1413 CreateChannels(0, 0); |
1379 EXPECT_TRUE(SendInitiate()); | 1414 EXPECT_TRUE(SendInitiate()); |
1380 EXPECT_TRUE(SendAccept()); | 1415 EXPECT_TRUE(SendAccept()); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 CreateSessionDescriptionWithStream(3)); | 1653 CreateSessionDescriptionWithStream(3)); |
1619 EXPECT_TRUE(channel1_->PushdownRemoteDescription( | 1654 EXPECT_TRUE(channel1_->PushdownRemoteDescription( |
1620 sdesc3.get(), cricket::CA_ANSWER, &err)); | 1655 sdesc3.get(), cricket::CA_ANSWER, &err)); |
1621 EXPECT_TRUE(media_channel1_->HasSendStream(1)); | 1656 EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
1622 EXPECT_FALSE(media_channel1_->HasRecvStream(2)); | 1657 EXPECT_FALSE(media_channel1_->HasRecvStream(2)); |
1623 EXPECT_TRUE(media_channel1_->HasRecvStream(3)); | 1658 EXPECT_TRUE(media_channel1_->HasRecvStream(3)); |
1624 } | 1659 } |
1625 | 1660 |
1626 void TestFlushRtcp() { | 1661 void TestFlushRtcp() { |
1627 bool send_rtcp1; | 1662 bool send_rtcp1; |
1628 | |
1629 CreateChannels(RTCP, RTCP); | 1663 CreateChannels(RTCP, RTCP); |
1630 EXPECT_TRUE(SendInitiate()); | 1664 EXPECT_TRUE(SendInitiate()); |
1631 EXPECT_TRUE(SendAccept()); | 1665 EXPECT_TRUE(SendAccept()); |
1632 ASSERT_TRUE(GetTransport1()); | 1666 ASSERT_TRUE(GetTransport1()); |
1633 ASSERT_TRUE(GetTransport2()); | 1667 ASSERT_TRUE(GetTransport2()); |
1634 EXPECT_EQ(2U, GetTransport1()->channels().size()); | 1668 EXPECT_EQ(2U, GetTransport1()->channels().size()); |
1635 EXPECT_EQ(2U, GetTransport2()->channels().size()); | 1669 EXPECT_EQ(2U, GetTransport2()->channels().size()); |
1636 | 1670 |
1637 // Send RTCP1 from a different thread. | 1671 // Send RTCP1 from a different thread. |
1638 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1); | 1672 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1); |
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2690 }; | 2724 }; |
2691 rtc::Buffer payload(data, 3); | 2725 rtc::Buffer payload(data, 3); |
2692 cricket::SendDataResult result; | 2726 cricket::SendDataResult result; |
2693 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); | 2727 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); |
2694 EXPECT_EQ(params.ssrc, | 2728 EXPECT_EQ(params.ssrc, |
2695 media_channel1_->last_sent_data_params().ssrc); | 2729 media_channel1_->last_sent_data_params().ssrc); |
2696 EXPECT_EQ("foo", media_channel1_->last_sent_data()); | 2730 EXPECT_EQ("foo", media_channel1_->last_sent_data()); |
2697 } | 2731 } |
2698 | 2732 |
2699 // TODO(pthatcher): TestSetReceiver? | 2733 // TODO(pthatcher): TestSetReceiver? |
OLD | NEW |