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_PROXY_DECRYPTOR_H_ | 5 #ifndef MEDIA_CDM_PROXY_DECRYPTOR_H_ |
6 #define MEDIA_CDM_PROXY_DECRYPTOR_H_ | 6 #define MEDIA_CDM_PROXY_DECRYPTOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | |
12 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
16 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
17 #include "media/base/cdm_context.h" | 16 #include "media/base/cdm_context.h" |
18 #include "media/base/decryptor.h" | 17 #include "media/base/decryptor.h" |
19 #include "media/base/eme_constants.h" | 18 #include "media/base/eme_constants.h" |
20 #include "media/base/media_export.h" | 19 #include "media/base/media_export.h" |
21 #include "media/base/media_keys.h" | 20 #include "media/base/media_keys.h" |
(...skipping 15 matching lines...) Expand all Loading... |
37 public: | 36 public: |
38 // Callback to provide a CdmContext when the CDM creation is finished. | 37 // Callback to provide a CdmContext when the CDM creation is finished. |
39 // If CDM creation failed, |cdm_context| will be null. | 38 // If CDM creation failed, |cdm_context| will be null. |
40 typedef base::Callback<void(CdmContext* cdm_context)> CdmContextReadyCB; | 39 typedef base::Callback<void(CdmContext* cdm_context)> CdmContextReadyCB; |
41 | 40 |
42 // These are similar to the callbacks in media_keys.h, but pass back the | 41 // These are similar to the callbacks in media_keys.h, but pass back the |
43 // session ID rather than the internal session ID. | 42 // session ID rather than the internal session ID. |
44 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; | 43 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; |
45 typedef base::Callback<void(const std::string& session_id, | 44 typedef base::Callback<void(const std::string& session_id, |
46 MediaKeys::KeyError error_code, | 45 MediaKeys::KeyError error_code, |
47 uint32 system_code)> KeyErrorCB; | 46 uint32_t system_code)> KeyErrorCB; |
48 typedef base::Callback<void(const std::string& session_id, | 47 typedef base::Callback<void(const std::string& session_id, |
49 const std::vector<uint8>& message, | 48 const std::vector<uint8_t>& message, |
50 const GURL& destination_url)> KeyMessageCB; | 49 const GURL& destination_url)> KeyMessageCB; |
51 | 50 |
52 ProxyDecryptor(MediaPermission* media_permission, | 51 ProxyDecryptor(MediaPermission* media_permission, |
53 bool use_hw_secure_codecs, | 52 bool use_hw_secure_codecs, |
54 const KeyAddedCB& key_added_cb, | 53 const KeyAddedCB& key_added_cb, |
55 const KeyErrorCB& key_error_cb, | 54 const KeyErrorCB& key_error_cb, |
56 const KeyMessageCB& key_message_cb); | 55 const KeyMessageCB& key_message_cb); |
57 virtual ~ProxyDecryptor(); | 56 virtual ~ProxyDecryptor(); |
58 | 57 |
59 // Creates the CDM and fires |cdm_created_cb|. This method should only be | 58 // Creates the CDM and fires |cdm_created_cb|. This method should only be |
60 // called once. If CDM creation failed, all following GenerateKeyRequest, | 59 // called once. If CDM creation failed, all following GenerateKeyRequest, |
61 // AddKey and CancelKeyRequest calls will result in a KeyError. | 60 // AddKey and CancelKeyRequest calls will result in a KeyError. |
62 void CreateCdm(CdmFactory* cdm_factory, | 61 void CreateCdm(CdmFactory* cdm_factory, |
63 const std::string& key_system, | 62 const std::string& key_system, |
64 const GURL& security_origin, | 63 const GURL& security_origin, |
65 const CdmContextReadyCB& cdm_context_ready_cb); | 64 const CdmContextReadyCB& cdm_context_ready_cb); |
66 | 65 |
67 // May only be called after CreateCDM(). | 66 // May only be called after CreateCDM(). |
68 void GenerateKeyRequest(EmeInitDataType init_data_type, | 67 void GenerateKeyRequest(EmeInitDataType init_data_type, |
69 const uint8* init_data, | 68 const uint8_t* init_data, |
70 int init_data_length); | 69 int init_data_length); |
71 void AddKey(const uint8* key, int key_length, | 70 void AddKey(const uint8_t* key, |
72 const uint8* init_data, int init_data_length, | 71 int key_length, |
| 72 const uint8_t* init_data, |
| 73 int init_data_length, |
73 const std::string& session_id); | 74 const std::string& session_id); |
74 void CancelKeyRequest(const std::string& session_id); | 75 void CancelKeyRequest(const std::string& session_id); |
75 | 76 |
76 private: | 77 private: |
77 // Callback for CreateCdm(). | 78 // Callback for CreateCdm(). |
78 void OnCdmCreated(const std::string& key_system, | 79 void OnCdmCreated(const std::string& key_system, |
79 const GURL& security_origin, | 80 const GURL& security_origin, |
80 const CdmContextReadyCB& cdm_context_ready_cb, | 81 const CdmContextReadyCB& cdm_context_ready_cb, |
81 const scoped_refptr<MediaKeys>& cdm, | 82 const scoped_refptr<MediaKeys>& cdm, |
82 const std::string& error_message); | 83 const std::string& error_message); |
83 | 84 |
84 void GenerateKeyRequestInternal(EmeInitDataType init_data_type, | 85 void GenerateKeyRequestInternal(EmeInitDataType init_data_type, |
85 const std::vector<uint8>& init_data); | 86 const std::vector<uint8_t>& init_data); |
86 | 87 |
87 // Callbacks for firing session events. | 88 // Callbacks for firing session events. |
88 void OnSessionMessage(const std::string& session_id, | 89 void OnSessionMessage(const std::string& session_id, |
89 MediaKeys::MessageType message_type, | 90 MediaKeys::MessageType message_type, |
90 const std::vector<uint8>& message, | 91 const std::vector<uint8_t>& message, |
91 const GURL& legacy_destination_url); | 92 const GURL& legacy_destination_url); |
92 void OnSessionKeysChange(const std::string& session_id, | 93 void OnSessionKeysChange(const std::string& session_id, |
93 bool has_additional_usable_key, | 94 bool has_additional_usable_key, |
94 CdmKeysInfo keys_info); | 95 CdmKeysInfo keys_info); |
95 void OnSessionExpirationUpdate(const std::string& session_id, | 96 void OnSessionExpirationUpdate(const std::string& session_id, |
96 const base::Time& new_expiry_time); | 97 const base::Time& new_expiry_time); |
97 void GenerateKeyAdded(const std::string& session_id); | 98 void GenerateKeyAdded(const std::string& session_id); |
98 void OnSessionClosed(const std::string& session_id); | 99 void OnSessionClosed(const std::string& session_id); |
99 void OnLegacySessionError(const std::string& session_id, | 100 void OnLegacySessionError(const std::string& session_id, |
100 MediaKeys::Exception exception_code, | 101 MediaKeys::Exception exception_code, |
101 uint32 system_code, | 102 uint32_t system_code, |
102 const std::string& error_message); | 103 const std::string& error_message); |
103 | 104 |
104 // Callback for permission request. | 105 // Callback for permission request. |
105 void OnPermissionStatus(MediaKeys::SessionType session_type, | 106 void OnPermissionStatus(MediaKeys::SessionType session_type, |
106 EmeInitDataType init_data_type, | 107 EmeInitDataType init_data_type, |
107 const std::vector<uint8>& init_data, | 108 const std::vector<uint8_t>& init_data, |
108 scoped_ptr<NewSessionCdmPromise> promise, | 109 scoped_ptr<NewSessionCdmPromise> promise, |
109 bool granted); | 110 bool granted); |
110 | 111 |
111 enum SessionCreationType { | 112 enum SessionCreationType { |
112 TemporarySession, | 113 TemporarySession, |
113 PersistentSession, | 114 PersistentSession, |
114 LoadSession | 115 LoadSession |
115 }; | 116 }; |
116 | 117 |
117 // Called when a session is actually created or loaded. | 118 // Called when a session is actually created or loaded. |
118 void SetSessionId(SessionCreationType session_type, | 119 void SetSessionId(SessionCreationType session_type, |
119 const std::string& session_id); | 120 const std::string& session_id); |
120 | 121 |
121 struct PendingGenerateKeyRequestData { | 122 struct PendingGenerateKeyRequestData { |
122 PendingGenerateKeyRequestData(EmeInitDataType init_data_type, | 123 PendingGenerateKeyRequestData(EmeInitDataType init_data_type, |
123 const std::vector<uint8>& init_data); | 124 const std::vector<uint8_t>& init_data); |
124 ~PendingGenerateKeyRequestData(); | 125 ~PendingGenerateKeyRequestData(); |
125 | 126 |
126 const EmeInitDataType init_data_type; | 127 const EmeInitDataType init_data_type; |
127 const std::vector<uint8> init_data; | 128 const std::vector<uint8_t> init_data; |
128 }; | 129 }; |
129 | 130 |
130 bool is_creating_cdm_; | 131 bool is_creating_cdm_; |
131 | 132 |
132 // The real MediaKeys that manages key operations for the ProxyDecryptor. | 133 // The real MediaKeys that manages key operations for the ProxyDecryptor. |
133 scoped_refptr<MediaKeys> media_keys_; | 134 scoped_refptr<MediaKeys> media_keys_; |
134 | 135 |
135 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 136 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
136 MediaPermission* media_permission_; | 137 MediaPermission* media_permission_; |
137 #endif | 138 #endif |
(...skipping 17 matching lines...) Expand all Loading... |
155 | 156 |
156 // NOTE: Weak pointers must be invalidated before all other member variables. | 157 // NOTE: Weak pointers must be invalidated before all other member variables. |
157 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; | 158 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; |
158 | 159 |
159 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 160 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
160 }; | 161 }; |
161 | 162 |
162 } // namespace media | 163 } // namespace media |
163 | 164 |
164 #endif // MEDIA_CDM_PROXY_DECRYPTOR_H_ | 165 #endif // MEDIA_CDM_PROXY_DECRYPTOR_H_ |
OLD | NEW |