OLD | NEW |
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 if (!reader->PrepareForeignSocketHandle(PeerHandle(), | 230 if (!reader->PrepareForeignSocketHandle(PeerHandle(), |
232 &foreign_socket_handle)) { | 231 &foreign_socket_handle)) { |
233 ReportErrorAndClose(entry->stream_id()); | 232 ReportErrorAndClose(entry->stream_id()); |
234 return; | 233 return; |
235 } | 234 } |
236 | 235 |
237 Send(new AudioMsg_NotifyStreamCreated( | 236 Send(new AudioMsg_NotifyStreamCreated( |
238 entry->stream_id(), | 237 entry->stream_id(), |
239 foreign_memory_handle, | 238 foreign_memory_handle, |
240 foreign_socket_handle, | 239 foreign_socket_handle, |
241 media::PacketSizeInBytes(entry->shared_memory()->requested_size()))); | 240 entry->shared_memory()->requested_size())); |
242 } | 241 } |
243 | 242 |
244 void AudioRendererHost::DoNotifyAudioPowerLevel(int stream_id, | 243 void AudioRendererHost::DoNotifyAudioPowerLevel(int stream_id, |
245 float power_dbfs, | 244 float power_dbfs, |
246 bool clipped) { | 245 bool clipped) { |
247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
248 | 247 |
249 MediaObserver* const media_observer = | 248 MediaObserver* const media_observer = |
250 GetContentClient()->browser()->GetMediaObserver(); | 249 GetContentClient()->browser()->GetMediaObserver(); |
251 if (media_observer) { | 250 if (media_observer) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 << "session_id=" << session_id; | 315 << "session_id=" << session_id; |
317 return; | 316 return; |
318 } | 317 } |
319 | 318 |
320 input_device_id = info->device.id; | 319 input_device_id = info->device.id; |
321 } | 320 } |
322 | 321 |
323 // Calculate output and input memory size. | 322 // Calculate output and input memory size. |
324 int output_memory_size = AudioBus::CalculateMemorySize(params); | 323 int output_memory_size = AudioBus::CalculateMemorySize(params); |
325 int frames = params.frames_per_buffer(); | 324 int frames = params.frames_per_buffer(); |
326 int input_memory_size = | 325 int input_memory_size = AudioBus::CalculateMemorySize(input_channels, frames); |
327 AudioBus::CalculateMemorySize(input_channels, frames); | |
328 | 326 |
329 // Create the shared memory and share with the renderer process. | 327 // Create the shared memory and share with the renderer process. |
330 // For synchronized I/O (if input_channels > 0) then we allocate | 328 // For synchronized I/O (if input_channels > 0) then we allocate |
331 // extra memory after the output data for the input data. | 329 // extra memory after the output data for the input data. |
332 uint32 io_buffer_size = output_memory_size + input_memory_size; | 330 uint32 shared_memory_size = output_memory_size + input_memory_size; |
333 uint32 shared_memory_size = | |
334 media::TotalSharedMemorySizeInBytes(io_buffer_size); | |
335 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 331 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
336 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) { | 332 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) { |
337 SendErrorMessage(stream_id); | 333 SendErrorMessage(stream_id); |
338 return; | 334 return; |
339 } | 335 } |
340 | 336 |
341 scoped_ptr<AudioSyncReader> reader( | 337 scoped_ptr<AudioSyncReader> reader( |
342 new AudioSyncReader(shared_memory.get(), params, input_channels)); | 338 new AudioSyncReader(shared_memory.get(), params, input_channels)); |
343 if (!reader->Init()) { | 339 if (!reader->Init()) { |
344 SendErrorMessage(stream_id); | 340 SendErrorMessage(stream_id); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 } | 471 } |
476 | 472 |
477 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 473 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
479 | 475 |
480 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); | 476 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); |
481 return i != audio_entries_.end() ? i->second : NULL; | 477 return i != audio_entries_.end() ? i->second : NULL; |
482 } | 478 } |
483 | 479 |
484 } // namespace content | 480 } // namespace content |
OLD | NEW |