diff options
author | xhwang <xhwang@chromium.org> | 2016-03-24 22:45:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-25 05:47:11 +0000 |
commit | d37992392cb62d9207105704c2361eff64d35825 (patch) | |
tree | f67b0a56d9d1d6a9fd750e6f7a1910e27dfc703e /media | |
parent | 776c27e916f27261eff437954efe0d79b6195f30 (diff) | |
download | chromium_src-d37992392cb62d9207105704c2361eff64d35825.zip chromium_src-d37992392cb62d9207105704c2361eff64d35825.tar.gz chromium_src-d37992392cb62d9207105704c2361eff64d35825.tar.bz2 |
media: Add OnHasAdditionalUsableKey() in MediaDrmBridge
When an addtional usable key is available, instead of notifying the
player immediately, post a task (OnHasAdditionalUsableKey()) to the
|task_runner_| to notify the player.
Since UpdateSession() also happens on |task_runner_|, this makes
sure that OnHasAdditionalUsableKey() must run after UpdateSession()
returns. This helps avoid tricky race conditions.
This implementation is more consistent with the spec:
https://www.w3.org/TR/encrypted-media/#update-key-statuses
6.6.2 Update Key Statuses
5. Queue a task to fire a simple event named keystatuseschange at the
session.
6. Queue a task to run the Attempt to Resume Playback If Necessary
algorithm on each of the media element(s) whose mediaKeys
attribute is the MediaKeys object that created the session.
BUG=597892
TEST=Resume playback after session update works.
Review URL: https://codereview.chromium.org/1827343002
Cr-Commit-Position: refs/heads/master@{#383253}
Diffstat (limited to 'media')
-rw-r--r-- | media/base/android/media_drm_bridge.cc | 22 | ||||
-rw-r--r-- | media/base/android/media_drm_bridge.h | 3 |
2 files changed, 22 insertions, 3 deletions
diff --git a/media/base/android/media_drm_bridge.cc b/media/base/android/media_drm_bridge.cc index f82d176..96821ae 100644 --- a/media/base/android/media_drm_bridge.cc +++ b/media/base/android/media_drm_bridge.cc @@ -346,6 +346,7 @@ scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateWithoutSessionSupport( void MediaDrmBridge::SetServerCertificate( const std::vector<uint8_t>& certificate, scoped_ptr<media::SimpleCdmPromise> promise) { + DCHECK(task_runner_->BelongsToCurrentThread()); DVLOG(2) << __FUNCTION__ << "(" << certificate.size() << " bytes)"; DCHECK(!certificate.empty()); @@ -366,6 +367,7 @@ void MediaDrmBridge::CreateSessionAndGenerateRequest( media::EmeInitDataType init_data_type, const std::vector<uint8_t>& init_data, scoped_ptr<media::NewSessionCdmPromise> promise) { + DCHECK(task_runner_->BelongsToCurrentThread()); DVLOG(2) << __FUNCTION__; if (session_type != media::MediaKeys::TEMPORARY_SESSION) { @@ -421,6 +423,7 @@ void MediaDrmBridge::LoadSession( SessionType session_type, const std::string& session_id, scoped_ptr<media::NewSessionCdmPromise> promise) { + DCHECK(task_runner_->BelongsToCurrentThread()); DVLOG(2) << __FUNCTION__; NOTIMPLEMENTED() << "EME persistent sessions not yet supported on Android."; @@ -431,6 +434,7 @@ void MediaDrmBridge::UpdateSession( const std::string& session_id, const std::vector<uint8_t>& response, scoped_ptr<media::SimpleCdmPromise> promise) { + DCHECK(task_runner_->BelongsToCurrentThread()); DVLOG(2) << __FUNCTION__; JNIEnv* env = AttachCurrentThread(); @@ -446,6 +450,7 @@ void MediaDrmBridge::UpdateSession( void MediaDrmBridge::CloseSession(const std::string& session_id, scoped_ptr<media::SimpleCdmPromise> promise) { + DCHECK(task_runner_->BelongsToCurrentThread()); DVLOG(2) << __FUNCTION__; JNIEnv* env = AttachCurrentThread(); @@ -460,6 +465,7 @@ void MediaDrmBridge::CloseSession(const std::string& session_id, void MediaDrmBridge::RemoveSession( const std::string& session_id, scoped_ptr<media::SimpleCdmPromise> promise) { + DCHECK(task_runner_->BelongsToCurrentThread()); DVLOG(2) << __FUNCTION__; NOTIMPLEMENTED() << "EME persistent sessions not yet supported on Android."; @@ -664,9 +670,6 @@ void MediaDrmBridge::OnSessionKeysChange( bool has_additional_usable_key) { DVLOG(2) << __FUNCTION__; - if (has_additional_usable_key) - player_tracker_.NotifyNewKey(); - CdmKeysInfo cdm_keys_info; size_t size = env->GetArrayLength(j_keys_info); @@ -697,6 +700,12 @@ void MediaDrmBridge::OnSessionKeysChange( FROM_HERE, base::Bind(session_keys_change_cb_, AsString(env, j_session_id), has_additional_usable_key, base::Passed(&cdm_keys_info))); + + if (has_additional_usable_key) { + task_runner_->PostTask(FROM_HERE, + base::Bind(&MediaDrmBridge::OnHasAdditionalUsableKey, + weak_factory_.GetWeakPtr())); + } } // According to MeidaDrm documentation [1], zero |expiry_time_ms| means the keys @@ -887,4 +896,11 @@ void MediaDrmBridge::ProcessProvisionResponse(bool success, j_response.obj()); } +void MediaDrmBridge::OnHasAdditionalUsableKey() { + DCHECK(task_runner_->BelongsToCurrentThread()); + DVLOG(1) << __FUNCTION__; + + player_tracker_.NotifyNewKey(); +} + } // namespace media diff --git a/media/base/android/media_drm_bridge.h b/media/base/android/media_drm_bridge.h index 0a74fcd..8c31f89 100644 --- a/media/base/android/media_drm_bridge.h +++ b/media/base/android/media_drm_bridge.h @@ -288,6 +288,9 @@ class MEDIA_EXPORT MediaDrmBridge : public MediaKeys, public PlayerTracker { // Process the data received by provisioning server. void ProcessProvisionResponse(bool success, const std::string& response); + // Called on the |task_runner_| when there is additional usable key. + void OnHasAdditionalUsableKey(); + // UUID of the key system. std::vector<uint8_t> scheme_uuid_; |