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 10 matching lines...) Expand all Loading... |
21 #include "ppapi/cpp/private/content_decryptor_private.h" | 21 #include "ppapi/cpp/private/content_decryptor_private.h" |
22 #include "ppapi/cpp/var.h" | 22 #include "ppapi/cpp/var.h" |
23 #include "ppapi/cpp/var_array_buffer.h" | 23 #include "ppapi/cpp/var_array_buffer.h" |
24 #include "ppapi/utility/completion_callback_factory.h" | 24 #include "ppapi/utility/completion_callback_factory.h" |
25 | 25 |
26 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
27 #include "ppapi/cpp/private/output_protection_private.h" | 27 #include "ppapi/cpp/private/output_protection_private.h" |
28 #include "ppapi/cpp/private/platform_verification.h" | 28 #include "ppapi/cpp/private/platform_verification.h" |
29 #endif | 29 #endif |
30 | 30 |
| 31 #if defined(GetCurrentTime) |
| 32 // winbase.h defines this which messes up calls to Host_5::GetCurrentTime. |
| 33 #undef GetCurrentTime |
| 34 #endif |
| 35 |
31 namespace media { | 36 namespace media { |
32 | 37 |
33 // GetCdmHostFunc implementation. | 38 // GetCdmHostFunc implementation. |
34 void* GetCdmHost(int host_interface_version, void* user_data); | 39 void* GetCdmHost(int host_interface_version, void* user_data); |
35 | 40 |
36 // An adapter class for abstracting away PPAPI interaction and threading for a | 41 // An adapter class for abstracting away PPAPI interaction and threading for a |
37 // Content Decryption Module (CDM). | 42 // Content Decryption Module (CDM). |
38 class CdmAdapter : public pp::Instance, | 43 class CdmAdapter : public pp::Instance, |
39 public pp::ContentDecryptor_Private, | 44 public pp::ContentDecryptor_Private, |
40 public cdm::Host_4 { | 45 public cdm::Host_4, |
| 46 public cdm::Host_5 { |
41 public: | 47 public: |
42 CdmAdapter(PP_Instance instance, pp::Module* module); | 48 CdmAdapter(PP_Instance instance, pp::Module* module); |
43 virtual ~CdmAdapter(); | 49 virtual ~CdmAdapter(); |
44 | 50 |
45 // pp::Instance implementation. | 51 // pp::Instance implementation. |
46 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 52 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
47 return true; | 53 return true; |
48 } | 54 } |
49 | 55 |
50 // PPP_ContentDecryptor_Private implementation. | 56 // PPP_ContentDecryptor_Private implementation. |
51 // Note: Results of calls to these methods must be reported through the | 57 // Note: Results of calls to these methods must be reported through the |
52 // PPB_ContentDecryptor_Private interface. | 58 // PPB_ContentDecryptor_Private interface. |
53 virtual void Initialize(const std::string& key_system) OVERRIDE; | 59 virtual void Initialize(const std::string& key_system) OVERRIDE; |
54 virtual void CreateSession(uint32_t session_id, | 60 virtual void CreateSession(uint32_t promise_id, |
55 const std::string& content_type, | 61 const std::string& init_data_type, |
56 pp::VarArrayBuffer init_data) OVERRIDE; | 62 pp::VarArrayBuffer init_data, |
57 virtual void LoadSession(uint32_t session_id, | 63 PP_SessionType session_type) OVERRIDE; |
| 64 virtual void LoadSession(uint32_t promise_id, |
58 const std::string& web_session_id) OVERRIDE; | 65 const std::string& web_session_id) OVERRIDE; |
59 virtual void UpdateSession(uint32_t session_id, | 66 virtual void UpdateSession(uint32_t promise_id, |
| 67 const std::string& web_session_id, |
60 pp::VarArrayBuffer response) OVERRIDE; | 68 pp::VarArrayBuffer response) OVERRIDE; |
61 virtual void ReleaseSession(uint32_t session_id) OVERRIDE; | 69 virtual void ReleaseSession(uint32_t promise_id, |
| 70 const std::string& web_session_id) OVERRIDE; |
62 virtual void Decrypt( | 71 virtual void Decrypt( |
63 pp::Buffer_Dev encrypted_buffer, | 72 pp::Buffer_Dev encrypted_buffer, |
64 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 73 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
65 virtual void InitializeAudioDecoder( | 74 virtual void InitializeAudioDecoder( |
66 const PP_AudioDecoderConfig& decoder_config, | 75 const PP_AudioDecoderConfig& decoder_config, |
67 pp::Buffer_Dev extra_data_buffer) OVERRIDE; | 76 pp::Buffer_Dev extra_data_buffer) OVERRIDE; |
68 virtual void InitializeVideoDecoder( | 77 virtual void InitializeVideoDecoder( |
69 const PP_VideoDecoderConfig& decoder_config, | 78 const PP_VideoDecoderConfig& decoder_config, |
70 pp::Buffer_Dev extra_data_buffer) OVERRIDE; | 79 pp::Buffer_Dev extra_data_buffer) OVERRIDE; |
71 virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, | 80 virtual void DeinitializeDecoder(PP_DecryptorStreamType decoder_type, |
72 uint32_t request_id) OVERRIDE; | 81 uint32_t request_id) OVERRIDE; |
73 virtual void ResetDecoder(PP_DecryptorStreamType decoder_type, | 82 virtual void ResetDecoder(PP_DecryptorStreamType decoder_type, |
74 uint32_t request_id) OVERRIDE; | 83 uint32_t request_id) OVERRIDE; |
75 virtual void DecryptAndDecode( | 84 virtual void DecryptAndDecode( |
76 PP_DecryptorStreamType decoder_type, | 85 PP_DecryptorStreamType decoder_type, |
77 pp::Buffer_Dev encrypted_buffer, | 86 pp::Buffer_Dev encrypted_buffer, |
78 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 87 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
79 | 88 |
80 // cdm::Host implementation. | 89 // cdm::Host_4 and cdm::Host_5 implementation. |
81 virtual cdm::Buffer* Allocate(uint32_t capacity) OVERRIDE; | 90 virtual cdm::Buffer* Allocate(uint32_t capacity) OVERRIDE; |
82 virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE; | 91 virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE; |
| 92 |
| 93 // cdm::Host_4 implementation. |
83 virtual double GetCurrentWallTimeInSeconds() OVERRIDE; | 94 virtual double GetCurrentWallTimeInSeconds() OVERRIDE; |
84 virtual void OnSessionCreated(uint32_t session_id, | 95 virtual void OnSessionCreated(uint32_t session_id, |
85 const char* web_session_id, | 96 const char* web_session_id, |
86 uint32_t web_session_id_length) OVERRIDE; | 97 uint32_t web_session_id_length) OVERRIDE; |
87 virtual void OnSessionMessage(uint32_t session_id, | 98 virtual void OnSessionMessage(uint32_t session_id, |
88 const char* message, | 99 const char* message, |
89 uint32_t message_length, | 100 uint32_t message_length, |
90 const char* destination_url, | 101 const char* destination_url, |
91 uint32_t destination_url_length) OVERRIDE; | 102 uint32_t destination_url_length) OVERRIDE; |
92 virtual void OnSessionReady(uint32_t session_id) OVERRIDE; | 103 virtual void OnSessionReady(uint32_t session_id) OVERRIDE; |
93 virtual void OnSessionClosed(uint32_t session_id) OVERRIDE; | 104 virtual void OnSessionClosed(uint32_t session_id) OVERRIDE; |
94 virtual void OnSessionError(uint32_t session_id, | 105 virtual void OnSessionError(uint32_t session_id, |
95 cdm::MediaKeyError error_code, | 106 cdm::MediaKeyError error_code, |
96 uint32_t system_code) OVERRIDE; | 107 uint32_t system_code) OVERRIDE; |
97 virtual void SendPlatformChallenge( | 108 |
98 const char* service_id, uint32_t service_id_length, | 109 // cdm::Host_5 implementation. |
99 const char* challenge, uint32_t challenge_length) OVERRIDE; | 110 virtual cdm::Time GetCurrentTime() OVERRIDE; |
| 111 virtual void OnResolveNewSessionPromise( |
| 112 uint32_t promise_id, |
| 113 const char* web_session_id, |
| 114 uint32_t web_session_id_length) OVERRIDE; |
| 115 virtual void OnResolvePromise(uint32_t promise_id) OVERRIDE; |
| 116 virtual void OnRejectPromise(uint32_t promise_id, |
| 117 cdm::Error error, |
| 118 uint32_t system_code, |
| 119 const char* error_message, |
| 120 uint32_t error_message_length) OVERRIDE; |
| 121 virtual void OnSessionMessage(const char* web_session_id, |
| 122 uint32_t web_session_id_length, |
| 123 const char* message, |
| 124 uint32_t message_length, |
| 125 const char* destination_url, |
| 126 uint32_t destination_url_length) OVERRIDE; |
| 127 virtual void OnSessionKeysChange(const char* web_session_id, |
| 128 uint32_t web_session_id_length, |
| 129 bool has_additional_usable_key); |
| 130 virtual void OnExpirationChange(const char* web_session_id, |
| 131 uint32_t web_session_id_length, |
| 132 cdm::Time new_expiry_time); |
| 133 virtual void OnSessionReady(const char* web_session_id, |
| 134 uint32_t web_session_id_length) OVERRIDE; |
| 135 virtual void OnSessionClosed(const char* web_session_id, |
| 136 uint32_t web_session_id_length) OVERRIDE; |
| 137 virtual void OnSessionError(const char* web_session_id, |
| 138 uint32_t web_session_id_length, |
| 139 cdm::Error error, |
| 140 uint32_t system_code, |
| 141 const char* error_message, |
| 142 uint32_t error_message_length) OVERRIDE; |
| 143 |
| 144 // cdm::Host_4 and cdm::Host_5 implementation. |
| 145 virtual void SendPlatformChallenge(const char* service_id, |
| 146 uint32_t service_id_length, |
| 147 const char* challenge, |
| 148 uint32_t challenge_length) OVERRIDE; |
100 virtual void EnableOutputProtection( | 149 virtual void EnableOutputProtection( |
101 uint32_t desired_protection_mask) OVERRIDE; | 150 uint32_t desired_protection_mask) OVERRIDE; |
102 virtual void QueryOutputProtectionStatus() OVERRIDE; | 151 virtual void QueryOutputProtectionStatus() OVERRIDE; |
103 virtual void OnDeferredInitializationDone( | 152 virtual void OnDeferredInitializationDone( |
104 cdm::StreamType stream_type, | 153 cdm::StreamType stream_type, |
105 cdm::Status decoder_status) OVERRIDE; | 154 cdm::Status decoder_status) OVERRIDE; |
106 virtual cdm::FileIO* CreateFileIO(cdm::FileIOClient* client) OVERRIDE; | 155 virtual cdm::FileIO* CreateFileIO(cdm::FileIOClient* client) OVERRIDE; |
107 | 156 |
108 private: | 157 private: |
109 // These are reported to UMA server. Do not change the existing values! | 158 // These are reported to UMA server. Do not change the existing values! |
110 enum OutputProtectionStatus { | 159 enum OutputProtectionStatus { |
111 OUTPUT_PROTECTION_QUERIED = 0, | 160 OUTPUT_PROTECTION_QUERIED = 0, |
112 OUTPUT_PROTECTION_NO_EXTERNAL_LINK = 1, | 161 OUTPUT_PROTECTION_NO_EXTERNAL_LINK = 1, |
113 OUTPUT_PROTECTION_ALL_EXTERNAL_LINKS_PROTECTED = 2, | 162 OUTPUT_PROTECTION_ALL_EXTERNAL_LINKS_PROTECTED = 2, |
114 OUTPUT_PROTECTION_MAX = 3 | 163 OUTPUT_PROTECTION_MAX = 3 |
115 }; | 164 }; |
116 | 165 |
117 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; | 166 typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock; |
118 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; | 167 typedef linked_ptr<VideoFrameImpl> LinkedVideoFrame; |
119 typedef linked_ptr<AudioFramesImpl> LinkedAudioFrames; | 168 typedef linked_ptr<AudioFramesImpl> LinkedAudioFrames; |
120 | 169 |
| 170 struct SessionError { |
| 171 SessionError(cdm::Error error, |
| 172 uint32_t system_code, |
| 173 std::string error_description); |
| 174 cdm::Error error; |
| 175 uint32_t system_code; |
| 176 std::string error_description; |
| 177 }; |
| 178 |
121 bool CreateCdmInstance(const std::string& key_system); | 179 bool CreateCdmInstance(const std::string& key_system); |
122 | 180 |
123 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to | 181 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to |
124 // <code>callback_factory_</code> to ensure that calls into | 182 // <code>callback_factory_</code> to ensure that calls into |
125 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. | 183 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. |
126 void SendSessionCreatedInternal(int32_t result, | 184 void SendPromiseResolvedInternal(int32_t result, uint32_t promise_id); |
127 uint32_t session_id, | 185 void SendPromiseResolvedWithSessionInternal( |
128 const std::string& web_session_id); | 186 int32_t result, |
| 187 uint32_t promise_id, |
| 188 const std::string& web_session_id); |
| 189 void SendPromiseRejectedInternal(int32_t result, |
| 190 uint32_t promise_id, |
| 191 const SessionError& error); |
129 void SendSessionMessageInternal(int32_t result, | 192 void SendSessionMessageInternal(int32_t result, |
130 uint32_t session_id, | 193 const std::string& web_session_id, |
131 const std::vector<uint8>& message, | 194 const std::vector<uint8>& message, |
132 const std::string& destination_url); | 195 const std::string& destination_url); |
133 void SendSessionReadyInternal(int32_t result, uint32_t session_id); | 196 void SendSessionReadyInternal(int32_t result, |
134 void SendSessionClosedInternal(int32_t result, uint32_t session_id); | 197 const std::string& web_session_id); |
| 198 void SendSessionClosedInternal(int32_t result, |
| 199 const std::string& web_session_id); |
135 void SendSessionErrorInternal(int32_t result, | 200 void SendSessionErrorInternal(int32_t result, |
136 uint32_t session_id, | 201 const std::string& web_session_id, |
137 cdm::MediaKeyError error_code, | 202 const SessionError& error); |
138 uint32_t system_code); | 203 void RejectPromise(uint32_t promise_id, |
| 204 cdm::Error error, |
| 205 uint32_t system_code, |
| 206 const std::string& error_message); |
139 | 207 |
140 void DeliverBlock(int32_t result, | 208 void DeliverBlock(int32_t result, |
141 const cdm::Status& status, | 209 const cdm::Status& status, |
142 const LinkedDecryptedBlock& decrypted_block, | 210 const LinkedDecryptedBlock& decrypted_block, |
143 const PP_DecryptTrackingInfo& tracking_info); | 211 const PP_DecryptTrackingInfo& tracking_info); |
144 void DecoderInitializeDone(int32_t result, | 212 void DecoderInitializeDone(int32_t result, |
145 PP_DecryptorStreamType decoder_type, | 213 PP_DecryptorStreamType decoder_type, |
146 uint32_t request_id, | 214 uint32_t request_id, |
147 bool success); | 215 bool success); |
148 void DecoderDeinitializeDone(int32_t result, | 216 void DecoderDeinitializeDone(int32_t result, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 uint32_t deferred_audio_decoder_config_id_; | 283 uint32_t deferred_audio_decoder_config_id_; |
216 bool deferred_initialize_video_decoder_; | 284 bool deferred_initialize_video_decoder_; |
217 uint32_t deferred_video_decoder_config_id_; | 285 uint32_t deferred_video_decoder_config_id_; |
218 | 286 |
219 DISALLOW_COPY_AND_ASSIGN(CdmAdapter); | 287 DISALLOW_COPY_AND_ASSIGN(CdmAdapter); |
220 }; | 288 }; |
221 | 289 |
222 } // namespace media | 290 } // namespace media |
223 | 291 |
224 #endif // MEDIA_CDM_PPAPI_CDM_ADAPTER_H_ | 292 #endif // MEDIA_CDM_PPAPI_CDM_ADAPTER_H_ |
OLD | NEW |