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

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 22886005: Switch audio synchronization from sleep() based to select() based. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Split out base/ changes. Created 7 years, 3 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/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/process/process.h" 12 #include "base/process/process.h"
13 #include "content/browser/browser_main_loop.h" 13 #include "content/browser/browser_main_loop.h"
14 #include "content/browser/media/media_internals.h" 14 #include "content/browser/media/media_internals.h"
15 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 15 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
16 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" 16 #include "content/browser/renderer_host/media/audio_mirroring_manager.h"
17 #include "content/browser/renderer_host/media/audio_sync_reader.h" 17 #include "content/browser/renderer_host/media/audio_sync_reader.h"
18 #include "content/browser/renderer_host/media/media_stream_manager.h" 18 #include "content/browser/renderer_host/media/media_stream_manager.h"
19 #include "content/common/media/audio_messages.h" 19 #include "content/common/media/audio_messages.h"
20 #include "content/public/browser/content_browser_client.h" 20 #include "content/public/browser/content_browser_client.h"
21 #include "content/public/browser/media_observer.h" 21 #include "content/public/browser/media_observer.h"
22 #include "content/public/common/content_switches.h" 22 #include "content/public/common/content_switches.h"
23 #include "media/audio/audio_manager_base.h" 23 #include "media/audio/audio_manager_base.h"
24 #include "media/audio/shared_memory_util.h"
25 #include "media/base/audio_bus.h" 24 #include "media/base/audio_bus.h"
26 #include "media/base/limits.h" 25 #include "media/base/limits.h"
27 26
28 using media::AudioBus; 27 using media::AudioBus;
29 28
30 namespace content { 29 namespace content {
31 30
32 class AudioRendererHost::AudioEntry 31 class AudioRendererHost::AudioEntry
33 : public media::AudioOutputController::EventHandler { 32 : public media::AudioOutputController::EventHandler {
34 public: 33 public:
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if (!reader->PrepareForeignSocketHandle(PeerHandle(), 234 if (!reader->PrepareForeignSocketHandle(PeerHandle(),
236 &foreign_socket_handle)) { 235 &foreign_socket_handle)) {
237 ReportErrorAndClose(entry->stream_id()); 236 ReportErrorAndClose(entry->stream_id());
238 return; 237 return;
239 } 238 }
240 239
241 Send(new AudioMsg_NotifyStreamCreated( 240 Send(new AudioMsg_NotifyStreamCreated(
242 entry->stream_id(), 241 entry->stream_id(),
243 foreign_memory_handle, 242 foreign_memory_handle,
244 foreign_socket_handle, 243 foreign_socket_handle,
245 media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); 244 entry->shared_memory()->requested_size()));
246 } 245 }
247 246
248 void AudioRendererHost::DoNotifyAudioPowerLevel(int stream_id, 247 void AudioRendererHost::DoNotifyAudioPowerLevel(int stream_id,
249 float power_dbfs, 248 float power_dbfs,
250 bool clipped) { 249 bool clipped) {
251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
252 251
253 MediaObserver* const media_observer = 252 MediaObserver* const media_observer =
254 GetContentClient()->browser()->GetMediaObserver(); 253 GetContentClient()->browser()->GetMediaObserver();
255 if (media_observer) { 254 if (media_observer) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 << "session_id=" << session_id; 319 << "session_id=" << session_id;
321 return; 320 return;
322 } 321 }
323 322
324 input_device_id = info->device.id; 323 input_device_id = info->device.id;
325 } 324 }
326 325
327 // Calculate output and input memory size. 326 // Calculate output and input memory size.
328 int output_memory_size = AudioBus::CalculateMemorySize(params); 327 int output_memory_size = AudioBus::CalculateMemorySize(params);
329 int frames = params.frames_per_buffer(); 328 int frames = params.frames_per_buffer();
330 int input_memory_size = 329 int input_memory_size = AudioBus::CalculateMemorySize(input_channels, frames);
331 AudioBus::CalculateMemorySize(input_channels, frames);
332 330
333 // Create the shared memory and share with the renderer process. 331 // Create the shared memory and share with the renderer process.
334 // For synchronized I/O (if input_channels > 0) then we allocate 332 // For synchronized I/O (if input_channels > 0) then we allocate
335 // extra memory after the output data for the input data. 333 // extra memory after the output data for the input data.
336 uint32 io_buffer_size = output_memory_size + input_memory_size; 334 uint32 shared_memory_size = output_memory_size + input_memory_size;
337 uint32 shared_memory_size =
338 media::TotalSharedMemorySizeInBytes(io_buffer_size);
339 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 335 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
340 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) { 336 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) {
341 SendErrorMessage(stream_id); 337 SendErrorMessage(stream_id);
342 return; 338 return;
343 } 339 }
344 340
345 scoped_ptr<AudioSyncReader> reader( 341 scoped_ptr<AudioSyncReader> reader(
346 new AudioSyncReader(shared_memory.get(), params, input_channels)); 342 new AudioSyncReader(shared_memory.get(), params, input_channels));
347 if (!reader->Init()) { 343 if (!reader->Init()) {
348 SendErrorMessage(stream_id); 344 SendErrorMessage(stream_id);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 475 }
480 476
481 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { 477 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) {
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
483 479
484 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); 480 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id);
485 return i != audio_entries_.end() ? i->second : NULL; 481 return i != audio_entries_.end() ? i->second : NULL;
486 } 482 }
487 483
488 } // namespace content 484 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698