| 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     int 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  | 
|   43   // TODO(crogers): remove once we properly handle input device selection. |   45   // TODO(crogers): remove once we properly handle input device selection. | 
|   44   // https://code.google.com/p/chromium/issues/detail?id=147327 |   46   // https://code.google.com/p/chromium/issues/detail?id=147327 | 
|   45   if (CommandLine::ForCurrentProcess()->HasSwitch( |   47   if (CommandLine::ForCurrentProcess()->HasSwitch( | 
|   46       switches::kEnableWebAudioInput)) { |   48       switches::kEnableWebAudioInput)) { | 
|   47     // TODO(crogers): support more than hard-coded stereo: |   49     // TODO(crogers): support more than hard-coded stereo: | 
|   48     // https://code.google.com/p/chromium/issues/detail?id=147326 |   50     // https://code.google.com/p/chromium/issues/detail?id=147326 | 
|   49     output_device_->InitializeIO(params_, 2, this); |   51     output_device_->InitializeIO(params_, 2, this); | 
|   50   } else { |   52   } else { | 
|   51     output_device_->Initialize(params_, this); |   53     output_device_->InitializeIO(params_, input_channels_, this); | 
|   52   } |   54   } | 
|   53  |   55  | 
|   54   // Assumption: This method is being invoked within a V8 call stack.  CHECKs |   56   // Assumption: This method is being invoked within a V8 call stack.  CHECKs | 
|   55   // will fail in the call to frameForCurrentContext() otherwise. |   57   // will fail in the call to frameForCurrentContext() otherwise. | 
|   56   // |   58   // | 
|   57   // Therefore, we can perform look-ups to determine which RenderView is |   59   // 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 |   60   // 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., |   61   // 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). |   62   // an extension creates a object that is passed and used within a page). | 
|   61   WebFrame* const web_frame = WebFrame::frameForCurrentContext(); |   63   WebFrame* const web_frame = WebFrame::frameForCurrentContext(); | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  111                              web_audio_data, |  113                              web_audio_data, | 
|  112                              dest->frames()); |  114                              dest->frames()); | 
|  113   } |  115   } | 
|  114 } |  116 } | 
|  115  |  117  | 
|  116 void RendererWebAudioDeviceImpl::OnRenderError() { |  118 void RendererWebAudioDeviceImpl::OnRenderError() { | 
|  117   // TODO(crogers): implement error handling. |  119   // TODO(crogers): implement error handling. | 
|  118 } |  120 } | 
|  119  |  121  | 
|  120 }  // namespace content |  122 }  // namespace content | 
| OLD | NEW |