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

Side by Side Diff: content/browser/renderer_host/media/audio_input_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
« no previous file with comments | « no previous file | content/browser/renderer_host/media/audio_renderer_host.cc » ('j') | 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/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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // successfully, OnDeviceStarted() callback will be triggered. 205 // successfully, OnDeviceStarted() callback will be triggered.
206 media_stream_manager_->audio_input_device_manager()->Start(session_id, this); 206 media_stream_manager_->audio_input_device_manager()->Start(session_id, this);
207 } 207 }
208 208
209 void AudioInputRendererHost::OnCreateStream( 209 void AudioInputRendererHost::OnCreateStream(
210 int stream_id, const media::AudioParameters& params, 210 int stream_id, const media::AudioParameters& params,
211 const std::string& device_id, bool automatic_gain_control) { 211 const std::string& device_id, bool automatic_gain_control) {
212 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id=" 212 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id="
213 << stream_id << ")"; 213 << stream_id << ")";
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
215 DCHECK(LookupById(stream_id) == NULL); 215 // media::AudioParameters is validated in the deserializer.
216 if (LookupById(stream_id) != NULL) {
217 SendErrorMessage(stream_id);
218 return;
219 }
216 220
217 media::AudioParameters audio_params(params); 221 media::AudioParameters audio_params(params);
218 222
219 if (media_stream_manager_->audio_input_device_manager()-> 223 if (media_stream_manager_->audio_input_device_manager()->
220 ShouldUseFakeDevice()) { 224 ShouldUseFakeDevice()) {
221 audio_params.Reset(media::AudioParameters::AUDIO_FAKE, 225 audio_params.Reset(media::AudioParameters::AUDIO_FAKE,
222 params.channel_layout(), params.sample_rate(), 226 params.channel_layout(), params.sample_rate(),
223 params.bits_per_sample(), params.frames_per_buffer()); 227 params.bits_per_sample(), params.frames_per_buffer());
224 } else if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { 228 } else if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) {
225 audio_params.Reset(media::AudioParameters::AUDIO_VIRTUAL, 229 audio_params.Reset(media::AudioParameters::AUDIO_VIRTUAL,
226 params.channel_layout(), params.sample_rate(), 230 params.channel_layout(), params.sample_rate(),
227 params.bits_per_sample(), params.frames_per_buffer()); 231 params.bits_per_sample(), params.frames_per_buffer());
228 } 232 }
229 233
230 DCHECK_GT(audio_params.frames_per_buffer(), 0);
231 uint32 buffer_size = audio_params.GetBytesPerBuffer(); 234 uint32 buffer_size = audio_params.GetBytesPerBuffer();
232 235
233 // Create a new AudioEntry structure. 236 // Create a new AudioEntry structure.
234 scoped_ptr<AudioEntry> entry(new AudioEntry()); 237 scoped_ptr<AudioEntry> entry(new AudioEntry());
235 238
236 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size; 239 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size;
237 240
238 // Create the shared memory and share it with the renderer process 241 // Create the shared memory and share it with the renderer process
239 // using a new SyncWriter object. 242 // using a new SyncWriter object.
240 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { 243 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 for (SessionEntryMap::iterator it = session_entries_.begin(); 449 for (SessionEntryMap::iterator it = session_entries_.begin();
447 it != session_entries_.end(); ++it) { 450 it != session_entries_.end(); ++it) {
448 if (stream_id == it->second) { 451 if (stream_id == it->second) {
449 return it->first; 452 return it->first;
450 } 453 }
451 } 454 }
452 return 0; 455 return 0;
453 } 456 }
454 457
455 } // namespace content 458 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/media/audio_renderer_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698