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