OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/base/android/media_codec_player.h" | 5 #include "media/base/android/media_codec_player.h" |
6 | 6 |
7 #include "base/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // Release the codecs here, before any member variable is destroyed to make | 92 // Release the codecs here, before any member variable is destroyed to make |
93 // the unit tests happy. | 93 // the unit tests happy. |
94 | 94 |
95 if (video_decoder_) | 95 if (video_decoder_) |
96 video_decoder_->ReleaseDecoderResources(); | 96 video_decoder_->ReleaseDecoderResources(); |
97 if (audio_decoder_) | 97 if (audio_decoder_) |
98 audio_decoder_->ReleaseDecoderResources(); | 98 audio_decoder_->ReleaseDecoderResources(); |
99 | 99 |
100 media_stat_->StopAndReport(GetInterpolatedTime()); | 100 media_stat_->StopAndReport(GetInterpolatedTime()); |
101 | 101 |
102 if (drm_bridge_) { | 102 if (cdm_) { |
103 DCHECK(cdm_registration_id_); | 103 DCHECK(cdm_registration_id_); |
104 drm_bridge_->UnregisterPlayer(cdm_registration_id_); | 104 drm_bridge_->UnregisterPlayer(cdm_registration_id_); |
Tima Vaisburd
2015/10/28 22:49:40
Can you use a cast from MediaKeys to MediaDemBridg
| |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 void MediaCodecPlayer::Initialize() { | 108 void MediaCodecPlayer::Initialize() { |
109 DVLOG(1) << __FUNCTION__; | 109 DVLOG(1) << __FUNCTION__; |
110 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | 110 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); |
111 | 111 |
112 interpolator_.SetUpperBound(base::TimeDelta()); | 112 interpolator_.SetUpperBound(base::TimeDelta()); |
113 | 113 |
114 CreateDecoders(); | 114 CreateDecoders(); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 return false; | 403 return false; |
404 } | 404 } |
405 | 405 |
406 bool MediaCodecPlayer::IsPlayerReady() { | 406 bool MediaCodecPlayer::IsPlayerReady() { |
407 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 407 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
408 // This method is called to check whether it's safe to release the player when | 408 // This method is called to check whether it's safe to release the player when |
409 // the OS needs more resources. This class can be released at any time. | 409 // the OS needs more resources. This class can be released at any time. |
410 return true; | 410 return true; |
411 } | 411 } |
412 | 412 |
413 void MediaCodecPlayer::SetCdm(BrowserCdm* cdm) { | 413 void MediaCodecPlayer::SetCdm(const scoped_refptr<MediaKeys>& cdm) { |
414 RUN_ON_MEDIA_THREAD(SetCdm, cdm); | 414 RUN_ON_MEDIA_THREAD(SetCdm, cdm); |
415 DCHECK(cdm); | |
415 | 416 |
416 DVLOG(1) << __FUNCTION__; | 417 DVLOG(1) << __FUNCTION__; |
417 | 418 |
418 // Currently we don't support DRM change during the middle of playback, even | 419 // Currently we don't support DRM change during the middle of playback, even |
419 // if the player is paused. There is no current plan to support it, see | 420 // if the player is paused. There is no current plan to support it, see |
420 // http://crbug.com/253792. | 421 // http://crbug.com/253792. |
421 if (state_ != kStatePaused || GetInterpolatedTime() > base::TimeDelta()) { | 422 if (state_ != kStatePaused || GetInterpolatedTime() > base::TimeDelta()) { |
422 VLOG(0) << "Setting DRM bridge after playback has started is not supported"; | 423 VLOG(0) << "Setting DRM bridge after playback has started is not supported"; |
423 return; | 424 return; |
424 } | 425 } |
425 | 426 |
426 if (drm_bridge_) { | 427 if (cdm_) { |
427 NOTREACHED() << "Currently we do not support resetting CDM."; | 428 NOTREACHED() << "Currently we do not support resetting CDM."; |
428 return; | 429 return; |
429 } | 430 } |
430 | 431 |
431 DCHECK(cdm); | 432 cdm_ = cdm; |
432 drm_bridge_ = static_cast<MediaDrmBridge*>(cdm); | |
433 | 433 |
434 DCHECK(drm_bridge_); | 434 // Only MediaDrmBridge will be set on MediaCodecPlayer. |
435 drm_bridge_ = static_cast<MediaDrmBridge*>(cdm_.get()); | |
Tima Vaisburd
2015/10/28 22:49:40
I think we can get rid of |drm_bridge_|. See below
xhwang
2015/10/29 00:17:28
Done.
| |
436 | |
437 // Register CDM callbacks. The callbacks registered will be posted back to the | |
438 // media thread via BindToCurrentLoop. | |
435 | 439 |
436 cdm_registration_id_ = drm_bridge_->RegisterPlayer( | 440 cdm_registration_id_ = drm_bridge_->RegisterPlayer( |
437 base::Bind(&MediaCodecPlayer::OnKeyAdded, media_weak_this_), | 441 BindToCurrentLoop( |
438 base::Bind(&MediaCodecPlayer::OnCdmUnset, media_weak_this_)); | 442 base::Bind(&MediaCodecPlayer::OnKeyAdded, media_weak_this_)), |
443 BindToCurrentLoop( | |
444 base::Bind(&MediaCodecPlayer::OnCdmUnset, media_weak_this_))); | |
439 | 445 |
440 MediaDrmBridge::MediaCryptoReadyCB cb = BindToCurrentLoop( | 446 drm_bridge_->SetMediaCryptoReadyCB(BindToCurrentLoop( |
441 base::Bind(&MediaCodecPlayer::OnMediaCryptoReady, media_weak_this_)); | 447 base::Bind(&MediaCodecPlayer::OnMediaCryptoReady, media_weak_this_))); |
442 | |
443 // Post back to MediaDrmBridge's default thread. | |
444 ui_task_runner_->PostTask(FROM_HERE, | |
445 base::Bind(&MediaDrmBridge::SetMediaCryptoReadyCB, | |
446 drm_bridge_->WeakPtr(), cb)); | |
447 } | 448 } |
448 | 449 |
449 // Callbacks from Demuxer. | 450 // Callbacks from Demuxer. |
450 | 451 |
451 void MediaCodecPlayer::OnDemuxerConfigsAvailable( | 452 void MediaCodecPlayer::OnDemuxerConfigsAvailable( |
452 const DemuxerConfigs& configs) { | 453 const DemuxerConfigs& configs) { |
453 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | 454 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); |
454 | 455 |
455 DVLOG(1) << __FUNCTION__; | 456 DVLOG(1) << __FUNCTION__; |
456 | 457 |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 if (audio_decoder_) { | 980 if (audio_decoder_) { |
980 audio_decoder_->SetNeedsReconfigure(); | 981 audio_decoder_->SetNeedsReconfigure(); |
981 } | 982 } |
982 | 983 |
983 if (video_decoder_) { | 984 if (video_decoder_) { |
984 video_decoder_->SetProtectedSurfaceRequired(false); | 985 video_decoder_->SetProtectedSurfaceRequired(false); |
985 video_decoder_->SetNeedsReconfigure(); | 986 video_decoder_->SetNeedsReconfigure(); |
986 } | 987 } |
987 | 988 |
988 cdm_registration_id_ = 0; | 989 cdm_registration_id_ = 0; |
990 media_crypto_.reset(); | |
989 drm_bridge_ = nullptr; | 991 drm_bridge_ = nullptr; |
990 media_crypto_.reset(); | 992 cdm_ = nullptr; |
991 } | 993 } |
992 | 994 |
993 // State machine operations, called on Media thread | 995 // State machine operations, called on Media thread |
994 | 996 |
995 void MediaCodecPlayer::SetState(PlayerState new_state) { | 997 void MediaCodecPlayer::SetState(PlayerState new_state) { |
996 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); | 998 DCHECK(GetMediaTaskRunner()->BelongsToCurrentThread()); |
997 | 999 |
998 DVLOG(1) << "SetState:" << AsString(state_) << " -> " << AsString(new_state); | 1000 DVLOG(1) << "SetState:" << AsString(state_) << " -> " << AsString(new_state); |
999 state_ = new_state; | 1001 state_ = new_state; |
1000 } | 1002 } |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1417 RETURN_STRING(kStateWaitingForMediaCrypto); | 1419 RETURN_STRING(kStateWaitingForMediaCrypto); |
1418 RETURN_STRING(kStateWaitingForSeek); | 1420 RETURN_STRING(kStateWaitingForSeek); |
1419 RETURN_STRING(kStateError); | 1421 RETURN_STRING(kStateError); |
1420 } | 1422 } |
1421 return nullptr; // crash early | 1423 return nullptr; // crash early |
1422 } | 1424 } |
1423 | 1425 |
1424 #undef RETURN_STRING | 1426 #undef RETURN_STRING |
1425 | 1427 |
1426 } // namespace media | 1428 } // namespace media |
OLD | NEW |