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"
8 #include "content/renderer/render_view_impl.h"
13 // TODO(miu): This is a temporary hack until the Chrome audio vertical is
14 // migrated for the Cross-Site Isolation project. http://crbug.com/392596
15 int ToRenderViewId(int render_frame_id
) {
16 RenderFrameImpl
* const frame
=
17 RenderFrameImpl::FromRoutingID(render_frame_id
);
18 RenderViewImpl
* const view
= frame
? frame
->render_view() : NULL
;
19 return view
? view
->GetRoutingID() : -1;
23 MediaStreamAudioSource::MediaStreamAudioSource(
25 const StreamDeviceInfo
& device_info
,
26 const SourceStoppedCallback
& stop_callback
,
27 PeerConnectionDependencyFactory
* factory
)
28 : render_view_id_(ToRenderViewId(render_frame_id
)),
30 SetDeviceInfo(device_info
);
31 SetStopCallback(stop_callback
);
34 MediaStreamAudioSource::MediaStreamAudioSource()
35 : render_view_id_(-1),
39 MediaStreamAudioSource::~MediaStreamAudioSource() {}
41 void MediaStreamAudioSource::DoStopSource() {
42 if (audio_capturer_
.get())
43 audio_capturer_
->Stop();
46 void MediaStreamAudioSource::AddTrack(
47 const blink::WebMediaStreamTrack
& track
,
48 const blink::WebMediaConstraints
& constraints
,
49 const ConstraintsCallback
& callback
) {
50 // TODO(xians): Properly implement for audio sources.
51 if (!local_audio_source_
.get()) {
52 if (!factory_
->InitializeMediaStreamAudioSource(render_view_id_
,
55 // The source failed to start.
56 // MediaStreamImpl rely on the |stop_callback| to be triggered when the
57 // last track is removed from the source. But in this case, the source is
58 // is not even started. So we need to fail both adding the track and
59 // trigger |stop_callback|.
60 callback
.Run(this, MEDIA_DEVICE_TRACK_START_FAILURE
, "");
66 factory_
->CreateLocalAudioTrack(track
);
67 callback
.Run(this, MEDIA_DEVICE_OK
, "");
70 } // namespace content