Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: webrtc/test/fake_audio_device.h

Issue 2717623003: Add the ability to read/write to WAV files in FakeAudioDevice (Closed)
Patch Set: Remove obsolete files from build Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..def670f06bc0b5b192da33f7b244f1c7e8e7d2bd 100644
--- a/webrtc/test/fake_audio_device.h
+++ b/webrtc/test/fake_audio_device.h
@@ -14,7 +14,9 @@
#include <string>
#include <vector>
+#include "webrtc/base/array_view.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"
@@ -28,19 +30,82 @@ namespace test {
// 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 {
+ private:
+ class Streamer {
+ public:
+ explicit Streamer(int sampling_frequency_in_hz);
+ int SamplingFrequency() const {
+ return sampling_frequency_in_hz_;
+ }
+ size_t SamplesPerFrame() const {
+ return num_samples_per_frame_;
+ }
+
+ private:
+ const int sampling_frequency_in_hz_;
+ const size_t num_samples_per_frame_;
+ };
+
+ class PulsedNoiseCapturer;
+ class WavFileReader;
+
+ class Discarder;
+ class WavFileWriter;
kwiberg-webrtc 2017/03/09 10:04:11 Why do you need to mention these four in the .h fi
oprypin_webrtc 2017/03/10 10:44:27 Done. Together with the change to anonymous namesp
+
public:
+ class Capturer : public Streamer {
+ public:
+ using Streamer::Streamer;
+ // Should capture and return some data (limited to SamplesPerFrame), or
+ // return an empty ArrayView when the capture finishes.
+ virtual rtc::ArrayView<const int16_t> Capture() = 0;
kwiberg-webrtc 2017/03/09 10:04:11 It's not usually a good idea to return an ArrayVie
oprypin_webrtc 2017/03/10 10:44:27 Done.
+ virtual ~Capturer() {}
kwiberg-webrtc 2017/03/09 10:04:11 Put the destructor before the regular methods (jus
oprypin_webrtc 2017/03/10 10:44:27 Done.
+ };
+
+ class Renderer : public Streamer {
+ public:
+ using Streamer::Streamer;
+ // Should render the passed audio data and return true if the renderer wants
+ // to keep receiving data, or false otherwise.
+ virtual bool Render(rtc::ArrayView<const int16_t> data) = 0;
+ virtual ~Renderer() {}
+ };
kwiberg-webrtc 2017/03/09 10:04:10 Unless you have a very good reason, please make Ca
oprypin_webrtc 2017/03/10 10:44:27 I just want to get rid of this num_samples_per_fra
kwiberg-webrtc 2017/03/13 10:18:21 I have two alternative suggestions. The first one
+
// 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
// frame is zero and every second frame is evenly distributed random noise
// with max amplitude |max_amplitude|.
+ FakeAudioDevice(std::unique_ptr<Capturer> capturer,
+ std::unique_ptr<Renderer> renderer,
+ float speed = 1);
kwiberg-webrtc 2017/03/09 10:04:10 The default speed is 0.1x realtime?
oprypin_webrtc 2017/03/10 10:44:27 I'm quite sure this is just realtime, because call
kwiberg-webrtc 2017/03/13 10:18:21 OK, then either the existing comment is wrong, or
FakeAudioDevice(float speed,
int sampling_frequency_in_hz,
int16_t max_amplitude);
~FakeAudioDevice() override;
- private:
+ // 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<Capturer> CreatePulsedNoiseCapturer(
+ int sampling_frequency_in_hz, int16_t max_amplitude);
kwiberg-webrtc 2017/03/09 10:04:11 The sample rate is the last argument in all the ot
oprypin_webrtc 2017/03/10 10:44:27 Done. Made it the last here as well.
+
+ // 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);
+
+ static std::unique_ptr<Renderer> CreateDiscarder(
+ int sampling_frequency_in_hz);
+
int32_t Init() override;
int32_t RegisterAudioCallback(AudioTransport* callback) override;
@@ -52,20 +117,25 @@ class FakeAudioDevice : public FakeAudioDeviceModule {
bool Playing() const override;
bool Recording() const override;
+ // Block until the Renderer refuses to receive data.
+ bool WaitForPlayoutEnd(int timeout_ms = rtc::Event::kForever);
+ // Block until the Recorder stops producing data.
+ bool WaitForRecordingEnd(int timeout_ms = rtc::Event::kForever);
kwiberg-webrtc 2017/03/09 10:04:10 What do these two return?
oprypin_webrtc 2017/03/10 10:44:27 Done. Added comment.
+
+ 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_);

Powered by Google App Engine
This is Rietveld 408576698