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

Side by Side Diff: content/browser/renderer_host/media/audio_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: 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/browser/renderer_host/media/audio_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 DeleteEntryOnError(entry); 233 DeleteEntryOnError(entry);
234 } 234 }
235 235
236 /////////////////////////////////////////////////////////////////////////////// 236 ///////////////////////////////////////////////////////////////////////////////
237 // IPC Messages handler 237 // IPC Messages handler
238 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, 238 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message,
239 bool* message_was_ok) { 239 bool* message_was_ok) {
240 bool handled = true; 240 bool handled = true;
241 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) 241 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok)
242 IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream) 242 IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream)
243 IPC_MESSAGE_HANDLER(AudioHostMsg_AssociateStreamWithProducer,
244 OnAssociateStreamWithProducer)
245 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) 243 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream)
246 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) 244 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream)
247 IPC_MESSAGE_HANDLER(AudioHostMsg_FlushStream, OnFlushStream) 245 IPC_MESSAGE_HANDLER(AudioHostMsg_FlushStream, OnFlushStream)
248 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) 246 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream)
249 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) 247 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume)
250 IPC_MESSAGE_UNHANDLED(handled = false) 248 IPC_MESSAGE_UNHANDLED(handled = false)
251 IPC_END_MESSAGE_MAP_EX() 249 IPC_END_MESSAGE_MAP_EX()
252 250
253 return handled; 251 return handled;
254 } 252 }
255 253
256 void AudioRendererHost::OnCreateStream( 254 void AudioRendererHost::OnCreateStream(
257 int stream_id, const media::AudioParameters& params) { 255 int stream_id, int render_view_id, const media::AudioParameters& params) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
257
258 DVLOG(1) << "AudioRendererHost@" << this
259 << "::OnCreateStream(stream_id=" << stream_id
260 << ", render_view_id=" << render_view_id << ")";
261 DCHECK_LT(0, render_view_id);
DaleCurtis 2013/03/05 23:29:54 Drive your Smart Car elsewhere. http://what-if.xkc
262
259 // media::AudioParameters is validated in the deserializer. 263 // media::AudioParameters is validated in the deserializer.
260 int input_channels = params.input_channels(); 264 int input_channels = params.input_channels();
261 if (input_channels < 0 || 265 if (input_channels < 0 ||
262 input_channels > media::limits::kMaxChannels || 266 input_channels > media::limits::kMaxChannels ||
263 LookupById(stream_id) != NULL) { 267 LookupById(stream_id) != NULL) {
264 SendErrorMessage(stream_id); 268 SendErrorMessage(stream_id);
265 return; 269 return;
266 } 270 }
267 271
268 media::AudioParameters audio_params(params); 272 media::AudioParameters audio_params(params);
269 273
270 // Calculate output and input memory size. 274 // Calculate output and input memory size.
271 int output_memory_size = AudioBus::CalculateMemorySize(audio_params); 275 int output_memory_size = AudioBus::CalculateMemorySize(audio_params);
palmer 2013/03/05 21:09:32 This should be an unsigned type (size_t or uint32)
miu 2013/03/06 22:36:52 I agree with you. But, the style guide generally
palmer 2013/03/06 23:11:59 Yeah, this is an area where the style guide is sim
272 276
273 int frames = audio_params.frames_per_buffer(); 277 int frames = audio_params.frames_per_buffer();
274 int input_memory_size = 278 int input_memory_size =
palmer 2013/03/05 21:09:32 This should be an unsigned type (size_t or uint32)
275 AudioBus::CalculateMemorySize(input_channels, frames); 279 AudioBus::CalculateMemorySize(input_channels, frames);
276 280
277 scoped_ptr<AudioEntry> entry(new AudioEntry()); 281 scoped_ptr<AudioEntry> entry(new AudioEntry());
278 282
279 // Create the shared memory and share with the renderer process. 283 // Create the shared memory and share with the renderer process.
280 // For synchronized I/O (if input_channels > 0) then we allocate 284 // For synchronized I/O (if input_channels > 0) then we allocate
281 // extra memory after the output data for the input data. 285 // extra memory after the output data for the input data.
282 uint32 io_buffer_size = output_memory_size + input_memory_size; 286 uint32 io_buffer_size = output_memory_size + input_memory_size;
palmer 2013/03/05 21:09:32 How do we know this addition won't overflow? |outp
DaleCurtis 2013/03/05 23:29:54 Same AudioParameters verification ensures Calculat
283 287
284 uint32 shared_memory_size = 288 uint32 shared_memory_size =
285 media::TotalSharedMemorySizeInBytes(io_buffer_size); 289 media::TotalSharedMemorySizeInBytes(io_buffer_size);
286 if (!entry->shared_memory.CreateAndMapAnonymous(shared_memory_size)) { 290 if (!entry->shared_memory.CreateAndMapAnonymous(shared_memory_size)) {
287 // If creation of shared memory failed then send an error message. 291 // If creation of shared memory failed then send an error message.
288 SendErrorMessage(stream_id); 292 SendErrorMessage(stream_id);
289 return; 293 return;
290 } 294 }
291 295
292 // Create sync reader and try to initialize it. 296 // Create sync reader and try to initialize it.
293 scoped_ptr<AudioSyncReader> reader( 297 scoped_ptr<AudioSyncReader> reader(
294 new AudioSyncReader(&entry->shared_memory, params, input_channels)); 298 new AudioSyncReader(&entry->shared_memory, params, input_channels));
295 299
296 if (!reader->Init()) { 300 if (!reader->Init()) {
297 SendErrorMessage(stream_id); 301 SendErrorMessage(stream_id);
298 return; 302 return;
299 } 303 }
300 304
301 // If we have successfully created the SyncReader then assign it to the 305 // If we have successfully created the SyncReader then assign it to the
302 // entry and construct an AudioOutputController. 306 // entry and construct an AudioOutputController.
303 entry->reader.reset(reader.release()); 307 entry->reader.reset(reader.release());
304 entry->controller = media::AudioOutputController::Create( 308 entry->controller = media::AudioOutputController::Create(
305 audio_manager_, this, audio_params, entry->reader.get()); 309 audio_manager_, this, audio_params, entry->reader.get());
306 310
307 if (!entry->controller) { 311 if (!entry->controller) {
308 SendErrorMessage(stream_id); 312 SendErrorMessage(stream_id);
309 return; 313 return;
310 } 314 }
311 315
312 // If we have created the controller successfully, create an entry and add it 316 // Since the controller was created successfully, create an entry and add it
313 // to the map. 317 // to the map.
314 entry->stream_id = stream_id; 318 entry->stream_id = stream_id;
319 entry->render_view_id = render_view_id;
320 if (mirroring_manager_) {
321 mirroring_manager_->AddDiverter(
322 render_process_id_, entry->render_view_id, entry->controller);
323 }
315 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 324 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
316 if (media_internals_) 325 if (media_internals_)
317 media_internals_->OnSetAudioStreamStatus(this, stream_id, "created"); 326 media_internals_->OnSetAudioStreamStatus(this, stream_id, "created");
318 } 327 }
319 328
320 void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id,
321 int render_view_id) {
322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
323
324 DVLOG(1) << "AudioRendererHost@" << this
325 << "::OnAssociateStreamWithProducer(stream_id=" << stream_id
326 << ", render_view_id=" << render_view_id << ")";
327
328 AudioEntry* const entry = LookupById(stream_id);
329 if (!entry) {
330 SendErrorMessage(stream_id);
331 return;
332 }
333
334 if (entry->render_view_id == render_view_id)
335 return;
336
337 // TODO(miu): Merge "AssociateWithProducer" message into "CreateStream"
338 // message so AudioRendererHost can assume a simpler "render_view_id is set
339 // once" scheme. http://crbug.com/166779
340 if (mirroring_manager_) {
341 mirroring_manager_->RemoveDiverter(
342 render_process_id_, entry->render_view_id, entry->controller);
343 }
344 entry->render_view_id = render_view_id;
345 if (mirroring_manager_) {
346 mirroring_manager_->AddDiverter(
347 render_process_id_, entry->render_view_id, entry->controller);
348 }
349 }
350
351 void AudioRendererHost::OnPlayStream(int stream_id) { 329 void AudioRendererHost::OnPlayStream(int stream_id) {
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
353 331
354 AudioEntry* entry = LookupById(stream_id); 332 AudioEntry* entry = LookupById(stream_id);
355 if (!entry) { 333 if (!entry) {
356 SendErrorMessage(stream_id); 334 SendErrorMessage(stream_id);
357 return; 335 return;
358 } 336 }
359 337
360 entry->controller->Play(); 338 entry->controller->Play();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 return NULL; 504 return NULL;
527 } 505 }
528 506
529 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( 507 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting(
530 int stream_id) { 508 int stream_id) {
531 AudioEntry* const entry = LookupById(stream_id); 509 AudioEntry* const entry = LookupById(stream_id);
532 return entry ? entry->controller : NULL; 510 return entry ? entry->controller : NULL;
533 } 511 }
534 512
535 } // namespace content 513 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698