Revert "Separate test/fake_audio_device on API and implementation."

This reverts commit 8ea5f9ae5b757aa3a0e6abe46f5c9ef3aaf4b337.

Reason for revert: breaks downstream project

Original change's description:
> Separate test/fake_audio_device on API and implementation.
> 
> Adding ability of injecting audio in end to end tests, that are using
> WebRTC. For this purpose as a 1st step test/fake_audio_device will
> be moved to production part of WebRTC source code and renamed to
> test_audio_device_module. Old header is replaced with alias to the
> new one and will be deleted after a while.
> 
> Change-Id: I5284d1dd46ce9bf86cf43268e855520606fa8c5c
> 
> Bug: webrtc:8946
> Change-Id: I5284d1dd46ce9bf86cf43268e855520606fa8c5c
> Reviewed-on: https://webrtc-review.googlesource.com/58086
> Commit-Queue: Artem Titov <titovartem@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#22289}

TBR=kwiberg@webrtc.org,titovartem@webrtc.org

Change-Id: I88d9c4f09cc576ed7c9182dcf0a873d25a8bab54
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8946
Reviewed-on: https://webrtc-review.googlesource.com/59720
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22291}
This commit is contained in:
Artem Titov
2018-03-05 15:36:09 +00:00
committed by Commit Bot
parent f9f71b91ae
commit 6723cdc8a4
20 changed files with 723 additions and 797 deletions

View File

@ -98,6 +98,7 @@ if (rtc_include_tests) {
deps = [
":audio",
"../system_wrappers:system_wrappers",
"../test:fake_audio_device",
"../test:test_common",
"../test:test_support",
]
@ -178,6 +179,7 @@ if (rtc_include_tests) {
"../common_audio",
"../rtc_base:rtc_base_approved",
"../system_wrappers",
"../test:fake_audio_device",
"../test:test_common",
"../test:test_main",
"//testing/gtest",
@ -228,6 +230,7 @@ if (rtc_include_tests) {
"../common_audio",
"../rtc_base:rtc_base_approved",
"../system_wrappers",
"../test:fake_audio_device",
"../test:field_trial",
"../test:single_threaded_task_queue",
"../test:test_common",

View File

@ -37,14 +37,14 @@ size_t AudioBweTest::GetNumFlexfecStreams() const {
return 0;
}
std::unique_ptr<TestAudioDeviceModule::Capturer>
std::unique_ptr<test::FakeAudioDevice::Capturer>
AudioBweTest::CreateCapturer() {
return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile());
}
void AudioBweTest::OnFakeAudioDevicesCreated(
TestAudioDeviceModule* send_audio_device,
TestAudioDeviceModule* recv_audio_device) {
test::FakeAudioDevice* send_audio_device,
test::FakeAudioDevice* recv_audio_device) {
send_audio_device_ = send_audio_device;
}

View File

@ -14,6 +14,7 @@
#include <string>
#include "test/call_test.h"
#include "test/fake_audio_device.h"
#include "test/single_threaded_task_queue.h"
namespace webrtc {
@ -32,11 +33,11 @@ class AudioBweTest : public test::EndToEndTest {
size_t GetNumAudioStreams() const override;
size_t GetNumFlexfecStreams() const override;
std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override;
std::unique_ptr<test::FakeAudioDevice::Capturer> CreateCapturer() override;
void OnFakeAudioDevicesCreated(
TestAudioDeviceModule* send_audio_device,
TestAudioDeviceModule* recv_audio_device) override;
test::FakeAudioDevice* send_audio_device,
test::FakeAudioDevice* recv_audio_device) override;
test::PacketTransport* CreateSendTransport(
SingleThreadedTaskQueueForTesting* task_queue,
@ -47,7 +48,7 @@ class AudioBweTest : public test::EndToEndTest {
void PerformTest() override;
private:
TestAudioDeviceModule* send_audio_device_;
test::FakeAudioDevice* send_audio_device_;
};
} // namespace test

View File

@ -12,6 +12,7 @@
#include "audio/test/audio_end_to_end_test.h"
#include "system_wrappers/include/sleep.h"
#include "test/fake_audio_device.h"
#include "test/gtest.h"
namespace webrtc {
@ -42,19 +43,19 @@ size_t AudioEndToEndTest::GetNumFlexfecStreams() const {
return 0;
}
std::unique_ptr<TestAudioDeviceModule::Capturer>
AudioEndToEndTest::CreateCapturer() {
return TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, kSampleRate);
std::unique_ptr<test::FakeAudioDevice::Capturer>
AudioEndToEndTest::CreateCapturer() {
return test::FakeAudioDevice::CreatePulsedNoiseCapturer(32000, kSampleRate);
}
std::unique_ptr<TestAudioDeviceModule::Renderer>
AudioEndToEndTest::CreateRenderer() {
return TestAudioDeviceModule::CreateDiscardRenderer(kSampleRate);
std::unique_ptr<test::FakeAudioDevice::Renderer>
AudioEndToEndTest::CreateRenderer() {
return test::FakeAudioDevice::CreateDiscardRenderer(kSampleRate);
}
void AudioEndToEndTest::OnFakeAudioDevicesCreated(
TestAudioDeviceModule* send_audio_device,
TestAudioDeviceModule* recv_audio_device) {
test::FakeAudioDevice* send_audio_device,
test::FakeAudioDevice* recv_audio_device) {
send_audio_device_ = send_audio_device;
}

View File

@ -24,7 +24,7 @@ class AudioEndToEndTest : public test::EndToEndTest {
AudioEndToEndTest();
protected:
TestAudioDeviceModule* send_audio_device() { return send_audio_device_; }
test::FakeAudioDevice* send_audio_device() { return send_audio_device_; }
const AudioSendStream* send_stream() const { return send_stream_; }
const AudioReceiveStream* receive_stream() const { return receive_stream_; }
@ -34,12 +34,12 @@ class AudioEndToEndTest : public test::EndToEndTest {
size_t GetNumAudioStreams() const override;
size_t GetNumFlexfecStreams() const override;
std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override;
std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer() override;
std::unique_ptr<test::FakeAudioDevice::Capturer> CreateCapturer() override;
std::unique_ptr<test::FakeAudioDevice::Renderer> CreateRenderer() override;
void OnFakeAudioDevicesCreated(
TestAudioDeviceModule* send_audio_device,
TestAudioDeviceModule* recv_audio_device) override;
test::FakeAudioDevice* send_audio_device,
test::FakeAudioDevice* recv_audio_device) override;
test::PacketTransport* CreateSendTransport(
SingleThreadedTaskQueueForTesting* task_queue,
@ -57,7 +57,7 @@ class AudioEndToEndTest : public test::EndToEndTest {
void PerformTest() override;
private:
TestAudioDeviceModule* send_audio_device_ = nullptr;
test::FakeAudioDevice* send_audio_device_ = nullptr;
AudioSendStream* send_stream_ = nullptr;
AudioReceiveStream* receive_stream_ = nullptr;
};

View File

@ -45,12 +45,12 @@ class AudioQualityTest : public AudioEndToEndTest {
"_" + FileSampleRateSuffix() + ".wav";
}
std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer() override {
return TestAudioDeviceModule::CreateWavFileReader(AudioInputFile());
std::unique_ptr<test::FakeAudioDevice::Capturer> CreateCapturer() override {
return test::FakeAudioDevice::CreateWavFileReader(AudioInputFile());
}
std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer() override {
return TestAudioDeviceModule::CreateBoundedWavFileWriter(
std::unique_ptr<test::FakeAudioDevice::Renderer> CreateRenderer() override {
return test::FakeAudioDevice::CreateBoundedWavFileWriter(
AudioOutputFile(), FLAG_sample_rate_hz);
}

View File

@ -283,7 +283,6 @@ if (rtc_include_tests) {
"../api/audio_codecs:builtin_audio_encoder_factory",
"../logging:rtc_event_log_api",
"../modules/audio_coding",
"../modules/audio_device",
"../modules/audio_mixer:audio_mixer_impl",
"../modules/rtp_rtcp",
"../rtc_base:checks",
@ -292,6 +291,7 @@ if (rtc_include_tests) {
"../system_wrappers:metrics_default",
"../system_wrappers:runtime_enabled_features_default",
"../test:direct_transport",
"../test:fake_audio_device",
"../test:field_trial",
"../test:perf_test",
"../test:test_common",

View File

@ -18,7 +18,6 @@
#include "call/video_config.h"
#include "logging/rtc_event_log/rtc_event_log.h"
#include "modules/audio_coding/include/audio_coding_module.h"
#include "modules/audio_device/include/test_audio_device.h"
#include "modules/audio_mixer/audio_mixer_impl.h"
#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/bitrateallocationstrategy.h"
@ -30,6 +29,7 @@
#include "test/direct_transport.h"
#include "test/drifting_clock.h"
#include "test/encoder_settings.h"
#include "test/fake_audio_device.h"
#include "test/fake_encoder.h"
#include "test/field_trial.h"
#include "test/frame_generator.h"
@ -42,6 +42,7 @@
#include "video/transport_adapter.h"
using webrtc::test::DriftingClock;
using webrtc::test::FakeAudioDevice;
namespace webrtc {
@ -169,11 +170,10 @@ void CallPerfTest::TestAudioVideoSync(FecMode fec,
task_queue_.SendTask([&]() {
metrics::Reset();
rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device =
TestAudioDeviceModule::CreateTestAudioDeviceModule(
TestAudioDeviceModule::CreatePulsedNoiseCapturer(256, 48000),
TestAudioDeviceModule::CreateDiscardRenderer(48000),
audio_rtp_speed);
rtc::scoped_refptr<FakeAudioDevice> fake_audio_device =
new rtc::RefCountedObject<FakeAudioDevice>(
FakeAudioDevice::CreatePulsedNoiseCapturer(256, 48000),
FakeAudioDevice::CreateDiscardRenderer(48000), audio_rtp_speed);
EXPECT_EQ(0, fake_audio_device->Init());
AudioState::Config send_audio_state_config;

View File

@ -130,11 +130,8 @@ rtc_source_set("audio_device_generic") {
"fine_audio_buffer.cc",
"fine_audio_buffer.h",
"include/audio_device.h",
"include/audio_device_default.h",
"include/audio_device_defines.h",
"include/fake_audio_device.h",
"include/test_audio_device.cc",
"include/test_audio_device.h",
]
if (build_with_mozilla) {
@ -343,14 +340,12 @@ if (rtc_include_tests) {
sources = [
"fine_audio_buffer_unittest.cc",
"include/test_audio_device_unittest.cc",
]
deps = [
":audio_device",
":mock_audio_device",
"../../api:array_view",
"../../api:optional",
"../../common_audio",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
"../../system_wrappers",

View File

@ -1,137 +0,0 @@
/*
* Copyright (c) 2018 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.
*/
#ifndef MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFAULT_H_
#define MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFAULT_H_
#include "modules/audio_device/include/audio_device.h"
namespace webrtc {
namespace webrtc_impl {
// AudioDeviceModuleDefault template adds default implementation for all
// AudioDeviceModule methods to the class, which inherits from
// AudioDeviceModuleDefault<T>.
template <typename T>
class AudioDeviceModuleDefault : public T {
public:
AudioDeviceModuleDefault() {}
virtual ~AudioDeviceModuleDefault() {}
// TODO(nisse): Fix all users of this class to managed references using
// scoped_refptr. Current code doesn't always use refcounting for this class.
void AddRef() const override {}
rtc::RefCountReleaseStatus Release() const override {
return rtc::RefCountReleaseStatus::kDroppedLastRef;
}
int32_t RegisterAudioCallback(AudioTransport* audioCallback) override {
return 0;
}
int32_t Init() override { return 0; }
int32_t InitSpeaker() override { return 0; }
int32_t SetPlayoutDevice(uint16_t index) override { return 0; }
int32_t SetPlayoutDevice(
AudioDeviceModule::WindowsDeviceType device) override {
return 0;
}
int32_t SetStereoPlayout(bool enable) override { return 0; }
int32_t StopPlayout() override { return 0; }
int32_t InitMicrophone() override { return 0; }
int32_t SetRecordingDevice(uint16_t index) override { return 0; }
int32_t SetRecordingDevice(
AudioDeviceModule::WindowsDeviceType device) override {
return 0;
}
int32_t SetStereoRecording(bool enable) override { return 0; }
int32_t StopRecording() override { return 0; }
int32_t Terminate() override { return 0; }
int32_t ActiveAudioLayer(
AudioDeviceModule::AudioLayer* audioLayer) const override {
return 0;
}
bool Initialized() const override { return true; }
int16_t PlayoutDevices() override { return 0; }
int16_t RecordingDevices() override { return 0; }
int32_t PlayoutDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) override {
return 0;
}
int32_t RecordingDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) override {
return 0;
}
int32_t PlayoutIsAvailable(bool* available) override { return 0; }
int32_t InitPlayout() override { return 0; }
bool PlayoutIsInitialized() const override { return true; }
int32_t RecordingIsAvailable(bool* available) override { return 0; }
int32_t InitRecording() override { return 0; }
bool RecordingIsInitialized() const override { return true; }
int32_t StartPlayout() override { return 0; }
bool Playing() const override { return false; }
int32_t StartRecording() override { return 0; }
bool Recording() const override { return false; }
bool SpeakerIsInitialized() const override { return true; }
bool MicrophoneIsInitialized() const override { return true; }
int32_t SpeakerVolumeIsAvailable(bool* available) override { return 0; }
int32_t SetSpeakerVolume(uint32_t volume) override { return 0; }
int32_t SpeakerVolume(uint32_t* volume) const override { return 0; }
int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override { return 0; }
int32_t MinSpeakerVolume(uint32_t* minVolume) const override { return 0; }
int32_t MicrophoneVolumeIsAvailable(bool* available) override { return 0; }
int32_t SetMicrophoneVolume(uint32_t volume) override { return 0; }
int32_t MicrophoneVolume(uint32_t* volume) const override { return 0; }
int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override { return 0; }
int32_t MinMicrophoneVolume(uint32_t* minVolume) const override { return 0; }
int32_t SpeakerMuteIsAvailable(bool* available) override { return 0; }
int32_t SetSpeakerMute(bool enable) override { return 0; }
int32_t SpeakerMute(bool* enabled) const override { return 0; }
int32_t MicrophoneMuteIsAvailable(bool* available) override { return 0; }
int32_t SetMicrophoneMute(bool enable) override { return 0; }
int32_t MicrophoneMute(bool* enabled) const override { return 0; }
int32_t StereoPlayoutIsAvailable(bool* available) const override {
*available = false;
return 0;
}
int32_t StereoPlayout(bool* enabled) const override { return 0; }
int32_t StereoRecordingIsAvailable(bool* available) const override {
*available = false;
return 0;
}
int32_t StereoRecording(bool* enabled) const override { return 0; }
int32_t PlayoutDelay(uint16_t* delayMS) const override {
*delayMS = 0;
return 0;
}
bool BuiltInAECIsAvailable() const override { return false; }
int32_t EnableBuiltInAEC(bool enable) override { return -1; }
bool BuiltInAGCIsAvailable() const override { return false; }
int32_t EnableBuiltInAGC(bool enable) override { return -1; }
bool BuiltInNSIsAvailable() const override { return false; }
int32_t EnableBuiltInNS(bool enable) override { return -1; }
#if defined(WEBRTC_IOS)
int GetPlayoutAudioParameters(AudioParameters* params) const override {
return -1;
}
int GetRecordAudioParameters(AudioParameters* params) const override {
return -1;
}
#endif // WEBRTC_IOS
};
} // namespace webrtc_impl
} // namespace webrtc
#endif // MODULES_AUDIO_DEVICE_INCLUDE_AUDIO_DEVICE_DEFAULT_H_

View File

@ -12,12 +12,111 @@
#define MODULES_AUDIO_DEVICE_INCLUDE_FAKE_AUDIO_DEVICE_H_
#include "modules/audio_device/include/audio_device.h"
#include "modules/audio_device/include/audio_device_default.h"
namespace webrtc {
class FakeAudioDeviceModule
: public webrtc_impl::AudioDeviceModuleDefault<AudioDeviceModule> {};
class FakeAudioDeviceModule : public AudioDeviceModule {
public:
FakeAudioDeviceModule() {}
virtual ~FakeAudioDeviceModule() {}
// TODO(nisse): Fix all users of this class to managed references using
// scoped_refptr. Current code doesn't always use refcounting for this class.
void AddRef() const override {}
rtc::RefCountReleaseStatus Release() const override {
return rtc::RefCountReleaseStatus::kDroppedLastRef;
}
private:
int32_t RegisterAudioCallback(AudioTransport* audioCallback) override {
return 0;
}
int32_t Init() override { return 0; }
int32_t InitSpeaker() override { return 0; }
int32_t SetPlayoutDevice(uint16_t index) override { return 0; }
int32_t SetPlayoutDevice(WindowsDeviceType device) override { return 0; }
int32_t SetStereoPlayout(bool enable) override { return 0; }
int32_t StopPlayout() override { return 0; }
int32_t InitMicrophone() override { return 0; }
int32_t SetRecordingDevice(uint16_t index) override { return 0; }
int32_t SetRecordingDevice(WindowsDeviceType device) override { return 0; }
int32_t SetStereoRecording(bool enable) override { return 0; }
int32_t StopRecording() override { return 0; }
int32_t Terminate() override { return 0; }
int32_t ActiveAudioLayer(AudioLayer* audioLayer) const override { return 0; }
bool Initialized() const override { return true; }
int16_t PlayoutDevices() override { return 0; }
int16_t RecordingDevices() override { return 0; }
int32_t PlayoutDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) override {
return 0;
}
int32_t RecordingDeviceName(uint16_t index,
char name[kAdmMaxDeviceNameSize],
char guid[kAdmMaxGuidSize]) override {
return 0;
}
int32_t PlayoutIsAvailable(bool* available) override { return 0; }
int32_t InitPlayout() override { return 0; }
bool PlayoutIsInitialized() const override { return true; }
int32_t RecordingIsAvailable(bool* available) override { return 0; }
int32_t InitRecording() override { return 0; }
bool RecordingIsInitialized() const override { return true; }
int32_t StartPlayout() override { return 0; }
bool Playing() const override { return false; }
int32_t StartRecording() override { return 0; }
bool Recording() const override { return false; }
bool SpeakerIsInitialized() const override { return true; }
bool MicrophoneIsInitialized() const override { return true; }
int32_t SpeakerVolumeIsAvailable(bool* available) override { return 0; }
int32_t SetSpeakerVolume(uint32_t volume) override { return 0; }
int32_t SpeakerVolume(uint32_t* volume) const override { return 0; }
int32_t MaxSpeakerVolume(uint32_t* maxVolume) const override { return 0; }
int32_t MinSpeakerVolume(uint32_t* minVolume) const override { return 0; }
int32_t MicrophoneVolumeIsAvailable(bool* available) override { return 0; }
int32_t SetMicrophoneVolume(uint32_t volume) override { return 0; }
int32_t MicrophoneVolume(uint32_t* volume) const override { return 0; }
int32_t MaxMicrophoneVolume(uint32_t* maxVolume) const override { return 0; }
int32_t MinMicrophoneVolume(uint32_t* minVolume) const override { return 0; }
int32_t SpeakerMuteIsAvailable(bool* available) override { return 0; }
int32_t SetSpeakerMute(bool enable) override { return 0; }
int32_t SpeakerMute(bool* enabled) const override { return 0; }
int32_t MicrophoneMuteIsAvailable(bool* available) override { return 0; }
int32_t SetMicrophoneMute(bool enable) override { return 0; }
int32_t MicrophoneMute(bool* enabled) const override { return 0; }
int32_t StereoPlayoutIsAvailable(bool* available) const override {
*available = false;
return 0;
}
int32_t StereoPlayout(bool* enabled) const override { return 0; }
int32_t StereoRecordingIsAvailable(bool* available) const override {
*available = false;
return 0;
}
int32_t StereoRecording(bool* enabled) const override { return 0; }
int32_t PlayoutDelay(uint16_t* delayMS) const override {
*delayMS = 0;
return 0;
}
bool BuiltInAECIsAvailable() const override { return false; }
int32_t EnableBuiltInAEC(bool enable) override { return -1; }
bool BuiltInAGCIsAvailable() const override { return false; }
int32_t EnableBuiltInAGC(bool enable) override { return -1; }
bool BuiltInNSIsAvailable() const override { return false; }
int32_t EnableBuiltInNS(bool enable) override { return -1; }
#if defined(WEBRTC_IOS)
int GetPlayoutAudioParameters(AudioParameters* params) const override {
return -1;
}
int GetRecordAudioParameters(AudioParameters* params) const override {
return -1;
}
#endif // WEBRTC_IOS
};
} // namespace webrtc

View File

@ -1,439 +0,0 @@
/*
* Copyright (c) 2013 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 <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "api/array_view.h"
#include "common_audio/wav_file.h"
#include "modules/audio_device/include/audio_device_default.h"
#include "modules/audio_device/include/test_audio_device.h"
#include "rtc_base/buffer.h"
#include "rtc_base/checks.h"
#include "rtc_base/criticalsection.h"
#include "rtc_base/event.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/random.h"
#include "rtc_base/refcountedobject.h"
#include "system_wrappers/include/event_wrapper.h"
#include "typedefs.h" // NOLINT(build/include)
namespace webrtc {
class EventTimerWrapper;
namespace {
constexpr int kFrameLengthMs = 10;
constexpr int kFramesPerSecond = 1000 / kFrameLengthMs;
// TestAudioDeviceModule implements an AudioDevice module that can act both as a
// capturer and a renderer. It will use 10ms audio frames.
class TestAudioDeviceModuleImpl
: public webrtc_impl::AudioDeviceModuleDefault<TestAudioDeviceModule> {
public:
// Creates a new TestAudioDeviceModule. When capturing or playing, 10 ms audio
// frames will be processed every 10ms / |speed|.
// |capturer| is an object that produces audio data. Can be nullptr if this
// device is never used for recording.
// |renderer| is an object that receives audio data that would have been
// played out. Can be nullptr if this device is never used for playing.
// Use one of the Create... functions to get these instances.
TestAudioDeviceModuleImpl(std::unique_ptr<Capturer> capturer,
std::unique_ptr<Renderer> renderer,
float speed)
: capturer_(std::move(capturer)),
renderer_(std::move(renderer)),
speed_(speed),
audio_callback_(nullptr),
rendering_(false),
capturing_(false),
done_rendering_(true, true),
done_capturing_(true, true),
tick_(EventTimerWrapper::Create()),
thread_(TestAudioDeviceModuleImpl::Run,
this,
"TestAudioDeviceModuleImpl") {
auto good_sample_rate = [](int sr) {
return sr == 8000 || sr == 16000 || sr == 32000 || sr == 44100 ||
sr == 48000;
};
if (renderer_) {
const int sample_rate = renderer_->SamplingFrequency();
playout_buffer_.resize(SamplesPerFrame(sample_rate), 0);
RTC_CHECK(good_sample_rate(sample_rate));
}
if (capturer_) {
RTC_CHECK(good_sample_rate(capturer_->SamplingFrequency()));
}
}
~TestAudioDeviceModuleImpl() override {
StopPlayout();
StopRecording();
thread_.Stop();
}
int32_t Init() override {
RTC_CHECK(tick_->StartTimer(true, kFrameLengthMs / speed_));
thread_.Start();
thread_.SetPriority(rtc::kHighPriority);
return 0;
}
int32_t RegisterAudioCallback(AudioTransport* callback) override {
rtc::CritScope cs(&lock_);
RTC_DCHECK(callback || audio_callback_);
audio_callback_ = callback;
return 0;
}
int32_t StartPlayout() override {
rtc::CritScope cs(&lock_);
RTC_CHECK(renderer_);
rendering_ = true;
done_rendering_.Reset();
return 0;
}
int32_t StopPlayout() override {
rtc::CritScope cs(&lock_);
rendering_ = false;
done_rendering_.Set();
return 0;
}
int32_t StartRecording() override {
rtc::CritScope cs(&lock_);
RTC_CHECK(capturer_);
capturing_ = true;
done_capturing_.Reset();
return 0;
}
int32_t StopRecording() override {
rtc::CritScope cs(&lock_);
capturing_ = false;
done_capturing_.Set();
return 0;
}
bool Playing() const override {
rtc::CritScope cs(&lock_);
return rendering_;
}
bool Recording() const override {
rtc::CritScope cs(&lock_);
return capturing_;
}
// Blocks until the Renderer refuses to receive data.
// Returns false if |timeout_ms| passes before that happens.
bool WaitForPlayoutEnd(int timeout_ms = rtc::Event::kForever) override {
return done_rendering_.Wait(timeout_ms);
}
// Blocks until the Recorder stops producing data.
// Returns false if |timeout_ms| passes before that happens.
bool WaitForRecordingEnd(int timeout_ms = rtc::Event::kForever) override {
return done_capturing_.Wait(timeout_ms);
}
private:
void ProcessAudio() {
{
rtc::CritScope cs(&lock_);
if (capturing_) {
// Capture 10ms of audio. 2 bytes per sample.
const bool keep_capturing = capturer_->Capture(&recording_buffer_);
uint32_t new_mic_level;
if (recording_buffer_.size() > 0) {
audio_callback_->RecordedDataIsAvailable(
recording_buffer_.data(), recording_buffer_.size(), 2, 1,
capturer_->SamplingFrequency(), 0, 0, 0, false, new_mic_level);
}
if (!keep_capturing) {
capturing_ = false;
done_capturing_.Set();
}
}
if (rendering_) {
size_t samples_out;
int64_t elapsed_time_ms;
int64_t ntp_time_ms;
const int sampling_frequency = renderer_->SamplingFrequency();
audio_callback_->NeedMorePlayData(SamplesPerFrame(sampling_frequency),
2, 1, sampling_frequency,
playout_buffer_.data(), samples_out,
&elapsed_time_ms, &ntp_time_ms);
const bool keep_rendering = renderer_->Render(
rtc::ArrayView<const int16_t>(playout_buffer_.data(), samples_out));
if (!keep_rendering) {
rendering_ = false;
done_rendering_.Set();
}
}
}
tick_->Wait(WEBRTC_EVENT_INFINITE);
}
static bool Run(void* obj) {
static_cast<TestAudioDeviceModuleImpl*>(obj)->ProcessAudio();
return true;
}
const std::unique_ptr<Capturer> capturer_ RTC_GUARDED_BY(lock_);
const std::unique_ptr<Renderer> renderer_ RTC_GUARDED_BY(lock_);
const float speed_;
rtc::CriticalSection lock_;
AudioTransport* audio_callback_ RTC_GUARDED_BY(lock_);
bool rendering_ RTC_GUARDED_BY(lock_);
bool capturing_ RTC_GUARDED_BY(lock_);
rtc::Event done_rendering_;
rtc::Event done_capturing_;
std::vector<int16_t> playout_buffer_ RTC_GUARDED_BY(lock_);
rtc::BufferT<int16_t> recording_buffer_ RTC_GUARDED_BY(lock_);
std::unique_ptr<EventTimerWrapper> tick_;
rtc::PlatformThread thread_;
};
// A fake capturer that generates pulses with random samples between
// -max_amplitude and +max_amplitude.
class PulsedNoiseCapturerImpl final
: public TestAudioDeviceModule::PulsedNoiseCapturer {
public:
// Assuming 10ms audio packets.
PulsedNoiseCapturerImpl(int16_t max_amplitude, int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
fill_with_zero_(false),
random_generator_(1),
max_amplitude_(max_amplitude) {
RTC_DCHECK_GT(max_amplitude, 0);
}
int SamplingFrequency() const override { return sampling_frequency_in_hz_; }
bool Capture(rtc::BufferT<int16_t>* buffer) override {
fill_with_zero_ = !fill_with_zero_;
int16_t max_amplitude;
{
rtc::CritScope cs(&lock_);
max_amplitude = max_amplitude_;
}
buffer->SetData(
TestAudioDeviceModule::SamplesPerFrame(sampling_frequency_in_hz_),
[&](rtc::ArrayView<int16_t> data) {
if (fill_with_zero_) {
std::fill(data.begin(), data.end(), 0);
} else {
std::generate(data.begin(), data.end(), [&]() {
return random_generator_.Rand(-max_amplitude, max_amplitude);
});
}
return data.size();
});
return true;
}
void SetMaxAmplitude(int16_t amplitude) override {
rtc::CritScope cs(&lock_);
max_amplitude_ = amplitude;
}
private:
int sampling_frequency_in_hz_;
bool fill_with_zero_;
Random random_generator_;
rtc::CriticalSection lock_;
int16_t max_amplitude_ RTC_GUARDED_BY(lock_);
};
class WavFileReader final : public TestAudioDeviceModule::Capturer {
public:
WavFileReader(std::string filename, int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
wav_reader_(filename) {
RTC_CHECK_EQ(wav_reader_.sample_rate(), sampling_frequency_in_hz);
RTC_CHECK_EQ(wav_reader_.num_channels(), 1);
}
int SamplingFrequency() const override { return sampling_frequency_in_hz_; }
bool Capture(rtc::BufferT<int16_t>* buffer) override {
buffer->SetData(
TestAudioDeviceModule::SamplesPerFrame(sampling_frequency_in_hz_),
[&](rtc::ArrayView<int16_t> data) {
return wav_reader_.ReadSamples(data.size(), data.data());
});
return buffer->size() > 0;
}
private:
int sampling_frequency_in_hz_;
WavReader wav_reader_;
};
class WavFileWriter final : public TestAudioDeviceModule::Renderer {
public:
WavFileWriter(std::string filename, int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
wav_writer_(filename, sampling_frequency_in_hz, 1) {}
int SamplingFrequency() const override { return sampling_frequency_in_hz_; }
bool Render(rtc::ArrayView<const int16_t> data) override {
wav_writer_.WriteSamples(data.data(), data.size());
return true;
}
private:
int sampling_frequency_in_hz_;
WavWriter wav_writer_;
};
class BoundedWavFileWriter : public TestAudioDeviceModule::Renderer {
public:
BoundedWavFileWriter(std::string filename, int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
wav_writer_(filename, sampling_frequency_in_hz, 1),
silent_audio_(
TestAudioDeviceModule::SamplesPerFrame(sampling_frequency_in_hz),
0),
started_writing_(false),
trailing_zeros_(0) {}
int SamplingFrequency() const override { return sampling_frequency_in_hz_; }
bool Render(rtc::ArrayView<const int16_t> data) override {
const int16_t kAmplitudeThreshold = 5;
const int16_t* begin = data.begin();
const int16_t* end = data.end();
if (!started_writing_) {
// Cut off silence at the beginning.
while (begin < end) {
if (std::abs(*begin) > kAmplitudeThreshold) {
started_writing_ = true;
break;
}
++begin;
}
}
if (started_writing_) {
// Cut off silence at the end.
while (begin < end) {
if (*(end - 1) != 0) {
break;
}
--end;
}
if (begin < end) {
// If it turns out that the silence was not final, need to write all the
// skipped zeros and continue writing audio.
while (trailing_zeros_ > 0) {
const size_t zeros_to_write =
std::min(trailing_zeros_, silent_audio_.size());
wav_writer_.WriteSamples(silent_audio_.data(), zeros_to_write);
trailing_zeros_ -= zeros_to_write;
}
wav_writer_.WriteSamples(begin, end - begin);
}
// Save the number of zeros we skipped in case this needs to be restored.
trailing_zeros_ += data.end() - end;
}
return true;
}
private:
int sampling_frequency_in_hz_;
WavWriter wav_writer_;
std::vector<int16_t> silent_audio_;
bool started_writing_;
size_t trailing_zeros_;
};
class DiscardRenderer final : public TestAudioDeviceModule::Renderer {
public:
explicit DiscardRenderer(int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz) {}
int SamplingFrequency() const override { return sampling_frequency_in_hz_; }
bool Render(rtc::ArrayView<const int16_t> data) override { return true; }
private:
int sampling_frequency_in_hz_;
};
} // namespace
size_t TestAudioDeviceModule::SamplesPerFrame(int sampling_frequency_in_hz) {
return rtc::CheckedDivExact(sampling_frequency_in_hz, kFramesPerSecond);
}
rtc::scoped_refptr<TestAudioDeviceModule>
TestAudioDeviceModule::CreateTestAudioDeviceModule(
std::unique_ptr<Capturer> capturer,
std::unique_ptr<Renderer> renderer,
float speed) {
return new rtc::RefCountedObject<TestAudioDeviceModuleImpl>(
std::move(capturer), std::move(renderer), speed);
}
std::unique_ptr<TestAudioDeviceModule::PulsedNoiseCapturer>
TestAudioDeviceModule::CreatePulsedNoiseCapturer(int16_t max_amplitude,
int sampling_frequency_in_hz) {
return std::unique_ptr<TestAudioDeviceModule::PulsedNoiseCapturer>(
new PulsedNoiseCapturerImpl(max_amplitude, sampling_frequency_in_hz));
}
std::unique_ptr<TestAudioDeviceModule::Capturer>
TestAudioDeviceModule::CreateWavFileReader(std::string filename,
int sampling_frequency_in_hz) {
return std::unique_ptr<TestAudioDeviceModule::Capturer>(
new WavFileReader(filename, sampling_frequency_in_hz));
}
std::unique_ptr<TestAudioDeviceModule::Capturer>
TestAudioDeviceModule::CreateWavFileReader(std::string filename) {
int sampling_frequency_in_hz = WavReader(filename).sample_rate();
return std::unique_ptr<TestAudioDeviceModule::Capturer>(
new WavFileReader(filename, sampling_frequency_in_hz));
}
std::unique_ptr<TestAudioDeviceModule::Renderer>
TestAudioDeviceModule::CreateWavFileWriter(std::string filename,
int sampling_frequency_in_hz) {
return std::unique_ptr<TestAudioDeviceModule::Renderer>(
new WavFileWriter(filename, sampling_frequency_in_hz));
}
std::unique_ptr<TestAudioDeviceModule::Renderer>
TestAudioDeviceModule::CreateBoundedWavFileWriter(
std::string filename,
int sampling_frequency_in_hz) {
return std::unique_ptr<TestAudioDeviceModule::Renderer>(
new BoundedWavFileWriter(filename, sampling_frequency_in_hz));
}
std::unique_ptr<TestAudioDeviceModule::Renderer>
TestAudioDeviceModule::CreateDiscardRenderer(int sampling_frequency_in_hz) {
return std::unique_ptr<TestAudioDeviceModule::Renderer>(
new DiscardRenderer(sampling_frequency_in_hz));
}
} // namespace webrtc

View File

@ -1,131 +0,0 @@
/*
* Copyright (c) 2018 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.
*/
#ifndef MODULES_AUDIO_DEVICE_INCLUDE_TEST_AUDIO_DEVICE_H_
#define MODULES_AUDIO_DEVICE_INCLUDE_TEST_AUDIO_DEVICE_H_
#include <memory>
#include <string>
#include <vector>
#include "modules/audio_device/include/audio_device.h"
#include "rtc_base/buffer.h"
#include "rtc_base/event.h"
#include "typedefs.h" // NOLINT(build/include)
namespace webrtc {
// TestAudioDeviceModule implements an AudioDevice module that can act both as a
// capturer and a renderer. It will use 10ms audio frames.
class TestAudioDeviceModule : public AudioDeviceModule {
public:
// Returns the number of samples that Capturers and Renderers with this
// sampling frequency will work with every time Capture or Render is called.
static size_t SamplesPerFrame(int sampling_frequency_in_hz);
class Capturer {
public:
virtual ~Capturer() {}
// Returns the sampling frequency in Hz of the audio data that this
// capturer produces.
virtual int SamplingFrequency() const = 0;
// Replaces the contents of |buffer| with 10ms of captured audio data
// (see TestAudioDeviceModule::SamplesPerFrame). Returns true if the
// capturer can keep producing data, or false when the capture finishes.
virtual bool Capture(rtc::BufferT<int16_t>* buffer) = 0;
};
class Renderer {
public:
virtual ~Renderer() {}
// Returns the sampling frequency in Hz of the audio data that this
// renderer receives.
virtual int SamplingFrequency() const = 0;
// Renders the passed audio data and returns true if the renderer wants
// to keep receiving data, or false otherwise.
virtual bool Render(rtc::ArrayView<const int16_t> data) = 0;
};
// A fake capturer that generates pulses with random samples between
// -max_amplitude and +max_amplitude.
class PulsedNoiseCapturer : public Capturer {
public:
virtual ~PulsedNoiseCapturer() {}
virtual void SetMaxAmplitude(int16_t amplitude) = 0;
};
virtual ~TestAudioDeviceModule() {}
// Creates a new TestAudioDeviceModule. When capturing or playing, 10 ms audio
// frames will be processed every 10ms / |speed|.
// |capturer| is an object that produces audio data. Can be nullptr if this
// device is never used for recording.
// |renderer| is an object that receives audio data that would have been
// played out. Can be nullptr if this device is never used for playing.
// Use one of the Create... functions to get these instances.
static rtc::scoped_refptr<TestAudioDeviceModule> CreateTestAudioDeviceModule(
std::unique_ptr<Capturer> capturer,
std::unique_ptr<Renderer> renderer,
float speed = 1);
// Returns a Capturer instance that generates a signal where every second
// frame is zero and every second frame is evenly distributed random noise
// with max amplitude |max_amplitude|.
static std::unique_ptr<PulsedNoiseCapturer> CreatePulsedNoiseCapturer(
int16_t max_amplitude,
int sampling_frequency_in_hz);
// Returns a Capturer instance that gets its data from a file.
static std::unique_ptr<Capturer> CreateWavFileReader(
std::string filename,
int sampling_frequency_in_hz);
// Returns a Capturer instance that gets its data from a file.
// Automatically detects sample rate.
static std::unique_ptr<Capturer> CreateWavFileReader(std::string filename);
// Returns a Renderer instance that writes its data to a file.
static std::unique_ptr<Renderer> CreateWavFileWriter(
std::string filename,
int sampling_frequency_in_hz);
// Returns a Renderer instance that writes its data to a WAV file, cutting
// off silence at the beginning (not necessarily perfect silence, see
// kAmplitudeThreshold) and at the end (only actual 0 samples in this case).
static std::unique_ptr<Renderer> CreateBoundedWavFileWriter(
std::string filename,
int sampling_frequency_in_hz);
// Returns a Renderer instance that does nothing with the audio data.
static std::unique_ptr<Renderer> CreateDiscardRenderer(
int sampling_frequency_in_hz);
virtual int32_t Init() = 0;
virtual int32_t RegisterAudioCallback(AudioTransport* callback) = 0;
virtual int32_t StartPlayout() = 0;
virtual int32_t StopPlayout() = 0;
virtual int32_t StartRecording() = 0;
virtual int32_t StopRecording() = 0;
virtual bool Playing() const = 0;
virtual bool Recording() const = 0;
// Blocks until the Renderer refuses to receive data.
// Returns false if |timeout_ms| passes before that happens.
virtual bool WaitForPlayoutEnd(int timeout_ms = rtc::Event::kForever) = 0;
// Blocks until the Recorder stops producing data.
// Returns false if |timeout_ms| passes before that happens.
virtual bool WaitForRecordingEnd(int timeout_ms = rtc::Event::kForever) = 0;
};
} // namespace webrtc
#endif // MODULES_AUDIO_DEVICE_INCLUDE_TEST_AUDIO_DEVICE_H_

View File

@ -326,18 +326,19 @@ if (rtc_include_tests) {
rtc_test("test_support_unittests") {
deps = [
":fake_audio_device",
":perf_test",
":rtp_test_utils",
"../api:video_frame_api",
"../api:video_frame_api_i420",
"../call:call_interfaces",
"../common_audio",
"../modules/audio_device",
"../modules/rtp_rtcp",
"../rtc_base:rtc_base_approved",
"../system_wrappers",
]
sources = [
"fake_audio_device_unittest.cc",
"fake_network_pipe_unittest.cc",
"frame_generator_unittest.cc",
"rtp_file_reader_unittest.cc",
@ -532,6 +533,7 @@ rtc_source_set("fake_audio_device") {
visibility = [ "*" ]
testonly = true
sources = [
"fake_audio_device.cc",
"fake_audio_device.h",
]
if (!build_with_chromium && is_clang) {
@ -543,7 +545,7 @@ rtc_source_set("fake_audio_device") {
"../:typedefs",
"../api:array_view",
"../common_audio:common_audio",
"../modules/audio_device",
"../modules/audio_device:audio_device",
"../rtc_base:checks",
"../rtc_base:rtc_base_approved",
"../system_wrappers",
@ -592,6 +594,7 @@ rtc_source_set("test_common") {
deps = [
":direct_transport",
":fake_audio_device",
":rtp_test_utils",
":test_support",
":video_test_common",
@ -613,7 +616,6 @@ rtc_source_set("test_common") {
"../logging:rtc_event_log_api",
"../logging:rtc_event_log_impl_base",
"../media:rtc_media_base",
"../modules/audio_device",
"../modules/audio_device:mock_audio_device",
"../modules/audio_mixer:audio_mixer_impl",
"../modules/audio_processing",

View File

@ -333,11 +333,11 @@ void CallTest::CreateFrameGeneratorCapturer(int framerate,
}
void CallTest::CreateFakeAudioDevices(
std::unique_ptr<TestAudioDeviceModule::Capturer> capturer,
std::unique_ptr<TestAudioDeviceModule::Renderer> renderer) {
fake_send_audio_device_ = TestAudioDeviceModule::CreateTestAudioDeviceModule(
std::unique_ptr<FakeAudioDevice::Capturer> capturer,
std::unique_ptr<FakeAudioDevice::Renderer> renderer) {
fake_send_audio_device_ = new rtc::RefCountedObject<FakeAudioDevice>(
std::move(capturer), nullptr, 1.f);
fake_recv_audio_device_ = TestAudioDeviceModule::CreateTestAudioDeviceModule(
fake_recv_audio_device_ = new rtc::RefCountedObject<FakeAudioDevice>(
nullptr, std::move(renderer), 1.f);
}
@ -496,17 +496,17 @@ BaseTest::BaseTest(unsigned int timeout_ms)
BaseTest::~BaseTest() {
}
std::unique_ptr<TestAudioDeviceModule::Capturer> BaseTest::CreateCapturer() {
return TestAudioDeviceModule::CreatePulsedNoiseCapturer(256, 48000);
std::unique_ptr<FakeAudioDevice::Capturer> BaseTest::CreateCapturer() {
return FakeAudioDevice::CreatePulsedNoiseCapturer(256, 48000);
}
std::unique_ptr<TestAudioDeviceModule::Renderer> BaseTest::CreateRenderer() {
return TestAudioDeviceModule::CreateDiscardRenderer(48000);
std::unique_ptr<FakeAudioDevice::Renderer> BaseTest::CreateRenderer() {
return FakeAudioDevice::CreateDiscardRenderer(48000);
}
void BaseTest::OnFakeAudioDevicesCreated(
TestAudioDeviceModule* send_audio_device,
TestAudioDeviceModule* recv_audio_device) {}
void BaseTest::OnFakeAudioDevicesCreated(FakeAudioDevice* send_audio_device,
FakeAudioDevice* recv_audio_device) {
}
Call::Config BaseTest::GetSenderCallConfig() {
return Call::Config(event_log_.get());

View File

@ -16,8 +16,8 @@
#include "call/call.h"
#include "call/rtp_transport_controller_send.h"
#include "logging/rtc_event_log/rtc_event_log.h"
#include "modules/audio_device/include/test_audio_device.h"
#include "test/encoder_settings.h"
#include "test/fake_audio_device.h"
#include "test/fake_decoder.h"
#include "test/fake_encoder.h"
#include "test/fake_videorenderer.h"
@ -99,8 +99,8 @@ class CallTest : public ::testing::Test {
int height);
void CreateFrameGeneratorCapturer(int framerate, int width, int height);
void CreateFakeAudioDevices(
std::unique_ptr<TestAudioDeviceModule::Capturer> capturer,
std::unique_ptr<TestAudioDeviceModule::Renderer> renderer);
std::unique_ptr<FakeAudioDevice::Capturer> capturer,
std::unique_ptr<FakeAudioDevice::Renderer> renderer);
void CreateVideoStreams();
void CreateAudioStreams();
@ -150,8 +150,8 @@ class CallTest : public ::testing::Test {
private:
rtc::scoped_refptr<AudioProcessing> apm_send_;
rtc::scoped_refptr<AudioProcessing> apm_recv_;
rtc::scoped_refptr<TestAudioDeviceModule> fake_send_audio_device_;
rtc::scoped_refptr<TestAudioDeviceModule> fake_recv_audio_device_;
rtc::scoped_refptr<test::FakeAudioDevice> fake_send_audio_device_;
rtc::scoped_refptr<test::FakeAudioDevice> fake_recv_audio_device_;
};
class BaseTest : public RtpRtcpObserver {
@ -167,11 +167,10 @@ class BaseTest : public RtpRtcpObserver {
virtual size_t GetNumAudioStreams() const;
virtual size_t GetNumFlexfecStreams() const;
virtual std::unique_ptr<TestAudioDeviceModule::Capturer> CreateCapturer();
virtual std::unique_ptr<TestAudioDeviceModule::Renderer> CreateRenderer();
virtual void OnFakeAudioDevicesCreated(
TestAudioDeviceModule* send_audio_device,
TestAudioDeviceModule* recv_audio_device);
virtual std::unique_ptr<FakeAudioDevice::Capturer> CreateCapturer();
virtual std::unique_ptr<FakeAudioDevice::Renderer> CreateRenderer();
virtual void OnFakeAudioDevicesCreated(FakeAudioDevice* send_audio_device,
FakeAudioDevice* recv_audio_device);
virtual Call::Config GetSenderCallConfig();
virtual Call::Config GetReceiverCallConfig();

379
test/fake_audio_device.cc Normal file
View File

@ -0,0 +1,379 @@
/*
* Copyright (c) 2013 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 "test/fake_audio_device.h"
#include <algorithm>
#include <utility>
#include "common_audio/wav_file.h"
#include "rtc_base/checks.h"
#include "system_wrappers/include/event_wrapper.h"
namespace webrtc {
namespace {
constexpr int kFrameLengthMs = 10;
constexpr int kFramesPerSecond = 1000 / kFrameLengthMs;
class WavFileReader final : public test::FakeAudioDevice::Capturer {
public:
WavFileReader(std::string filename, int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
wav_reader_(filename) {
RTC_CHECK_EQ(wav_reader_.sample_rate(), sampling_frequency_in_hz);
RTC_CHECK_EQ(wav_reader_.num_channels(), 1);
}
int SamplingFrequency() const override {
return sampling_frequency_in_hz_;
}
bool Capture(rtc::BufferT<int16_t>* buffer) override {
buffer->SetData(
test::FakeAudioDevice::SamplesPerFrame(sampling_frequency_in_hz_),
[&](rtc::ArrayView<int16_t> data) {
return wav_reader_.ReadSamples(data.size(), data.data());
});
return buffer->size() > 0;
}
private:
int sampling_frequency_in_hz_;
WavReader wav_reader_;
};
class WavFileWriter final : public test::FakeAudioDevice::Renderer {
public:
WavFileWriter(std::string filename, int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
wav_writer_(filename, sampling_frequency_in_hz, 1) {}
int SamplingFrequency() const override {
return sampling_frequency_in_hz_;
}
bool Render(rtc::ArrayView<const int16_t> data) override {
wav_writer_.WriteSamples(data.data(), data.size());
return true;
}
private:
int sampling_frequency_in_hz_;
WavWriter wav_writer_;
};
class BoundedWavFileWriter : public test::FakeAudioDevice::Renderer {
public:
BoundedWavFileWriter(std::string filename, int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
wav_writer_(filename, sampling_frequency_in_hz, 1),
silent_audio_(test::FakeAudioDevice::SamplesPerFrame(
sampling_frequency_in_hz), 0),
started_writing_(false),
trailing_zeros_(0) {}
int SamplingFrequency() const override {
return sampling_frequency_in_hz_;
}
bool Render(rtc::ArrayView<const int16_t> data) override {
const int16_t kAmplitudeThreshold = 5;
const int16_t* begin = data.begin();
const int16_t* end = data.end();
if (!started_writing_) {
// Cut off silence at the beginning.
while (begin < end) {
if (std::abs(*begin) > kAmplitudeThreshold) {
started_writing_ = true;
break;
}
++begin;
}
}
if (started_writing_) {
// Cut off silence at the end.
while (begin < end) {
if (*(end - 1) != 0) {
break;
}
--end;
}
if (begin < end) {
// If it turns out that the silence was not final, need to write all the
// skipped zeros and continue writing audio.
while (trailing_zeros_ > 0) {
const size_t zeros_to_write = std::min(trailing_zeros_,
silent_audio_.size());
wav_writer_.WriteSamples(silent_audio_.data(), zeros_to_write);
trailing_zeros_ -= zeros_to_write;
}
wav_writer_.WriteSamples(begin, end - begin);
}
// Save the number of zeros we skipped in case this needs to be restored.
trailing_zeros_ += data.end() - end;
}
return true;
}
private:
int sampling_frequency_in_hz_;
WavWriter wav_writer_;
std::vector<int16_t> silent_audio_;
bool started_writing_;
size_t trailing_zeros_;
};
class DiscardRenderer final : public test::FakeAudioDevice::Renderer {
public:
explicit DiscardRenderer(int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz) {}
int SamplingFrequency() const override {
return sampling_frequency_in_hz_;
}
bool Render(rtc::ArrayView<const int16_t> data) override {
return true;
}
private:
int sampling_frequency_in_hz_;
};
} // namespace
namespace test {
// Assuming 10ms audio packets.
FakeAudioDevice::PulsedNoiseCapturer::PulsedNoiseCapturer(
int16_t max_amplitude,
int sampling_frequency_in_hz)
: sampling_frequency_in_hz_(sampling_frequency_in_hz),
fill_with_zero_(false),
random_generator_(1),
max_amplitude_(max_amplitude) {
RTC_DCHECK_GT(max_amplitude, 0);
}
bool FakeAudioDevice::PulsedNoiseCapturer::Capture(
rtc::BufferT<int16_t>* buffer) {
fill_with_zero_ = !fill_with_zero_;
int16_t max_amplitude;
{
rtc::CritScope cs(&lock_);
max_amplitude = max_amplitude_;
}
buffer->SetData(FakeAudioDevice::SamplesPerFrame(sampling_frequency_in_hz_),
[&](rtc::ArrayView<int16_t> data) {
if (fill_with_zero_) {
std::fill(data.begin(), data.end(), 0);
} else {
std::generate(data.begin(), data.end(), [&]() {
return random_generator_.Rand(-max_amplitude,
max_amplitude);
});
}
return data.size();
});
return true;
}
void FakeAudioDevice::PulsedNoiseCapturer::SetMaxAmplitude(int16_t amplitude) {
rtc::CritScope cs(&lock_);
max_amplitude_ = amplitude;
}
size_t FakeAudioDevice::SamplesPerFrame(int sampling_frequency_in_hz) {
return rtc::CheckedDivExact(sampling_frequency_in_hz, kFramesPerSecond);
}
std::unique_ptr<FakeAudioDevice::PulsedNoiseCapturer>
FakeAudioDevice::CreatePulsedNoiseCapturer(int16_t max_amplitude,
int sampling_frequency_in_hz) {
return std::unique_ptr<FakeAudioDevice::PulsedNoiseCapturer>(
new PulsedNoiseCapturer(max_amplitude, sampling_frequency_in_hz));
}
std::unique_ptr<FakeAudioDevice::Capturer> FakeAudioDevice::CreateWavFileReader(
std::string filename, int sampling_frequency_in_hz) {
return std::unique_ptr<FakeAudioDevice::Capturer>(
new WavFileReader(filename, sampling_frequency_in_hz));
}
std::unique_ptr<FakeAudioDevice::Capturer> FakeAudioDevice::CreateWavFileReader(
std::string filename) {
int sampling_frequency_in_hz = WavReader(filename).sample_rate();
return std::unique_ptr<FakeAudioDevice::Capturer>(
new WavFileReader(filename, sampling_frequency_in_hz));
}
std::unique_ptr<FakeAudioDevice::Renderer> FakeAudioDevice::CreateWavFileWriter(
std::string filename, int sampling_frequency_in_hz) {
return std::unique_ptr<FakeAudioDevice::Renderer>(
new WavFileWriter(filename, sampling_frequency_in_hz));
}
std::unique_ptr<FakeAudioDevice::Renderer>
FakeAudioDevice::CreateBoundedWavFileWriter(
std::string filename, int sampling_frequency_in_hz) {
return std::unique_ptr<FakeAudioDevice::Renderer>(
new BoundedWavFileWriter(filename, sampling_frequency_in_hz));
}
std::unique_ptr<FakeAudioDevice::Renderer>
FakeAudioDevice::CreateDiscardRenderer(int sampling_frequency_in_hz) {
return std::unique_ptr<FakeAudioDevice::Renderer>(
new DiscardRenderer(sampling_frequency_in_hz));
}
FakeAudioDevice::FakeAudioDevice(std::unique_ptr<Capturer> capturer,
std::unique_ptr<Renderer> renderer,
float speed)
: capturer_(std::move(capturer)),
renderer_(std::move(renderer)),
speed_(speed),
audio_callback_(nullptr),
rendering_(false),
capturing_(false),
done_rendering_(true, true),
done_capturing_(true, true),
tick_(EventTimerWrapper::Create()),
thread_(FakeAudioDevice::Run, this, "FakeAudioDevice") {
auto good_sample_rate = [](int sr) {
return sr == 8000 || sr == 16000 || sr == 32000
|| sr == 44100 || sr == 48000;
};
if (renderer_) {
const int sample_rate = renderer_->SamplingFrequency();
playout_buffer_.resize(SamplesPerFrame(sample_rate), 0);
RTC_CHECK(good_sample_rate(sample_rate));
}
if (capturer_) {
RTC_CHECK(good_sample_rate(capturer_->SamplingFrequency()));
}
}
FakeAudioDevice::~FakeAudioDevice() {
StopPlayout();
StopRecording();
thread_.Stop();
}
int32_t FakeAudioDevice::StartPlayout() {
rtc::CritScope cs(&lock_);
RTC_CHECK(renderer_);
rendering_ = true;
done_rendering_.Reset();
return 0;
}
int32_t FakeAudioDevice::StopPlayout() {
rtc::CritScope cs(&lock_);
rendering_ = false;
done_rendering_.Set();
return 0;
}
int32_t FakeAudioDevice::StartRecording() {
rtc::CritScope cs(&lock_);
RTC_CHECK(capturer_);
capturing_ = true;
done_capturing_.Reset();
return 0;
}
int32_t FakeAudioDevice::StopRecording() {
rtc::CritScope cs(&lock_);
capturing_ = false;
done_capturing_.Set();
return 0;
}
int32_t FakeAudioDevice::Init() {
RTC_CHECK(tick_->StartTimer(true, kFrameLengthMs / speed_));
thread_.Start();
thread_.SetPriority(rtc::kHighPriority);
return 0;
}
int32_t FakeAudioDevice::RegisterAudioCallback(AudioTransport* callback) {
rtc::CritScope cs(&lock_);
RTC_DCHECK(callback || audio_callback_);
audio_callback_ = callback;
return 0;
}
bool FakeAudioDevice::Playing() const {
rtc::CritScope cs(&lock_);
return rendering_;
}
bool FakeAudioDevice::Recording() const {
rtc::CritScope cs(&lock_);
return capturing_;
}
bool FakeAudioDevice::WaitForPlayoutEnd(int timeout_ms) {
return done_rendering_.Wait(timeout_ms);
}
bool FakeAudioDevice::WaitForRecordingEnd(int timeout_ms) {
return done_capturing_.Wait(timeout_ms);
}
bool FakeAudioDevice::Run(void* obj) {
static_cast<FakeAudioDevice*>(obj)->ProcessAudio();
return true;
}
void FakeAudioDevice::ProcessAudio() {
{
rtc::CritScope cs(&lock_);
if (capturing_) {
// Capture 10ms of audio. 2 bytes per sample.
const bool keep_capturing = capturer_->Capture(&recording_buffer_);
uint32_t new_mic_level;
if (recording_buffer_.size() > 0) {
audio_callback_->RecordedDataIsAvailable(
recording_buffer_.data(), recording_buffer_.size(), 2, 1,
capturer_->SamplingFrequency(), 0, 0, 0, false, new_mic_level);
}
if (!keep_capturing) {
capturing_ = false;
done_capturing_.Set();
}
}
if (rendering_) {
size_t samples_out;
int64_t elapsed_time_ms;
int64_t ntp_time_ms;
const int sampling_frequency = renderer_->SamplingFrequency();
audio_callback_->NeedMorePlayData(
SamplesPerFrame(sampling_frequency), 2, 1, sampling_frequency,
playout_buffer_.data(), samples_out, &elapsed_time_ms, &ntp_time_ms);
const bool keep_rendering = renderer_->Render(
rtc::ArrayView<const int16_t>(playout_buffer_.data(), samples_out));
if (!keep_rendering) {
rendering_ = false;
done_rendering_.Set();
}
}
}
tick_->Wait(WEBRTC_EVENT_INFINITE);
}
} // namespace test
} // namespace webrtc

View File

@ -10,14 +10,156 @@
#ifndef TEST_FAKE_AUDIO_DEVICE_H_
#define TEST_FAKE_AUDIO_DEVICE_H_
#include "modules/audio_device/include/test_audio_device.h"
#include <memory>
#include <string>
#include <vector>
#include "api/array_view.h"
#include "modules/audio_device/include/fake_audio_device.h"
#include "rtc_base/buffer.h"
#include "rtc_base/criticalsection.h"
#include "rtc_base/event.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/random.h"
#include "typedefs.h" // NOLINT(build/include)
namespace webrtc {
class EventTimerWrapper;
namespace test {
using FakeAudioDevice = webrtc::TestAudioDeviceModule;
// FakeAudioDevice implements an AudioDevice module that can act both as a
// capturer and a renderer. It will use 10ms audio frames.
class FakeAudioDevice : public FakeAudioDeviceModule {
public:
// Returns the number of samples that Capturers and Renderers with this
// sampling frequency will work with every time Capture or Render is called.
static size_t SamplesPerFrame(int sampling_frequency_in_hz);
class Capturer {
public:
virtual ~Capturer() {}
// Returns the sampling frequency in Hz of the audio data that this
// capturer produces.
virtual int SamplingFrequency() const = 0;
// Replaces the contents of |buffer| with 10ms of captured audio data
// (see FakeAudioDevice::SamplesPerFrame). Returns true if the capturer can
// keep producing data, or false when the capture finishes.
virtual bool Capture(rtc::BufferT<int16_t>* buffer) = 0;
};
class Renderer {
public:
virtual ~Renderer() {}
// Returns the sampling frequency in Hz of the audio data that this
// renderer receives.
virtual int SamplingFrequency() const = 0;
// Renders the passed audio data and returns true if the renderer wants
// to keep receiving data, or false otherwise.
virtual bool Render(rtc::ArrayView<const int16_t> data) = 0;
};
// A fake capturer that generates pulses with random samples between
// -max_amplitude and +max_amplitude.
class PulsedNoiseCapturer final : public Capturer {
public:
PulsedNoiseCapturer(int16_t max_amplitude, int sampling_frequency_in_hz);
int SamplingFrequency() const override { return sampling_frequency_in_hz_; }
bool Capture(rtc::BufferT<int16_t>* buffer) override;
void SetMaxAmplitude(int16_t amplitude);
private:
int sampling_frequency_in_hz_;
bool fill_with_zero_;
Random random_generator_;
rtc::CriticalSection lock_;
int16_t max_amplitude_ RTC_GUARDED_BY(lock_);
};
// Creates a new FakeAudioDevice. When capturing or playing, 10 ms audio
// frames will be processed every 10ms / |speed|.
// |capturer| is an object that produces audio data. Can be nullptr if this
// device is never used for recording.
// |renderer| is an object that receives audio data that would have been
// played out. Can be nullptr if this device is never used for playing.
// Use one of the Create... functions to get these instances.
FakeAudioDevice(std::unique_ptr<Capturer> capturer,
std::unique_ptr<Renderer> renderer,
float speed = 1);
~FakeAudioDevice() override;
// Returns a Capturer instance that generates a signal where every second
// frame is zero and every second frame is evenly distributed random noise
// with max amplitude |max_amplitude|.
static std::unique_ptr<PulsedNoiseCapturer> CreatePulsedNoiseCapturer(
int16_t max_amplitude,
int sampling_frequency_in_hz);
// Returns a Capturer instance that gets its data from a file.
static std::unique_ptr<Capturer> CreateWavFileReader(
std::string filename, int sampling_frequency_in_hz);
// Returns a Capturer instance that gets its data from a file.
// Automatically detects sample rate.
static std::unique_ptr<Capturer> CreateWavFileReader(std::string filename);
// Returns a Renderer instance that writes its data to a file.
static std::unique_ptr<Renderer> CreateWavFileWriter(
std::string filename, int sampling_frequency_in_hz);
// Returns a Renderer instance that writes its data to a WAV file, cutting
// off silence at the beginning (not necessarily perfect silence, see
// kAmplitudeThreshold) and at the end (only actual 0 samples in this case).
static std::unique_ptr<Renderer> CreateBoundedWavFileWriter(
std::string filename, int sampling_frequency_in_hz);
// Returns a Renderer instance that does nothing with the audio data.
static std::unique_ptr<Renderer> CreateDiscardRenderer(
int sampling_frequency_in_hz);
int32_t Init() override;
int32_t RegisterAudioCallback(AudioTransport* callback) override;
int32_t StartPlayout() override;
int32_t StopPlayout() override;
int32_t StartRecording() override;
int32_t StopRecording() override;
bool Playing() const override;
bool Recording() const override;
// Blocks until the Renderer refuses to receive data.
// Returns false if |timeout_ms| passes before that happens.
bool WaitForPlayoutEnd(int timeout_ms = rtc::Event::kForever);
// Blocks until the Recorder stops producing data.
// Returns false if |timeout_ms| passes before that happens.
bool WaitForRecordingEnd(int timeout_ms = rtc::Event::kForever);
private:
static bool Run(void* obj);
void ProcessAudio();
const std::unique_ptr<Capturer> capturer_ RTC_GUARDED_BY(lock_);
const std::unique_ptr<Renderer> renderer_ RTC_GUARDED_BY(lock_);
const float speed_;
rtc::CriticalSection lock_;
AudioTransport* audio_callback_ RTC_GUARDED_BY(lock_);
bool rendering_ RTC_GUARDED_BY(lock_);
bool capturing_ RTC_GUARDED_BY(lock_);
rtc::Event done_rendering_;
rtc::Event done_capturing_;
std::vector<int16_t> playout_buffer_ RTC_GUARDED_BY(lock_);
rtc::BufferT<int16_t> recording_buffer_ RTC_GUARDED_BY(lock_);
std::unique_ptr<EventTimerWrapper> tick_;
rtc::PlatformThread thread_;
};
} // namespace test
} // namespace webrtc

View File

@ -13,11 +13,12 @@
#include "common_audio/wav_file.h"
#include "common_audio/wav_header.h"
#include "modules/audio_device/include/test_audio_device.h"
#include "test/fake_audio_device.h"
#include "test/gtest.h"
#include "test/testsupport/fileutils.h"
namespace webrtc {
namespace test {
namespace {
void RunTest(const std::vector<int16_t>& input_samples,
@ -27,17 +28,15 @@ void RunTest(const std::vector<int16_t>& input_samples,
::testing::UnitTest::GetInstance()->current_test_info();
const std::string output_filename = test::OutputPath() +
"BoundedWavFileWriterTest_" +
test_info->name() + ".wav";
"BoundedWavFileWriterTest_" + test_info->name() + ".wav";
static const size_t kSamplesPerFrame = 8;
static const int kSampleRate = kSamplesPerFrame * 100;
EXPECT_EQ(TestAudioDeviceModule::SamplesPerFrame(kSampleRate),
kSamplesPerFrame);
EXPECT_EQ(FakeAudioDevice::SamplesPerFrame(kSampleRate), kSamplesPerFrame);
{
std::unique_ptr<TestAudioDeviceModule::Renderer> writer =
TestAudioDeviceModule::CreateBoundedWavFileWriter(output_filename, 800);
std::unique_ptr<FakeAudioDevice::Renderer> writer =
FakeAudioDevice::CreateBoundedWavFileWriter(output_filename, 800);
for (size_t i = 0; i < input_samples.size(); i += kSamplesPerFrame) {
EXPECT_TRUE(writer->Render(rtc::ArrayView<const int16_t>(
@ -62,15 +61,18 @@ void RunTest(const std::vector<int16_t>& input_samples,
TEST(BoundedWavFileWriterTest, NoSilence) {
static const std::vector<int16_t> kInputSamples = {
75, 1234, 243, -1231, -22222, 0, 3, 88,
1222, -1213, -13222, -7, -3525, 5787, -25247, 8};
75, 1234, 243, -1231, -22222, 0, 3, 88,
1222, -1213, -13222, -7, -3525, 5787, -25247, 8
};
static const std::vector<int16_t> kExpectedSamples = kInputSamples;
RunTest(kInputSamples, kExpectedSamples, 8);
}
TEST(BoundedWavFileWriterTest, SomeStartSilence) {
static const std::vector<int16_t> kInputSamples = {
0, 0, 0, 0, 3, 0, 0, 0, 0, 3, -13222, -7, -3525, 5787, -25247, 8};
0, 0, 0, 0, 3, 0, 0, 0,
0, 3, -13222, -7, -3525, 5787, -25247, 8
};
static const std::vector<int16_t> kExpectedSamples(kInputSamples.begin() + 10,
kInputSamples.end());
RunTest(kInputSamples, kExpectedSamples, 8);
@ -78,7 +80,9 @@ TEST(BoundedWavFileWriterTest, SomeStartSilence) {
TEST(BoundedWavFileWriterTest, NegativeStartSilence) {
static const std::vector<int16_t> kInputSamples = {
0, -4, -6, 0, 3, 0, 0, 0, 0, 3, -13222, -7, -3525, 5787, -25247, 8};
0, -4, -6, 0, 3, 0, 0, 0,
0, 3, -13222, -7, -3525, 5787, -25247, 8
};
static const std::vector<int16_t> kExpectedSamples(kInputSamples.begin() + 2,
kInputSamples.end());
RunTest(kInputSamples, kExpectedSamples, 8);
@ -86,7 +90,9 @@ TEST(BoundedWavFileWriterTest, NegativeStartSilence) {
TEST(BoundedWavFileWriterTest, SomeEndSilence) {
static const std::vector<int16_t> kInputSamples = {
75, 1234, 243, -1231, -22222, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
75, 1234, 243, -1231, -22222, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
static const std::vector<int16_t> kExpectedSamples(kInputSamples.begin(),
kInputSamples.end() - 9);
RunTest(kInputSamples, kExpectedSamples, 8);
@ -94,16 +100,18 @@ TEST(BoundedWavFileWriterTest, SomeEndSilence) {
TEST(BoundedWavFileWriterTest, DoubleEndSilence) {
static const std::vector<int16_t> kInputSamples = {
75, 1234, 243, -1231, -22222, 0, 0, 0,
0, -1213, -13222, -7, -3525, 5787, 0, 0};
75, 1234, 243, -1231, -22222, 0, 0, 0,
0, -1213, -13222, -7, -3525, 5787, 0, 0
};
static const std::vector<int16_t> kExpectedSamples(kInputSamples.begin(),
kInputSamples.end() - 2);
RunTest(kInputSamples, kExpectedSamples, 8);
}
TEST(BoundedWavFileWriterTest, DoubleSilence) {
static const std::vector<int16_t> kInputSamples = {0, -1213, -13222, -7,
-3525, 5787, 0, 0};
static const std::vector<int16_t> kInputSamples = {
0, -1213, -13222, -7, -3525, 5787, 0, 0
};
static const std::vector<int16_t> kExpectedSamples(kInputSamples.begin() + 1,
kInputSamples.end() - 2);
RunTest(kInputSamples, kExpectedSamples, 8);
@ -111,7 +119,9 @@ TEST(BoundedWavFileWriterTest, DoubleSilence) {
TEST(BoundedWavFileWriterTest, EndSilenceCutoff) {
static const std::vector<int16_t> kInputSamples = {
75, 1234, 243, -1231, -22222, 0, 1, 0, 0, 0, 0};
75, 1234, 243, -1231, -22222, 0, 1, 0,
0, 0, 0
};
static const std::vector<int16_t> kExpectedSamples(kInputSamples.begin(),
kInputSamples.end() - 4);
RunTest(kInputSamples, kExpectedSamples, 8);
@ -119,8 +129,8 @@ TEST(BoundedWavFileWriterTest, EndSilenceCutoff) {
TEST(PulsedNoiseCapturerTest, SetMaxAmplitude) {
const int16_t kAmplitude = 50;
std::unique_ptr<TestAudioDeviceModule::PulsedNoiseCapturer> capturer =
TestAudioDeviceModule::CreatePulsedNoiseCapturer(
std::unique_ptr<FakeAudioDevice::PulsedNoiseCapturer> capturer =
FakeAudioDevice::CreatePulsedNoiseCapturer(
kAmplitude, /*sampling_frequency_in_hz=*/8000);
rtc::BufferT<int16_t> recording_buffer;
@ -143,4 +153,5 @@ TEST(PulsedNoiseCapturerTest, SetMaxAmplitude) {
EXPECT_GT(max_sample, kAmplitude);
}
} // namespace test
} // namespace webrtc

View File

@ -2092,10 +2092,11 @@ void VideoQualityTest::RunWithRenderers(const Params& params) {
Call::Config call_config(event_log_.get());
call_config.bitrate_config = params_.call.call_bitrate_config;
rtc::scoped_refptr<TestAudioDeviceModule> fake_audio_device =
TestAudioDeviceModule::CreateTestAudioDeviceModule(
TestAudioDeviceModule::CreatePulsedNoiseCapturer(32000, 48000),
TestAudioDeviceModule::CreateDiscardRenderer(48000), 1.f);
rtc::scoped_refptr<test::FakeAudioDevice> fake_audio_device =
new rtc::RefCountedObject<test::FakeAudioDevice>(
test::FakeAudioDevice::CreatePulsedNoiseCapturer(32000, 48000),
test::FakeAudioDevice::CreateDiscardRenderer(48000),
1.f);
if (params_.audio.enabled) {
AudioState::Config audio_state_config;