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

Side by Side Diff: content/browser/renderer_host/media/audio_input_renderer_host.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: Addressed review comments. 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/browser/renderer_host/media/audio_input_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_input_renderer_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/process.h" 9 #include "base/process.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 DeleteEntryOnError(entry); 179 DeleteEntryOnError(entry);
180 } 180 }
181 181
182 bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message, 182 bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message,
183 bool* message_was_ok) { 183 bool* message_was_ok) {
184 bool handled = true; 184 bool handled = true;
185 IPC_BEGIN_MESSAGE_MAP_EX(AudioInputRendererHost, message, *message_was_ok) 185 IPC_BEGIN_MESSAGE_MAP_EX(AudioInputRendererHost, message, *message_was_ok)
186 IPC_MESSAGE_HANDLER(AudioInputHostMsg_StartDevice, OnStartDevice) 186 IPC_MESSAGE_HANDLER(AudioInputHostMsg_StartDevice, OnStartDevice)
187 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CreateStream, OnCreateStream) 187 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CreateStream, OnCreateStream)
188 IPC_MESSAGE_HANDLER(AudioInputHostMsg_AssociateStreamWithConsumer,
189 OnAssociateStreamWithConsumer)
190 IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream) 188 IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream)
191 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream) 189 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream)
192 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume) 190 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume)
193 IPC_MESSAGE_UNHANDLED(handled = false) 191 IPC_MESSAGE_UNHANDLED(handled = false)
194 IPC_END_MESSAGE_MAP_EX() 192 IPC_END_MESSAGE_MAP_EX()
195 193
196 return handled; 194 return handled;
197 } 195 }
198 196
199 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) { 197 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) {
200 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id=" 198 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id="
201 << stream_id << ", session_id = " << session_id << ")"; 199 << stream_id << ", session_id = " << session_id << ")";
202 200
203 // Add the session entry to the map. 201 // Add the session entry to the map.
204 session_entries_[session_id] = stream_id; 202 session_entries_[session_id] = stream_id;
205 203
206 // Start the device with the session_id. If the device is started 204 // Start the device with the session_id. If the device is started
207 // successfully, OnDeviceStarted() callback will be triggered. 205 // successfully, OnDeviceStarted() callback will be triggered.
208 media_stream_manager_->audio_input_device_manager()->Start(session_id, this); 206 media_stream_manager_->audio_input_device_manager()->Start(session_id, this);
209 } 207 }
210 208
211 void AudioInputRendererHost::OnCreateStream( 209 void AudioInputRendererHost::OnCreateStream(
212 int stream_id, const media::AudioParameters& params, 210 int stream_id, int render_view_id, const media::AudioParameters& params,
213 const std::string& device_id, bool automatic_gain_control) { 211 const std::string& device_id, bool automatic_gain_control) {
214 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id="
215 << stream_id << ")";
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
213
214 DVLOG(1) << "AudioInputRendererHost@" << this
215 << "::OnCreateStream(stream_id=" << stream_id
216 << ", render_view_id=" << render_view_id << ")";
217 DCHECK_GT(render_view_id, 0);
218
217 // media::AudioParameters is validated in the deserializer. 219 // media::AudioParameters is validated in the deserializer.
218 if (LookupById(stream_id) != NULL) { 220 if (LookupById(stream_id) != NULL) {
219 SendErrorMessage(stream_id); 221 SendErrorMessage(stream_id);
220 return; 222 return;
221 } 223 }
222 224
223 media::AudioParameters audio_params(params); 225 media::AudioParameters audio_params(params);
224 226
225 if (media_stream_manager_->audio_input_device_manager()-> 227 if (media_stream_manager_->audio_input_device_manager()->
226 ShouldUseFakeDevice()) { 228 ShouldUseFakeDevice()) {
227 audio_params.Reset(media::AudioParameters::AUDIO_FAKE, 229 audio_params.Reset(media::AudioParameters::AUDIO_FAKE,
228 params.channel_layout(), 0, params.sample_rate(), 230 params.channel_layout(), 0, params.sample_rate(),
229 params.bits_per_sample(), params.frames_per_buffer()); 231 params.bits_per_sample(), params.frames_per_buffer());
230 } 232 }
231 233
232 uint32 buffer_size = audio_params.GetBytesPerBuffer();
233
234 // Create a new AudioEntry structure. 234 // Create a new AudioEntry structure.
235 scoped_ptr<AudioEntry> entry(new AudioEntry()); 235 scoped_ptr<AudioEntry> entry(new AudioEntry());
236 236
237 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size;
238
239 // Create the shared memory and share it with the renderer process 237 // Create the shared memory and share it with the renderer process
240 // using a new SyncWriter object. 238 // using a new SyncWriter object.
239 const uint32 mem_size = (sizeof(media::AudioInputBufferParameters) +
240 audio_params.GetBytesPerBuffer());
241 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { 241 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) {
242 // If creation of shared memory failed then send an error message. 242 // If creation of shared memory failed then send an error message.
243 SendErrorMessage(stream_id); 243 SendErrorMessage(stream_id);
244 return; 244 return;
245 } 245 }
246 246
247 scoped_ptr<AudioInputSyncWriter> writer( 247 scoped_ptr<AudioInputSyncWriter> writer(
248 new AudioInputSyncWriter(&entry->shared_memory)); 248 new AudioInputSyncWriter(&entry->shared_memory));
249 249
250 if (!writer->Init()) { 250 if (!writer->Init()) {
(...skipping 26 matching lines...) Expand all
277 if (!entry->controller) { 277 if (!entry->controller) {
278 SendErrorMessage(stream_id); 278 SendErrorMessage(stream_id);
279 return; 279 return;
280 } 280 }
281 281
282 // Set the initial AGC state for the audio input stream. Note that, the AGC 282 // Set the initial AGC state for the audio input stream. Note that, the AGC
283 // is only supported in AUDIO_PCM_LOW_LATENCY mode. 283 // is only supported in AUDIO_PCM_LOW_LATENCY mode.
284 if (params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY) 284 if (params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY)
285 entry->controller->SetAutomaticGainControl(automatic_gain_control); 285 entry->controller->SetAutomaticGainControl(automatic_gain_control);
286 286
287 // If we have created the controller successfully create a entry and add it 287 // Since the controller was created successfully, create an entry and add it
288 // to the map. 288 // to the map.
289 entry->stream_id = stream_id; 289 entry->stream_id = stream_id;
290
291 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 290 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
292 } 291 }
293 292
294 void AudioInputRendererHost::OnAssociateStreamWithConsumer(int stream_id,
295 int render_view_id) {
296 // TODO(miu): Will use render_view_id in upcoming change.
297 DVLOG(1) << "AudioInputRendererHost@" << this
298 << "::OnAssociateStreamWithConsumer(stream_id=" << stream_id
299 << ", render_view_id=" << render_view_id << ")";
300 }
301
302 void AudioInputRendererHost::OnRecordStream(int stream_id) { 293 void AudioInputRendererHost::OnRecordStream(int stream_id) {
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
304 295
305 AudioEntry* entry = LookupById(stream_id); 296 AudioEntry* entry = LookupById(stream_id);
306 if (!entry) { 297 if (!entry) {
307 SendErrorMessage(stream_id); 298 SendErrorMessage(stream_id);
308 return; 299 return;
309 } 300 }
310 301
311 entry->controller->Record(); 302 entry->controller->Record();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 for (SessionEntryMap::iterator it = session_entries_.begin(); 447 for (SessionEntryMap::iterator it = session_entries_.begin();
457 it != session_entries_.end(); ++it) { 448 it != session_entries_.end(); ++it) {
458 if (stream_id == it->second) { 449 if (stream_id == it->second) {
459 return it->first; 450 return it->first;
460 } 451 }
461 } 452 }
462 return 0; 453 return 0;
463 } 454 }
464 455
465 } // namespace content 456 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698