| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 // Reset the device credentials. | 139 // Reset the device credentials. |
| 140 void ResetDeviceCredentials(const ResetCredentialsCB& callback); | 140 void ResetDeviceCredentials(const ResetCredentialsCB& callback); |
| 141 | 141 |
| 142 // Helper functions to resolve promises. | 142 // Helper functions to resolve promises. |
| 143 void ResolvePromise(uint32_t promise_id); | 143 void ResolvePromise(uint32_t promise_id); |
| 144 void ResolvePromiseWithSession(uint32_t promise_id, | 144 void ResolvePromiseWithSession(uint32_t promise_id, |
| 145 const std::string& session_id); | 145 const std::string& session_id); |
| 146 void RejectPromise(uint32_t promise_id, const std::string& error_message); | 146 void RejectPromise(uint32_t promise_id, const std::string& error_message); |
| 147 | 147 |
| 148 // Returns a MediaCrypto object if it's already created. Returns a null object | 148 // Returns a MediaCrypto object. Can only be called after |j_media_crypto_| |
| 149 // otherwise. | 149 // is set. |
| 150 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); | 150 // TODO(xhwang): This is only used by MediaSourcePlayer et al. Remove this |
| 151 // method when MediaSourcePlayer is deprecated. |
| 152 jobject GetMediaCrypto(); |
| 151 | 153 |
| 152 // Registers a callback which will be called when MediaCrypto is ready. | 154 // Registers a callback which will be called when MediaCrypto is ready. |
| 153 // Can be called on any thread. Only one callback should be registered. | 155 // Can be called on any thread. Only one callback should be registered. |
| 154 // The registered callbacks will be fired on |task_runner_|. The caller | 156 // The registered callbacks will be fired on |task_runner_|. The caller |
| 155 // should make sure that the callbacks are posted to the correct thread. | 157 // should make sure that the callbacks are posted to the correct thread. |
| 156 // TODO(xhwang): Move this up to be close to RegisterPlayer(). | 158 // TODO(xhwang): Move this up to be close to RegisterPlayer(). |
| 157 void SetMediaCryptoReadyCB(const MediaCryptoReadyCB& media_crypto_ready_cb); | 159 void SetMediaCryptoReadyCB(const MediaCryptoReadyCB& media_crypto_ready_cb); |
| 158 | 160 |
| 159 // All the OnXxx functions below are called from Java. The implementation must | 161 // All the OnXxx functions below are called from Java. The implementation must |
| 160 // only do minimal work and then post tasks to avoid reentrancy issues. | 162 // only do minimal work and then post tasks to avoid reentrancy issues. |
| 161 | 163 |
| 162 // Called by Java after a MediaCrypto object is created. | 164 // Called by Java after a MediaCrypto object is created. |
| 163 void OnMediaCryptoReady( | 165 void OnMediaCryptoReady( |
| 164 JNIEnv* env, | 166 JNIEnv* env, |
| 165 const base::android::JavaParamRef<jobject>& j_media_drm); | 167 const base::android::JavaParamRef<jobject>& j_media_drm, |
| 168 const base::android::JavaParamRef<jobject>& j_media_crypto); |
| 166 | 169 |
| 167 // Called by Java when we need to send a provisioning request, | 170 // Called by Java when we need to send a provisioning request, |
| 168 void OnStartProvisioning( | 171 void OnStartProvisioning( |
| 169 JNIEnv* env, | 172 JNIEnv* env, |
| 170 const base::android::JavaParamRef<jobject>& j_media_drm, | 173 const base::android::JavaParamRef<jobject>& j_media_drm, |
| 171 const base::android::JavaParamRef<jstring>& j_default_url, | 174 const base::android::JavaParamRef<jstring>& j_default_url, |
| 172 const base::android::JavaParamRef<jbyteArray>& j_request_data); | 175 const base::android::JavaParamRef<jbyteArray>& j_request_data); |
| 173 | 176 |
| 174 // Callbacks to resolve the promise for |promise_id|. | 177 // Callbacks to resolve the promise for |promise_id|. |
| 175 void OnPromiseResolved( | 178 void OnPromiseResolved( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 const SessionKeysChangeCB& session_keys_change_cb, | 256 const SessionKeysChangeCB& session_keys_change_cb, |
| 254 const SessionExpirationUpdateCB& session_expiration_update_cb); | 257 const SessionExpirationUpdateCB& session_expiration_update_cb); |
| 255 | 258 |
| 256 ~MediaDrmBridge() override; | 259 ~MediaDrmBridge() override; |
| 257 | 260 |
| 258 static bool IsSecureDecoderRequired(SecurityLevel security_level); | 261 static bool IsSecureDecoderRequired(SecurityLevel security_level); |
| 259 | 262 |
| 260 // Get the security level of the media. | 263 // Get the security level of the media. |
| 261 SecurityLevel GetSecurityLevel(); | 264 SecurityLevel GetSecurityLevel(); |
| 262 | 265 |
| 263 // A helper method that calculates the |media_crypto_ready_cb_| arguments and | 266 // A helper method to create a JavaObjectPtr. |
| 264 // run this callback. | 267 JavaObjectPtr CreateJavaObjectPtr(jobject object); |
| 265 void NotifyMediaCryptoReady(const MediaCryptoReadyCB& cb); | 268 |
| 269 // A helper method that is called when MediaCrypto is ready. |
| 270 void NotifyMediaCryptoReady(JavaObjectPtr j_media_crypto); |
| 266 | 271 |
| 267 // Sends HTTP provisioning request to a provisioning server. | 272 // Sends HTTP provisioning request to a provisioning server. |
| 268 void SendProvisioningRequest(const std::string& default_url, | 273 void SendProvisioningRequest(const std::string& default_url, |
| 269 const std::string& request_data); | 274 const std::string& request_data); |
| 270 | 275 |
| 271 // Process the data received by provisioning server. | 276 // Process the data received by provisioning server. |
| 272 void ProcessProvisionResponse(bool success, const std::string& response); | 277 void ProcessProvisionResponse(bool success, const std::string& response); |
| 273 | 278 |
| 274 // UUID of the key system. | 279 // UUID of the key system. |
| 275 std::vector<uint8> scheme_uuid_; | 280 std::vector<uint8> scheme_uuid_; |
| 276 | 281 |
| 277 // Java MediaDrm instance. | 282 // Java MediaDrm instance. |
| 278 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; | 283 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; |
| 279 | 284 |
| 285 // Java MediaCrypto instance. Possible values are: |
| 286 // !j_media_crypto_: |
| 287 // MediaCrypto creation has not been notified via NotifyMediaCryptoReady(). |
| 288 // !j_media_crypto_->is_null(): |
| 289 // MediaCrypto creation succeeded and it has been notified. |
| 290 // j_media_crypto_->is_null(): |
| 291 // MediaCrypto creation failed and it has been notified. |
| 292 JavaObjectPtr j_media_crypto_; |
| 293 |
| 280 // The callback to create a ProvisionFetcher. | 294 // The callback to create a ProvisionFetcher. |
| 281 CreateFetcherCB create_fetcher_cb_; | 295 CreateFetcherCB create_fetcher_cb_; |
| 282 | 296 |
| 283 // The ProvisionFetcher that requests and receives provisioning data. | 297 // The ProvisionFetcher that requests and receives provisioning data. |
| 284 // Non-null iff when a provision request is pending. | 298 // Non-null iff when a provision request is pending. |
| 285 scoped_ptr<ProvisionFetcher> provision_fetcher_; | 299 scoped_ptr<ProvisionFetcher> provision_fetcher_; |
| 286 | 300 |
| 287 // Callbacks for firing session events. | 301 // Callbacks for firing session events. |
| 288 SessionMessageCB session_message_cb_; | 302 SessionMessageCB session_message_cb_; |
| 289 SessionClosedCB session_closed_cb_; | 303 SessionClosedCB session_closed_cb_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 304 | 318 |
| 305 // NOTE: Weak pointers must be invalidated before all other member variables. | 319 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 306 base::WeakPtrFactory<MediaDrmBridge> weak_factory_; | 320 base::WeakPtrFactory<MediaDrmBridge> weak_factory_; |
| 307 | 321 |
| 308 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); | 322 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); |
| 309 }; | 323 }; |
| 310 | 324 |
| 311 } // namespace media | 325 } // namespace media |
| 312 | 326 |
| 313 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ | 327 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ |
| OLD | NEW |