| 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 <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 using ResetCredentialsCB = base::Callback<void(bool)>; | 61 using ResetCredentialsCB = base::Callback<void(bool)>; |
| 62 | 62 |
| 63 // Notification called when MediaCrypto object is ready. | 63 // Notification called when MediaCrypto object is ready. |
| 64 // Parameters: | 64 // Parameters: |
| 65 // |media_crypto| - global reference to MediaCrypto object | 65 // |media_crypto| - global reference to MediaCrypto object |
| 66 // |needs_protected_surface| - true if protected surface is required. | 66 // |needs_protected_surface| - true if protected surface is required. |
| 67 using MediaCryptoReadyCB = base::Callback<void(JavaObjectPtr media_crypto, | 67 using MediaCryptoReadyCB = base::Callback<void(JavaObjectPtr media_crypto, |
| 68 bool needs_protected_surface)>; | 68 bool needs_protected_surface)>; |
| 69 | 69 |
| 70 using CreatedCB = base::OnceCallback<void(scoped_refptr<MediaDrmBridge>)>; |
| 71 |
| 70 // Checks whether MediaDRM is available and usable, including for decoding. | 72 // Checks whether MediaDRM is available and usable, including for decoding. |
| 71 // All other static methods check IsAvailable() or equivalent internally. | 73 // All other static methods check IsAvailable() or equivalent internally. |
| 72 // There is no need to check IsAvailable() explicitly before calling them. | 74 // There is no need to check IsAvailable() explicitly before calling them. |
| 73 static bool IsAvailable(); | 75 static bool IsAvailable(); |
| 74 | 76 |
| 75 static bool RegisterMediaDrmBridge(JNIEnv* env); | 77 static bool RegisterMediaDrmBridge(JNIEnv* env); |
| 76 | 78 |
| 77 // Checks whether |key_system| is supported. | 79 // Checks whether |key_system| is supported. |
| 78 static bool IsKeySystemSupported(const std::string& key_system); | 80 static bool IsKeySystemSupported(const std::string& key_system); |
| 79 | 81 |
| 80 // Checks whether |key_system| is supported with |container_mime_type|. | 82 // Checks whether |key_system| is supported with |container_mime_type|. |
| 81 // |container_mime_type| must not be empty. | 83 // |container_mime_type| must not be empty. |
| 82 static bool IsKeySystemSupportedWithType( | 84 static bool IsKeySystemSupportedWithType( |
| 83 const std::string& key_system, | 85 const std::string& key_system, |
| 84 const std::string& container_mime_type); | 86 const std::string& container_mime_type); |
| 85 | 87 |
| 86 static bool IsPersistentLicenseTypeSupported(const std::string& key_system); | 88 static bool IsPersistentLicenseTypeSupported(const std::string& key_system); |
| 87 | 89 |
| 88 // Returns the list of the platform-supported key system names that | 90 // Returns the list of the platform-supported key system names that |
| 89 // are not handled by Chrome explicitly. | 91 // are not handled by Chrome explicitly. |
| 90 static std::vector<std::string> GetPlatformKeySystemNames(); | 92 static std::vector<std::string> GetPlatformKeySystemNames(); |
| 91 | 93 |
| 92 // Returns a MediaDrmBridge instance if |key_system| and |security_level| are | 94 // Returns a MediaDrmBridge instance if |key_system| and |security_level| are |
| 93 // supported, and nullptr otherwise. The default security level will be used | 95 // supported, and nullptr otherwise. The default security level will be used |
| 94 // if |security_level| is SECURITY_LEVEL_DEFAULT. | 96 // if |security_level| is SECURITY_LEVEL_DEFAULT. |
| 95 static scoped_refptr<MediaDrmBridge> Create( | 97 static void Create( |
| 96 const std::string& key_system, | 98 const std::string& key_system, |
| 97 const GURL& security_origin, | 99 const GURL& security_origin, |
| 98 SecurityLevel security_level, | 100 SecurityLevel security_level, |
| 99 const CreateFetcherCB& create_fetcher_cb, | 101 const CreateFetcherCB& create_fetcher_cb, |
| 100 const CreateStorageCB& create_storage_cb, | 102 const CreateStorageCB& create_storage_cb, |
| 101 const SessionMessageCB& session_message_cb, | 103 const SessionMessageCB& session_message_cb, |
| 102 const SessionClosedCB& session_closed_cb, | 104 const SessionClosedCB& session_closed_cb, |
| 103 const SessionKeysChangeCB& session_keys_change_cb, | 105 const SessionKeysChangeCB& session_keys_change_cb, |
| 104 const SessionExpirationUpdateCB& session_expiration_update_cb); | 106 const SessionExpirationUpdateCB& session_expiration_update_cb, |
| 107 CreatedCB created_cb); |
| 105 | 108 |
| 106 // Same as Create() except that no session callbacks are provided. This is | 109 // Same as Create() except that no session callbacks are provided. This is |
| 107 // used when we need to use MediaDrmBridge without creating any sessions. | 110 // used when we need to use MediaDrmBridge without creating any sessions. |
| 108 // TODO(yucliu): Pass |security_origin| here to clear per-origin certs and | 111 // TODO(yucliu): Pass |security_origin| here to clear per-origin certs and |
| 109 // licenses. | 112 // licenses. |
| 110 static scoped_refptr<MediaDrmBridge> CreateWithoutSessionSupport( | 113 static void CreateWithoutSessionSupport( |
| 111 const std::string& key_system, | 114 const std::string& key_system, |
| 112 SecurityLevel security_level, | 115 SecurityLevel security_level, |
| 113 const CreateFetcherCB& create_fetcher_cb); | 116 const CreateFetcherCB& create_fetcher_cb, |
| 117 CreatedCB created_cb); |
| 114 | 118 |
| 115 // ContentDecryptionModule implementation. | 119 // ContentDecryptionModule implementation. |
| 116 void SetServerCertificate( | 120 void SetServerCertificate( |
| 117 const std::vector<uint8_t>& certificate, | 121 const std::vector<uint8_t>& certificate, |
| 118 std::unique_ptr<media::SimpleCdmPromise> promise) override; | 122 std::unique_ptr<media::SimpleCdmPromise> promise) override; |
| 119 void CreateSessionAndGenerateRequest( | 123 void CreateSessionAndGenerateRequest( |
| 120 CdmSessionType session_type, | 124 CdmSessionType session_type, |
| 121 media::EmeInitDataType init_data_type, | 125 media::EmeInitDataType init_data_type, |
| 122 const std::vector<uint8_t>& init_data, | 126 const std::vector<uint8_t>& init_data, |
| 123 std::unique_ptr<media::NewSessionCdmPromise> promise) override; | 127 std::unique_ptr<media::NewSessionCdmPromise> promise) override; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Called by the java object when credential reset is completed. | 242 // Called by the java object when credential reset is completed. |
| 239 void OnResetDeviceCredentialsCompleted( | 243 void OnResetDeviceCredentialsCompleted( |
| 240 JNIEnv* env, | 244 JNIEnv* env, |
| 241 const base::android::JavaParamRef<jobject>&, | 245 const base::android::JavaParamRef<jobject>&, |
| 242 bool success); | 246 bool success); |
| 243 | 247 |
| 244 private: | 248 private: |
| 245 // For DeleteSoon() in DeleteOnCorrectThread(). | 249 // For DeleteSoon() in DeleteOnCorrectThread(). |
| 246 friend class base::DeleteHelper<MediaDrmBridge>; | 250 friend class base::DeleteHelper<MediaDrmBridge>; |
| 247 | 251 |
| 248 static scoped_refptr<MediaDrmBridge> CreateInternal( | 252 static void CreateInternal( |
| 249 const std::string& key_system, | 253 const std::vector<uint8_t>& scheme_uuid, |
| 250 const GURL& security_origin, | |
| 251 SecurityLevel security_level, | 254 SecurityLevel security_level, |
| 255 std::unique_ptr<MediaDrmStorageBridge> storage, |
| 252 const CreateFetcherCB& create_fetcher_cb, | 256 const CreateFetcherCB& create_fetcher_cb, |
| 253 const CreateStorageCB& create_storage_cb, | |
| 254 const SessionMessageCB& session_message_cb, | 257 const SessionMessageCB& session_message_cb, |
| 255 const SessionClosedCB& session_closed_cb, | 258 const SessionClosedCB& session_closed_cb, |
| 256 const SessionKeysChangeCB& session_keys_change_cb, | 259 const SessionKeysChangeCB& session_keys_change_cb, |
| 257 const SessionExpirationUpdateCB& session_expiration_update_cb); | 260 const SessionExpirationUpdateCB& session_expiration_update_cb, |
| 261 CreatedCB bound_cdm_created_cb); |
| 258 | 262 |
| 259 // Constructs a MediaDrmBridge for |scheme_uuid| and |security_level|. The | 263 // Constructs a MediaDrmBridge for |scheme_uuid| and |security_level|. The |
| 260 // default security level will be used if |security_level| is | 264 // default security level will be used if |security_level| is |
| 261 // SECURITY_LEVEL_DEFAULT. Sessions should not be created if session callbacks | 265 // SECURITY_LEVEL_DEFAULT. Sessions should not be created if session callbacks |
| 262 // are null. | 266 // are null. |
| 263 MediaDrmBridge(const std::vector<uint8_t>& scheme_uuid, | 267 MediaDrmBridge(const std::vector<uint8_t>& scheme_uuid, |
| 264 const GURL& security_origin, | |
| 265 SecurityLevel security_level, | 268 SecurityLevel security_level, |
| 269 std::unique_ptr<MediaDrmStorageBridge> storage, |
| 266 const CreateFetcherCB& create_fetcher_cb, | 270 const CreateFetcherCB& create_fetcher_cb, |
| 267 const CreateStorageCB& create_storage_cb, | |
| 268 const SessionMessageCB& session_message_cb, | 271 const SessionMessageCB& session_message_cb, |
| 269 const SessionClosedCB& session_closed_cb, | 272 const SessionClosedCB& session_closed_cb, |
| 270 const SessionKeysChangeCB& session_keys_change_cb, | 273 const SessionKeysChangeCB& session_keys_change_cb, |
| 271 const SessionExpirationUpdateCB& session_expiration_update_cb); | 274 const SessionExpirationUpdateCB& session_expiration_update_cb); |
| 272 | 275 |
| 273 ~MediaDrmBridge() override; | 276 ~MediaDrmBridge() override; |
| 274 | 277 |
| 275 static bool IsSecureDecoderRequired(SecurityLevel security_level); | 278 static bool IsSecureDecoderRequired(SecurityLevel security_level); |
| 276 | 279 |
| 277 // Get the security level of the media. | 280 // Get the security level of the media. |
| 278 SecurityLevel GetSecurityLevel(); | 281 SecurityLevel GetSecurityLevel(); |
| 279 | 282 |
| 280 // A helper method that is called when MediaCrypto is ready. | 283 // A helper method that is called when MediaCrypto is ready. |
| 281 void NotifyMediaCryptoReady(JavaObjectPtr j_media_crypto); | 284 void NotifyMediaCryptoReady(JavaObjectPtr j_media_crypto); |
| 282 | 285 |
| 283 // Sends HTTP provisioning request to a provisioning server. | 286 // Sends HTTP provisioning request to a provisioning server. |
| 284 void SendProvisioningRequest(const std::string& default_url, | 287 void SendProvisioningRequest(const std::string& default_url, |
| 285 const std::string& request_data); | 288 const std::string& request_data); |
| 286 | 289 |
| 287 // Process the data received by provisioning server. | 290 // Process the data received by provisioning server. |
| 288 void ProcessProvisionResponse(bool success, const std::string& response); | 291 void ProcessProvisionResponse(bool success, const std::string& response); |
| 289 | 292 |
| 290 // Called on the |task_runner_| when there is additional usable key. | 293 // Called on the |task_runner_| when there is additional usable key. |
| 291 void OnHasAdditionalUsableKey(); | 294 void OnHasAdditionalUsableKey(); |
| 292 | 295 |
| 293 // UUID of the key system. | 296 // UUID of the key system. |
| 294 std::vector<uint8_t> scheme_uuid_; | 297 std::vector<uint8_t> scheme_uuid_; |
| 295 | 298 |
| 296 // Persistent storage for session ID map. | 299 // Persistent storage for session ID map. It may or may not be bound to an |
| 297 MediaDrmStorageBridge storage_; | 300 // origin. |
| 301 std::unique_ptr<MediaDrmStorageBridge> storage_; |
| 298 | 302 |
| 299 // Java MediaDrm instance. | 303 // Java MediaDrm instance. |
| 300 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; | 304 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; |
| 301 | 305 |
| 302 // Java MediaCrypto instance. Possible values are: | 306 // Java MediaCrypto instance. Possible values are: |
| 303 // !j_media_crypto_: | 307 // !j_media_crypto_: |
| 304 // MediaCrypto creation has not been notified via NotifyMediaCryptoReady(). | 308 // MediaCrypto creation has not been notified via NotifyMediaCryptoReady(). |
| 305 // !j_media_crypto_->is_null(): | 309 // !j_media_crypto_->is_null(): |
| 306 // MediaCrypto creation succeeded and it has been notified. | 310 // MediaCrypto creation succeeded and it has been notified. |
| 307 // j_media_crypto_->is_null(): | 311 // j_media_crypto_->is_null(): |
| (...skipping 28 matching lines...) Expand all Loading... |
| 336 | 340 |
| 337 // NOTE: Weak pointers must be invalidated before all other member variables. | 341 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 338 base::WeakPtrFactory<MediaDrmBridge> weak_factory_; | 342 base::WeakPtrFactory<MediaDrmBridge> weak_factory_; |
| 339 | 343 |
| 340 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); | 344 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); |
| 341 }; | 345 }; |
| 342 | 346 |
| 343 } // namespace media | 347 } // namespace media |
| 344 | 348 |
| 345 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ | 349 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ |
| OLD | NEW |