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 "content/renderer/media/media_stream_audio_source.h"
7 #include "content/renderer/render_frame_impl.h"
11 MediaStreamAudioSource::MediaStreamAudioSource(
13 const StreamDeviceInfo
& device_info
,
14 const SourceStoppedCallback
& stop_callback
,
15 PeerConnectionDependencyFactory
* factory
)
16 : render_frame_id_(render_frame_id
), factory_(factory
) {
17 SetDeviceInfo(device_info
);
18 SetStopCallback(stop_callback
);
21 MediaStreamAudioSource::MediaStreamAudioSource()
22 : render_frame_id_(-1), factory_(NULL
) {
25 MediaStreamAudioSource::~MediaStreamAudioSource() {}
27 void MediaStreamAudioSource::DoStopSource() {
28 if (audio_capturer_
.get())
29 audio_capturer_
->Stop();
32 void MediaStreamAudioSource::AddTrack(
33 const blink::WebMediaStreamTrack
& track
,
34 const blink::WebMediaConstraints
& constraints
,
35 const ConstraintsCallback
& callback
) {
36 // TODO(xians): Properly implement for audio sources.
37 if (!local_audio_source_
.get()) {
38 if (!factory_
->InitializeMediaStreamAudioSource(render_frame_id_
,
40 // The source failed to start.
41 // UserMediaClientImpl rely on the |stop_callback| to be triggered when
42 // the last track is removed from the source. But in this case, the
43 // source is is not even started. So we need to fail both adding the
44 // track and trigger |stop_callback|.
45 callback
.Run(this, MEDIA_DEVICE_TRACK_START_FAILURE
, "");
51 factory_
->CreateLocalAudioTrack(track
);
52 callback
.Run(this, MEDIA_DEVICE_OK
, "");
55 } // namespace content