OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/renderer_webaudiodevice_impl.h" | 5 #include "content/renderer/media/renderer_webaudiodevice_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/renderer/media/audio_device_factory.h" | 9 #include "content/renderer/media/audio_device_factory.h" |
10 #include "content/renderer/media/renderer_audio_output_device.h" | |
11 #include "content/renderer/render_view_impl.h" | |
10 #include "media/base/media_switches.h" | 12 #include "media/base/media_switches.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
11 | 15 |
12 using WebKit::WebAudioDevice; | 16 using WebKit::WebAudioDevice; |
17 using WebKit::WebFrame; | |
13 using WebKit::WebVector; | 18 using WebKit::WebVector; |
19 using WebKit::WebView; | |
14 | 20 |
15 namespace content { | 21 namespace content { |
16 | 22 |
17 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( | 23 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( |
18 const media::AudioParameters& params, | 24 const media::AudioParameters& params, |
19 WebAudioDevice::RenderCallback* callback) | 25 WebAudioDevice::RenderCallback* callback) |
20 : is_running_(false), | 26 : is_running_(false), |
21 client_callback_(callback) { | 27 client_callback_(callback) { |
22 audio_device_ = AudioDeviceFactory::NewOutputDevice(); | 28 audio_device_ = AudioDeviceFactory::NewOutputDevice(); |
23 | 29 |
24 // TODO(crogers): remove once we properly handle input device selection. | 30 // TODO(crogers): remove once we properly handle input device selection. |
25 // https://code.google.com/p/chromium/issues/detail?id=147327 | 31 // https://code.google.com/p/chromium/issues/detail?id=147327 |
26 if (CommandLine::ForCurrentProcess()->HasSwitch( | 32 if (CommandLine::ForCurrentProcess()->HasSwitch( |
27 switches::kEnableWebAudioInput)) { | 33 switches::kEnableWebAudioInput)) { |
28 // TODO(crogers): support more than hard-coded stereo: | 34 // TODO(crogers): support more than hard-coded stereo: |
29 // https://code.google.com/p/chromium/issues/detail?id=147326 | 35 // https://code.google.com/p/chromium/issues/detail?id=147326 |
30 audio_device_->InitializeIO(params, 2, this); | 36 audio_device_->InitializeIO(params, 2, this); |
31 } else { | 37 } else { |
32 audio_device_->Initialize(params, this); | 38 audio_device_->Initialize(params, this); |
33 } | 39 } |
34 } | 40 } |
35 | 41 |
36 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { | 42 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { |
37 stop(); | 43 stop(); |
38 } | 44 } |
39 | 45 |
40 void RendererWebAudioDeviceImpl::start() { | 46 void RendererWebAudioDeviceImpl::start() { |
41 if (!is_running_) { | 47 if (is_running_) |
tommi (sloooow) - chröme
2012/11/30 06:51:31
I don't see any thread checks in this file, yet th
miu
2012/12/01 00:40:17
Done. I left thread-checking out of Render/Render
| |
42 audio_device_->Start(); | 48 return; |
43 is_running_ = true; | 49 |
50 // Assumption: This method is being invoked within a V8 call stack. CHECKs | |
51 // will fail in the call to frameForCurrentContext() otherwise. | |
52 // | |
53 // Therefore, we can perform look-ups to determine which RenderView is | |
54 // starting the audio device. The reason for all this is because the creator | |
55 // of the WebAudio objects might not be the actual source of the audio (e.g., | |
56 // an extension creates a object that is passed and used within a page). | |
57 WebFrame* const web_frame = WebFrame::frameForCurrentContext(); | |
58 WebView* const web_view = web_frame ? web_frame->view() : NULL; | |
59 RenderViewImpl* const render_view = | |
60 web_view ? RenderViewImpl::FromWebView(web_view) : NULL; | |
61 if (render_view) { | |
62 audio_device_->SetSourceRenderView(render_view->routing_id()); | |
44 } | 63 } |
64 | |
65 audio_device_->Start(); | |
66 is_running_ = true; | |
45 } | 67 } |
46 | 68 |
47 void RendererWebAudioDeviceImpl::stop() { | 69 void RendererWebAudioDeviceImpl::stop() { |
48 if (is_running_) { | 70 if (is_running_) { |
49 audio_device_->Stop(); | 71 audio_device_->Stop(); |
50 is_running_ = false; | 72 is_running_ = false; |
51 } | 73 } |
52 } | 74 } |
53 | 75 |
54 double RendererWebAudioDeviceImpl::sampleRate() { | 76 double RendererWebAudioDeviceImpl::sampleRate() { |
(...skipping 29 matching lines...) Expand all Loading... | |
84 web_audio_data, | 106 web_audio_data, |
85 dest->frames()); | 107 dest->frames()); |
86 } | 108 } |
87 } | 109 } |
88 | 110 |
89 void RendererWebAudioDeviceImpl::OnRenderError() { | 111 void RendererWebAudioDeviceImpl::OnRenderError() { |
90 // TODO(crogers): implement error handling. | 112 // TODO(crogers): implement error handling. |
91 } | 113 } |
92 | 114 |
93 } // namespace content | 115 } // namespace content |
OLD | NEW |