| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" |
| 6 #include "base/bind_helpers.h" |
| 5 #include "base/logging.h" | 7 #include "base/logging.h" |
| 6 #include "content/renderer/media/webrtc/webrtc_audio_sink_adapter.h" | 8 #include "content/renderer/media/webrtc/webrtc_audio_sink_adapter.h" |
| 7 #include "media/base/audio_bus.h" | 9 #include "media/base/audio_bus.h" |
| 8 #include "third_party/webrtc/api/mediastreaminterface.h" | 10 #include "third_party/webrtc/api/mediastreaminterface.h" |
| 9 | 11 |
| 10 namespace content { | 12 namespace content { |
| 11 | 13 |
| 12 WebRtcAudioSinkAdapter::WebRtcAudioSinkAdapter( | 14 WebRtcAudioSinkAdapter::WebRtcAudioSinkAdapter( |
| 13 webrtc::AudioTrackSinkInterface* sink) | 15 webrtc::AudioTrackSinkInterface* sink) |
| 14 : sink_(sink) { | 16 : sink_(sink), |
| 17 rechunker_(base::TimeDelta::FromMilliseconds(10), |
| 18 base::Bind(&WebRtcAudioSinkAdapter::DeliverRechunkedAudio, |
| 19 base::Unretained(this))) { |
| 15 DCHECK(sink); | 20 DCHECK(sink); |
| 16 } | 21 } |
| 17 | 22 |
| 18 WebRtcAudioSinkAdapter::~WebRtcAudioSinkAdapter() { | 23 WebRtcAudioSinkAdapter::~WebRtcAudioSinkAdapter() { |
| 19 } | 24 } |
| 20 | 25 |
| 21 bool WebRtcAudioSinkAdapter::IsEqual( | 26 bool WebRtcAudioSinkAdapter::IsEqual( |
| 22 const webrtc::AudioTrackSinkInterface* other) const { | 27 const webrtc::AudioTrackSinkInterface* other) const { |
| 23 return (other == sink_); | 28 return (other == sink_); |
| 24 } | 29 } |
| 25 | 30 |
| 26 void WebRtcAudioSinkAdapter::OnData(const media::AudioBus& audio_bus, | 31 void WebRtcAudioSinkAdapter::OnData(const media::AudioBus& audio_bus, |
| 27 base::TimeTicks estimated_capture_time) { | 32 base::TimeTicks estimated_capture_time) { |
| 28 DCHECK_EQ(audio_bus.frames(), params_.frames_per_buffer()); | 33 // The following will result in zero, one, or multiple synchronous calls to |
| 29 DCHECK_EQ(audio_bus.channels(), params_.channels()); | 34 // DeliverRechunkedAudio(). |
| 35 rechunker_.Push(audio_bus, estimated_capture_time - base::TimeTicks()); |
| 36 } |
| 37 |
| 38 void WebRtcAudioSinkAdapter::DeliverRechunkedAudio( |
| 39 const media::AudioBus& audio_bus, |
| 40 base::TimeDelta timestamp) { |
| 30 // TODO(henrika): Remove this conversion once the interface in libjingle | 41 // TODO(henrika): Remove this conversion once the interface in libjingle |
| 31 // supports float vectors. | 42 // supports float vectors. |
| 32 audio_bus.ToInterleaved(audio_bus.frames(), | 43 audio_bus.ToInterleaved(audio_bus.frames(), |
| 33 sizeof(interleaved_data_[0]), | 44 sizeof(interleaved_data_[0]), |
| 34 interleaved_data_.get()); | 45 interleaved_data_.get()); |
| 46 // TODO(miu): Why doesn't a WebRTC sink care about the reference timestamp? |
| 47 // How is AV sync achieved otherwise? |
| 35 sink_->OnData(interleaved_data_.get(), | 48 sink_->OnData(interleaved_data_.get(), |
| 36 16, | 49 16, |
| 37 params_.sample_rate(), | 50 rechunker_.sample_rate(), |
| 38 audio_bus.channels(), | 51 audio_bus.channels(), |
| 39 audio_bus.frames()); | 52 audio_bus.frames()); |
| 40 } | 53 } |
| 41 | 54 |
| 42 void WebRtcAudioSinkAdapter::OnSetFormat( | 55 void WebRtcAudioSinkAdapter::OnSetFormat(const media::AudioParameters& params) { |
| 43 const media::AudioParameters& params) { | |
| 44 DCHECK(params.IsValid()); | 56 DCHECK(params.IsValid()); |
| 45 params_ = params; | 57 rechunker_.SetSampleRate(params.sample_rate()); |
| 46 const int num_pcm16_data_elements = | 58 const int num_pcm16_data_elements = |
| 47 params_.frames_per_buffer() * params_.channels(); | 59 rechunker_.output_frames() * params.channels(); |
| 48 interleaved_data_.reset(new int16_t[num_pcm16_data_elements]); | 60 interleaved_data_.reset(new int16_t[num_pcm16_data_elements]); |
| 49 } | 61 } |
| 50 | 62 |
| 51 } // namespace content | 63 } // namespace content |
| OLD | NEW |