| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2008 Google Inc. | 3 * Copyright 2008 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "talk/media/base/fakecapturemanager.h" | 28 #include "talk/media/base/fakecapturemanager.h" |
| 29 #include "talk/media/base/fakemediaengine.h" | 29 #include "talk/media/base/fakemediaengine.h" |
| 30 #include "talk/media/base/fakemediaprocessor.h" | 30 #include "talk/media/base/fakemediaprocessor.h" |
| 31 #include "talk/media/base/testutils.h" | 31 #include "talk/media/base/testutils.h" |
| 32 #include "talk/media/devices/fakedevicemanager.h" | 32 #include "talk/media/devices/fakedevicemanager.h" |
| 33 #include "webrtc/p2p/base/fakesession.h" | |
| 34 #include "talk/session/media/channelmanager.h" | 33 #include "talk/session/media/channelmanager.h" |
| 35 #include "webrtc/base/gunit.h" | 34 #include "webrtc/base/gunit.h" |
| 36 #include "webrtc/base/logging.h" | 35 #include "webrtc/base/logging.h" |
| 37 #include "webrtc/base/thread.h" | 36 #include "webrtc/base/thread.h" |
| 37 #include "webrtc/p2p/base/faketransportcontroller.h" |
| 38 | 38 |
| 39 namespace cricket { | 39 namespace cricket { |
| 40 | 40 |
| 41 static const AudioCodec kAudioCodecs[] = { | 41 static const AudioCodec kAudioCodecs[] = { |
| 42 AudioCodec(97, "voice", 1, 2, 3, 0), | 42 AudioCodec(97, "voice", 1, 2, 3, 0), |
| 43 AudioCodec(111, "OPUS", 48000, 32000, 2, 0), | 43 AudioCodec(111, "OPUS", 48000, 32000, 2, 0), |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 static const VideoCodec kVideoCodecs[] = { | 46 static const VideoCodec kVideoCodecs[] = { |
| 47 VideoCodec(99, "H264", 100, 200, 300, 0), | 47 VideoCodec(99, "H264", 100, 200, 300, 0), |
| 48 VideoCodec(100, "VP8", 100, 200, 300, 0), | 48 VideoCodec(100, "VP8", 100, 200, 300, 0), |
| 49 VideoCodec(96, "rtx", 100, 200, 300, 0), | 49 VideoCodec(96, "rtx", 100, 200, 300, 0), |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 class ChannelManagerTest : public testing::Test { | 52 class ChannelManagerTest : public testing::Test { |
| 53 protected: | 53 protected: |
| 54 ChannelManagerTest() : fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) { | 54 ChannelManagerTest() : fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) { |
| 55 } | 55 } |
| 56 | 56 |
| 57 virtual void SetUp() { | 57 virtual void SetUp() { |
| 58 fme_ = new cricket::FakeMediaEngine(); | 58 fme_ = new cricket::FakeMediaEngine(); |
| 59 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); | 59 fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs)); |
| 60 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); | 60 fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs)); |
| 61 fdme_ = new cricket::FakeDataEngine(); | 61 fdme_ = new cricket::FakeDataEngine(); |
| 62 fdm_ = new cricket::FakeDeviceManager(); | 62 fdm_ = new cricket::FakeDeviceManager(); |
| 63 fcm_ = new cricket::FakeCaptureManager(); | 63 fcm_ = new cricket::FakeCaptureManager(); |
| 64 cm_ = new cricket::ChannelManager( | 64 cm_ = new cricket::ChannelManager( |
| 65 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); | 65 fme_, fdme_, fdm_, fcm_, rtc::Thread::Current()); |
| 66 session_ = new cricket::FakeSession(true); | 66 transport_controller_ = new cricket::FakeTransportController(true); |
| 67 | 67 |
| 68 std::vector<std::string> in_device_list, out_device_list, vid_device_list; | 68 std::vector<std::string> in_device_list, out_device_list, vid_device_list; |
| 69 in_device_list.push_back("audio-in1"); | 69 in_device_list.push_back("audio-in1"); |
| 70 in_device_list.push_back("audio-in2"); | 70 in_device_list.push_back("audio-in2"); |
| 71 out_device_list.push_back("audio-out1"); | 71 out_device_list.push_back("audio-out1"); |
| 72 out_device_list.push_back("audio-out2"); | 72 out_device_list.push_back("audio-out2"); |
| 73 vid_device_list.push_back("video-in1"); | 73 vid_device_list.push_back("video-in1"); |
| 74 vid_device_list.push_back("video-in2"); | 74 vid_device_list.push_back("video-in2"); |
| 75 fdm_->SetAudioInputDevices(in_device_list); | 75 fdm_->SetAudioInputDevices(in_device_list); |
| 76 fdm_->SetAudioOutputDevices(out_device_list); | 76 fdm_->SetAudioOutputDevices(out_device_list); |
| 77 fdm_->SetVideoCaptureDevices(vid_device_list); | 77 fdm_->SetVideoCaptureDevices(vid_device_list); |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual void TearDown() { | 80 virtual void TearDown() { |
| 81 delete session_; | 81 delete transport_controller_; |
| 82 delete cm_; | 82 delete cm_; |
| 83 cm_ = NULL; | 83 cm_ = NULL; |
| 84 fdm_ = NULL; | 84 fdm_ = NULL; |
| 85 fcm_ = NULL; | 85 fcm_ = NULL; |
| 86 fdme_ = NULL; | 86 fdme_ = NULL; |
| 87 fme_ = NULL; | 87 fme_ = NULL; |
| 88 } | 88 } |
| 89 | 89 |
| 90 rtc::Thread worker_; | 90 rtc::Thread worker_; |
| 91 cricket::FakeMediaEngine* fme_; | 91 cricket::FakeMediaEngine* fme_; |
| 92 cricket::FakeDataEngine* fdme_; | 92 cricket::FakeDataEngine* fdme_; |
| 93 cricket::FakeDeviceManager* fdm_; | 93 cricket::FakeDeviceManager* fdm_; |
| 94 cricket::FakeCaptureManager* fcm_; | 94 cricket::FakeCaptureManager* fcm_; |
| 95 cricket::ChannelManager* cm_; | 95 cricket::ChannelManager* cm_; |
| 96 cricket::FakeSession* session_; | 96 cricket::FakeTransportController* transport_controller_; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 // Test that we startup/shutdown properly. | 99 // Test that we startup/shutdown properly. |
| 100 TEST_F(ChannelManagerTest, StartupShutdown) { | 100 TEST_F(ChannelManagerTest, StartupShutdown) { |
| 101 EXPECT_FALSE(cm_->initialized()); | 101 EXPECT_FALSE(cm_->initialized()); |
| 102 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); | 102 EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread()); |
| 103 EXPECT_TRUE(cm_->Init()); | 103 EXPECT_TRUE(cm_->Init()); |
| 104 EXPECT_TRUE(cm_->initialized()); | 104 EXPECT_TRUE(cm_->initialized()); |
| 105 cm_->Terminate(); | 105 cm_->Terminate(); |
| 106 EXPECT_FALSE(cm_->initialized()); | 106 EXPECT_FALSE(cm_->initialized()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 118 // Setting the worker thread while initialized should fail. | 118 // Setting the worker thread while initialized should fail. |
| 119 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); | 119 EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current())); |
| 120 cm_->Terminate(); | 120 cm_->Terminate(); |
| 121 EXPECT_FALSE(cm_->initialized()); | 121 EXPECT_FALSE(cm_->initialized()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Test that we can create and destroy a voice and video channel. | 124 // Test that we can create and destroy a voice and video channel. |
| 125 TEST_F(ChannelManagerTest, CreateDestroyChannels) { | 125 TEST_F(ChannelManagerTest, CreateDestroyChannels) { |
| 126 EXPECT_TRUE(cm_->Init()); | 126 EXPECT_TRUE(cm_->Init()); |
| 127 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( | 127 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
| 128 session_, cricket::CN_AUDIO, false, AudioOptions()); | 128 transport_controller_, cricket::CN_AUDIO, false, AudioOptions()); |
| 129 EXPECT_TRUE(voice_channel != nullptr); | 129 EXPECT_TRUE(voice_channel != nullptr); |
| 130 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( | 130 cricket::VideoChannel* video_channel = |
| 131 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); | 131 cm_->CreateVideoChannel(transport_controller_, cricket::CN_VIDEO, false, |
| 132 VideoOptions(), voice_channel); |
| 132 EXPECT_TRUE(video_channel != nullptr); | 133 EXPECT_TRUE(video_channel != nullptr); |
| 133 cricket::DataChannel* data_channel = | 134 cricket::DataChannel* data_channel = cm_->CreateDataChannel( |
| 134 cm_->CreateDataChannel(session_, cricket::CN_DATA, | 135 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); |
| 135 false, cricket::DCT_RTP); | |
| 136 EXPECT_TRUE(data_channel != nullptr); | 136 EXPECT_TRUE(data_channel != nullptr); |
| 137 cm_->DestroyVideoChannel(video_channel); | 137 cm_->DestroyVideoChannel(video_channel); |
| 138 cm_->DestroyVoiceChannel(voice_channel, nullptr); | 138 cm_->DestroyVoiceChannel(voice_channel, nullptr); |
| 139 cm_->DestroyDataChannel(data_channel); | 139 cm_->DestroyDataChannel(data_channel); |
| 140 cm_->Terminate(); | 140 cm_->Terminate(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Test that we can create and destroy a voice and video channel with a worker. | 143 // Test that we can create and destroy a voice and video channel with a worker. |
| 144 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { | 144 TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) { |
| 145 worker_.Start(); | 145 worker_.Start(); |
| 146 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); | 146 EXPECT_TRUE(cm_->set_worker_thread(&worker_)); |
| 147 EXPECT_TRUE(cm_->Init()); | 147 EXPECT_TRUE(cm_->Init()); |
| 148 delete session_; | 148 delete transport_controller_; |
| 149 session_ = new cricket::FakeSession(&worker_, true); | 149 transport_controller_ = new cricket::FakeTransportController(&worker_, true); |
| 150 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( | 150 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
| 151 session_, cricket::CN_AUDIO, false, AudioOptions()); | 151 transport_controller_, cricket::CN_AUDIO, false, AudioOptions()); |
| 152 EXPECT_TRUE(voice_channel != nullptr); | 152 EXPECT_TRUE(voice_channel != nullptr); |
| 153 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( | 153 cricket::VideoChannel* video_channel = |
| 154 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); | 154 cm_->CreateVideoChannel(transport_controller_, cricket::CN_VIDEO, false, |
| 155 VideoOptions(), voice_channel); |
| 155 EXPECT_TRUE(video_channel != nullptr); | 156 EXPECT_TRUE(video_channel != nullptr); |
| 156 cricket::DataChannel* data_channel = | 157 cricket::DataChannel* data_channel = cm_->CreateDataChannel( |
| 157 cm_->CreateDataChannel(session_, cricket::CN_DATA, | 158 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); |
| 158 false, cricket::DCT_RTP); | |
| 159 EXPECT_TRUE(data_channel != nullptr); | 159 EXPECT_TRUE(data_channel != nullptr); |
| 160 cm_->DestroyVideoChannel(video_channel); | 160 cm_->DestroyVideoChannel(video_channel); |
| 161 cm_->DestroyVoiceChannel(voice_channel, nullptr); | 161 cm_->DestroyVoiceChannel(voice_channel, nullptr); |
| 162 cm_->DestroyDataChannel(data_channel); | 162 cm_->DestroyDataChannel(data_channel); |
| 163 cm_->Terminate(); | 163 cm_->Terminate(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // Test that we fail to create a voice/video channel if the session is unable | 166 // Test that we fail to create a voice/video channel if the session is unable |
| 167 // to create a cricket::TransportChannel | 167 // to create a cricket::TransportChannel |
| 168 TEST_F(ChannelManagerTest, NoTransportChannelTest) { | 168 TEST_F(ChannelManagerTest, NoTransportChannelTest) { |
| 169 EXPECT_TRUE(cm_->Init()); | 169 EXPECT_TRUE(cm_->Init()); |
| 170 session_->set_fail_channel_creation(true); | 170 transport_controller_->set_fail_channel_creation(true); |
| 171 // The test is useless unless the session does not fail creating | 171 // The test is useless unless the session does not fail creating |
| 172 // cricket::TransportChannel. | 172 // cricket::TransportChannel. |
| 173 ASSERT_TRUE(session_->CreateChannel( | 173 ASSERT_TRUE(transport_controller_->CreateTransportChannel_w( |
| 174 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); | 174 "audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr); |
| 175 | 175 |
| 176 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( | 176 cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel( |
| 177 session_, cricket::CN_AUDIO, false, AudioOptions()); | 177 transport_controller_, cricket::CN_AUDIO, false, AudioOptions()); |
| 178 EXPECT_TRUE(voice_channel == nullptr); | 178 EXPECT_TRUE(voice_channel == nullptr); |
| 179 cricket::VideoChannel* video_channel = cm_->CreateVideoChannel( | 179 cricket::VideoChannel* video_channel = |
| 180 session_, cricket::CN_VIDEO, false, VideoOptions(), voice_channel); | 180 cm_->CreateVideoChannel(transport_controller_, cricket::CN_VIDEO, false, |
| 181 VideoOptions(), voice_channel); |
| 181 EXPECT_TRUE(video_channel == nullptr); | 182 EXPECT_TRUE(video_channel == nullptr); |
| 182 cricket::DataChannel* data_channel = | 183 cricket::DataChannel* data_channel = cm_->CreateDataChannel( |
| 183 cm_->CreateDataChannel(session_, cricket::CN_DATA, | 184 transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP); |
| 184 false, cricket::DCT_RTP); | |
| 185 EXPECT_TRUE(data_channel == nullptr); | 185 EXPECT_TRUE(data_channel == nullptr); |
| 186 cm_->Terminate(); | 186 cm_->Terminate(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Test that SetDefaultVideoCodec passes through the right values. | 189 // Test that SetDefaultVideoCodec passes through the right values. |
| 190 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { | 190 TEST_F(ChannelManagerTest, SetDefaultVideoEncoderConfig) { |
| 191 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); | 191 cricket::VideoCodec codec(96, "G264", 1280, 720, 60, 0); |
| 192 cricket::VideoEncoderConfig config(codec, 1, 2); | 192 cricket::VideoEncoderConfig config(codec, 1, 2); |
| 193 EXPECT_TRUE(cm_->Init()); | 193 EXPECT_TRUE(cm_->Init()); |
| 194 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); | 194 EXPECT_TRUE(cm_->SetDefaultVideoEncoderConfig(config)); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); | 577 EXPECT_FALSE(cm_->SetVideoRtxEnabled(false)); |
| 578 | 578 |
| 579 // Can set again after terminate. | 579 // Can set again after terminate. |
| 580 cm_->Terminate(); | 580 cm_->Terminate(); |
| 581 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); | 581 EXPECT_TRUE(cm_->SetVideoRtxEnabled(true)); |
| 582 cm_->GetSupportedVideoCodecs(&codecs); | 582 cm_->GetSupportedVideoCodecs(&codecs); |
| 583 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); | 583 EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec)); |
| 584 } | 584 } |
| 585 | 585 |
| 586 } // namespace cricket | 586 } // namespace cricket |
| OLD | NEW |