| 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 CHECK(render_view); |
| 56 output_device_->SetSourceRenderView(render_view->routing_id()); | 53 output_device_ = |
| 57 } | 54 AudioDeviceFactory::NewOutputDevice(render_view->routing_id()); |
| 58 | 55 output_device_->Initialize(params_, this); |
| 59 output_device_->Start(); | 56 output_device_->Start(); |
| 60 // Note: Default behavior is to auto-play on start. | 57 // Note: Default behavior is to auto-play on start. |
| 61 } | 58 } |
| 62 | 59 |
| 63 void RendererWebAudioDeviceImpl::stop() { | 60 void RendererWebAudioDeviceImpl::stop() { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); | 61 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 | 62 |
| 66 if (output_device_) { | 63 if (output_device_) { |
| 67 output_device_->Stop(); | 64 output_device_->Stop(); |
| 68 output_device_ = NULL; | 65 output_device_ = NULL; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 web_audio_dest_data, | 98 web_audio_dest_data, |
| 102 dest->frames()); | 99 dest->frames()); |
| 103 } | 100 } |
| 104 } | 101 } |
| 105 | 102 |
| 106 void RendererWebAudioDeviceImpl::OnRenderError() { | 103 void RendererWebAudioDeviceImpl::OnRenderError() { |
| 107 // TODO(crogers): implement error handling. | 104 // TODO(crogers): implement error handling. |
| 108 } | 105 } |
| 109 | 106 |
| 110 } // namespace content | 107 } // namespace content |
| OLD | NEW |