| 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" | 10 #include "content/renderer/media/renderer_audio_output_device.h" |
| 11 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.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 unsigned input_channels, |
| 25 WebAudioDevice::RenderCallback* callback) | 26 WebAudioDevice::RenderCallback* callback) |
| 26 : params_(params), | 27 : params_(params), |
| 28 input_channels_(input_channels), |
| 27 client_callback_(callback) { | 29 client_callback_(callback) { |
| 28 DCHECK(client_callback_); | 30 DCHECK(client_callback_); |
| 29 } | 31 } |
| 30 | 32 |
| 31 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { | 33 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { |
| 32 DCHECK(!output_device_); | 34 DCHECK(!output_device_); |
| 33 } | 35 } |
| 34 | 36 |
| 35 void RendererWebAudioDeviceImpl::start() { | 37 void RendererWebAudioDeviceImpl::start() { |
| 36 DCHECK(thread_checker_.CalledOnValidThread()); | 38 DCHECK(thread_checker_.CalledOnValidThread()); |
| 37 | 39 |
| 38 if (output_device_) | 40 if (output_device_) |
| 39 return; // Already started. | 41 return; // Already started. |
| 40 | 42 |
| 41 output_device_ = AudioDeviceFactory::NewOutputDevice(); | 43 output_device_ = AudioDeviceFactory::NewOutputDevice(); |
| 42 | 44 output_device_->InitializeIO(params_, input_channels_, this); |
| 43 // TODO(crogers): remove once we properly handle input device selection. | |
| 44 // https://code.google.com/p/chromium/issues/detail?id=147327 | |
| 45 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 46 switches::kEnableWebAudioInput)) { | |
| 47 // TODO(crogers): support more than hard-coded stereo: | |
| 48 // https://code.google.com/p/chromium/issues/detail?id=147326 | |
| 49 output_device_->InitializeIO(params_, 2, this); | |
| 50 } else { | |
| 51 output_device_->Initialize(params_, this); | |
| 52 } | |
| 53 | 45 |
| 54 // Assumption: This method is being invoked within a V8 call stack. CHECKs | 46 // Assumption: This method is being invoked within a V8 call stack. CHECKs |
| 55 // will fail in the call to frameForCurrentContext() otherwise. | 47 // will fail in the call to frameForCurrentContext() otherwise. |
| 56 // | 48 // |
| 57 // Therefore, we can perform look-ups to determine which RenderView is | 49 // Therefore, we can perform look-ups to determine which RenderView is |
| 58 // starting the audio device. The reason for all this is because the creator | 50 // starting the audio device. The reason for all this is because the creator |
| 59 // of the WebAudio objects might not be the actual source of the audio (e.g., | 51 // of the WebAudio objects might not be the actual source of the audio (e.g., |
| 60 // an extension creates a object that is passed and used within a page). | 52 // an extension creates a object that is passed and used within a page). |
| 61 WebFrame* const web_frame = WebFrame::frameForCurrentContext(); | 53 WebFrame* const web_frame = WebFrame::frameForCurrentContext(); |
| 62 WebView* const web_view = web_frame ? web_frame->view() : NULL; | 54 WebView* const web_view = web_frame ? web_frame->view() : NULL; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 web_audio_data, | 103 web_audio_data, |
| 112 dest->frames()); | 104 dest->frames()); |
| 113 } | 105 } |
| 114 } | 106 } |
| 115 | 107 |
| 116 void RendererWebAudioDeviceImpl::OnRenderError() { | 108 void RendererWebAudioDeviceImpl::OnRenderError() { |
| 117 // TODO(crogers): implement error handling. | 109 // TODO(crogers): implement error handling. |
| 118 } | 110 } |
| 119 | 111 |
| 120 } // namespace content | 112 } // namespace content |
| OLD | NEW |