Chromium Code Reviews| 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 fifo_(base::Bind(&WebRtcAudioSinkAdapter::DeliverRebufferedAudio, | |
| 18 base::Unretained(this))) { | |
| 15 DCHECK(sink); | 19 DCHECK(sink); |
| 16 } | 20 } |
| 17 | 21 |
| 18 WebRtcAudioSinkAdapter::~WebRtcAudioSinkAdapter() { | 22 WebRtcAudioSinkAdapter::~WebRtcAudioSinkAdapter() { |
| 19 } | 23 } |
| 20 | 24 |
| 21 bool WebRtcAudioSinkAdapter::IsEqual( | 25 bool WebRtcAudioSinkAdapter::IsEqual( |
| 22 const webrtc::AudioTrackSinkInterface* other) const { | 26 const webrtc::AudioTrackSinkInterface* other) const { |
| 23 return (other == sink_); | 27 return (other == sink_); |
| 24 } | 28 } |
| 25 | 29 |
| 26 void WebRtcAudioSinkAdapter::OnData(const media::AudioBus& audio_bus, | 30 void WebRtcAudioSinkAdapter::OnData(const media::AudioBus& audio_bus, |
| 27 base::TimeTicks estimated_capture_time) { | 31 base::TimeTicks estimated_capture_time) { |
| 28 DCHECK_EQ(audio_bus.frames(), params_.frames_per_buffer()); | 32 // The following will result in zero, one, or multiple synchronous calls to |
| 29 DCHECK_EQ(audio_bus.channels(), params_.channels()); | 33 // DeliverRebufferedAudio(). |
| 34 fifo_.Push(audio_bus); | |
| 35 } | |
| 36 | |
| 37 void WebRtcAudioSinkAdapter::DeliverRebufferedAudio( | |
| 38 const media::AudioBus& audio_bus, | |
| 39 int frame_delay) { | |
| 40 // TODO(miu): Why doesn't a WebRTC sink care about reference time passed to | |
| 41 // OnData(), and the |frame_delay| here? How is AV sync achieved otherwise? | |
| 42 | |
| 30 // TODO(henrika): Remove this conversion once the interface in libjingle | 43 // TODO(henrika): Remove this conversion once the interface in libjingle |
| 31 // supports float vectors. | 44 // supports float vectors. |
| 32 audio_bus.ToInterleaved(audio_bus.frames(), | 45 audio_bus.ToInterleaved(audio_bus.frames(), |
| 33 sizeof(interleaved_data_[0]), | 46 sizeof(interleaved_data_[0]), |
| 34 interleaved_data_.get()); | 47 interleaved_data_.get()); |
| 35 sink_->OnData(interleaved_data_.get(), | 48 sink_->OnData(interleaved_data_.get(), |
| 36 16, | 49 16, |
| 37 params_.sample_rate(), | 50 params_.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( |
| 43 const media::AudioParameters& params) { | 56 const media::AudioParameters& params) { |
| 44 DCHECK(params.IsValid()); | 57 DCHECK(params.IsValid()); |
| 45 params_ = params; | 58 params_ = params; |
| 59 fifo_.Reset(params_.frames_per_buffer()); | |
|
o1ka
2016/04/01 15:11:41
What is the guarantee that there is no race betwee
miu
2016/04/19 00:40:23
Done. (This method moved to the new WebRtcAudioSi
| |
| 46 const int num_pcm16_data_elements = | 60 const int num_pcm16_data_elements = |
| 47 params_.frames_per_buffer() * params_.channels(); | 61 params_.frames_per_buffer() * params_.channels(); |
| 48 interleaved_data_.reset(new int16_t[num_pcm16_data_elements]); | 62 interleaved_data_.reset(new int16_t[num_pcm16_data_elements]); |
| 49 } | 63 } |
| 50 | 64 |
| 51 } // namespace content | 65 } // namespace content |
| OLD | NEW |