| 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 14 matching lines...) Expand all Loading... |
| 25 namespace media { | 25 namespace media { |
| 26 | 26 |
| 27 // Implements a CDM using Android MediaDrm API. | 27 // Implements a CDM using Android MediaDrm API. |
| 28 // | 28 // |
| 29 // Thread Safety: | 29 // Thread Safety: |
| 30 // | 30 // |
| 31 // This class lives on the thread where it is created. All methods must be | 31 // This class lives on the thread where it is created. All methods must be |
| 32 // called on the |task_runner_| except for the PlayerTracker methods and | 32 // called on the |task_runner_| except for the PlayerTracker methods and |
| 33 // SetMediaCryptoReadyCB(), which can be called on any thread. | 33 // SetMediaCryptoReadyCB(), which can be called on any thread. |
| 34 | 34 |
| 35 class ProvisionFetcher; |
| 36 |
| 35 class MEDIA_EXPORT MediaDrmBridge : public MediaKeys, public PlayerTracker { | 37 class MEDIA_EXPORT MediaDrmBridge : public MediaKeys, public PlayerTracker { |
| 36 public: | 38 public: |
| 37 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400 | 39 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400 |
| 38 enum SecurityLevel { | 40 enum SecurityLevel { |
| 39 SECURITY_LEVEL_NONE = 0, | 41 SECURITY_LEVEL_NONE = 0, |
| 40 SECURITY_LEVEL_1 = 1, | 42 SECURITY_LEVEL_1 = 1, |
| 41 SECURITY_LEVEL_3 = 3, | 43 SECURITY_LEVEL_3 = 3, |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 using JavaObjectPtr = scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>>; | 46 using JavaObjectPtr = scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>>; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 70 | 72 |
| 71 // Returns the list of the platform-supported key system names that | 73 // Returns the list of the platform-supported key system names that |
| 72 // are not handled by Chrome explicitly. | 74 // are not handled by Chrome explicitly. |
| 73 static std::vector<std::string> GetPlatformKeySystemNames(); | 75 static std::vector<std::string> GetPlatformKeySystemNames(); |
| 74 | 76 |
| 75 // 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 |
| 76 // pointer otherwise. | 78 // pointer otherwise. |
| 77 // TODO(xhwang): Is it okay not to update session expiration info? | 79 // TODO(xhwang): Is it okay not to update session expiration info? |
| 78 static scoped_refptr<MediaDrmBridge> Create( | 80 static scoped_refptr<MediaDrmBridge> Create( |
| 79 const std::string& key_system, | 81 const std::string& key_system, |
| 82 scoped_ptr<ProvisionFetcher> provision_fetcher, |
| 80 const SessionMessageCB& session_message_cb, | 83 const SessionMessageCB& session_message_cb, |
| 81 const SessionClosedCB& session_closed_cb, | 84 const SessionClosedCB& session_closed_cb, |
| 82 const LegacySessionErrorCB& legacy_session_error_cb, | 85 const LegacySessionErrorCB& legacy_session_error_cb, |
| 83 const SessionKeysChangeCB& session_keys_change_cb, | 86 const SessionKeysChangeCB& session_keys_change_cb, |
| 84 const SessionExpirationUpdateCB& session_expiration_update_cb); | 87 const SessionExpirationUpdateCB& session_expiration_update_cb); |
| 85 | 88 |
| 86 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL | 89 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL |
| 87 // otherwise. No session callbacks are provided. This is used when we need to | 90 // otherwise. No session callbacks are provided. This is used when we need to |
| 88 // use MediaDrmBridge without creating any sessions. | 91 // use MediaDrmBridge without creating any sessions. |
| 89 static scoped_refptr<MediaDrmBridge> CreateWithoutSessionSupport( | 92 static scoped_refptr<MediaDrmBridge> CreateWithoutSessionSupport( |
| 90 const std::string& key_system); | 93 const std::string& key_system, |
| 94 scoped_ptr<ProvisionFetcher> provision_fetcher); |
| 91 | 95 |
| 92 // MediaKeys implementation. | 96 // MediaKeys implementation. |
| 93 void SetServerCertificate( | 97 void SetServerCertificate( |
| 94 const std::vector<uint8_t>& certificate, | 98 const std::vector<uint8_t>& certificate, |
| 95 scoped_ptr<media::SimpleCdmPromise> promise) override; | 99 scoped_ptr<media::SimpleCdmPromise> promise) override; |
| 96 void CreateSessionAndGenerateRequest( | 100 void CreateSessionAndGenerateRequest( |
| 97 SessionType session_type, | 101 SessionType session_type, |
| 98 media::EmeInitDataType init_data_type, | 102 media::EmeInitDataType init_data_type, |
| 99 const std::vector<uint8_t>& init_data, | 103 const std::vector<uint8_t>& init_data, |
| 100 scoped_ptr<media::NewSessionCdmPromise> promise) override; | 104 scoped_ptr<media::NewSessionCdmPromise> promise) override; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // should make sure that the callbacks are posted to the correct thread. | 156 // should make sure that the callbacks are posted to the correct thread. |
| 153 // TODO(xhwang): Move this up to be close to RegisterPlayer(). | 157 // TODO(xhwang): Move this up to be close to RegisterPlayer(). |
| 154 void SetMediaCryptoReadyCB(const MediaCryptoReadyCB& media_crypto_ready_cb); | 158 void SetMediaCryptoReadyCB(const MediaCryptoReadyCB& media_crypto_ready_cb); |
| 155 | 159 |
| 156 // All the OnXxx functions below are called from Java. The implementation must | 160 // All the OnXxx functions below are called from Java. The implementation must |
| 157 // only do minimal work and then post tasks to avoid reentrancy issues. | 161 // only do minimal work and then post tasks to avoid reentrancy issues. |
| 158 | 162 |
| 159 // Called by Java after a MediaCrypto object is created. | 163 // Called by Java after a MediaCrypto object is created. |
| 160 void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm); | 164 void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm); |
| 161 | 165 |
| 166 // Called by Java when we need to send a provisioning request, |
| 167 void OnStartProvisioning(JNIEnv* env, |
| 168 jobject j_media_drm, |
| 169 jstring j_default_url, |
| 170 jbyteArray j_request_data); |
| 171 |
| 162 // Callbacks to resolve the promise for |promise_id|. | 172 // Callbacks to resolve the promise for |promise_id|. |
| 163 void OnPromiseResolved(JNIEnv* env, jobject j_media_drm, jint j_promise_id); | 173 void OnPromiseResolved(JNIEnv* env, jobject j_media_drm, jint j_promise_id); |
| 164 void OnPromiseResolvedWithSession(JNIEnv* env, | 174 void OnPromiseResolvedWithSession(JNIEnv* env, |
| 165 jobject j_media_drm, | 175 jobject j_media_drm, |
| 166 jint j_promise_id, | 176 jint j_promise_id, |
| 167 jbyteArray j_session_id); | 177 jbyteArray j_session_id); |
| 168 | 178 |
| 169 // Callback to reject the promise for |promise_id| with |error_message|. | 179 // Callback to reject the promise for |promise_id| with |error_message|. |
| 170 // Note: No |system_error| is available from MediaDrm. | 180 // Note: No |system_error| is available from MediaDrm. |
| 171 // TODO(xhwang): Implement Exception code. | 181 // TODO(xhwang): Implement Exception code. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 jstring j_error_message); | 224 jstring j_error_message); |
| 215 | 225 |
| 216 // Called by the java object when credential reset is completed. | 226 // Called by the java object when credential reset is completed. |
| 217 void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success); | 227 void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success); |
| 218 | 228 |
| 219 private: | 229 private: |
| 220 // For DeleteSoon() in DeleteOnCorrectThread(). | 230 // For DeleteSoon() in DeleteOnCorrectThread(). |
| 221 friend class base::DeleteHelper<MediaDrmBridge>; | 231 friend class base::DeleteHelper<MediaDrmBridge>; |
| 222 | 232 |
| 223 MediaDrmBridge(const std::vector<uint8>& scheme_uuid, | 233 MediaDrmBridge(const std::vector<uint8>& scheme_uuid, |
| 234 scoped_ptr<ProvisionFetcher> provision_fetcher, |
| 224 const SessionMessageCB& session_message_cb, | 235 const SessionMessageCB& session_message_cb, |
| 225 const SessionClosedCB& session_closed_cb, | 236 const SessionClosedCB& session_closed_cb, |
| 226 const LegacySessionErrorCB& legacy_session_error_cb, | 237 const LegacySessionErrorCB& legacy_session_error_cb, |
| 227 const SessionKeysChangeCB& session_keys_change_cb, | 238 const SessionKeysChangeCB& session_keys_change_cb, |
| 228 const SessionExpirationUpdateCB& session_expiration_update_cb); | 239 const SessionExpirationUpdateCB& session_expiration_update_cb); |
| 229 | 240 |
| 230 ~MediaDrmBridge() override; | 241 ~MediaDrmBridge() override; |
| 231 | 242 |
| 232 static bool IsSecureDecoderRequired(SecurityLevel security_level); | 243 static bool IsSecureDecoderRequired(SecurityLevel security_level); |
| 233 | 244 |
| 234 // Get the security level of the media. | 245 // Get the security level of the media. |
| 235 SecurityLevel GetSecurityLevel(); | 246 SecurityLevel GetSecurityLevel(); |
| 236 | 247 |
| 237 // A helper method that calculates the |media_crypto_ready_cb_| arguments and | 248 // A helper method that calculates the |media_crypto_ready_cb_| arguments and |
| 238 // run this callback. | 249 // run this callback. |
| 239 void NotifyMediaCryptoReady(const MediaCryptoReadyCB& cb); | 250 void NotifyMediaCryptoReady(const MediaCryptoReadyCB& cb); |
| 240 | 251 |
| 252 // Sends HTTP provisioning request to a provisioning server. |
| 253 void SendProvisioningRequest(const std::string& default_url, |
| 254 const std::string& request_data); |
| 255 |
| 256 // Process the data received by provisioning server. |
| 257 void ProcessProvisionResponse(bool success, const std::string& response); |
| 258 |
| 241 // UUID of the key system. | 259 // UUID of the key system. |
| 242 std::vector<uint8> scheme_uuid_; | 260 std::vector<uint8> scheme_uuid_; |
| 243 | 261 |
| 244 // Java MediaDrm instance. | 262 // Java MediaDrm instance. |
| 245 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; | 263 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; |
| 246 | 264 |
| 265 // The object that requests and receives provisioning data. |
| 266 scoped_ptr<ProvisionFetcher> provision_fetcher_; |
| 267 |
| 247 // Callbacks for firing session events. | 268 // Callbacks for firing session events. |
| 248 SessionMessageCB session_message_cb_; | 269 SessionMessageCB session_message_cb_; |
| 249 SessionClosedCB session_closed_cb_; | 270 SessionClosedCB session_closed_cb_; |
| 250 LegacySessionErrorCB legacy_session_error_cb_; | 271 LegacySessionErrorCB legacy_session_error_cb_; |
| 251 SessionKeysChangeCB session_keys_change_cb_; | 272 SessionKeysChangeCB session_keys_change_cb_; |
| 252 SessionExpirationUpdateCB session_expiration_update_cb_; | 273 SessionExpirationUpdateCB session_expiration_update_cb_; |
| 253 | 274 |
| 254 MediaCryptoReadyCB media_crypto_ready_cb_; | 275 MediaCryptoReadyCB media_crypto_ready_cb_; |
| 255 | 276 |
| 256 ResetCredentialsCB reset_credentials_cb_; | 277 ResetCredentialsCB reset_credentials_cb_; |
| 257 | 278 |
| 258 PlayerTrackerImpl player_tracker_; | 279 PlayerTrackerImpl player_tracker_; |
| 259 | 280 |
| 260 // TODO(xhwang): Host a CdmPromiseAdapter directly. No need to use scoped_ptr. | 281 // TODO(xhwang): Host a CdmPromiseAdapter directly. No need to use scoped_ptr. |
| 261 scoped_ptr<CdmPromiseAdapter> cdm_promise_adapter_; | 282 scoped_ptr<CdmPromiseAdapter> cdm_promise_adapter_; |
| 262 | 283 |
| 263 // Default task runner. | 284 // Default task runner. |
| 264 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 285 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 265 | 286 |
| 266 // NOTE: Weak pointers must be invalidated before all other member variables. | 287 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 267 base::WeakPtrFactory<MediaDrmBridge> weak_factory_; | 288 base::WeakPtrFactory<MediaDrmBridge> weak_factory_; |
| 268 | 289 |
| 269 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); | 290 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); |
| 270 }; | 291 }; |
| 271 | 292 |
| 272 } // namespace media | 293 } // namespace media |
| 273 | 294 |
| 274 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ | 295 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ |
| OLD | NEW |