Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / renderer / media_stream_audio_sink.cc
blob507bef0fa29c9e6cdb623e5fbc7f7ce8d497cc3f
1 // Copyright 2013 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 "content/public/renderer/media_stream_audio_sink.h"
7 #include "base/logging.h"
8 #include "content/renderer/media/media_stream_track.h"
9 #include "content/renderer/media/webrtc_local_audio_track.h"
10 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
11 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
13 namespace content {
15 void MediaStreamAudioSink::AddToAudioTrack(
16 MediaStreamAudioSink* sink,
17 const blink::WebMediaStreamTrack& track) {
18 DCHECK(track.source().type() == blink::WebMediaStreamSource::TypeAudio);
19 MediaStreamTrack* native_track = MediaStreamTrack::GetTrack(track);
20 // TODO(xians): Support remote audio track.
21 if (!native_track->is_local_track()) {
22 LOG(ERROR) << "Can't add the sink to a remote audio track";
23 return;
26 WebRtcLocalAudioTrack* audio_track =
27 static_cast<WebRtcLocalAudioTrack*>(native_track);
28 audio_track->AddSink(sink);
31 void MediaStreamAudioSink::RemoveFromAudioTrack(
32 MediaStreamAudioSink* sink,
33 const blink::WebMediaStreamTrack& track) {
34 MediaStreamTrack* native_track = MediaStreamTrack::GetTrack(track);
35 // TODO(xians): Support remote audio track.
36 if (!native_track->is_local_track()) {
37 LOG(ERROR) << "Can't remove the sink from a remote audio track";
38 return;
41 WebRtcLocalAudioTrack* audio_track =
42 static_cast<WebRtcLocalAudioTrack*>(native_track);
43 audio_track->RemoveSink(sink);
46 media::AudioParameters MediaStreamAudioSink::GetFormatFromAudioTrack(
47 const blink::WebMediaStreamTrack& track) {
48 MediaStreamTrack* native_track = MediaStreamTrack::GetTrack(track);
49 if (!native_track->is_local_track()) {
50 LOG(ERROR) << "Can't get format from a remote audio track";
51 return media::AudioParameters();
54 WebRtcLocalAudioTrack* audio_track =
55 static_cast<WebRtcLocalAudioTrack*>(native_track);
56 return audio_track->GetOutputFormat();
59 } // namespace content