Migrate PeerConnection tests to EnableMedia api

Add test helper to inject fake media engine for those tests.

Bug: webrtc:15574
Change-Id: Iae4282d2d3b9804548ccadf58797f39508f07c6a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/325880
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41075}
This commit is contained in:
Danil Chapovalov 2023-11-03 11:32:24 +01:00 committed by WebRTC LUCI CQ
parent 37f5172f6e
commit c63120a092
11 changed files with 134 additions and 29 deletions

View file

@ -2372,6 +2372,7 @@ if (rtc_include_tests && !build_with_chromium) {
":dtls_srtp_transport",
":dtls_transport",
":dtmf_sender",
":enable_fake_media",
":ice_server_parsing",
":integration_test_helpers",
":jitter_buffer_delay",
@ -2532,7 +2533,6 @@ if (rtc_include_tests && !build_with_chromium) {
":libjingle_peerconnection",
":pc_test_utils",
":rtc_pc",
"../api:callfactory_api",
"../api:rtc_event_log_output_file",
"../api:rtc_stats_api",
"../api:rtp_parameters",
@ -2729,6 +2729,23 @@ if (rtc_include_tests && !build_with_chromium) {
]
}
rtc_library("enable_fake_media") {
testonly = true
visibility = [ ":*" ]
sources = [
"test/enable_fake_media.cc",
"test/enable_fake_media.h",
]
deps = [
":media_factory",
"../api:libjingle_peerconnection_api",
"../call:call_interfaces",
"../media:rtc_media_tests_utils",
"../rtc_base:checks",
]
absl_deps = [ "//third_party/abseil-cpp/absl/base:nullability" ]
}
rtc_library("pc_test_utils") {
testonly = true
sources = [
@ -2761,6 +2778,7 @@ if (rtc_include_tests && !build_with_chromium) {
deps = [
":channel",
":channel_interface",
":enable_fake_media",
":jitter_buffer_delay",
":libjingle_peerconnection",
":peer_connection_internal",

View file

@ -15,7 +15,6 @@
#include <vector>
#include "absl/types/optional.h"
#include "api/call/call_factory_interface.h"
#include "api/jsep.h"
#include "api/media_types.h"
#include "api/peer_connection_interface.h"
@ -24,8 +23,6 @@
#include "api/task_queue/default_task_queue_factory.h"
#include "api/task_queue/task_queue_factory.h"
#include "api/transport/sctp_transport_factory_interface.h"
#include "media/base/fake_media_engine.h"
#include "media/base/media_engine.h"
#include "p2p/base/p2p_constants.h"
#include "p2p/base/port_allocator.h"
#include "pc/media_session.h"
@ -35,6 +32,7 @@
#include "pc/sctp_transport.h"
#include "pc/sdp_utils.h"
#include "pc/session_description.h"
#include "pc/test/enable_fake_media.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
@ -64,8 +62,7 @@ PeerConnectionFactoryDependencies CreatePeerConnectionFactoryDependencies() {
deps.worker_thread = rtc::Thread::Current();
deps.signaling_thread = rtc::Thread::Current();
deps.task_queue_factory = CreateDefaultTaskQueueFactory();
deps.media_engine = std::make_unique<cricket::FakeMediaEngine>();
deps.call_factory = CreateCallFactory();
EnableFakeMedia(deps);
deps.sctp_factory = std::make_unique<FakeSctpTransportFactory>();
return deps;
}

View file

@ -16,7 +16,6 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/call/call_factory_interface.h"
#include "api/jsep.h"
#include "api/media_types.h"
#include "api/peer_connection_interface.h"
@ -35,6 +34,7 @@
#include "p2p/base/port_allocator.h"
#include "pc/peer_connection_wrapper.h"
#include "pc/session_description.h"
#include "pc/test/enable_fake_media.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/internal/default_socket_server.h"
#include "rtc_base/rtc_certificate_generator.h"
@ -77,21 +77,18 @@ class PeerConnectionHeaderExtensionTest
std::unique_ptr<PeerConnectionWrapper> CreatePeerConnection(
cricket::MediaType media_type,
absl::optional<SdpSemantics> semantics) {
auto voice = std::make_unique<cricket::FakeVoiceEngine>();
auto video = std::make_unique<cricket::FakeVideoEngine>();
auto media_engine = std::make_unique<cricket::FakeMediaEngine>();
if (media_type == cricket::MediaType::MEDIA_TYPE_AUDIO)
voice->SetRtpHeaderExtensions(extensions_);
media_engine->fake_voice_engine()->SetRtpHeaderExtensions(extensions_);
else
video->SetRtpHeaderExtensions(extensions_);
auto media_engine = std::make_unique<cricket::CompositeMediaEngine>(
std::move(voice), std::move(video));
media_engine->fake_video_engine()->SetRtpHeaderExtensions(extensions_);
PeerConnectionFactoryDependencies factory_dependencies;
factory_dependencies.network_thread = rtc::Thread::Current();
factory_dependencies.worker_thread = rtc::Thread::Current();
factory_dependencies.signaling_thread = rtc::Thread::Current();
factory_dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
factory_dependencies.media_engine = std::move(media_engine);
factory_dependencies.call_factory = CreateCallFactory();
EnableFakeMedia(factory_dependencies, std::move(media_engine));
factory_dependencies.event_log_factory =
std::make_unique<RtcEventLogFactory>(
factory_dependencies.task_queue_factory.get());

View file

@ -16,7 +16,6 @@
#include "absl/types/optional.h"
#include "api/async_resolver_factory.h"
#include "api/call/call_factory_interface.h"
#include "api/jsep.h"
#include "api/jsep_session_description.h"
#include "api/peer_connection_interface.h"
@ -25,7 +24,6 @@
#include "api/task_queue/default_task_queue_factory.h"
#include "api/task_queue/task_queue_factory.h"
#include "api/test/mock_async_dns_resolver.h"
#include "media/base/fake_media_engine.h"
#include "media/base/media_engine.h"
#include "p2p/base/mock_async_resolver.h"
#include "p2p/base/port_allocator.h"
@ -35,6 +33,7 @@
#include "pc/peer_connection_proxy.h"
#include "pc/peer_connection_wrapper.h"
#include "pc/sdp_utils.h"
#include "pc/test/enable_fake_media.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "pc/usage_pattern.h"
#include "pc/webrtc_sdp.h"
@ -84,9 +83,7 @@ class PeerConnectionFactoryForUsageHistogramTest
dependencies.worker_thread = rtc::Thread::Current();
dependencies.signaling_thread = rtc::Thread::Current();
dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
dependencies.media_engine =
std::make_unique<cricket::FakeMediaEngine>();
dependencies.call_factory = CreateCallFactory();
EnableFakeMedia(dependencies);
return dependencies;
}()) {}
};

View file

@ -22,7 +22,6 @@
#include "api/audio/audio_mixer.h"
#include "api/audio_codecs/builtin_audio_decoder_factory.h"
#include "api/audio_codecs/builtin_audio_encoder_factory.h"
#include "api/call/call_factory_interface.h"
#include "api/create_peerconnection_factory.h"
#include "api/data_channel_interface.h"
#include "api/enable_media_with_defaults.h"

View file

@ -20,7 +20,6 @@
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/call/call_factory_interface.h"
#include "api/enable_media_with_defaults.h"
#include "api/field_trials_view.h"
#include "api/jsep.h"

View file

@ -27,7 +27,6 @@
#include "absl/algorithm/container.h"
#include "absl/types/optional.h"
#include "api/audio_options.h"
#include "api/call/call_factory_interface.h"
#include "api/jsep.h"
#include "api/media_types.h"
#include "api/peer_connection_interface.h"
@ -57,6 +56,7 @@
#include "pc/rtp_media_utils.h"
#include "pc/rtp_transceiver.h"
#include "pc/session_description.h"
#include "pc/test/enable_fake_media.h"
#include "pc/test/mock_peer_connection_observers.h"
#include "rtc_base/checks.h"
#include "rtc_base/rtc_certificate_generator.h"
@ -173,8 +173,7 @@ class PeerConnectionMediaBaseTest : public ::testing::Test {
factory_dependencies.worker_thread = rtc::Thread::Current();
factory_dependencies.signaling_thread = rtc::Thread::Current();
factory_dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
factory_dependencies.media_engine = std::move(media_engine);
factory_dependencies.call_factory = CreateCallFactory();
EnableFakeMedia(factory_dependencies, std::move(media_engine));
factory_dependencies.event_log_factory =
std::make_unique<RtcEventLogFactory>(
factory_dependencies.task_queue_factory.get());

View file

@ -19,8 +19,8 @@
#include "absl/types/optional.h"
#include "api/peer_connection_interface.h"
#include "api/rtp_parameters.h"
#include "media/base/fake_media_engine.h"
#include "media/base/media_engine.h"
#include "pc/test/enable_fake_media.h"
#include "pc/test/mock_channel_interface.h"
#include "pc/test/mock_rtp_receiver_internal.h"
#include "pc/test/mock_rtp_sender_internal.h"
@ -60,7 +60,7 @@ class RtpTransceiverTest : public testing::Test {
d.network_thread = rtc::Thread::Current();
d.worker_thread = rtc::Thread::Current();
d.signaling_thread = rtc::Thread::Current();
d.media_engine = std::make_unique<cricket::FakeMediaEngine>();
EnableFakeMedia(d);
return d;
}

View file

@ -0,0 +1,61 @@
/*
* Copyright 2023 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/test/enable_fake_media.h"
#include <memory>
#include <utility>
#include "absl/base/nullability.h"
#include "api/peer_connection_interface.h"
#include "call/call.h"
#include "call/call_config.h"
#include "media/base/fake_media_engine.h"
#include "pc/media_factory.h"
#include "rtc_base/checks.h"
namespace webrtc {
using ::cricket::FakeMediaEngine;
using ::cricket::MediaEngineInterface;
void EnableFakeMedia(
PeerConnectionFactoryDependencies& deps,
absl::Nonnull<std::unique_ptr<FakeMediaEngine>> fake_media_engine) {
class FakeMediaFactory : public MediaFactory {
public:
explicit FakeMediaFactory(
absl::Nonnull<std::unique_ptr<FakeMediaEngine>> fake)
: fake_(std::move(fake)) {}
std::unique_ptr<Call> CreateCall(const CallConfig& config) override {
return Call::Create(config);
}
std::unique_ptr<MediaEngineInterface> CreateMediaEngine(
PeerConnectionFactoryDependencies& /*dependencies*/) {
RTC_CHECK(fake_ != nullptr)
<< "CreateMediaEngine can be called at most once.";
return std::move(fake_);
}
private:
absl::Nullable<std::unique_ptr<FakeMediaEngine>> fake_;
};
deps.media_factory =
std::make_unique<FakeMediaFactory>(std::move(fake_media_engine));
}
void EnableFakeMedia(PeerConnectionFactoryDependencies& deps) {
EnableFakeMedia(deps, std::make_unique<cricket::FakeMediaEngine>());
}
} // namespace webrtc

View file

@ -0,0 +1,38 @@
/*
* Copyright 2023 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.
*/
// Enables fake media support for PeerConnnectionFactory created from `deps` for
// testing purposes. Such fake media support ignores media dependencies in the
// `PeerConnectionFactoryDependencies`. Allows to test PeerConnection and
// PeerConnectionFactory in the presence of the media, but doesn't test media
// support itself.
#ifndef PC_TEST_ENABLE_FAKE_MEDIA_H_
#define PC_TEST_ENABLE_FAKE_MEDIA_H_
#include <memory>
#include "absl/base/nullability.h"
#include "api/peer_connection_interface.h"
#include "media/base/fake_media_engine.h"
namespace webrtc {
// Enables media support backed by the 'fake_media_engine'.
void EnableFakeMedia(
PeerConnectionFactoryDependencies& deps,
absl::Nonnull<std::unique_ptr<cricket::FakeMediaEngine>> fake_media_engine);
// Enables media support backed by unspecified lightweight fake implementation.
void EnableFakeMedia(PeerConnectionFactoryDependencies& deps);
} // namespace webrtc
#endif // PC_TEST_ENABLE_FAKE_MEDIA_H_

View file

@ -18,10 +18,10 @@
#include <utility>
#include <vector>
#include "media/base/fake_media_engine.h"
#include "media/base/media_channel.h"
#include "pc/channel.h"
#include "pc/stream_collection.h"
#include "pc/test/enable_fake_media.h"
#include "pc/test/fake_data_channel_controller.h"
#include "pc/test/fake_peer_connection_base.h"
@ -235,7 +235,7 @@ class FakePeerConnectionForStats : public FakePeerConnectionBase {
dependencies.network_thread = rtc::Thread::Current();
dependencies.worker_thread = rtc::Thread::Current();
dependencies.signaling_thread = rtc::Thread::Current();
dependencies.media_engine = std::make_unique<cricket::FakeMediaEngine>();
EnableFakeMedia(dependencies);
return dependencies;
}