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
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "content/renderer/media/webrtc/webrtc_audio_sink_adapter.h"
7 #include "media/base/audio_bus.h"
8 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
12 WebRtcAudioSinkAdapter::WebRtcAudioSinkAdapter(
13 webrtc::AudioTrackSinkInterface
* sink
)
18 WebRtcAudioSinkAdapter::~WebRtcAudioSinkAdapter() {
21 bool WebRtcAudioSinkAdapter::IsEqual(
22 const webrtc::AudioTrackSinkInterface
* other
) const {
23 return (other
== sink_
);
26 void WebRtcAudioSinkAdapter::OnData(const media::AudioBus
& audio_bus
,
27 base::TimeTicks estimated_capture_time
) {
28 DCHECK_EQ(audio_bus
.frames(), params_
.frames_per_buffer());
29 DCHECK_EQ(audio_bus
.channels(), params_
.channels());
30 // TODO(henrika): Remove this conversion once the interface in libjingle
31 // supports float vectors.
32 audio_bus
.ToInterleaved(audio_bus
.frames(),
33 sizeof(interleaved_data_
[0]),
34 interleaved_data_
.get());
35 sink_
->OnData(interleaved_data_
.get(),
37 params_
.sample_rate(),
42 void WebRtcAudioSinkAdapter::OnSetFormat(
43 const media::AudioParameters
& params
) {
44 DCHECK(params
.IsValid());
46 const int num_pcm16_data_elements
=
47 params_
.frames_per_buffer() * params_
.channels();
48 interleaved_data_
.reset(new int16
[num_pcm16_data_elements
]);
51 } // namespace content