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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "media/cdm/ppapi/api/content_decryption_module.h" | 9 #include "media/cdm/ppapi/api/content_decryption_module.h" |
10 #include "media/cdm/ppapi/cdm_helpers.h" | 10 #include "media/cdm/ppapi/cdm_helpers.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 // calls to corresponding ContentDecryptionModule calls. | 24 // calls to corresponding ContentDecryptionModule calls. |
25 // | 25 // |
26 // Note that CdmWrapper interface always reflects the latest state of content | 26 // Note that CdmWrapper interface always reflects the latest state of content |
27 // decryption related PPAPI APIs (e.g. pp::ContentDecryptor_Private). | 27 // decryption related PPAPI APIs (e.g. pp::ContentDecryptor_Private). |
28 // | 28 // |
29 // Since this file is highly templated and default implementations are short | 29 // Since this file is highly templated and default implementations are short |
30 // (just a shim layer in most cases), everything is done in this header file. | 30 // (just a shim layer in most cases), everything is done in this header file. |
31 class CdmWrapper { | 31 class CdmWrapper { |
32 public: | 32 public: |
33 static CdmWrapper* Create(const char* key_system, | 33 static CdmWrapper* Create(const char* key_system, |
34 int key_system_size, | 34 uint32_t key_system_size, |
35 GetCdmHostFunc get_cdm_host_func, | 35 GetCdmHostFunc get_cdm_host_func, |
36 void* user_data); | 36 void* user_data); |
37 | 37 |
38 virtual ~CdmWrapper() {}; | 38 virtual ~CdmWrapper() {}; |
39 | 39 |
40 virtual cdm::Status GenerateKeyRequest(const char* type, | 40 virtual cdm::Status GenerateKeyRequest(const char* type, |
41 int type_size, | 41 uint32_t type_size, |
42 const uint8_t* init_data, | 42 const uint8_t* init_data, |
43 int init_data_size) = 0; | 43 uint32_t init_data_size) = 0; |
44 virtual cdm::Status AddKey(const char* session_id, | 44 virtual cdm::Status AddKey(const char* session_id, |
45 int session_id_size, | 45 uint32_t session_id_size, |
46 const uint8_t* key, | 46 const uint8_t* key, |
47 int key_size, | 47 uint32_t key_size, |
48 const uint8_t* key_id, | 48 const uint8_t* key_id, |
49 int key_id_size) = 0; | 49 uint32_t key_id_size) = 0; |
50 virtual cdm::Status CancelKeyRequest(const char* session_id, | 50 virtual cdm::Status CancelKeyRequest(const char* session_id, |
51 int session_id_size) = 0; | 51 uint32_t session_id_size) = 0; |
52 virtual void TimerExpired(void* context) = 0; | 52 virtual void TimerExpired(void* context) = 0; |
53 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, | 53 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, |
54 cdm::DecryptedBlock* decrypted_buffer) = 0; | 54 cdm::DecryptedBlock* decrypted_buffer) = 0; |
55 virtual cdm::Status InitializeAudioDecoder( | 55 virtual cdm::Status InitializeAudioDecoder( |
56 const cdm::AudioDecoderConfig& audio_decoder_config) = 0; | 56 const cdm::AudioDecoderConfig& audio_decoder_config) = 0; |
57 virtual cdm::Status InitializeVideoDecoder( | 57 virtual cdm::Status InitializeVideoDecoder( |
58 const cdm::VideoDecoderConfig& video_decoder_config) = 0; | 58 const cdm::VideoDecoderConfig& video_decoder_config) = 0; |
59 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) = 0; | 59 virtual void DeinitializeDecoder(cdm::StreamType decoder_type) = 0; |
60 virtual void ResetDecoder(cdm::StreamType decoder_type) = 0; | 60 virtual void ResetDecoder(cdm::StreamType decoder_type) = 0; |
61 virtual cdm::Status DecryptAndDecodeFrame( | 61 virtual cdm::Status DecryptAndDecodeFrame( |
(...skipping 15 matching lines...) Expand all Loading... |
77 DISALLOW_COPY_AND_ASSIGN(CdmWrapper); | 77 DISALLOW_COPY_AND_ASSIGN(CdmWrapper); |
78 }; | 78 }; |
79 | 79 |
80 // Template class that does the CdmWrapper -> CdmInterface conversion. Default | 80 // Template class that does the CdmWrapper -> CdmInterface conversion. Default |
81 // implementations are provided. Any methods that need special treatment should | 81 // implementations are provided. Any methods that need special treatment should |
82 // be specialized. | 82 // be specialized. |
83 template <class CdmInterface> | 83 template <class CdmInterface> |
84 class CdmWrapperImpl : public CdmWrapper { | 84 class CdmWrapperImpl : public CdmWrapper { |
85 public: | 85 public: |
86 static CdmWrapper* Create(const char* key_system, | 86 static CdmWrapper* Create(const char* key_system, |
87 int key_system_size, | 87 uint32_t key_system_size, |
88 GetCdmHostFunc get_cdm_host_func, | 88 GetCdmHostFunc get_cdm_host_func, |
89 void* user_data) { | 89 void* user_data) { |
90 void* cdm_instance = ::CreateCdmInstance( | 90 void* cdm_instance = ::CreateCdmInstance( |
91 CdmInterface::kVersion, key_system, key_system_size, get_cdm_host_func, | 91 CdmInterface::kVersion, key_system, key_system_size, get_cdm_host_func, |
92 user_data); | 92 user_data); |
93 if (!cdm_instance) | 93 if (!cdm_instance) |
94 return NULL; | 94 return NULL; |
95 | 95 |
96 return new CdmWrapperImpl<CdmInterface>( | 96 return new CdmWrapperImpl<CdmInterface>( |
97 static_cast<CdmInterface*>(cdm_instance)); | 97 static_cast<CdmInterface*>(cdm_instance)); |
98 } | 98 } |
99 | 99 |
100 virtual ~CdmWrapperImpl() { | 100 virtual ~CdmWrapperImpl() { |
101 cdm_->Destroy(); | 101 cdm_->Destroy(); |
102 } | 102 } |
103 | 103 |
104 virtual cdm::Status GenerateKeyRequest(const char* type, | 104 virtual cdm::Status GenerateKeyRequest(const char* type, |
105 int type_size, | 105 uint32_t type_size, |
106 const uint8_t* init_data, | 106 const uint8_t* init_data, |
107 int init_data_size) OVERRIDE { | 107 uint32_t init_data_size) OVERRIDE { |
108 return cdm_->GenerateKeyRequest(type, type_size, init_data, init_data_size); | 108 return cdm_->GenerateKeyRequest(type, type_size, init_data, init_data_size); |
109 } | 109 } |
110 | 110 |
111 virtual cdm::Status AddKey(const char* session_id, | 111 virtual cdm::Status AddKey(const char* session_id, |
112 int session_id_size, | 112 uint32_t session_id_size, |
113 const uint8_t* key, | 113 const uint8_t* key, |
114 int key_size, | 114 uint32_t key_size, |
115 const uint8_t* key_id, | 115 const uint8_t* key_id, |
116 int key_id_size) OVERRIDE { | 116 uint32_t key_id_size) OVERRIDE { |
117 return cdm_->AddKey( | 117 return cdm_->AddKey( |
118 session_id, session_id_size, key, key_size, key_id, key_id_size); | 118 session_id, session_id_size, key, key_size, key_id, key_id_size); |
119 } | 119 } |
120 | 120 |
121 virtual cdm::Status CancelKeyRequest(const char* session_id, | 121 virtual cdm::Status CancelKeyRequest(const char* session_id, |
122 int session_id_size) OVERRIDE { | 122 uint32_t session_id_size) OVERRIDE { |
123 return cdm_->CancelKeyRequest(session_id, session_id_size); | 123 return cdm_->CancelKeyRequest(session_id, session_id_size); |
124 } | 124 } |
125 | 125 |
126 virtual void TimerExpired(void* context) OVERRIDE { | 126 virtual void TimerExpired(void* context) OVERRIDE { |
127 cdm_->TimerExpired(context); | 127 cdm_->TimerExpired(context); |
128 } | 128 } |
129 | 129 |
130 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, | 130 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, |
131 cdm::DecryptedBlock* decrypted_buffer) OVERRIDE { | 131 cdm::DecryptedBlock* decrypted_buffer) OVERRIDE { |
132 return cdm_->Decrypt(encrypted_buffer, decrypted_buffer); | 132 return cdm_->Decrypt(encrypted_buffer, decrypted_buffer); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 cdm_->DecryptAndDecodeSamples(encrypted_buffer, &audio_frames_1); | 205 cdm_->DecryptAndDecodeSamples(encrypted_buffer, &audio_frames_1); |
206 if (status != cdm::kSuccess) | 206 if (status != cdm::kSuccess) |
207 return status; | 207 return status; |
208 | 208 |
209 audio_frames->SetFrameBuffer(audio_frames_1.PassFrameBuffer()); | 209 audio_frames->SetFrameBuffer(audio_frames_1.PassFrameBuffer()); |
210 audio_frames->SetFormat(cdm::kAudioFormatS16); | 210 audio_frames->SetFormat(cdm::kAudioFormatS16); |
211 return cdm::kSuccess; | 211 return cdm::kSuccess; |
212 } | 212 } |
213 | 213 |
214 CdmWrapper* CdmWrapper::Create(const char* key_system, | 214 CdmWrapper* CdmWrapper::Create(const char* key_system, |
215 int key_system_size, | 215 uint32_t key_system_size, |
216 GetCdmHostFunc get_cdm_host_func, | 216 GetCdmHostFunc get_cdm_host_func, |
217 void* user_data) { | 217 void* user_data) { |
218 // Try to create the CDM using the latest CDM interface version. | 218 // Try to create the CDM using the latest CDM interface version. |
219 CdmWrapper* cdm_adapter = | 219 CdmWrapper* cdm_adapter = |
220 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( | 220 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( |
221 key_system, key_system_size, get_cdm_host_func, user_data); | 221 key_system, key_system_size, get_cdm_host_func, user_data); |
222 if (cdm_adapter) | 222 if (cdm_adapter) |
223 return cdm_adapter; | 223 return cdm_adapter; |
224 | 224 |
225 // Try to see if the CDM supports older version(s) of CDM interface(s). | 225 // Try to see if the CDM supports older version(s) of CDM interface(s). |
226 cdm_adapter = CdmWrapperImpl<cdm::ContentDecryptionModule_1>::Create( | 226 cdm_adapter = CdmWrapperImpl<cdm::ContentDecryptionModule_1>::Create( |
227 key_system, key_system_size, get_cdm_host_func, user_data); | 227 key_system, key_system_size, get_cdm_host_func, user_data); |
228 return cdm_adapter; | 228 return cdm_adapter; |
229 } | 229 } |
230 | 230 |
231 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain | 231 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain |
232 // stub implementations for new or modified methods that the older CDM interface | 232 // stub implementations for new or modified methods that the older CDM interface |
233 // does not have. | 233 // does not have. |
234 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == | 234 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == |
235 cdm::ContentDecryptionModule_2::kVersion, | 235 cdm::ContentDecryptionModule_2::kVersion, |
236 ensure_cdm_wrapper_templates_have_old_version_support); | 236 ensure_cdm_wrapper_templates_have_old_version_support); |
237 | 237 |
238 } // namespace media | 238 } // namespace media |
239 | 239 |
240 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ | 240 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ |
OLD | NEW |