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

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

Issue 12383016: Merge AssociateStreamWithProducer message into CreateStream message for both audio output and input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 DeleteEntryOnError(entry); 179 DeleteEntryOnError(entry);
180 } 180 }
181 181
182 bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message, 182 bool AudioInputRendererHost::OnMessageReceived(const IPC::Message& message,
183 bool* message_was_ok) { 183 bool* message_was_ok) {
184 bool handled = true; 184 bool handled = true;
185 IPC_BEGIN_MESSAGE_MAP_EX(AudioInputRendererHost, message, *message_was_ok) 185 IPC_BEGIN_MESSAGE_MAP_EX(AudioInputRendererHost, message, *message_was_ok)
186 IPC_MESSAGE_HANDLER(AudioInputHostMsg_StartDevice, OnStartDevice) 186 IPC_MESSAGE_HANDLER(AudioInputHostMsg_StartDevice, OnStartDevice)
187 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CreateStream, OnCreateStream) 187 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CreateStream, OnCreateStream)
188 IPC_MESSAGE_HANDLER(AudioInputHostMsg_AssociateStreamWithConsumer,
189 OnAssociateStreamWithConsumer)
190 IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream) 188 IPC_MESSAGE_HANDLER(AudioInputHostMsg_RecordStream, OnRecordStream)
191 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream) 189 IPC_MESSAGE_HANDLER(AudioInputHostMsg_CloseStream, OnCloseStream)
192 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume) 190 IPC_MESSAGE_HANDLER(AudioInputHostMsg_SetVolume, OnSetVolume)
193 IPC_MESSAGE_UNHANDLED(handled = false) 191 IPC_MESSAGE_UNHANDLED(handled = false)
194 IPC_END_MESSAGE_MAP_EX() 192 IPC_END_MESSAGE_MAP_EX()
195 193
196 return handled; 194 return handled;
197 } 195 }
198 196
199 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) { 197 void AudioInputRendererHost::OnStartDevice(int stream_id, int session_id) {
200 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id=" 198 VLOG(1) << "AudioInputRendererHost::OnStartDevice(stream_id="
201 << stream_id << ", session_id = " << session_id << ")"; 199 << stream_id << ", session_id = " << session_id << ")";
202 200
203 // Add the session entry to the map. 201 // Add the session entry to the map.
204 session_entries_[session_id] = stream_id; 202 session_entries_[session_id] = stream_id;
205 203
206 // Start the device with the session_id. If the device is started 204 // Start the device with the session_id. If the device is started
207 // successfully, OnDeviceStarted() callback will be triggered. 205 // successfully, OnDeviceStarted() callback will be triggered.
208 media_stream_manager_->audio_input_device_manager()->Start(session_id, this); 206 media_stream_manager_->audio_input_device_manager()->Start(session_id, this);
209 } 207 }
210 208
211 void AudioInputRendererHost::OnCreateStream( 209 void AudioInputRendererHost::OnCreateStream(
212 int stream_id, const media::AudioParameters& params, 210 int stream_id, int render_view_id, const media::AudioParameters& params,
213 const std::string& device_id, bool automatic_gain_control) { 211 const std::string& device_id, bool automatic_gain_control) {
214 VLOG(1) << "AudioInputRendererHost::OnCreateStream(stream_id="
215 << stream_id << ")";
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
213
214 DVLOG(1) << "AudioInputRendererHost@" << this
215 << "::OnCreateStream(stream_id=" << stream_id
216 << ", render_view_id=" << render_view_id << ")";
217 DCHECK_LT(0, render_view_id);
DaleCurtis 2013/03/05 23:29:54 Yoda is persona non grata in Chrome style.
miu 2013/03/06 22:36:52 Gtest semantics, I blame. Fixed all of these, I h
218
217 // media::AudioParameters is validated in the deserializer. 219 // media::AudioParameters is validated in the deserializer.
218 if (LookupById(stream_id) != NULL) { 220 if (LookupById(stream_id) != NULL) {
219 SendErrorMessage(stream_id); 221 SendErrorMessage(stream_id);
220 return; 222 return;
221 } 223 }
222 224
223 media::AudioParameters audio_params(params); 225 media::AudioParameters audio_params(params);
224 226
225 if (media_stream_manager_->audio_input_device_manager()-> 227 if (media_stream_manager_->audio_input_device_manager()->
226 ShouldUseFakeDevice()) { 228 ShouldUseFakeDevice()) {
227 audio_params.Reset(media::AudioParameters::AUDIO_FAKE, 229 audio_params.Reset(media::AudioParameters::AUDIO_FAKE,
228 params.channel_layout(), 0, params.sample_rate(), 230 params.channel_layout(), 0, params.sample_rate(),
229 params.bits_per_sample(), params.frames_per_buffer()); 231 params.bits_per_sample(), params.frames_per_buffer());
230 } 232 }
231 233
232 uint32 buffer_size = audio_params.GetBytesPerBuffer(); 234 uint32 buffer_size = audio_params.GetBytesPerBuffer();
233 235
234 // Create a new AudioEntry structure. 236 // Create a new AudioEntry structure.
235 scoped_ptr<AudioEntry> entry(new AudioEntry()); 237 scoped_ptr<AudioEntry> entry(new AudioEntry());
236 238
237 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size; 239 uint32 mem_size = sizeof(media::AudioInputBufferParameters) + buffer_size;
palmer 2013/03/05 21:09:32 This addition could overflow; buffer_size comes fr
DaleCurtis 2013/03/05 23:29:54 This is sanitized in media_param_traits by checkin
238 240
239 // Create the shared memory and share it with the renderer process 241 // Create the shared memory and share it with the renderer process
240 // using a new SyncWriter object. 242 // using a new SyncWriter object.
241 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) { 243 if (!entry->shared_memory.CreateAndMapAnonymous(mem_size)) {
242 // If creation of shared memory failed then send an error message. 244 // If creation of shared memory failed then send an error message.
243 SendErrorMessage(stream_id); 245 SendErrorMessage(stream_id);
244 return; 246 return;
245 } 247 }
246 248
247 scoped_ptr<AudioInputSyncWriter> writer( 249 scoped_ptr<AudioInputSyncWriter> writer(
(...skipping 29 matching lines...) Expand all
277 if (!entry->controller) { 279 if (!entry->controller) {
278 SendErrorMessage(stream_id); 280 SendErrorMessage(stream_id);
279 return; 281 return;
280 } 282 }
281 283
282 // Set the initial AGC state for the audio input stream. Note that, the AGC 284 // Set the initial AGC state for the audio input stream. Note that, the AGC
283 // is only supported in AUDIO_PCM_LOW_LATENCY mode. 285 // is only supported in AUDIO_PCM_LOW_LATENCY mode.
284 if (params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY) 286 if (params.format() == media::AudioParameters::AUDIO_PCM_LOW_LATENCY)
285 entry->controller->SetAutomaticGainControl(automatic_gain_control); 287 entry->controller->SetAutomaticGainControl(automatic_gain_control);
286 288
287 // If we have created the controller successfully create a entry and add it 289 // Since the controller was created successfully, create an entry and add it
288 // to the map. 290 // to the map.
289 entry->stream_id = stream_id; 291 entry->stream_id = stream_id;
290
291 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 292 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
292 } 293 }
293 294
294 void AudioInputRendererHost::OnAssociateStreamWithConsumer(int stream_id,
295 int render_view_id) {
296 // TODO(miu): Will use render_view_id in upcoming change.
297 DVLOG(1) << "AudioInputRendererHost@" << this
298 << "::OnAssociateStreamWithConsumer(stream_id=" << stream_id
299 << ", render_view_id=" << render_view_id << ")";
300 }
301
302 void AudioInputRendererHost::OnRecordStream(int stream_id) { 295 void AudioInputRendererHost::OnRecordStream(int stream_id) {
303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
304 297
305 AudioEntry* entry = LookupById(stream_id); 298 AudioEntry* entry = LookupById(stream_id);
306 if (!entry) { 299 if (!entry) {
307 SendErrorMessage(stream_id); 300 SendErrorMessage(stream_id);
308 return; 301 return;
309 } 302 }
310 303
311 entry->controller->Record(); 304 entry->controller->Record();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 for (SessionEntryMap::iterator it = session_entries_.begin(); 449 for (SessionEntryMap::iterator it = session_entries_.begin();
457 it != session_entries_.end(); ++it) { 450 it != session_entries_.end(); ++it) {
458 if (stream_id == it->second) { 451 if (stream_id == it->second) {
459 return it->first; 452 return it->first;
460 } 453 }
461 } 454 }
462 return 0; 455 return 0;
463 } 456 }
464 457
465 } // namespace content 458 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698