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_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/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/numerics/safe_math.h" | 10 #include "base/numerics/safe_math.h" |
11 #include "base/process/process.h" | 11 #include "base/process/process.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "content/browser/media/capture/web_contents_audio_input_stream.h" | 13 #include "content/browser/media/capture/web_contents_audio_input_stream.h" |
14 #include "content/browser/media/capture/web_contents_capture_util.h" | 14 #include "content/browser/media/capture/web_contents_capture_util.h" |
15 #include "content/browser/media/media_internals.h" | 15 #include "content/browser/media/media_internals.h" |
16 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 16 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
17 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" | 17 #include "content/browser/renderer_host/media/audio_input_sync_writer.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 "media/audio/audio_manager_base.h" | 19 #include "media/audio/audio_manager_base.h" |
| 20 #include "media/base/audio_bus.h" |
| 21 |
| 22 using media::AudioBus; |
20 | 23 |
21 namespace content { | 24 namespace content { |
22 | 25 |
23 struct AudioInputRendererHost::AudioEntry { | 26 struct AudioInputRendererHost::AudioEntry { |
24 AudioEntry(); | 27 AudioEntry(); |
25 ~AudioEntry(); | 28 ~AudioEntry(); |
26 | 29 |
27 // The AudioInputController that manages the audio input stream. | 30 // The AudioInputController that manages the audio input stream. |
28 scoped_refptr<media::AudioInputController> controller; | 31 scoped_refptr<media::AudioInputController> controller; |
29 | 32 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 289 } |
287 | 290 |
288 device_id = info->device.id; | 291 device_id = info->device.id; |
289 device_name = info->device.name; | 292 device_name = info->device.name; |
290 } | 293 } |
291 | 294 |
292 // Create a new AudioEntry structure. | 295 // Create a new AudioEntry structure. |
293 scoped_ptr<AudioEntry> entry(new AudioEntry()); | 296 scoped_ptr<AudioEntry> entry(new AudioEntry()); |
294 | 297 |
295 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + | 298 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + |
296 audio_params.GetBytesPerBuffer()); | 299 AudioBus::CalculateMemorySize(audio_params)); |
297 entry->shared_memory_segment_count = config.shared_memory_count; | 300 entry->shared_memory_segment_count = config.shared_memory_count; |
298 | 301 |
299 // Create the shared memory and share it with the renderer process | 302 // Create the shared memory and share it with the renderer process |
300 // using a new SyncWriter object. | 303 // using a new SyncWriter object. |
301 base::CheckedNumeric<uint32> size = segment_size; | 304 base::CheckedNumeric<uint32> size = segment_size; |
302 size *= entry->shared_memory_segment_count; | 305 size *= entry->shared_memory_segment_count; |
303 if (!size.IsValid() || | 306 if (!size.IsValid() || |
304 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) { | 307 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) { |
305 // If creation of shared memory failed then send an error message. | 308 // If creation of shared memory failed then send an error message. |
306 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); | 309 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); |
307 return; | 310 return; |
308 } | 311 } |
309 | 312 |
310 scoped_ptr<AudioInputSyncWriter> writer( | 313 scoped_ptr<AudioInputSyncWriter> writer(new AudioInputSyncWriter( |
311 new AudioInputSyncWriter(&entry->shared_memory, | 314 &entry->shared_memory, entry->shared_memory_segment_count, audio_params)); |
312 entry->shared_memory_segment_count)); | |
313 | 315 |
314 if (!writer->Init()) { | 316 if (!writer->Init()) { |
315 SendErrorMessage(stream_id, SYNC_WRITER_INIT_FAILED); | 317 SendErrorMessage(stream_id, SYNC_WRITER_INIT_FAILED); |
316 return; | 318 return; |
317 } | 319 } |
318 | 320 |
319 // If we have successfully created the SyncWriter then assign it to the | 321 // If we have successfully created the SyncWriter then assign it to the |
320 // entry and construct an AudioInputController. | 322 // entry and construct an AudioInputController. |
321 entry->writer.reset(writer.release()); | 323 entry->writer.reset(writer.release()); |
322 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { | 324 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 // TODO(hclam): Implement a faster look up method. | 466 // TODO(hclam): Implement a faster look up method. |
465 for (AudioEntryMap::iterator i = audio_entries_.begin(); | 467 for (AudioEntryMap::iterator i = audio_entries_.begin(); |
466 i != audio_entries_.end(); ++i) { | 468 i != audio_entries_.end(); ++i) { |
467 if (controller == i->second->controller.get()) | 469 if (controller == i->second->controller.get()) |
468 return i->second; | 470 return i->second; |
469 } | 471 } |
470 return NULL; | 472 return NULL; |
471 } | 473 } |
472 | 474 |
473 } // namespace content | 475 } // namespace content |
OLD | NEW |