Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / content / renderer / media / webrtc / webrtc_audio_sink_adapter.cc
blob914f704e3f9200aeb7b3e793cd2b6c809e76e75f
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"
10 namespace content {
12 WebRtcAudioSinkAdapter::WebRtcAudioSinkAdapter(
13 webrtc::AudioTrackSinkInterface* sink)
14 : sink_(sink) {
15 DCHECK(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(),
36 16,
37 params_.sample_rate(),
38 audio_bus.channels(),
39 audio_bus.frames());
42 void WebRtcAudioSinkAdapter::OnSetFormat(
43 const media::AudioParameters& params) {
44 DCHECK(params.IsValid());
45 params_ = params;
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