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
|
|
|
|
2019-05-21 11:12:57 -07:00
|
|
|
#include "pc/channel_manager.h"
|
|
|
|
|
|
2022-02-23 13:44:59 +00:00
|
|
|
#include "api/sequence_checker.h"
|
2019-04-17 07:38:40 +02:00
|
|
|
#include "api/video/builtin_video_bitrate_allocator_factory.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "media/base/fake_media_engine.h"
|
|
|
|
|
#include "media/base/test_utils.h"
|
|
|
|
|
#include "media/engine/fake_webrtc_call.h"
|
|
|
|
|
#include "p2p/base/fake_dtls_transport.h"
|
|
|
|
|
#include "p2p/base/p2p_constants.h"
|
|
|
|
|
#include "pc/dtls_srtp_transport.h"
|
2022-02-23 13:44:59 +00:00
|
|
|
#include "pc/rtp_transport_internal.h"
|
|
|
|
|
#include "rtc_base/arraysize.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/checks.h"
|
2022-02-23 13:44:59 +00:00
|
|
|
#include "rtc_base/location.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2022-03-09 09:28:10 +01:00
|
|
|
#include "test/scoped_key_value_config.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
2021-04-01 16:49:42 +02:00
|
|
|
namespace cricket {
|
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
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2021-04-01 16:49:42 +02:00
|
|
|
std::unique_ptr<MediaEngineInterface> CreateFakeMediaEngine() {
|
|
|
|
|
auto fme = std::make_unique<FakeMediaEngine>();
|
|
|
|
|
fme->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
|
|
|
|
|
fme->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
|
|
|
|
|
return fme;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2019-04-09 15:11:12 +02:00
|
|
|
class ChannelManagerTest : public ::testing::Test {
|
2013-07-10 00:45:36 +00:00
|
|
|
protected:
|
2015-09-23 11:50:27 -07:00
|
|
|
ChannelManagerTest()
|
2017-07-14 14:44:46 -07:00
|
|
|
: network_(rtc::Thread::CreateWithSocketServer()),
|
2021-04-01 16:49:42 +02:00
|
|
|
worker_(rtc::Thread::Current()),
|
2019-04-17 07:38:40 +02:00
|
|
|
video_bitrate_allocator_factory_(
|
|
|
|
|
webrtc::CreateBuiltinVideoBitrateAllocatorFactory()),
|
2021-04-01 16:49:42 +02:00
|
|
|
cm_(cricket::ChannelManager::Create(CreateFakeMediaEngine(),
|
|
|
|
|
false,
|
|
|
|
|
worker_,
|
|
|
|
|
network_.get())),
|
2021-04-19 09:21:06 +02:00
|
|
|
fake_call_(worker_, network_.get()) {
|
2021-03-30 23:47:49 +02:00
|
|
|
network_->SetName("Network", this);
|
|
|
|
|
network_->Start();
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2020-06-16 16:39:13 +02:00
|
|
|
void TestCreateDestroyChannels(webrtc::RtpTransportInternal* rtp_transport) {
|
2021-04-01 16:49:42 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_);
|
|
|
|
|
cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
|
2022-01-24 08:45:26 +01:00
|
|
|
&fake_call_, cricket::MediaConfig(), cricket::CN_AUDIO,
|
|
|
|
|
kDefaultSrtpRequired, webrtc::CryptoOptions(), AudioOptions());
|
2022-01-19 11:36:23 +01:00
|
|
|
ASSERT_TRUE(voice_channel != nullptr);
|
|
|
|
|
|
2021-04-01 16:49:42 +02:00
|
|
|
cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
|
2022-01-24 08:45:26 +01:00
|
|
|
&fake_call_, cricket::MediaConfig(), cricket::CN_VIDEO,
|
|
|
|
|
kDefaultSrtpRequired, webrtc::CryptoOptions(), VideoOptions(),
|
2021-04-01 16:49:42 +02:00
|
|
|
video_bitrate_allocator_factory_.get());
|
2022-01-19 11:36:23 +01:00
|
|
|
ASSERT_TRUE(video_channel != nullptr);
|
|
|
|
|
|
2022-01-24 08:45:26 +01:00
|
|
|
cm_->DestroyChannel(video_channel);
|
|
|
|
|
cm_->DestroyChannel(voice_channel);
|
2018-03-30 10:48:35 -07:00
|
|
|
}
|
|
|
|
|
|
2017-07-14 14:44:46 -07:00
|
|
|
std::unique_ptr<rtc::Thread> network_;
|
2021-04-01 16:49:42 +02:00
|
|
|
rtc::Thread* const worker_;
|
2019-04-17 07:38:40 +02:00
|
|
|
std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
|
|
|
|
|
video_bitrate_allocator_factory_;
|
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_;
|
2022-03-09 09:28:10 +01:00
|
|
|
webrtc::test::ScopedKeyValueConfig field_trials_;
|
2013-07-10 00:45:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(ChannelManagerTest, SetVideoRtxEnabled) {
|
2020-03-29 22:17:00 +02:00
|
|
|
std::vector<VideoCodec> send_codecs;
|
|
|
|
|
std::vector<VideoCodec> recv_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.
|
2020-03-29 22:17:00 +02:00
|
|
|
cm_->GetSupportedVideoSendCodecs(&send_codecs);
|
2022-03-10 15:21:28 +01:00
|
|
|
EXPECT_FALSE(ContainsMatchingCodec(send_codecs, rtx_codec, &field_trials_));
|
2020-03-29 22:17:00 +02:00
|
|
|
cm_->GetSupportedVideoSendCodecs(&recv_codecs);
|
2022-03-10 15:21:28 +01:00
|
|
|
EXPECT_FALSE(ContainsMatchingCodec(recv_codecs, rtx_codec, &field_trials_));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Enable and check.
|
2021-04-01 16:49:42 +02:00
|
|
|
cm_ = cricket::ChannelManager::Create(CreateFakeMediaEngine(),
|
|
|
|
|
true, worker_, network_.get());
|
2020-03-29 22:17:00 +02:00
|
|
|
cm_->GetSupportedVideoSendCodecs(&send_codecs);
|
2022-03-10 15:21:28 +01:00
|
|
|
EXPECT_TRUE(ContainsMatchingCodec(send_codecs, rtx_codec, &field_trials_));
|
2020-03-29 22:17:00 +02:00
|
|
|
cm_->GetSupportedVideoSendCodecs(&recv_codecs);
|
2022-03-10 15:21:28 +01:00
|
|
|
EXPECT_TRUE(ContainsMatchingCodec(recv_codecs, rtx_codec, &field_trials_));
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
// Disable and check.
|
2021-04-01 16:49:42 +02:00
|
|
|
cm_ = cricket::ChannelManager::Create(CreateFakeMediaEngine(),
|
|
|
|
|
false, worker_, network_.get());
|
2020-03-29 22:17:00 +02:00
|
|
|
cm_->GetSupportedVideoSendCodecs(&send_codecs);
|
2022-03-10 15:21:28 +01:00
|
|
|
EXPECT_FALSE(ContainsMatchingCodec(send_codecs, rtx_codec, &field_trials_));
|
2020-03-29 22:17:00 +02:00
|
|
|
cm_->GetSupportedVideoSendCodecs(&recv_codecs);
|
2022-03-10 15:21:28 +01:00
|
|
|
EXPECT_FALSE(ContainsMatchingCodec(recv_codecs, rtx_codec, &field_trials_));
|
2013-07-10 00:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-30 10:48:35 -07:00
|
|
|
TEST_F(ChannelManagerTest, CreateDestroyChannels) {
|
2021-03-18 10:03:19 +01:00
|
|
|
auto rtp_dtls_transport = std::make_unique<FakeDtlsTransport>(
|
|
|
|
|
"fake_dtls_transport", cricket::ICE_CANDIDATE_COMPONENT_RTP,
|
|
|
|
|
network_.get());
|
|
|
|
|
auto dtls_srtp_transport = std::make_unique<webrtc::DtlsSrtpTransport>(
|
2022-03-09 09:28:10 +01:00
|
|
|
/*rtcp_mux_required=*/true, field_trials_);
|
|
|
|
|
|
2021-03-18 10:03:19 +01:00
|
|
|
network_->Invoke<void>(
|
|
|
|
|
RTC_FROM_HERE, [&rtp_dtls_transport, &dtls_srtp_transport] {
|
|
|
|
|
dtls_srtp_transport->SetDtlsTransports(rtp_dtls_transport.get(),
|
|
|
|
|
/*rtcp_dtls_transport=*/nullptr);
|
|
|
|
|
});
|
|
|
|
|
TestCreateDestroyChannels(dtls_srtp_transport.get());
|
2017-12-04 13:38:48 -08:00
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
} // namespace cricket
|