Chromium Code Reviews| 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..67e76ef2b0b4ee5620a84fb93b88a149930a0cf6 |
| --- /dev/null |
| +++ b/webrtc/test/file_audio_device.h |
| @@ -0,0 +1,113 @@ |
| +/* |
| + * 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 { |
| + |
| +// FileReaderAudioDevice implements an AudioDevice module that acts as a |
| +// capturer (read audio from a WAV file and send it). It uses 10ms audio frames. |
| +class FileReaderAudioDevice : public FakeAudioDeviceModule { |
| + public: |
| + // Creates a new FileReaderAudioDevice. When capturing, 10 ms audio frames |
|
kwiberg-webrtc
2017/03/07 10:11:57
"When capturing, one 10 ms audio frame will [...]"
|
| + // will be processed every 100ms / |speed|. |
|
kwiberg-webrtc
2017/03/07 10:11:57
I'll just note for the record that I find the unit
oprypin_webrtc
2017/03/09 08:23:24
Acknowledged.
|
| + // |sample_rate_hz| can be 8, 16, 32, 44.1 or 48kHz. |
| + FileReaderAudioDevice(std::string filename, float speed, |
| + int sample_rate_hz); |
| + ~FileReaderAudioDevice() override; |
| + |
| + // Block until the input audio file ends. |
| + bool WaitForFileEnd(int timeout_ms = rtc::Event::kForever); |
| + |
| + private: |
| + int32_t RegisterAudioCallback(AudioTransport* callback) override; |
| + |
| + // Start reading audio data from the file and sending it. |
| + int32_t StartRecording() override; |
| + int32_t StopRecording() override; |
| + |
| + bool Recording() const override; |
|
kwiberg-webrtc
2017/03/07 10:11:57
Are these four public in FakeAudioDeviceModule? If
oprypin_webrtc
2017/03/09 08:23:24
Done.
|
| + |
| + static bool Run(void* obj); |
| + void ProcessAudio(); |
| + |
| + const std::string filename_; |
| + const int sample_rate_hz_; |
| + const float speed_; |
| + |
| + rtc::CriticalSection lock_; |
| + AudioTransport* audio_callback_ GUARDED_BY(lock_); |
| + std::unique_ptr<WavReader> wav_reader_ GUARDED_BY(lock_); |
| + |
| + std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_); |
| + |
| + std::unique_ptr<EventTimerWrapper> tick_; |
|
kwiberg-webrtc
2017/03/07 10:11:57
Can this be a const std::unique_ptr<EventTimerWrap
|
| + rtc::PlatformThread thread_; |
| + // This event is set when the audio input file ends or has not been opened |
| + // yet. |
| + rtc::Event done_reading_; |
| +}; |
| + |
| +// FileWriterAudioDevice implements an AudioDevice module that acts as a |
| +// renderer (receive audio and write it to a WAV file). |
| +// It uses 10ms audio frames. |
| +class FileWriterAudioDevice : public FakeAudioDeviceModule { |
| + public: |
| + // Creates a new FileWriterAudioDevice. When playing, 10 ms audio frames will |
| + // be processed every 100ms / |speed|. |
| + // |sample_rate_hz| can be 8, 16, 32, 44.1 or 48kHz. |
| + FileWriterAudioDevice(std::string filename, float speed, |
| + int sample_rate_hz); |
| + ~FileWriterAudioDevice() override; |
| + |
| + private: |
| + int32_t RegisterAudioCallback(AudioTransport* callback) override; |
| + |
| + // Start receiving audio data and writing it to the file. |
| + int32_t StartPlayout() override; |
| + int32_t StopPlayout() override; |
| + |
| + bool Playing() const override; |
| + |
| + static bool Run(void* obj); |
| + void ProcessAudio(); |
| + |
| + const std::string filename_; |
| + const int sample_rate_hz_; |
| + const float speed_; |
| + |
| + rtc::CriticalSection lock_; |
| + AudioTransport* audio_callback_ GUARDED_BY(lock_); |
| + std::unique_ptr<WavWriter> wav_writer_ GUARDED_BY(lock_); |
| + |
| + std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_); |
| + |
| + std::unique_ptr<EventTimerWrapper> tick_; |
| + rtc::PlatformThread thread_; |
| +}; |
| +} // namespace test |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_TEST_FILE_AUDIO_DEVICE_H_ |