From e1d617c266476e63982d3d54ed78bd38c082e0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Kalliom=C3=A4ki?= Date: Mon, 11 Jun 2018 15:28:33 +0200 Subject: [PATCH] Delay the creation of the platform thread in TestAudioDeviceModule. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows constructing TestAudioDeviceModule on a different thread than the worker thread and avoids unnecessary invoke. Before, thread->Start() would fail in a thread check. Bug: b/79961243 Change-Id: I5c55d8feada2b0ae12bc121f3f795e76a8d04059 Reviewed-on: https://webrtc-review.googlesource.com/82941 Reviewed-by: Karl Wiberg Commit-Queue: Sami Kalliomäki Cr-Commit-Position: refs/heads/master@{#23574} --- modules/audio_device/include/test_audio_device.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/audio_device/include/test_audio_device.cc b/modules/audio_device/include/test_audio_device.cc index 8ee21601f0..9d833b312f 100644 --- a/modules/audio_device/include/test_audio_device.cc +++ b/modules/audio_device/include/test_audio_device.cc @@ -61,10 +61,7 @@ class TestAudioDeviceModuleImpl capturing_(false), done_rendering_(true, true), done_capturing_(true, true), - tick_(EventTimerWrapper::Create()), - thread_(TestAudioDeviceModuleImpl::Run, - this, - "TestAudioDeviceModuleImpl") { + tick_(EventTimerWrapper::Create()) { auto good_sample_rate = [](int sr) { return sr == 8000 || sr == 16000 || sr == 32000 || sr == 44100 || sr == 48000; @@ -84,13 +81,15 @@ class TestAudioDeviceModuleImpl ~TestAudioDeviceModuleImpl() { StopPlayout(); StopRecording(); - thread_.Stop(); + thread_->Stop(); } int32_t Init() { RTC_CHECK(tick_->StartTimer(true, kFrameLengthMs / speed_)); - thread_.Start(); - thread_.SetPriority(rtc::kHighPriority); + thread_ = rtc::MakeUnique( + TestAudioDeviceModuleImpl::Run, this, "TestAudioDeviceModuleImpl"); + thread_->Start(); + thread_->SetPriority(rtc::kHighPriority); return 0; } @@ -212,7 +211,7 @@ class TestAudioDeviceModuleImpl rtc::BufferT recording_buffer_ RTC_GUARDED_BY(lock_); std::unique_ptr tick_; - rtc::PlatformThread thread_; + std::unique_ptr thread_; }; // A fake capturer that generates pulses with random samples between