| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 DCHECK(cdm_context); | 114 DCHECK(cdm_context); |
| 115 | 115 |
| 116 if (cdm_context_) { | 116 if (cdm_context_) { |
| 117 DVLOG(1) << "Switching CDM not supported."; | 117 DVLOG(1) << "Switching CDM not supported."; |
| 118 cdm_attached_cb.Run(false); | 118 cdm_attached_cb.Run(false); |
| 119 return; | 119 return; |
| 120 } | 120 } |
| 121 | 121 |
| 122 cdm_context_ = cdm_context; | 122 cdm_context_ = cdm_context; |
| 123 | 123 |
| 124 if (decryptor_ready_cb_.is_null()) { | 124 if (cdm_ready_cb_.is_null()) { |
| 125 cdm_attached_cb.Run(true); | 125 cdm_attached_cb.Run(true); |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 base::ResetAndReturn(&decryptor_ready_cb_) | 129 base::ResetAndReturn(&cdm_ready_cb_).Run(cdm_context, cdm_attached_cb); |
| 130 .Run(cdm_context->GetDecryptor(), cdm_attached_cb); | |
| 131 } | 130 } |
| 132 | 131 |
| 133 void RendererImpl::Flush(const base::Closure& flush_cb) { | 132 void RendererImpl::Flush(const base::Closure& flush_cb) { |
| 134 DVLOG(1) << __FUNCTION__; | 133 DVLOG(1) << __FUNCTION__; |
| 135 DCHECK(task_runner_->BelongsToCurrentThread()); | 134 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 136 DCHECK(flush_cb_.is_null()); | 135 DCHECK(flush_cb_.is_null()); |
| 137 | 136 |
| 138 if (state_ != STATE_PLAYING) { | 137 if (state_ != STATE_PLAYING) { |
| 139 DCHECK_EQ(state_, STATE_ERROR); | 138 DCHECK_EQ(state_, STATE_ERROR); |
| 140 return; | 139 return; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 for (auto const &media_time : media_timestamps) { | 245 for (auto const &media_time : media_timestamps) { |
| 247 wall_clock_times->push_back(base::TimeTicks() + media_time); | 246 wall_clock_times->push_back(base::TimeTicks() + media_time); |
| 248 } | 247 } |
| 249 } | 248 } |
| 250 return true; | 249 return true; |
| 251 } | 250 } |
| 252 | 251 |
| 253 return time_source_->GetWallClockTimes(media_timestamps, wall_clock_times); | 252 return time_source_->GetWallClockTimes(media_timestamps, wall_clock_times); |
| 254 } | 253 } |
| 255 | 254 |
| 256 void RendererImpl::SetDecryptorReadyCallback( | 255 void RendererImpl::SetCdmReadyCallback(const CdmReadyCB& cdm_ready_cb) { |
| 257 const DecryptorReadyCB& decryptor_ready_cb) { | 256 // Cancels the previous CDM request. |
| 258 // Cancels the previous decryptor request. | 257 if (cdm_ready_cb.is_null()) { |
| 259 if (decryptor_ready_cb.is_null()) { | 258 if (!cdm_ready_cb_.is_null()) { |
| 260 if (!decryptor_ready_cb_.is_null()) { | 259 base::ResetAndReturn(&cdm_ready_cb_) |
| 261 base::ResetAndReturn(&decryptor_ready_cb_) | |
| 262 .Run(nullptr, base::Bind(IgnoreCdmAttached)); | 260 .Run(nullptr, base::Bind(IgnoreCdmAttached)); |
| 263 } | 261 } |
| 264 return; | 262 return; |
| 265 } | 263 } |
| 266 | 264 |
| 267 // We initialize audio and video decoders in sequence. | 265 // We initialize audio and video decoders in sequence. |
| 268 DCHECK(decryptor_ready_cb_.is_null()); | 266 DCHECK(cdm_ready_cb_.is_null()); |
| 269 | 267 |
| 270 if (cdm_context_) { | 268 if (cdm_context_) { |
| 271 decryptor_ready_cb.Run(cdm_context_->GetDecryptor(), | 269 cdm_ready_cb.Run(cdm_context_, base::Bind(IgnoreCdmAttached)); |
| 272 base::Bind(IgnoreCdmAttached)); | |
| 273 return; | 270 return; |
| 274 } | 271 } |
| 275 | 272 |
| 276 decryptor_ready_cb_ = decryptor_ready_cb; | 273 cdm_ready_cb_ = cdm_ready_cb; |
| 277 } | 274 } |
| 278 | 275 |
| 279 void RendererImpl::InitializeAudioRenderer() { | 276 void RendererImpl::InitializeAudioRenderer() { |
| 280 DVLOG(1) << __FUNCTION__; | 277 DVLOG(1) << __FUNCTION__; |
| 281 DCHECK(task_runner_->BelongsToCurrentThread()); | 278 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 282 DCHECK_EQ(state_, STATE_INITIALIZING); | 279 DCHECK_EQ(state_, STATE_INITIALIZING); |
| 283 DCHECK(!init_cb_.is_null()); | 280 DCHECK(!init_cb_.is_null()); |
| 284 | 281 |
| 285 PipelineStatusCB done_cb = | 282 PipelineStatusCB done_cb = |
| 286 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); | 283 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); |
| 287 | 284 |
| 288 if (!demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO)) { | 285 if (!demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO)) { |
| 289 audio_renderer_.reset(); | 286 audio_renderer_.reset(); |
| 290 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 287 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
| 291 return; | 288 return; |
| 292 } | 289 } |
| 293 | 290 |
| 294 // Note: After the initialization of a renderer, error events from it may | 291 // Note: After the initialization of a renderer, error events from it may |
| 295 // happen at any time and all future calls must guard against STATE_ERROR. | 292 // happen at any time and all future calls must guard against STATE_ERROR. |
| 296 audio_renderer_->Initialize( | 293 audio_renderer_->Initialize( |
| 297 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO), done_cb, | 294 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO), done_cb, |
| 298 base::Bind(&RendererImpl::SetDecryptorReadyCallback, weak_this_), | 295 base::Bind(&RendererImpl::SetCdmReadyCallback, weak_this_), |
| 299 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), | 296 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), |
| 300 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, | 297 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, |
| 301 &audio_buffering_state_), | 298 &audio_buffering_state_), |
| 302 base::Bind(&RendererImpl::OnAudioRendererEnded, weak_this_), | 299 base::Bind(&RendererImpl::OnAudioRendererEnded, weak_this_), |
| 303 base::Bind(&RendererImpl::OnError, weak_this_), | 300 base::Bind(&RendererImpl::OnError, weak_this_), |
| 304 waiting_for_decryption_key_cb_); | 301 waiting_for_decryption_key_cb_); |
| 305 } | 302 } |
| 306 | 303 |
| 307 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { | 304 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { |
| 308 DVLOG(1) << __FUNCTION__ << ": " << status; | 305 DVLOG(1) << __FUNCTION__ << ": " << status; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 335 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); | 332 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); |
| 336 | 333 |
| 337 if (!demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO)) { | 334 if (!demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO)) { |
| 338 video_renderer_.reset(); | 335 video_renderer_.reset(); |
| 339 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 336 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
| 340 return; | 337 return; |
| 341 } | 338 } |
| 342 | 339 |
| 343 video_renderer_->Initialize( | 340 video_renderer_->Initialize( |
| 344 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO), done_cb, | 341 demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO), done_cb, |
| 345 base::Bind(&RendererImpl::SetDecryptorReadyCallback, weak_this_), | 342 base::Bind(&RendererImpl::SetCdmReadyCallback, weak_this_), |
| 346 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), | 343 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), |
| 347 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, | 344 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, |
| 348 &video_buffering_state_), | 345 &video_buffering_state_), |
| 349 base::Bind(&RendererImpl::OnVideoRendererEnded, weak_this_), | 346 base::Bind(&RendererImpl::OnVideoRendererEnded, weak_this_), |
| 350 base::Bind(&RendererImpl::OnError, weak_this_), | 347 base::Bind(&RendererImpl::OnError, weak_this_), |
| 351 base::Bind(&RendererImpl::GetWallClockTimes, base::Unretained(this)), | 348 base::Bind(&RendererImpl::GetWallClockTimes, base::Unretained(this)), |
| 352 waiting_for_decryption_key_cb_); | 349 waiting_for_decryption_key_cb_); |
| 353 } | 350 } |
| 354 | 351 |
| 355 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { | 352 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 } | 641 } |
| 645 | 642 |
| 646 // After OnError() returns, the pipeline may destroy |this|. | 643 // After OnError() returns, the pipeline may destroy |this|. |
| 647 base::ResetAndReturn(&error_cb_).Run(error); | 644 base::ResetAndReturn(&error_cb_).Run(error); |
| 648 | 645 |
| 649 if (!flush_cb_.is_null()) | 646 if (!flush_cb_.is_null()) |
| 650 base::ResetAndReturn(&flush_cb_).Run(); | 647 base::ResetAndReturn(&flush_cb_).Run(); |
| 651 } | 648 } |
| 652 | 649 |
| 653 } // namespace media | 650 } // namespace media |
| OLD | NEW |