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 "content/renderer/render_view_impl.h" |
| 11 #include "media/audio/audio_output_device.h" |
12 #include "media/base/media_switches.h" | 12 #include "media/base/media_switches.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
15 | 15 |
16 using WebKit::WebAudioDevice; | 16 using WebKit::WebAudioDevice; |
17 using WebKit::WebFrame; | 17 using WebKit::WebFrame; |
18 using WebKit::WebVector; | 18 using WebKit::WebVector; |
19 using WebKit::WebView; | 19 using WebKit::WebView; |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( | 23 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( |
24 const media::AudioParameters& params, | 24 const media::AudioParameters& params, |
25 WebAudioDevice::RenderCallback* callback) | 25 WebAudioDevice::RenderCallback* callback) |
26 : params_(params), | 26 : params_(params), |
27 client_callback_(callback) { | 27 client_callback_(callback) { |
28 DCHECK(client_callback_); | 28 DCHECK(client_callback_); |
29 } | 29 } |
30 | 30 |
31 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { | 31 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { |
32 DCHECK(!output_device_); | 32 DCHECK(!output_device_); |
33 } | 33 } |
34 | 34 |
35 void RendererWebAudioDeviceImpl::start() { | 35 void RendererWebAudioDeviceImpl::start() { |
36 DCHECK(thread_checker_.CalledOnValidThread()); | 36 DCHECK(thread_checker_.CalledOnValidThread()); |
37 | 37 |
38 if (output_device_) | 38 if (output_device_) |
39 return; // Already started. | 39 return; // Already started. |
40 | 40 |
41 output_device_ = AudioDeviceFactory::NewOutputDevice(); | |
42 output_device_->Initialize(params_, this); | |
43 | |
44 // Assumption: This method is being invoked within a V8 call stack. CHECKs | 41 // Assumption: This method is being invoked within a V8 call stack. CHECKs |
45 // will fail in the call to frameForCurrentContext() otherwise. | 42 // will fail in the call to frameForCurrentContext() otherwise. |
46 // | 43 // |
47 // Therefore, we can perform look-ups to determine which RenderView is | 44 // Therefore, we can perform look-ups to determine which RenderView is |
48 // starting the audio device. The reason for all this is because the creator | 45 // starting the audio device. The reason for all this is because the creator |
49 // of the WebAudio objects might not be the actual source of the audio (e.g., | 46 // of the WebAudio objects might not be the actual source of the audio (e.g., |
50 // an extension creates a object that is passed and used within a page). | 47 // an extension creates a object that is passed and used within a page). |
51 WebFrame* const web_frame = WebFrame::frameForCurrentContext(); | 48 WebFrame* const web_frame = WebFrame::frameForCurrentContext(); |
52 WebView* const web_view = web_frame ? web_frame->view() : NULL; | 49 WebView* const web_view = web_frame ? web_frame->view() : NULL; |
53 RenderViewImpl* const render_view = | 50 RenderViewImpl* const render_view = |
54 web_view ? RenderViewImpl::FromWebView(web_view) : NULL; | 51 web_view ? RenderViewImpl::FromWebView(web_view) : NULL; |
55 if (render_view) { | 52 output_device_ = AudioDeviceFactory::NewOutputDevice( |
56 output_device_->SetSourceRenderView(render_view->routing_id()); | 53 render_view ? render_view->routing_id() : MSG_ROUTING_NONE); |
57 } | 54 output_device_->Initialize(params_, this); |
58 | |
59 output_device_->Start(); | 55 output_device_->Start(); |
60 // Note: Default behavior is to auto-play on start. | 56 // Note: Default behavior is to auto-play on start. |
61 } | 57 } |
62 | 58 |
63 void RendererWebAudioDeviceImpl::stop() { | 59 void RendererWebAudioDeviceImpl::stop() { |
64 DCHECK(thread_checker_.CalledOnValidThread()); | 60 DCHECK(thread_checker_.CalledOnValidThread()); |
65 | 61 |
66 if (output_device_) { | 62 if (output_device_) { |
67 output_device_->Stop(); | 63 output_device_->Stop(); |
68 output_device_ = NULL; | 64 output_device_ = NULL; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 web_audio_dest_data, | 97 web_audio_dest_data, |
102 dest->frames()); | 98 dest->frames()); |
103 } | 99 } |
104 } | 100 } |
105 | 101 |
106 void RendererWebAudioDeviceImpl::OnRenderError() { | 102 void RendererWebAudioDeviceImpl::OnRenderError() { |
107 // TODO(crogers): implement error handling. | 103 // TODO(crogers): implement error handling. |
108 } | 104 } |
109 | 105 |
110 } // namespace content | 106 } // namespace content |
OLD | NEW |