Chromium Code Reviews| 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 "media/base/browser_cdm.h" | 15 #include "media/base/browser_cdm.h" |
| 16 #include "media/base/cdm_promise_adapter.h" | 16 #include "media/base/cdm_promise_adapter.h" |
| 17 #include "media/base/media_export.h" | 17 #include "media/base/media_export.h" |
| 18 #include "media/cdm/player_tracker_impl.h" | 18 #include "media/cdm/player_tracker_impl.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 class GURL; | 21 class GURL; |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 class MediaPlayerManager; | 25 class MediaPlayerManager; |
| 26 | 26 |
| 27 // This class provides DRM services for android EME implementation. | 27 // This class provides DRM services for android EME implementation. |
| 28 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm { | 28 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm { |
| 29 public: | 29 public: |
| 30 // Allows embedders to modify the Android DRM flow. Delegates are registered | |
| 31 // to a specific key system. | |
| 32 class Delegate { | |
| 33 public: | |
| 34 Delegate(); | |
| 35 virtual ~Delegate(); | |
| 36 | |
| 37 // Invoked from CreateSession. | |
| 38 // If |init_data_out| is filled, it replaces |init_data| to send to the | |
| 39 // DRM plugin. | |
| 40 // If |optional_parameters_out| is filled, it is expected to be an | |
| 41 // even-length list of (key, value) pairs to send to the DRM plugin. | |
| 42 // Returns false if the request should be rejected. | |
| 43 virtual bool OnCreateSession( | |
| 44 const EmeInitDataType init_data_type, | |
| 45 const uint8* init_data, | |
| 46 int init_data_length, | |
| 47 std::vector<uint8>& init_data_out, | |
| 48 std::vector<std::string>& optional_parameters_out); | |
| 49 | |
| 50 private: | |
| 51 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
| 52 }; | |
| 53 | |
| 30 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400 | 54 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400 |
| 31 enum SecurityLevel { | 55 enum SecurityLevel { |
| 32 SECURITY_LEVEL_NONE = 0, | 56 SECURITY_LEVEL_NONE = 0, |
| 33 SECURITY_LEVEL_1 = 1, | 57 SECURITY_LEVEL_1 = 1, |
| 34 SECURITY_LEVEL_3 = 3, | 58 SECURITY_LEVEL_3 = 3, |
| 35 }; | 59 }; |
| 36 | 60 |
| 37 typedef base::Callback<void(bool)> ResetCredentialsCB; | 61 typedef base::Callback<void(bool)> ResetCredentialsCB; |
| 38 | 62 |
| 39 ~MediaDrmBridge() override; | 63 ~MediaDrmBridge() override; |
| 40 | 64 |
| 41 // Checks whether MediaDRM is available. | 65 // Checks whether MediaDRM is available. |
| 42 // All other static methods check IsAvailable() internally. There's no need | 66 // All other static methods check IsAvailable() internally. There's no need |
| 43 // to check IsAvailable() explicitly before calling them. | 67 // to check IsAvailable() explicitly before calling them. |
| 44 static bool IsAvailable(); | 68 static bool IsAvailable(); |
| 45 | 69 |
| 46 // Checks whether |key_system| is supported. | 70 // Checks whether |key_system| is supported. |
| 47 static bool IsKeySystemSupported(const std::string& key_system); | 71 static bool IsKeySystemSupported(const std::string& key_system); |
| 48 | 72 |
| 49 // Returns the list of the platform-supported key system names that | 73 // Returns the list of the platform-supported key system names that |
| 50 // are not handled by Chrome explicitly. | 74 // are not handled by Chrome explicitly. |
| 51 static std::vector<std::string> GetPlatformKeySystemNames(); | 75 static std::vector<std::string> GetPlatformKeySystemNames(); |
| 52 | 76 |
| 53 // Checks whether |key_system| is supported with |container_mime_type|. | 77 // Checks whether |key_system| is supported with |container_mime_type|. |
| 54 // |container_mime_type| must not be empty. | 78 // |container_mime_type| must not be empty. |
| 55 static bool IsKeySystemSupportedWithType( | 79 static bool IsKeySystemSupportedWithType( |
| 56 const std::string& key_system, | 80 const std::string& key_system, |
| 57 const std::string& container_mime_type); | 81 const std::string& container_mime_type); |
| 58 | 82 |
| 83 // Registers a delegate to handle requests with a given UUID. | |
| 84 static void RegisterDelegate( | |
| 85 const std::string& key_system, | |
| 86 Delegate* delegate); | |
| 87 | |
| 59 static bool RegisterMediaDrmBridge(JNIEnv* env); | 88 static bool RegisterMediaDrmBridge(JNIEnv* env); |
| 60 | 89 |
| 61 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL | 90 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL |
| 62 // pointer otherwise. | 91 // pointer otherwise. |
| 63 // TODO(xhwang): Is it okay not to update session expiration info? | 92 // TODO(xhwang): Is it okay not to update session expiration info? |
| 64 static scoped_ptr<MediaDrmBridge> Create( | 93 static scoped_ptr<MediaDrmBridge> Create( |
| 65 const std::string& key_system, | 94 const std::string& key_system, |
| 66 const SessionMessageCB& session_message_cb, | 95 const SessionMessageCB& session_message_cb, |
| 67 const SessionClosedCB& session_closed_cb, | 96 const SessionClosedCB& session_closed_cb, |
| 68 const LegacySessionErrorCB& legacy_session_error_cb, | 97 const LegacySessionErrorCB& legacy_session_error_cb, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 207 |
| 179 // Helper function to determine whether a protected surface is needed for the | 208 // Helper function to determine whether a protected surface is needed for the |
| 180 // video playback. | 209 // video playback. |
| 181 bool IsProtectedSurfaceRequired(); | 210 bool IsProtectedSurfaceRequired(); |
| 182 | 211 |
| 183 private: | 212 private: |
| 184 MediaDrmBridge(const std::vector<uint8>& scheme_uuid, | 213 MediaDrmBridge(const std::vector<uint8>& scheme_uuid, |
| 185 const SessionMessageCB& session_message_cb, | 214 const SessionMessageCB& session_message_cb, |
| 186 const SessionClosedCB& session_closed_cb, | 215 const SessionClosedCB& session_closed_cb, |
| 187 const LegacySessionErrorCB& legacy_session_error_cb, | 216 const LegacySessionErrorCB& legacy_session_error_cb, |
| 188 const SessionKeysChangeCB& session_keys_change_cb); | 217 const SessionKeysChangeCB& session_keys_change_cb, |
| 218 Delegate* delegate); | |
| 189 | 219 |
| 190 static bool IsSecureDecoderRequired(SecurityLevel security_level); | 220 static bool IsSecureDecoderRequired(SecurityLevel security_level); |
| 191 | 221 |
| 192 // Get the security level of the media. | 222 // Get the security level of the media. |
| 193 SecurityLevel GetSecurityLevel(); | 223 SecurityLevel GetSecurityLevel(); |
| 194 | 224 |
| 195 // UUID of the key system. | 225 // UUID of the key system. |
| 196 std::vector<uint8> scheme_uuid_; | 226 std::vector<uint8> scheme_uuid_; |
| 197 | 227 |
| 198 // Java MediaDrm instance. | 228 // Java MediaDrm instance. |
| 199 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; | 229 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; |
| 200 | 230 |
| 231 Delegate* const delegate_; | |
|
xhwang
2015/04/09 22:37:10
nit: document about lifetime.
gunsch
2015/04/10 00:21:11
Done.
| |
| 232 | |
| 201 // Callbacks for firing session events. | 233 // Callbacks for firing session events. |
| 202 SessionMessageCB session_message_cb_; | 234 SessionMessageCB session_message_cb_; |
| 203 SessionClosedCB session_closed_cb_; | 235 SessionClosedCB session_closed_cb_; |
| 204 LegacySessionErrorCB legacy_session_error_cb_; | 236 LegacySessionErrorCB legacy_session_error_cb_; |
| 205 SessionKeysChangeCB session_keys_change_cb_; | 237 SessionKeysChangeCB session_keys_change_cb_; |
| 206 | 238 |
| 207 base::Closure media_crypto_ready_cb_; | 239 base::Closure media_crypto_ready_cb_; |
| 208 | 240 |
| 209 ResetCredentialsCB reset_credentials_cb_; | 241 ResetCredentialsCB reset_credentials_cb_; |
| 210 | 242 |
| 211 PlayerTrackerImpl player_tracker_; | 243 PlayerTrackerImpl player_tracker_; |
| 212 | 244 |
| 213 CdmPromiseAdapter cdm_promise_adapter_; | 245 CdmPromiseAdapter cdm_promise_adapter_; |
| 214 | 246 |
| 215 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); | 247 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); |
| 216 }; | 248 }; |
| 217 | 249 |
| 218 } // namespace media | 250 } // namespace media |
| 219 | 251 |
| 220 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ | 252 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ |
| OLD | NEW |