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