Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/protocol/webrtc_audio_module.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/stl_util.h" | |
| 9 #include "base/threading/thread_task_runner_handle.h" | |
| 10 | |
| 11 namespace remoting { | |
| 12 namespace protocol { | |
| 13 | |
| 14 namespace { | |
|
nicholss
2016/10/04 21:42:00
Is the plan to finish implementing the reset of th
Sergey Ulanov
2016/10/04 22:32:32
Nope. The only reason we need this class is to cal
| |
| 15 | |
| 16 const int kSamplingRate = 48000; | |
| 17 | |
| 18 // Webrtc uses 10ms frames. | |
| 19 const int kFrameLengthMs = 10; | |
| 20 const int kSamplesPerFrame = kSamplingRate * kFrameLengthMs / 1000; | |
| 21 | |
| 22 constexpr base::TimeDelta kPollInterval = | |
| 23 base::TimeDelta::FromMilliseconds(5 * kFrameLengthMs); | |
| 24 const int kChannels = 2; | |
| 25 const int kBytesPerSample = 2; | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 WebrtcAudioModule::WebrtcAudioModule() {} | |
| 30 WebrtcAudioModule::~WebrtcAudioModule() {} | |
| 31 | |
| 32 void WebrtcAudioModule::Initialize( | |
| 33 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner) { | |
| 34 DCHECK(!audio_task_runner_); | |
| 35 DCHECK(audio_task_runner); | |
| 36 audio_task_runner_ = audio_task_runner; | |
| 37 } | |
| 38 | |
| 39 int64_t WebrtcAudioModule::TimeUntilNextProcess() { | |
| 40 // We don't need to do anything in Process(), so returning just an arbitrary | |
| 41 // value that's not too low, so that Process() doesn't get called too | |
| 42 // frequently. | |
| 43 return 1000000; | |
| 44 } | |
| 45 | |
| 46 void WebrtcAudioModule::Process() {} | |
| 47 | |
| 48 int32_t WebrtcAudioModule::ActiveAudioLayer(AudioLayer* audio_layer) const { | |
| 49 NOTREACHED(); | |
| 50 return -1; | |
| 51 } | |
| 52 | |
| 53 WebrtcAudioModule::ErrorCode WebrtcAudioModule::LastError() const { | |
| 54 return kAdmErrNone; | |
| 55 } | |
| 56 | |
| 57 int32_t WebrtcAudioModule::RegisterEventObserver( | |
| 58 webrtc::AudioDeviceObserver* event_callback) { | |
| 59 return 0; | |
| 60 } | |
| 61 | |
| 62 int32_t WebrtcAudioModule::RegisterAudioCallback( | |
| 63 webrtc::AudioTransport* audio_transport) { | |
| 64 base::AutoLock lock(lock_); | |
| 65 audio_transport_ = audio_transport; | |
| 66 return 0; | |
| 67 } | |
| 68 | |
| 69 int32_t WebrtcAudioModule::Init() { | |
| 70 base::AutoLock auto_lock(lock_); | |
| 71 initialized_ = true; | |
| 72 return 0; | |
| 73 } | |
| 74 | |
| 75 int32_t WebrtcAudioModule::Terminate() { | |
| 76 base::AutoLock auto_lock(lock_); | |
| 77 initialized_ = false; | |
| 78 return 0; | |
| 79 } | |
| 80 | |
| 81 bool WebrtcAudioModule::Initialized() const { | |
| 82 base::AutoLock auto_lock(lock_); | |
| 83 return initialized_; | |
| 84 } | |
| 85 | |
| 86 int16_t WebrtcAudioModule::PlayoutDevices() { | |
| 87 return 0; | |
| 88 } | |
| 89 | |
| 90 int16_t WebrtcAudioModule::RecordingDevices() { | |
| 91 return 0; | |
| 92 } | |
| 93 | |
| 94 int32_t WebrtcAudioModule::PlayoutDeviceName( | |
| 95 uint16_t index, | |
| 96 char name[webrtc::kAdmMaxDeviceNameSize], | |
| 97 char guid[webrtc::kAdmMaxGuidSize]) { | |
| 98 return 0; | |
| 99 } | |
| 100 | |
| 101 int32_t WebrtcAudioModule::RecordingDeviceName( | |
| 102 uint16_t index, | |
| 103 char name[webrtc::kAdmMaxDeviceNameSize], | |
| 104 char guid[webrtc::kAdmMaxGuidSize]) { | |
| 105 return 0; | |
| 106 } | |
| 107 | |
| 108 int32_t WebrtcAudioModule::SetPlayoutDevice(uint16_t index) { | |
| 109 return 0; | |
| 110 } | |
| 111 | |
| 112 int32_t WebrtcAudioModule::SetPlayoutDevice(WindowsDeviceType device) { | |
| 113 return 0; | |
| 114 } | |
| 115 | |
| 116 int32_t WebrtcAudioModule::SetRecordingDevice(uint16_t index) { | |
| 117 return 0; | |
| 118 } | |
| 119 | |
| 120 int32_t WebrtcAudioModule::SetRecordingDevice(WindowsDeviceType device) { | |
| 121 return 0; | |
| 122 } | |
| 123 | |
| 124 int32_t WebrtcAudioModule::PlayoutIsAvailable(bool* available) { | |
| 125 base::AutoLock auto_lock(lock_); | |
| 126 *available = initialized_; | |
|
nicholss
2016/10/04 21:42:00
Is this call intended to be a buffer check? Playou
Sergey Ulanov
2016/10/04 22:32:32
I assume the intended use of this method is to det
| |
| 127 return 0; | |
| 128 } | |
| 129 | |
| 130 int32_t WebrtcAudioModule::InitPlayout() { | |
| 131 return 0; | |
| 132 } | |
| 133 | |
| 134 bool WebrtcAudioModule::PlayoutIsInitialized() const { | |
| 135 base::AutoLock auto_lock(lock_); | |
| 136 return initialized_; | |
| 137 } | |
| 138 | |
| 139 int32_t WebrtcAudioModule::RecordingIsAvailable(bool* available) { | |
| 140 NOTREACHED(); | |
| 141 return -1; | |
| 142 } | |
| 143 | |
| 144 int32_t WebrtcAudioModule::InitRecording() { | |
| 145 return 0; | |
| 146 } | |
| 147 | |
| 148 bool WebrtcAudioModule::RecordingIsInitialized() const { | |
| 149 return false; | |
| 150 } | |
| 151 | |
| 152 int32_t WebrtcAudioModule::StartPlayout() { | |
| 153 base::AutoLock auto_lock(lock_); | |
| 154 if (!playing_ && audio_task_runner_) { | |
| 155 audio_task_runner_->PostTask( | |
| 156 FROM_HERE, | |
| 157 base::Bind(&WebrtcAudioModule::StartPlayoutOnAudioThread, this)); | |
| 158 playing_ = true; | |
| 159 } | |
| 160 return 0; | |
| 161 } | |
| 162 | |
| 163 int32_t WebrtcAudioModule::StopPlayout() { | |
| 164 base::AutoLock auto_lock(lock_); | |
| 165 if (playing_) { | |
| 166 audio_task_runner_->PostTask( | |
| 167 FROM_HERE, | |
| 168 base::Bind(&WebrtcAudioModule::StopPlayoutOnAudioThread, this)); | |
| 169 playing_ = false; | |
| 170 } | |
| 171 return 0; | |
| 172 } | |
| 173 | |
| 174 bool WebrtcAudioModule::Playing() const { | |
| 175 base::AutoLock auto_lock(lock_); | |
| 176 return playing_; | |
| 177 } | |
| 178 | |
| 179 int32_t WebrtcAudioModule::StartRecording() { | |
| 180 return 0; | |
| 181 } | |
| 182 | |
| 183 int32_t WebrtcAudioModule::StopRecording() { | |
| 184 return 0; | |
| 185 } | |
| 186 | |
| 187 bool WebrtcAudioModule::Recording() const { | |
| 188 return false; | |
| 189 } | |
| 190 | |
| 191 int32_t WebrtcAudioModule::SetAGC(bool enable) { | |
| 192 return 0; | |
| 193 } | |
| 194 | |
| 195 bool WebrtcAudioModule::AGC() const { | |
| 196 NOTREACHED(); | |
| 197 return false; | |
| 198 } | |
| 199 | |
| 200 int32_t WebrtcAudioModule::SetWaveOutVolume(uint16_t volume_left, | |
| 201 uint16_t volume_right) { | |
| 202 NOTREACHED(); | |
| 203 return -1; | |
| 204 } | |
| 205 | |
| 206 int32_t WebrtcAudioModule::WaveOutVolume(uint16_t* volume_left, | |
| 207 uint16_t* volume_right) const { | |
| 208 NOTREACHED(); | |
| 209 return -1; | |
| 210 } | |
| 211 | |
| 212 int32_t WebrtcAudioModule::InitSpeaker() { | |
| 213 return 0; | |
| 214 } | |
| 215 | |
| 216 bool WebrtcAudioModule::SpeakerIsInitialized() const { | |
| 217 return false; | |
| 218 } | |
| 219 | |
| 220 int32_t WebrtcAudioModule::InitMicrophone() { | |
| 221 return 0; | |
| 222 } | |
| 223 | |
| 224 bool WebrtcAudioModule::MicrophoneIsInitialized() const { | |
| 225 return false; | |
| 226 } | |
| 227 | |
| 228 int32_t WebrtcAudioModule::SpeakerVolumeIsAvailable(bool* available) { | |
| 229 NOTREACHED(); | |
| 230 return -1; | |
| 231 } | |
| 232 | |
| 233 int32_t WebrtcAudioModule::SetSpeakerVolume(uint32_t volume) { | |
| 234 NOTREACHED(); | |
| 235 return -1; | |
| 236 } | |
| 237 | |
| 238 int32_t WebrtcAudioModule::SpeakerVolume(uint32_t* volume) const { | |
| 239 NOTREACHED(); | |
| 240 return -1; | |
| 241 } | |
| 242 | |
| 243 int32_t WebrtcAudioModule::MaxSpeakerVolume(uint32_t* max_volume) const { | |
| 244 NOTREACHED(); | |
| 245 return -1; | |
| 246 } | |
| 247 | |
| 248 int32_t WebrtcAudioModule::MinSpeakerVolume(uint32_t* min_volume) const { | |
| 249 NOTREACHED(); | |
| 250 return -1; | |
| 251 } | |
| 252 | |
| 253 int32_t WebrtcAudioModule::SpeakerVolumeStepSize(uint16_t* step_size) const { | |
| 254 NOTREACHED(); | |
| 255 return -1; | |
| 256 } | |
| 257 | |
| 258 int32_t WebrtcAudioModule::MicrophoneVolumeIsAvailable(bool* available) { | |
| 259 NOTREACHED(); | |
| 260 return -1; | |
| 261 } | |
| 262 | |
| 263 int32_t WebrtcAudioModule::SetMicrophoneVolume(uint32_t volume) { | |
| 264 NOTREACHED(); | |
| 265 return -1; | |
| 266 } | |
| 267 | |
| 268 int32_t WebrtcAudioModule::MicrophoneVolume(uint32_t* volume) const { | |
| 269 NOTREACHED(); | |
| 270 return -1; | |
| 271 } | |
| 272 | |
| 273 int32_t WebrtcAudioModule::MaxMicrophoneVolume(uint32_t* max_volume) const { | |
| 274 NOTREACHED(); | |
| 275 return -1; | |
| 276 } | |
| 277 | |
| 278 int32_t WebrtcAudioModule::MinMicrophoneVolume(uint32_t* min_volume) const { | |
| 279 NOTREACHED(); | |
| 280 return -1; | |
| 281 } | |
| 282 | |
| 283 int32_t WebrtcAudioModule::MicrophoneVolumeStepSize(uint16_t* step_size) const { | |
| 284 NOTREACHED(); | |
| 285 return -1; | |
| 286 } | |
| 287 | |
| 288 int32_t WebrtcAudioModule::SpeakerMuteIsAvailable(bool* available) { | |
| 289 NOTREACHED(); | |
| 290 return -1; | |
| 291 } | |
| 292 | |
| 293 int32_t WebrtcAudioModule::SetSpeakerMute(bool enable) { | |
| 294 NOTREACHED(); | |
| 295 return -1; | |
| 296 } | |
| 297 | |
| 298 int32_t WebrtcAudioModule::SpeakerMute(bool* enabled) const { | |
| 299 NOTREACHED(); | |
| 300 return -1; | |
| 301 } | |
| 302 | |
| 303 int32_t WebrtcAudioModule::MicrophoneMuteIsAvailable(bool* available) { | |
| 304 NOTREACHED(); | |
| 305 return -1; | |
| 306 } | |
| 307 | |
| 308 int32_t WebrtcAudioModule::SetMicrophoneMute(bool enable) { | |
| 309 NOTREACHED(); | |
| 310 return -1; | |
| 311 } | |
| 312 | |
| 313 int32_t WebrtcAudioModule::MicrophoneMute(bool* enabled) const { | |
| 314 NOTREACHED(); | |
| 315 return -1; | |
| 316 } | |
| 317 | |
| 318 int32_t WebrtcAudioModule::MicrophoneBoostIsAvailable(bool* available) { | |
| 319 NOTREACHED(); | |
| 320 return -1; | |
| 321 } | |
| 322 | |
| 323 int32_t WebrtcAudioModule::SetMicrophoneBoost(bool enable) { | |
| 324 NOTREACHED(); | |
| 325 return -1; | |
| 326 } | |
| 327 | |
| 328 int32_t WebrtcAudioModule::MicrophoneBoost(bool* enabled) const { | |
| 329 NOTREACHED(); | |
| 330 return -1; | |
| 331 } | |
| 332 | |
| 333 int32_t WebrtcAudioModule::StereoPlayoutIsAvailable(bool* available) const { | |
| 334 *available = true; | |
| 335 return 0; | |
| 336 } | |
| 337 | |
| 338 int32_t WebrtcAudioModule::SetStereoPlayout(bool enable) { | |
| 339 DCHECK(enable); | |
| 340 return 0; | |
| 341 } | |
| 342 | |
| 343 int32_t WebrtcAudioModule::StereoPlayout(bool* enabled) const { | |
| 344 NOTREACHED(); | |
| 345 return -1; | |
| 346 } | |
| 347 | |
| 348 int32_t WebrtcAudioModule::StereoRecordingIsAvailable(bool* available) const { | |
| 349 *available = false; | |
| 350 return 0; | |
| 351 } | |
| 352 | |
| 353 int32_t WebrtcAudioModule::SetStereoRecording(bool enable) { | |
| 354 return 0; | |
| 355 } | |
| 356 | |
| 357 int32_t WebrtcAudioModule::StereoRecording(bool* enabled) const { | |
| 358 NOTREACHED(); | |
| 359 return -1; | |
| 360 } | |
| 361 | |
| 362 int32_t WebrtcAudioModule::SetRecordingChannel(const ChannelType channel) { | |
| 363 return 0; | |
| 364 } | |
| 365 | |
| 366 int32_t WebrtcAudioModule::RecordingChannel(ChannelType* channel) const { | |
| 367 NOTREACHED(); | |
| 368 return -1; | |
| 369 } | |
| 370 | |
| 371 int32_t WebrtcAudioModule::SetPlayoutBuffer(const BufferType type, | |
| 372 uint16_t size_ms) { | |
| 373 NOTREACHED(); | |
| 374 return -1; | |
| 375 } | |
| 376 | |
| 377 int32_t WebrtcAudioModule::PlayoutBuffer(BufferType* type, | |
| 378 uint16_t* size_ms) const { | |
| 379 NOTREACHED(); | |
| 380 return -1; | |
| 381 } | |
| 382 | |
| 383 int32_t WebrtcAudioModule::PlayoutDelay(uint16_t* delay_ms) const { | |
| 384 *delay_ms = 0; | |
| 385 return 0; | |
| 386 } | |
| 387 | |
| 388 int32_t WebrtcAudioModule::RecordingDelay(uint16_t* delay_ms) const { | |
| 389 NOTREACHED(); | |
| 390 return -1; | |
| 391 } | |
| 392 | |
| 393 int32_t WebrtcAudioModule::CPULoad(uint16_t* load) const { | |
| 394 NOTREACHED(); | |
| 395 return -1; | |
| 396 } | |
| 397 | |
| 398 int32_t WebrtcAudioModule::StartRawOutputFileRecording( | |
| 399 const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) { | |
| 400 NOTREACHED(); | |
| 401 return -1; | |
| 402 } | |
| 403 | |
| 404 int32_t WebrtcAudioModule::StopRawOutputFileRecording() { | |
| 405 NOTREACHED(); | |
| 406 return -1; | |
| 407 } | |
| 408 | |
| 409 int32_t WebrtcAudioModule::StartRawInputFileRecording( | |
| 410 const char pcm_file_name_utf8[webrtc::kAdmMaxFileNameSize]) { | |
| 411 NOTREACHED(); | |
| 412 return -1; | |
| 413 } | |
| 414 | |
| 415 int32_t WebrtcAudioModule::StopRawInputFileRecording() { | |
| 416 NOTREACHED(); | |
| 417 return -1; | |
| 418 } | |
| 419 | |
| 420 int32_t WebrtcAudioModule::SetRecordingSampleRate( | |
| 421 const uint32_t samples_per_sec) { | |
| 422 NOTREACHED(); | |
| 423 return -1; | |
| 424 } | |
| 425 | |
| 426 int32_t WebrtcAudioModule::RecordingSampleRate( | |
| 427 uint32_t* samples_per_sec) const { | |
| 428 NOTREACHED(); | |
| 429 return -1; | |
| 430 } | |
| 431 | |
| 432 int32_t WebrtcAudioModule::SetPlayoutSampleRate( | |
| 433 const uint32_t samples_per_sec) { | |
| 434 NOTREACHED(); | |
| 435 return -1; | |
| 436 } | |
| 437 | |
| 438 int32_t WebrtcAudioModule::PlayoutSampleRate(uint32_t* samples_per_sec) const { | |
| 439 NOTREACHED(); | |
| 440 return -1; | |
| 441 } | |
| 442 | |
| 443 int32_t WebrtcAudioModule::ResetAudioDevice() { | |
| 444 NOTREACHED(); | |
| 445 return -1; | |
| 446 } | |
| 447 | |
| 448 int32_t WebrtcAudioModule::SetLoudspeakerStatus(bool enable) { | |
| 449 NOTREACHED(); | |
| 450 return -1; | |
| 451 } | |
| 452 | |
| 453 int32_t WebrtcAudioModule::GetLoudspeakerStatus(bool* enabled) const { | |
| 454 NOTREACHED(); | |
| 455 return -1; | |
| 456 } | |
| 457 | |
| 458 bool WebrtcAudioModule::BuiltInAECIsAvailable() const { | |
| 459 return false; | |
| 460 } | |
| 461 | |
| 462 bool WebrtcAudioModule::BuiltInAGCIsAvailable() const { | |
| 463 return false; | |
| 464 } | |
| 465 | |
| 466 bool WebrtcAudioModule::BuiltInNSIsAvailable() const { | |
| 467 return false; | |
| 468 } | |
| 469 | |
| 470 int32_t WebrtcAudioModule::EnableBuiltInAEC(bool enable) { | |
| 471 NOTREACHED(); | |
| 472 return -1; | |
| 473 } | |
| 474 | |
| 475 int32_t WebrtcAudioModule::EnableBuiltInAGC(bool enable) { | |
| 476 NOTREACHED(); | |
| 477 return -1; | |
| 478 } | |
| 479 | |
| 480 int32_t WebrtcAudioModule::EnableBuiltInNS(bool enable) { | |
| 481 NOTREACHED(); | |
| 482 return -1; | |
| 483 } | |
| 484 | |
| 485 #if defined(WEBRTC_IOS) | |
| 486 int WebrtcAudioModule::GetPlayoutAudioParameters( | |
| 487 AudioParameters* params) const { | |
| 488 NOTREACHED(); | |
| 489 return -1; | |
| 490 } | |
| 491 | |
| 492 int WebrtcAudioModule::GetRecordAudioParameters(AudioParameters* params) const { | |
| 493 } | |
| 494 #endif // WEBRTC_IOS | |
| 495 | |
| 496 void WebrtcAudioModule::StartPlayoutOnAudioThread() { | |
| 497 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | |
| 498 poll_timer_.Start( | |
| 499 FROM_HERE, kPollInterval, | |
| 500 base::Bind(&WebrtcAudioModule::PollFromSource, base::Unretained(this))); | |
| 501 } | |
| 502 | |
| 503 void WebrtcAudioModule::StopPlayoutOnAudioThread() { | |
| 504 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | |
| 505 poll_timer_.Stop(); | |
| 506 } | |
| 507 | |
| 508 void WebrtcAudioModule::PollFromSource() { | |
| 509 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | |
| 510 | |
| 511 base::AutoLock lock(lock_); | |
| 512 if (!audio_transport_) | |
| 513 return; | |
| 514 | |
| 515 for (int i = 0; i < kPollInterval.InMilliseconds() / kFrameLengthMs; i++) { | |
| 516 int64_t elapsed_time_ms = -1; | |
| 517 int64_t ntp_time_ms = -1; | |
| 518 char data[kBytesPerSample * kChannels * kSamplesPerFrame]; | |
| 519 audio_transport_->PullRenderData(kBytesPerSample * 8, kSamplingRate, | |
| 520 kChannels, kSamplesPerFrame, data, | |
| 521 &elapsed_time_ms, &ntp_time_ms); | |
| 522 } | |
| 523 } | |
| 524 | |
| 525 } // namespace protocol | |
| 526 } // namespace remoting | |
| OLD | NEW |