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

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

Issue 9968054: Move media/audio files into media namespace (relanding) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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/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"
11 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 11 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
12 #include "content/browser/renderer_host/media/audio_input_sync_writer.h" 12 #include "content/browser/renderer_host/media/audio_input_sync_writer.h"
13 #include "content/browser/renderer_host/media/media_stream_manager.h" 13 #include "content/browser/renderer_host/media/media_stream_manager.h"
14 #include "content/common/media/audio_messages.h" 14 #include "content/common/media/audio_messages.h"
15 15
16 using content::BrowserMessageFilter; 16 using content::BrowserMessageFilter;
17 using content::BrowserThread; 17 using content::BrowserThread;
18 18
19 AudioInputRendererHost::AudioEntry::AudioEntry() 19 AudioInputRendererHost::AudioEntry::AudioEntry()
20 : stream_id(0), 20 : stream_id(0),
21 pending_close(false) { 21 pending_close(false) {
22 } 22 }
23 23
24 AudioInputRendererHost::AudioEntry::~AudioEntry() {} 24 AudioInputRendererHost::AudioEntry::~AudioEntry() {}
25 25
26 AudioInputRendererHost::AudioInputRendererHost( 26 AudioInputRendererHost::AudioInputRendererHost(
27 content::ResourceContext* resource_context, 27 content::ResourceContext* resource_context,
28 AudioManager* audio_manager) 28 media::AudioManager* audio_manager)
29 : resource_context_(resource_context), 29 : resource_context_(resource_context),
30 audio_manager_(audio_manager) { 30 audio_manager_(audio_manager) {
31 } 31 }
32 32
33 AudioInputRendererHost::~AudioInputRendererHost() { 33 AudioInputRendererHost::~AudioInputRendererHost() {
34 DCHECK(audio_entries_.empty()); 34 DCHECK(audio_entries_.empty());
35 } 35 }
36 36
37 void AudioInputRendererHost::OnChannelClosing() { 37 void AudioInputRendererHost::OnChannelClosing() {
38 BrowserMessageFilter::OnChannelClosing(); 38 BrowserMessageFilter::OnChannelClosing();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // mapping shared memory and sharing with the renderer process. 107 // mapping shared memory and sharing with the renderer process.
108 base::SharedMemoryHandle foreign_memory_handle; 108 base::SharedMemoryHandle foreign_memory_handle;
109 if (!entry->shared_memory.ShareToProcess(peer_handle(), 109 if (!entry->shared_memory.ShareToProcess(peer_handle(),
110 &foreign_memory_handle)) { 110 &foreign_memory_handle)) {
111 // If we failed to map and share the shared memory then close the audio 111 // If we failed to map and share the shared memory then close the audio
112 // stream and send an error message. 112 // stream and send an error message.
113 DeleteEntryOnError(entry); 113 DeleteEntryOnError(entry);
114 return; 114 return;
115 } 115 }
116 116
117 AudioInputSyncWriter* writer = 117 media::AudioInputSyncWriter* writer =
118 static_cast<AudioInputSyncWriter*>(entry->writer.get()); 118 static_cast<media::AudioInputSyncWriter*>(entry->writer.get());
119 119
120 #if defined(OS_WIN) 120 #if defined(OS_WIN)
121 base::SyncSocket::Handle foreign_socket_handle; 121 base::SyncSocket::Handle foreign_socket_handle;
122 #else 122 #else
123 base::FileDescriptor foreign_socket_handle; 123 base::FileDescriptor foreign_socket_handle;
124 #endif 124 #endif
125 125
126 // If we failed to prepare the sync socket for the renderer then we fail 126 // If we failed to prepare the sync socket for the renderer then we fail
127 // the construction of audio input stream. 127 // the construction of audio input stream.
128 if (!writer->PrepareForeignSocketHandle(peer_handle(), 128 if (!writer->PrepareForeignSocketHandle(peer_handle(),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 resource_context_, audio_manager_)->audio_input_device_manager(); 190 resource_context_, audio_manager_)->audio_input_device_manager();
191 191
192 // Add the session entry to the map. 192 // Add the session entry to the map.
193 session_entries_[session_id] = stream_id; 193 session_entries_[session_id] = stream_id;
194 194
195 // Start the device with the session_id. If the device is started 195 // Start the device with the session_id. If the device is started
196 // successfully, OnDeviceStarted() callback will be triggered. 196 // successfully, OnDeviceStarted() callback will be triggered.
197 audio_input_man->Start(session_id, this); 197 audio_input_man->Start(session_id, this);
198 } 198 }
199 199
200 void AudioInputRendererHost::OnCreateStream(int stream_id, 200 void AudioInputRendererHost::OnCreateStream(
201 const AudioParameters& params, 201 int stream_id, const media::AudioParameters& params,
202 const std::string& device_id, 202 const std::string& device_id, bool automatic_gain_control) {
203 bool automatic_gain_control) {
204 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id=" 203 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id="
205 << stream_id << ")"; 204 << stream_id << ")";
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
207 DCHECK(LookupById(stream_id) == NULL); 206 DCHECK(LookupById(stream_id) == NULL);
208 207
209 AudioParameters audio_params(params); 208 media::AudioParameters audio_params(params);
210 209
211 DCHECK_GT(audio_params.frames_per_buffer(), 0); 210 DCHECK_GT(audio_params.frames_per_buffer(), 0);
212 uint32 buffer_size = audio_params.GetBytesPerBuffer(); 211 uint32 buffer_size = audio_params.GetBytesPerBuffer();
213 212
214 // Create a new AudioEntry structure. 213 // Create a new AudioEntry structure.
215 scoped_ptr<AudioEntry> entry(new AudioEntry()); 214 scoped_ptr<AudioEntry> entry(new AudioEntry());
216 215
217 uint32 mem_size = sizeof(AudioInputBufferParameters) + buffer_size; 216 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size;
218 217
219 // Create the shared memory and share it with the renderer process 218 // Create the shared memory and share it with the renderer process
220 // using a new SyncWriter object. 219 // using a new SyncWriter object.
221 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { 220 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) {
222 // If creation of shared memory failed then send an error message. 221 // If creation of shared memory failed then send an error message.
223 SendErrorMessage(stream_id); 222 SendErrorMessage(stream_id);
224 return; 223 return;
225 } 224 }
226 225
227 scoped_ptr<AudioInputSyncWriter> writer( 226 scoped_ptr<media::AudioInputSyncWriter> writer(
228 new AudioInputSyncWriter(&entry->shared_memory)); 227 new media::AudioInputSyncWriter(&entry->shared_memory));
229 228
230 if (!writer->Init()) { 229 if (!writer->Init()) {
231 SendErrorMessage(stream_id); 230 SendErrorMessage(stream_id);
232 return; 231 return;
233 } 232 }
234 233
235 // If we have successfully created the SyncWriter then assign it to the 234 // If we have successfully created the SyncWriter then assign it to the
236 // entry and construct an AudioInputController. 235 // entry and construct an AudioInputController.
237 // TODO(henrika): replace CreateLowLatency() with Create() as soon 236 // TODO(henrika): replace CreateLowLatency() with Create() as soon
238 // as satish has ensured that Speech Input also uses the default low- 237 // as satish has ensured that Speech Input also uses the default low-
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
419 418
420 for (SessionEntryMap::iterator it = session_entries_.begin(); 419 for (SessionEntryMap::iterator it = session_entries_.begin();
421 it != session_entries_.end(); ++it) { 420 it != session_entries_.end(); ++it) {
422 if (stream_id == it->second) { 421 if (stream_id == it->second) {
423 return it->first; 422 return it->first;
424 } 423 }
425 } 424 }
426 return 0; 425 return 0;
427 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698