Propagate TaskQueueFactory to AudioDeviceBuffer

keep using GlobalTaskQueueFactory in android/ios bindings.
Switch to DefaultTaskQueueFactory in tests.

Bug: webrtc:10284
Change-Id: I034c70542be5eeb830be86527830d51204fb2855
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130223
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27380}
This commit is contained in:
Danil Chapovalov
2019-04-01 09:16:12 +02:00
committed by Commit Bot
parent 105a10aef0
commit 1c41be6e05
24 changed files with 137 additions and 45 deletions

View File

@ -17,6 +17,8 @@
#include "absl/types/optional.h"
#include "api/array_view.h"
#include "api/scoped_refptr.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/task_queue/task_queue_factory.h"
#include "modules/audio_device/audio_device_impl.h"
#include "modules/audio_device/include/audio_device.h"
#include "modules/audio_device/include/mock_audio_transport.h"
@ -510,7 +512,9 @@ class MockAudioTransport : public test::MockAudioTransport {
class AudioDeviceTest
: public ::testing::TestWithParam<webrtc::AudioDeviceModule::AudioLayer> {
protected:
AudioDeviceTest() : audio_layer_(GetParam()) {
AudioDeviceTest()
: audio_layer_(GetParam()),
task_queue_factory_(CreateDefaultTaskQueueFactory()) {
// TODO(webrtc:9778): Re-enable on THREAD_SANITIZER?
#if !defined(ADDRESS_SANITIZER) && !defined(MEMORY_SANITIZER) && \
!defined(WEBRTC_DUMMY_AUDIO_BUILD) && !defined(THREAD_SANITIZER)
@ -579,7 +583,8 @@ class AudioDeviceTest
// The value of |audio_layer_| is set at construction by GetParam() and two
// different layers are tested on Windows only.
if (audio_layer_ == AudioDeviceModule::kPlatformDefaultAudio) {
return AudioDeviceModule::CreateForTest(audio_layer_);
return AudioDeviceModule::CreateForTest(audio_layer_,
task_queue_factory_.get());
} else if (audio_layer_ == AudioDeviceModule::kWindowsCoreAudio2) {
#ifdef WEBRTC_WIN
// We must initialize the COM library on a thread before we calling any of
@ -590,7 +595,8 @@ class AudioDeviceTest
EXPECT_TRUE(com_initializer_->Succeeded());
EXPECT_TRUE(webrtc_win::core_audio_utility::IsSupported());
EXPECT_TRUE(webrtc_win::core_audio_utility::IsMMCSSSupported());
return CreateWindowsCoreAudioAudioDeviceModuleForTest();
return CreateWindowsCoreAudioAudioDeviceModuleForTest(
task_queue_factory_.get());
#else
return nullptr;
#endif
@ -647,6 +653,7 @@ class AudioDeviceTest
std::unique_ptr<webrtc_win::ScopedCOMInitializer> com_initializer_;
#endif
AudioDeviceModule::AudioLayer audio_layer_;
std::unique_ptr<TaskQueueFactory> task_queue_factory_;
bool requirements_satisfied_ = true;
rtc::Event event_;
rtc::scoped_refptr<AudioDeviceModuleForTest> audio_device_;
@ -656,11 +663,13 @@ class AudioDeviceTest
// Instead of using the test fixture, verify that the different factory methods
// work as intended.
TEST(AudioDeviceTestWin, ConstructDestructWithFactory) {
std::unique_ptr<TaskQueueFactory> task_queue_factory =
CreateDefaultTaskQueueFactory();
rtc::scoped_refptr<AudioDeviceModule> audio_device;
// The default factory should work for all platforms when a default ADM is
// requested.
audio_device =
AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio);
audio_device = AudioDeviceModule::Create(
AudioDeviceModule::kPlatformDefaultAudio, task_queue_factory.get());
EXPECT_TRUE(audio_device);
audio_device = nullptr;
#ifdef WEBRTC_WIN
@ -668,8 +677,8 @@ TEST(AudioDeviceTestWin, ConstructDestructWithFactory) {
// specific parts are implemented by an AudioDeviceGeneric object. Verify
// that the old factory can't be used in combination with the latest audio
// layer AudioDeviceModule::kWindowsCoreAudio2.
audio_device =
AudioDeviceModule::Create(AudioDeviceModule::kWindowsCoreAudio2);
audio_device = AudioDeviceModule::Create(
AudioDeviceModule::kWindowsCoreAudio2, task_queue_factory.get());
EXPECT_FALSE(audio_device);
audio_device = nullptr;
// Instead, ensure that the new dedicated factory method called
@ -679,7 +688,8 @@ TEST(AudioDeviceTestWin, ConstructDestructWithFactory) {
webrtc_win::ScopedCOMInitializer com_initializer(
webrtc_win::ScopedCOMInitializer::kMTA);
EXPECT_TRUE(com_initializer.Succeeded());
audio_device = CreateWindowsCoreAudioAudioDeviceModule();
audio_device =
CreateWindowsCoreAudioAudioDeviceModule(task_queue_factory.get());
EXPECT_TRUE(audio_device);
AudioDeviceModule::AudioLayer audio_layer;
EXPECT_EQ(0, audio_device->ActiveAudioLayer(&audio_layer));