Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 #ifndef WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ | 10 #ifndef WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ |
| 11 #define WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ | 11 #define WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | |
| 15 | 16 |
| 16 #include "webrtc/base/criticalsection.h" | 17 #include "webrtc/base/criticalsection.h" |
| 17 #include "webrtc/base/platform_thread.h" | 18 #include "webrtc/base/platform_thread.h" |
| 18 #include "webrtc/modules/audio_device/include/fake_audio_device.h" | 19 #include "webrtc/modules/audio_device/include/fake_audio_device.h" |
| 19 #include "webrtc/test/drifting_clock.h" | |
| 20 #include "webrtc/typedefs.h" | 20 #include "webrtc/typedefs.h" |
| 21 | 21 |
| 22 namespace webrtc { | 22 namespace webrtc { |
| 23 | 23 |
| 24 class Clock; | |
| 25 class EventTimerWrapper; | 24 class EventTimerWrapper; |
| 26 class FileWrapper; | |
| 27 class ModuleFileUtility; | |
| 28 | 25 |
| 29 namespace test { | 26 namespace test { |
| 30 | 27 |
| 28 // FakeAudioDevice implements an AudioDevice module that can act both as a | |
| 29 // capturer and a renderer. It will use 10ms audio frames. | |
| 31 class FakeAudioDevice : public FakeAudioDeviceModule { | 30 class FakeAudioDevice : public FakeAudioDeviceModule { |
| 32 public: | 31 public: |
| 33 FakeAudioDevice(Clock* clock, const std::string& filename, float speed); | 32 // Creates a new FakeAudioDevice. When capturing or playing, 10 ms audio |
| 33 // frames will be processed every 100ms / |speed|. | |
| 34 // |sampling_frequency_in_hz| can be 8, 16, 32, 44.1 or 48kHz. | |
| 35 // When recording is started, it will generates a signal where every second | |
| 36 // frame is zero and every second frame is evenly distributed random noise | |
| 37 // with max amplitude |max_amplitude|. | |
| 38 FakeAudioDevice(float speed, | |
| 39 int sampling_frequency_in_hz, | |
| 40 int16_t max_amplitude); | |
| 41 ~FakeAudioDevice() override; | |
| 34 | 42 |
| 35 virtual ~FakeAudioDevice(); | 43 private: |
| 36 | |
| 37 int32_t Init() override; | 44 int32_t Init() override; |
| 38 int32_t RegisterAudioCallback(AudioTransport* callback) override; | 45 int32_t RegisterAudioCallback(AudioTransport* callback) override; |
| 39 | 46 |
| 47 int32_t StartPlayout() override; | |
| 48 int32_t StopPlayout() override; | |
| 49 int32_t StartRecording() override; | |
| 50 int32_t StopRecording() override; | |
| 51 | |
| 40 bool Playing() const override; | 52 bool Playing() const override; |
| 41 int32_t PlayoutDelay(uint16_t* delay_ms) const override; | |
| 42 bool Recording() const override; | 53 bool Recording() const override; |
| 43 | 54 |
| 44 void Start(); | 55 static bool Run(void* obj); |
| 45 void Stop(); | 56 void ProcessAudio(); |
| 46 | 57 |
| 47 private: | 58 const int sampling_frequency_in_hz_; |
| 48 static bool Run(void* obj); | 59 const int num_samples_per_frame_; |
| 49 void CaptureAudio(); | |
| 50 | 60 |
| 51 static const uint32_t kFrequencyHz = 16000; | 61 rtc::CriticalSection lock_; |
| 52 static const size_t kBufferSizeBytes = 2 * kFrequencyHz; | 62 AudioTransport* audio_callback_ GUARDED_BY(lock_); |
| 63 bool rendering_ GUARDED_BY(lock_); | |
| 64 bool capturing_ GUARDED_BY(lock_); | |
| 53 | 65 |
| 54 AudioTransport* audio_callback_; | 66 class PulsedNoiseCapturer; |
| 55 bool capturing_; | 67 const std::unique_ptr<PulsedNoiseCapturer> capturer_ GUARDED_BY(lock_); |
| 56 int8_t captured_audio_[kBufferSizeBytes]; | 68 |
| 57 int8_t playout_buffer_[kBufferSizeBytes]; | 69 std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_); |
| 58 const float speed_; | 70 const float speed_; |
|
the sun
2017/01/31 16:27:08
nit: move up with sample rate and samples per fram
perkj_webrtc
2017/01/31 19:11:07
Done.
| |
| 59 int64_t last_playout_ms_; | |
| 60 | 71 |
| 61 DriftingClock clock_; | |
| 62 std::unique_ptr<EventTimerWrapper> tick_; | 72 std::unique_ptr<EventTimerWrapper> tick_; |
| 63 rtc::CriticalSection lock_; | |
| 64 rtc::PlatformThread thread_; | 73 rtc::PlatformThread thread_; |
| 65 std::unique_ptr<ModuleFileUtility> file_utility_; | |
| 66 std::unique_ptr<FileWrapper> input_stream_; | |
| 67 }; | 74 }; |
| 68 } // namespace test | 75 } // namespace test |
| 69 } // namespace webrtc | 76 } // namespace webrtc |
| 70 | 77 |
| 71 #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ | 78 #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ |
| OLD | NEW |