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" |
11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "media/base/audio_decoder_config.h" | 17 #include "media/base/audio_decoder_config.h" |
18 #include "media/base/audio_renderer.h" | 18 #include "media/base/audio_renderer.h" |
19 #include "media/base/bind_to_current_loop.h" | 19 #include "media/base/bind_to_current_loop.h" |
20 #include "media/base/demuxer_stream_provider.h" | |
21 #include "media/base/media_log.h" | 20 #include "media/base/media_log.h" |
| 21 #include "media/base/media_resource.h" |
22 #include "media/base/media_switches.h" | 22 #include "media/base/media_switches.h" |
23 #include "media/base/renderer_client.h" | 23 #include "media/base/renderer_client.h" |
24 #include "media/base/time_source.h" | 24 #include "media/base/time_source.h" |
25 #include "media/base/video_decoder_config.h" | 25 #include "media/base/video_decoder_config.h" |
26 #include "media/base/video_renderer.h" | 26 #include "media/base/video_renderer.h" |
27 #include "media/base/wall_clock_time_source.h" | 27 #include "media/base/wall_clock_time_source.h" |
28 | 28 |
29 namespace media { | 29 namespace media { |
30 | 30 |
31 // See |video_underflow_threshold_|. | 31 // See |video_underflow_threshold_|. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 video_renderer_.reset(); | 122 video_renderer_.reset(); |
123 audio_renderer_.reset(); | 123 audio_renderer_.reset(); |
124 | 124 |
125 if (!init_cb_.is_null()) { | 125 if (!init_cb_.is_null()) { |
126 FinishInitialization(PIPELINE_ERROR_ABORT); | 126 FinishInitialization(PIPELINE_ERROR_ABORT); |
127 } else if (!flush_cb_.is_null()) { | 127 } else if (!flush_cb_.is_null()) { |
128 base::ResetAndReturn(&flush_cb_).Run(); | 128 base::ResetAndReturn(&flush_cb_).Run(); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 void RendererImpl::Initialize(DemuxerStreamProvider* demuxer_stream_provider, | 132 void RendererImpl::Initialize(MediaResource* media_resource, |
133 RendererClient* client, | 133 RendererClient* client, |
134 const PipelineStatusCB& init_cb) { | 134 const PipelineStatusCB& init_cb) { |
135 DVLOG(1) << __func__; | 135 DVLOG(1) << __func__; |
136 DCHECK(task_runner_->BelongsToCurrentThread()); | 136 DCHECK(task_runner_->BelongsToCurrentThread()); |
137 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 137 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
138 DCHECK(!init_cb.is_null()); | 138 DCHECK(!init_cb.is_null()); |
139 DCHECK(client); | 139 DCHECK(client); |
140 | 140 |
141 client_ = client; | 141 client_ = client; |
142 demuxer_stream_provider_ = demuxer_stream_provider; | 142 media_resource_ = media_resource; |
143 init_cb_ = init_cb; | 143 init_cb_ = init_cb; |
144 | 144 |
145 if (HasEncryptedStream() && !cdm_context_) { | 145 if (HasEncryptedStream() && !cdm_context_) { |
146 state_ = STATE_INIT_PENDING_CDM; | 146 state_ = STATE_INIT_PENDING_CDM; |
147 return; | 147 return; |
148 } | 148 } |
149 | 149 |
150 state_ = STATE_INITIALIZING; | 150 state_ = STATE_INITIALIZING; |
151 InitializeAudioRenderer(); | 151 InitializeAudioRenderer(); |
152 } | 152 } |
(...skipping 190 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 demuxer_stream_provider_->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& s : demuxer_streams) { |
359 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO); | 356 if (s->type() == DemuxerStream::AUDIO && |
360 if (video_stream && video_stream->video_decoder_config().is_encrypted()) | 357 s->audio_decoder_config().is_encrypted()) |
361 return true; | 358 return true; |
| 359 if (s->type() == DemuxerStream::VIDEO && |
| 360 s->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 std::vector<DemuxerStream*> streams = media_resource_->GetStreams(); |
385 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO); | 386 DemuxerStream* audio_stream = nullptr; |
| 387 for (const auto& s : streams) { |
| 388 if (s->type() == DemuxerStream::AUDIO && s->enabled()) { |
| 389 audio_stream = s; |
| 390 break; |
| 391 } |
| 392 } |
386 if (!audio_stream) { | 393 if (!audio_stream) { |
387 audio_renderer_.reset(); | 394 audio_renderer_.reset(); |
388 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 395 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
389 return; | 396 return; |
390 } | 397 } |
391 | 398 |
392 audio_stream->SetStreamStatusChangeCB(base::Bind( | 399 audio_stream->SetStreamStatusChangeCB(base::Bind( |
393 &RendererImpl::OnStreamStatusChanged, weak_this_, audio_stream)); | 400 &RendererImpl::OnStreamStatusChanged, weak_this_, audio_stream)); |
394 | 401 |
395 audio_renderer_client_.reset( | 402 audio_renderer_client_.reset( |
(...skipping 27 matching lines...) Expand all Loading... |
423 | 430 |
424 void RendererImpl::InitializeVideoRenderer() { | 431 void RendererImpl::InitializeVideoRenderer() { |
425 DVLOG(1) << __func__; | 432 DVLOG(1) << __func__; |
426 DCHECK(task_runner_->BelongsToCurrentThread()); | 433 DCHECK(task_runner_->BelongsToCurrentThread()); |
427 DCHECK_EQ(state_, STATE_INITIALIZING); | 434 DCHECK_EQ(state_, STATE_INITIALIZING); |
428 DCHECK(!init_cb_.is_null()); | 435 DCHECK(!init_cb_.is_null()); |
429 | 436 |
430 PipelineStatusCB done_cb = | 437 PipelineStatusCB done_cb = |
431 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); | 438 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); |
432 | 439 |
433 DemuxerStream* video_stream = | 440 std::vector<DemuxerStream*> streams = media_resource_->GetStreams(); |
434 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO); | 441 DemuxerStream* video_stream = nullptr; |
| 442 for (const auto& s : streams) { |
| 443 if (s->type() == DemuxerStream::VIDEO && s->enabled()) { |
| 444 video_stream = s; |
| 445 break; |
| 446 } |
| 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( | 455 video_stream->SetStreamStatusChangeCB(base::Bind( |
442 &RendererImpl::OnStreamStatusChanged, weak_this_, video_stream)); | 456 &RendererImpl::OnStreamStatusChanged, weak_this_, video_stream)); |
443 | 457 |
444 video_renderer_client_.reset( | 458 video_renderer_client_.reset( |
(...skipping 400 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 |