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> |
11 | 11 |
12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/synchronization/lock.h" |
15 #include "media/base/browser_cdm.h" | 17 #include "media/base/browser_cdm.h" |
16 #include "media/base/cdm_promise_adapter.h" | 18 #include "media/base/cdm_promise_adapter.h" |
17 #include "media/base/media_export.h" | 19 #include "media/base/media_export.h" |
18 #include "media/cdm/player_tracker_impl.h" | 20 #include "media/cdm/player_tracker_impl.h" |
19 #include "url/gurl.h" | 21 #include "url/gurl.h" |
20 | 22 |
21 class GURL; | 23 class GURL; |
22 | 24 |
23 namespace media { | 25 namespace media { |
24 | 26 |
25 class MediaPlayerManager; | 27 class MediaPlayerManager; |
26 | 28 |
27 // This class provides DRM services for android EME implementation. | 29 // This class provides DRM services for android EME implementation. |
28 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm { | 30 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm { |
29 public: | 31 public: |
30 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400 | 32 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400 |
31 enum SecurityLevel { | 33 enum SecurityLevel { |
32 SECURITY_LEVEL_NONE = 0, | 34 SECURITY_LEVEL_NONE = 0, |
33 SECURITY_LEVEL_1 = 1, | 35 SECURITY_LEVEL_1 = 1, |
34 SECURITY_LEVEL_3 = 3, | 36 SECURITY_LEVEL_3 = 3, |
35 }; | 37 }; |
36 | 38 |
37 typedef base::Callback<void(bool)> ResetCredentialsCB; | 39 typedef base::Callback<void(bool)> ResetCredentialsCB; |
38 | 40 |
39 ~MediaDrmBridge() override; | 41 ~MediaDrmBridge() override; |
40 | 42 |
| 43 void DeleteOnCorrectThread() override; |
| 44 |
41 // Checks whether MediaDRM is available. | 45 // Checks whether MediaDRM is available. |
42 // All other static methods check IsAvailable() internally. There's no need | 46 // All other static methods check IsAvailable() internally. There's no need |
43 // to check IsAvailable() explicitly before calling them. | 47 // to check IsAvailable() explicitly before calling them. |
44 static bool IsAvailable(); | 48 static bool IsAvailable(); |
45 | 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, |
66 const SessionMessageCB& session_message_cb, | 70 const SessionMessageCB& session_message_cb, |
67 const SessionClosedCB& session_closed_cb, | 71 const SessionClosedCB& session_closed_cb, |
68 const LegacySessionErrorCB& legacy_session_error_cb, | 72 const LegacySessionErrorCB& legacy_session_error_cb, |
69 const SessionKeysChangeCB& session_keys_change_cb, | 73 const SessionKeysChangeCB& session_keys_change_cb, |
70 const SessionExpirationUpdateCB& session_expiration_update_cb); | 74 const SessionExpirationUpdateCB& session_expiration_update_cb); |
71 | 75 |
72 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL | 76 // 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 | 77 // otherwise. No session callbacks are provided. This is used when we need to |
74 // use MediaDrmBridge without creating any sessions. | 78 // use MediaDrmBridge without creating any sessions. |
75 static scoped_ptr<MediaDrmBridge> CreateWithoutSessionSupport( | 79 static scoped_ptr<MediaDrmBridge, BrowserCdmDeleter> |
76 const std::string& key_system); | 80 CreateWithoutSessionSupport(const std::string& key_system); |
77 | 81 |
78 // Returns true if |security_level| is successfully set, or false otherwise. | 82 // Returns true if |security_level| is successfully set, or false otherwise. |
79 // Call this function right after Create() and before any other calls. | 83 // Call this function right after Create() and before any other calls. |
80 // Note: | 84 // Note: |
81 // - If this function is not called, the default security level of the device | 85 // - If this function is not called, the default security level of the device |
82 // will be used. | 86 // will be used. |
83 // - It's recommended to call this function only once on a MediaDrmBridge | 87 // - It's recommended to call this function only once on a MediaDrmBridge |
84 // object. Calling this function multiples times may cause errors. | 88 // object. Calling this function multiples times may cause errors. |
85 bool SetSecurityLevel(SecurityLevel security_level); | 89 bool SetSecurityLevel(SecurityLevel security_level); |
86 | 90 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 const SessionClosedCB& session_closed_cb, | 196 const SessionClosedCB& session_closed_cb, |
193 const LegacySessionErrorCB& legacy_session_error_cb, | 197 const LegacySessionErrorCB& legacy_session_error_cb, |
194 const SessionKeysChangeCB& session_keys_change_cb, | 198 const SessionKeysChangeCB& session_keys_change_cb, |
195 const SessionExpirationUpdateCB& session_expiration_update_cb); | 199 const SessionExpirationUpdateCB& session_expiration_update_cb); |
196 | 200 |
197 static bool IsSecureDecoderRequired(SecurityLevel security_level); | 201 static bool IsSecureDecoderRequired(SecurityLevel security_level); |
198 | 202 |
199 // Get the security level of the media. | 203 // Get the security level of the media. |
200 SecurityLevel GetSecurityLevel(); | 204 SecurityLevel GetSecurityLevel(); |
201 | 205 |
| 206 void InternalKeysAdded(bool has_additional_usable_key); |
| 207 |
202 // UUID of the key system. | 208 // UUID of the key system. |
203 std::vector<uint8> scheme_uuid_; | 209 std::vector<uint8> scheme_uuid_; |
204 | 210 |
205 // Java MediaDrm instance. | 211 // Java MediaDrm instance. |
206 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; | 212 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; |
207 | 213 |
208 // Callbacks for firing session events. | 214 // Callbacks for firing session events. |
209 SessionMessageCB session_message_cb_; | 215 SessionMessageCB session_message_cb_; |
210 SessionClosedCB session_closed_cb_; | 216 SessionClosedCB session_closed_cb_; |
211 LegacySessionErrorCB legacy_session_error_cb_; | 217 LegacySessionErrorCB legacy_session_error_cb_; |
212 SessionKeysChangeCB session_keys_change_cb_; | 218 SessionKeysChangeCB session_keys_change_cb_; |
213 SessionExpirationUpdateCB session_expiration_update_cb_; | 219 SessionExpirationUpdateCB session_expiration_update_cb_; |
214 | 220 |
215 base::Closure media_crypto_ready_cb_; | 221 base::Closure media_crypto_ready_cb_; |
216 | 222 |
217 ResetCredentialsCB reset_credentials_cb_; | 223 ResetCredentialsCB reset_credentials_cb_; |
218 | 224 |
219 PlayerTrackerImpl player_tracker_; | 225 PlayerTrackerImpl player_tracker_; |
220 | 226 |
221 CdmPromiseAdapter cdm_promise_adapter_; | 227 CdmPromiseAdapter cdm_promise_adapter_; |
222 | 228 |
| 229 // Callback for posting Java notifications to Media thread. |
| 230 typedef base::Callback<void(bool)> KeysAddedCallback; |
| 231 KeysAddedCallback internal_keys_added_cb_; |
| 232 |
| 233 // This flag is set when we use media thread for certain callbacks. |
| 234 bool use_media_thread_; |
| 235 |
| 236 // A flag with the lock to prevent GetMediaCrypto() calls |
| 237 // after we started destruction. Maybe it's possible to pass |
| 238 // MediaCrypto with a callback and avoid this. |
| 239 bool destruction_started_; |
| 240 base::Lock destruction_started_lock_; |
| 241 |
| 242 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 243 base::WeakPtrFactory<MediaDrmBridge> weak_factory_; |
| 244 |
223 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); | 245 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); |
224 }; | 246 }; |
225 | 247 |
226 } // namespace media | 248 } // namespace media |
227 | 249 |
228 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ | 250 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ |
OLD | NEW |