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

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

Issue 850183002: media: Support unprefixed EME API on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase only Created 5 years, 11 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 "media/base/browser_cdm.h" 15 #include "media/base/browser_cdm.h"
16 #include "media/base/cdm_promise_adapter.h"
16 #include "media/base/media_export.h" 17 #include "media/base/media_export.h"
17 #include "media/cdm/player_tracker_impl.h" 18 #include "media/cdm/player_tracker_impl.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
20 class GURL; 21 class GURL;
21 22
22 namespace media { 23 namespace media {
23 24
24 class MediaPlayerManager; 25 class MediaPlayerManager;
25 26
26 // This class provides DRM services for android EME implementation. 27 // This class provides DRM services for android EME implementation.
27 // TODO(qinmin): implement all the functions in this class.
28 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm { 28 class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm {
29 public: 29 public:
30 enum SecurityLevel { 30 enum SecurityLevel {
31 SECURITY_LEVEL_NONE = 0, 31 SECURITY_LEVEL_NONE = 0,
32 SECURITY_LEVEL_1 = 1, 32 SECURITY_LEVEL_1 = 1,
33 SECURITY_LEVEL_3 = 3, 33 SECURITY_LEVEL_3 = 3,
34 }; 34 };
35 35
36 typedef base::Callback<void(bool)> ResetCredentialsCB; 36 typedef base::Callback<void(bool)> ResetCredentialsCB;
37 37
(...skipping 19 matching lines...) Expand all
57 static bool IsKeySystemSupportedWithType( 57 static bool IsKeySystemSupportedWithType(
58 const std::string& key_system, 58 const std::string& key_system,
59 const std::string& container_mime_type); 59 const std::string& container_mime_type);
60 60
61 static bool IsSecureDecoderRequired(SecurityLevel security_level); 61 static bool IsSecureDecoderRequired(SecurityLevel security_level);
62 62
63 static bool RegisterMediaDrmBridge(JNIEnv* env); 63 static bool RegisterMediaDrmBridge(JNIEnv* env);
64 64
65 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL 65 // Returns a MediaDrmBridge instance if |key_system| is supported, or a NULL
66 // pointer otherwise. 66 // pointer otherwise.
67 // TODO(xhwang): Is it okay not to update session expiration info?
67 static scoped_ptr<MediaDrmBridge> Create( 68 static scoped_ptr<MediaDrmBridge> Create(
68 const std::string& key_system, 69 const std::string& key_system,
69 const SessionCreatedCB& session_created_cb,
70 const SessionMessageCB& session_message_cb, 70 const SessionMessageCB& session_message_cb,
71 const SessionReadyCB& session_ready_cb,
72 const SessionClosedCB& session_closed_cb, 71 const SessionClosedCB& session_closed_cb,
73 const SessionErrorCB& session_error_cb); 72 const SessionErrorCB& session_error_cb,
73 const SessionKeysChangeCB& session_keys_change_cb,
74 const SessionExpirationUpdateCB& session_expiration_update_cb);
74 75
75 // 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
76 // otherwise. No session callbacks are provided. This is used when we need to 77 // otherwise. No session callbacks are provided. This is used when we need to
77 // use MediaDrmBridge without creating any sessions. 78 // use MediaDrmBridge without creating any sessions.
78 static scoped_ptr<MediaDrmBridge> CreateSessionless( 79 static scoped_ptr<MediaDrmBridge> CreateWithoutSessionSupport(
79 const std::string& key_system); 80 const std::string& key_system);
80 81
81 // Returns true if |security_level| is successfully set, or false otherwise. 82 // Returns true if |security_level| is successfully set, or false otherwise.
82 // Call this function right after Create() and before any other calls. 83 // Call this function right after Create() and before any other calls.
83 // Note: 84 // Note:
84 // - If this function is not called, the default security level of the device 85 // - If this function is not called, the default security level of the device
85 // will be used. 86 // will be used.
86 // - It's recommended to call this function only once on a MediaDrmBridge 87 // - It's recommended to call this function only once on a MediaDrmBridge
87 // object. Calling this function multiples times may cause errors. 88 // object. Calling this function multiples times may cause errors.
88 bool SetSecurityLevel(SecurityLevel security_level); 89 bool SetSecurityLevel(SecurityLevel security_level);
89 90
90 // BrowserCdm implementations. 91 // MediaKeys (via BrowserCdm) implementation.
91 virtual bool CreateSession(uint32 session_id, 92 void SetServerCertificate(
92 const std::string& content_type, 93 const uint8* certificate_data,
93 const uint8* init_data, 94 int certificate_data_length,
94 int init_data_length) override; 95 scoped_ptr<media::SimpleCdmPromise> promise) override;
95 virtual void LoadSession(uint32 session_id, 96 void CreateSessionAndGenerateRequest(
96 const std::string& web_session_id) override; 97 SessionType session_type,
97 virtual void UpdateSession(uint32 session_id, 98 const std::string& init_data_type,
98 const uint8* response, 99 const uint8* init_data,
99 int response_length) override; 100 int init_data_length,
100 virtual void ReleaseSession(uint32 session_id) override; 101 scoped_ptr<media::NewSessionCdmPromise> promise) override;
101 virtual int RegisterPlayer(const base::Closure& new_key_cb, 102 void LoadSession(SessionType session_type,
102 const base::Closure& cdm_unset_cb) override; 103 const std::string& session_id,
103 virtual void UnregisterPlayer(int registration_id) override; 104 scoped_ptr<media::NewSessionCdmPromise> promise) override;
105 void UpdateSession(const std::string& session_id,
106 const uint8* response,
107 int response_length,
108 scoped_ptr<media::SimpleCdmPromise> promise) override;
109 void CloseSession(const std::string& session_id,
110 scoped_ptr<media::SimpleCdmPromise> promise) override;
111 void RemoveSession(const std::string& session_id,
112 scoped_ptr<media::SimpleCdmPromise> promise) override;
113 CdmContext* GetCdmContext() override;
114
115 // PlayerTracker (via BrowserCdm) implementation.
116 int RegisterPlayer(const base::Closure& new_key_cb,
117 const base::Closure& cdm_unset_cb) override;
118 void UnregisterPlayer(int registration_id) override;
104 119
105 // Returns a MediaCrypto object if it's already created. Returns a null object 120 // Returns a MediaCrypto object if it's already created. Returns a null object
106 // otherwise. 121 // otherwise.
107 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto(); 122 base::android::ScopedJavaLocalRef<jobject> GetMediaCrypto();
108 123
109 // Sets callback which will be called when MediaCrypto is ready. 124 // Sets callback which will be called when MediaCrypto is ready.
110 // If |closure| is null, previously set callback will be cleared. 125 // If |closure| is null, previously set callback will be cleared.
111 void SetMediaCryptoReadyCB(const base::Closure& closure); 126 void SetMediaCryptoReadyCB(const base::Closure& closure);
112 127
113 // Called after a MediaCrypto object is created. 128 // Called after a MediaCrypto object is created.
114 void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm); 129 void OnMediaCryptoReady(JNIEnv* env, jobject j_media_drm);
115 130
116 // Callbacks for firing session events. 131 // Callbacks to resolve the promise for |promise_id|.
117 void OnSessionCreated(JNIEnv* env, 132 void OnPromiseResolved(JNIEnv* env, jobject j_media_drm, jint j_promise_id);
118 jobject j_media_drm, 133 void OnPromiseResolvedWithSession(JNIEnv* env,
119 jint j_session_id, 134 jobject j_media_drm,
120 jstring j_web_session_id); 135 jint j_promise_id,
136 jbyteArray j_session_id);
137
138 // Callback to reject the promise for |promise_id| with |error_message|.
139 // Note: No |system_error| is available from MediaDrm.
140 // TODO(xhwang): Implement Exception code.
141 void OnPromiseRejected(JNIEnv* env,
142 jobject j_media_drm,
143 jint j_promise_id,
144 jstring j_error_message);
145
146 // Session event callbacks.
147 // Note: Session expiration update is not supported by MediaDrm.
148
121 void OnSessionMessage(JNIEnv* env, 149 void OnSessionMessage(JNIEnv* env,
122 jobject j_media_drm, 150 jobject j_media_drm,
123 jint j_session_id, 151 jbyteArray j_session_id,
124 jbyteArray j_message, 152 jbyteArray j_message,
125 jstring j_destination_url); 153 jstring j_legacy_destination_url);
126 void OnSessionReady(JNIEnv* env, jobject j_media_drm, jint j_session_id); 154 void OnSessionClosed(JNIEnv* env,
127 void OnSessionClosed(JNIEnv* env, jobject j_media_drm, jint j_session_id); 155 jobject j_media_drm,
128 void OnSessionError(JNIEnv* env, jobject j_media_drm, jint j_session_id); 156 jbyteArray j_session_id);
157
158 // Note: Key ID is not available in MediaDrm, so only a generic |j_key_status|
159 // and |has_additional_usable_key| are returned.
160 void OnSessionKeysChange(JNIEnv* env,
161 jobject j_media_drm,
162 jbyteArray j_session_id,
163 bool has_additional_usable_key,
164 jint j_key_status);
165
166 // Called by the CDM when an error occurred in session |j_session_id|
167 // unrelated to one of the MediaKeys calls that accept a |promise|.
168 // Note:
169 // - This method is only for supporting prefixed EME API.
170 // - This method will be ignored by unprefixed EME. All errors reported
171 // in this method should probably also be reported by one of other methods.
172 void OnLegacySessionError(JNIEnv* env,
173 jobject j_media_drm,
174 jbyteArray j_session_id,
175 jstring j_error_message);
129 176
130 // Reset the device credentials. 177 // Reset the device credentials.
131 void ResetDeviceCredentials(const ResetCredentialsCB& callback); 178 void ResetDeviceCredentials(const ResetCredentialsCB& callback);
132 179
133 // Called by the java object when credential reset is completed. 180 // Called by the java object when credential reset is completed.
134 void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success); 181 void OnResetDeviceCredentialsCompleted(JNIEnv* env, jobject, bool success);
135 182
136 // Helper function to determine whether a protected surface is needed for the 183 // Helper function to determine whether a protected surface is needed for the
137 // video playback. 184 // video playback.
138 bool IsProtectedSurfaceRequired(); 185 bool IsProtectedSurfaceRequired();
139 186
140 private: 187 private:
141 MediaDrmBridge(const std::vector<uint8>& scheme_uuid, 188 MediaDrmBridge(const std::vector<uint8>& scheme_uuid,
142 const SessionCreatedCB& session_created_cb,
143 const SessionMessageCB& session_message_cb, 189 const SessionMessageCB& session_message_cb,
144 const SessionReadyCB& session_ready_cb,
145 const SessionClosedCB& session_closed_cb, 190 const SessionClosedCB& session_closed_cb,
146 const SessionErrorCB& session_error_cb); 191 const SessionErrorCB& session_error_cb,
192 const SessionKeysChangeCB& session_keys_change_cb);
147 193
148 // Get the security level of the media. 194 // Get the security level of the media.
149 SecurityLevel GetSecurityLevel(); 195 SecurityLevel GetSecurityLevel();
150 196
151 // UUID of the key system. 197 // UUID of the key system.
152 std::vector<uint8> scheme_uuid_; 198 std::vector<uint8> scheme_uuid_;
153 199
154 // Java MediaDrm instance. 200 // Java MediaDrm instance.
155 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_; 201 base::android::ScopedJavaGlobalRef<jobject> j_media_drm_;
156 202
157 // Callbacks for firing session events. 203 // Callbacks for firing session events.
158 SessionCreatedCB session_created_cb_;
159 SessionMessageCB session_message_cb_; 204 SessionMessageCB session_message_cb_;
160 SessionReadyCB session_ready_cb_;
161 SessionClosedCB session_closed_cb_; 205 SessionClosedCB session_closed_cb_;
162 SessionErrorCB session_error_cb_; 206 SessionErrorCB session_error_cb_;
207 SessionKeysChangeCB session_keys_change_cb_;
163 208
164 base::Closure media_crypto_ready_cb_; 209 base::Closure media_crypto_ready_cb_;
165 210
166 ResetCredentialsCB reset_credentials_cb_; 211 ResetCredentialsCB reset_credentials_cb_;
167 212
168 PlayerTrackerImpl player_tracker_; 213 PlayerTrackerImpl player_tracker_;
169 214
215 CdmPromiseAdapter cdm_promise_adapter_;
216
170 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge); 217 DISALLOW_COPY_AND_ASSIGN(MediaDrmBridge);
171 }; 218 };
172 219
173 } // namespace media 220 } // namespace media
174 221
175 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_ 222 #endif // MEDIA_BASE_ANDROID_MEDIA_DRM_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698