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" | 11 #include "base/basictypes.h" |
12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "media/base/cdm_context.h" |
15 #include "media/base/decryptor.h" | 17 #include "media/base/decryptor.h" |
16 #include "media/base/eme_constants.h" | 18 #include "media/base/eme_constants.h" |
17 #include "media/base/media_export.h" | 19 #include "media/base/media_export.h" |
18 #include "media/base/media_keys.h" | 20 #include "media/base/media_keys.h" |
19 #include "url/gurl.h" | 21 #include "url/gurl.h" |
20 | 22 |
21 namespace media { | 23 namespace media { |
22 | 24 |
23 class CdmFactory; | 25 class CdmFactory; |
24 class MediaPermission; | 26 class MediaPermission; |
25 | 27 |
26 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. | 28 // ProxyDecryptor is for EME v0.1b only. It should not be used for the WD API. |
27 // A decryptor proxy that creates a real decryptor object on demand and | 29 // A decryptor proxy that creates a real decryptor object on demand and |
28 // forwards decryptor calls to it. | 30 // forwards decryptor calls to it. |
29 // | 31 // |
30 // TODO(xhwang): Currently we don't support run-time switching among decryptor | 32 // TODO(xhwang): Currently we don't support run-time switching among decryptor |
31 // objects. Fix this when needed. | 33 // objects. Fix this when needed. |
32 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! | 34 // TODO(xhwang): The ProxyDecryptor is not a Decryptor. Find a better name! |
33 class MEDIA_EXPORT ProxyDecryptor { | 35 class MEDIA_EXPORT ProxyDecryptor { |
34 public: | 36 public: |
| 37 // Callback to provide a CdmContext when the CDM creation is finished. |
| 38 // If CDM creation failed, |cdm_context| will be null. |
| 39 typedef base::Callback<void(CdmContext* cdm_context)> CdmContextReadyCB; |
| 40 |
35 // 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 |
36 // session ID rather than the internal session ID. | 42 // session ID rather than the internal session ID. |
37 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; | 43 typedef base::Callback<void(const std::string& session_id)> KeyAddedCB; |
38 typedef base::Callback<void(const std::string& session_id, | 44 typedef base::Callback<void(const std::string& session_id, |
39 MediaKeys::KeyError error_code, | 45 MediaKeys::KeyError error_code, |
40 uint32 system_code)> KeyErrorCB; | 46 uint32 system_code)> KeyErrorCB; |
41 typedef base::Callback<void(const std::string& session_id, | 47 typedef base::Callback<void(const std::string& session_id, |
42 const std::vector<uint8>& message, | 48 const std::vector<uint8>& message, |
43 const GURL& destination_url)> KeyMessageCB; | 49 const GURL& destination_url)> KeyMessageCB; |
44 | 50 |
45 ProxyDecryptor(MediaPermission* media_permission, | 51 ProxyDecryptor(MediaPermission* media_permission, |
46 const KeyAddedCB& key_added_cb, | 52 const KeyAddedCB& key_added_cb, |
47 const KeyErrorCB& key_error_cb, | 53 const KeyErrorCB& key_error_cb, |
48 const KeyMessageCB& key_message_cb); | 54 const KeyMessageCB& key_message_cb); |
49 virtual ~ProxyDecryptor(); | 55 virtual ~ProxyDecryptor(); |
50 | 56 |
51 // Returns the CdmContext associated with this object. | 57 // Creates the CDM and fires |cdm_created_cb|. This method should only be |
52 CdmContext* GetCdmContext(); | 58 // called once. If CDM creation failed, all following GenerateKeyRequest, |
| 59 // AddKey and CancelKeyRequest calls will result in a KeyError. |
| 60 void CreateCdm(CdmFactory* cdm_factory, |
| 61 const std::string& key_system, |
| 62 const GURL& security_origin, |
| 63 const CdmContextReadyCB& cdm_context_ready_cb); |
53 | 64 |
54 // Only call this once. | 65 // May only be called after CreateCDM(). |
55 bool InitializeCDM(CdmFactory* cdm_factory, | 66 void GenerateKeyRequest(EmeInitDataType init_data_type, |
56 const std::string& key_system, | |
57 const GURL& security_origin); | |
58 | |
59 // May only be called after InitializeCDM() succeeds. | |
60 bool GenerateKeyRequest(EmeInitDataType init_data_type, | |
61 const uint8* init_data, | 67 const uint8* init_data, |
62 int init_data_length); | 68 int init_data_length); |
63 void AddKey(const uint8* key, int key_length, | 69 void AddKey(const uint8* key, int key_length, |
64 const uint8* init_data, int init_data_length, | 70 const uint8* init_data, int init_data_length, |
65 const std::string& session_id); | 71 const std::string& session_id); |
66 void CancelKeyRequest(const std::string& session_id); | 72 void CancelKeyRequest(const std::string& session_id); |
67 | 73 |
68 private: | 74 private: |
69 // Helper function to create MediaKeys to handle the given |key_system|. | 75 // Callback for CreateCdm(). |
70 scoped_ptr<MediaKeys> CreateMediaKeys( | 76 void OnCdmCreated(const std::string& key_system, |
71 CdmFactory* cdm_factory, | 77 const GURL& security_origin, |
72 const std::string& key_system, | 78 const CdmContextReadyCB& cdm_context_ready_cb, |
73 const GURL& security_origin); | 79 scoped_ptr<MediaKeys> cdm); |
| 80 |
| 81 void GenerateKeyRequestInternal(EmeInitDataType init_data_type, |
| 82 const std::vector<uint8>& init_data); |
74 | 83 |
75 // Callbacks for firing session events. | 84 // Callbacks for firing session events. |
76 void OnSessionMessage(const std::string& session_id, | 85 void OnSessionMessage(const std::string& session_id, |
77 MediaKeys::MessageType message_type, | 86 MediaKeys::MessageType message_type, |
78 const std::vector<uint8>& message, | 87 const std::vector<uint8>& message, |
79 const GURL& legacy_destination_url); | 88 const GURL& legacy_destination_url); |
80 void OnSessionKeysChange(const std::string& session_id, | 89 void OnSessionKeysChange(const std::string& session_id, |
81 bool has_additional_usable_key, | 90 bool has_additional_usable_key, |
82 CdmKeysInfo keys_info); | 91 CdmKeysInfo keys_info); |
83 void OnSessionExpirationUpdate(const std::string& session_id, | 92 void OnSessionExpirationUpdate(const std::string& session_id, |
(...skipping 15 matching lines...) Expand all Loading... |
99 enum SessionCreationType { | 108 enum SessionCreationType { |
100 TemporarySession, | 109 TemporarySession, |
101 PersistentSession, | 110 PersistentSession, |
102 LoadSession | 111 LoadSession |
103 }; | 112 }; |
104 | 113 |
105 // Called when a session is actually created or loaded. | 114 // Called when a session is actually created or loaded. |
106 void SetSessionId(SessionCreationType session_type, | 115 void SetSessionId(SessionCreationType session_type, |
107 const std::string& session_id); | 116 const std::string& session_id); |
108 | 117 |
| 118 struct PendingGenerateKeyRequestData { |
| 119 PendingGenerateKeyRequestData(EmeInitDataType init_data_type, |
| 120 const std::vector<uint8>& init_data); |
| 121 ~PendingGenerateKeyRequestData(); |
| 122 |
| 123 const EmeInitDataType init_data_type; |
| 124 const std::vector<uint8> init_data; |
| 125 }; |
| 126 |
| 127 bool is_creating_cdm_; |
| 128 |
109 // The real MediaKeys that manages key operations for the ProxyDecryptor. | 129 // The real MediaKeys that manages key operations for the ProxyDecryptor. |
110 scoped_ptr<MediaKeys> media_keys_; | 130 scoped_ptr<MediaKeys> media_keys_; |
111 | 131 |
112 MediaPermission* media_permission_; | 132 MediaPermission* media_permission_; |
113 | 133 |
114 // Callbacks for firing key events. | 134 // Callbacks for firing key events. |
115 KeyAddedCB key_added_cb_; | 135 KeyAddedCB key_added_cb_; |
116 KeyErrorCB key_error_cb_; | 136 KeyErrorCB key_error_cb_; |
117 KeyMessageCB key_message_cb_; | 137 KeyMessageCB key_message_cb_; |
118 | 138 |
119 std::string key_system_; | 139 std::string key_system_; |
120 GURL security_origin_; | 140 GURL security_origin_; |
121 | 141 |
122 // Keep track of both persistent and non-persistent sessions. | 142 // Keep track of both persistent and non-persistent sessions. |
123 base::hash_map<std::string, bool> active_sessions_; | 143 base::hash_map<std::string, bool> active_sessions_; |
124 | 144 |
125 bool is_clear_key_; | 145 bool is_clear_key_; |
126 | 146 |
| 147 ScopedVector<PendingGenerateKeyRequestData> pending_requests_; |
| 148 |
127 // NOTE: Weak pointers must be invalidated before all other member variables. | 149 // NOTE: Weak pointers must be invalidated before all other member variables. |
128 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; | 150 base::WeakPtrFactory<ProxyDecryptor> weak_ptr_factory_; |
129 | 151 |
130 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); | 152 DISALLOW_COPY_AND_ASSIGN(ProxyDecryptor); |
131 }; | 153 }; |
132 | 154 |
133 } // namespace media | 155 } // namespace media |
134 | 156 |
135 #endif // MEDIA_CDM_PROXY_DECRYPTOR_H_ | 157 #endif // MEDIA_CDM_PROXY_DECRYPTOR_H_ |
OLD | NEW |