OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ | 5 #ifndef MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ |
6 #define MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ | 6 #define MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 typedef base::Callback<void(bool)> ResetCredentialsCB; | 37 typedef base::Callback<void(bool)> ResetCredentialsCB; |
38 | 38 |
39 ~MediaDrmBridge() override; | 39 ~MediaDrmBridge() override; |
40 | 40 |
41 // Checks whether MediaDRM is available. | 41 // Checks whether MediaDRM is available. |
42 // All other static methods check IsAvailable() internally. There's no need | 42 // All other static methods check IsAvailable() internally. There's no need |
43 // to check IsAvailable() explicitly before calling them. | 43 // to check IsAvailable() explicitly before calling them. |
44 static bool IsAvailable(); | 44 static bool IsAvailable(); |
45 | 45 |
| 46 // Checks whether we can create the DRM for key system and security level. |
| 47 static bool CanCreate(const std::string& key_system, |
| 48 SecurityLevel widevine_security_level); |
| 49 |
46 // Checks whether |key_system| is supported. | 50 // Checks whether |key_system| is supported. |
47 static bool IsKeySystemSupported(const std::string& key_system); | 51 static bool IsKeySystemSupported(const std::string& key_system); |
48 | 52 |
49 // Returns the list of the platform-supported key system names that | 53 // Returns the list of the platform-supported key system names that |
50 // are not handled by Chrome explicitly. | 54 // are not handled by Chrome explicitly. |
51 static std::vector<std::string> GetPlatformKeySystemNames(); | 55 static std::vector<std::string> GetPlatformKeySystemNames(); |
52 | 56 |
53 // Checks whether |key_system| is supported with |container_mime_type|. | 57 // Checks whether |key_system| is supported with |container_mime_type|. |
54 // |container_mime_type| must not be empty. | 58 // |container_mime_type| must not be empty. |
55 static bool IsKeySystemSupportedWithType( | 59 static bool IsKeySystemSupportedWithType( |
56 const std::string& key_system, | 60 const std::string& key_system, |
57 const std::string& container_mime_type); | 61 const std::string& container_mime_type); |
58 | 62 |
59 static bool RegisterMediaDrmBridge(JNIEnv* env); | 63 static bool RegisterMediaDrmBridge(JNIEnv* env); |
60 | 64 |
61 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL | 65 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL |
62 // pointer otherwise. | 66 // pointer otherwise. |
63 // TODO(xhwang): Is it okay not to update session expiration info? | 67 // TODO(xhwang): Is it okay not to update session expiration info? |
64 static scoped_ptr<MediaDrmBridge> Create( | 68 static scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> Create( |
65 const std::string& key_system, | 69 const std::string& key_system, |
| 70 SecurityLevel widevine_security_level, |
66 const SessionMessageCB& session_message_cb, | 71 const SessionMessageCB& session_message_cb, |
67 const SessionClosedCB& session_closed_cb, | 72 const SessionClosedCB& session_closed_cb, |
68 const LegacySessionErrorCB& legacy_session_error_cb, | 73 const LegacySessionErrorCB& legacy_session_error_cb, |
69 const SessionKeysChangeCB& session_keys_change_cb, | 74 const SessionKeysChangeCB& session_keys_change_cb, |
70 const SessionExpirationUpdateCB& session_expiration_update_cb); | 75 const SessionExpirationUpdateCB& session_expiration_update_cb); |
71 | 76 |
72 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL | 77 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL |
73 // otherwise. No session callbacks are provided. This is used when we need to | 78 // otherwise. No session callbacks are provided. This is used when we need to |
74 // use MediaDrmBridge without creating any sessions. | 79 // use MediaDrmBridge without creating any sessions. |
75 static scoped_ptr<MediaDrmBridge> CreateWithoutSessionSupport( | 80 static scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> |
76 const std::string& key_system); | 81 CreateWithoutSessionSupport(const std::string& key_system); |
77 | 82 |
78 // Returns true if |security_level| is successfully set, or false otherwise. | 83 // Returns true if |security_level| is successfully set, or false otherwise. |
79 // Call this function right after Create() and before any other calls. | 84 // Call this function right after Create() and before any other calls. |
80 // Note: | 85 // Note: |
81 // - If this function is not called, the default security level of the device | 86 // - If this function is not called, the default security level of the device |
82 // will be used. | 87 // will be used. |
83 // - It's recommended to call this function only once on a MediaDrmBridge | 88 // - It's recommended to call this function only once on a MediaDrmBridge |
84 // object. Calling this function multiples times may cause errors. | 89 // object. Calling this function multiples times may cause errors. |
85 bool SetSecurityLevel(SecurityLevel security_level); | 90 bool SetSecurityLevel(SecurityLevel security_level); |
86 | 91 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 const SessionClosedCB& session_closed_cb, | 197 const SessionClosedCB& session_closed_cb, |
193 const LegacySessionErrorCB& legacy_session_error_cb, | 198 const LegacySessionErrorCB& legacy_session_error_cb, |
194 const SessionKeysChangeCB& session_keys_change_cb, | 199 const SessionKeysChangeCB& session_keys_change_cb, |
195 const SessionExpirationUpdateCB& session_expiration_update_cb); | 200 const SessionExpirationUpdateCB& session_expiration_update_cb); |
196 | 201 |
197 static bool IsSecureDecoderRequired(SecurityLevel security_level); | 202 static bool IsSecureDecoderRequired(SecurityLevel security_level); |
198 | 203 |
199 // Get the security level of the media. | 204 // Get the security level of the media. |
200 SecurityLevel GetSecurityLevel(); | 205 SecurityLevel GetSecurityLevel(); |
201 | 206 |
| 207 void InternalPromiseResolved(uint32_t promise_id); |
| 208 void InternalPromiseResolvedWithSession(uint32_t promise_id, |
| 209 const std::string& session_id); |
| 210 void InternalPromiseRejected(uint32_t promise_id, |
| 211 const std::string& error_message); |
| 212 void InternalSessionKeysChanged(const std::string& session_id, |
| 213 bool has_additional_usable_key, |
| 214 CdmKeysInfo cdm_keys_info); |
| 215 |
| 216 void InternalKeysAdded(bool has_additional_usable_key); |
| 217 |
202 // UUID of the key system. | 218 // UUID of the key system. |
203 std::vector<uint8> scheme_uuid_; | 219 std::vector<uint8> scheme_uuid_; |
204 | 220 |
205 // Java MediaDrm instance. | 221 // Java MediaDrm instance. |
206 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; | 222 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; |
207 | 223 |
208 // Callbacks for firing session events. | 224 // Callbacks for firing session events. |
209 SessionMessageCB session_message_cb_; | 225 SessionMessageCB session_message_cb_; |
210 SessionClosedCB session_closed_cb_; | 226 SessionClosedCB session_closed_cb_; |
211 LegacySessionErrorCB legacy_session_error_cb_; | 227 LegacySessionErrorCB legacy_session_error_cb_; |
212 SessionKeysChangeCB session_keys_change_cb_; | 228 SessionKeysChangeCB session_keys_change_cb_; |
213 SessionExpirationUpdateCB session_expiration_update_cb_; | 229 SessionExpirationUpdateCB session_expiration_update_cb_; |
214 | 230 |
215 base::Closure media_crypto_ready_cb_; | 231 base::Closure media_crypto_ready_cb_; |
216 | 232 |
217 ResetCredentialsCB reset_credentials_cb_; | 233 ResetCredentialsCB reset_credentials_cb_; |
218 | 234 |
219 PlayerTrackerImpl player_tracker_; | 235 PlayerTrackerImpl player_tracker_; |
220 | 236 |
221 CdmPromiseAdapter cdm_promise_adapter_; | 237 CdmPromiseAdapter cdm_promise_adapter_; |
222 | 238 |
| 239 // Callbacks for posting Java notifications to Media thread |
| 240 typedef base::Callback<void(uint32_t)> PromiseCallback; |
| 241 typedef base::Callback<void(uint32_t, const std::string&)> PromiseWSCallback; |
| 242 typedef base::Callback<void(bool)> KeysAddedCallback; |
| 243 |
| 244 PromiseCallback internal_promise_resolved_cb_; |
| 245 PromiseWSCallback internal_promise_resolved_with_session_cb_; |
| 246 PromiseWSCallback internal_promise_rejected_cb_; |
| 247 SessionKeysChangeCB internal_session_keys_changed_cb_; |
| 248 |
| 249 KeysAddedCallback internal_keys_added_cb_; |
| 250 |
| 251 bool run_on_media_thread_; |
| 252 |
223 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); | 253 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); |
224 }; | 254 }; |
225 | 255 |
226 } // namespace media | 256 } // namespace media |
227 | 257 |
228 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ | 258 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ |
OLD | NEW |