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" |
(...skipping 11 matching lines...) Expand all Loading... |
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_.get()); |
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_.get()) |
39 return; // Already started. | 39 return; // Already started. |
40 | 40 |
41 // 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 |
42 // will fail in the call to frameForCurrentContext() otherwise. | 42 // will fail in the call to frameForCurrentContext() otherwise. |
43 // | 43 // |
44 // Therefore, we can perform look-ups to determine which RenderView is | 44 // 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 | 45 // 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., | 46 // 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). | 47 // an extension creates a object that is passed and used within a page). |
48 WebFrame* const web_frame = WebFrame::frameForCurrentContext(); | 48 WebFrame* const web_frame = WebFrame::frameForCurrentContext(); |
49 WebView* const web_view = web_frame ? web_frame->view() : NULL; | 49 WebView* const web_view = web_frame ? web_frame->view() : NULL; |
50 RenderViewImpl* const render_view = | 50 RenderViewImpl* const render_view = |
51 web_view ? RenderViewImpl::FromWebView(web_view) : NULL; | 51 web_view ? RenderViewImpl::FromWebView(web_view) : NULL; |
52 output_device_ = AudioDeviceFactory::NewOutputDevice( | 52 output_device_ = AudioDeviceFactory::NewOutputDevice( |
53 render_view ? render_view->routing_id() : MSG_ROUTING_NONE); | 53 render_view ? render_view->routing_id() : MSG_ROUTING_NONE); |
54 output_device_->Initialize(params_, this); | 54 output_device_->Initialize(params_, this); |
55 output_device_->Start(); | 55 output_device_->Start(); |
56 // Note: Default behavior is to auto-play on start. | 56 // Note: Default behavior is to auto-play on start. |
57 } | 57 } |
58 | 58 |
59 void RendererWebAudioDeviceImpl::stop() { | 59 void RendererWebAudioDeviceImpl::stop() { |
60 DCHECK(thread_checker_.CalledOnValidThread()); | 60 DCHECK(thread_checker_.CalledOnValidThread()); |
61 | 61 |
62 if (output_device_) { | 62 if (output_device_.get()) { |
63 output_device_->Stop(); | 63 output_device_->Stop(); |
64 output_device_ = NULL; | 64 output_device_ = NULL; |
65 } | 65 } |
66 } | 66 } |
67 | 67 |
68 double RendererWebAudioDeviceImpl::sampleRate() { | 68 double RendererWebAudioDeviceImpl::sampleRate() { |
69 return params_.sample_rate(); | 69 return params_.sample_rate(); |
70 } | 70 } |
71 | 71 |
72 int RendererWebAudioDeviceImpl::Render(media::AudioBus* dest, | 72 int RendererWebAudioDeviceImpl::Render(media::AudioBus* dest, |
(...skipping 24 matching lines...) Expand all Loading... |
97 web_audio_dest_data, | 97 web_audio_dest_data, |
98 dest->frames()); | 98 dest->frames()); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void RendererWebAudioDeviceImpl::OnRenderError() { | 102 void RendererWebAudioDeviceImpl::OnRenderError() { |
103 // TODO(crogers): implement error handling. | 103 // TODO(crogers): implement error handling. |
104 } | 104 } |
105 | 105 |
106 } // namespace content | 106 } // namespace content |
OLD | NEW |