From 2a569a2fc9cfce021ec3563c5ba71a1ff8f69479 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Mon, 14 Oct 2024 19:00:13 +0200 Subject: [PATCH] For test peer start/stop AEC dump using peer connection factory api Instead of using AudioProcessing API directly With AudioProcessing constructing move into the PeerConnectionFactory it is possible TestPeer doesn't have direct access to audio_processing, yet it is not null. Bug: webrtc:369904700 Change-Id: I5a4a9453ea3a0c735da8953c9ae5d9046d4e3916 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/365585 Commit-Queue: Danil Chapovalov Reviewed-by: Artem Titov Cr-Commit-Position: refs/heads/main@{#43240} --- test/pc/e2e/BUILD.gn | 29 +++++++++++++ test/pc/e2e/peer_connection_quality_test.cc | 42 +++++++++++++++--- test/pc/e2e/test_peer.cc | 23 +++++++--- test/pc/e2e/test_peer.h | 28 +++++++----- test/pc/e2e/test_peer_factory.cc | 47 ++++++++++++--------- test/pc/e2e/test_peer_factory.h | 29 +++++++------ 6 files changed, 143 insertions(+), 55 deletions(-) diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn index 01ae59812f..d728237ffc 100644 --- a/test/pc/e2e/BUILD.gn +++ b/test/pc/e2e/BUILD.gn @@ -67,6 +67,11 @@ if (!build_with_chromium) { "../../../api:frame_generator_api", "../../../api:function_view", "../../../api:libjingle_peerconnection_api", + "../../../api:make_ref_counted", + "../../../api:media_stream_interface", + "../../../api:rtc_error", + "../../../api:rtc_stats_api", + "../../../api:rtp_parameters", "../../../api:scoped_refptr", "../../../api:sequence_checker", "../../../api/audio:audio_processing", @@ -74,9 +79,13 @@ if (!build_with_chromium) { "../../../api/test/pclf:media_configuration", "../../../api/test/pclf:media_quality_test_params", "../../../api/test/pclf:peer_configurer", + "../../../pc:pc_test_utils", "../../../pc:peerconnection_wrapper", + "../../../rtc_base:checks", "../../../rtc_base:logging", + "../../../rtc_base:macromagic", "../../../rtc_base:refcount", + "../../../rtc_base:threading", "../../../rtc_base/synchronization:mutex", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings:string_view", @@ -95,7 +104,10 @@ if (!build_with_chromium) { "../..:copy_to_file_audio_capturer", "../../../api:create_time_controller", "../../../api:enable_media_with_defaults", + "../../../api:libjingle_peerconnection_api", + "../../../api:scoped_refptr", "../../../api:time_controller", + "../../../api/audio:audio_device", "../../../api/rtc_event_log:rtc_event_log_factory", "../../../api/task_queue", "../../../api/task_queue:default_task_queue_factory", @@ -105,13 +117,18 @@ if (!build_with_chromium) { "../../../api/transport:field_trial_based_config", "../../../api/video_codecs:builtin_video_decoder_factory", "../../../api/video_codecs:builtin_video_encoder_factory", + "../../../api/video_codecs:video_codecs_api", "../../../modules/audio_device:test_audio_device_module", "../../../modules/audio_processing/aec_dump", "../../../p2p:basic_port_allocator", "../../../p2p:rtc_p2p", + "../../../pc:pc_test_utils", + "../../../rtc_base:checks", "../../../rtc_base:threading", + "../../../rtc_base/system:file_wrapper", "analyzer/video:quality_analyzing_video_encoder", "analyzer/video:video_quality_analyzer_injection_helper", + "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings:string_view", ] @@ -218,19 +235,26 @@ if (!build_with_chromium) { ":peer_params_preprocessor", ":sdp_changer", ":stats_poller", + ":stats_provider", ":test_activities_executor", ":test_peer", ":test_peer_factory", + ":test_video_capturer_video_track_source", "../..:field_trial", "../..:fileutils", "../..:perf_test", "../..:test_flags", + "../..:test_support", "../../../api:audio_quality_analyzer_api", "../../../api:libjingle_peerconnection_api", "../../../api:media_stream_interface", "../../../api:peer_connection_quality_test_fixture_api", + "../../../api:rtc_error", "../../../api:rtc_event_log_output_file", + "../../../api:rtp_parameters", + "../../../api:rtp_transceiver_direction", "../../../api:scoped_refptr", + "../../../api:stats_observer_interface", "../../../api:time_controller", "../../../api:video_quality_analyzer_api", "../../../api/rtc_event_log", @@ -242,15 +266,20 @@ if (!build_with_chromium) { "../../../api/test/pclf:peer_configurer", "../../../api/units:time_delta", "../../../api/units:timestamp", + "../../../api/video:video_frame", + "../../../media:media_constants", "../../../pc:pc_test_utils", "../../../pc:sdp_utils", + "../../../rtc_base:checks", "../../../rtc_base:gunit_helpers", + "../../../rtc_base:logging", "../../../rtc_base:macromagic", "../../../rtc_base:safe_conversions", "../../../rtc_base:stringutils", "../../../rtc_base:task_queue_for_test", "../../../rtc_base:threading", "../../../rtc_base/synchronization:mutex", + "../../../rtc_base/task_utils:repeating_task", "../../../system_wrappers", "../../../system_wrappers:field_trial", "analyzer/video:default_video_quality_analyzer", diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc index fac96e2835..8fa99826df 100644 --- a/test/pc/e2e/peer_connection_quality_test.cc +++ b/test/pc/e2e/peer_connection_quality_test.cc @@ -10,40 +10,72 @@ #include "test/pc/e2e/peer_connection_quality_test.h" #include +#include +#include +#include +#include #include -#include +#include +#include #include +#include #include "absl/flags/flag.h" #include "absl/strings/string_view.h" #include "api/jsep.h" #include "api/media_stream_interface.h" +#include "api/media_types.h" #include "api/peer_connection_interface.h" +#include "api/rtc_error.h" #include "api/rtc_event_log/rtc_event_log.h" #include "api/rtc_event_log_output_file.h" +#include "api/rtp_parameters.h" +#include "api/rtp_transceiver_direction.h" +#include "api/rtp_transceiver_interface.h" #include "api/scoped_refptr.h" +#include "api/task_queue/task_queue_factory.h" +#include "api/test/audio_quality_analyzer_interface.h" #include "api/test/metrics/metric.h" +#include "api/test/metrics/metrics_logger.h" #include "api/test/pclf/media_configuration.h" +#include "api/test/pclf/media_quality_test_params.h" #include "api/test/pclf/peer_configurer.h" +#include "api/test/stats_observer_interface.h" #include "api/test/time_controller.h" #include "api/test/video_quality_analyzer_interface.h" -#include "pc/sdp_utils.h" +#include "api/units/time_delta.h" +#include "api/units/timestamp.h" +#include "api/video/video_frame.h" +#include "api/video/video_sink_interface.h" +#include "api/video/video_source_interface.h" +#include "media/base/media_constants.h" #include "pc/test/mock_peer_connection_observers.h" -#include "rtc_base/gunit.h" -#include "rtc_base/numerics/safe_conversions.h" +#include "rtc_base/checks.h" +#include "rtc_base/logging.h" #include "rtc_base/strings/string_builder.h" +#include "rtc_base/synchronization/mutex.h" #include "rtc_base/task_queue_for_test.h" +#include "rtc_base/task_utils/repeating_task.h" #include "system_wrappers/include/cpu_info.h" #include "system_wrappers/include/field_trial.h" #include "test/field_trial.h" +#include "test/gtest.h" #include "test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h" #include "test/pc/e2e/analyzer/video/default_video_quality_analyzer.h" +#include "test/pc/e2e/analyzer/video/single_process_encoded_image_data_injector.h" #include "test/pc/e2e/analyzer/video/video_frame_tracking_id_injector.h" +#include "test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h" #include "test/pc/e2e/analyzer/video/video_quality_metrics_reporter.h" #include "test/pc/e2e/cross_media_metrics_reporter.h" +#include "test/pc/e2e/media/media_helper.h" +#include "test/pc/e2e/media/test_video_capturer_video_track_source.h" #include "test/pc/e2e/metric_metadata_keys.h" #include "test/pc/e2e/peer_params_preprocessor.h" +#include "test/pc/e2e/sdp/sdp_changer.h" #include "test/pc/e2e/stats_poller.h" +#include "test/pc/e2e/stats_provider.h" +#include "test/pc/e2e/test_activities_executor.h" +#include "test/pc/e2e/test_peer.h" #include "test/pc/e2e/test_peer_factory.h" #include "test/test_flags.h" #include "test/testsupport/file_utils.h" @@ -275,7 +307,7 @@ void PeerConnectionE2EQualityTest::Run(RunParams run_params) { TestPeerFactory test_peer_factory( signaling_thread.get(), time_controller_, - video_quality_analyzer_injection_helper_.get(), task_queue_->Get()); + video_quality_analyzer_injection_helper_.get()); alice_ = test_peer_factory.CreateTestPeer( std::move(alice_configurer), std::make_unique( diff --git a/test/pc/e2e/test_peer.cc b/test/pc/e2e/test_peer.cc index d1f4534c6a..6c5f7d192f 100644 --- a/test/pc/e2e/test_peer.cc +++ b/test/pc/e2e/test_peer.cc @@ -9,15 +9,29 @@ */ #include "test/pc/e2e/test_peer.h" +#include #include #include +#include -#include "absl/memory/memory.h" #include "absl/strings/string_view.h" -#include "api/audio/audio_processing.h" +#include "api/jsep.h" +#include "api/make_ref_counted.h" +#include "api/peer_connection_interface.h" +#include "api/rtc_error.h" #include "api/scoped_refptr.h" +#include "api/set_remote_description_observer_interface.h" +#include "api/stats/rtc_stats_collector_callback.h" +#include "api/task_queue/pending_task_safety_flag.h" #include "api/test/pclf/media_configuration.h" +#include "api/test/pclf/media_quality_test_params.h" #include "api/test/pclf/peer_configurer.h" +#include "pc/peer_connection_wrapper.h" +#include "pc/test/mock_peer_connection_observers.h" +#include "rtc_base/checks.h" +#include "rtc_base/logging.h" +#include "rtc_base/synchronization/mutex.h" +#include "rtc_base/thread.h" namespace webrtc { namespace webrtc_pc_e2e { @@ -121,7 +135,6 @@ void TestPeer::Close() { signaling_thread_task_safety_->SetNotAlive(); wrapper_->pc()->Close(); remote_ice_candidates_.clear(); - audio_processing_ = nullptr; video_sources_.clear(); wrapper_ = nullptr; worker_thread_ = nullptr; @@ -134,7 +147,6 @@ TestPeer::TestPeer( Params params, ConfigurableParams configurable_params, std::vector video_sources, - rtc::scoped_refptr audio_processing, std::unique_ptr worker_thread) : params_(std::move(params)), configurable_params_(std::move(configurable_params)), @@ -142,8 +154,7 @@ TestPeer::TestPeer( wrapper_(std::make_unique(std::move(pc_factory), std::move(pc), std::move(observer))), - video_sources_(std::move(video_sources)), - audio_processing_(audio_processing) { + video_sources_(std::move(video_sources)) { signaling_thread_task_safety_ = PendingTaskSafetyFlag::CreateDetached(); } diff --git a/test/pc/e2e/test_peer.h b/test/pc/e2e/test_peer.h index 0956e05969..96a376b529 100644 --- a/test/pc/e2e/test_peer.h +++ b/test/pc/e2e/test_peer.h @@ -11,24 +11,34 @@ #ifndef TEST_PC_E2E_TEST_PEER_H_ #define TEST_PC_E2E_TEST_PEER_H_ +#include #include #include +#include +#include #include -#include "absl/memory/memory.h" #include "absl/strings/string_view.h" -#include "api/function_view.h" +#include "api/data_channel_interface.h" +#include "api/jsep.h" +#include "api/media_stream_interface.h" +#include "api/media_types.h" +#include "api/peer_connection_interface.h" +#include "api/rtp_sender_interface.h" +#include "api/rtp_transceiver_interface.h" #include "api/scoped_refptr.h" -#include "api/sequence_checker.h" -#include "api/set_remote_description_observer_interface.h" +#include "api/stats/rtc_stats_collector_callback.h" +#include "api/stats/rtc_stats_report.h" #include "api/task_queue/pending_task_safety_flag.h" -#include "api/test/frame_generator_interface.h" #include "api/test/pclf/media_configuration.h" #include "api/test/pclf/media_quality_test_params.h" #include "api/test/pclf/peer_configurer.h" #include "pc/peer_connection_wrapper.h" -#include "rtc_base/logging.h" +#include "pc/test/mock_peer_connection_observers.h" +#include "rtc_base/checks.h" #include "rtc_base/synchronization/mutex.h" +#include "rtc_base/thread.h" +#include "rtc_base/thread_annotations.h" #include "test/pc/e2e/stats_provider.h" namespace webrtc { @@ -138,9 +148,7 @@ class TestPeer final : public StatsProvider { void DetachAecDump() { RTC_CHECK(wrapper_) << "TestPeer is already closed"; - if (audio_processing_) { - audio_processing_->DetachAecDump(); - } + wrapper_->pc_factory()->StopAecDump(); } // Adds provided `candidates` to the owned peer connection. @@ -159,7 +167,6 @@ class TestPeer final : public StatsProvider { Params params, ConfigurableParams configurable_params, std::vector video_sources, - rtc::scoped_refptr audio_processing, std::unique_ptr worker_thread); private: @@ -179,7 +186,6 @@ class TestPeer final : public StatsProvider { std::unique_ptr worker_thread_; std::unique_ptr wrapper_; std::vector video_sources_; - rtc::scoped_refptr audio_processing_; std::vector> remote_ice_candidates_; }; diff --git a/test/pc/e2e/test_peer_factory.cc b/test/pc/e2e/test_peer_factory.cc index f0ffe9f75a..a744b95c89 100644 --- a/test/pc/e2e/test_peer_factory.cc +++ b/test/pc/e2e/test_peer_factory.cc @@ -9,24 +9,40 @@ */ #include "test/pc/e2e/test_peer_factory.h" +#include +#include +#include #include +#include #include "absl/memory/memory.h" #include "absl/strings/string_view.h" -#include "api/enable_media_with_defaults.h" -#include "api/task_queue/default_task_queue_factory.h" +#include "api/audio/audio_device.h" +#include "api/peer_connection_interface.h" +#include "api/rtc_event_log/rtc_event_log_factory.h" +#include "api/scoped_refptr.h" +#include "api/task_queue/task_queue_factory.h" #include "api/test/create_time_controller.h" #include "api/test/pclf/media_configuration.h" +#include "api/test/pclf/media_quality_test_params.h" #include "api/test/pclf/peer_configurer.h" #include "api/test/time_controller.h" #include "api/transport/field_trial_based_config.h" #include "api/video_codecs/builtin_video_decoder_factory.h" #include "api/video_codecs/builtin_video_encoder_factory.h" -#include "modules/audio_processing/aec_dump/aec_dump_factory.h" +#include "api/video_codecs/video_decoder_factory.h" +#include "api/video_codecs/video_encoder_factory.h" +#include "modules/audio_device/include/test_audio_device.h" +#include "p2p/base/port_allocator.h" #include "p2p/client/basic_port_allocator.h" +#include "pc/test/mock_peer_connection_observers.h" +#include "rtc_base/checks.h" +#include "rtc_base/system/file_wrapper.h" #include "rtc_base/thread.h" #include "test/pc/e2e/analyzer/video/quality_analyzing_video_encoder.h" +#include "test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h" #include "test/pc/e2e/echo/echo_emulation.h" +#include "test/pc/e2e/test_peer.h" #include "test/testsupport/copy_to_file_audio_capturer.h" namespace webrtc { @@ -288,14 +304,6 @@ std::unique_ptr TestPeerFactory::CreateTestPeer( params->rtc_configuration.sdp_semantics = SdpSemantics::kUnifiedPlan; // Create peer connection factory. - if (components->pcf_dependencies->audio_processing == nullptr) { - components->pcf_dependencies->audio_processing = - webrtc::AudioProcessingBuilder().Create(); - } - if (params->aec_dump_path) { - components->pcf_dependencies->audio_processing->CreateAndAttachAecDump( - *params->aec_dump_path, -1, task_queue_); - } rtc::scoped_refptr audio_device_module = CreateAudioDeviceModule(params->audio_config, remote_audio_config, echo_emulation_config, @@ -317,10 +325,6 @@ std::unique_ptr TestPeerFactory::CreateTestPeer( components->worker_thread = owned_worker_thread.get(); } - // Store `webrtc::AudioProcessing` into local variable before move of - // `components->pcf_dependencies` - rtc::scoped_refptr audio_processing = - components->pcf_dependencies->audio_processing; PeerConnectionFactoryDependencies pcf_deps = CreatePCFDependencies( std::move(components->pcf_dependencies), time_controller_, std::move(audio_device_module), signaling_thread_, @@ -328,6 +332,10 @@ std::unique_ptr TestPeerFactory::CreateTestPeer( rtc::scoped_refptr peer_connection_factory = CreateModularPeerConnectionFactory(std::move(pcf_deps)); peer_connection_factory->SetOptions(params->peer_connection_factory_options); + if (params->aec_dump_path) { + peer_connection_factory->StartAecDump( + FileWrapper::OpenWriteOnly(*params->aec_dump_path).Release(), -1); + } // Create peer connection. PeerConnectionDependencies pc_deps = @@ -340,11 +348,10 @@ std::unique_ptr TestPeerFactory::CreateTestPeer( .MoveValue(); peer_connection->SetBitrate(params->bitrate_settings); - return absl::WrapUnique( - new TestPeer(peer_connection_factory, peer_connection, - std::move(observer), std::move(*params), - std::move(*configurable_params), std::move(video_sources), - audio_processing, std::move(owned_worker_thread))); + return absl::WrapUnique(new TestPeer( + peer_connection_factory, peer_connection, std::move(observer), + std::move(*params), std::move(*configurable_params), + std::move(video_sources), std::move(owned_worker_thread))); } } // namespace webrtc_pc_e2e diff --git a/test/pc/e2e/test_peer_factory.h b/test/pc/e2e/test_peer_factory.h index 34462c14da..aa42f98089 100644 --- a/test/pc/e2e/test_peer_factory.h +++ b/test/pc/e2e/test_peer_factory.h @@ -11,19 +11,17 @@ #ifndef TEST_PC_E2E_TEST_PEER_FACTORY_H_ #define TEST_PC_E2E_TEST_PEER_FACTORY_H_ -#include #include +#include #include -#include -#include "absl/strings/string_view.h" -#include "api/rtc_event_log/rtc_event_log_factory.h" +#include "absl/base/macros.h" #include "api/task_queue/task_queue_base.h" #include "api/test/pclf/media_configuration.h" -#include "api/test/pclf/media_quality_test_params.h" #include "api/test/pclf/peer_configurer.h" #include "api/test/time_controller.h" -#include "modules/audio_device/include/test_audio_device.h" +#include "pc/test/mock_peer_connection_observers.h" +#include "rtc_base/thread.h" #include "test/pc/e2e/analyzer/video/video_quality_analyzer_injection_helper.h" #include "test/pc/e2e/test_peer.h" @@ -51,15 +49,21 @@ class TestPeerFactory { // factories and call factory. // `video_analyzer_helper` will be used to setup video quality analysis for // created peers. - // `task_queue` will be used for AEC dump if it is requested. + TestPeerFactory(rtc::Thread* signaling_thread, + TimeController& time_controller, + VideoQualityAnalyzerInjectionHelper* video_analyzer_helper) + : signaling_thread_(signaling_thread), + time_controller_(time_controller), + video_analyzer_helper_(video_analyzer_helper) {} + + ABSL_DEPRECATE_AND_INLINE() TestPeerFactory(rtc::Thread* signaling_thread, TimeController& time_controller, VideoQualityAnalyzerInjectionHelper* video_analyzer_helper, - TaskQueueBase* task_queue) - : signaling_thread_(signaling_thread), - time_controller_(time_controller), - video_analyzer_helper_(video_analyzer_helper), - task_queue_(task_queue) {} + TaskQueueBase* /*task_queue*/) + : TestPeerFactory(signaling_thread, + time_controller, + video_analyzer_helper) {} // Setups all components, that should be provided to WebRTC // PeerConnectionFactory and PeerConnection creation methods, @@ -75,7 +79,6 @@ class TestPeerFactory { rtc::Thread* signaling_thread_; TimeController& time_controller_; VideoQualityAnalyzerInjectionHelper* video_analyzer_helper_; - TaskQueueBase* const task_queue_; }; } // namespace webrtc_pc_e2e