cdm_wrapper.h revision 1e9bf3e0803691d0a228da41fc608347b6db4340
18bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 28bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 38bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// found in the LICENSE file. 48bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#ifndef MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 78bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 88bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/basictypes.h" 98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "media/cdm/ppapi/api/content_decryption_module.h" 108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "media/cdm/ppapi/cdm_helpers.h" 118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "ppapi/cpp/logging.h" 128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)namespace media { 148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// CdmWrapper wraps different versions of ContentDecryptionModule interfaces and 168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// exposes a common interface to the caller. 178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// 188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// The caller should call CdmWrapper::Create() to create a CDM instance. 198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// CdmWrapper will first try to create a CDM instance that supports the latest 208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// CDM interface (ContentDecryptionModule). If such an instance cannot be 218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// created (e.g. an older CDM was loaded), CdmWrapper will try to create a CDM 228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// that supports an older version of CDM interface (e.g. 238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// ContentDecryptionModule_*). Internally CdmWrapper converts the CdmWrapper 248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// calls to corresponding ContentDecryptionModule calls. 258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// 268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Note that CdmWrapper interface always reflects the latest state of content 278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// decryption related PPAPI APIs (e.g. pp::ContentDecryptor_Private). 288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// 298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Since this file is highly templated and default implementations are short 308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// (just a shim layer in most cases), everything is done in this header file. 318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class CdmWrapper { 328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public: 338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static CdmWrapper* Create(const char* key_system, 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t key_system_size, 358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) GetCdmHostFunc get_cdm_host_func, 368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void* user_data); 378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual ~CdmWrapper() {}; 398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status GenerateKeyRequest(const char* type, 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t type_size, 428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const uint8_t* init_data, 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t init_data_size) = 0; 448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status AddKey(const char* session_id, 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t session_id_size, 468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const uint8_t* key, 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t key_size, 488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const uint8_t* key_id, 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t key_id_size) = 0; 508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status CancelKeyRequest(const char* session_id, 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t session_id_size) = 0; 528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void TimerExpired(void* context) = 0; 538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, 548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm::DecryptedBlock* decrypted_buffer) = 0; 558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status InitializeAudioDecoder( 568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::AudioDecoderConfig& audio_decoder_config) = 0; 578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status InitializeVideoDecoder( 588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::VideoDecoderConfig& video_decoder_config) = 0; 598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void DeinitializeDecoder(cdm::StreamType decoder_type) = 0; 608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void ResetDecoder(cdm::StreamType decoder_type) = 0; 618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status DecryptAndDecodeFrame( 628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::InputBuffer& encrypted_buffer, 638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm::VideoFrame* video_frame) = 0; 648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status DecryptAndDecodeSamples( 658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::InputBuffer& encrypted_buffer, 668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm::AudioFrames* audio_frames) = 0; 678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void OnPlatformChallengeResponse( 688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::PlatformChallengeResponse& response) = 0; 698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void OnQueryOutputProtectionStatus( 708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) uint32_t link_mask, 718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) uint32_t output_protection_mask) = 0; 728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) protected: 748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CdmWrapper() {}; 758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private: 778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(CdmWrapper); 788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}; 798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Template class that does the CdmWrapper -> CdmInterface conversion. Default 818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// implementations are provided. Any methods that need special treatment should 828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// be specialized. 838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)template <class CdmInterface> 848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class CdmWrapperImpl : public CdmWrapper { 858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) public: 868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static CdmWrapper* Create(const char* key_system, 871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t key_system_size, 888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) GetCdmHostFunc get_cdm_host_func, 898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void* user_data) { 908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void* cdm_instance = ::CreateCdmInstance( 918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CdmInterface::kVersion, key_system, key_system_size, get_cdm_host_func, 928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) user_data); 938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (!cdm_instance) 948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return NULL; 958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return new CdmWrapperImpl<CdmInterface>( 978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static_cast<CdmInterface*>(cdm_instance)); 988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual ~CdmWrapperImpl() { 1018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm_->Destroy(); 1028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status GenerateKeyRequest(const char* type, 1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t type_size, 1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const uint8_t* init_data, 1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t init_data_size) OVERRIDE { 1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_->GenerateKeyRequest(type, type_size, init_data, init_data_size); 1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status AddKey(const char* session_id, 1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t session_id_size, 1138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const uint8_t* key, 1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t key_size, 1158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const uint8_t* key_id, 1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t key_id_size) OVERRIDE { 1178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_->AddKey( 1188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) session_id, session_id_size, key, key_size, key_id, key_id_size); 1198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status CancelKeyRequest(const char* session_id, 1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t session_id_size) OVERRIDE { 1238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_->CancelKeyRequest(session_id, session_id_size); 1248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void TimerExpired(void* context) OVERRIDE { 1278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm_->TimerExpired(context); 1288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, 1318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm::DecryptedBlock* decrypted_buffer) OVERRIDE { 1328bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_->Decrypt(encrypted_buffer, decrypted_buffer); 1338bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status InitializeAudioDecoder( 1368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::AudioDecoderConfig& audio_decoder_config) OVERRIDE { 1378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_->InitializeAudioDecoder(audio_decoder_config); 1388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status InitializeVideoDecoder( 1418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::VideoDecoderConfig& video_decoder_config) OVERRIDE { 1428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_->InitializeVideoDecoder(video_decoder_config); 1438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void DeinitializeDecoder(cdm::StreamType decoder_type) OVERRIDE { 1468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm_->DeinitializeDecoder(decoder_type); 1478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void ResetDecoder(cdm::StreamType decoder_type) OVERRIDE { 1508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm_->ResetDecoder(decoder_type); 1518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status DecryptAndDecodeFrame( 1548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::InputBuffer& encrypted_buffer, 1558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm::VideoFrame* video_frame) OVERRIDE { 1568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_->DecryptAndDecodeFrame(encrypted_buffer, video_frame); 1578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1588bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual cdm::Status DecryptAndDecodeSamples( 1608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::InputBuffer& encrypted_buffer, 1618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm::AudioFrames* audio_frames) OVERRIDE { 1628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_->DecryptAndDecodeSamples(encrypted_buffer, audio_frames); 1638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1648bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void OnPlatformChallengeResponse( 1668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::PlatformChallengeResponse& response) OVERRIDE { 1678bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm_->OnPlatformChallengeResponse(response); 1688bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) virtual void OnQueryOutputProtectionStatus( 1718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) uint32_t link_mask, 1728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) uint32_t output_protection_mask) OVERRIDE { 1738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm_->OnQueryOutputProtectionStatus(link_mask, output_protection_mask); 1748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) private: 1778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { 1788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PP_DCHECK(cdm_); 1798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1808bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1818bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CdmInterface* cdm_; 1828bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); 1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}; 1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// Specializations for ContentDecryptionModule_1. 1878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)template <> void CdmWrapperImpl<cdm::ContentDecryptionModule_1>:: 1898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) OnPlatformChallengeResponse( 1908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const cdm::PlatformChallengeResponse& response) { 1918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PP_NOTREACHED(); 1928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)template <> void CdmWrapperImpl<cdm::ContentDecryptionModule_1>:: 1958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) OnQueryOutputProtectionStatus(uint32_t link_mask, 1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) uint32_t output_protection_mask) { 1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) PP_NOTREACHED(); 1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)template <> cdm::Status CdmWrapperImpl<cdm::ContentDecryptionModule_1>:: 2018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DecryptAndDecodeSamples(const cdm::InputBuffer& encrypted_buffer, 2028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm::AudioFrames* audio_frames) { 2038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) AudioFramesImpl audio_frames_1; 2048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm::Status status = 2058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm_->DecryptAndDecodeSamples(encrypted_buffer, &audio_frames_1); 2068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (status != cdm::kSuccess) 2078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return status; 2088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) audio_frames->SetFrameBuffer(audio_frames_1.PassFrameBuffer()); 2108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) audio_frames->SetFormat(cdm::kAudioFormatS16); 2118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm::kSuccess; 2128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 2138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)CdmWrapper* CdmWrapper::Create(const char* key_system, 2151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) uint32_t key_system_size, 2168bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) GetCdmHostFunc get_cdm_host_func, 2178bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void* user_data) { 2188bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Try to create the CDM using the latest CDM interface version. 2198bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CdmWrapper* cdm_adapter = 2208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( 2218bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) key_system, key_system_size, get_cdm_host_func, user_data); 2228bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) if (cdm_adapter) 2238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_adapter; 2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2258bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Try to see if the CDM supports older version(s) of CDM interface(s). 2268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) cdm_adapter = CdmWrapperImpl<cdm::ContentDecryptionModule_1>::Create( 2278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) key_system, key_system_size, get_cdm_host_func, user_data); 2288bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return cdm_adapter; 2298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 2308bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2318bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)// When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain 2321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// stub implementations for new or modified methods that the older CDM interface 2331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// does not have. 2341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == 2351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) cdm::ContentDecryptionModule_2::kVersion, 2368bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ensure_cdm_wrapper_templates_have_old_version_support); 2378bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2388bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} // namespace media 2398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 2408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 241