You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
6.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * libjingle
  3. * Copyright 2012, Google Inc.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  19. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  20. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  22. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  23. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include <string>
  26. #include "talk/app/webrtc/fakeportallocatorfactory.h"
  27. #include "talk/app/webrtc/mediastreaminterface.h"
  28. #include "talk/app/webrtc/peerconnectionfactory.h"
  29. #include "talk/app/webrtc/videosourceinterface.h"
  30. #include "talk/app/webrtc/test/fakevideotrackrenderer.h"
  31. #include "talk/base/gunit.h"
  32. #include "talk/base/scoped_ptr.h"
  33. #include "talk/base/thread.h"
  34. #include "talk/media/base/fakevideocapturer.h"
  35. #include "talk/media/webrtc/webrtccommon.h"
  36. #include "talk/media/webrtc/webrtcvoe.h"
  37. using webrtc::FakeVideoTrackRenderer;
  38. using webrtc::MediaStreamInterface;
  39. using webrtc::PeerConnectionFactoryInterface;
  40. using webrtc::PeerConnectionInterface;
  41. using webrtc::PeerConnectionObserver;
  42. using webrtc::PortAllocatorFactoryInterface;
  43. using webrtc::VideoSourceInterface;
  44. using webrtc::VideoTrackInterface;
  45. namespace {
  46. static const char kStunIceServer[] = "stun:stun.l.google.com:19302";
  47. static const char kTurnIceServer[] = "turn:test@test.com:1234";
  48. static const char kInvalidTurnIceServer[] = "turn:test.com:1234";
  49. static const char kTurnPassword[] = "turnpassword";
  50. class NullPeerConnectionObserver : public PeerConnectionObserver {
  51. public:
  52. virtual void OnError() {}
  53. virtual void OnMessage(const std::string& msg) {}
  54. virtual void OnSignalingMessage(const std::string& msg) {}
  55. virtual void OnSignalingChange(
  56. PeerConnectionInterface::SignalingState new_state) {}
  57. virtual void OnAddStream(MediaStreamInterface* stream) {}
  58. virtual void OnRemoveStream(MediaStreamInterface* stream) {}
  59. virtual void OnRenegotiationNeeded() {}
  60. virtual void OnIceConnectionChange(
  61. PeerConnectionInterface::IceConnectionState new_state) {}
  62. virtual void OnIceGatheringChange(
  63. PeerConnectionInterface::IceGatheringState new_state) {}
  64. virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {}
  65. };
  66. } // namespace
  67. class PeerConnectionFactoryTest : public testing::Test {
  68. void SetUp() {
  69. factory_ = webrtc::CreatePeerConnectionFactory(talk_base::Thread::Current(),
  70. talk_base::Thread::Current(),
  71. NULL);
  72. ASSERT_TRUE(factory_.get() != NULL);
  73. allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
  74. }
  75. protected:
  76. talk_base::scoped_refptr<PeerConnectionFactoryInterface> factory_;
  77. NullPeerConnectionObserver observer_;
  78. talk_base::scoped_refptr<PortAllocatorFactoryInterface> allocator_factory_;
  79. };
  80. TEST(PeerConnectionFactoryTestInternal, CreatePCUsingInternalModules) {
  81. talk_base::scoped_refptr<PeerConnectionFactoryInterface> factory(
  82. webrtc::CreatePeerConnectionFactory());
  83. NullPeerConnectionObserver observer;
  84. webrtc::PeerConnectionInterface::IceServers servers;
  85. talk_base::scoped_refptr<PeerConnectionInterface> pc(
  86. factory->CreatePeerConnection(servers, NULL, &observer));
  87. EXPECT_TRUE(pc.get() != NULL);
  88. }
  89. TEST_F(PeerConnectionFactoryTest, CreatePCUsingIceServers) {
  90. webrtc::PeerConnectionInterface::IceServers ice_servers;
  91. webrtc::PeerConnectionInterface::IceServer ice_server;
  92. ice_server.uri = kStunIceServer;
  93. ice_servers.push_back(ice_server);
  94. ice_server.uri = kTurnIceServer;
  95. ice_server.password = kTurnPassword;
  96. ice_servers.push_back(ice_server);
  97. talk_base::scoped_refptr<PeerConnectionInterface> pc(
  98. factory_->CreatePeerConnection(ice_servers, NULL,
  99. allocator_factory_.get(),
  100. &observer_));
  101. EXPECT_TRUE(pc.get() != NULL);
  102. }
  103. TEST_F(PeerConnectionFactoryTest, CreatePCUsingInvalidTurnUrl) {
  104. webrtc::PeerConnectionInterface::IceServers ice_servers;
  105. webrtc::PeerConnectionInterface::IceServer ice_server;
  106. ice_server.uri = kInvalidTurnIceServer;
  107. ice_server.password = kTurnPassword;
  108. ice_servers.push_back(ice_server);
  109. talk_base::scoped_refptr<PeerConnectionInterface> pc(
  110. factory_->CreatePeerConnection(ice_servers, NULL,
  111. allocator_factory_.get(),
  112. &observer_));
  113. EXPECT_TRUE(pc.get() == NULL);
  114. }
  115. TEST_F(PeerConnectionFactoryTest, LocalRendering) {
  116. cricket::FakeVideoCapturer* capturer = new cricket::FakeVideoCapturer();
  117. // The source take ownership of |capturer|.
  118. talk_base::scoped_refptr<VideoSourceInterface> source(
  119. factory_->CreateVideoSource(capturer, NULL));
  120. ASSERT_TRUE(source.get() != NULL);
  121. talk_base::scoped_refptr<VideoTrackInterface> track(
  122. factory_->CreateVideoTrack("testlabel", source));
  123. ASSERT_TRUE(track.get() != NULL);
  124. FakeVideoTrackRenderer local_renderer(track);
  125. EXPECT_EQ(0, local_renderer.num_rendered_frames());
  126. EXPECT_TRUE(capturer->CaptureFrame());
  127. EXPECT_EQ(1, local_renderer.num_rendered_frames());
  128. track->set_enabled(false);
  129. EXPECT_TRUE(capturer->CaptureFrame());
  130. EXPECT_EQ(1, local_renderer.num_rendered_frames());
  131. track->set_enabled(true);
  132. EXPECT_TRUE(capturer->CaptureFrame());
  133. EXPECT_EQ(2, local_renderer.num_rendered_frames());
  134. }