| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ | 5 #ifndef MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ |
| 6 #define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ | 6 #define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // (just a shim layer in most cases), everything is done in this header file. | 35 // (just a shim layer in most cases), everything is done in this header file. |
| 36 class CdmWrapper { | 36 class CdmWrapper { |
| 37 public: | 37 public: |
| 38 static CdmWrapper* Create(const char* key_system, | 38 static CdmWrapper* Create(const char* key_system, |
| 39 uint32_t key_system_size, | 39 uint32_t key_system_size, |
| 40 GetCdmHostFunc get_cdm_host_func, | 40 GetCdmHostFunc get_cdm_host_func, |
| 41 void* user_data); | 41 void* user_data); |
| 42 | 42 |
| 43 virtual ~CdmWrapper() {}; | 43 virtual ~CdmWrapper() {}; |
| 44 | 44 |
| 45 virtual void Initialize(bool allow_distinctive_identifier, |
| 46 bool allow_persistent_state) = 0; |
| 45 virtual void SetServerCertificate(uint32_t promise_id, | 47 virtual void SetServerCertificate(uint32_t promise_id, |
| 46 const uint8_t* server_certificate_data, | 48 const uint8_t* server_certificate_data, |
| 47 uint32_t server_certificate_data_size) = 0; | 49 uint32_t server_certificate_data_size) = 0; |
| 48 virtual void CreateSessionAndGenerateRequest(uint32_t promise_id, | 50 virtual void CreateSessionAndGenerateRequest(uint32_t promise_id, |
| 49 cdm::SessionType session_type, | 51 cdm::SessionType session_type, |
| 50 const char* init_data_type, | 52 cdm::InitDataType init_data_type, |
| 51 uint32_t init_data_type_size, | |
| 52 const uint8_t* init_data, | 53 const uint8_t* init_data, |
| 53 uint32_t init_data_size) = 0; | 54 uint32_t init_data_size) = 0; |
| 54 virtual void LoadSession(uint32_t promise_id, | 55 virtual void LoadSession(uint32_t promise_id, |
| 55 cdm::SessionType session_type, | 56 cdm::SessionType session_type, |
| 56 const char* session_id, | 57 const char* session_id, |
| 57 uint32_t session_id_size) = 0; | 58 uint32_t session_id_size) = 0; |
| 58 virtual void UpdateSession(uint32_t promise_id, | 59 virtual void UpdateSession(uint32_t promise_id, |
| 59 const char* session_id, | 60 const char* session_id, |
| 60 uint32_t session_id_size, | 61 uint32_t session_id_size, |
| 61 const uint8_t* response, | 62 const uint8_t* response, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 return NULL; | 113 return NULL; |
| 113 | 114 |
| 114 return new CdmWrapperImpl<CdmInterface>( | 115 return new CdmWrapperImpl<CdmInterface>( |
| 115 static_cast<CdmInterface*>(cdm_instance)); | 116 static_cast<CdmInterface*>(cdm_instance)); |
| 116 } | 117 } |
| 117 | 118 |
| 118 virtual ~CdmWrapperImpl() { | 119 virtual ~CdmWrapperImpl() { |
| 119 cdm_->Destroy(); | 120 cdm_->Destroy(); |
| 120 } | 121 } |
| 121 | 122 |
| 123 virtual void Initialize(bool allow_distinctive_identifier, |
| 124 bool allow_persistent_state) override { |
| 125 cdm_->Initialize(allow_distinctive_identifier, allow_persistent_state); |
| 126 } |
| 127 |
| 122 virtual void SetServerCertificate( | 128 virtual void SetServerCertificate( |
| 123 uint32_t promise_id, | 129 uint32_t promise_id, |
| 124 const uint8_t* server_certificate_data, | 130 const uint8_t* server_certificate_data, |
| 125 uint32_t server_certificate_data_size) override { | 131 uint32_t server_certificate_data_size) override { |
| 126 cdm_->SetServerCertificate( | 132 cdm_->SetServerCertificate( |
| 127 promise_id, server_certificate_data, server_certificate_data_size); | 133 promise_id, server_certificate_data, server_certificate_data_size); |
| 128 } | 134 } |
| 129 | 135 |
| 130 virtual void CreateSessionAndGenerateRequest( | 136 virtual void CreateSessionAndGenerateRequest( |
| 131 uint32_t promise_id, | 137 uint32_t promise_id, |
| 132 cdm::SessionType session_type, | 138 cdm::SessionType session_type, |
| 133 const char* init_data_type, | 139 cdm::InitDataType init_data_type, |
| 134 uint32_t init_data_type_size, | |
| 135 const uint8_t* init_data, | 140 const uint8_t* init_data, |
| 136 uint32_t init_data_size) override { | 141 uint32_t init_data_size) override { |
| 137 cdm_->CreateSessionAndGenerateRequest(promise_id, session_type, | 142 cdm_->CreateSessionAndGenerateRequest( |
| 138 init_data_type, init_data_type_size, | 143 promise_id, session_type, init_data_type, init_data, init_data_size); |
| 139 init_data, init_data_size); | |
| 140 } | 144 } |
| 141 | 145 |
| 142 virtual void LoadSession(uint32_t promise_id, | 146 virtual void LoadSession(uint32_t promise_id, |
| 143 cdm::SessionType session_type, | 147 cdm::SessionType session_type, |
| 144 const char* session_id, | 148 const char* session_id, |
| 145 uint32_t session_id_size) override { | 149 uint32_t session_id_size) override { |
| 146 cdm_->LoadSession(promise_id, session_type, session_id, session_id_size); | 150 cdm_->LoadSession(promise_id, session_type, session_id, session_id_size); |
| 147 } | 151 } |
| 148 | 152 |
| 149 virtual void UpdateSession(uint32_t promise_id, | 153 virtual void UpdateSession(uint32_t promise_id, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 private: | 226 private: |
| 223 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { | 227 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { |
| 224 PP_DCHECK(cdm_); | 228 PP_DCHECK(cdm_); |
| 225 } | 229 } |
| 226 | 230 |
| 227 CdmInterface* cdm_; | 231 CdmInterface* cdm_; |
| 228 | 232 |
| 229 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); | 233 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); |
| 230 }; | 234 }; |
| 231 | 235 |
| 232 // Overrides for the cdm::Host_6 methods. | 236 // Overrides for the cdm::Host_7 methods. |
| 233 // TODO(jrummell): Remove these once Host_6 interface is removed. | 237 // TODO(jrummell): Remove these once Host_7 interface is removed. |
| 234 | 238 |
| 235 template <> | 239 template <> |
| 236 void CdmWrapperImpl<cdm::ContentDecryptionModule_6>:: | 240 void CdmWrapperImpl<cdm::ContentDecryptionModule_7>::Initialize( |
| 237 CreateSessionAndGenerateRequest(uint32_t promise_id, | 241 bool allow_distinctive_identifier, |
| 238 cdm::SessionType session_type, | 242 bool allow_persistent_state) { |
| 239 const char* init_data_type, | |
| 240 uint32_t init_data_type_size, | |
| 241 const uint8_t* init_data, | |
| 242 uint32_t init_data_size) { | |
| 243 cdm_->CreateSession(promise_id, init_data_type, init_data_type_size, | |
| 244 init_data, init_data_size, session_type); | |
| 245 } | 243 } |
| 246 | 244 |
| 247 template <> | 245 template <> |
| 248 void CdmWrapperImpl<cdm::ContentDecryptionModule_6>::LoadSession( | 246 void CdmWrapperImpl<cdm::ContentDecryptionModule_7>:: |
| 249 uint32_t promise_id, | 247 CreateSessionAndGenerateRequest(uint32_t promise_id, |
| 250 cdm::SessionType session_type, | 248 cdm::SessionType session_type, |
| 251 const char* session_id, | 249 cdm::InitDataType init_data_type, |
| 252 uint32_t session_id_size) { | 250 const uint8_t* init_data, |
| 253 cdm_->LoadSession(promise_id, session_id, session_id_size); | 251 uint32_t init_data_size) { |
| 254 } | 252 std::string init_data_type_as_string = "unknown"; |
| 255 | 253 switch (init_data_type) { |
| 256 template <> | 254 case cdm::kCenc: |
| 257 void CdmWrapperImpl<cdm::ContentDecryptionModule_6>:: | 255 init_data_type_as_string = "cenc"; |
| 258 OnQueryOutputProtectionStatus(cdm::QueryResult result, | 256 break; |
| 259 uint32_t link_mask, | 257 case cdm::kKeyIds: |
| 260 uint32_t output_protection_mask) { | 258 init_data_type_as_string = "keyids"; |
| 261 if (result == cdm::kQuerySucceeded) { | 259 break; |
| 262 cdm_->OnQueryOutputProtectionStatus(link_mask, output_protection_mask); | 260 case cdm::kWebM: |
| 263 return; | 261 init_data_type_as_string = "webm"; |
| 262 break; |
| 264 } | 263 } |
| 265 | 264 |
| 266 // Invalid results, so return 0, 0 to indicate failure. | 265 cdm_->CreateSessionAndGenerateRequest( |
| 267 cdm_->OnQueryOutputProtectionStatus(0, 0); | 266 promise_id, session_type, &init_data_type_as_string[0], |
| 267 init_data_type_as_string.length(), init_data, init_data_size); |
| 268 } | 268 } |
| 269 | 269 |
| 270 CdmWrapper* CdmWrapper::Create(const char* key_system, | 270 CdmWrapper* CdmWrapper::Create(const char* key_system, |
| 271 uint32_t key_system_size, | 271 uint32_t key_system_size, |
| 272 GetCdmHostFunc get_cdm_host_func, | 272 GetCdmHostFunc get_cdm_host_func, |
| 273 void* user_data) { | 273 void* user_data) { |
| 274 static_assert(cdm::ContentDecryptionModule::kVersion == | 274 static_assert(cdm::ContentDecryptionModule::kVersion == |
| 275 cdm::ContentDecryptionModule_7::kVersion, | 275 cdm::ContentDecryptionModule_8::kVersion, |
| 276 "update the code below"); | 276 "update the code below"); |
| 277 | 277 |
| 278 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation. | 278 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation. |
| 279 // Always update this DCHECK when updating this function. | 279 // Always update this DCHECK when updating this function. |
| 280 // If this check fails, update this function and DCHECK or update | 280 // If this check fails, update this function and DCHECK or update |
| 281 // IsSupportedCdmInterfaceVersion(). | 281 // IsSupportedCdmInterfaceVersion(). |
| 282 PP_DCHECK(!IsSupportedCdmInterfaceVersion( | 282 PP_DCHECK(!IsSupportedCdmInterfaceVersion( |
| 283 cdm::ContentDecryptionModule_7::kVersion + 1) && | 283 cdm::ContentDecryptionModule_8::kVersion + 1) && |
| 284 IsSupportedCdmInterfaceVersion( |
| 285 cdm::ContentDecryptionModule_8::kVersion) && |
| 284 IsSupportedCdmInterfaceVersion( | 286 IsSupportedCdmInterfaceVersion( |
| 285 cdm::ContentDecryptionModule_7::kVersion) && | 287 cdm::ContentDecryptionModule_7::kVersion) && |
| 286 IsSupportedCdmInterfaceVersion( | |
| 287 cdm::ContentDecryptionModule_6::kVersion) && | |
| 288 !IsSupportedCdmInterfaceVersion( | 288 !IsSupportedCdmInterfaceVersion( |
| 289 cdm::ContentDecryptionModule_6::kVersion - 1)); | 289 cdm::ContentDecryptionModule_7::kVersion - 1)); |
| 290 | 290 |
| 291 // Try to create the CDM using the latest CDM interface version. | 291 // Try to create the CDM using the latest CDM interface version. |
| 292 CdmWrapper* cdm_wrapper = | 292 CdmWrapper* cdm_wrapper = |
| 293 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( | 293 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( |
| 294 key_system, key_system_size, get_cdm_host_func, user_data); | 294 key_system, key_system_size, get_cdm_host_func, user_data); |
| 295 | 295 |
| 296 // If |cdm_wrapper| is NULL, try to create the CDM using older supported | 296 // If |cdm_wrapper| is NULL, try to create the CDM using older supported |
| 297 // versions of the CDM interface here. | 297 // versions of the CDM interface here. |
| 298 if (!cdm_wrapper) { | 298 if (!cdm_wrapper) { |
| 299 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_6>::Create( | 299 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_7>::Create( |
| 300 key_system, key_system_size, get_cdm_host_func, user_data); | 300 key_system, key_system_size, get_cdm_host_func, user_data); |
| 301 } | 301 } |
| 302 | 302 |
| 303 return cdm_wrapper; | 303 return cdm_wrapper; |
| 304 } | 304 } |
| 305 | 305 |
| 306 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain | 306 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain |
| 307 // stub implementations for new or modified methods that the older CDM interface | 307 // stub implementations for new or modified methods that the older CDM interface |
| 308 // does not have. | 308 // does not have. |
| 309 // Also update supported_cdm_versions.h. | 309 // Also update supported_cdm_versions.h. |
| 310 static_assert(cdm::ContentDecryptionModule::kVersion == | 310 static_assert(cdm::ContentDecryptionModule::kVersion == |
| 311 cdm::ContentDecryptionModule_7::kVersion, | 311 cdm::ContentDecryptionModule_8::kVersion, |
| 312 "ensure cdm wrapper templates have old version support"); | 312 "ensure cdm wrapper templates have old version support"); |
| 313 | 313 |
| 314 } // namespace media | 314 } // namespace media |
| 315 | 315 |
| 316 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ | 316 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ |
| OLD | NEW |