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 | 15 |
16 #include "webrtc/base/criticalsection.h" | 16 #include "webrtc/base/criticalsection.h" |
17 #include "webrtc/base/platform_thread.h" | 17 #include "webrtc/base/platform_thread.h" |
18 #include "webrtc/modules/audio_device/include/fake_audio_device.h" | 18 #include "webrtc/modules/audio_device/include/fake_audio_device.h" |
19 #include "webrtc/test/drifting_clock.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; | 24 class Clock; |
25 class EventTimerWrapper; | 25 class EventTimerWrapper; |
26 class FileWrapper; | |
27 class ModuleFileUtility; | |
28 | 26 |
29 namespace test { | 27 namespace test { |
30 | 28 |
31 class FakeAudioDevice : public FakeAudioDeviceModule { | 29 class FakeAudioDevice : public FakeAudioDeviceModule { |
32 public: | 30 public: |
33 FakeAudioDevice(Clock* clock, const std::string& filename, float speed); | 31 // Creates a new FakeAudioDevice. |speed| controls how much faster or slower |
peah-webrtc
2017/01/25 10:45:28
It seems to me very strange that the sample rate i
| |
32 // time elapse compared to the system clock. It can be used to simulate | |
33 // clock drift. 1.0 means that the system clock will be used. | |
34 FakeAudioDevice(Clock* clock, float speed); | |
35 ~FakeAudioDevice() override; | |
34 | 36 |
35 virtual ~FakeAudioDevice(); | 37 int32_t StartPlayout() override; |
38 int32_t StopPlayout() override; | |
36 | 39 |
40 // Generates a sine tone with |frequency_in_hz| and |peak_to_peak|. | |
41 void StartRecordingSine(int frequency_in_hz, uint16_t peak_to_peak); | |
42 int32_t StopRecording() override; | |
43 | |
44 private: | |
37 int32_t Init() override; | 45 int32_t Init() override; |
38 int32_t RegisterAudioCallback(AudioTransport* callback) override; | 46 int32_t RegisterAudioCallback(AudioTransport* callback) override; |
39 | 47 |
40 bool Playing() const override; | 48 bool Playing() const override; |
41 int32_t PlayoutDelay(uint16_t* delay_ms) const override; | 49 int32_t PlayoutDelay(uint16_t* delay_ms) const override; |
42 bool Recording() const override; | 50 bool Recording() const override; |
43 | 51 |
44 void Start(); | |
45 void Stop(); | |
46 | |
47 private: | |
48 static bool Run(void* obj); | 52 static bool Run(void* obj); |
49 void CaptureAudio(); | 53 void ProcessAudio(); |
50 | 54 |
51 static const uint32_t kFrequencyHz = 16000; | 55 static const uint32_t kFrequencyHz = 16000; |
52 static const size_t kBufferSizeBytes = 2 * kFrequencyHz; | 56 static const size_t kBufferSizeBytes = 2 * kFrequencyHz; |
53 | 57 |
54 AudioTransport* audio_callback_; | 58 rtc::CriticalSection lock_; |
55 bool capturing_; | 59 AudioTransport* audio_callback_ GUARDED_BY(lock_); |
56 int8_t captured_audio_[kBufferSizeBytes]; | 60 bool rendering_ GUARDED_BY(lock_); |
61 | |
62 class SinusCapturer; | |
63 std::unique_ptr<SinusCapturer> capturer_ GUARDED_BY(lock_); | |
64 | |
65 // Used for playout. | |
57 int8_t playout_buffer_[kBufferSizeBytes]; | 66 int8_t playout_buffer_[kBufferSizeBytes]; |
58 const float speed_; | 67 const float speed_; |
59 int64_t last_playout_ms_; | 68 int64_t last_playout_ms_; |
60 | 69 |
61 DriftingClock clock_; | 70 DriftingClock clock_; |
62 std::unique_ptr<EventTimerWrapper> tick_; | 71 std::unique_ptr<EventTimerWrapper> tick_; |
63 rtc::CriticalSection lock_; | |
64 rtc::PlatformThread thread_; | 72 rtc::PlatformThread thread_; |
65 std::unique_ptr<ModuleFileUtility> file_utility_; | |
66 std::unique_ptr<FileWrapper> input_stream_; | |
67 }; | 73 }; |
68 } // namespace test | 74 } // namespace test |
69 } // namespace webrtc | 75 } // namespace webrtc |
70 | 76 |
71 #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ | 77 #endif // WEBRTC_TEST_FAKE_AUDIO_DEVICE_H_ |
OLD | NEW |