| Index: webrtc/test/fake_audio_device.h
|
| diff --git a/webrtc/test/fake_audio_device.h b/webrtc/test/fake_audio_device.h
|
| index 4daeab43650066c258d0bb172a12d14f36fe64c3..e44ec540f0f36221624bf457ef11324d60d52f82 100644
|
| --- a/webrtc/test/fake_audio_device.h
|
| +++ b/webrtc/test/fake_audio_device.h
|
| @@ -14,7 +14,10 @@
|
| #include <string>
|
| #include <vector>
|
|
|
| +#include "webrtc/base/array_view.h"
|
| +#include "webrtc/base/buffer.h"
|
| #include "webrtc/base/criticalsection.h"
|
| +#include "webrtc/base/event.h"
|
| #include "webrtc/base/platform_thread.h"
|
| #include "webrtc/modules/audio_device/include/fake_audio_device.h"
|
| #include "webrtc/typedefs.h"
|
| @@ -29,18 +32,67 @@ namespace test {
|
| // 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;
|
| + };
|
| +
|
| // Creates a new FakeAudioDevice. When capturing or playing, 10 ms audio
|
| - // frames will be processed every 100ms / |speed|.
|
| - // |sampling_frequency_in_hz| can be 8, 16, 32, 44.1 or 48kHz.
|
| - // When recording is started, it will generates a signal where every second
|
| + // 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|.
|
| - FakeAudioDevice(float speed,
|
| - int sampling_frequency_in_hz,
|
| - int16_t max_amplitude);
|
| - ~FakeAudioDevice() override;
|
| + static std::unique_ptr<Capturer> 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 does nothing with the audio data.
|
| + static std::unique_ptr<Renderer> CreateDiscardRenderer(
|
| + int sampling_frequency_in_hz);
|
|
|
| - private:
|
| int32_t Init() override;
|
| int32_t RegisterAudioCallback(AudioTransport* callback) override;
|
|
|
| @@ -52,22 +104,30 @@ class FakeAudioDevice : public FakeAudioDeviceModule {
|
| 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 int sampling_frequency_in_hz_;
|
| - const size_t num_samples_per_frame_;
|
| + const std::unique_ptr<Capturer> capturer_ GUARDED_BY(lock_);
|
| + const std::unique_ptr<Renderer> renderer_ GUARDED_BY(lock_);
|
| const float speed_;
|
|
|
| rtc::CriticalSection lock_;
|
| AudioTransport* audio_callback_ GUARDED_BY(lock_);
|
| bool rendering_ GUARDED_BY(lock_);
|
| bool capturing_ GUARDED_BY(lock_);
|
| -
|
| - class PulsedNoiseCapturer;
|
| - const std::unique_ptr<PulsedNoiseCapturer> capturer_ GUARDED_BY(lock_);
|
| + rtc::Event done_rendering_;
|
| + rtc::Event done_capturing_;
|
|
|
| std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_);
|
| + rtc::BufferT<int16_t> recording_buffer_ GUARDED_BY(lock_);
|
|
|
| std::unique_ptr<EventTimerWrapper> tick_;
|
| rtc::PlatformThread thread_;
|
|
|