OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/renderers/renderer_impl.h" | 5 #include "media/renderers/renderer_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 wall_clock_times->push_back(base::TimeTicks() + media_time); | 343 wall_clock_times->push_back(base::TimeTicks() + media_time); |
344 } | 344 } |
345 } | 345 } |
346 return true; | 346 return true; |
347 } | 347 } |
348 | 348 |
349 return time_source_->GetWallClockTimes(media_timestamps, wall_clock_times); | 349 return time_source_->GetWallClockTimes(media_timestamps, wall_clock_times); |
350 } | 350 } |
351 | 351 |
352 bool RendererImpl::HasEncryptedStream() { | 352 bool RendererImpl::HasEncryptedStream() { |
353 DemuxerStream* audio_stream = | 353 std::vector<DemuxerStream*> demuxer_streams = media_resource_->GetStreams(); |
354 media_resource_->GetStream(DemuxerStream::AUDIO); | |
355 if (audio_stream && audio_stream->audio_decoder_config().is_encrypted()) | |
356 return true; | |
357 | 354 |
358 DemuxerStream* video_stream = | 355 for (const auto& stream : demuxer_streams) { |
359 media_resource_->GetStream(DemuxerStream::VIDEO); | 356 if (stream->type() == DemuxerStream::AUDIO && |
360 if (video_stream && video_stream->video_decoder_config().is_encrypted()) | 357 stream->audio_decoder_config().is_encrypted()) |
361 return true; | 358 return true; |
| 359 if (stream->type() == DemuxerStream::VIDEO && |
| 360 stream->video_decoder_config().is_encrypted()) |
| 361 return true; |
| 362 } |
362 | 363 |
363 return false; | 364 return false; |
364 } | 365 } |
365 | 366 |
366 void RendererImpl::FinishInitialization(PipelineStatus status) { | 367 void RendererImpl::FinishInitialization(PipelineStatus status) { |
367 DCHECK(!init_cb_.is_null()); | 368 DCHECK(!init_cb_.is_null()); |
368 | 369 |
369 if (!pending_cdm_attached_cb_.is_null()) | 370 if (!pending_cdm_attached_cb_.is_null()) |
370 base::ResetAndReturn(&pending_cdm_attached_cb_).Run(status == PIPELINE_OK); | 371 base::ResetAndReturn(&pending_cdm_attached_cb_).Run(status == PIPELINE_OK); |
371 | 372 |
372 base::ResetAndReturn(&init_cb_).Run(status); | 373 base::ResetAndReturn(&init_cb_).Run(status); |
373 } | 374 } |
374 | 375 |
375 void RendererImpl::InitializeAudioRenderer() { | 376 void RendererImpl::InitializeAudioRenderer() { |
376 DVLOG(1) << __func__; | 377 DVLOG(1) << __func__; |
377 DCHECK(task_runner_->BelongsToCurrentThread()); | 378 DCHECK(task_runner_->BelongsToCurrentThread()); |
378 DCHECK_EQ(state_, STATE_INITIALIZING); | 379 DCHECK_EQ(state_, STATE_INITIALIZING); |
379 DCHECK(!init_cb_.is_null()); | 380 DCHECK(!init_cb_.is_null()); |
380 | 381 |
381 PipelineStatusCB done_cb = | 382 PipelineStatusCB done_cb = |
382 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); | 383 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); |
383 | 384 |
384 DemuxerStream* audio_stream = | 385 // TODO(servolk): Implement proper support for multiple streams. But for now |
385 media_resource_->GetStream(DemuxerStream::AUDIO); | 386 // pick the first enabled stream to preserve the existing behavior. |
| 387 std::vector<DemuxerStream*> streams = media_resource_->GetStreams(); |
| 388 DemuxerStream* audio_stream = nullptr; |
| 389 for (const auto& stream : streams) { |
| 390 if (stream->type() == DemuxerStream::AUDIO && stream->enabled()) { |
| 391 audio_stream = stream; |
| 392 break; |
| 393 } |
| 394 } |
386 if (!audio_stream) { | 395 if (!audio_stream) { |
387 audio_renderer_.reset(); | 396 audio_renderer_.reset(); |
388 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 397 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
389 return; | 398 return; |
390 } | 399 } |
391 | 400 |
392 audio_stream->SetStreamStatusChangeCB(base::Bind( | |
393 &RendererImpl::OnStreamStatusChanged, weak_this_, audio_stream)); | |
394 | |
395 audio_renderer_client_.reset( | 401 audio_renderer_client_.reset( |
396 new RendererClientInternal(DemuxerStream::AUDIO, this)); | 402 new RendererClientInternal(DemuxerStream::AUDIO, this)); |
397 // Note: After the initialization of a renderer, error events from it may | 403 // Note: After the initialization of a renderer, error events from it may |
398 // happen at any time and all future calls must guard against STATE_ERROR. | 404 // happen at any time and all future calls must guard against STATE_ERROR. |
399 audio_renderer_->Initialize(audio_stream, cdm_context_, | 405 audio_renderer_->Initialize(audio_stream, cdm_context_, |
400 audio_renderer_client_.get(), done_cb); | 406 audio_renderer_client_.get(), done_cb); |
401 } | 407 } |
402 | 408 |
403 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { | 409 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { |
404 DVLOG(1) << __func__ << ": " << status; | 410 DVLOG(1) << __func__ << ": " << status; |
(...skipping 18 matching lines...) Expand all Loading... |
423 | 429 |
424 void RendererImpl::InitializeVideoRenderer() { | 430 void RendererImpl::InitializeVideoRenderer() { |
425 DVLOG(1) << __func__; | 431 DVLOG(1) << __func__; |
426 DCHECK(task_runner_->BelongsToCurrentThread()); | 432 DCHECK(task_runner_->BelongsToCurrentThread()); |
427 DCHECK_EQ(state_, STATE_INITIALIZING); | 433 DCHECK_EQ(state_, STATE_INITIALIZING); |
428 DCHECK(!init_cb_.is_null()); | 434 DCHECK(!init_cb_.is_null()); |
429 | 435 |
430 PipelineStatusCB done_cb = | 436 PipelineStatusCB done_cb = |
431 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); | 437 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); |
432 | 438 |
433 DemuxerStream* video_stream = | 439 // TODO(servolk): Implement proper support for multiple streams. But for now |
434 media_resource_->GetStream(DemuxerStream::VIDEO); | 440 // pick the first enabled stream to preserve the existing behavior. |
| 441 std::vector<DemuxerStream*> streams = media_resource_->GetStreams(); |
| 442 DemuxerStream* video_stream = nullptr; |
| 443 for (const auto& stream : streams) { |
| 444 if (stream->type() == DemuxerStream::VIDEO && stream->enabled()) { |
| 445 video_stream = stream; |
| 446 break; |
| 447 } |
| 448 } |
435 if (!video_stream) { | 449 if (!video_stream) { |
436 video_renderer_.reset(); | 450 video_renderer_.reset(); |
437 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 451 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
438 return; | 452 return; |
439 } | 453 } |
440 | 454 |
441 video_stream->SetStreamStatusChangeCB(base::Bind( | |
442 &RendererImpl::OnStreamStatusChanged, weak_this_, video_stream)); | |
443 | |
444 video_renderer_client_.reset( | 455 video_renderer_client_.reset( |
445 new RendererClientInternal(DemuxerStream::VIDEO, this)); | 456 new RendererClientInternal(DemuxerStream::VIDEO, this)); |
446 video_renderer_->Initialize( | 457 video_renderer_->Initialize( |
447 video_stream, cdm_context_, video_renderer_client_.get(), | 458 video_stream, cdm_context_, video_renderer_client_.get(), |
448 base::Bind(&RendererImpl::GetWallClockTimes, base::Unretained(this)), | 459 base::Bind(&RendererImpl::GetWallClockTimes, base::Unretained(this)), |
449 done_cb); | 460 done_cb); |
450 } | 461 } |
451 | 462 |
452 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { | 463 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { |
453 DVLOG(1) << __func__ << ": " << status; | 464 DVLOG(1) << __func__ << ": " << status; |
454 DCHECK(task_runner_->BelongsToCurrentThread()); | 465 DCHECK(task_runner_->BelongsToCurrentThread()); |
455 | 466 |
456 // OnError() may be fired at any time by the renderers, even if they thought | 467 // OnError() may be fired at any time by the renderers, even if they thought |
457 // they initialized successfully (due to delayed output device setup). | 468 // they initialized successfully (due to delayed output device setup). |
458 if (state_ != STATE_INITIALIZING) { | 469 if (state_ != STATE_INITIALIZING) { |
459 DCHECK(init_cb_.is_null()); | 470 DCHECK(init_cb_.is_null()); |
460 audio_renderer_.reset(); | 471 audio_renderer_.reset(); |
461 video_renderer_.reset(); | 472 video_renderer_.reset(); |
462 return; | 473 return; |
463 } | 474 } |
464 | 475 |
465 DCHECK(!init_cb_.is_null()); | 476 DCHECK(!init_cb_.is_null()); |
466 | 477 |
467 if (status != PIPELINE_OK) { | 478 if (status != PIPELINE_OK) { |
468 FinishInitialization(status); | 479 FinishInitialization(status); |
469 return; | 480 return; |
470 } | 481 } |
471 | 482 |
| 483 media_resource_->SetStreamStatusChangeCB( |
| 484 base::Bind(&RendererImpl::OnStreamStatusChanged, weak_this_)); |
| 485 |
472 if (audio_renderer_) { | 486 if (audio_renderer_) { |
473 time_source_ = audio_renderer_->GetTimeSource(); | 487 time_source_ = audio_renderer_->GetTimeSource(); |
474 } else if (!time_source_) { | 488 } else if (!time_source_) { |
475 wall_clock_time_source_.reset(new WallClockTimeSource()); | 489 wall_clock_time_source_.reset(new WallClockTimeSource()); |
476 time_source_ = wall_clock_time_source_.get(); | 490 time_source_ = wall_clock_time_source_.get(); |
477 } | 491 } |
478 | 492 |
479 state_ = STATE_PLAYING; | 493 state_ = STATE_PLAYING; |
480 DCHECK(time_source_); | 494 DCHECK(time_source_); |
481 DCHECK(audio_renderer_ || video_renderer_); | 495 DCHECK(audio_renderer_ || video_renderer_); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 DCHECK(task_runner_->BelongsToCurrentThread()); | 859 DCHECK(task_runner_->BelongsToCurrentThread()); |
846 client_->OnVideoNaturalSizeChange(size); | 860 client_->OnVideoNaturalSizeChange(size); |
847 } | 861 } |
848 | 862 |
849 void RendererImpl::OnVideoOpacityChange(bool opaque) { | 863 void RendererImpl::OnVideoOpacityChange(bool opaque) { |
850 DCHECK(task_runner_->BelongsToCurrentThread()); | 864 DCHECK(task_runner_->BelongsToCurrentThread()); |
851 client_->OnVideoOpacityChange(opaque); | 865 client_->OnVideoOpacityChange(opaque); |
852 } | 866 } |
853 | 867 |
854 } // namespace media | 868 } // namespace media |
OLD | NEW |