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

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

Issue 241503004: Merge 261549 "Check shared memory size before allocating it." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1847/src/
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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/media_internals.h" 13 #include "content/browser/media/media_internals.h"
13 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 14 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
14 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" 15 #include "content/browser/renderer_host/media/audio_input_sync_writer.h"
15 #include "content/browser/renderer_host/media/media_stream_manager.h" 16 #include "content/browser/renderer_host/media/media_stream_manager.h"
16 #include "content/browser/renderer_host/media/web_contents_audio_input_stream.h" 17 #include "content/browser/renderer_host/media/web_contents_audio_input_stream.h"
17 #include "content/browser/renderer_host/media/web_contents_capture_util.h" 18 #include "content/browser/renderer_host/media/web_contents_capture_util.h"
18 #include "media/audio/audio_manager_base.h" 19 #include "media/audio/audio_manager_base.h"
19 20
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 252
252 // Create a new AudioEntry structure. 253 // Create a new AudioEntry structure.
253 scoped_ptr<AudioEntry> entry(new AudioEntry()); 254 scoped_ptr<AudioEntry> entry(new AudioEntry());
254 255
255 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + 256 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) +
256 audio_params.GetBytesPerBuffer()); 257 audio_params.GetBytesPerBuffer());
257 entry->shared_memory_segment_count = config.shared_memory_count; 258 entry->shared_memory_segment_count = config.shared_memory_count;
258 259
259 // Create the shared memory and share it with the renderer process 260 // Create the shared memory and share it with the renderer process
260 // using a new SyncWriter object. 261 // using a new SyncWriter object.
261 if (!entry->shared_memory.CreateAndMapAnonymous( 262 base::CheckedNumeric<uint32> size = segment_size;
262 segment_size * entry->shared_memory_segment_count)) { 263 size *= entry->shared_memory_segment_count;
264 if (!size.IsValid() ||
265 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) {
263 // If creation of shared memory failed then send an error message. 266 // If creation of shared memory failed then send an error message.
264 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); 267 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED);
265 return; 268 return;
266 } 269 }
267 270
268 scoped_ptr<AudioInputSyncWriter> writer( 271 scoped_ptr<AudioInputSyncWriter> writer(
269 new AudioInputSyncWriter(&entry->shared_memory, 272 new AudioInputSyncWriter(&entry->shared_memory,
270 entry->shared_memory_segment_count)); 273 entry->shared_memory_segment_count));
271 274
272 if (!writer->Init()) { 275 if (!writer->Init()) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 // TODO(hclam): Implement a faster look up method. 425 // TODO(hclam): Implement a faster look up method.
423 for (AudioEntryMap::iterator i = audio_entries_.begin(); 426 for (AudioEntryMap::iterator i = audio_entries_.begin();
424 i != audio_entries_.end(); ++i) { 427 i != audio_entries_.end(); ++i) {
425 if (controller == i->second->controller.get()) 428 if (controller == i->second->controller.get())
426 return i->second; 429 return i->second;
427 } 430 }
428 return NULL; 431 return NULL;
429 } 432 }
430 433
431 } // namespace content 434 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698