Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: content/renderer/media/renderer_webaudiodevice_impl.cc

Issue 11359196: Associate audio streams with their source/destination RenderView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Dale's comments. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_message_filter.h"
10 #include "content/renderer/render_thread_impl.h"
11 #include "content/renderer/render_view_impl.h"
10 #include "media/base/media_switches.h" 12 #include "media/base/media_switches.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
11 15
12 using WebKit::WebAudioDevice; 16 using WebKit::WebAudioDevice;
17 using WebKit::WebFrame;
13 using WebKit::WebVector; 18 using WebKit::WebVector;
19 using WebKit::WebView;
14 20
15 namespace content { 21 namespace content {
16 22
17 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl( 23 RendererWebAudioDeviceImpl::RendererWebAudioDeviceImpl(
18 const media::AudioParameters& params, 24 const media::AudioParameters& params,
19 WebAudioDevice::RenderCallback* callback) 25 WebAudioDevice::RenderCallback* callback)
20 : is_running_(false), 26 : is_running_(false),
21 client_callback_(callback) { 27 client_callback_(callback) {
22 audio_device_ = AudioDeviceFactory::NewOutputDevice(); 28 audio_device_ = new media::AudioOutputDevice(
29 RenderThreadImpl::current()->audio_message_filter(),
30 RenderThreadImpl::current()->GetIOMessageLoopProxy());
23 31
24 // TODO(crogers): remove once we properly handle input device selection. 32 // TODO(crogers): remove once we properly handle input device selection.
25 // https://code.google.com/p/chromium/issues/detail?id=147327 33 // https://code.google.com/p/chromium/issues/detail?id=147327
26 if (CommandLine::ForCurrentProcess()->HasSwitch( 34 if (CommandLine::ForCurrentProcess()->HasSwitch(
27 switches::kEnableWebAudioInput)) { 35 switches::kEnableWebAudioInput)) {
28 // TODO(crogers): support more than hard-coded stereo: 36 // TODO(crogers): support more than hard-coded stereo:
29 // https://code.google.com/p/chromium/issues/detail?id=147326 37 // https://code.google.com/p/chromium/issues/detail?id=147326
30 audio_device_->InitializeIO(params, 2, this); 38 audio_device_->InitializeIO(params, 2, this);
31 } else { 39 } else {
32 audio_device_->Initialize(params, this); 40 audio_device_->Initialize(params, this);
33 } 41 }
34 } 42 }
35 43
36 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() { 44 RendererWebAudioDeviceImpl::~RendererWebAudioDeviceImpl() {
37 stop(); 45 stop();
38 } 46 }
39 47
40 void RendererWebAudioDeviceImpl::start() { 48 void RendererWebAudioDeviceImpl::start() {
41 if (!is_running_) { 49 if (!is_running_) {
50 // Assumption: This method is being invoked within a V8 call stack. CHECKs
51 // will fail in the call to frameForCurrentContext() otherwise.
52 //
53 // Therefore, we can perform look-ups to determine which RenderView is
54 // starting the audio device. The reason for all this is because the
55 // creator of the WebAudio objects might not be the actual source of the
56 // audio (e.g., an extension creates a object that is passed and used within
57 // a page).
58 WebFrame* const web_frame = WebFrame::frameForCurrentContext();
59 WebView* const web_view = web_frame ? web_frame->view() : NULL;
60 RenderViewImpl* const render_view =
61 web_view ? RenderViewImpl::FromWebView(web_view) : NULL;
62 if (render_view) {
63 RenderThreadImpl::current()->audio_message_filter()->
64 AssociateStreamWithProducer(audio_device_->stream_id(),
65 render_view->routing_id());
66 }
67
42 audio_device_->Start(); 68 audio_device_->Start();
43 is_running_ = true; 69 is_running_ = true;
44 } 70 }
45 } 71 }
46 72
47 void RendererWebAudioDeviceImpl::stop() { 73 void RendererWebAudioDeviceImpl::stop() {
48 if (is_running_) { 74 if (is_running_) {
49 audio_device_->Stop(); 75 audio_device_->Stop();
50 is_running_ = false; 76 is_running_ = false;
51 } 77 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 web_audio_data, 110 web_audio_data,
85 dest->frames()); 111 dest->frames());
86 } 112 }
87 } 113 }
88 114
89 void RendererWebAudioDeviceImpl::OnRenderError() { 115 void RendererWebAudioDeviceImpl::OnRenderError() {
90 // TODO(crogers): implement error handling. 116 // TODO(crogers): implement error handling.
91 } 117 }
92 118
93 } // namespace content 119 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698