webrtc_m130/pc/channel_manager_unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
5.1 KiB
C++
Raw Normal View History

/*
* Copyright 2008 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "pc/channel_manager.h"
#include "api/sequence_checker.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h"
#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"
#include "pc/rtp_transport_internal.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/checks.h"
#include "rtc_base/location.h"
#include "rtc_base/thread.h"
#include "test/gtest.h"
#include "test/scoped_key_value_config.h"
namespace cricket {
namespace {
const bool kDefaultSrtpRequired = true;
static const AudioCodec kAudioCodecs[] = {
AudioCodec(97, "voice", 1, 2, 3),
AudioCodec(111, "OPUS", 48000, 32000, 2),
};
static const VideoCodec kVideoCodecs[] = {
VideoCodec(99, "H264"),
VideoCodec(100, "VP8"),
VideoCodec(96, "rtx"),
};
std::unique_ptr<MediaEngineInterface> CreateFakeMediaEngine() {
auto fme = std::make_unique<FakeMediaEngine>();
fme->SetAudioCodecs(MAKE_VECTOR(kAudioCodecs));
fme->SetVideoCodecs(MAKE_VECTOR(kVideoCodecs));
return fme;
}
} // namespace
class ChannelManagerTest : public ::testing::Test {
protected:
Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ ) Reason for revert: This CL just landed: https://codereview.chromium.org/1323243006/ Which fixes the FYI bots for the original CL, and breaks them for this revert. Original issue's description: > Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ ) > > Reason for revert: > This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step. > > Original issue's description: > > TransportController refactoring. > > > > Getting rid of TransportProxy, and in its place adding a > > TransportController class which will facilitate access to and manage > > the lifetimes of Transports. These Transports will now be accessed > > solely from the worker thread, simplifying their implementation. > > > > This refactoring also pulls Transport-related code out of BaseSession. > > Which means that BaseChannels will now rely on the TransportController > > interface to create channels, rather than BaseSession. > > > > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83 > > Cr-Commit-Position: refs/heads/master@{#10022} > > TBR=pthatcher@webrtc.org,deadbeef@webrtc.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > > Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c > Cr-Commit-Position: refs/heads/master@{#10024} TBR=pthatcher@webrtc.org,torbjorng@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.webrtc.org/1361773005 Cr-Commit-Position: refs/heads/master@{#10036}
2015-09-23 11:50:27 -07:00
ChannelManagerTest()
: network_(rtc::Thread::CreateWithSocketServer()),
worker_(rtc::Thread::Current()),
video_bitrate_allocator_factory_(
webrtc::CreateBuiltinVideoBitrateAllocatorFactory()),
cm_(cricket::ChannelManager::Create(CreateFakeMediaEngine(),
false,
worker_,
network_.get())),
fake_call_(worker_, network_.get()) {
network_->SetName("Network", this);
network_->Start();
}
void TestCreateDestroyChannels(webrtc::RtpTransportInternal* rtp_transport) {
RTC_DCHECK_RUN_ON(worker_);
cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
Add a channel factory interface. The interface is implemented by the ChannelManager and contains methods to create and destroy media channel objects as used by a transceiver. This will subsequently allow us to delete the channel objects from the transceiver class where ownership really lies rather than from the outside - which is currently required by some tests that keep channel objects on the stack. We'll furthermore be able to do the destruction asynchronously without additional Invoke()s as we do now which will remove an Invoke when making sdp changes. With introducing the interface, the following simplifications were made: * ChannelManager constructed on the signaling thread. Before, there was an Invoke in the context class, which existed for the purposes of calling MediaEngine::Init() (which in turn is only needed for the VoiceEngine). This Invoke has now been moved into the CM (more tbd). * The CM now has a pointer to the signaling thread (since that's the construction thread). That allows us to remove the signaling thread parameter from the CreateFooChannel methods. * The ssrc_generator (UniqueRandomIdGenerator) instance for SSRCs moved from SdpOfferAnswerHandler to the CM, as it's always used in combination with the CM. This simplifies the CreateFooChannel methods as well as a couple of other classes that have a CM dependency. * Removed DestroyFooChannel related code from SdpOfferAnswerHandler since the channel type detail can be taken care of by the CM. Bug: webrtc:11992, webrtc:13540 Change-Id: I04938a803734de8489ba31e6212d9eaecc244126 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247904 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35766}
2022-01-24 08:45:26 +01:00
&fake_call_, cricket::MediaConfig(), cricket::CN_AUDIO,
kDefaultSrtpRequired, webrtc::CryptoOptions(), AudioOptions());
ASSERT_TRUE(voice_channel != nullptr);
cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
Add a channel factory interface. The interface is implemented by the ChannelManager and contains methods to create and destroy media channel objects as used by a transceiver. This will subsequently allow us to delete the channel objects from the transceiver class where ownership really lies rather than from the outside - which is currently required by some tests that keep channel objects on the stack. We'll furthermore be able to do the destruction asynchronously without additional Invoke()s as we do now which will remove an Invoke when making sdp changes. With introducing the interface, the following simplifications were made: * ChannelManager constructed on the signaling thread. Before, there was an Invoke in the context class, which existed for the purposes of calling MediaEngine::Init() (which in turn is only needed for the VoiceEngine). This Invoke has now been moved into the CM (more tbd). * The CM now has a pointer to the signaling thread (since that's the construction thread). That allows us to remove the signaling thread parameter from the CreateFooChannel methods. * The ssrc_generator (UniqueRandomIdGenerator) instance for SSRCs moved from SdpOfferAnswerHandler to the CM, as it's always used in combination with the CM. This simplifies the CreateFooChannel methods as well as a couple of other classes that have a CM dependency. * Removed DestroyFooChannel related code from SdpOfferAnswerHandler since the channel type detail can be taken care of by the CM. Bug: webrtc:11992, webrtc:13540 Change-Id: I04938a803734de8489ba31e6212d9eaecc244126 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247904 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35766}
2022-01-24 08:45:26 +01:00
&fake_call_, cricket::MediaConfig(), cricket::CN_VIDEO,
kDefaultSrtpRequired, webrtc::CryptoOptions(), VideoOptions(),
video_bitrate_allocator_factory_.get());
ASSERT_TRUE(video_channel != nullptr);
Add a channel factory interface. The interface is implemented by the ChannelManager and contains methods to create and destroy media channel objects as used by a transceiver. This will subsequently allow us to delete the channel objects from the transceiver class where ownership really lies rather than from the outside - which is currently required by some tests that keep channel objects on the stack. We'll furthermore be able to do the destruction asynchronously without additional Invoke()s as we do now which will remove an Invoke when making sdp changes. With introducing the interface, the following simplifications were made: * ChannelManager constructed on the signaling thread. Before, there was an Invoke in the context class, which existed for the purposes of calling MediaEngine::Init() (which in turn is only needed for the VoiceEngine). This Invoke has now been moved into the CM (more tbd). * The CM now has a pointer to the signaling thread (since that's the construction thread). That allows us to remove the signaling thread parameter from the CreateFooChannel methods. * The ssrc_generator (UniqueRandomIdGenerator) instance for SSRCs moved from SdpOfferAnswerHandler to the CM, as it's always used in combination with the CM. This simplifies the CreateFooChannel methods as well as a couple of other classes that have a CM dependency. * Removed DestroyFooChannel related code from SdpOfferAnswerHandler since the channel type detail can be taken care of by the CM. Bug: webrtc:11992, webrtc:13540 Change-Id: I04938a803734de8489ba31e6212d9eaecc244126 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/247904 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35766}
2022-01-24 08:45:26 +01:00
cm_->DestroyChannel(video_channel);
cm_->DestroyChannel(voice_channel);
}
std::unique_ptr<rtc::Thread> network_;
rtc::Thread* const worker_;
std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
video_bitrate_allocator_factory_;
std::unique_ptr<cricket::ChannelManager> cm_;
cricket::FakeCall fake_call_;
webrtc::test::ScopedKeyValueConfig field_trials_;
};
TEST_F(ChannelManagerTest, SetVideoRtxEnabled) {
std::vector<VideoCodec> send_codecs;
std::vector<VideoCodec> recv_codecs;
const VideoCodec rtx_codec(96, "rtx");
// By default RTX is disabled.
cm_->GetSupportedVideoSendCodecs(&send_codecs);
EXPECT_FALSE(ContainsMatchingCodec(send_codecs, rtx_codec, &field_trials_));
cm_->GetSupportedVideoSendCodecs(&recv_codecs);
EXPECT_FALSE(ContainsMatchingCodec(recv_codecs, rtx_codec, &field_trials_));
// Enable and check.
cm_ = cricket::ChannelManager::Create(CreateFakeMediaEngine(),
true, worker_, network_.get());
cm_->GetSupportedVideoSendCodecs(&send_codecs);
EXPECT_TRUE(ContainsMatchingCodec(send_codecs, rtx_codec, &field_trials_));
cm_->GetSupportedVideoSendCodecs(&recv_codecs);
EXPECT_TRUE(ContainsMatchingCodec(recv_codecs, rtx_codec, &field_trials_));
// Disable and check.
cm_ = cricket::ChannelManager::Create(CreateFakeMediaEngine(),
false, worker_, network_.get());
cm_->GetSupportedVideoSendCodecs(&send_codecs);
EXPECT_FALSE(ContainsMatchingCodec(send_codecs, rtx_codec, &field_trials_));
cm_->GetSupportedVideoSendCodecs(&recv_codecs);
EXPECT_FALSE(ContainsMatchingCodec(recv_codecs, rtx_codec, &field_trials_));
}
TEST_F(ChannelManagerTest, CreateDestroyChannels) {
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>(
/*rtcp_mux_required=*/true, field_trials_);
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());
}
} // namespace cricket