| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/protocol/webrtc_audio_module.h" | 5 #include "remoting/protocol/webrtc_audio_module.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "base/timer/timer.h" | |
| 12 | 10 |
| 13 namespace remoting { | 11 namespace remoting { |
| 14 namespace protocol { | 12 namespace protocol { |
| 15 | 13 |
| 16 namespace { | 14 namespace { |
| 17 | 15 |
| 18 const int kSamplingRate = 48000; | 16 const int kSamplingRate = 48000; |
| 19 | 17 |
| 20 // Webrtc uses 10ms frames. | 18 // Webrtc uses 10ms frames. |
| 21 const int kFrameLengthMs = 10; | 19 const int kFrameLengthMs = 10; |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 | 495 |
| 498 int WebrtcAudioModule::GetRecordAudioParameters( | 496 int WebrtcAudioModule::GetRecordAudioParameters( |
| 499 webrtc::AudioParameters* params) const { | 497 webrtc::AudioParameters* params) const { |
| 500 NOTREACHED(); | 498 NOTREACHED(); |
| 501 return -1; | 499 return -1; |
| 502 } | 500 } |
| 503 #endif // WEBRTC_IOS | 501 #endif // WEBRTC_IOS |
| 504 | 502 |
| 505 void WebrtcAudioModule::StartPlayoutOnAudioThread() { | 503 void WebrtcAudioModule::StartPlayoutOnAudioThread() { |
| 506 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | 504 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
| 507 poll_timer_ = base::MakeUnique<base::RepeatingTimer>(); | 505 poll_timer_.Start( |
| 508 poll_timer_->Start( | |
| 509 FROM_HERE, kPollInterval, | 506 FROM_HERE, kPollInterval, |
| 510 base::Bind(&WebrtcAudioModule::PollFromSource, base::Unretained(this))); | 507 base::Bind(&WebrtcAudioModule::PollFromSource, base::Unretained(this))); |
| 511 } | 508 } |
| 512 | 509 |
| 513 void WebrtcAudioModule::StopPlayoutOnAudioThread() { | 510 void WebrtcAudioModule::StopPlayoutOnAudioThread() { |
| 514 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | 511 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
| 515 poll_timer_.reset(); | 512 poll_timer_.Stop(); |
| 516 } | 513 } |
| 517 | 514 |
| 518 void WebrtcAudioModule::PollFromSource() { | 515 void WebrtcAudioModule::PollFromSource() { |
| 519 DCHECK(audio_task_runner_->BelongsToCurrentThread()); | 516 DCHECK(audio_task_runner_->BelongsToCurrentThread()); |
| 520 | 517 |
| 521 base::AutoLock lock(lock_); | 518 base::AutoLock lock(lock_); |
| 522 if (!audio_transport_) | 519 if (!audio_transport_) |
| 523 return; | 520 return; |
| 524 | 521 |
| 525 for (int i = 0; i < kPollInterval.InMilliseconds() / kFrameLengthMs; i++) { | 522 for (int i = 0; i < kPollInterval.InMilliseconds() / kFrameLengthMs; i++) { |
| 526 int64_t elapsed_time_ms = -1; | 523 int64_t elapsed_time_ms = -1; |
| 527 int64_t ntp_time_ms = -1; | 524 int64_t ntp_time_ms = -1; |
| 528 char data[kBytesPerSample * kChannels * kSamplesPerFrame]; | 525 char data[kBytesPerSample * kChannels * kSamplesPerFrame]; |
| 529 audio_transport_->PullRenderData(kBytesPerSample * 8, kSamplingRate, | 526 audio_transport_->PullRenderData(kBytesPerSample * 8, kSamplingRate, |
| 530 kChannels, kSamplesPerFrame, data, | 527 kChannels, kSamplesPerFrame, data, |
| 531 &elapsed_time_ms, &ntp_time_ms); | 528 &elapsed_time_ms, &ntp_time_ms); |
| 532 } | 529 } |
| 533 } | 530 } |
| 534 | 531 |
| 535 } // namespace protocol | 532 } // namespace protocol |
| 536 } // namespace remoting | 533 } // namespace remoting |
| OLD | NEW |