2015-01-20 21:36:13 +00:00
|
|
|
/*
|
2016-02-12 00:05:01 -08:00
|
|
|
* Copyright 2008 The WebRTC project authors. All Rights Reserved.
|
2015-01-20 21:36:13 +00:00
|
|
|
*
|
2016-02-12 00:05:01 -08:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2015-01-20 21:36:13 +00:00
|
|
|
*/
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-02-10 20:13:37 -08:00
|
|
|
#include <memory>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "logging/rtc_event_log/rtc_event_log.h"
|
|
|
|
|
#include "media/base/fakemediaengine.h"
|
|
|
|
|
#include "media/base/fakevideocapturer.h"
|
|
|
|
|
#include "media/base/testutils.h"
|
|
|
|
|
#include "media/engine/fakewebrtccall.h"
|
|
|
|
|
#include "pc/channelmanager.h"
|
2017-09-29 10:51:43 -07:00
|
|
|
#include "pc/test/faketransportcontroller.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gunit.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
|
|
|
|
#include "rtc_base/thread.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2017-02-10 23:44:49 -08:00
|
|
|
namespace {
|
2016-12-13 11:29:11 -08:00
|
|
|
const bool kDefaultSrtpRequired = true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
namespace cricket {
|
|
|
|
|
|
|
|
|
|
static const AudioCodec kAudioCodecs[] = {
|
2016-04-13 10:07:16 -07:00
|
|
|
AudioCodec(97, "voice", 1, 2, 3), AudioCodec(111, "OPUS", 48000, 32000, 2),
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const VideoCodec kVideoCodecs[] = {
|
2016-10-24 01:21:16 -07:00
|
|
|
VideoCodec(99, "H264"), VideoCodec(100, "VP8"), VideoCodec(96, "rtx"),
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ChannelManagerTest : public testing::Test {
|
|
|
|
|
protected:
|
2015-09-23 11:50:27 -07:00
|
|
|
ChannelManagerTest()
|
2017-07-14 14:44:46 -07:00
|
|
|
: network_(rtc::Thread::CreateWithSocketServer()),
|
|
|
|
|
worker_(rtc::Thread::Create()),
|
|
|
|
|
fme_(new cricket::FakeMediaEngine()),
|
2015-10-15 07:26:07 -07:00
|
|
|
fdme_(new cricket::FakeDataEngine()),
|
2017-02-10 20:13:37 -08:00
|
|
|
cm_(new cricket::ChannelManager(
|
|
|
|
|
std::unique_ptr<MediaEngineInterface>(fme_),
|
|
|
|
|
std::unique_ptr<DataEngineInterface>(fdme_),
|
2017-11-06 15:40:09 -08:00
|
|
|
rtc::Thread::Current(),
|
2017-02-10 20:13:37 -08:00
|
|
|
rtc::Thread::Current())),
|
2016-10-07 11:53:05 -07:00
|
|
|
fake_call_(webrtc::Call::Config(&event_log_)),
|
2015-10-15 07:26:07 -07:00
|
|
|
transport_controller_(
|
2017-02-10 20:13:37 -08:00
|
|
|
new cricket::FakeTransportController(ICEROLE_CONTROLLING)) {
|
2013-07-10 00:45:36 +00:00
|
|
|
fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
|
|
|
|
|
fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 11:53:05 -07:00
|
|
|
webrtc::RtcEventLogNullImpl event_log_;
|
2017-07-14 14:44:46 -07:00
|
|
|
std::unique_ptr<rtc::Thread> network_;
|
|
|
|
|
std::unique_ptr<rtc::Thread> worker_;
|
2017-02-10 20:13:37 -08:00
|
|
|
// |fme_| and |fdme_| are actually owned by |cm_|.
|
2013-07-10 00:45:36 +00:00
|
|
|
cricket::FakeMediaEngine* fme_;
|
|
|
|
|
cricket::FakeDataEngine* fdme_;
|
2017-02-10 20:13:37 -08:00
|
|
|
std::unique_ptr<cricket::ChannelManager> cm_;
|
2015-10-15 07:26:07 -07:00
|
|
|
cricket::FakeCall fake_call_;
|
2017-02-10 20:13:37 -08:00
|
|
|
std::unique_ptr<cricket::FakeTransportController> transport_controller_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Test that we startup/shutdown properly.
|
|
|
|
|
TEST_F(ChannelManagerTest, StartupShutdown) {
|
|
|
|
|
EXPECT_FALSE(cm_->initialized());
|
2014-07-29 17:36:52 +00:00
|
|
|
EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(cm_->Init());
|
|
|
|
|
EXPECT_TRUE(cm_->initialized());
|
|
|
|
|
cm_->Terminate();
|
|
|
|
|
EXPECT_FALSE(cm_->initialized());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that we startup/shutdown properly with a worker thread.
|
|
|
|
|
TEST_F(ChannelManagerTest, StartupShutdownOnThread) {
|
2017-07-14 14:44:46 -07:00
|
|
|
network_->Start();
|
|
|
|
|
worker_->Start();
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_FALSE(cm_->initialized());
|
2014-07-29 17:36:52 +00:00
|
|
|
EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
|
2017-07-14 14:44:46 -07:00
|
|
|
EXPECT_TRUE(cm_->set_network_thread(network_.get()));
|
|
|
|
|
EXPECT_EQ(network_.get(), cm_->network_thread());
|
|
|
|
|
EXPECT_TRUE(cm_->set_worker_thread(worker_.get()));
|
|
|
|
|
EXPECT_EQ(worker_.get(), cm_->worker_thread());
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(cm_->Init());
|
|
|
|
|
EXPECT_TRUE(cm_->initialized());
|
2016-05-11 19:55:27 +02:00
|
|
|
// Setting the network or worker thread while initialized should fail.
|
|
|
|
|
EXPECT_FALSE(cm_->set_network_thread(rtc::Thread::Current()));
|
2014-07-29 17:36:52 +00:00
|
|
|
EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current()));
|
2013-07-10 00:45:36 +00:00
|
|
|
cm_->Terminate();
|
|
|
|
|
EXPECT_FALSE(cm_->initialized());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that we can create and destroy a voice and video channel.
|
|
|
|
|
TEST_F(ChannelManagerTest, CreateDestroyChannels) {
|
|
|
|
|
EXPECT_TRUE(cm_->Init());
|
2017-01-19 16:54:25 -08:00
|
|
|
cricket::DtlsTransportInternal* rtp_transport =
|
|
|
|
|
transport_controller_->CreateDtlsTransport(
|
2017-01-12 19:37:48 -08:00
|
|
|
cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
2016-05-17 17:49:52 -07:00
|
|
|
cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
&fake_call_, cricket::MediaConfig(),
|
|
|
|
|
rtp_transport, nullptr /*rtcp_transport*/,
|
2017-02-10 23:44:49 -08:00
|
|
|
rtc::Thread::Current(), cricket::CN_AUDIO, kDefaultSrtpRequired,
|
|
|
|
|
AudioOptions());
|
2015-05-29 15:05:44 +02:00
|
|
|
EXPECT_TRUE(voice_channel != nullptr);
|
2016-05-17 17:49:52 -07:00
|
|
|
cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
&fake_call_, cricket::MediaConfig(),
|
|
|
|
|
rtp_transport, nullptr /*rtcp_transport*/,
|
2017-02-10 23:44:49 -08:00
|
|
|
rtc::Thread::Current(), cricket::CN_VIDEO, kDefaultSrtpRequired,
|
|
|
|
|
VideoOptions());
|
2015-05-29 15:05:44 +02:00
|
|
|
EXPECT_TRUE(video_channel != nullptr);
|
2017-01-09 14:53:41 -08:00
|
|
|
cricket::RtpDataChannel* rtp_data_channel = cm_->CreateRtpDataChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
cricket::MediaConfig(), rtp_transport, nullptr /*rtcp_transport*/,
|
2017-02-10 23:44:49 -08:00
|
|
|
rtc::Thread::Current(), cricket::CN_DATA, kDefaultSrtpRequired);
|
2017-01-09 14:53:41 -08:00
|
|
|
EXPECT_TRUE(rtp_data_channel != nullptr);
|
2013-07-10 00:45:36 +00:00
|
|
|
cm_->DestroyVideoChannel(video_channel);
|
2015-09-15 12:26:33 +02:00
|
|
|
cm_->DestroyVoiceChannel(voice_channel);
|
2017-01-09 14:53:41 -08:00
|
|
|
cm_->DestroyRtpDataChannel(rtp_data_channel);
|
2013-07-10 00:45:36 +00:00
|
|
|
cm_->Terminate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test that we can create and destroy a voice and video channel with a worker.
|
2013-09-27 23:04:10 +00:00
|
|
|
TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
|
2017-07-14 14:44:46 -07:00
|
|
|
network_->Start();
|
|
|
|
|
worker_->Start();
|
|
|
|
|
EXPECT_TRUE(cm_->set_worker_thread(worker_.get()));
|
|
|
|
|
EXPECT_TRUE(cm_->set_network_thread(network_.get()));
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(cm_->Init());
|
2017-07-14 14:44:46 -07:00
|
|
|
transport_controller_.reset(new cricket::FakeTransportController(
|
|
|
|
|
network_.get(), ICEROLE_CONTROLLING));
|
2017-01-19 16:54:25 -08:00
|
|
|
cricket::DtlsTransportInternal* rtp_transport =
|
|
|
|
|
transport_controller_->CreateDtlsTransport(
|
2017-01-12 19:37:48 -08:00
|
|
|
cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP);
|
2016-05-17 17:49:52 -07:00
|
|
|
cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
&fake_call_, cricket::MediaConfig(),
|
|
|
|
|
rtp_transport, nullptr /*rtcp_transport*/,
|
2017-02-10 23:44:49 -08:00
|
|
|
rtc::Thread::Current(), cricket::CN_AUDIO, kDefaultSrtpRequired,
|
|
|
|
|
AudioOptions());
|
2015-05-29 15:05:44 +02:00
|
|
|
EXPECT_TRUE(voice_channel != nullptr);
|
2016-05-17 17:49:52 -07:00
|
|
|
cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
&fake_call_, cricket::MediaConfig(),
|
|
|
|
|
rtp_transport, nullptr /*rtcp_transport*/,
|
2017-02-10 23:44:49 -08:00
|
|
|
rtc::Thread::Current(), cricket::CN_VIDEO, kDefaultSrtpRequired,
|
|
|
|
|
VideoOptions());
|
2015-05-29 15:05:44 +02:00
|
|
|
EXPECT_TRUE(video_channel != nullptr);
|
2017-01-09 14:53:41 -08:00
|
|
|
cricket::RtpDataChannel* rtp_data_channel = cm_->CreateRtpDataChannel(
|
2017-05-05 02:23:02 -07:00
|
|
|
cricket::MediaConfig(), rtp_transport, nullptr /*rtcp_transport*/,
|
2017-02-10 23:44:49 -08:00
|
|
|
rtc::Thread::Current(), cricket::CN_DATA, kDefaultSrtpRequired);
|
2017-01-09 14:53:41 -08:00
|
|
|
EXPECT_TRUE(rtp_data_channel != nullptr);
|
2013-07-10 00:45:36 +00:00
|
|
|
cm_->DestroyVideoChannel(video_channel);
|
2015-09-15 12:26:33 +02:00
|
|
|
cm_->DestroyVoiceChannel(voice_channel);
|
2017-01-09 14:53:41 -08:00
|
|
|
cm_->DestroyRtpDataChannel(rtp_data_channel);
|
2013-07-10 00:45:36 +00:00
|
|
|
cm_->Terminate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ChannelManagerTest, SetVideoRtxEnabled) {
|
|
|
|
|
std::vector<VideoCodec> codecs;
|
2016-10-24 01:21:16 -07:00
|
|
|
const VideoCodec rtx_codec(96, "rtx");
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// By default RTX is disabled.
|
2016-11-10 03:36:53 -08:00
|
|
|
cm_->GetSupportedVideoCodecs(&codecs);
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
|
|
|
|
|
|
|
|
|
|
// Enable and check.
|
|
|
|
|
EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
|
2016-11-10 03:36:53 -08:00
|
|
|
cm_->GetSupportedVideoCodecs(&codecs);
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
|
|
|
|
|
|
|
|
|
|
// Disable and check.
|
|
|
|
|
EXPECT_TRUE(cm_->SetVideoRtxEnabled(false));
|
2016-11-10 03:36:53 -08:00
|
|
|
cm_->GetSupportedVideoCodecs(&codecs);
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_FALSE(ContainsMatchingCodec(codecs, rtx_codec));
|
|
|
|
|
|
|
|
|
|
// Cannot toggle rtx after initialization.
|
|
|
|
|
EXPECT_TRUE(cm_->Init());
|
|
|
|
|
EXPECT_FALSE(cm_->SetVideoRtxEnabled(true));
|
|
|
|
|
EXPECT_FALSE(cm_->SetVideoRtxEnabled(false));
|
|
|
|
|
|
|
|
|
|
// Can set again after terminate.
|
|
|
|
|
cm_->Terminate();
|
|
|
|
|
EXPECT_TRUE(cm_->SetVideoRtxEnabled(true));
|
2016-11-10 03:36:53 -08:00
|
|
|
cm_->GetSupportedVideoCodecs(&codecs);
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(ContainsMatchingCodec(codecs, rtx_codec));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace cricket
|