| 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/process/process.h" | 11 #include "base/process/process.h" |
| 11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 12 #include "content/browser/media/capture/web_contents_audio_input_stream.h" | 13 #include "content/browser/media/capture/web_contents_audio_input_stream.h" |
| 13 #include "content/browser/media/capture/web_contents_capture_util.h" | 14 #include "content/browser/media/capture/web_contents_capture_util.h" |
| 14 #include "content/browser/media/media_internals.h" | 15 #include "content/browser/media/media_internals.h" |
| 15 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 16 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 16 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" | 17 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" |
| 17 #include "content/browser/renderer_host/media/media_stream_manager.h" | 18 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 18 #include "media/audio/audio_manager_base.h" | 19 #include "media/audio/audio_manager_base.h" |
| 19 | 20 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 253 |
| 253 // Create a new AudioEntry structure. | 254 // Create a new AudioEntry structure. |
| 254 scoped_ptr<AudioEntry> entry(new AudioEntry()); | 255 scoped_ptr<AudioEntry> entry(new AudioEntry()); |
| 255 | 256 |
| 256 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + | 257 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + |
| 257 audio_params.GetBytesPerBuffer()); | 258 audio_params.GetBytesPerBuffer()); |
| 258 entry->shared_memory_segment_count = config.shared_memory_count; | 259 entry->shared_memory_segment_count = config.shared_memory_count; |
| 259 | 260 |
| 260 // Create the shared memory and share it with the renderer process | 261 // Create the shared memory and share it with the renderer process |
| 261 // using a new SyncWriter object. | 262 // using a new SyncWriter object. |
| 262 if (!entry->shared_memory.CreateAndMapAnonymous( | 263 base::CheckedNumeric<uint32> size = segment_size; |
| 263 segment_size * entry->shared_memory_segment_count)) { | 264 size *= entry->shared_memory_segment_count; |
| 265 if (!size.IsValid() || |
| 266 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) { |
| 264 // If creation of shared memory failed then send an error message. | 267 // If creation of shared memory failed then send an error message. |
| 265 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); | 268 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); |
| 266 return; | 269 return; |
| 267 } | 270 } |
| 268 | 271 |
| 269 scoped_ptr<AudioInputSyncWriter> writer( | 272 scoped_ptr<AudioInputSyncWriter> writer( |
| 270 new AudioInputSyncWriter(&entry->shared_memory, | 273 new AudioInputSyncWriter(&entry->shared_memory, |
| 271 entry->shared_memory_segment_count)); | 274 entry->shared_memory_segment_count)); |
| 272 | 275 |
| 273 if (!writer->Init()) { | 276 if (!writer->Init()) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 // TODO(hclam): Implement a faster look up method. | 426 // TODO(hclam): Implement a faster look up method. |
| 424 for (AudioEntryMap::iterator i = audio_entries_.begin(); | 427 for (AudioEntryMap::iterator i = audio_entries_.begin(); |
| 425 i != audio_entries_.end(); ++i) { | 428 i != audio_entries_.end(); ++i) { |
| 426 if (controller == i->second->controller.get()) | 429 if (controller == i->second->controller.get()) |
| 427 return i->second; | 430 return i->second; |
| 428 } | 431 } |
| 429 return NULL; | 432 return NULL; |
| 430 } | 433 } |
| 431 | 434 |
| 432 } // namespace content | 435 } // namespace content |
| OLD | NEW |