| 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_CDM_WRAPPER_H_ | 5 #ifndef MEDIA_CDM_CDM_WRAPPER_H_ |
| 6 #define MEDIA_CDM_CDM_WRAPPER_H_ | 6 #define MEDIA_CDM_CDM_WRAPPER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 } | 239 } |
| 240 | 240 |
| 241 private: | 241 private: |
| 242 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { PLATFORM_DCHECK(cdm_); } | 242 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { PLATFORM_DCHECK(cdm_); } |
| 243 | 243 |
| 244 CdmInterface* cdm_; | 244 CdmInterface* cdm_; |
| 245 | 245 |
| 246 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); | 246 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); |
| 247 }; | 247 }; |
| 248 | 248 |
| 249 // Overrides for the cdm::Host_7 methods. | |
| 250 // TODO(jrummell): Remove these once Host_7 interface is removed. | |
| 251 | |
| 252 template <> | |
| 253 void CdmWrapperImpl<cdm::ContentDecryptionModule_7>::Initialize( | |
| 254 bool allow_distinctive_identifier, | |
| 255 bool allow_persistent_state) {} | |
| 256 | |
| 257 template <> | |
| 258 void CdmWrapperImpl<cdm::ContentDecryptionModule_7>:: | |
| 259 CreateSessionAndGenerateRequest(uint32_t promise_id, | |
| 260 cdm::SessionType session_type, | |
| 261 cdm::InitDataType init_data_type, | |
| 262 const uint8_t* init_data, | |
| 263 uint32_t init_data_size) { | |
| 264 std::string init_data_type_as_string = "unknown"; | |
| 265 switch (init_data_type) { | |
| 266 case cdm::kCenc: | |
| 267 init_data_type_as_string = "cenc"; | |
| 268 break; | |
| 269 case cdm::kKeyIds: | |
| 270 init_data_type_as_string = "keyids"; | |
| 271 break; | |
| 272 case cdm::kWebM: | |
| 273 init_data_type_as_string = "webm"; | |
| 274 break; | |
| 275 } | |
| 276 | |
| 277 cdm_->CreateSessionAndGenerateRequest( | |
| 278 promise_id, session_type, &init_data_type_as_string[0], | |
| 279 init_data_type_as_string.length(), init_data, init_data_size); | |
| 280 } | |
| 281 | |
| 282 CdmWrapper* CdmWrapper::Create(CreateCdmFunc create_cdm_func, | 249 CdmWrapper* CdmWrapper::Create(CreateCdmFunc create_cdm_func, |
| 283 const char* key_system, | 250 const char* key_system, |
| 284 uint32_t key_system_size, | 251 uint32_t key_system_size, |
| 285 GetCdmHostFunc get_cdm_host_func, | 252 GetCdmHostFunc get_cdm_host_func, |
| 286 void* user_data) { | 253 void* user_data) { |
| 287 static_assert(cdm::ContentDecryptionModule::kVersion == | 254 static_assert(cdm::ContentDecryptionModule::kVersion == |
| 288 cdm::ContentDecryptionModule_8::kVersion, | 255 cdm::ContentDecryptionModule_8::kVersion, |
| 289 "update the code below"); | 256 "update the code below"); |
| 290 | 257 |
| 291 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation. | 258 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation. |
| 292 // Always update this DCHECK when updating this function. | 259 // Always update this DCHECK when updating this function. |
| 293 // If this check fails, update this function and DCHECK or update | 260 // If this check fails, update this function and DCHECK or update |
| 294 // IsSupportedCdmInterfaceVersion(). | 261 // IsSupportedCdmInterfaceVersion(). |
| 295 PLATFORM_DCHECK(!IsSupportedCdmInterfaceVersion( | 262 PLATFORM_DCHECK(!IsSupportedCdmInterfaceVersion( |
| 296 cdm::ContentDecryptionModule_8::kVersion + 1) && | 263 cdm::ContentDecryptionModule_8::kVersion + 1) && |
| 297 IsSupportedCdmInterfaceVersion( | 264 IsSupportedCdmInterfaceVersion( |
| 298 cdm::ContentDecryptionModule_8::kVersion) && | 265 cdm::ContentDecryptionModule_8::kVersion) && |
| 299 IsSupportedCdmInterfaceVersion( | |
| 300 cdm::ContentDecryptionModule_7::kVersion) && | |
| 301 !IsSupportedCdmInterfaceVersion( | 266 !IsSupportedCdmInterfaceVersion( |
| 302 cdm::ContentDecryptionModule_7::kVersion - 1)); | 267 cdm::ContentDecryptionModule_8::kVersion - 1)); |
| 303 | 268 |
| 304 // Try to create the CDM using the latest CDM interface version. | 269 // Try to create the CDM using the latest CDM interface version. |
| 305 CdmWrapper* cdm_wrapper = | 270 CdmWrapper* cdm_wrapper = |
| 306 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( | 271 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( |
| 307 create_cdm_func, key_system, key_system_size, get_cdm_host_func, | 272 create_cdm_func, key_system, key_system_size, get_cdm_host_func, |
| 308 user_data); | 273 user_data); |
| 309 | 274 |
| 310 // If |cdm_wrapper| is NULL, try to create the CDM using older supported | |
| 311 // versions of the CDM interface here. | |
| 312 if (!cdm_wrapper) { | |
| 313 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_7>::Create( | |
| 314 create_cdm_func, key_system, key_system_size, get_cdm_host_func, | |
| 315 user_data); | |
| 316 } | |
| 317 | |
| 318 return cdm_wrapper; | 275 return cdm_wrapper; |
| 319 } | 276 } |
| 320 | 277 |
| 321 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain | 278 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain |
| 322 // stub implementations for new or modified methods that the older CDM interface | 279 // stub implementations for new or modified methods that the older CDM interface |
| 323 // does not have. | 280 // does not have. |
| 324 // Also update supported_cdm_versions.h. | 281 // Also update supported_cdm_versions.h. |
| 325 static_assert(cdm::ContentDecryptionModule::kVersion == | 282 static_assert(cdm::ContentDecryptionModule::kVersion == |
| 326 cdm::ContentDecryptionModule_8::kVersion, | 283 cdm::ContentDecryptionModule_8::kVersion, |
| 327 "ensure cdm wrapper templates have old version support"); | 284 "ensure cdm wrapper templates have old version support"); |
| 328 | 285 |
| 329 } // namespace media | 286 } // namespace media |
| 330 | 287 |
| 331 #undef PLATFORM_DCHECK | 288 #undef PLATFORM_DCHECK |
| 332 | 289 |
| 333 #endif // MEDIA_CDM_CDM_WRAPPER_H_ | 290 #endif // MEDIA_CDM_CDM_WRAPPER_H_ |
| OLD | NEW |