diff options
author | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-21 19:25:25 +0000 |
---|---|---|
committer | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-21 19:25:25 +0000 |
commit | 037d4fcb2f6dde15b557cfd0258aeb48fcd16114 (patch) | |
tree | c7df5ecd3ae3fd2daa1d2eb8149128a89389a055 | |
parent | 24a446bd922561c210a3cdd5a1881f6dd1e4fe5a (diff) | |
download | chromium_src-037d4fcb2f6dde15b557cfd0258aeb48fcd16114.zip chromium_src-037d4fcb2f6dde15b557cfd0258aeb48fcd16114.tar.gz chromium_src-037d4fcb2f6dde15b557cfd0258aeb48fcd16114.tar.bz2 |
Merge 251934 "PpapiDecryptor: Call NewKeyCB on OnSessionReady()."
> PpapiDecryptor: Call NewKeyCB on OnSessionReady().
>
> Also updated the browser test to test the case where media pipeline starts to
> ask the CDM to do decryption before the session is fully loaded.
>
> BUG=344651
> TEST=Updated test.
> R=ddorwin@chromium.org
>
> Review URL: https://codereview.chromium.org/166273009
TBR=xhwang@chromium.org
Review URL: https://codereview.chromium.org/169433004
git-svn-id: svn://svn.chromium.org/chrome/branches/1847/src@252610 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/renderer/media/crypto/ppapi_decryptor.cc | 19 | ||||
-rw-r--r-- | media/cdm/ppapi/external_clear_key/clear_key_cdm.cc | 41 | ||||
-rw-r--r-- | media/cdm/ppapi/external_clear_key/clear_key_cdm.h | 8 |
3 files changed, 50 insertions, 18 deletions
diff --git a/content/renderer/media/crypto/ppapi_decryptor.cc b/content/renderer/media/crypto/ppapi_decryptor.cc index 350bfa1..d1fda56 100644 --- a/content/renderer/media/crypto/ppapi_decryptor.cc +++ b/content/renderer/media/crypto/ppapi_decryptor.cc @@ -137,12 +137,6 @@ void PpapiDecryptor::UpdateSession(uint32 session_id, ReportFailureToCallPlugin(session_id); return; } - - if (!new_audio_key_cb_.is_null()) - new_audio_key_cb_.Run(); - - if (!new_video_key_cb_.is_null()) - new_video_key_cb_.Run(); } void PpapiDecryptor::ReleaseSession(uint32 session_id) { @@ -352,6 +346,19 @@ void PpapiDecryptor::OnSessionMessage(uint32 session_id, void PpapiDecryptor::OnSessionReady(uint32 session_id) { DCHECK(render_loop_proxy_->BelongsToCurrentThread()); + + // Based on the spec, we need to resume playback when update() completes + // successfully, or when a session is successfully loaded. In both cases, + // the CDM fires OnSessionReady() event. So we choose to call the NewKeyCBs + // here. + // TODO(xhwang): Rename OnSessionReady to indicate that the playback may + // resume successfully (e.g. a new key is available or available again). + if (!new_audio_key_cb_.is_null()) + new_audio_key_cb_.Run(); + + if (!new_video_key_cb_.is_null()) + new_video_key_cb_.Run(); + session_ready_cb_.Run(session_id); } diff --git a/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc b/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc index 63d1066..64e0158 100644 --- a/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc +++ b/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc @@ -5,6 +5,7 @@ #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" #include <algorithm> +#include <cstring> #include <sstream> #include <string> #include <vector> @@ -196,7 +197,7 @@ ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, const std::string& key_system) last_session_id_(MediaKeys::kInvalidSessionId), session_id_for_emulated_loadsession_(MediaKeys::kInvalidSessionId), timer_delay_ms_(kInitialTimerDelayMs), - timer_set_(false) { + heartbeat_timer_set_(false) { #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) channel_count_ = 0; bits_per_channel_ = 0; @@ -250,9 +251,9 @@ void ClearKeyCdm::UpdateSession(uint32 session_id, DVLOG(1) << __FUNCTION__; decryptor_.UpdateSession(session_id, response, response_size); - if (!timer_set_) { + if (!heartbeat_timer_set_) { ScheduleNextHeartBeat(); - timer_set_ = true; + heartbeat_timer_set_ = true; } } @@ -262,6 +263,12 @@ void ClearKeyCdm::ReleaseSession(uint32 session_id) { } void ClearKeyCdm::TimerExpired(void* context) { + if (context == &session_id_for_emulated_loadsession_) { + LoadLoadableSession(); + return; + } + + DCHECK(heartbeat_timer_set_); std::string heartbeat_message; if (!next_heartbeat_message_.empty() && context == &next_heartbeat_message_[0]) { @@ -521,7 +528,7 @@ void ClearKeyCdm::OnQueryOutputProtectionStatus( NOTIMPLEMENTED(); }; -void ClearKeyCdm::UpdateLoadableSession() { +void ClearKeyCdm::LoadLoadableSession() { std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, sizeof(kLoadableSessionKey), kLoadableSessionKeyId, @@ -538,18 +545,30 @@ void ClearKeyCdm::OnSessionCreated(uint32 session_id, std::string new_web_session_id = web_session_id; if (session_id == session_id_for_emulated_loadsession_) { - new_web_session_id = kLoadableWebSessionId; - UpdateLoadableSession(); - session_id_for_emulated_loadsession_ = MediaKeys::kInvalidSessionId; + // Delay LoadLoadableSession() to test the case where Decrypt*() calls are + // made before the session is fully loaded. + const int64 kDelayToLoadSessionMs = 500; + // Use the address of |session_id_for_emulated_loadsession_| as the timer + // context so that we can call LoadLoadableSession() when the timer expires. + host_->SetTimer(kDelayToLoadSessionMs, + &session_id_for_emulated_loadsession_); + // Defer OnSessionCreated() until the session is loaded. + return; } host_->OnSessionCreated( - session_id, new_web_session_id.data(), new_web_session_id.size()); + session_id, web_session_id.data(), web_session_id.size()); } void ClearKeyCdm::OnSessionMessage(uint32 session_id, const std::vector<uint8>& message, const std::string& destination_url) { + DVLOG(1) << "OnSessionMessage: " << message.size(); + + // Ignore the message when we are waiting to update the loadable session. + if (session_id == session_id_for_emulated_loadsession_) + return; + host_->OnSessionMessage(session_id, reinterpret_cast<const char*>(message.data()), message.size(), @@ -558,6 +577,12 @@ void ClearKeyCdm::OnSessionMessage(uint32 session_id, } void ClearKeyCdm::OnSessionReady(uint32 session_id) { + if (session_id == session_id_for_emulated_loadsession_) { + session_id_for_emulated_loadsession_ = MediaKeys::kInvalidSessionId; + host_->OnSessionCreated( + session_id, kLoadableWebSessionId, strlen(kLoadableWebSessionId)); + } + host_->OnSessionReady(session_id); } diff --git a/media/cdm/ppapi/external_clear_key/clear_key_cdm.h b/media/cdm/ppapi/external_clear_key/clear_key_cdm.h index be77340..a79d62b 100644 --- a/media/cdm/ppapi/external_clear_key/clear_key_cdm.h +++ b/media/cdm/ppapi/external_clear_key/clear_key_cdm.h @@ -70,7 +70,7 @@ class ClearKeyCdm : public ClearKeyCdmInterface { private: // Emulates a session stored for |session_id_for_emulated_loadsession_|. This // is necessary since aes_decryptor.cc does not support storing sessions. - void UpdateLoadableSession(); + void LoadLoadableSession(); // ContentDecryptionModule callbacks. void OnSessionCreated(uint32 session_id, const std::string& web_session_id); @@ -133,9 +133,9 @@ class ClearKeyCdm : public ClearKeyCdmInterface { // Timer delay in milliseconds for the next host_->SetTimer() call. int64 timer_delay_ms_; - // Indicates whether a timer has been set to prevent multiple timers from - // running. - bool timer_set_; + // Indicates whether a heartbeat timer has been set to prevent multiple timers + // from running. + bool heartbeat_timer_set_; #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) int channel_count_; |