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

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

Issue 23517002: MediaSourcePlayer implements IsTypeSupported(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 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 | Annotate | Revision Log
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 #include "media/base/android/media_drm_bridge.h" 5 #include "media/base/android/media_drm_bridge.h"
6 6
7 #include "base/android/build_info.h" 7 #include "base/android/build_info.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 if (box_end < cur + data_size) 134 if (box_end < cur + data_size)
135 return false; 135 return false;
136 136
137 pssh_data->assign(cur, cur + data_size); 137 pssh_data->assign(cur, cur + data_size);
138 return true; 138 return true;
139 } 139 }
140 140
141 return false; 141 return false;
142 } 142 }
143 143
144 static MediaDrmBridge::SecurityLevel GetSecurityLevelFromString(
145 const std::string& security_level_str) {
146 if (0 == security_level_str.compare("L1"))
147 return MediaDrmBridge::SECURITY_LEVEL_1;
148 if (0 == security_level_str.compare("L3"))
149 return MediaDrmBridge::SECURITY_LEVEL_3;
150 DCHECK(security_level_str.empty());
151 return MediaDrmBridge::SECURITY_LEVEL_NONE;
152 }
153
144 // static 154 // static
145 MediaDrmBridge* MediaDrmBridge::Create(int media_keys_id, 155 MediaDrmBridge* MediaDrmBridge::Create(int media_keys_id,
146 const std::vector<uint8>& scheme_uuid, 156 const std::vector<uint8>& scheme_uuid,
147 MediaPlayerManager* manager) { 157 MediaPlayerManager* manager) {
148 if (!IsAvailable() || scheme_uuid.empty()) 158 if (!IsAvailable() || scheme_uuid.empty())
149 return NULL; 159 return NULL;
150 160
151 // TODO(qinmin): check whether the uuid is valid. 161 // TODO(qinmin): check whether the uuid is valid.
152 return new MediaDrmBridge(media_keys_id, scheme_uuid, manager); 162 return new MediaDrmBridge(media_keys_id, scheme_uuid, manager);
153 } 163 }
154 164
165 // static
155 bool MediaDrmBridge::IsAvailable() { 166 bool MediaDrmBridge::IsAvailable() {
156 return base::android::BuildInfo::GetInstance()->sdk_int() >= 18; 167 return base::android::BuildInfo::GetInstance()->sdk_int() >= 18;
157 } 168 }
158 169
170 // static
171 bool MediaDrmBridge::IsSecureDecoderRequired(
172 const std::string& security_level_str) {
173 return IsSecureDecoderRequired(
174 GetSecurityLevelFromString(security_level_str));
175 }
176
177 bool MediaDrmBridge::IsCryptoSchemeSupported(
178 const std::vector<uint8>& scheme_uuid,
179 const std::string& container_mime_type) {
180 JNIEnv* env = AttachCurrentThread();
181 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid =
182 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size());
183 ScopedJavaLocalRef<jstring> j_container_mime_type =
184 ConvertUTF8ToJavaString(env, container_mime_type);
185 return Java_MediaDrmBridge_isCryptoSchemeSupported(
186 env, j_scheme_uuid.obj(), j_container_mime_type.obj());
187 }
188
159 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { 189 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) {
160 return RegisterNativesImpl(env); 190 return RegisterNativesImpl(env);
161 } 191 }
162 192
163 MediaDrmBridge::MediaDrmBridge(int media_keys_id, 193 MediaDrmBridge::MediaDrmBridge(int media_keys_id,
164 const std::vector<uint8>& scheme_uuid, 194 const std::vector<uint8>& scheme_uuid,
165 MediaPlayerManager* manager) 195 MediaPlayerManager* manager)
166 : media_keys_id_(media_keys_id), 196 : media_keys_id_(media_keys_id),
167 scheme_uuid_(scheme_uuid), 197 scheme_uuid_(scheme_uuid),
168 manager_(manager) { 198 manager_(manager) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // |j_session_id| can be NULL, in which case we'll return an empty string. 290 // |j_session_id| can be NULL, in which case we'll return an empty string.
261 std::string session_id = ConvertJavaStringToUTF8(env, j_session_id); 291 std::string session_id = ConvertJavaStringToUTF8(env, j_session_id);
262 manager_->OnKeyError(media_keys_id_, session_id, MediaKeys::kUnknownError, 0); 292 manager_->OnKeyError(media_keys_id_, session_id, MediaKeys::kUnknownError, 0);
263 } 293 }
264 294
265 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() { 295 ScopedJavaLocalRef<jobject> MediaDrmBridge::GetMediaCrypto() {
266 JNIEnv* env = AttachCurrentThread(); 296 JNIEnv* env = AttachCurrentThread();
267 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj()); 297 return Java_MediaDrmBridge_getMediaCrypto(env, j_media_drm_.obj());
268 } 298 }
269 299
300 // static
301 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) {
302 return MediaDrmBridge::SECURITY_LEVEL_1 == security_level;
303 }
304
270 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { 305 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() {
271 JNIEnv* env = AttachCurrentThread(); 306 JNIEnv* env = AttachCurrentThread();
272 ScopedJavaLocalRef<jstring> j_security_level = 307 ScopedJavaLocalRef<jstring> j_security_level =
273 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); 308 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj());
274 std::string security_level = 309 std::string security_level_str =
275 ConvertJavaStringToUTF8(env, j_security_level.obj()); 310 ConvertJavaStringToUTF8(env, j_security_level.obj());
276 if (0 == security_level.compare("L1")) 311 return GetSecurityLevelFromString(security_level_str);
277 return SECURITY_LEVEL_1;
278 if (0 == security_level.compare("L3"))
279 return SECURITY_LEVEL_3;
280 DCHECK(security_level.empty());
281 return SECURITY_LEVEL_NONE;
282 } 312 }
283 313
284 bool MediaDrmBridge::IsProtectedSurfaceRequired() { 314 bool MediaDrmBridge::IsProtectedSurfaceRequired() {
285 return MediaDrmBridge::SECURITY_LEVEL_1 == GetSecurityLevel(); 315 return IsSecureDecoderRequired(GetSecurityLevel());
286 } 316 }
287 317
288 } // namespace media 318 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698