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

Side by Side Diff: content/renderer/pepper/pepper_platform_audio_output_impl.cc

Issue 11359196: Associate audio streams with their source/destination RenderView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Plus, removed CalledOnValidThread DCHECK from sampleRate() call since nothing mutates. 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/pepper/pepper_platform_audio_output_impl.h" 5 #include "content/renderer/pepper/pepper_platform_audio_output_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "content/common/child_process.h" 12 #include "content/common/child_process.h"
13 #include "content/common/media/audio_messages.h" 13 #include "content/common/media/audio_messages.h"
14 #include "content/renderer/media/audio_hardware.h" 14 #include "content/renderer/media/audio_hardware.h"
15 #include "content/renderer/media/audio_message_filter.h" 15 #include "content/renderer/media/audio_message_filter.h"
16 #include "content/renderer/render_thread_impl.h" 16 #include "content/renderer/render_thread_impl.h"
17 #include "media/base/media_switches.h" 17 #include "media/base/media_switches.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 // static 21 // static
22 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create( 22 PepperPlatformAudioOutputImpl* PepperPlatformAudioOutputImpl::Create(
23 int sample_rate, 23 int sample_rate,
24 int frames_per_buffer, 24 int frames_per_buffer,
25 int source_render_view_id,
25 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { 26 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) {
26 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output( 27 scoped_refptr<PepperPlatformAudioOutputImpl> audio_output(
27 new PepperPlatformAudioOutputImpl()); 28 new PepperPlatformAudioOutputImpl());
28 if (audio_output->Initialize(sample_rate, frames_per_buffer, client)) { 29 if (audio_output->Initialize(sample_rate, frames_per_buffer,
30 source_render_view_id, client)) {
29 // Balanced by Release invoked in 31 // Balanced by Release invoked in
30 // PepperPlatformAudioOutputImpl::ShutDownOnIOThread(). 32 // PepperPlatformAudioOutputImpl::ShutDownOnIOThread().
31 return audio_output.release(); 33 return audio_output.release();
32 } 34 }
33 return NULL; 35 return NULL;
34 } 36 }
35 37
36 bool PepperPlatformAudioOutputImpl::StartPlayback() { 38 bool PepperPlatformAudioOutputImpl::StartPlayback() {
37 if (ipc_) { 39 if (ipc_) {
38 ChildProcess::current()->io_message_loop()->PostTask( 40 ChildProcess::current()->io_message_loop()->PostTask(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl() 109 PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl()
108 : client_(NULL), 110 : client_(NULL),
109 stream_id_(0), 111 stream_id_(0),
110 main_message_loop_proxy_(base::MessageLoopProxy::current()) { 112 main_message_loop_proxy_(base::MessageLoopProxy::current()) {
111 ipc_ = RenderThreadImpl::current()->audio_message_filter(); 113 ipc_ = RenderThreadImpl::current()->audio_message_filter();
112 } 114 }
113 115
114 bool PepperPlatformAudioOutputImpl::Initialize( 116 bool PepperPlatformAudioOutputImpl::Initialize(
115 int sample_rate, 117 int sample_rate,
116 int frames_per_buffer, 118 int frames_per_buffer,
119 int source_render_view_id,
117 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { 120 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) {
118 DCHECK(client); 121 DCHECK(client);
119 // Make sure we don't call init more than once.
120 DCHECK_EQ(0, stream_id_);
121
122 client_ = client; 122 client_ = client;
123 123
124 media::AudioParameters::Format format; 124 media::AudioParameters::Format format;
125 const int kMaxFramesForLowLatency = 2047; 125 const int kMaxFramesForLowLatency = 2047;
126 126
127 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 127 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
128 if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler)) { 128 if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler)) {
129 // Rely on AudioOutputResampler to handle any inconsistencies between the 129 // Rely on AudioOutputResampler to handle any inconsistencies between the
130 // hardware params required for low latency and the requested params. 130 // hardware params required for low latency and the requested params.
131 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; 131 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY;
132 } else if (sample_rate == GetAudioOutputSampleRate() && 132 } else if (sample_rate == GetAudioOutputSampleRate() &&
133 frames_per_buffer <= kMaxFramesForLowLatency && 133 frames_per_buffer <= kMaxFramesForLowLatency &&
134 frames_per_buffer % content::GetAudioOutputBufferSize() == 0) { 134 frames_per_buffer % content::GetAudioOutputBufferSize() == 0) {
135 // Use the low latency back end if the client request is compatible, and 135 // Use the low latency back end if the client request is compatible, and
136 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. 136 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY.
137 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; 137 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY;
138 } else { 138 } else {
139 format = media::AudioParameters::AUDIO_PCM_LINEAR; 139 format = media::AudioParameters::AUDIO_PCM_LINEAR;
140 } 140 }
141 141
142 media::AudioParameters params(format, media::CHANNEL_LAYOUT_STEREO, 142 media::AudioParameters params(format, media::CHANNEL_LAYOUT_STEREO,
143 sample_rate, 16, frames_per_buffer); 143 sample_rate, 16, frames_per_buffer);
144 144
145 ChildProcess::current()->io_message_loop()->PostTask( 145 ChildProcess::current()->io_message_loop()->PostTask(
146 FROM_HERE, 146 FROM_HERE,
147 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread, 147 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread,
148 this, params)); 148 this, params, source_render_view_id));
149 return true; 149 return true;
150 } 150 }
151 151
152 void PepperPlatformAudioOutputImpl::InitializeOnIOThread( 152 void PepperPlatformAudioOutputImpl::InitializeOnIOThread(
153 const media::AudioParameters& params) { 153 const media::AudioParameters& params, int source_render_view_id) {
154 // Make sure we don't call init more than once.
155 DCHECK_EQ(0, stream_id_);
154 stream_id_ = ipc_->AddDelegate(this); 156 stream_id_ = ipc_->AddDelegate(this);
157 DCHECK_NE(0, stream_id_);
158
155 ipc_->CreateStream(stream_id_, params, 0); 159 ipc_->CreateStream(stream_id_, params, 0);
160 ipc_->AssociateStreamWithProducer(stream_id_, source_render_view_id);
156 } 161 }
157 162
158 void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() { 163 void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() {
159 if (stream_id_) 164 if (stream_id_)
160 ipc_->PlayStream(stream_id_); 165 ipc_->PlayStream(stream_id_);
161 } 166 }
162 167
163 void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() { 168 void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() {
164 if (stream_id_) 169 if (stream_id_)
165 ipc_->PauseStream(stream_id_); 170 ipc_->PauseStream(stream_id_);
166 } 171 }
167 172
168 void PepperPlatformAudioOutputImpl::ShutDownOnIOThread() { 173 void PepperPlatformAudioOutputImpl::ShutDownOnIOThread() {
169 // Make sure we don't call shutdown more than once. 174 // Make sure we don't call shutdown more than once.
170 if (!stream_id_) 175 if (!stream_id_)
171 return; 176 return;
172 177
173 ipc_->CloseStream(stream_id_); 178 ipc_->CloseStream(stream_id_);
174 ipc_->RemoveDelegate(stream_id_); 179 ipc_->RemoveDelegate(stream_id_);
175 stream_id_ = 0; 180 stream_id_ = 0;
176 181
177 Release(); // Release for the delegate, balances out the reference taken in 182 Release(); // Release for the delegate, balances out the reference taken in
178 // PepperPluginDelegateImpl::CreateAudio. 183 // PepperPluginDelegateImpl::CreateAudio.
179 } 184 }
180 185
181 } // namespace content 186 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_platform_audio_output_impl.h ('k') | content/renderer/pepper/pepper_plugin_delegate_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698