diff options
Diffstat (limited to 'media/cdm/ppapi/cdm_wrapper.h')
-rw-r--r-- | media/cdm/ppapi/cdm_wrapper.h | 198 |
1 files changed, 173 insertions, 25 deletions
diff --git a/media/cdm/ppapi/cdm_wrapper.h b/media/cdm/ppapi/cdm_wrapper.h index cf8e88b..665b6b6 100644 --- a/media/cdm/ppapi/cdm_wrapper.h +++ b/media/cdm/ppapi/cdm_wrapper.h @@ -42,18 +42,23 @@ class CdmWrapper { virtual ~CdmWrapper() {}; - virtual void CreateSession(uint32_t session_id, - const char* content_type, - uint32_t content_type_size, + virtual void CreateSession(uint32_t promise_id, + const char* init_data_type, + uint32_t init_data_type_size, const uint8_t* init_data, - uint32_t init_data_size) = 0; - virtual void LoadSession(uint32_t session_id, + uint32_t init_data_size, + cdm::SessionType session_type) = 0; + virtual void LoadSession(uint32_t promise_id, const char* web_session_id, uint32_t web_session_id_size) = 0; - virtual void UpdateSession(uint32_t session_id, + virtual void UpdateSession(uint32_t promise_id, + const char* web_session_id, + uint32_t web_session_id_size, const uint8_t* response, uint32_t response_size) = 0; - virtual void ReleaseSession(uint32_t session_id) = 0; + virtual void ReleaseSession(uint32_t promise_id, + const char* web_session_id, + uint32_t web_session_id_size) = 0; virtual void TimerExpired(void* context) = 0; virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, cdm::DecryptedBlock* decrypted_buffer) = 0; @@ -75,6 +80,21 @@ class CdmWrapper { uint32_t link_mask, uint32_t output_protection_mask) = 0; + // Helper function for the cdm::Host_4 methods. Calls to CreateSession(), + // LoadSession(), UpdateSession(), and ReleaseSession() pass in promise ids, + // but the CDM interface needs session ids. For create and load, we need to + // create a new session_id to pass to the CDM. For update and release, we need + // to look up |web_session_id| and convert it into the existing |session_id|. + // Since the callbacks don't come through this interface, cdm_adapter needs to + // create the mapping (and delete it on release). + // TODO(jrummell): Remove these once Host_4 interface is removed. + virtual uint32_t LookupPromiseId(uint32_t session_id) = 0; + virtual void AssignWebSessionId(uint32_t session_id, + const char* web_session_id, + uint32_t web_session_id_size) = 0; + virtual std::string LookupWebSessionId(uint32_t session_id) = 0; + virtual void DropWebSessionId(std::string web_session_id) = 0; + protected: CdmWrapper() {} @@ -106,29 +126,42 @@ class CdmWrapperImpl : public CdmWrapper { cdm_->Destroy(); } - virtual void CreateSession(uint32_t session_id, - const char* content_type, - uint32_t content_type_size, + virtual void CreateSession(uint32_t promise_id, + const char* init_data_type, + uint32_t init_data_type_size, const uint8_t* init_data, - uint32_t init_data_size) OVERRIDE { - cdm_->CreateSession( - session_id, content_type, content_type_size, init_data, init_data_size); + uint32_t init_data_size, + cdm::SessionType session_type) OVERRIDE { + cdm_->CreateSession(promise_id, + init_data_type, + init_data_type_size, + init_data, + init_data_size, + session_type); } - virtual void LoadSession(uint32_t session_id, + virtual void LoadSession(uint32_t promise_id, const char* web_session_id, uint32_t web_session_id_size) OVERRIDE { - cdm_->LoadSession(session_id, web_session_id, web_session_id_size); + cdm_->LoadSession(promise_id, web_session_id, web_session_id_size); } - virtual void UpdateSession(uint32_t session_id, + virtual void UpdateSession(uint32_t promise_id, + const char* web_session_id, + uint32_t web_session_id_size, const uint8_t* response, uint32_t response_size) OVERRIDE { - cdm_->UpdateSession(session_id, response, response_size); + cdm_->UpdateSession(promise_id, + web_session_id, + web_session_id_size, + response, + response_size); } - virtual void ReleaseSession(uint32_t session_id) OVERRIDE { - cdm_->ReleaseSession(session_id); + virtual void ReleaseSession(uint32_t promise_id, + const char* web_session_id, + uint32_t web_session_id_size) OVERRIDE { + cdm_->ReleaseSession(promise_id, web_session_id, web_session_id_size); } virtual void TimerExpired(void* context) OVERRIDE { @@ -181,22 +214,133 @@ class CdmWrapperImpl : public CdmWrapper { cdm_->OnQueryOutputProtectionStatus(link_mask, output_protection_mask); } + uint32_t CreateSessionId() { + return next_session_id_++; + } + + void RegisterPromise(uint32_t session_id, uint32_t promise_id) { + PP_DCHECK(promise_to_session_id_map_.find(session_id) == + promise_to_session_id_map_.end()); + promise_to_session_id_map_.insert(std::make_pair(session_id, promise_id)); + } + + virtual uint32_t LookupPromiseId(uint32_t session_id) { + std::map<uint32_t, uint32_t>::iterator it = + promise_to_session_id_map_.find(session_id); + if (it == promise_to_session_id_map_.end()) + return 0; + uint32_t promise_id = it->second; + promise_to_session_id_map_.erase(it); + return promise_id; + } + + virtual void AssignWebSessionId(uint32_t session_id, + const char* web_session_id, + uint32_t web_session_id_size) { + web_session_to_session_id_map_.insert(std::make_pair( + std::string(web_session_id, web_session_id_size), session_id)); + } + + uint32_t LookupSessionId(std::string web_session_id) { + return web_session_to_session_id_map_.find(web_session_id)->second; + } + + virtual std::string LookupWebSessionId(uint32_t session_id) { + std::map<std::string, uint32_t>::iterator it; + for (it = web_session_to_session_id_map_.begin(); + it != web_session_to_session_id_map_.end(); + ++it) { + if (it->second == session_id) + return it->first; + } + PP_NOTREACHED(); + return std::string(); + } + + virtual void DropWebSessionId(std::string web_session_id) { + web_session_to_session_id_map_.erase(web_session_id); + } + private: - CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { + CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm), next_session_id_(100) { PP_DCHECK(cdm_); } CdmInterface* cdm_; + std::map<uint32_t, uint32_t> promise_to_session_id_map_; + uint32_t next_session_id_; + std::map<std::string, uint32_t> web_session_to_session_id_map_; + DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); }; +// Overrides for the cdm::Host_4 methods. Calls to CreateSession(), +// LoadSession(), UpdateSession(), and ReleaseSession() pass in promise ids, +// but the CDM interface needs session ids. For create and load, we need to +// create a new session_id to pass to the CDM. For update and release, we need +// to look up |web_session_id| and convert it into the existing |session_id|. +// Since the callbacks don't come through this interface, cdm_adapter needs to +// create the mapping (and delete it on release). +// TODO(jrummell): Remove these once Host_4 interface is removed. + +template <> +void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::CreateSession( + uint32_t promise_id, + const char* init_data_type, + uint32_t init_data_type_size, + const uint8_t* init_data, + uint32_t init_data_size, + cdm::SessionType session_type) { + uint32_t session_id = CreateSessionId(); + RegisterPromise(session_id, promise_id); + cdm_->CreateSession(session_id, + init_data_type, + init_data_type_size, + init_data, + init_data_size); +} + +template <> +void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::LoadSession( + uint32_t promise_id, + const char* web_session_id, + uint32_t web_session_id_size) { + uint32_t session_id = CreateSessionId(); + RegisterPromise(session_id, promise_id); + cdm_->LoadSession(session_id, web_session_id, web_session_id_size); +} + +template <> +void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::UpdateSession( + uint32_t promise_id, + const char* web_session_id, + uint32_t web_session_id_size, + const uint8_t* response, + uint32_t response_size) { + std::string web_session_str(web_session_id, web_session_id_size); + uint32_t session_id = LookupSessionId(web_session_str); + RegisterPromise(session_id, promise_id); + cdm_->UpdateSession(session_id, response, response_size); +} + +template <> +void CdmWrapperImpl<cdm::ContentDecryptionModule_4>::ReleaseSession( + uint32_t promise_id, + const char* web_session_id, + uint32_t web_session_id_size) { + std::string web_session_str(web_session_id, web_session_id_size); + uint32_t session_id = LookupSessionId(web_session_str); + RegisterPromise(session_id, promise_id); + cdm_->ReleaseSession(session_id); +} + CdmWrapper* CdmWrapper::Create(const char* key_system, uint32_t key_system_size, GetCdmHostFunc get_cdm_host_func, void* user_data) { COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == - cdm::ContentDecryptionModule_4::kVersion, + cdm::ContentDecryptionModule_5::kVersion, update_code_below); // Ensure IsSupportedCdmInterfaceVersion() matches this implementation. @@ -207,18 +351,22 @@ CdmWrapper* CdmWrapper::Create(const char* key_system, !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion + 1) && IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion) && - !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule::kVersion - + IsSupportedCdmInterfaceVersion( + cdm::ContentDecryptionModule_4::kVersion) && + !IsSupportedCdmInterfaceVersion(cdm::ContentDecryptionModule_4::kVersion - 1)); // Try to create the CDM using the latest CDM interface version. CdmWrapper* cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( key_system, key_system_size, get_cdm_host_func, user_data); + if (cdm_wrapper) + return cdm_wrapper; // If |cdm_wrapper| is NULL, try to create the CDM using older supported // versions of the CDM interface. - // No older versions of CDM interface supported. - + cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_4>::Create( + key_system, key_system_size, get_cdm_host_func, user_data); return cdm_wrapper; } @@ -227,7 +375,7 @@ CdmWrapper* CdmWrapper::Create(const char* key_system, // does not have. // Also update supported_cdm_versions.h. COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == - cdm::ContentDecryptionModule_4::kVersion, + cdm::ContentDecryptionModule_5::kVersion, ensure_cdm_wrapper_templates_have_old_version_support); } // namespace media |