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

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

Issue 216473002: Replace DCHECK(BrowserThread::CurrentlyOn) with DCHECK_CURRENTLY_ON in content/browser/renderer_hos… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to r260263 Created 6 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/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/process/process.h" 10 #include "base/process/process.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 112
113 void AudioInputRendererHost::OnData(media::AudioInputController* controller, 113 void AudioInputRendererHost::OnData(media::AudioInputController* controller,
114 const uint8* data, 114 const uint8* data,
115 uint32 size) { 115 uint32 size) {
116 NOTREACHED() << "Only low-latency mode is supported."; 116 NOTREACHED() << "Only low-latency mode is supported.";
117 } 117 }
118 118
119 void AudioInputRendererHost::DoCompleteCreation( 119 void AudioInputRendererHost::DoCompleteCreation(
120 media::AudioInputController* controller) { 120 media::AudioInputController* controller) {
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 121 DCHECK_CURRENTLY_ON(BrowserThread::IO);
122 122
123 AudioEntry* entry = LookupByController(controller); 123 AudioEntry* entry = LookupByController(controller);
124 if (!entry) 124 if (!entry)
125 return; 125 return;
126 126
127 if (!PeerHandle()) { 127 if (!PeerHandle()) {
128 NOTREACHED() << "Renderer process handle is invalid."; 128 NOTREACHED() << "Renderer process handle is invalid.";
129 DeleteEntryOnError(entry, INVALID_PEER_HANDLE); 129 DeleteEntryOnError(entry, INVALID_PEER_HANDLE);
130 return; 130 return;
131 } 131 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 166
167 Send(new AudioInputMsg_NotifyStreamCreated(entry->stream_id, 167 Send(new AudioInputMsg_NotifyStreamCreated(entry->stream_id,
168 foreign_memory_handle, foreign_socket_handle, 168 foreign_memory_handle, foreign_socket_handle,
169 entry->shared_memory.requested_size(), 169 entry->shared_memory.requested_size(),
170 entry->shared_memory_segment_count)); 170 entry->shared_memory_segment_count));
171 } 171 }
172 172
173 void AudioInputRendererHost::DoSendRecordingMessage( 173 void AudioInputRendererHost::DoSendRecordingMessage(
174 media::AudioInputController* controller) { 174 media::AudioInputController* controller) {
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 175 DCHECK_CURRENTLY_ON(BrowserThread::IO);
176 // TODO(henrika): See crbug.com/115262 for details on why this method 176 // TODO(henrika): See crbug.com/115262 for details on why this method
177 // should be implemented. 177 // should be implemented.
178 } 178 }
179 179
180 void AudioInputRendererHost::DoHandleError( 180 void AudioInputRendererHost::DoHandleError(
181 media::AudioInputController* controller, 181 media::AudioInputController* controller,
182 media::AudioInputController::ErrorCode error_code) { 182 media::AudioInputController::ErrorCode error_code) {
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 183 DCHECK_CURRENTLY_ON(BrowserThread::IO);
184 MediaStreamManager::SendMessageToNativeLog( 184 MediaStreamManager::SendMessageToNativeLog(
185 base::StringPrintf("AudioInputController error: %d", error_code)); 185 base::StringPrintf("AudioInputController error: %d", error_code));
186 186
187 AudioEntry* entry = LookupByController(controller); 187 AudioEntry* entry = LookupByController(controller);
188 if (!entry) 188 if (!entry)
189 return; 189 return;
190 190
191 audio_log_->OnError(entry->stream_id); 191 audio_log_->OnError(entry->stream_id);
192 DeleteEntryOnError(entry, AUDIO_INPUT_CONTROLLER_ERROR); 192 DeleteEntryOnError(entry, AUDIO_INPUT_CONTROLLER_ERROR);
193 } 193 }
(...skipping 10 matching lines...) Expand all
204 IPC_END_MESSAGE_MAP_EX() 204 IPC_END_MESSAGE_MAP_EX()
205 205
206 return handled; 206 return handled;
207 } 207 }
208 208
209 void AudioInputRendererHost::OnCreateStream( 209 void AudioInputRendererHost::OnCreateStream(
210 int stream_id, 210 int stream_id,
211 int render_view_id, 211 int render_view_id,
212 int session_id, 212 int session_id,
213 const AudioInputHostMsg_CreateStream_Config& config) { 213 const AudioInputHostMsg_CreateStream_Config& config) {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 214 DCHECK_CURRENTLY_ON(BrowserThread::IO);
215 215
216 DVLOG(1) << "AudioInputRendererHost@" << this 216 DVLOG(1) << "AudioInputRendererHost@" << this
217 << "::OnCreateStream(stream_id=" << stream_id 217 << "::OnCreateStream(stream_id=" << stream_id
218 << ", render_view_id=" << render_view_id 218 << ", render_view_id=" << render_view_id
219 << ", session_id=" << session_id << ")"; 219 << ", session_id=" << session_id << ")";
220 DCHECK_GT(render_view_id, 0); 220 DCHECK_GT(render_view_id, 0);
221 221
222 // media::AudioParameters is validated in the deserializer. 222 // media::AudioParameters is validated in the deserializer.
223 if (LookupById(stream_id) != NULL) { 223 if (LookupById(stream_id) != NULL) {
224 SendErrorMessage(stream_id, STREAM_ALREADY_EXISTS); 224 SendErrorMessage(stream_id, STREAM_ALREADY_EXISTS);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // to the map. 316 // to the map.
317 entry->stream_id = stream_id; 317 entry->stream_id = stream_id;
318 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 318 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
319 319
320 MediaStreamManager::SendMessageToNativeLog( 320 MediaStreamManager::SendMessageToNativeLog(
321 "Audio input stream created successfully."); 321 "Audio input stream created successfully.");
322 audio_log_->OnCreated(stream_id, audio_params, device_id); 322 audio_log_->OnCreated(stream_id, audio_params, device_id);
323 } 323 }
324 324
325 void AudioInputRendererHost::OnRecordStream(int stream_id) { 325 void AudioInputRendererHost::OnRecordStream(int stream_id) {
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 326 DCHECK_CURRENTLY_ON(BrowserThread::IO);
327 327
328 AudioEntry* entry = LookupById(stream_id); 328 AudioEntry* entry = LookupById(stream_id);
329 if (!entry) { 329 if (!entry) {
330 SendErrorMessage(stream_id, INVALID_AUDIO_ENTRY); 330 SendErrorMessage(stream_id, INVALID_AUDIO_ENTRY);
331 return; 331 return;
332 } 332 }
333 333
334 entry->controller->Record(); 334 entry->controller->Record();
335 audio_log_->OnStarted(stream_id); 335 audio_log_->OnStarted(stream_id);
336 } 336 }
337 337
338 void AudioInputRendererHost::OnCloseStream(int stream_id) { 338 void AudioInputRendererHost::OnCloseStream(int stream_id) {
339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 339 DCHECK_CURRENTLY_ON(BrowserThread::IO);
340 340
341 AudioEntry* entry = LookupById(stream_id); 341 AudioEntry* entry = LookupById(stream_id);
342 342
343 if (entry) 343 if (entry)
344 CloseAndDeleteStream(entry); 344 CloseAndDeleteStream(entry);
345 } 345 }
346 346
347 void AudioInputRendererHost::OnSetVolume(int stream_id, double volume) { 347 void AudioInputRendererHost::OnSetVolume(int stream_id, double volume) {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 348 DCHECK_CURRENTLY_ON(BrowserThread::IO);
349 349
350 AudioEntry* entry = LookupById(stream_id); 350 AudioEntry* entry = LookupById(stream_id);
351 if (!entry) { 351 if (!entry) {
352 SendErrorMessage(stream_id, INVALID_AUDIO_ENTRY); 352 SendErrorMessage(stream_id, INVALID_AUDIO_ENTRY);
353 return; 353 return;
354 } 354 }
355 355
356 entry->controller->SetVolume(volume); 356 entry->controller->SetVolume(volume);
357 audio_log_->OnSetVolume(stream_id, volume); 357 audio_log_->OnSetVolume(stream_id, volume);
358 } 358 }
359 359
360 void AudioInputRendererHost::SendErrorMessage( 360 void AudioInputRendererHost::SendErrorMessage(
361 int stream_id, ErrorCode error_code) { 361 int stream_id, ErrorCode error_code) {
362 MediaStreamManager::SendMessageToNativeLog( 362 MediaStreamManager::SendMessageToNativeLog(
363 base::StringPrintf("AudioInputRendererHost error: %d", error_code)); 363 base::StringPrintf("AudioInputRendererHost error: %d", error_code));
364 Send(new AudioInputMsg_NotifyStreamStateChanged( 364 Send(new AudioInputMsg_NotifyStreamStateChanged(
365 stream_id, media::AudioInputIPCDelegate::kError)); 365 stream_id, media::AudioInputIPCDelegate::kError));
366 } 366 }
367 367
368 void AudioInputRendererHost::DeleteEntries() { 368 void AudioInputRendererHost::DeleteEntries() {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 369 DCHECK_CURRENTLY_ON(BrowserThread::IO);
370 370
371 for (AudioEntryMap::iterator i = audio_entries_.begin(); 371 for (AudioEntryMap::iterator i = audio_entries_.begin();
372 i != audio_entries_.end(); ++i) { 372 i != audio_entries_.end(); ++i) {
373 CloseAndDeleteStream(i->second); 373 CloseAndDeleteStream(i->second);
374 } 374 }
375 } 375 }
376 376
377 void AudioInputRendererHost::CloseAndDeleteStream(AudioEntry* entry) { 377 void AudioInputRendererHost::CloseAndDeleteStream(AudioEntry* entry) {
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 378 DCHECK_CURRENTLY_ON(BrowserThread::IO);
379 379
380 if (!entry->pending_close) { 380 if (!entry->pending_close) {
381 entry->controller->Close(base::Bind(&AudioInputRendererHost::DeleteEntry, 381 entry->controller->Close(base::Bind(&AudioInputRendererHost::DeleteEntry,
382 this, entry)); 382 this, entry));
383 entry->pending_close = true; 383 entry->pending_close = true;
384 audio_log_->OnClosed(entry->stream_id); 384 audio_log_->OnClosed(entry->stream_id);
385 } 385 }
386 } 386 }
387 387
388 void AudioInputRendererHost::DeleteEntry(AudioEntry* entry) { 388 void AudioInputRendererHost::DeleteEntry(AudioEntry* entry) {
389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 389 DCHECK_CURRENTLY_ON(BrowserThread::IO);
390 390
391 // Delete the entry when this method goes out of scope. 391 // Delete the entry when this method goes out of scope.
392 scoped_ptr<AudioEntry> entry_deleter(entry); 392 scoped_ptr<AudioEntry> entry_deleter(entry);
393 393
394 // Erase the entry from the map. 394 // Erase the entry from the map.
395 audio_entries_.erase(entry->stream_id); 395 audio_entries_.erase(entry->stream_id);
396 } 396 }
397 397
398 void AudioInputRendererHost::DeleteEntryOnError(AudioEntry* entry, 398 void AudioInputRendererHost::DeleteEntryOnError(AudioEntry* entry,
399 ErrorCode error_code) { 399 ErrorCode error_code) {
400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 400 DCHECK_CURRENTLY_ON(BrowserThread::IO);
401 401
402 // Sends the error message first before we close the stream because 402 // Sends the error message first before we close the stream because
403 // |entry| is destroyed in DeleteEntry(). 403 // |entry| is destroyed in DeleteEntry().
404 SendErrorMessage(entry->stream_id, error_code); 404 SendErrorMessage(entry->stream_id, error_code);
405 CloseAndDeleteStream(entry); 405 CloseAndDeleteStream(entry);
406 } 406 }
407 407
408 AudioInputRendererHost::AudioEntry* AudioInputRendererHost::LookupById( 408 AudioInputRendererHost::AudioEntry* AudioInputRendererHost::LookupById(
409 int stream_id) { 409 int stream_id) {
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 410 DCHECK_CURRENTLY_ON(BrowserThread::IO);
411 411
412 AudioEntryMap::iterator i = audio_entries_.find(stream_id); 412 AudioEntryMap::iterator i = audio_entries_.find(stream_id);
413 if (i != audio_entries_.end()) 413 if (i != audio_entries_.end())
414 return i->second; 414 return i->second;
415 return NULL; 415 return NULL;
416 } 416 }
417 417
418 AudioInputRendererHost::AudioEntry* AudioInputRendererHost::LookupByController( 418 AudioInputRendererHost::AudioEntry* AudioInputRendererHost::LookupByController(
419 media::AudioInputController* controller) { 419 media::AudioInputController* controller) {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 420 DCHECK_CURRENTLY_ON(BrowserThread::IO);
421 421
422 // Iterate the map of entries. 422 // Iterate the map of entries.
423 // TODO(hclam): Implement a faster look up method. 423 // TODO(hclam): Implement a faster look up method.
424 for (AudioEntryMap::iterator i = audio_entries_.begin(); 424 for (AudioEntryMap::iterator i = audio_entries_.begin();
425 i != audio_entries_.end(); ++i) { 425 i != audio_entries_.end(); ++i) {
426 if (controller == i->second->controller.get()) 426 if (controller == i->second->controller.get())
427 return i->second; 427 return i->second;
428 } 428 }
429 return NULL; 429 return NULL;
430 } 430 }
431 431
432 } // namespace content 432 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698