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

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

Issue 11647012: Improve validation when creating audio streams. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/process.h" 9 #include "base/process.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) 212 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume)
213 IPC_MESSAGE_UNHANDLED(handled = false) 213 IPC_MESSAGE_UNHANDLED(handled = false)
214 IPC_END_MESSAGE_MAP_EX() 214 IPC_END_MESSAGE_MAP_EX()
215 215
216 return handled; 216 return handled;
217 } 217 }
218 218
219 void AudioRendererHost::OnCreateStream( 219 void AudioRendererHost::OnCreateStream(
220 int stream_id, const media::AudioParameters& params, int input_channels) { 220 int stream_id, const media::AudioParameters& params, int input_channels) {
221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
222 DCHECK(LookupById(stream_id) == NULL); 222 // media::AudioParameters is validated in the deserializer.
223 if (input_channels < 0 ||
224 input_channels > media::limits::kMaxChannels ||
225 LookupById(stream_id) != NULL) {
226 SendErrorMessage(stream_id);
227 return;
228 }
223 229
224 media::AudioParameters audio_params(params); 230 media::AudioParameters audio_params(params);
225 uint32 buffer_size = media::AudioBus::CalculateMemorySize(audio_params);
226 DCHECK_GT(buffer_size, 0U);
227 DCHECK_LE(buffer_size,
228 static_cast<uint32>(media::limits::kMaxPacketSizeInBytes));
229
230 DCHECK_GE(input_channels, 0);
231 DCHECK_LT(input_channels, media::limits::kMaxChannels);
232 231
233 // Calculate output and input memory size. 232 // Calculate output and input memory size.
234 int output_memory_size = AudioBus::CalculateMemorySize(audio_params); 233 int output_memory_size = AudioBus::CalculateMemorySize(audio_params);
235 DCHECK_GT(output_memory_size, 0);
236 234
237 int frames = audio_params.frames_per_buffer(); 235 int frames = audio_params.frames_per_buffer();
238 int input_memory_size = 236 int input_memory_size =
239 AudioBus::CalculateMemorySize(input_channels, frames); 237 AudioBus::CalculateMemorySize(input_channels, frames);
240 238
241 DCHECK_GE(input_memory_size, 0);
242
243 scoped_ptr<AudioEntry> entry(new AudioEntry()); 239 scoped_ptr<AudioEntry> entry(new AudioEntry());
244 240
245 // Create the shared memory and share with the renderer process. 241 // Create the shared memory and share with the renderer process.
246 // For synchronized I/O (if input_channels > 0) then we allocate 242 // For synchronized I/O (if input_channels > 0) then we allocate
247 // extra memory after the output data for the input data. 243 // extra memory after the output data for the input data.
248 uint32 io_buffer_size = output_memory_size + input_memory_size; 244 uint32 io_buffer_size = output_memory_size + input_memory_size;
249 245
250 uint32 shared_memory_size = 246 uint32 shared_memory_size =
251 media::TotalSharedMemorySizeInBytes(io_buffer_size); 247 media::TotalSharedMemorySizeInBytes(io_buffer_size);
252 if (!entry->shared_memory.CreateAndMapAnonymous(shared_memory_size)) { 248 if (!entry->shared_memory.CreateAndMapAnonymous(shared_memory_size)) {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 return NULL; 431 return NULL;
436 } 432 }
437 433
438 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( 434 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting(
439 int stream_id) { 435 int stream_id) {
440 AudioEntry* const entry = LookupById(stream_id); 436 AudioEntry* const entry = LookupById(stream_id);
441 return entry ? entry->controller : NULL; 437 return entry ? entry->controller : NULL;
442 } 438 }
443 439
444 } // namespace content 440 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_input_renderer_host.cc ('k') | content/common/media/audio_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698