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 | 10 |
11 #include "webrtc/test/fake_audio_device.h" | 11 #include "webrtc/test/fake_audio_device.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/base/platform_thread.h" | 16 #include "webrtc/base/platform_thread.h" |
17 #include "webrtc/modules/media_file/media_file_utility.h" | 17 #include "webrtc/modules/media_file/media_file_utility.h" |
18 #include "webrtc/system_wrappers/include/clock.h" | 18 #include "webrtc/system_wrappers/include/clock.h" |
19 #include "webrtc/system_wrappers/include/event_wrapper.h" | 19 #include "webrtc/system_wrappers/include/event_wrapper.h" |
20 #include "webrtc/system_wrappers/include/file_wrapper.h" | 20 #include "webrtc/system_wrappers/include/file_wrapper.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 namespace test { | 23 namespace test { |
24 | 24 |
25 FakeAudioDevice::FakeAudioDevice(Clock* clock, const std::string& filename) | 25 FakeAudioDevice::FakeAudioDevice(Clock* clock, |
| 26 const std::string& filename, |
| 27 float speed) |
26 : audio_callback_(NULL), | 28 : audio_callback_(NULL), |
27 capturing_(false), | 29 capturing_(false), |
28 captured_audio_(), | 30 captured_audio_(), |
29 playout_buffer_(), | 31 playout_buffer_(), |
| 32 speed_(speed), |
30 last_playout_ms_(-1), | 33 last_playout_ms_(-1), |
31 clock_(clock), | 34 clock_(clock, speed), |
32 tick_(EventTimerWrapper::Create()), | 35 tick_(EventTimerWrapper::Create()), |
33 thread_(FakeAudioDevice::Run, this, "FakeAudioDevice"), | 36 thread_(FakeAudioDevice::Run, this, "FakeAudioDevice"), |
34 file_utility_(new ModuleFileUtility(0)), | 37 file_utility_(new ModuleFileUtility(0)), |
35 input_stream_(FileWrapper::Create()) { | 38 input_stream_(FileWrapper::Create()) { |
36 memset(captured_audio_, 0, sizeof(captured_audio_)); | 39 memset(captured_audio_, 0, sizeof(captured_audio_)); |
37 memset(playout_buffer_, 0, sizeof(playout_buffer_)); | 40 memset(playout_buffer_, 0, sizeof(playout_buffer_)); |
38 // Open audio input file as read-only and looping. | 41 // Open audio input file as read-only and looping. |
39 EXPECT_EQ(0, input_stream_->OpenFile(filename.c_str(), true, true)) | 42 EXPECT_EQ(0, input_stream_->OpenFile(filename.c_str(), true, true)) |
40 << filename; | 43 << filename; |
41 } | 44 } |
42 | 45 |
43 FakeAudioDevice::~FakeAudioDevice() { | 46 FakeAudioDevice::~FakeAudioDevice() { |
44 Stop(); | 47 Stop(); |
45 | 48 |
46 thread_.Stop(); | 49 thread_.Stop(); |
47 } | 50 } |
48 | 51 |
49 int32_t FakeAudioDevice::Init() { | 52 int32_t FakeAudioDevice::Init() { |
50 rtc::CritScope cs(&lock_); | 53 rtc::CritScope cs(&lock_); |
51 if (file_utility_->InitPCMReading(*input_stream_.get()) != 0) | 54 if (file_utility_->InitPCMReading(*input_stream_.get()) != 0) |
52 return -1; | 55 return -1; |
53 | 56 |
54 if (!tick_->StartTimer(true, 10)) | 57 if (!tick_->StartTimer(true, 10 / speed_)) |
55 return -1; | 58 return -1; |
56 thread_.Start(); | 59 thread_.Start(); |
57 thread_.SetPriority(rtc::kHighPriority); | 60 thread_.SetPriority(rtc::kHighPriority); |
58 return 0; | 61 return 0; |
59 } | 62 } |
60 | 63 |
61 int32_t FakeAudioDevice::RegisterAudioCallback(AudioTransport* callback) { | 64 int32_t FakeAudioDevice::RegisterAudioCallback(AudioTransport* callback) { |
62 rtc::CritScope cs(&lock_); | 65 rtc::CritScope cs(&lock_); |
63 audio_callback_ = callback; | 66 audio_callback_ = callback; |
64 return 0; | 67 return 0; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 num_samples, | 103 num_samples, |
101 2, | 104 2, |
102 1, | 105 1, |
103 kFrequencyHz, | 106 kFrequencyHz, |
104 0, | 107 0, |
105 0, | 108 0, |
106 0, | 109 0, |
107 false, | 110 false, |
108 new_mic_level)); | 111 new_mic_level)); |
109 size_t samples_needed = kFrequencyHz / 100; | 112 size_t samples_needed = kFrequencyHz / 100; |
110 int64_t now_ms = clock_->TimeInMilliseconds(); | 113 int64_t now_ms = clock_.TimeInMilliseconds(); |
111 uint32_t time_since_last_playout_ms = now_ms - last_playout_ms_; | 114 uint32_t time_since_last_playout_ms = now_ms - last_playout_ms_; |
112 if (last_playout_ms_ > 0 && time_since_last_playout_ms > 0) { | 115 if (last_playout_ms_ > 0 && time_since_last_playout_ms > 0) { |
113 samples_needed = std::min( | 116 samples_needed = std::min( |
114 static_cast<size_t>(kFrequencyHz / time_since_last_playout_ms), | 117 static_cast<size_t>(kFrequencyHz / time_since_last_playout_ms), |
115 kBufferSizeBytes / 2); | 118 kBufferSizeBytes / 2); |
116 } | 119 } |
117 size_t samples_out = 0; | 120 size_t samples_out = 0; |
118 int64_t elapsed_time_ms = -1; | 121 int64_t elapsed_time_ms = -1; |
119 int64_t ntp_time_ms = -1; | 122 int64_t ntp_time_ms = -1; |
120 EXPECT_EQ(0, | 123 EXPECT_EQ(0, |
(...skipping 14 matching lines...) Expand all Loading... |
135 rtc::CritScope cs(&lock_); | 138 rtc::CritScope cs(&lock_); |
136 capturing_ = true; | 139 capturing_ = true; |
137 } | 140 } |
138 | 141 |
139 void FakeAudioDevice::Stop() { | 142 void FakeAudioDevice::Stop() { |
140 rtc::CritScope cs(&lock_); | 143 rtc::CritScope cs(&lock_); |
141 capturing_ = false; | 144 capturing_ = false; |
142 } | 145 } |
143 } // namespace test | 146 } // namespace test |
144 } // namespace webrtc | 147 } // namespace webrtc |
OLD | NEW |