henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #include "webrtc/api/test/fakeaudiocapturemodule.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 13 | #include "webrtc/base/checks.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 14 | #include "webrtc/base/common.h" |
| 15 | #include "webrtc/base/refcount.h" |
| 16 | #include "webrtc/base/thread.h" |
| 17 | #include "webrtc/base/timeutils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
| 19 | // Audio sample value that is high enough that it doesn't occur naturally when |
| 20 | // frames are being faked. E.g. NetEq will not generate this large sample value |
| 21 | // unless it has received an audio frame containing a sample of this value. |
| 22 | // Even simpler buffers would likely just contain audio sample values of 0. |
| 23 | static const int kHighSampleValue = 10000; |
| 24 | |
| 25 | // Same value as src/modules/audio_device/main/source/audio_device_config.h in |
| 26 | // https://code.google.com/p/webrtc/ |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 27 | static const int kAdmMaxIdleTimeProcess = 1000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 28 | |
| 29 | // Constants here are derived by running VoE using a real ADM. |
| 30 | // The constants correspond to 10ms of mono audio at 44kHz. |
| 31 | static const int kTimePerFrameMs = 10; |
Peter Kasting | b7e5054 | 2015-06-11 12:55:50 -0700 | [diff] [blame] | 32 | static const uint8_t kNumberOfChannels = 1; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | static const int kSamplesPerSecond = 44000; |
| 34 | static const int kTotalDelayMs = 0; |
| 35 | static const int kClockDriftMs = 0; |
| 36 | static const uint32_t kMaxVolume = 14392; |
| 37 | |
| 38 | enum { |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 39 | MSG_START_PROCESS, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 40 | MSG_RUN_PROCESS, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 43 | FakeAudioCaptureModule::FakeAudioCaptureModule() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | : last_process_time_ms_(0), |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 45 | audio_callback_(nullptr), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | recording_(false), |
| 47 | playing_(false), |
| 48 | play_is_initialized_(false), |
| 49 | rec_is_initialized_(false), |
| 50 | current_mic_level_(kMaxVolume), |
| 51 | started_(false), |
| 52 | next_frame_time_(0), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | frames_received_(0) { |
| 54 | } |
| 55 | |
| 56 | FakeAudioCaptureModule::~FakeAudioCaptureModule() { |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 57 | if (process_thread_) { |
| 58 | process_thread_->Stop(); |
| 59 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 60 | } |
| 61 | |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 62 | rtc::scoped_refptr<FakeAudioCaptureModule> FakeAudioCaptureModule::Create() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 63 | rtc::scoped_refptr<FakeAudioCaptureModule> capture_module( |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 64 | new rtc::RefCountedObject<FakeAudioCaptureModule>()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 65 | if (!capture_module->Initialize()) { |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 66 | return nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | } |
| 68 | return capture_module; |
| 69 | } |
| 70 | |
| 71 | int FakeAudioCaptureModule::frames_received() const { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 72 | rtc::CritScope cs(&crit_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | return frames_received_; |
| 74 | } |
| 75 | |
pkasting@chromium.org | 0b1534c | 2014-12-15 22:09:40 +0000 | [diff] [blame] | 76 | int64_t FakeAudioCaptureModule::TimeUntilNextProcess() { |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 77 | const int64_t current_time = rtc::TimeMillis(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | if (current_time < last_process_time_ms_) { |
| 79 | // TODO: wraparound could be handled more gracefully. |
| 80 | return 0; |
| 81 | } |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 82 | const int64_t elapsed_time = current_time - last_process_time_ms_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | if (kAdmMaxIdleTimeProcess < elapsed_time) { |
| 84 | return 0; |
| 85 | } |
| 86 | return kAdmMaxIdleTimeProcess - elapsed_time; |
| 87 | } |
| 88 | |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 89 | void FakeAudioCaptureModule::Process() { |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 90 | last_process_time_ms_ = rtc::TimeMillis(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 91 | } |
| 92 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 93 | int32_t FakeAudioCaptureModule::ActiveAudioLayer( |
| 94 | AudioLayer* /*audio_layer*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 95 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | webrtc::AudioDeviceModule::ErrorCode FakeAudioCaptureModule::LastError() const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 100 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 101 | return webrtc::AudioDeviceModule::kAdmErrNone; |
| 102 | } |
| 103 | |
| 104 | int32_t FakeAudioCaptureModule::RegisterEventObserver( |
| 105 | webrtc::AudioDeviceObserver* /*event_callback*/) { |
| 106 | // Only used to report warnings and errors. This fake implementation won't |
| 107 | // generate any so discard this callback. |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | int32_t FakeAudioCaptureModule::RegisterAudioCallback( |
| 112 | webrtc::AudioTransport* audio_callback) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 113 | rtc::CritScope cs(&crit_callback_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | audio_callback_ = audio_callback; |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | int32_t FakeAudioCaptureModule::Init() { |
| 119 | // Initialize is called by the factory method. Safe to ignore this Init call. |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | int32_t FakeAudioCaptureModule::Terminate() { |
| 124 | // Clean up in the destructor. No action here, just success. |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | bool FakeAudioCaptureModule::Initialized() const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 129 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | int16_t FakeAudioCaptureModule::PlayoutDevices() { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 134 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | int16_t FakeAudioCaptureModule::RecordingDevices() { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 139 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | int32_t FakeAudioCaptureModule::PlayoutDeviceName( |
| 144 | uint16_t /*index*/, |
| 145 | char /*name*/[webrtc::kAdmMaxDeviceNameSize], |
| 146 | char /*guid*/[webrtc::kAdmMaxGuidSize]) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 147 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | int32_t FakeAudioCaptureModule::RecordingDeviceName( |
| 152 | uint16_t /*index*/, |
| 153 | char /*name*/[webrtc::kAdmMaxDeviceNameSize], |
| 154 | char /*guid*/[webrtc::kAdmMaxGuidSize]) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 155 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | int32_t FakeAudioCaptureModule::SetPlayoutDevice(uint16_t /*index*/) { |
| 160 | // No playout device, just playing from file. Return success. |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | int32_t FakeAudioCaptureModule::SetPlayoutDevice(WindowsDeviceType /*device*/) { |
| 165 | if (play_is_initialized_) { |
| 166 | return -1; |
| 167 | } |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | int32_t FakeAudioCaptureModule::SetRecordingDevice(uint16_t /*index*/) { |
| 172 | // No recording device, just dropping audio. Return success. |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | int32_t FakeAudioCaptureModule::SetRecordingDevice( |
| 177 | WindowsDeviceType /*device*/) { |
| 178 | if (rec_is_initialized_) { |
| 179 | return -1; |
| 180 | } |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | int32_t FakeAudioCaptureModule::PlayoutIsAvailable(bool* /*available*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 185 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | int32_t FakeAudioCaptureModule::InitPlayout() { |
| 190 | play_is_initialized_ = true; |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | bool FakeAudioCaptureModule::PlayoutIsInitialized() const { |
| 195 | return play_is_initialized_; |
| 196 | } |
| 197 | |
| 198 | int32_t FakeAudioCaptureModule::RecordingIsAvailable(bool* /*available*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 199 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | int32_t FakeAudioCaptureModule::InitRecording() { |
| 204 | rec_is_initialized_ = true; |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | bool FakeAudioCaptureModule::RecordingIsInitialized() const { |
solenberg | d53a3f9 | 2016-04-14 13:56:37 -0700 | [diff] [blame] | 209 | return rec_is_initialized_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | int32_t FakeAudioCaptureModule::StartPlayout() { |
| 213 | if (!play_is_initialized_) { |
| 214 | return -1; |
| 215 | } |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 216 | { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 217 | rtc::CritScope cs(&crit_); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 218 | playing_ = true; |
| 219 | } |
| 220 | bool start = true; |
| 221 | UpdateProcessing(start); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | int32_t FakeAudioCaptureModule::StopPlayout() { |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 226 | bool start = false; |
| 227 | { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 228 | rtc::CritScope cs(&crit_); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 229 | playing_ = false; |
| 230 | start = ShouldStartProcessing(); |
| 231 | } |
| 232 | UpdateProcessing(start); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | bool FakeAudioCaptureModule::Playing() const { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 237 | rtc::CritScope cs(&crit_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 238 | return playing_; |
| 239 | } |
| 240 | |
| 241 | int32_t FakeAudioCaptureModule::StartRecording() { |
| 242 | if (!rec_is_initialized_) { |
| 243 | return -1; |
| 244 | } |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 245 | { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 246 | rtc::CritScope cs(&crit_); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 247 | recording_ = true; |
| 248 | } |
| 249 | bool start = true; |
| 250 | UpdateProcessing(start); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | int32_t FakeAudioCaptureModule::StopRecording() { |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 255 | bool start = false; |
| 256 | { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 257 | rtc::CritScope cs(&crit_); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 258 | recording_ = false; |
| 259 | start = ShouldStartProcessing(); |
| 260 | } |
| 261 | UpdateProcessing(start); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | bool FakeAudioCaptureModule::Recording() const { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 266 | rtc::CritScope cs(&crit_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 267 | return recording_; |
| 268 | } |
| 269 | |
| 270 | int32_t FakeAudioCaptureModule::SetAGC(bool /*enable*/) { |
| 271 | // No AGC but not needed since audio is pregenerated. Return success. |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | bool FakeAudioCaptureModule::AGC() const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 276 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | int32_t FakeAudioCaptureModule::SetWaveOutVolume(uint16_t /*volume_left*/, |
| 281 | uint16_t /*volume_right*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 282 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | int32_t FakeAudioCaptureModule::WaveOutVolume( |
| 287 | uint16_t* /*volume_left*/, |
| 288 | uint16_t* /*volume_right*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 289 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 293 | int32_t FakeAudioCaptureModule::InitSpeaker() { |
| 294 | // No speaker, just playing from file. Return success. |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | bool FakeAudioCaptureModule::SpeakerIsInitialized() const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 299 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 303 | int32_t FakeAudioCaptureModule::InitMicrophone() { |
| 304 | // No microphone, just playing from file. Return success. |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | bool FakeAudioCaptureModule::MicrophoneIsInitialized() const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 309 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | int32_t FakeAudioCaptureModule::SpeakerVolumeIsAvailable(bool* /*available*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 314 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | int32_t FakeAudioCaptureModule::SetSpeakerVolume(uint32_t /*volume*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 319 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | int32_t FakeAudioCaptureModule::SpeakerVolume(uint32_t* /*volume*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 324 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 325 | return 0; |
| 326 | } |
| 327 | |
| 328 | int32_t FakeAudioCaptureModule::MaxSpeakerVolume( |
| 329 | uint32_t* /*max_volume*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 330 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | int32_t FakeAudioCaptureModule::MinSpeakerVolume( |
| 335 | uint32_t* /*min_volume*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 336 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | int32_t FakeAudioCaptureModule::SpeakerVolumeStepSize( |
| 341 | uint16_t* /*step_size*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 342 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | int32_t FakeAudioCaptureModule::MicrophoneVolumeIsAvailable( |
| 347 | bool* /*available*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 348 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | return 0; |
| 350 | } |
| 351 | |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 352 | int32_t FakeAudioCaptureModule::SetMicrophoneVolume(uint32_t volume) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 353 | rtc::CritScope cs(&crit_); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 354 | current_mic_level_ = volume; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | int32_t FakeAudioCaptureModule::MicrophoneVolume(uint32_t* volume) const { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 359 | rtc::CritScope cs(&crit_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 360 | *volume = current_mic_level_; |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | int32_t FakeAudioCaptureModule::MaxMicrophoneVolume( |
| 365 | uint32_t* max_volume) const { |
| 366 | *max_volume = kMaxVolume; |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | int32_t FakeAudioCaptureModule::MinMicrophoneVolume( |
| 371 | uint32_t* /*min_volume*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 372 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | int32_t FakeAudioCaptureModule::MicrophoneVolumeStepSize( |
| 377 | uint16_t* /*step_size*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 378 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | int32_t FakeAudioCaptureModule::SpeakerMuteIsAvailable(bool* /*available*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 383 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | int32_t FakeAudioCaptureModule::SetSpeakerMute(bool /*enable*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 388 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | int32_t FakeAudioCaptureModule::SpeakerMute(bool* /*enabled*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 393 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | int32_t FakeAudioCaptureModule::MicrophoneMuteIsAvailable(bool* /*available*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 398 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | int32_t FakeAudioCaptureModule::SetMicrophoneMute(bool /*enable*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 403 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | int32_t FakeAudioCaptureModule::MicrophoneMute(bool* /*enabled*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 408 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | int32_t FakeAudioCaptureModule::MicrophoneBoostIsAvailable( |
| 413 | bool* /*available*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 414 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | int32_t FakeAudioCaptureModule::SetMicrophoneBoost(bool /*enable*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 419 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | int32_t FakeAudioCaptureModule::MicrophoneBoost(bool* /*enabled*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 424 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | int32_t FakeAudioCaptureModule::StereoPlayoutIsAvailable( |
| 429 | bool* available) const { |
| 430 | // No recording device, just dropping audio. Stereo can be dropped just |
| 431 | // as easily as mono. |
| 432 | *available = true; |
| 433 | return 0; |
| 434 | } |
| 435 | |
| 436 | int32_t FakeAudioCaptureModule::SetStereoPlayout(bool /*enable*/) { |
| 437 | // No recording device, just dropping audio. Stereo can be dropped just |
| 438 | // as easily as mono. |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | int32_t FakeAudioCaptureModule::StereoPlayout(bool* /*enabled*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 443 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | int32_t FakeAudioCaptureModule::StereoRecordingIsAvailable( |
| 448 | bool* available) const { |
| 449 | // Keep thing simple. No stereo recording. |
| 450 | *available = false; |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | int32_t FakeAudioCaptureModule::SetStereoRecording(bool enable) { |
| 455 | if (!enable) { |
| 456 | return 0; |
| 457 | } |
| 458 | return -1; |
| 459 | } |
| 460 | |
| 461 | int32_t FakeAudioCaptureModule::StereoRecording(bool* /*enabled*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 462 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | int32_t FakeAudioCaptureModule::SetRecordingChannel( |
| 467 | const ChannelType channel) { |
| 468 | if (channel != AudioDeviceModule::kChannelBoth) { |
| 469 | // There is no right or left in mono. I.e. kChannelBoth should be used for |
| 470 | // mono. |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 471 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 472 | return -1; |
| 473 | } |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | int32_t FakeAudioCaptureModule::RecordingChannel(ChannelType* channel) const { |
| 478 | // Stereo recording not supported. However, WebRTC ADM returns kChannelBoth |
| 479 | // in that case. Do the same here. |
| 480 | *channel = AudioDeviceModule::kChannelBoth; |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | int32_t FakeAudioCaptureModule::SetPlayoutBuffer(const BufferType /*type*/, |
| 485 | uint16_t /*size_ms*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 486 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 487 | return 0; |
| 488 | } |
| 489 | |
| 490 | int32_t FakeAudioCaptureModule::PlayoutBuffer(BufferType* /*type*/, |
| 491 | uint16_t* /*size_ms*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 492 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | int32_t FakeAudioCaptureModule::PlayoutDelay(uint16_t* delay_ms) const { |
| 497 | // No delay since audio frames are dropped. |
| 498 | *delay_ms = 0; |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | int32_t FakeAudioCaptureModule::RecordingDelay(uint16_t* /*delay_ms*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 503 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | int32_t FakeAudioCaptureModule::CPULoad(uint16_t* /*load*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 508 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | int32_t FakeAudioCaptureModule::StartRawOutputFileRecording( |
| 513 | const char /*pcm_file_name_utf8*/[webrtc::kAdmMaxFileNameSize]) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 514 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | int32_t FakeAudioCaptureModule::StopRawOutputFileRecording() { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 519 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | int32_t FakeAudioCaptureModule::StartRawInputFileRecording( |
| 524 | const char /*pcm_file_name_utf8*/[webrtc::kAdmMaxFileNameSize]) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 525 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | int32_t FakeAudioCaptureModule::StopRawInputFileRecording() { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 530 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | int32_t FakeAudioCaptureModule::SetRecordingSampleRate( |
| 535 | const uint32_t /*samples_per_sec*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 536 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | int32_t FakeAudioCaptureModule::RecordingSampleRate( |
| 541 | uint32_t* /*samples_per_sec*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 542 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | int32_t FakeAudioCaptureModule::SetPlayoutSampleRate( |
| 547 | const uint32_t /*samples_per_sec*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 548 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | |
| 552 | int32_t FakeAudioCaptureModule::PlayoutSampleRate( |
| 553 | uint32_t* /*samples_per_sec*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 554 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | int32_t FakeAudioCaptureModule::ResetAudioDevice() { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 559 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | int32_t FakeAudioCaptureModule::SetLoudspeakerStatus(bool /*enable*/) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 564 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | int32_t FakeAudioCaptureModule::GetLoudspeakerStatus(bool* /*enabled*/) const { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 569 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 573 | void FakeAudioCaptureModule::OnMessage(rtc::Message* msg) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 574 | switch (msg->message_id) { |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 575 | case MSG_START_PROCESS: |
| 576 | StartProcessP(); |
| 577 | break; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 578 | case MSG_RUN_PROCESS: |
| 579 | ProcessFrameP(); |
| 580 | break; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 581 | default: |
| 582 | // All existing messages should be caught. Getting here should never |
| 583 | // happen. |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 584 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | |
| 588 | bool FakeAudioCaptureModule::Initialize() { |
| 589 | // Set the send buffer samples high enough that it would not occur on the |
| 590 | // remote side unless a packet containing a sample of that magnitude has been |
| 591 | // sent to it. Note that the audio processing pipeline will likely distort the |
| 592 | // original signal. |
| 593 | SetSendBuffer(kHighSampleValue); |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 594 | last_process_time_ms_ = rtc::TimeMillis(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 595 | return true; |
| 596 | } |
| 597 | |
| 598 | void FakeAudioCaptureModule::SetSendBuffer(int value) { |
| 599 | Sample* buffer_ptr = reinterpret_cast<Sample*>(send_buffer_); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 600 | const size_t buffer_size_in_samples = |
Peter Kasting | 728d903 | 2015-06-11 14:31:38 -0700 | [diff] [blame] | 601 | sizeof(send_buffer_) / kNumberBytesPerSample; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 602 | for (size_t i = 0; i < buffer_size_in_samples; ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 603 | buffer_ptr[i] = value; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | void FakeAudioCaptureModule::ResetRecBuffer() { |
| 608 | memset(rec_buffer_, 0, sizeof(rec_buffer_)); |
| 609 | } |
| 610 | |
| 611 | bool FakeAudioCaptureModule::CheckRecBuffer(int value) { |
| 612 | const Sample* buffer_ptr = reinterpret_cast<const Sample*>(rec_buffer_); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 613 | const size_t buffer_size_in_samples = |
Peter Kasting | 728d903 | 2015-06-11 14:31:38 -0700 | [diff] [blame] | 614 | sizeof(rec_buffer_) / kNumberBytesPerSample; |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 615 | for (size_t i = 0; i < buffer_size_in_samples; ++i) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 616 | if (buffer_ptr[i] >= value) return true; |
| 617 | } |
| 618 | return false; |
| 619 | } |
| 620 | |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 621 | bool FakeAudioCaptureModule::ShouldStartProcessing() { |
| 622 | return recording_ || playing_; |
| 623 | } |
| 624 | |
| 625 | void FakeAudioCaptureModule::UpdateProcessing(bool start) { |
| 626 | if (start) { |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 627 | if (!process_thread_) { |
| 628 | process_thread_.reset(new rtc::Thread()); |
| 629 | process_thread_->Start(); |
| 630 | } |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 631 | process_thread_->Post(RTC_FROM_HERE, this, MSG_START_PROCESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 632 | } else { |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 633 | if (process_thread_) { |
| 634 | process_thread_->Stop(); |
| 635 | process_thread_.reset(nullptr); |
| 636 | } |
| 637 | started_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 641 | void FakeAudioCaptureModule::StartProcessP() { |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame^] | 642 | RTC_CHECK(process_thread_->IsCurrent()); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 643 | if (started_) { |
| 644 | // Already started. |
| 645 | return; |
| 646 | } |
| 647 | ProcessFrameP(); |
| 648 | } |
| 649 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 650 | void FakeAudioCaptureModule::ProcessFrameP() { |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame^] | 651 | RTC_CHECK(process_thread_->IsCurrent()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 652 | if (!started_) { |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 653 | next_frame_time_ = rtc::TimeMillis(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 654 | started_ = true; |
| 655 | } |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 656 | |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 657 | { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 658 | rtc::CritScope cs(&crit_); |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 659 | // Receive and send frames every kTimePerFrameMs. |
| 660 | if (playing_) { |
| 661 | ReceiveFrameP(); |
| 662 | } |
| 663 | if (recording_) { |
| 664 | SendFrameP(); |
| 665 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | next_frame_time_ += kTimePerFrameMs; |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 669 | const int64_t current_time = rtc::TimeMillis(); |
| 670 | const int64_t wait_time = |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 671 | (next_frame_time_ > current_time) ? next_frame_time_ - current_time : 0; |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 672 | process_thread_->PostDelayed(RTC_FROM_HERE, wait_time, this, MSG_RUN_PROCESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | void FakeAudioCaptureModule::ReceiveFrameP() { |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame^] | 676 | RTC_CHECK(process_thread_->IsCurrent()); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 677 | { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 678 | rtc::CritScope cs(&crit_callback_); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 679 | if (!audio_callback_) { |
| 680 | return; |
| 681 | } |
| 682 | ResetRecBuffer(); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 683 | size_t nSamplesOut = 0; |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 684 | int64_t elapsed_time_ms = 0; |
wu@webrtc.org | cb711f7 | 2014-05-19 17:39:11 +0000 | [diff] [blame] | 685 | int64_t ntp_time_ms = 0; |
| 686 | if (audio_callback_->NeedMorePlayData(kNumberSamples, kNumberBytesPerSample, |
| 687 | kNumberOfChannels, kSamplesPerSecond, |
| 688 | rec_buffer_, nSamplesOut, |
wu@webrtc.org | 94454b7 | 2014-06-05 20:34:08 +0000 | [diff] [blame] | 689 | &elapsed_time_ms, &ntp_time_ms) != 0) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 690 | RTC_NOTREACHED(); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 691 | } |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame^] | 692 | RTC_CHECK(nSamplesOut == kNumberSamples); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 693 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 694 | // The SetBuffer() function ensures that after decoding, the audio buffer |
| 695 | // should contain samples of similar magnitude (there is likely to be some |
| 696 | // distortion due to the audio pipeline). If one sample is detected to |
| 697 | // have the same or greater magnitude somewhere in the frame, an actual frame |
| 698 | // has been received from the remote side (i.e. faked frames are not being |
| 699 | // pulled). |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 700 | if (CheckRecBuffer(kHighSampleValue)) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 701 | rtc::CritScope cs(&crit_); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 702 | ++frames_received_; |
| 703 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | void FakeAudioCaptureModule::SendFrameP() { |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame^] | 707 | RTC_CHECK(process_thread_->IsCurrent()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 708 | rtc::CritScope cs(&crit_callback_); |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 709 | if (!audio_callback_) { |
| 710 | return; |
| 711 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 712 | bool key_pressed = false; |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 713 | uint32_t current_mic_level = 0; |
| 714 | MicrophoneVolume(¤t_mic_level); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 715 | if (audio_callback_->RecordedDataIsAvailable(send_buffer_, kNumberSamples, |
| 716 | kNumberBytesPerSample, |
| 717 | kNumberOfChannels, |
| 718 | kSamplesPerSecond, kTotalDelayMs, |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 719 | kClockDriftMs, current_mic_level, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 720 | key_pressed, |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 721 | current_mic_level) != 0) { |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 722 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 723 | } |
wu@webrtc.org | 8804a29 | 2013-10-22 23:09:20 +0000 | [diff] [blame] | 724 | SetMicrophoneVolume(current_mic_level); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 725 | } |