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/checks.h" | |
pbos-webrtc
2016/02/09 21:08:50
Is this in use?
danilchap
2016/02/10 12:40:35
No, overlooked leftover from early thoughts. Remov
| |
16 #include "webrtc/base/platform_thread.h" | 17 #include "webrtc/base/platform_thread.h" |
17 #include "webrtc/modules/media_file/media_file_utility.h" | 18 #include "webrtc/modules/media_file/media_file_utility.h" |
18 #include "webrtc/system_wrappers/include/clock.h" | 19 #include "webrtc/system_wrappers/include/clock.h" |
19 #include "webrtc/system_wrappers/include/event_wrapper.h" | 20 #include "webrtc/system_wrappers/include/event_wrapper.h" |
20 #include "webrtc/system_wrappers/include/file_wrapper.h" | 21 #include "webrtc/system_wrappers/include/file_wrapper.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 namespace test { | 24 namespace test { |
24 | 25 |
25 FakeAudioDevice::FakeAudioDevice(Clock* clock, const std::string& filename) | 26 FakeAudioDevice::FakeAudioDevice(Clock* clock, |
27 const std::string& filename, | |
28 float drift) | |
26 : audio_callback_(NULL), | 29 : audio_callback_(NULL), |
27 capturing_(false), | 30 capturing_(false), |
28 captured_audio_(), | 31 captured_audio_(), |
29 playout_buffer_(), | 32 playout_buffer_(), |
33 drift_(drift), | |
30 last_playout_ms_(-1), | 34 last_playout_ms_(-1), |
31 clock_(clock), | 35 drifting_clock_(clock, drift), |
36 clock_(drift == 0 ? clock : &drifting_clock_), | |
32 tick_(EventTimerWrapper::Create()), | 37 tick_(EventTimerWrapper::Create()), |
33 thread_(FakeAudioDevice::Run, this, "FakeAudioDevice"), | 38 thread_(FakeAudioDevice::Run, this, "FakeAudioDevice"), |
34 file_utility_(new ModuleFileUtility(0)), | 39 file_utility_(new ModuleFileUtility(0)), |
35 input_stream_(FileWrapper::Create()) { | 40 input_stream_(FileWrapper::Create()) { |
36 memset(captured_audio_, 0, sizeof(captured_audio_)); | 41 memset(captured_audio_, 0, sizeof(captured_audio_)); |
37 memset(playout_buffer_, 0, sizeof(playout_buffer_)); | 42 memset(playout_buffer_, 0, sizeof(playout_buffer_)); |
38 // Open audio input file as read-only and looping. | 43 // Open audio input file as read-only and looping. |
39 EXPECT_EQ(0, input_stream_->OpenFile(filename.c_str(), true, true)) | 44 EXPECT_EQ(0, input_stream_->OpenFile(filename.c_str(), true, true)) |
40 << filename; | 45 << filename; |
41 } | 46 } |
42 | 47 |
43 FakeAudioDevice::~FakeAudioDevice() { | 48 FakeAudioDevice::~FakeAudioDevice() { |
44 Stop(); | 49 Stop(); |
45 | 50 |
46 thread_.Stop(); | 51 thread_.Stop(); |
47 } | 52 } |
48 | 53 |
49 int32_t FakeAudioDevice::Init() { | 54 int32_t FakeAudioDevice::Init() { |
50 rtc::CritScope cs(&lock_); | 55 rtc::CritScope cs(&lock_); |
51 if (file_utility_->InitPCMReading(*input_stream_.get()) != 0) | 56 if (file_utility_->InitPCMReading(*input_stream_.get()) != 0) |
52 return -1; | 57 return -1; |
53 | 58 |
54 if (!tick_->StartTimer(true, 10)) | 59 if (!tick_->StartTimer(true, 10 * (1. + drift_))) |
55 return -1; | 60 return -1; |
56 thread_.Start(); | 61 thread_.Start(); |
57 thread_.SetPriority(rtc::kHighPriority); | 62 thread_.SetPriority(rtc::kHighPriority); |
58 return 0; | 63 return 0; |
59 } | 64 } |
60 | 65 |
61 int32_t FakeAudioDevice::RegisterAudioCallback(AudioTransport* callback) { | 66 int32_t FakeAudioDevice::RegisterAudioCallback(AudioTransport* callback) { |
62 rtc::CritScope cs(&lock_); | 67 rtc::CritScope cs(&lock_); |
63 audio_callback_ = callback; | 68 audio_callback_ = callback; |
64 return 0; | 69 return 0; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 rtc::CritScope cs(&lock_); | 140 rtc::CritScope cs(&lock_); |
136 capturing_ = true; | 141 capturing_ = true; |
137 } | 142 } |
138 | 143 |
139 void FakeAudioDevice::Stop() { | 144 void FakeAudioDevice::Stop() { |
140 rtc::CritScope cs(&lock_); | 145 rtc::CritScope cs(&lock_); |
141 capturing_ = false; | 146 capturing_ = false; |
142 } | 147 } |
143 } // namespace test | 148 } // namespace test |
144 } // namespace webrtc | 149 } // namespace webrtc |
OLD | NEW |