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

Unified Diff: webrtc/test/file_audio_device.h

Issue 2717623003: Add the ability to read/write to WAV files in FakeAudioDevice (Closed)
Patch Set: Created 3 years, 10 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/file_audio_device.h
diff --git a/webrtc/test/file_audio_device.h b/webrtc/test/file_audio_device.h
new file mode 100644
index 0000000000000000000000000000000000000000..182820e5c628211b5f8e32e6f6a79a26c043a511
--- /dev/null
+++ b/webrtc/test/file_audio_device.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2017 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 WEBRTC_TEST_FILE_AUDIO_DEVICE_H_
+#define WEBRTC_TEST_FILE_AUDIO_DEVICE_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "webrtc/base/criticalsection.h"
+#include "webrtc/base/event.h"
+#include "webrtc/base/platform_thread.h"
+#include "webrtc/common_audio/wav_file.h"
+#include "webrtc/modules/audio_device/include/fake_audio_device.h"
+#include "webrtc/typedefs.h"
+
+namespace webrtc {
+
+class EventTimerWrapper;
+
+namespace test {
+
+// FileAudioDevice implements an AudioDevice module that can act as a capturer
+// (read audio from a WAV file and send it) or a renderer (receive audio and
+// write it to a WAV file). It will use 10ms audio frames.
+class FileAudioDevice : public FakeAudioDeviceModule {
kwiberg-webrtc 2017/02/28 13:43:47 final? Or do you anticipate subclasses?
oprypin_webrtc 2017/03/06 16:45:01 It's hard to predict what people might want to do.
+ public:
+ // Creates a new FileAudioDevice. When capturing or playing, 10 ms audio
+ // frames will be processed every 100ms / |speed|.
kwiberg-webrtc 2017/02/28 13:43:47 Umm... so a speed of 1 gives one frame every 100ms
oprypin_webrtc 2017/03/06 16:45:01 Again this is just something I copied from FakeAud
+ // |sampling_frequency_in_hz| can be 8, 16, 32, 44.1 or 48kHz.
kwiberg-webrtc 2017/02/28 13:43:47 For consistency with other audio code (and for bre
oprypin_webrtc 2017/03/06 16:45:01 Done.
+ FileAudioDevice(const std::string& filename,
+ float speed, int sampling_frequency_in_hz);
+ ~FileAudioDevice() override;
+
+ // Block until the input audio file ends.
kwiberg-webrtc 2017/02/28 13:43:47 Document the argument? And that it only works if y
oprypin_webrtc 2017/03/06 16:45:01 Named it `timeout_ms`. And this should stay in onl
+ bool WaitForFileEnd(int milliseconds = rtc::Event::kForever);
+
+ private:
+ int32_t Init() override;
+ int32_t RegisterAudioCallback(AudioTransport* callback) override;
+
+ // Start receiving audio data and writing it to the file.
+ int32_t StartPlayout() override;
+ int32_t StopPlayout() override;
+ // Start reading audio data from the file and sending it.
+ int32_t StartRecording() override;
+ int32_t StopRecording() override;
+
+ bool Playing() const override;
+ bool Recording() const override;
+
+ static bool Run(void* obj);
+ void ProcessAudio();
+
+ const std::string filename_;
+ const int sampling_frequency_in_hz_;
+ const size_t num_samples_per_frame_;
+ const float speed_;
+
+ rtc::CriticalSection lock_;
+ AudioTransport* audio_callback_ GUARDED_BY(lock_);
+ std::unique_ptr<WavReader> wav_reader_ GUARDED_BY(lock_);
+ std::unique_ptr<WavWriter> wav_writer_ GUARDED_BY(lock_);
+
+ std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_);
kwiberg-webrtc 2017/02/28 13:43:47 Good use of const and GUARDED_BY!
oprypin_webrtc 2017/03/06 16:45:01 Not sure what you mean.
+
+ std::unique_ptr<EventTimerWrapper> tick_;
+ rtc::PlatformThread thread_;
+ rtc::Event done_reading_;
kwiberg-webrtc 2017/02/28 13:43:47 Document what this one does?
oprypin_webrtc 2017/03/06 16:45:01 Done.
+};
+} // namespace test
+} // namespace webrtc
+
+#endif // WEBRTC_TEST_FILE_AUDIO_DEVICE_H_

Powered by Google App Engine
This is Rietveld 408576698