Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: media/base/android/media_drm_bridge.h

Issue 1341883003: Prepare MediaDrmBridge to work with MediaCodecPlayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bug526755
Patch Set: Fixed MediaDrmBridgeTest unit tests Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
15 #include "media/base/browser_cdm.h" 16 #include "media/base/browser_cdm.h"
16 #include "media/base/cdm_promise_adapter.h" 17 #include "media/base/cdm_promise_adapter.h"
17 #include "media/base/media_export.h" 18 #include "media/base/media_export.h"
18 #include "media/cdm/player_tracker_impl.h" 19 #include "media/cdm/player_tracker_impl.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 class GURL; 22 class GURL;
22 23
23 namespace media { 24 namespace media {
24 25
26 class MediaDrmBridge;
25 class MediaPlayerManager; 27 class MediaPlayerManager;
26 28
29 using ScopedMediaDrmBridgePtr = scoped_ptr<MediaDrmBridge, BrowserCdmDeleter>;
30
27 // This class provides DRM services for android EME implementation. 31 // This class provides DRM services for android EME implementation.
28 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm { 32 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm {
29 public: 33 public:
30 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400 34 // TODO(ddorwin): These are specific to Widevine. http://crbug.com/459400
31 enum SecurityLevel { 35 enum SecurityLevel {
32 SECURITY_LEVEL_NONE = 0, 36 SECURITY_LEVEL_NONE = 0,
33 SECURITY_LEVEL_1 = 1, 37 SECURITY_LEVEL_1 = 1,
34 SECURITY_LEVEL_3 = 3, 38 SECURITY_LEVEL_3 = 3,
35 }; 39 };
36 40
37 typedef base::Callback<void(bool)> ResetCredentialsCB; 41 using JavaObjectPtr = scoped_ptr<base::android::ScopedJavaGlobalRef<jobject>>;
42
43 using ResetCredentialsCB = base::Callback<void(bool)>;
44
45 // Notification called when MediaCrypto object is ready.
46 // Parameters:
47 // |media_crypto| - global reference to MediaCrypto object
48 // |needs_protected_surface| - true if protected surface is required.
49 using MediaCryptoReadyCB = base::Callback<void(JavaObjectPtr media_crypto,
50 bool needs_protected_surface)>;
38 51
39 ~MediaDrmBridge() override; 52 ~MediaDrmBridge() override;
40 53
54 void DeleteOnCorrectThread() override;
55
41 // Checks whether MediaDRM is available. 56 // Checks whether MediaDRM is available.
42 // All other static methods check IsAvailable() internally. There's no need 57 // All other static methods check IsAvailable() internally. There's no need
43 // to check IsAvailable() explicitly before calling them. 58 // to check IsAvailable() explicitly before calling them.
44 static bool IsAvailable(); 59 static bool IsAvailable();
45 60
46 // Checks whether |key_system| is supported. 61 // Checks whether |key_system| is supported.
47 static bool IsKeySystemSupported(const std::string& key_system); 62 static bool IsKeySystemSupported(const std::string& key_system);
48 63
49 // Returns the list of the platform-supported key system names that 64 // Returns the list of the platform-supported key system names that
50 // are not handled by Chrome explicitly. 65 // are not handled by Chrome explicitly.
51 static std::vector<std::string> GetPlatformKeySystemNames(); 66 static std::vector<std::string> GetPlatformKeySystemNames();
52 67
53 // Checks whether |key_system| is supported with |container_mime_type|. 68 // Checks whether |key_system| is supported with |container_mime_type|.
54 // |container_mime_type| must not be empty. 69 // |container_mime_type| must not be empty.
55 static bool IsKeySystemSupportedWithType( 70 static bool IsKeySystemSupportedWithType(
56 const std::string& key_system, 71 const std::string& key_system,
57 const std::string& container_mime_type); 72 const std::string& container_mime_type);
58 73
59 static bool RegisterMediaDrmBridge(JNIEnv* env); 74 static bool RegisterMediaDrmBridge(JNIEnv* env);
60 75
61 // 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
62 // pointer otherwise. 77 // pointer otherwise.
63 // TODO(xhwang): Is it okay not to update session expiration info? 78 // TODO(xhwang): Is it okay not to update session expiration info?
64 static scoped_ptr<MediaDrmBridge> Create( 79 static ScopedMediaDrmBridgePtr Create(
65 const std::string& key_system, 80 const std::string& key_system,
66 const SessionMessageCB& session_message_cb, 81 const SessionMessageCB& session_message_cb,
67 const SessionClosedCB& session_closed_cb, 82 const SessionClosedCB& session_closed_cb,
68 const LegacySessionErrorCB& legacy_session_error_cb, 83 const LegacySessionErrorCB& legacy_session_error_cb,
69 const SessionKeysChangeCB& session_keys_change_cb, 84 const SessionKeysChangeCB& session_keys_change_cb,
70 const SessionExpirationUpdateCB& session_expiration_update_cb); 85 const SessionExpirationUpdateCB& session_expiration_update_cb);
71 86
72 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL 87 // 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 88 // otherwise. No session callbacks are provided. This is used when we need to
74 // use MediaDrmBridge without creating any sessions. 89 // use MediaDrmBridge without creating any sessions.
75 static scoped_ptr<MediaDrmBridge> CreateWithoutSessionSupport( 90 static ScopedMediaDrmBridgePtr CreateWithoutSessionSupport(
76 const std::string& key_system); 91 const std::string& key_system);
77 92
78 // Returns true if |security_level| is successfully set, or false otherwise. 93 // Returns true if |security_level| is successfully set, or false otherwise.
79 // Call this function right after Create() and before any other calls. 94 // Call this function right after Create() and before any other calls.
80 // Note: 95 // Note:
81 // - If this function is not called, the default security level of the device 96 // - If this function is not called, the default security level of the device
82 // will be used. 97 // will be used.
83 // - It's recommended to call this function only once on a MediaDrmBridge 98 // - It's recommended to call this function only once on a MediaDrmBridge
84 // object. Calling this function multiples times may cause errors. 99 // object. Calling this function multiples times may cause errors.
85 bool SetSecurityLevel(SecurityLevel security_level); 100 bool SetSecurityLevel(SecurityLevel security_level);
(...skipping 21 matching lines...) Expand all
107 122
108 // PlayerTracker (via BrowserCdm) implementation. 123 // PlayerTracker (via BrowserCdm) implementation.
109 int RegisterPlayer(const base::Closure& new_key_cb, 124 int RegisterPlayer(const base::Closure& new_key_cb,
110 const base::Closure& cdm_unset_cb) override; 125 const base::Closure& cdm_unset_cb) override;
111 void UnregisterPlayer(int registration_id) override; 126 void UnregisterPlayer(int registration_id) override;
112 127
113 // Returns a MediaCrypto object if it's already created. Returns a null object 128 // Returns a MediaCrypto object if it's already created. Returns a null object
114 // otherwise. 129 // otherwise.
115 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); 130 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
116 131
117 // Sets callback which will be called when MediaCrypto is ready. 132 // Sets callback which will be called when MediaCrypto is ready. If
118 // If |closure| is null, previously set callback will be cleared. 133 // |media_crypto_ready_cb| is null, previously set callback will be cleared.
119 void SetMediaCryptoReadyCB(const base::Closure& closure); 134 void SetMediaCryptoReadyCB(const MediaCryptoReadyCB& media_crypto_ready_cb);
120 135
121 // Called after a MediaCrypto object is created. 136 // Called by Java after a MediaCrypto object is created.
122 void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm); 137 void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm);
123 138
124 // Callbacks to resolve the promise for |promise_id|. 139 // Callbacks to resolve the promise for |promise_id|.
125 void OnPromiseResolved(JNIEnv* env, jobject j_media_drm, jint j_promise_id); 140 void OnPromiseResolved(JNIEnv* env, jobject j_media_drm, jint j_promise_id);
126 void OnPromiseResolvedWithSession(JNIEnv* env, 141 void OnPromiseResolvedWithSession(JNIEnv* env,
127 jobject j_media_drm, 142 jobject j_media_drm,
128 jint j_promise_id, 143 jint j_promise_id,
129 jbyteArray j_session_id); 144 jbyteArray j_session_id);
130 145
131 // Callback to reject the promise for |promise_id| with |error_message|. 146 // Callback to reject the promise for |promise_id| with |error_message|.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // Reset the device credentials. 194 // Reset the device credentials.
180 void ResetDeviceCredentials(const ResetCredentialsCB& callback); 195 void ResetDeviceCredentials(const ResetCredentialsCB& callback);
181 196
182 // Called by the java object when credential reset is completed. 197 // Called by the java object when credential reset is completed.
183 void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success); 198 void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success);
184 199
185 // Helper function to determine whether a protected surface is needed for the 200 // Helper function to determine whether a protected surface is needed for the
186 // video playback. 201 // video playback.
187 bool IsProtectedSurfaceRequired(); 202 bool IsProtectedSurfaceRequired();
188 203
204 // We use this pointer when we post SetMediaCryptoReadyCB onto UI thread.
205 base::WeakPtr<MediaDrmBridge> WeakPtrForUIThread();
206
189 private: 207 private:
190 MediaDrmBridge(const std::vector<uint8>& scheme_uuid, 208 MediaDrmBridge(const std::vector<uint8>& scheme_uuid,
191 const SessionMessageCB& session_message_cb, 209 const SessionMessageCB& session_message_cb,
192 const SessionClosedCB& session_closed_cb, 210 const SessionClosedCB& session_closed_cb,
193 const LegacySessionErrorCB& legacy_session_error_cb, 211 const LegacySessionErrorCB& legacy_session_error_cb,
194 const SessionKeysChangeCB& session_keys_change_cb, 212 const SessionKeysChangeCB& session_keys_change_cb,
195 const SessionExpirationUpdateCB& session_expiration_update_cb); 213 const SessionExpirationUpdateCB& session_expiration_update_cb);
196 214
197 static bool IsSecureDecoderRequired(SecurityLevel security_level); 215 static bool IsSecureDecoderRequired(SecurityLevel security_level);
198 216
199 // Get the security level of the media. 217 // Get the security level of the media.
200 SecurityLevel GetSecurityLevel(); 218 SecurityLevel GetSecurityLevel();
201 219
220 // A helper method that calls a |player_tracker_| method on correct thread.
221 void NotifyNewKeyOnCorrectThread();
222
223 // A helper method that calculates the |media_crypto_ready_cb_| arguments and
224 // run this callback.
225 void NotifyMediaCryptoReady(const MediaCryptoReadyCB& cb);
226
202 // UUID of the key system. 227 // UUID of the key system.
203 std::vector<uint8> scheme_uuid_; 228 std::vector<uint8> scheme_uuid_;
204 229
205 // Java MediaDrm instance. 230 // Java MediaDrm instance.
206 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; 231 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_;
207 232
208 // Callbacks for firing session events. 233 // Callbacks for firing session events.
209 SessionMessageCB session_message_cb_; 234 SessionMessageCB session_message_cb_;
210 SessionClosedCB session_closed_cb_; 235 SessionClosedCB session_closed_cb_;
211 LegacySessionErrorCB legacy_session_error_cb_; 236 LegacySessionErrorCB legacy_session_error_cb_;
212 SessionKeysChangeCB session_keys_change_cb_; 237 SessionKeysChangeCB session_keys_change_cb_;
213 SessionExpirationUpdateCB session_expiration_update_cb_; 238 SessionExpirationUpdateCB session_expiration_update_cb_;
214 239
215 base::Closure media_crypto_ready_cb_; 240 MediaCryptoReadyCB media_crypto_ready_cb_;
216 241
217 ResetCredentialsCB reset_credentials_cb_; 242 ResetCredentialsCB reset_credentials_cb_;
218 243
244 // The |player_tracker_| must be accessed by one thread only. It is accessed
245 // by the Media thread when |use_media_thread_| is true.
219 PlayerTrackerImpl player_tracker_; 246 PlayerTrackerImpl player_tracker_;
220 247
221 CdmPromiseAdapter cdm_promise_adapter_; 248 CdmPromiseAdapter cdm_promise_adapter_;
222 249
250 // Object for posting tasks on UI thread.
251 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
252
253 // This flag is set when we use media thread for certain callbacks.
254 const bool use_media_thread_;
255
256 // NOTE: Weak pointers must be invalidated before all other member variables.
257 base::WeakPtrFactory<MediaDrmBridge> media_weak_factory_;
258 base::WeakPtrFactory<MediaDrmBridge> ui_weak_factory_;
259
223 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); 260 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge);
224 }; 261 };
225 262
226 } // namespace media 263 } // namespace media
227 264
228 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ 265 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
OLDNEW
« no previous file with comments | « media/base/android/media_codec_player_unittest.cc ('k') | media/base/android/media_drm_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698