Index: media/base/android/media_source_player.cc |
diff --git a/media/base/android/media_source_player.cc b/media/base/android/media_source_player.cc |
index 081d69174577426b7553b8c64a796d14a27303a8..938562d8c23a39394c5ea6948dce0b85dbc05831 100644 |
--- a/media/base/android/media_source_player.cc |
+++ b/media/base/android/media_source_player.cc |
@@ -54,16 +54,21 @@ MediaSourcePlayer::MediaSourcePlayer( |
reconfig_audio_decoder_(false), |
reconfig_video_decoder_(false), |
drm_bridge_(NULL), |
+ cdm_registration_id_(0), |
is_waiting_for_key_(false), |
has_pending_audio_data_request_(false), |
has_pending_video_data_request_(false), |
weak_factory_(this) { |
demuxer_->Initialize(this); |
clock_.SetMaxTime(base::TimeDelta()); |
+ weak_this_ = weak_factory_.GetWeakPtr(); |
} |
MediaSourcePlayer::~MediaSourcePlayer() { |
Release(); |
+ if (drm_bridge_) |
+ drm_bridge_->UnregisterPlayer(cdm_registration_id_); |
ddorwin
2014/05/30 20:50:05
Should this be called even if cdm_registration_id_
xhwang
2014/06/02 20:11:43
Done.
|
+ cdm_registration_id_ = 0; |
} |
void MediaSourcePlayer::SetVideoSurface(gfx::ScopedJavaSurface surface) { |
@@ -239,16 +244,6 @@ void MediaSourcePlayer::SetVolume(double volume) { |
SetVolumeInternal(); |
} |
-void MediaSourcePlayer::OnKeyAdded() { |
- DVLOG(1) << __FUNCTION__; |
- if (!is_waiting_for_key_) |
- return; |
- |
- is_waiting_for_key_ = false; |
- if (playing_) |
- StartInternal(); |
-} |
- |
bool MediaSourcePlayer::IsSurfaceInUse() const { |
return is_surface_in_use_; |
} |
@@ -355,7 +350,7 @@ void MediaSourcePlayer::OnMediaCryptoReady() { |
StartInternal(); |
} |
-void MediaSourcePlayer::SetCdm(MediaKeys* cdm) { |
+void MediaSourcePlayer::SetCdm(BrowserCdm* cdm) { |
// Currently we don't support DRM change during the middle of playback, even |
// if the player is paused. |
// TODO(qinmin): support DRM change after playback has started. |
@@ -365,12 +360,20 @@ void MediaSourcePlayer::SetCdm(MediaKeys* cdm) { |
<< "This is not well supported!"; |
} |
+ // Currently we don't support resetting |drm_bridge_|. |
ddorwin
2014/05/30 20:50:05
Ditto about DCHECK and error reporting.
xhwang
2014/06/02 20:11:43
Done.
|
+ if (drm_bridge_) |
+ return; |
+ |
// Only MediaDrmBridge will be set on MediaSourcePlayer. |
drm_bridge_ = static_cast<MediaDrmBridge*>(cdm); |
+ cdm_registration_id_ = cdm->RegisterPlayer( |
ddorwin
2014/05/30 20:50:05
A bit odd to cast then use the previous pointer (c
xhwang
2014/06/02 20:11:43
Done.
|
+ base::Bind(&MediaSourcePlayer::OnKeyAdded, weak_this_), |
+ base::Bind(&MediaSourcePlayer::OnCdmDestroyed, weak_this_)); |
+ |
if (drm_bridge_->GetMediaCrypto().is_null()) { |
ddorwin
2014/05/30 20:50:05
Should this logic be made generic as well? Some ty
xhwang
2014/06/02 20:11:43
Not sure whether there's a general need for this.
|
- drm_bridge_->SetMediaCryptoReadyCB(base::Bind( |
- &MediaSourcePlayer::OnMediaCryptoReady, weak_factory_.GetWeakPtr())); |
+ drm_bridge_->SetMediaCryptoReadyCB( |
+ base::Bind(&MediaSourcePlayer::OnMediaCryptoReady, weak_this_)); |
return; |
} |
@@ -524,10 +527,8 @@ void MediaSourcePlayer::ProcessPendingEvents() { |
return; |
SetPendingEvent(PREFETCH_DONE_EVENT_PENDING); |
- base::Closure barrier = |
- BarrierClosure(count, |
- base::Bind(&MediaSourcePlayer::OnPrefetchDone, |
- weak_factory_.GetWeakPtr())); |
+ base::Closure barrier = BarrierClosure( |
+ count, base::Bind(&MediaSourcePlayer::OnPrefetchDone, weak_this_)); |
if (!AudioFinished()) |
audio_decoder_job_->Prefetch(barrier); |
@@ -655,9 +656,7 @@ void MediaSourcePlayer::DecodeMoreAudio() { |
scoped_ptr<DemuxerConfigs> configs(audio_decoder_job_->Decode( |
start_time_ticks_, |
start_presentation_timestamp_, |
- base::Bind(&MediaSourcePlayer::MediaDecoderCallback, |
- weak_factory_.GetWeakPtr(), |
- true))); |
+ base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, true))); |
if (!configs) { |
TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreAudio", |
audio_decoder_job_.get()); |
@@ -687,9 +686,7 @@ void MediaSourcePlayer::DecodeMoreVideo() { |
scoped_ptr<DemuxerConfigs> configs(video_decoder_job_->Decode( |
start_time_ticks_, |
start_presentation_timestamp_, |
- base::Bind(&MediaSourcePlayer::MediaDecoderCallback, |
- weak_factory_.GetWeakPtr(), |
- false))); |
+ base::Bind(&MediaSourcePlayer::MediaDecoderCallback, weak_this_, false))); |
if (!configs) { |
TRACE_EVENT_ASYNC_BEGIN0("media", "MediaSourcePlayer::DecodeMoreVideo", |
video_decoder_job_.get()); |
@@ -914,8 +911,8 @@ void MediaSourcePlayer::StartStarvationCallback( |
timeout = std::max(timeout, kMinStarvationTimeout); |
- decoder_starvation_callback_.Reset(base::Bind( |
- &MediaSourcePlayer::OnDecoderStarved, weak_factory_.GetWeakPtr())); |
+ decoder_starvation_callback_.Reset( |
+ base::Bind(&MediaSourcePlayer::OnDecoderStarved, weak_this_)); |
base::MessageLoop::current()->PostDelayedTask( |
FROM_HERE, decoder_starvation_callback_.callback(), timeout); |
} |
@@ -1022,4 +1019,21 @@ void MediaSourcePlayer::SetDemuxerConfigs(const DemuxerConfigs& configs, |
} |
} |
+void MediaSourcePlayer::OnKeyAdded() { |
+ DVLOG(1) << __FUNCTION__; |
+ if (!is_waiting_for_key_) |
+ return; |
+ |
+ is_waiting_for_key_ = false; |
+ if (playing_) |
+ StartInternal(); |
+} |
+ |
+void MediaSourcePlayer::OnCdmDestroyed() { |
+ DVLOG(1) << __FUNCTION__; |
+ DCHECK(drm_bridge_); |
+ // TODO(xhwang): Support detachment of CDM. |
ddorwin
2014/05/30 20:50:05
Don't you need to handle the platform-driven case
xhwang
2014/06/02 20:11:43
That'll be a non-trivial change. I'll probably do
ddorwin
2014/06/02 20:20:29
But does this break existing prefixed API behavior
xhwang
2014/06/02 21:41:22
Currently we are not releasing MediaDrm when the d
|
+ DVLOG(1) << "CDM detachment not supported."; |
+} |
+ |
} // namespace media |