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

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

Issue 9316077: Enable audio/video tag in content_shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 if (!entry->controller) { 285 if (!entry->controller) {
286 SendErrorMessage(stream_id); 286 SendErrorMessage(stream_id);
287 return; 287 return;
288 } 288 }
289 289
290 // If we have created the controller successfully create a entry and add it 290 // If we have created the controller successfully create a entry and add it
291 // to the map. 291 // to the map.
292 entry->stream_id = stream_id; 292 entry->stream_id = stream_id;
293 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 293 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
294 media_observer()->OnSetAudioStreamStatus(this, stream_id, "created"); 294 OnSetAudioStreamStatus(stream_id, "created");
295 } 295 }
296 296
297 void AudioRendererHost::OnPlayStream(int stream_id) { 297 void AudioRendererHost::OnPlayStream(int stream_id) {
298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
299 299
300 AudioEntry* entry = LookupById(stream_id); 300 AudioEntry* entry = LookupById(stream_id);
301 if (!entry) { 301 if (!entry) {
302 SendErrorMessage(stream_id); 302 SendErrorMessage(stream_id);
303 return; 303 return;
304 } 304 }
305 305
306 entry->controller->Play(); 306 entry->controller->Play();
307 media_observer()->OnSetAudioStreamPlaying(this, stream_id, true); 307 OnSetAudioStreamPlaying(stream_id, true);
308 } 308 }
309 309
310 void AudioRendererHost::OnPauseStream(int stream_id) { 310 void AudioRendererHost::OnPauseStream(int stream_id) {
311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
312 312
313 AudioEntry* entry = LookupById(stream_id); 313 AudioEntry* entry = LookupById(stream_id);
314 if (!entry) { 314 if (!entry) {
315 SendErrorMessage(stream_id); 315 SendErrorMessage(stream_id);
316 return; 316 return;
317 } 317 }
318 318
319 entry->controller->Pause(); 319 entry->controller->Pause();
320 media_observer()->OnSetAudioStreamPlaying(this, stream_id, false); 320 OnSetAudioStreamPlaying(stream_id, false);
321 } 321 }
322 322
323 void AudioRendererHost::OnFlushStream(int stream_id) { 323 void AudioRendererHost::OnFlushStream(int stream_id) {
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
325 325
326 AudioEntry* entry = LookupById(stream_id); 326 AudioEntry* entry = LookupById(stream_id);
327 if (!entry) { 327 if (!entry) {
328 SendErrorMessage(stream_id); 328 SendErrorMessage(stream_id);
329 return; 329 return;
330 } 330 }
331 331
332 entry->controller->Flush(); 332 entry->controller->Flush();
333 media_observer()->OnSetAudioStreamStatus(this, stream_id, "flushed"); 333 OnSetAudioStreamStatus(stream_id, "flushed");
334 } 334 }
335 335
336 void AudioRendererHost::OnCloseStream(int stream_id) { 336 void AudioRendererHost::OnCloseStream(int stream_id) {
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
338 338
339 media_observer()->OnSetAudioStreamStatus(this, stream_id, "closed"); 339 OnSetAudioStreamStatus(stream_id, "closed");
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 AudioRendererHost::OnSetVolume(int stream_id, double volume) { 347 void AudioRendererHost::OnSetVolume(int stream_id, double volume) {
348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 348 DCHECK(BrowserThread::CurrentlyOn(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); 352 SendErrorMessage(stream_id);
353 return; 353 return;
354 } 354 }
355 355
356 // Make sure the volume is valid. 356 // Make sure the volume is valid.
357 if (volume < 0 || volume > 1.0) 357 if (volume < 0 || volume > 1.0)
358 return; 358 return;
359 entry->controller->SetVolume(volume); 359 entry->controller->SetVolume(volume);
360 media_observer()->OnSetAudioStreamVolume(this, stream_id, volume); 360 OnSetAudioStreamVolume(stream_id, volume);
361 } 361 }
362 362
363 void AudioRendererHost::OnGetVolume(int stream_id) { 363 void AudioRendererHost::OnGetVolume(int stream_id) {
364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
365 NOTREACHED() << "This message shouldn't be received"; 365 NOTREACHED() << "This message shouldn't be received";
366 } 366 }
367 367
368 void AudioRendererHost::OnNotifyPacketReady(int stream_id, uint32 packet_size) { 368 void AudioRendererHost::OnNotifyPacketReady(int stream_id, uint32 packet_size) {
369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
370 370
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 void AudioRendererHost::DeleteEntry(AudioEntry* entry) { 422 void AudioRendererHost::DeleteEntry(AudioEntry* entry) {
423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
424 424
425 // Delete the entry when this method goes out of scope. 425 // Delete the entry when this method goes out of scope.
426 scoped_ptr<AudioEntry> entry_deleter(entry); 426 scoped_ptr<AudioEntry> entry_deleter(entry);
427 427
428 // Erase the entry identified by |stream_id| from the map. 428 // Erase the entry identified by |stream_id| from the map.
429 audio_entries_.erase(entry->stream_id); 429 audio_entries_.erase(entry->stream_id);
430 430
431 // Notify the media observer. 431 // Notify the media observer.
432 media_observer()->OnDeleteAudioStream(this, entry->stream_id); 432 OnDeleteAudioStream(entry->stream_id);
433 } 433 }
434 434
435 void AudioRendererHost::DeleteEntryOnError(AudioEntry* entry) { 435 void AudioRendererHost::DeleteEntryOnError(AudioEntry* entry) {
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
437 437
438 // Sends the error message first before we close the stream because 438 // Sends the error message first before we close the stream because
439 // |entry| is destroyed in DeleteEntry(). 439 // |entry| is destroyed in DeleteEntry().
440 SendErrorMessage(entry->stream_id); 440 SendErrorMessage(entry->stream_id);
441 441
442 media_observer()->OnSetAudioStreamStatus(this, entry->stream_id, "error"); 442 OnSetAudioStreamStatus(entry->stream_id, "error");
443 CloseAndDeleteStream(entry); 443 CloseAndDeleteStream(entry);
444 } 444 }
445 445
446 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { 446 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) {
447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
448 448
449 AudioEntryMap::iterator i = audio_entries_.find(stream_id); 449 AudioEntryMap::iterator i = audio_entries_.find(stream_id);
450 if (i != audio_entries_.end() && !i->second->pending_close) 450 if (i != audio_entries_.end() && !i->second->pending_close)
451 return i->second; 451 return i->second;
452 return NULL; 452 return NULL;
453 } 453 }
454 454
455 AudioRendererHost::AudioEntry* AudioRendererHost::LookupByController( 455 AudioRendererHost::AudioEntry* AudioRendererHost::LookupByController(
456 media::AudioOutputController* controller) { 456 media::AudioOutputController* controller) {
457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
458 458
459 // Iterate the map of entries. 459 // Iterate the map of entries.
460 // TODO(hclam): Implement a faster look up method. 460 // TODO(hclam): Implement a faster look up method.
461 for (AudioEntryMap::iterator i = audio_entries_.begin(); 461 for (AudioEntryMap::iterator i = audio_entries_.begin();
462 i != audio_entries_.end(); ++i) { 462 i != audio_entries_.end(); ++i) {
463 if (!i->second->pending_close && controller == i->second->controller.get()) 463 if (!i->second->pending_close && controller == i->second->controller.get())
464 return i->second; 464 return i->second;
465 } 465 }
466 return NULL; 466 return NULL;
467 } 467 }
468 468
469 void AudioRendererHost::OnSetAudioStreamPlaying(int stream_id, bool playing) {
470 if (!media_observer())
471 return;
472 media_observer()->OnSetAudioStreamPlaying(this, stream_id, playing);
473 }
474
475 void AudioRendererHost::OnSetAudioStreamStatus(int stream_id,
476 const std::string& status) {
477 if (!media_observer())
478 return;
479 media_observer()->OnSetAudioStreamStatus(this, stream_id, status);
480 }
481
482 void AudioRendererHost::OnSetAudioStreamVolume(int stream_id, double volume) {
483 if (!media_observer())
484 return;
485 media_observer()->OnSetAudioStreamVolume(this, stream_id, volume);
486 }
487
488 void AudioRendererHost::OnDeleteAudioStream(int stream_id) {
489 if (!media_observer())
490 return;
491 media_observer()->OnDeleteAudioStream(this, stream_id);
492 }
493
469 MediaObserver* AudioRendererHost::media_observer() { 494 MediaObserver* AudioRendererHost::media_observer() {
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
471 if (!media_observer_) 496 if (!media_observer_)
472 media_observer_ = resource_context_->media_observer(); 497 media_observer_ = resource_context_->media_observer();
473 return media_observer_; 498 return media_observer_;
scherkus (not reviewing) 2012/02/03 23:40:01 I forget why this was coded like this but I wonder
vrk (LEFT CHROMIUM) 2012/03/06 02:07:50 (as discussed offline) You're right it should be r
474 } 499 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698