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

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

Issue 12383016: Merge AssociateStreamWithProducer message into CreateStream message for both audio output and input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 months 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"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (client_) 90 if (client_)
91 client_->StreamCreated(handle, length, socket_handle); 91 client_->StreamCreated(handle, length, socket_handle);
92 } else { 92 } else {
93 main_message_loop_proxy_->PostTask(FROM_HERE, 93 main_message_loop_proxy_->PostTask(FROM_HERE,
94 base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this, 94 base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this,
95 handle, socket_handle, length)); 95 handle, socket_handle, length));
96 } 96 }
97 } 97 }
98 98
99 void PepperPlatformAudioOutputImpl::OnIPCClosed() { 99 void PepperPlatformAudioOutputImpl::OnIPCClosed() {
100 ipc_ = NULL; 100 ipc_.reset();
101 } 101 }
102 102
103 PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() { 103 PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() {
104 // Make sure we have been shut down. Warning: this will usually happen on 104 // Make sure we have been shut down. Warning: this will usually happen on
105 // the I/O thread! 105 // the I/O thread!
106 DCHECK_EQ(0, stream_id_); 106 DCHECK(!ipc_);
107 DCHECK(!client_); 107 DCHECK(!client_);
108 } 108 }
109 109
110 PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl() 110 PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl()
111 : client_(NULL), 111 : client_(NULL),
112 stream_id_(0),
113 main_message_loop_proxy_(base::MessageLoopProxy::current()) { 112 main_message_loop_proxy_(base::MessageLoopProxy::current()) {
114 ipc_ = RenderThreadImpl::current()->audio_message_filter();
115 } 113 }
116 114
117 bool PepperPlatformAudioOutputImpl::Initialize( 115 bool PepperPlatformAudioOutputImpl::Initialize(
118 int sample_rate, 116 int sample_rate,
119 int frames_per_buffer, 117 int frames_per_buffer,
120 int source_render_view_id, 118 int source_render_view_id,
121 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) { 119 webkit::ppapi::PluginDelegate::PlatformAudioOutputClient* client) {
122 DCHECK(client); 120 DCHECK(client);
123 client_ = client; 121 client_ = client;
124 122
123 ipc_ = AudioMessageFilter::Get()->CreateAudioOutputIPC(source_render_view_id);
124 CHECK(ipc_);
125
125 media::AudioParameters::Format format; 126 media::AudioParameters::Format format;
126 const int kMaxFramesForLowLatency = 2047; 127 const int kMaxFramesForLowLatency = 2047;
127 128
128 media::AudioHardwareConfig* hardware_config = 129 media::AudioHardwareConfig* hardware_config =
129 RenderThreadImpl::current()->GetAudioHardwareConfig(); 130 RenderThreadImpl::current()->GetAudioHardwareConfig();
130 131
131 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 132 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
132 if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler)) { 133 if (!cmd_line->HasSwitch(switches::kDisableAudioOutputResampler)) {
133 // Rely on AudioOutputResampler to handle any inconsistencies between the 134 // Rely on AudioOutputResampler to handle any inconsistencies between the
134 // hardware params required for low latency and the requested params. 135 // hardware params required for low latency and the requested params.
135 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; 136 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY;
136 } else if (sample_rate == hardware_config->GetOutputSampleRate() && 137 } else if (sample_rate == hardware_config->GetOutputSampleRate() &&
137 frames_per_buffer <= kMaxFramesForLowLatency && 138 frames_per_buffer <= kMaxFramesForLowLatency &&
138 frames_per_buffer % hardware_config->GetOutputBufferSize() == 0) { 139 frames_per_buffer % hardware_config->GetOutputBufferSize() == 0) {
139 // Use the low latency back end if the client request is compatible, and 140 // Use the low latency back end if the client request is compatible, and
140 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY. 141 // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY.
141 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY; 142 format = media::AudioParameters::AUDIO_PCM_LOW_LATENCY;
142 } else { 143 } else {
143 format = media::AudioParameters::AUDIO_PCM_LINEAR; 144 format = media::AudioParameters::AUDIO_PCM_LINEAR;
144 } 145 }
145 146
146 media::AudioParameters params(format, media::CHANNEL_LAYOUT_STEREO, 147 media::AudioParameters params(format, media::CHANNEL_LAYOUT_STEREO,
147 sample_rate, 16, frames_per_buffer); 148 sample_rate, 16, frames_per_buffer);
148 149
149 ChildProcess::current()->io_message_loop()->PostTask( 150 ChildProcess::current()->io_message_loop()->PostTask(
150 FROM_HERE, 151 FROM_HERE,
151 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread, 152 base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread,
152 this, params, source_render_view_id)); 153 this, params));
153 return true; 154 return true;
154 } 155 }
155 156
156 void PepperPlatformAudioOutputImpl::InitializeOnIOThread( 157 void PepperPlatformAudioOutputImpl::InitializeOnIOThread(
157 const media::AudioParameters& params, int source_render_view_id) { 158 const media::AudioParameters& params) {
158 // Make sure we don't call init more than once. 159 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
159 DCHECK_EQ(0, stream_id_); 160 BelongsToCurrentThread());
160 stream_id_ = ipc_->AddDelegate(this); 161 if (ipc_)
161 DCHECK_NE(0, stream_id_); 162 ipc_->CreateStream(this, params);
162
163 ipc_->CreateStream(stream_id_, params);
164 ipc_->AssociateStreamWithProducer(stream_id_, source_render_view_id);
165 } 163 }
166 164
167 void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() { 165 void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() {
168 if (stream_id_) 166 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
169 ipc_->PlayStream(stream_id_); 167 BelongsToCurrentThread());
168 if (ipc_)
169 ipc_->PlayStream();
170 } 170 }
171 171
172 void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() { 172 void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() {
173 if (stream_id_) 173 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
174 ipc_->PauseStream(stream_id_); 174 BelongsToCurrentThread());
175 if (ipc_)
176 ipc_->PauseStream();
175 } 177 }
176 178
177 void PepperPlatformAudioOutputImpl::ShutDownOnIOThread() { 179 void PepperPlatformAudioOutputImpl::ShutDownOnIOThread() {
180 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
181 BelongsToCurrentThread());
182
178 // Make sure we don't call shutdown more than once. 183 // Make sure we don't call shutdown more than once.
179 if (!stream_id_) 184 if (!ipc_)
180 return; 185 return;
181 186
182 ipc_->CloseStream(stream_id_); 187 ipc_->CloseStream();
183 ipc_->RemoveDelegate(stream_id_); 188 ipc_.reset();
184 stream_id_ = 0;
185 189
186 Release(); // Release for the delegate, balances out the reference taken in 190 Release(); // Release for the delegate, balances out the reference taken in
187 // PepperPluginDelegateImpl::CreateAudio. 191 // PepperPluginDelegateImpl::CreateAudio.
188 } 192 }
189 193
190 } // namespace content 194 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698