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/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" |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 struct AudioInputRendererHost::AudioEntry { | 24 struct AudioInputRendererHost::AudioEntry { |
24 AudioEntry(); | 25 AudioEntry(); |
25 ~AudioEntry(); | 26 ~AudioEntry(); |
26 | 27 |
27 // The AudioInputController that manages the audio input stream. | 28 // The AudioInputController that manages the audio input stream. |
28 scoped_refptr<media::AudioInputController> controller; | 29 scoped_refptr<media::AudioInputController> controller; |
29 | 30 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 BrowserThread::IO, | 107 BrowserThread::IO, |
107 FROM_HERE, | 108 FROM_HERE, |
108 base::Bind( | 109 base::Bind( |
109 &AudioInputRendererHost::DoHandleError, | 110 &AudioInputRendererHost::DoHandleError, |
110 this, | 111 this, |
111 make_scoped_refptr(controller), | 112 make_scoped_refptr(controller), |
112 error_code)); | 113 error_code)); |
113 } | 114 } |
114 | 115 |
115 void AudioInputRendererHost::OnData(media::AudioInputController* controller, | 116 void AudioInputRendererHost::OnData(media::AudioInputController* controller, |
116 const uint8* data, | 117 const media::AudioBus* data) { |
117 uint32 size) { | |
118 NOTREACHED() << "Only low-latency mode is supported."; | 118 NOTREACHED() << "Only low-latency mode is supported."; |
119 } | 119 } |
120 | 120 |
121 void AudioInputRendererHost::OnLog(media::AudioInputController* controller, | 121 void AudioInputRendererHost::OnLog(media::AudioInputController* controller, |
122 const std::string& message) { | 122 const std::string& message) { |
123 BrowserThread::PostTask(BrowserThread::IO, | 123 BrowserThread::PostTask(BrowserThread::IO, |
124 FROM_HERE, | 124 FROM_HERE, |
125 base::Bind(&AudioInputRendererHost::DoLog, | 125 base::Bind(&AudioInputRendererHost::DoLog, |
126 this, | 126 this, |
127 make_scoped_refptr(controller), | 127 make_scoped_refptr(controller), |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 return; | 285 return; |
286 } | 286 } |
287 | 287 |
288 device_id = info->device.id; | 288 device_id = info->device.id; |
289 device_name = info->device.name; | 289 device_name = info->device.name; |
290 } | 290 } |
291 | 291 |
292 // Create a new AudioEntry structure. | 292 // Create a new AudioEntry structure. |
293 scoped_ptr<AudioEntry> entry(new AudioEntry()); | 293 scoped_ptr<AudioEntry> entry(new AudioEntry()); |
294 | 294 |
295 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + | 295 const uint32 segment_size = |
296 audio_params.GetBytesPerBuffer()); | 296 (sizeof(media::AudioInputBufferParameters) + |
| 297 media::AudioBus::CalculateMemorySize(audio_params)); |
297 entry->shared_memory_segment_count = config.shared_memory_count; | 298 entry->shared_memory_segment_count = config.shared_memory_count; |
298 | 299 |
299 // Create the shared memory and share it with the renderer process | 300 // Create the shared memory and share it with the renderer process |
300 // using a new SyncWriter object. | 301 // using a new SyncWriter object. |
301 base::CheckedNumeric<uint32> size = segment_size; | 302 base::CheckedNumeric<uint32> size = segment_size; |
302 size *= entry->shared_memory_segment_count; | 303 size *= entry->shared_memory_segment_count; |
303 if (!size.IsValid() || | 304 if (!size.IsValid() || |
304 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) { | 305 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) { |
305 // If creation of shared memory failed then send an error message. | 306 // If creation of shared memory failed then send an error message. |
306 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); | 307 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); |
307 return; | 308 return; |
308 } | 309 } |
309 | 310 |
310 scoped_ptr<AudioInputSyncWriter> writer( | 311 scoped_ptr<AudioInputSyncWriter> writer(new AudioInputSyncWriter( |
311 new AudioInputSyncWriter(&entry->shared_memory, | 312 &entry->shared_memory, entry->shared_memory_segment_count, audio_params)); |
312 entry->shared_memory_segment_count)); | |
313 | 313 |
314 if (!writer->Init()) { | 314 if (!writer->Init()) { |
315 SendErrorMessage(stream_id, SYNC_WRITER_INIT_FAILED); | 315 SendErrorMessage(stream_id, SYNC_WRITER_INIT_FAILED); |
316 return; | 316 return; |
317 } | 317 } |
318 | 318 |
319 // If we have successfully created the SyncWriter then assign it to the | 319 // If we have successfully created the SyncWriter then assign it to the |
320 // entry and construct an AudioInputController. | 320 // entry and construct an AudioInputController. |
321 entry->writer.reset(writer.release()); | 321 entry->writer.reset(writer.release()); |
322 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { | 322 if (WebContentsCaptureUtil::IsWebContentsDeviceId(device_id)) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 // TODO(hclam): Implement a faster look up method. | 464 // TODO(hclam): Implement a faster look up method. |
465 for (AudioEntryMap::iterator i = audio_entries_.begin(); | 465 for (AudioEntryMap::iterator i = audio_entries_.begin(); |
466 i != audio_entries_.end(); ++i) { | 466 i != audio_entries_.end(); ++i) { |
467 if (controller == i->second->controller.get()) | 467 if (controller == i->second->controller.get()) |
468 return i->second; | 468 return i->second; |
469 } | 469 } |
470 return NULL; | 470 return NULL; |
471 } | 471 } |
472 | 472 |
473 } // namespace content | 473 } // namespace content |
OLD | NEW |