| 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 FakeAudioDevice(float speed, int sampling_frequency_in_hz); |
| 36 ~FakeAudioDevice() override; |
| 34 | 37 |
| 35 virtual ~FakeAudioDevice(); | 38 int32_t StartPlayout() override; |
| 39 int32_t StopPlayout() override; |
| 36 | 40 |
| 41 // Generates a signal where every second frame is zero and every second frame |
| 42 // is evenly distributed random noise with max amplitude |max_amplitude|. |
| 43 void StartRecordingPulsedNoise(int16_t max_amplitude); |
| 44 int32_t StopRecording() override; |
| 45 |
| 46 private: |
| 37 int32_t Init() override; | 47 int32_t Init() override; |
| 38 int32_t RegisterAudioCallback(AudioTransport* callback) override; | 48 int32_t RegisterAudioCallback(AudioTransport* callback) override; |
| 39 | 49 |
| 40 bool Playing() const override; | 50 bool Playing() const override; |
| 41 int32_t PlayoutDelay(uint16_t* delay_ms) const override; | 51 int32_t PlayoutDelay(uint16_t* delay_ms) const override; |
| 42 bool Recording() const override; | 52 bool Recording() const override; |
| 43 | 53 |
| 44 void Start(); | 54 static bool Run(void* obj); |
| 45 void Stop(); | 55 void ProcessAudio(); |
| 46 | 56 |
| 47 private: | 57 const int sampling_frequency_in_hz_; |
| 48 static bool Run(void* obj); | 58 const int num_samples_per_frame_; |
| 49 void CaptureAudio(); | |
| 50 | 59 |
| 51 static const uint32_t kFrequencyHz = 16000; | 60 rtc::CriticalSection lock_; |
| 52 static const size_t kBufferSizeBytes = 2 * kFrequencyHz; | 61 AudioTransport* audio_callback_ GUARDED_BY(lock_); |
| 62 bool rendering_ GUARDED_BY(lock_); |
| 53 | 63 |
| 54 AudioTransport* audio_callback_; | 64 class PulsedNoiseCapturer; |
| 55 bool capturing_; | 65 std::unique_ptr<PulsedNoiseCapturer> capturer_ GUARDED_BY(lock_); |
| 56 int8_t captured_audio_[kBufferSizeBytes]; | 66 |
| 57 int8_t playout_buffer_[kBufferSizeBytes]; | 67 std::vector<int16_t> playout_buffer_ GUARDED_BY(lock_); |
| 58 const float speed_; | 68 const float speed_; |
| 59 int64_t last_playout_ms_; | |
| 60 | 69 |
| 61 DriftingClock clock_; | |
| 62 std::unique_ptr<EventTimerWrapper> tick_; | 70 std::unique_ptr<EventTimerWrapper> tick_; |
| 63 rtc::CriticalSection lock_; | |
| 64 rtc::PlatformThread thread_; | 71 rtc::PlatformThread thread_; |
| 65 std::unique_ptr<ModuleFileUtility> file_utility_; | |
| 66 std::unique_ptr<FileWrapper> input_stream_; | |
| 67 }; | 72 }; |
| 68 } // namespace test | 73 } // namespace test |
| 69 } // namespace webrtc | 74 } // namespace webrtc |
| 70 | 75 |
| 71 #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ | 76 #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ |
| OLD | NEW |