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
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#include "webrtc/api/fakemediacontroller.h"
|
2014-08-13 17:26:08 +00:00
|
|
|
#include "webrtc/base/gunit.h"
|
|
|
|
|
#include "webrtc/base/logging.h"
|
|
|
|
|
#include "webrtc/base/thread.h"
|
2016-10-07 11:53:05 -07:00
|
|
|
#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
|
Move talk/media to webrtc/media
I removed the 'libjingle' target in talk/libjingle.gyp and replaced
all users of it with base/base.gyp:rtc_base. It seems the jsoncpp
and expat dependencies were not used by it's previous references.
The files in talk/media/testdata were uploaded to Google Storage and
added .sha1 files in resources/media instead of simply moving them.
The previously disabled warnings that were inherited from
talk/build/common.gypi are now replaced by target-specific disabling
of only the failing warnings. Additional disabling was needed since the stricter
compilation warnings that applies to code in webrtc/.
License headers will be updated in a follow-up CL in order to not
break Git history.
Other modifications:
* Updated the header guards.
* Sorted the includes using chromium/src/tools/sort-headers.py
except for these files:
talk/app/webrtc/peerconnectionendtoend_unittest.cc
talk/app/webrtc/java/jni/androidmediadecoder_jni.cc
talk/app/webrtc/java/jni/androidmediaencoder_jni.cc
webrtc/media/devices/win32devicemanager.cc.
* Unused GYP reference to libjingle_tests_additional_deps was removed.
* Removed duplicated GYP entries of
webrtc/base/testutils.cc
webrtc/base/testutils.h
The HAVE_WEBRTC_VIDEO and HAVE_WEBRTC_VOICE defines were used by only talk/media,
so they were moved to the media.gyp.
I also checked that none of
EXPAT_RELATIVE_PATH,
FEATURE_ENABLE_VOICEMAIL,
GTEST_RELATIVE_PATH,
JSONCPP_RELATIVE_PATH,
LOGGING=1,
SRTP_RELATIVE_PATH,
FEATURE_ENABLE_SSL,
FEATURE_ENABLE_VOICEMAIL,
FEATURE_ENABLE_PSTN,
HAVE_SCTP,
HAVE_SRTP,
are used by the talk/media code.
For Chromium, the following changes will need to be applied to the roll CL that updates the
DEPS for WebRTC and libjingle: https://codereview.chromium.org/1604303002/
BUG=webrtc:5420
NOPRESUBMIT=True
TBR=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/1587193006
Cr-Commit-Position: refs/heads/master@{#11495}
2016-02-04 23:52:28 -08:00
|
|
|
#include "webrtc/media/base/fakemediaengine.h"
|
|
|
|
|
#include "webrtc/media/base/fakevideocapturer.h"
|
|
|
|
|
#include "webrtc/media/base/testutils.h"
|
2016-02-12 06:39:40 +01:00
|
|
|
#include "webrtc/media/engine/fakewebrtccall.h"
|
2015-09-23 11:50:27 -07:00
|
|
|
#include "webrtc/p2p/base/faketransportcontroller.h"
|
2016-02-12 06:47:59 +01:00
|
|
|
#include "webrtc/pc/channelmanager.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2016-12-13 11:29:11 -08:00
|
|
|
namespace cricket {
|
|
|
|
|
const bool kDefaultRtcpEnabled = false;
|
|
|
|
|
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()
|
2015-10-15 07:26:07 -07:00
|
|
|
: fme_(new cricket::FakeMediaEngine()),
|
|
|
|
|
fdme_(new cricket::FakeDataEngine()),
|
2016-10-07 11:53:05 -07:00
|
|
|
cm_(new cricket::ChannelManager(fme_, fdme_, rtc::Thread::Current())),
|
|
|
|
|
fake_call_(webrtc::Call::Config(&event_log_)),
|
2015-10-15 07:26:07 -07:00
|
|
|
fake_mc_(cm_, &fake_call_),
|
|
|
|
|
transport_controller_(
|
|
|
|
|
new cricket::FakeTransportController(ICEROLE_CONTROLLING)) {}
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
virtual void SetUp() {
|
|
|
|
|
fme_->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
|
|
|
|
|
fme_->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void TearDown() {
|
2015-09-23 11:50:27 -07:00
|
|
|
delete transport_controller_;
|
2013-07-10 00:45:36 +00:00
|
|
|
delete cm_;
|
|
|
|
|
cm_ = NULL;
|
|
|
|
|
fdme_ = NULL;
|
|
|
|
|
fme_ = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-07 11:53:05 -07:00
|
|
|
webrtc::RtcEventLogNullImpl event_log_;
|
2016-05-11 19:55:27 +02:00
|
|
|
rtc::Thread network_;
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::Thread worker_;
|
2013-07-10 00:45:36 +00:00
|
|
|
cricket::FakeMediaEngine* fme_;
|
|
|
|
|
cricket::FakeDataEngine* fdme_;
|
|
|
|
|
cricket::ChannelManager* cm_;
|
2015-10-15 07:26:07 -07:00
|
|
|
cricket::FakeCall fake_call_;
|
|
|
|
|
cricket::FakeMediaController fake_mc_;
|
2015-09-23 11:50:27 -07:00
|
|
|
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) {
|
2016-05-11 19:55:27 +02:00
|
|
|
network_.Start();
|
2013-07-10 00:45:36 +00:00
|
|
|
worker_.Start();
|
|
|
|
|
EXPECT_FALSE(cm_->initialized());
|
2014-07-29 17:36:52 +00:00
|
|
|
EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
|
2016-05-11 19:55:27 +02:00
|
|
|
EXPECT_TRUE(cm_->set_network_thread(&network_));
|
|
|
|
|
EXPECT_EQ(&network_, cm_->network_thread());
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(cm_->set_worker_thread(&worker_));
|
|
|
|
|
EXPECT_EQ(&worker_, cm_->worker_thread());
|
|
|
|
|
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());
|
2016-05-17 17:49:52 -07:00
|
|
|
cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
|
2016-12-13 11:29:11 -08:00
|
|
|
&fake_mc_, transport_controller_, cricket::CN_AUDIO, nullptr,
|
|
|
|
|
kDefaultRtcpEnabled, 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(
|
2016-12-13 11:29:11 -08:00
|
|
|
&fake_mc_, transport_controller_, cricket::CN_VIDEO, nullptr,
|
|
|
|
|
kDefaultRtcpEnabled, 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(
|
2016-12-13 11:29:11 -08:00
|
|
|
&fake_mc_, transport_controller_, cricket::CN_DATA, nullptr,
|
2017-01-09 14:53:41 -08:00
|
|
|
kDefaultRtcpEnabled, kDefaultSrtpRequired);
|
|
|
|
|
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) {
|
2016-05-11 19:55:27 +02:00
|
|
|
network_.Start();
|
2013-07-10 00:45:36 +00:00
|
|
|
worker_.Start();
|
|
|
|
|
EXPECT_TRUE(cm_->set_worker_thread(&worker_));
|
2016-05-11 19:55:27 +02:00
|
|
|
EXPECT_TRUE(cm_->set_network_thread(&network_));
|
2013-07-10 00:45:36 +00:00
|
|
|
EXPECT_TRUE(cm_->Init());
|
2015-09-23 11:50:27 -07:00
|
|
|
delete transport_controller_;
|
|
|
|
|
transport_controller_ =
|
2016-05-11 19:55:27 +02:00
|
|
|
new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING);
|
2016-05-17 17:49:52 -07:00
|
|
|
cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
|
2016-12-13 11:29:11 -08:00
|
|
|
&fake_mc_, transport_controller_, cricket::CN_AUDIO, nullptr,
|
|
|
|
|
kDefaultRtcpEnabled, 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(
|
2016-12-13 11:29:11 -08:00
|
|
|
&fake_mc_, transport_controller_, cricket::CN_VIDEO, nullptr,
|
|
|
|
|
kDefaultRtcpEnabled, 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(
|
2016-12-13 11:29:11 -08:00
|
|
|
&fake_mc_, transport_controller_, cricket::CN_DATA, nullptr,
|
2017-01-09 14:53:41 -08:00
|
|
|
kDefaultRtcpEnabled, kDefaultSrtpRequired);
|
|
|
|
|
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
|