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

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

Issue 314713002: Modifies AudioInputCallback::OnData and use media::AudioBus instead of plain byte vector (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 6 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
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/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;
DaleCurtis 2014/06/10 17:03:14 I'd drop this, you don't see much content code doi
henrika (OOO until Aug 14) 2014/06/12 12:00:33 Done.
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 BrowserThread::IO, 109 BrowserThread::IO,
107 FROM_HERE, 110 FROM_HERE,
108 base::Bind( 111 base::Bind(
109 &AudioInputRendererHost::DoHandleError, 112 &AudioInputRendererHost::DoHandleError,
110 this, 113 this,
111 make_scoped_refptr(controller), 114 make_scoped_refptr(controller),
112 error_code)); 115 error_code));
113 } 116 }
114 117
115 void AudioInputRendererHost::OnData(media::AudioInputController* controller, 118 void AudioInputRendererHost::OnData(media::AudioInputController* controller,
116 const uint8* data, 119 const media::AudioBus* data) {
117 uint32 size) {
118 NOTREACHED() << "Only low-latency mode is supported."; 120 NOTREACHED() << "Only low-latency mode is supported.";
119 } 121 }
120 122
121 void AudioInputRendererHost::OnLog(media::AudioInputController* controller, 123 void AudioInputRendererHost::OnLog(media::AudioInputController* controller,
122 const std::string& message) { 124 const std::string& message) {
123 BrowserThread::PostTask(BrowserThread::IO, 125 BrowserThread::PostTask(BrowserThread::IO,
124 FROM_HERE, 126 FROM_HERE,
125 base::Bind(&AudioInputRendererHost::DoLog, 127 base::Bind(&AudioInputRendererHost::DoLog,
126 this, 128 this,
127 make_scoped_refptr(controller), 129 make_scoped_refptr(controller),
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 288 }
287 289
288 device_id = info->device.id; 290 device_id = info->device.id;
289 device_name = info->device.name; 291 device_name = info->device.name;
290 } 292 }
291 293
292 // Create a new AudioEntry structure. 294 // Create a new AudioEntry structure.
293 scoped_ptr<AudioEntry> entry(new AudioEntry()); 295 scoped_ptr<AudioEntry> entry(new AudioEntry());
294 296
295 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + 297 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) +
296 audio_params.GetBytesPerBuffer()); 298 AudioBus::CalculateMemorySize(audio_params));
297 entry->shared_memory_segment_count = config.shared_memory_count; 299 entry->shared_memory_segment_count = config.shared_memory_count;
298 300
299 // Create the shared memory and share it with the renderer process 301 // Create the shared memory and share it with the renderer process
300 // using a new SyncWriter object. 302 // using a new SyncWriter object.
301 base::CheckedNumeric<uint32> size = segment_size; 303 base::CheckedNumeric<uint32> size = segment_size;
302 size *= entry->shared_memory_segment_count; 304 size *= entry->shared_memory_segment_count;
303 if (!size.IsValid() || 305 if (!size.IsValid() ||
304 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) { 306 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) {
305 // If creation of shared memory failed then send an error message. 307 // If creation of shared memory failed then send an error message.
306 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); 308 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED);
307 return; 309 return;
308 } 310 }
309 311
310 scoped_ptr<AudioInputSyncWriter> writer( 312 scoped_ptr<AudioInputSyncWriter> writer(new AudioInputSyncWriter(
311 new AudioInputSyncWriter(&entry->shared_memory, 313 &entry->shared_memory, entry->shared_memory_segment_count, audio_params));
312 entry->shared_memory_segment_count));
313 314
314 if (!writer->Init()) { 315 if (!writer->Init()) {
315 SendErrorMessage(stream_id, SYNC_WRITER_INIT_FAILED); 316 SendErrorMessage(stream_id, SYNC_WRITER_INIT_FAILED);
316 return; 317 return;
317 } 318 }
318 319
319 // If we have successfully created the SyncWriter then assign it to the 320 // If we have successfully created the SyncWriter then assign it to the
320 // entry and construct an AudioInputController. 321 // entry and construct an AudioInputController.
321 entry->writer.reset(writer.release()); 322 entry->writer.reset(writer.release());
322 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { 323 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 // TODO(hclam): Implement a faster look up method. 465 // TODO(hclam): Implement a faster look up method.
465 for (AudioEntryMap::iterator i = audio_entries_.begin(); 466 for (AudioEntryMap::iterator i = audio_entries_.begin();
466 i != audio_entries_.end(); ++i) { 467 i != audio_entries_.end(); ++i) {
467 if (controller == i->second->controller.get()) 468 if (controller == i->second->controller.get())
468 return i->second; 469 return i->second;
469 } 470 }
470 return NULL; 471 return NULL;
471 } 472 }
472 473
473 } // namespace content 474 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698