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" | |
21 | 20 |
22 namespace content { | 21 namespace content { |
23 | 22 |
24 struct AudioInputRendererHost::AudioEntry { | 23 struct AudioInputRendererHost::AudioEntry { |
25 AudioEntry(); | 24 AudioEntry(); |
26 ~AudioEntry(); | 25 ~AudioEntry(); |
27 | 26 |
28 // The AudioInputController that manages the audio input stream. | 27 // The AudioInputController that manages the audio input stream. |
29 scoped_refptr<media::AudioInputController> controller; | 28 scoped_refptr<media::AudioInputController> controller; |
30 | 29 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 BrowserThread::IO, | 106 BrowserThread::IO, |
108 FROM_HERE, | 107 FROM_HERE, |
109 base::Bind( | 108 base::Bind( |
110 &AudioInputRendererHost::DoHandleError, | 109 &AudioInputRendererHost::DoHandleError, |
111 this, | 110 this, |
112 make_scoped_refptr(controller), | 111 make_scoped_refptr(controller), |
113 error_code)); | 112 error_code)); |
114 } | 113 } |
115 | 114 |
116 void AudioInputRendererHost::OnData(media::AudioInputController* controller, | 115 void AudioInputRendererHost::OnData(media::AudioInputController* controller, |
117 const media::AudioBus* data) { | 116 const uint8* 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 = | 295 const uint32 segment_size = (sizeof(media::AudioInputBufferParameters) + |
296 (sizeof(media::AudioInputBufferParameters) + | 296 audio_params.GetBytesPerBuffer()); |
297 media::AudioBus::CalculateMemorySize(audio_params)); | |
298 entry->shared_memory_segment_count = config.shared_memory_count; | 297 entry->shared_memory_segment_count = config.shared_memory_count; |
299 | 298 |
300 // Create the shared memory and share it with the renderer process | 299 // Create the shared memory and share it with the renderer process |
301 // using a new SyncWriter object. | 300 // using a new SyncWriter object. |
302 base::CheckedNumeric<uint32> size = segment_size; | 301 base::CheckedNumeric<uint32> size = segment_size; |
303 size *= entry->shared_memory_segment_count; | 302 size *= entry->shared_memory_segment_count; |
304 if (!size.IsValid() || | 303 if (!size.IsValid() || |
305 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) { | 304 !entry->shared_memory.CreateAndMapAnonymous(size.ValueOrDie())) { |
306 // If creation of shared memory failed then send an error message. | 305 // If creation of shared memory failed then send an error message. |
307 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); | 306 SendErrorMessage(stream_id, SHARED_MEMORY_CREATE_FAILED); |
308 return; | 307 return; |
309 } | 308 } |
310 | 309 |
311 scoped_ptr<AudioInputSyncWriter> writer(new AudioInputSyncWriter( | 310 scoped_ptr<AudioInputSyncWriter> writer( |
312 &entry->shared_memory, entry->shared_memory_segment_count, audio_params)); | 311 new AudioInputSyncWriter(&entry->shared_memory, |
| 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 |