Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 #ifndef WEBRTC_TEST_FILE_AUDIO_DEVICE_H_ | |
| 11 #define WEBRTC_TEST_FILE_AUDIO_DEVICE_H_ | |
| 12 | |
| 13 #include <memory> | |
| 14 #include <string> | |
| 15 #include <vector> | |
| 16 | |
| 17 #include "webrtc/base/criticalsection.h" | |
| 18 #include "webrtc/base/event.h" | |
| 19 #include "webrtc/base/platform_thread.h" | |
| 20 #include "webrtc/common_audio/wav_file.h" | |
| 21 #include "webrtc/modules/audio_device/include/fake_audio_device.h" | |
| 22 #include "webrtc/typedefs.h" | |
| 23 | |
| 24 namespace webrtc { | |
| 25 | |
| 26 class EventTimerWrapper; | |
| 27 | |
| 28 namespace test { | |
| 29 | |
| 30 // FileReaderAudioDevice implements an AudioDevice module that acts as a | |
| 31 // capturer (read audio from a WAV file and send it). It uses 10ms audio frames. | |
| 32 class FileReaderAudioDevice : public FakeAudioDeviceModule { | |
| 33 public: | |
| 34 // 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 [...]"
| |
| 35 // 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.
| |
| 36 // |sample_rate_hz| can be 8, 16, 32, 44.1 or 48kHz. | |
| 37 FileReaderAudioDevice(std::string filename, float speed, | |
| 38 int sample_rate_hz); | |
| 39 ~FileReaderAudioDevice() override; | |
| 40 | |
| 41 // Block until the input audio file ends. | |
| 42 bool WaitForFileEnd(int timeout_ms = rtc::Event::kForever); | |
| 43 | |
| 44 private: | |
| 45 int32_t RegisterAudioCallback(AudioTransport* callback) override; | |
| 46 | |
| 47 // Start reading audio data from the file and sending it. | |
| 48 int32_t StartRecording() override; | |
| 49 int32_t StopRecording() override; | |
| 50 | |
| 51 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.
| |
| 52 | |
| 53 static bool Run(void* obj); | |
| 54 void ProcessAudio(); | |
| 55 | |
| 56 const std::string filename_; | |
| 57 const int sample_rate_hz_; | |
| 58 const float speed_; | |
| 59 | |
| 60 rtc::CriticalSection lock_; | |
| 61 AudioTransport* audio_callback_ GUARDED_BY(lock_); | |
| 62 std::unique_ptr<WavReader> wav_reader_ GUARDED_BY(lock_); | |
| 63 | |
| 64 std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_); | |
| 65 | |
| 66 std::unique_ptr<EventTimerWrapper> tick_; | |
|
kwiberg-webrtc
2017/03/07 10:11:57
Can this be a const std::unique_ptr<EventTimerWrap
| |
| 67 rtc::PlatformThread thread_; | |
| 68 // This event is set when the audio input file ends or has not been opened | |
| 69 // yet. | |
| 70 rtc::Event done_reading_; | |
| 71 }; | |
| 72 | |
| 73 // FileWriterAudioDevice implements an AudioDevice module that acts as a | |
| 74 // renderer (receive audio and write it to a WAV file). | |
| 75 // It uses 10ms audio frames. | |
| 76 class FileWriterAudioDevice : public FakeAudioDeviceModule { | |
| 77 public: | |
| 78 // Creates a new FileWriterAudioDevice. When playing, 10 ms audio frames will | |
| 79 // be processed every 100ms / |speed|. | |
| 80 // |sample_rate_hz| can be 8, 16, 32, 44.1 or 48kHz. | |
| 81 FileWriterAudioDevice(std::string filename, float speed, | |
| 82 int sample_rate_hz); | |
| 83 ~FileWriterAudioDevice() override; | |
| 84 | |
| 85 private: | |
| 86 int32_t RegisterAudioCallback(AudioTransport* callback) override; | |
| 87 | |
| 88 // Start receiving audio data and writing it to the file. | |
| 89 int32_t StartPlayout() override; | |
| 90 int32_t StopPlayout() override; | |
| 91 | |
| 92 bool Playing() const override; | |
| 93 | |
| 94 static bool Run(void* obj); | |
| 95 void ProcessAudio(); | |
| 96 | |
| 97 const std::string filename_; | |
| 98 const int sample_rate_hz_; | |
| 99 const float speed_; | |
| 100 | |
| 101 rtc::CriticalSection lock_; | |
| 102 AudioTransport* audio_callback_ GUARDED_BY(lock_); | |
| 103 std::unique_ptr<WavWriter> wav_writer_ GUARDED_BY(lock_); | |
| 104 | |
| 105 std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_); | |
| 106 | |
| 107 std::unique_ptr<EventTimerWrapper> tick_; | |
| 108 rtc::PlatformThread thread_; | |
| 109 }; | |
| 110 } // namespace test | |
| 111 } // namespace webrtc | |
| 112 | |
| 113 #endif // WEBRTC_TEST_FILE_AUDIO_DEVICE_H_ | |
| OLD | NEW |