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 = |
354 media_resource_->GetStream(DemuxerStream::AUDIO); | 354 media_resource_->GetAllStreams(); |
355 if (audio_stream && audio_stream->audio_decoder_config().is_encrypted()) | |
356 return true; | |
357 | 355 |
358 DemuxerStream* video_stream = | 356 for (const auto& stream : demuxer_streams) { |
359 media_resource_->GetStream(DemuxerStream::VIDEO); | 357 if (stream->type() == DemuxerStream::AUDIO && |
360 if (video_stream && video_stream->video_decoder_config().is_encrypted()) | 358 stream->audio_decoder_config().is_encrypted()) |
361 return true; | 359 return true; |
| 360 if (stream->type() == DemuxerStream::VIDEO && |
| 361 stream->video_decoder_config().is_encrypted()) |
| 362 return true; |
| 363 } |
362 | 364 |
363 return false; | 365 return false; |
364 } | 366 } |
365 | 367 |
366 void RendererImpl::FinishInitialization(PipelineStatus status) { | 368 void RendererImpl::FinishInitialization(PipelineStatus status) { |
367 DCHECK(!init_cb_.is_null()); | 369 DCHECK(!init_cb_.is_null()); |
368 | 370 |
369 if (!pending_cdm_attached_cb_.is_null()) | 371 if (!pending_cdm_attached_cb_.is_null()) |
370 base::ResetAndReturn(&pending_cdm_attached_cb_).Run(status == PIPELINE_OK); | 372 base::ResetAndReturn(&pending_cdm_attached_cb_).Run(status == PIPELINE_OK); |
371 | 373 |
372 base::ResetAndReturn(&init_cb_).Run(status); | 374 base::ResetAndReturn(&init_cb_).Run(status); |
373 } | 375 } |
374 | 376 |
375 void RendererImpl::InitializeAudioRenderer() { | 377 void RendererImpl::InitializeAudioRenderer() { |
376 DVLOG(1) << __func__; | 378 DVLOG(1) << __func__; |
377 DCHECK(task_runner_->BelongsToCurrentThread()); | 379 DCHECK(task_runner_->BelongsToCurrentThread()); |
378 DCHECK_EQ(state_, STATE_INITIALIZING); | 380 DCHECK_EQ(state_, STATE_INITIALIZING); |
379 DCHECK(!init_cb_.is_null()); | 381 DCHECK(!init_cb_.is_null()); |
380 | 382 |
381 PipelineStatusCB done_cb = | 383 PipelineStatusCB done_cb = |
382 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); | 384 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); |
383 | 385 |
| 386 // TODO(servolk): Implement proper support for multiple streams. But for now |
| 387 // pick the first enabled stream to preserve the existing behavior. |
384 DemuxerStream* audio_stream = | 388 DemuxerStream* audio_stream = |
385 media_resource_->GetStream(DemuxerStream::AUDIO); | 389 media_resource_->GetFirstStream(DemuxerStream::AUDIO); |
386 if (!audio_stream) { | 390 if (!audio_stream) { |
387 audio_renderer_.reset(); | 391 audio_renderer_.reset(); |
388 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 392 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
389 return; | 393 return; |
390 } | 394 } |
391 | 395 |
392 audio_stream->SetStreamStatusChangeCB(base::Bind( | |
393 &RendererImpl::OnStreamStatusChanged, weak_this_, audio_stream)); | |
394 | |
395 audio_renderer_client_.reset( | 396 audio_renderer_client_.reset( |
396 new RendererClientInternal(DemuxerStream::AUDIO, this)); | 397 new RendererClientInternal(DemuxerStream::AUDIO, this)); |
397 // Note: After the initialization of a renderer, error events from it may | 398 // 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. | 399 // happen at any time and all future calls must guard against STATE_ERROR. |
399 audio_renderer_->Initialize(audio_stream, cdm_context_, | 400 audio_renderer_->Initialize(audio_stream, cdm_context_, |
400 audio_renderer_client_.get(), done_cb); | 401 audio_renderer_client_.get(), done_cb); |
401 } | 402 } |
402 | 403 |
403 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { | 404 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { |
404 DVLOG(1) << __func__ << ": " << status; | 405 DVLOG(1) << __func__ << ": " << status; |
(...skipping 18 matching lines...) Expand all Loading... |
423 | 424 |
424 void RendererImpl::InitializeVideoRenderer() { | 425 void RendererImpl::InitializeVideoRenderer() { |
425 DVLOG(1) << __func__; | 426 DVLOG(1) << __func__; |
426 DCHECK(task_runner_->BelongsToCurrentThread()); | 427 DCHECK(task_runner_->BelongsToCurrentThread()); |
427 DCHECK_EQ(state_, STATE_INITIALIZING); | 428 DCHECK_EQ(state_, STATE_INITIALIZING); |
428 DCHECK(!init_cb_.is_null()); | 429 DCHECK(!init_cb_.is_null()); |
429 | 430 |
430 PipelineStatusCB done_cb = | 431 PipelineStatusCB done_cb = |
431 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); | 432 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); |
432 | 433 |
| 434 // TODO(servolk): Implement proper support for multiple streams. But for now |
| 435 // pick the first enabled stream to preserve the existing behavior. |
433 DemuxerStream* video_stream = | 436 DemuxerStream* video_stream = |
434 media_resource_->GetStream(DemuxerStream::VIDEO); | 437 media_resource_->GetFirstStream(DemuxerStream::VIDEO); |
435 if (!video_stream) { | 438 if (!video_stream) { |
436 video_renderer_.reset(); | 439 video_renderer_.reset(); |
437 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 440 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
438 return; | 441 return; |
439 } | 442 } |
440 | 443 |
441 video_stream->SetStreamStatusChangeCB(base::Bind( | |
442 &RendererImpl::OnStreamStatusChanged, weak_this_, video_stream)); | |
443 | |
444 video_renderer_client_.reset( | 444 video_renderer_client_.reset( |
445 new RendererClientInternal(DemuxerStream::VIDEO, this)); | 445 new RendererClientInternal(DemuxerStream::VIDEO, this)); |
446 video_renderer_->Initialize( | 446 video_renderer_->Initialize( |
447 video_stream, cdm_context_, video_renderer_client_.get(), | 447 video_stream, cdm_context_, video_renderer_client_.get(), |
448 base::Bind(&RendererImpl::GetWallClockTimes, base::Unretained(this)), | 448 base::Bind(&RendererImpl::GetWallClockTimes, base::Unretained(this)), |
449 done_cb); | 449 done_cb); |
450 } | 450 } |
451 | 451 |
452 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { | 452 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { |
453 DVLOG(1) << __func__ << ": " << status; | 453 DVLOG(1) << __func__ << ": " << status; |
454 DCHECK(task_runner_->BelongsToCurrentThread()); | 454 DCHECK(task_runner_->BelongsToCurrentThread()); |
455 | 455 |
456 // OnError() may be fired at any time by the renderers, even if they thought | 456 // OnError() may be fired at any time by the renderers, even if they thought |
457 // they initialized successfully (due to delayed output device setup). | 457 // they initialized successfully (due to delayed output device setup). |
458 if (state_ != STATE_INITIALIZING) { | 458 if (state_ != STATE_INITIALIZING) { |
459 DCHECK(init_cb_.is_null()); | 459 DCHECK(init_cb_.is_null()); |
460 audio_renderer_.reset(); | 460 audio_renderer_.reset(); |
461 video_renderer_.reset(); | 461 video_renderer_.reset(); |
462 return; | 462 return; |
463 } | 463 } |
464 | 464 |
465 DCHECK(!init_cb_.is_null()); | 465 DCHECK(!init_cb_.is_null()); |
466 | 466 |
467 if (status != PIPELINE_OK) { | 467 if (status != PIPELINE_OK) { |
468 FinishInitialization(status); | 468 FinishInitialization(status); |
469 return; | 469 return; |
470 } | 470 } |
471 | 471 |
| 472 media_resource_->SetStreamStatusChangeCB( |
| 473 base::Bind(&RendererImpl::OnStreamStatusChanged, weak_this_)); |
| 474 |
472 if (audio_renderer_) { | 475 if (audio_renderer_) { |
473 time_source_ = audio_renderer_->GetTimeSource(); | 476 time_source_ = audio_renderer_->GetTimeSource(); |
474 } else if (!time_source_) { | 477 } else if (!time_source_) { |
475 wall_clock_time_source_.reset(new WallClockTimeSource()); | 478 wall_clock_time_source_.reset(new WallClockTimeSource()); |
476 time_source_ = wall_clock_time_source_.get(); | 479 time_source_ = wall_clock_time_source_.get(); |
477 } | 480 } |
478 | 481 |
479 state_ = STATE_PLAYING; | 482 state_ = STATE_PLAYING; |
480 DCHECK(time_source_); | 483 DCHECK(time_source_); |
481 DCHECK(audio_renderer_ || video_renderer_); | 484 DCHECK(audio_renderer_ || video_renderer_); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 DCHECK(task_runner_->BelongsToCurrentThread()); | 848 DCHECK(task_runner_->BelongsToCurrentThread()); |
846 client_->OnVideoNaturalSizeChange(size); | 849 client_->OnVideoNaturalSizeChange(size); |
847 } | 850 } |
848 | 851 |
849 void RendererImpl::OnVideoOpacityChange(bool opaque) { | 852 void RendererImpl::OnVideoOpacityChange(bool opaque) { |
850 DCHECK(task_runner_->BelongsToCurrentThread()); | 853 DCHECK(task_runner_->BelongsToCurrentThread()); |
851 client_->OnVideoOpacityChange(opaque); | 854 client_->OnVideoOpacityChange(opaque); |
852 } | 855 } |
853 | 856 |
854 } // namespace media | 857 } // namespace media |
OLD | NEW |