cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / renderer / media / media_stream_audio_source.cc
blobdad7699e8501ddf38f3a4f52411fd46dd85dd74f
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"
10 namespace content {
12 namespace {
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;
21 } // namespace
23 MediaStreamAudioSource::MediaStreamAudioSource(
24 int render_frame_id,
25 const StreamDeviceInfo& device_info,
26 const SourceStoppedCallback& stop_callback,
27 PeerConnectionDependencyFactory* factory)
28 : render_view_id_(ToRenderViewId(render_frame_id)),
29 factory_(factory) {
30 SetDeviceInfo(device_info);
31 SetStopCallback(stop_callback);
34 MediaStreamAudioSource::MediaStreamAudioSource()
35 : render_view_id_(-1),
36 factory_(NULL) {
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_,
53 constraints,
54 this)) {
55 // The source failed to start.
56 // UserMediaClientImpl rely on the |stop_callback| to be triggered when
57 // the last track is removed from the source. But in this case, the
58 // source is is not even started. So we need to fail both adding the
59 // track and trigger |stop_callback|.
60 callback.Run(this, MEDIA_DEVICE_TRACK_START_FAILURE, "");
61 StopSource();
62 return;
66 factory_->CreateLocalAudioTrack(track);
67 callback.Run(this, MEDIA_DEVICE_OK, "");
70 } // namespace content