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_ADAPTER_H_ | 5 #ifndef MEDIA_CDM_PPAPI_CDM_ADAPTER_H_ |
6 #define MEDIA_CDM_PPAPI_CDM_ADAPTER_H_ | 6 #define MEDIA_CDM_PPAPI_CDM_ADAPTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 namespace media { | 31 namespace media { |
32 | 32 |
33 // GetCdmHostFunc implementation. | 33 // GetCdmHostFunc implementation. |
34 void* GetCdmHost(int host_interface_version, void* user_data); | 34 void* GetCdmHost(int host_interface_version, void* user_data); |
35 | 35 |
36 // An adapter class for abstracting away PPAPI interaction and threading for a | 36 // An adapter class for abstracting away PPAPI interaction and threading for a |
37 // Content Decryption Module (CDM). | 37 // Content Decryption Module (CDM). |
38 class CdmAdapter : public pp::Instance, | 38 class CdmAdapter : public pp::Instance, |
39 public pp::ContentDecryptor_Private, | 39 public pp::ContentDecryptor_Private, |
40 public cdm::Host_6 { | 40 public cdm::Host_6, |
| 41 public cdm::Host_7 { |
41 public: | 42 public: |
42 CdmAdapter(PP_Instance instance, pp::Module* module); | 43 CdmAdapter(PP_Instance instance, pp::Module* module); |
43 virtual ~CdmAdapter(); | 44 virtual ~CdmAdapter(); |
44 | 45 |
45 // pp::Instance implementation. | 46 // pp::Instance implementation. |
46 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 47 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
47 return true; | 48 return true; |
48 } | 49 } |
49 | 50 |
50 // PPP_ContentDecryptor_Private implementation. | 51 // PPP_ContentDecryptor_Private implementation. |
51 // Note: Results of calls to these methods must be reported through the | 52 // Note: Results of calls to these methods must be reported through the |
52 // PPB_ContentDecryptor_Private interface. | 53 // PPB_ContentDecryptor_Private interface. |
53 virtual void Initialize(const std::string& key_system) override; | 54 void Initialize(const std::string& key_system) override; |
54 virtual void SetServerCertificate( | 55 void SetServerCertificate(uint32_t promise_id, |
55 uint32_t promise_id, | 56 pp::VarArrayBuffer server_certificate) override; |
56 pp::VarArrayBuffer server_certificate) override; | 57 void CreateSessionAndGenerateRequest(uint32_t promise_id, |
57 virtual void CreateSession(uint32_t promise_id, | 58 PP_SessionType session_type, |
58 const std::string& init_data_type, | 59 const std::string& init_data_type, |
59 pp::VarArrayBuffer init_data, | 60 pp::VarArrayBuffer init_data) override; |
60 PP_SessionType session_type) override; | 61 void LoadSession(uint32_t promise_id, |
61 virtual void LoadSession(uint32_t promise_id, | 62 PP_SessionType session_type, |
62 const std::string& web_session_id) override; | 63 const std::string& session_id) override; |
63 virtual void UpdateSession(uint32_t promise_id, | 64 void UpdateSession(uint32_t promise_id, |
64 const std::string& web_session_id, | 65 const std::string& session_id, |
65 pp::VarArrayBuffer response) override; | 66 pp::VarArrayBuffer response) override; |
66 virtual void CloseSession(uint32_t promise_id, | 67 void CloseSession(uint32_t promise_id, const std::string& session_id); |
67 const std::string& web_session_id); | 68 void RemoveSession(uint32_t promise_id, |
68 virtual void RemoveSession(uint32_t promise_id, | 69 const std::string& session_id) override; |
69 const std::string& web_session_id) override; | 70 void Decrypt(pp::Buffer_Dev encrypted_buffer, |
70 virtual void GetUsableKeyIds(uint32_t promise_id, | 71 const PP_EncryptedBlockInfo& encrypted_block_info) override; |
71 const std::string& web_session_id) override; | 72 void InitializeAudioDecoder(const PP_AudioDecoderConfig& decoder_config, |
72 virtual void Decrypt( | 73 pp::Buffer_Dev extra_data_buffer) override; |
73 pp::Buffer_Dev encrypted_buffer, | 74 void InitializeVideoDecoder(const PP_VideoDecoderConfig& decoder_config, |
74 const PP_EncryptedBlockInfo& encrypted_block_info) override; | 75 pp::Buffer_Dev extra_data_buffer) override; |
75 virtual void InitializeAudioDecoder( | 76 void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, |
76 const PP_AudioDecoderConfig& decoder_config, | 77 uint32_t request_id) override; |
77 pp::Buffer_Dev extra_data_buffer) override; | 78 void ResetDecoder(PP_DecryptorStreamType decoder_type, |
78 virtual void InitializeVideoDecoder( | 79 uint32_t request_id) override; |
79 const PP_VideoDecoderConfig& decoder_config, | 80 void DecryptAndDecode( |
80 pp::Buffer_Dev extra_data_buffer) override; | |
81 virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, | |
82 uint32_t request_id) override; | |
83 virtual void ResetDecoder(PP_DecryptorStreamType decoder_type, | |
84 uint32_t request_id) override; | |
85 virtual void DecryptAndDecode( | |
86 PP_DecryptorStreamType decoder_type, | 81 PP_DecryptorStreamType decoder_type, |
87 pp::Buffer_Dev encrypted_buffer, | 82 pp::Buffer_Dev encrypted_buffer, |
88 const PP_EncryptedBlockInfo& encrypted_block_info) override; | 83 const PP_EncryptedBlockInfo& encrypted_block_info) override; |
89 | 84 |
| 85 // cdm::Host_6 and cdm::Host_7 implementation. |
| 86 cdm::Buffer* Allocate(uint32_t capacity) override; |
| 87 void SetTimer(int64_t delay_ms, void* context) override; |
| 88 cdm::Time GetCurrentWallTime() override; |
| 89 void OnResolveNewSessionPromise(uint32_t promise_id, |
| 90 const char* session_id, |
| 91 uint32_t session_id_size) override; |
| 92 void OnResolvePromise(uint32_t promise_id) override; |
| 93 void OnRejectPromise(uint32_t promise_id, |
| 94 cdm::Error error, |
| 95 uint32_t system_code, |
| 96 const char* error_message, |
| 97 uint32_t error_message_size) override; |
| 98 void OnExpirationChange(const char* session_id, |
| 99 uint32_t session_id_size, |
| 100 cdm::Time new_expiry_time) override; |
| 101 void OnSessionClosed(const char* session_id, |
| 102 uint32_t session_id_size) override; |
| 103 void SendPlatformChallenge(const char* service_id, |
| 104 uint32_t service_id_size, |
| 105 const char* challenge, |
| 106 uint32_t challenge_size) override; |
| 107 void EnableOutputProtection(uint32_t desired_protection_mask) override; |
| 108 void QueryOutputProtectionStatus() override; |
| 109 void OnDeferredInitializationDone(cdm::StreamType stream_type, |
| 110 cdm::Status decoder_status) override; |
| 111 cdm::FileIO* CreateFileIO(cdm::FileIOClient* client) override; |
| 112 |
| 113 // cdm::Host_7 implementation. |
| 114 void OnSessionMessage(const char* session_id, |
| 115 uint32_t session_id_size, |
| 116 cdm::MessageType message_type, |
| 117 const char* message, |
| 118 uint32_t message_size) override; |
| 119 void OnSessionKeysChange(const char* session_id, |
| 120 uint32_t session_id_size, |
| 121 bool has_additional_usable_key, |
| 122 const cdm::KeyInformation* keys_info, |
| 123 uint32_t keys_info_count) override; |
| 124 |
90 // cdm::Host_6 implementation. | 125 // cdm::Host_6 implementation. |
91 virtual cdm::Buffer* Allocate(uint32_t capacity) override; | 126 void OnResolveKeyIdsPromise(uint32_t promise_id, |
92 virtual void SetTimer(int64_t delay_ms, void* context) override; | 127 const cdm::BinaryData* usable_key_ids, |
93 virtual cdm::Time GetCurrentWallTime() override; | 128 uint32_t usable_key_ids_size) override; |
94 virtual void OnResolveNewSessionPromise( | 129 void OnSessionMessage(const char* session_id, |
95 uint32_t promise_id, | 130 uint32_t session_id_size, |
96 const char* web_session_id, | 131 const char* message, |
97 uint32_t web_session_id_length) override; | 132 uint32_t message_size, |
98 virtual void OnResolvePromise(uint32_t promise_id) override; | 133 const char* destination_url, |
99 virtual void OnResolveKeyIdsPromise(uint32_t promise_id, | 134 uint32_t destination_url_size) override; |
100 const cdm::BinaryData* usable_key_ids, | 135 void OnSessionUsableKeysChange(const char* session_id, |
101 uint32_t usable_key_ids_length) override; | 136 uint32_t session_id_size, |
102 virtual void OnRejectPromise(uint32_t promise_id, | 137 bool has_additional_usable_key) override; |
103 cdm::Error error, | 138 void OnSessionError(const char* session_id, |
104 uint32_t system_code, | 139 uint32_t session_id_size, |
105 const char* error_message, | 140 cdm::Error error, |
106 uint32_t error_message_length) override; | 141 uint32_t system_code, |
107 virtual void OnSessionMessage(const char* web_session_id, | 142 const char* error_message, |
108 uint32_t web_session_id_length, | 143 uint32_t error_message_size) override; |
109 const char* message, | |
110 uint32_t message_length, | |
111 const char* destination_url, | |
112 uint32_t destination_url_length) override; | |
113 virtual void OnSessionUsableKeysChange( | |
114 const char* web_session_id, | |
115 uint32_t web_session_id_length, | |
116 bool has_additional_usable_key) override; | |
117 virtual void OnExpirationChange(const char* web_session_id, | |
118 uint32_t web_session_id_length, | |
119 cdm::Time new_expiry_time) override; | |
120 virtual void OnSessionClosed(const char* web_session_id, | |
121 uint32_t web_session_id_length) override; | |
122 virtual void OnSessionError(const char* web_session_id, | |
123 uint32_t web_session_id_length, | |
124 cdm::Error error, | |
125 uint32_t system_code, | |
126 const char* error_message, | |
127 uint32_t error_message_length) override; | |
128 virtual void SendPlatformChallenge(const char* service_id, | |
129 uint32_t service_id_length, | |
130 const char* challenge, | |
131 uint32_t challenge_length) override; | |
132 virtual void EnableOutputProtection( | |
133 uint32_t desired_protection_mask) override; | |
134 virtual void QueryOutputProtectionStatus() override; | |
135 virtual void OnDeferredInitializationDone( | |
136 cdm::StreamType stream_type, | |
137 cdm::Status decoder_status) override; | |
138 virtual cdm::FileIO* CreateFileIO(cdm::FileIOClient* client) override; | |
139 | 144 |
140 private: | 145 private: |
141 // These are reported to UMA server. Do not change the existing values! | 146 // These are reported to UMA server. Do not change the existing values! |
142 enum OutputProtectionStatus { | 147 enum OutputProtectionStatus { |
143 OUTPUT_PROTECTION_QUERIED = 0, | 148 OUTPUT_PROTECTION_QUERIED = 0, |
144 OUTPUT_PROTECTION_NO_EXTERNAL_LINK = 1, | 149 OUTPUT_PROTECTION_NO_EXTERNAL_LINK = 1, |
145 OUTPUT_PROTECTION_ALL_EXTERNAL_LINKS_PROTECTED = 2, | 150 OUTPUT_PROTECTION_ALL_EXTERNAL_LINKS_PROTECTED = 2, |
146 OUTPUT_PROTECTION_MAX = 3 | 151 OUTPUT_PROTECTION_MAX = 3 |
147 }; | 152 }; |
148 | 153 |
149 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; | 154 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; |
150 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; | 155 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; |
151 typedef linked_ptr<AudioFramesImpl> LinkedAudioFrames; | 156 typedef linked_ptr<AudioFramesImpl> LinkedAudioFrames; |
152 | 157 |
153 struct SessionError { | 158 struct SessionError { |
154 SessionError(cdm::Error error, | 159 SessionError(cdm::Error error, |
155 uint32_t system_code, | 160 uint32_t system_code, |
156 std::string error_description); | 161 std::string error_description); |
157 cdm::Error error; | 162 cdm::Error error; |
158 uint32_t system_code; | 163 uint32_t system_code; |
159 std::string error_description; | 164 std::string error_description; |
160 }; | 165 }; |
161 | 166 |
162 bool CreateCdmInstance(const std::string& key_system); | 167 bool CreateCdmInstance(const std::string& key_system); |
163 | 168 |
164 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to | 169 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to |
165 // <code>callback_factory_</code> to ensure that calls into | 170 // <code>callback_factory_</code> to ensure that calls into |
166 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. | 171 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. |
167 void SendPromiseResolvedInternal(int32_t result, uint32_t promise_id); | 172 void SendPromiseResolvedInternal(int32_t result, uint32_t promise_id); |
168 void SendPromiseResolvedWithSessionInternal( | 173 void SendPromiseResolvedWithSessionInternal(int32_t result, |
169 int32_t result, | 174 uint32_t promise_id, |
170 uint32_t promise_id, | 175 const std::string& session_id); |
171 const std::string& web_session_id); | |
172 void SendPromiseResolvedWithUsableKeyIdsInternal( | |
173 int32_t result, | |
174 uint32_t promise_id, | |
175 std::vector<std::vector<uint8> > key_ids); | |
176 void SendPromiseRejectedInternal(int32_t result, | 176 void SendPromiseRejectedInternal(int32_t result, |
177 uint32_t promise_id, | 177 uint32_t promise_id, |
178 const SessionError& error); | 178 const SessionError& error); |
179 void SendSessionMessageInternal(int32_t result, | 179 void SendSessionMessageInternal(int32_t result, |
180 const std::string& web_session_id, | 180 const std::string& session_id, |
181 const std::vector<uint8>& message, | 181 cdm::MessageType message_type, |
182 const std::string& destination_url); | 182 const std::vector<uint8_t>& message); |
183 void SendSessionReadyInternal(int32_t result, | 183 void SendSessionClosedInternal(int32_t result, const std::string& session_id); |
184 const std::string& web_session_id); | |
185 void SendSessionClosedInternal(int32_t result, | |
186 const std::string& web_session_id); | |
187 void SendSessionErrorInternal(int32_t result, | 184 void SendSessionErrorInternal(int32_t result, |
188 const std::string& web_session_id, | 185 const std::string& session_id, |
189 const SessionError& error); | 186 const SessionError& error); |
190 void SendSessionUsableKeysChangeInternal(int32_t result, | 187 void SendSessionKeysChangeInternal( |
191 const std::string& web_session_id, | 188 int32_t result, |
192 bool has_additional_usable_key); | 189 const std::string& session_id, |
| 190 bool has_additional_usable_key, |
| 191 const std::vector<PP_KeyInformation>& key_info); |
193 void SendExpirationChangeInternal(int32_t result, | 192 void SendExpirationChangeInternal(int32_t result, |
194 const std::string& web_session_id, | 193 const std::string& session_id, |
195 cdm::Time new_expiry_time); | 194 cdm::Time new_expiry_time); |
196 void RejectPromise(uint32_t promise_id, | 195 void RejectPromise(uint32_t promise_id, |
197 cdm::Error error, | 196 cdm::Error error, |
198 uint32_t system_code, | 197 uint32_t system_code, |
199 const std::string& error_message); | 198 const std::string& error_message); |
200 | 199 |
201 void DeliverBlock(int32_t result, | 200 void DeliverBlock(int32_t result, |
202 const cdm::Status& status, | 201 const cdm::Status& status, |
203 const LinkedDecryptedBlock& decrypted_block, | 202 const LinkedDecryptedBlock& decrypted_block, |
204 const PP_DecryptTrackingInfo& tracking_info); | 203 const PP_DecryptTrackingInfo& tracking_info); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 | 281 |
283 uint32_t last_read_file_size_kb_; | 282 uint32_t last_read_file_size_kb_; |
284 bool file_size_uma_reported_; | 283 bool file_size_uma_reported_; |
285 | 284 |
286 DISALLOW_COPY_AND_ASSIGN(CdmAdapter); | 285 DISALLOW_COPY_AND_ASSIGN(CdmAdapter); |
287 }; | 286 }; |
288 | 287 |
289 } // namespace media | 288 } // namespace media |
290 | 289 |
291 #endif // MEDIA_CDM_PPAPI_CDM_ADAPTER_H_ | 290 #endif // MEDIA_CDM_PPAPI_CDM_ADAPTER_H_ |
OLD | NEW |