OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_BLINK_CDM_SESSION_ADAPTER_H_ | 5 #ifndef MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ |
6 #define MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ | 6 #define MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "media/base/media_keys.h" | 18 #include "media/base/content_decryption_module.h" |
19 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 19 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
20 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h
" | 20 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleSession.h
" |
21 | 21 |
22 class GURL; | 22 class GURL; |
23 | 23 |
24 namespace media { | 24 namespace media { |
25 | 25 |
26 struct CdmConfig; | 26 struct CdmConfig; |
27 class CdmFactory; | 27 class CdmFactory; |
28 class WebContentDecryptionModuleSessionImpl; | 28 class WebContentDecryptionModuleSessionImpl; |
29 | 29 |
30 // Owns the CDM instance and makes calls from session objects to the CDM. | 30 // Owns the CDM instance and makes calls from session objects to the CDM. |
31 // Forwards the session ID-based callbacks of the MediaKeys interface to the | 31 // Forwards the session ID-based callbacks of the ContentDecryptionModule |
32 // appropriate session object. Callers should hold references to this class | 32 // interface to the appropriate session object. Callers should hold references |
33 // as long as they need the CDM instance. | 33 // to this class as long as they need the CDM instance. |
34 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { | 34 class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { |
35 public: | 35 public: |
36 CdmSessionAdapter(); | 36 CdmSessionAdapter(); |
37 | 37 |
38 // Creates the CDM for |key_system| using |cdm_factory| and returns the result | 38 // Creates the CDM for |key_system| using |cdm_factory| and returns the result |
39 // via |result|. | 39 // via |result|. |
40 void CreateCdm( | 40 void CreateCdm( |
41 CdmFactory* cdm_factory, | 41 CdmFactory* cdm_factory, |
42 const std::string& key_system, | 42 const std::string& key_system, |
43 const GURL& security_origin, | 43 const GURL& security_origin, |
(...skipping 17 matching lines...) Expand all Loading... |
61 const std::string& session_id, | 61 const std::string& session_id, |
62 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session); | 62 base::WeakPtr<WebContentDecryptionModuleSessionImpl> session); |
63 | 63 |
64 // Removes a session from the internal map. | 64 // Removes a session from the internal map. |
65 void UnregisterSession(const std::string& session_id); | 65 void UnregisterSession(const std::string& session_id); |
66 | 66 |
67 // Initializes a session with the |init_data_type|, |init_data| and | 67 // Initializes a session with the |init_data_type|, |init_data| and |
68 // |session_type| provided. | 68 // |session_type| provided. |
69 void InitializeNewSession(EmeInitDataType init_data_type, | 69 void InitializeNewSession(EmeInitDataType init_data_type, |
70 const std::vector<uint8_t>& init_data, | 70 const std::vector<uint8_t>& init_data, |
71 MediaKeys::SessionType session_type, | 71 ContentDecryptionModule::SessionType session_type, |
72 std::unique_ptr<NewSessionCdmPromise> promise); | 72 std::unique_ptr<NewSessionCdmPromise> promise); |
73 | 73 |
74 // Loads the session specified by |session_id|. | 74 // Loads the session specified by |session_id|. |
75 void LoadSession(MediaKeys::SessionType session_type, | 75 void LoadSession(ContentDecryptionModule::SessionType session_type, |
76 const std::string& session_id, | 76 const std::string& session_id, |
77 std::unique_ptr<NewSessionCdmPromise> promise); | 77 std::unique_ptr<NewSessionCdmPromise> promise); |
78 | 78 |
79 // Updates the session specified by |session_id| with |response|. | 79 // Updates the session specified by |session_id| with |response|. |
80 void UpdateSession(const std::string& session_id, | 80 void UpdateSession(const std::string& session_id, |
81 const std::vector<uint8_t>& response, | 81 const std::vector<uint8_t>& response, |
82 std::unique_ptr<SimpleCdmPromise> promise); | 82 std::unique_ptr<SimpleCdmPromise> promise); |
83 | 83 |
84 // Closes the session specified by |session_id|. | 84 // Closes the session specified by |session_id|. |
85 void CloseSession(const std::string& session_id, | 85 void CloseSession(const std::string& session_id, |
86 std::unique_ptr<SimpleCdmPromise> promise); | 86 std::unique_ptr<SimpleCdmPromise> promise); |
87 | 87 |
88 // Removes stored session data associated with the session specified by | 88 // Removes stored session data associated with the session specified by |
89 // |session_id|. | 89 // |session_id|. |
90 void RemoveSession(const std::string& session_id, | 90 void RemoveSession(const std::string& session_id, |
91 std::unique_ptr<SimpleCdmPromise> promise); | 91 std::unique_ptr<SimpleCdmPromise> promise); |
92 | 92 |
93 // Returns a reference to the CDM. | 93 // Returns a reference to the CDM. |
94 scoped_refptr<MediaKeys> GetCdm(); | 94 scoped_refptr<ContentDecryptionModule> GetCdm(); |
95 | 95 |
96 // Returns the key system name. | 96 // Returns the key system name. |
97 const std::string& GetKeySystem() const; | 97 const std::string& GetKeySystem() const; |
98 | 98 |
99 // Returns a prefix to use for UMAs. | 99 // Returns a prefix to use for UMAs. |
100 const std::string& GetKeySystemUMAPrefix() const; | 100 const std::string& GetKeySystemUMAPrefix() const; |
101 | 101 |
102 private: | 102 private: |
103 friend class base::RefCounted<CdmSessionAdapter>; | 103 friend class base::RefCounted<CdmSessionAdapter>; |
104 | 104 |
105 // Session ID to WebContentDecryptionModuleSessionImpl mapping. | 105 // Session ID to WebContentDecryptionModuleSessionImpl mapping. |
106 typedef base::hash_map<std::string, | 106 typedef base::hash_map<std::string, |
107 base::WeakPtr<WebContentDecryptionModuleSessionImpl> > | 107 base::WeakPtr<WebContentDecryptionModuleSessionImpl> > |
108 SessionMap; | 108 SessionMap; |
109 | 109 |
110 ~CdmSessionAdapter(); | 110 ~CdmSessionAdapter(); |
111 | 111 |
112 // Callback for CreateCdm(). | 112 // Callback for CreateCdm(). |
113 void OnCdmCreated(const std::string& key_system, | 113 void OnCdmCreated(const std::string& key_system, |
114 base::TimeTicks start_time, | 114 base::TimeTicks start_time, |
115 const scoped_refptr<MediaKeys>& cdm, | 115 const scoped_refptr<ContentDecryptionModule>& cdm, |
116 const std::string& error_message); | 116 const std::string& error_message); |
117 | 117 |
118 // Callbacks for firing session events. | 118 // Callbacks for firing session events. |
119 void OnSessionMessage(const std::string& session_id, | 119 void OnSessionMessage(const std::string& session_id, |
120 MediaKeys::MessageType message_type, | 120 ContentDecryptionModule::MessageType message_type, |
121 const std::vector<uint8_t>& message); | 121 const std::vector<uint8_t>& message); |
122 void OnSessionKeysChange(const std::string& session_id, | 122 void OnSessionKeysChange(const std::string& session_id, |
123 bool has_additional_usable_key, | 123 bool has_additional_usable_key, |
124 CdmKeysInfo keys_info); | 124 CdmKeysInfo keys_info); |
125 void OnSessionExpirationUpdate(const std::string& session_id, | 125 void OnSessionExpirationUpdate(const std::string& session_id, |
126 base::Time new_expiry_time); | 126 base::Time new_expiry_time); |
127 void OnSessionClosed(const std::string& session_id); | 127 void OnSessionClosed(const std::string& session_id); |
128 | 128 |
129 // Helper function of the callbacks. | 129 // Helper function of the callbacks. |
130 WebContentDecryptionModuleSessionImpl* GetSession( | 130 WebContentDecryptionModuleSessionImpl* GetSession( |
131 const std::string& session_id); | 131 const std::string& session_id); |
132 | 132 |
133 void ReportTimeToCreateCdmUMA(base::TimeDelta cdm_creation_time) const; | 133 void ReportTimeToCreateCdmUMA(base::TimeDelta cdm_creation_time) const; |
134 | 134 |
135 scoped_refptr<MediaKeys> cdm_; | 135 scoped_refptr<ContentDecryptionModule> cdm_; |
136 | 136 |
137 SessionMap sessions_; | 137 SessionMap sessions_; |
138 | 138 |
139 std::string key_system_; | 139 std::string key_system_; |
140 std::string key_system_uma_prefix_; | 140 std::string key_system_uma_prefix_; |
141 | 141 |
142 // A unique ID to trace CdmSessionAdapter::CreateCdm() call and the matching | 142 // A unique ID to trace CdmSessionAdapter::CreateCdm() call and the matching |
143 // OnCdmCreated() call. | 143 // OnCdmCreated() call. |
144 uint32_t trace_id_; | 144 uint32_t trace_id_; |
145 | 145 |
146 std::unique_ptr<blink::WebContentDecryptionModuleResult> cdm_created_result_; | 146 std::unique_ptr<blink::WebContentDecryptionModuleResult> cdm_created_result_; |
147 | 147 |
148 // NOTE: Weak pointers must be invalidated before all other member variables. | 148 // NOTE: Weak pointers must be invalidated before all other member variables. |
149 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; | 149 base::WeakPtrFactory<CdmSessionAdapter> weak_ptr_factory_; |
150 | 150 |
151 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); | 151 DISALLOW_COPY_AND_ASSIGN(CdmSessionAdapter); |
152 }; | 152 }; |
153 | 153 |
154 } // namespace media | 154 } // namespace media |
155 | 155 |
156 #endif // MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ | 156 #endif // MEDIA_BLINK_CDM_SESSION_ADAPTER_H_ |
OLD | NEW |