| 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 #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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if (box_end < cur + data_size) | 131 if (box_end < cur + data_size) |
| 132 return false; | 132 return false; |
| 133 | 133 |
| 134 pssh_data->assign(cur, cur + data_size); | 134 pssh_data->assign(cur, cur + data_size); |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 | 137 |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 | 140 |
| 141 static MediaDrmBridge::SecurityLevel GetSecurityLevelFromString( |
| 142 const std::string& security_level_str) { |
| 143 if (0 == security_level_str.compare("L1")) |
| 144 return MediaDrmBridge::SECURITY_LEVEL_1; |
| 145 if (0 == security_level_str.compare("L3")) |
| 146 return MediaDrmBridge::SECURITY_LEVEL_3; |
| 147 DCHECK(security_level_str.empty()); |
| 148 return MediaDrmBridge::SECURITY_LEVEL_NONE; |
| 149 } |
| 150 |
| 141 // static | 151 // static |
| 142 MediaDrmBridge* MediaDrmBridge::Create(int media_keys_id, | 152 MediaDrmBridge* MediaDrmBridge::Create(int media_keys_id, |
| 143 const std::vector<uint8>& scheme_uuid, | 153 const std::vector<uint8>& scheme_uuid, |
| 144 MediaPlayerManager* manager) { | 154 MediaPlayerManager* manager) { |
| 145 if (!IsAvailable() || scheme_uuid.empty()) | 155 if (!IsAvailable() || scheme_uuid.empty()) |
| 146 return NULL; | 156 return NULL; |
| 147 | 157 |
| 148 // TODO(qinmin): check whether the uuid is valid. | 158 // TODO(qinmin): check whether the uuid is valid. |
| 149 return new MediaDrmBridge(media_keys_id, scheme_uuid, manager); | 159 return new MediaDrmBridge(media_keys_id, scheme_uuid, manager); |
| 150 } | 160 } |
| 151 | 161 |
| 162 // static |
| 152 bool MediaDrmBridge::IsAvailable() { | 163 bool MediaDrmBridge::IsAvailable() { |
| 153 return base::android::BuildInfo::GetInstance()->sdk_int() >= 18; | 164 return base::android::BuildInfo::GetInstance()->sdk_int() >= 18; |
| 154 } | 165 } |
| 155 | 166 |
| 167 // static |
| 168 bool MediaDrmBridge::IsSecureDecoderRequired( |
| 169 const std::string& security_level_str) { |
| 170 return IsSecureDecoderRequired( |
| 171 GetSecurityLevelFromString(security_level_str)); |
| 172 } |
| 173 |
| 174 bool MediaDrmBridge::IsCryptoSchemeSupported( |
| 175 const std::vector<uint8>& scheme_uuid, |
| 176 const std::string& container_mime_type) { |
| 177 JNIEnv* env = AttachCurrentThread(); |
| 178 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 179 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 180 ScopedJavaLocalRef<jstring> j_container_mime_type = |
| 181 ConvertUTF8ToJavaString(env, container_mime_type); |
| 182 return Java_MediaDrmBridge_isCryptoSchemeSupported( |
| 183 env, j_scheme_uuid.obj(), j_container_mime_type.obj()); |
| 184 } |
| 185 |
| 156 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { | 186 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { |
| 157 return RegisterNativesImpl(env); | 187 return RegisterNativesImpl(env); |
| 158 } | 188 } |
| 159 | 189 |
| 160 MediaDrmBridge::MediaDrmBridge(int media_keys_id, | 190 MediaDrmBridge::MediaDrmBridge(int media_keys_id, |
| 161 const std::vector<uint8>& scheme_uuid, | 191 const std::vector<uint8>& scheme_uuid, |
| 162 MediaPlayerManager* manager) | 192 MediaPlayerManager* manager) |
| 163 : media_keys_id_(media_keys_id), | 193 : media_keys_id_(media_keys_id), |
| 164 scheme_uuid_(scheme_uuid), | 194 scheme_uuid_(scheme_uuid), |
| 165 manager_(manager) { | 195 manager_(manager) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 std::string session_id = ConvertJavaStringToUTF8(env, j_session_id); | 265 std::string session_id = ConvertJavaStringToUTF8(env, j_session_id); |
| 236 manager_->OnKeyAdded(media_keys_id_, session_id); | 266 manager_->OnKeyAdded(media_keys_id_, session_id); |
| 237 } | 267 } |
| 238 | 268 |
| 239 void MediaDrmBridge::OnKeyError(JNIEnv* env, jobject, jstring j_session_id) { | 269 void MediaDrmBridge::OnKeyError(JNIEnv* env, jobject, jstring j_session_id) { |
| 240 // |j_session_id| can be NULL, in which case we'll return an empty string. | 270 // |j_session_id| can be NULL, in which case we'll return an empty string. |
| 241 std::string session_id = ConvertJavaStringToUTF8(env, j_session_id); | 271 std::string session_id = ConvertJavaStringToUTF8(env, j_session_id); |
| 242 manager_->OnKeyError(media_keys_id_, session_id, MediaKeys::kUnknownError, 0); | 272 manager_->OnKeyError(media_keys_id_, session_id, MediaKeys::kUnknownError, 0); |
| 243 } | 273 } |
| 244 | 274 |
| 275 // static |
| 276 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) { |
| 277 return MediaDrmBridge::SECURITY_LEVEL_1 == security_level; |
| 278 } |
| 279 |
| 245 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { | 280 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { |
| 246 JNIEnv* env = AttachCurrentThread(); | 281 JNIEnv* env = AttachCurrentThread(); |
| 247 ScopedJavaLocalRef<jstring> j_security_level = | 282 ScopedJavaLocalRef<jstring> j_security_level = |
| 248 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); | 283 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); |
| 249 std::string security_level = | 284 std::string security_level_str = |
| 250 ConvertJavaStringToUTF8(env, j_security_level.obj()); | 285 ConvertJavaStringToUTF8(env, j_security_level.obj()); |
| 251 if (0 == security_level.compare("L1")) | 286 return GetSecurityLevelFromString(security_level_str); |
| 252 return SECURITY_LEVEL_1; | |
| 253 if (0 == security_level.compare("L3")) | |
| 254 return SECURITY_LEVEL_3; | |
| 255 DCHECK(security_level.empty()); | |
| 256 return SECURITY_LEVEL_NONE; | |
| 257 } | 287 } |
| 258 | 288 |
| 259 bool MediaDrmBridge::IsProtectedSurfaceRequired() { | 289 bool MediaDrmBridge::IsProtectedSurfaceRequired() { |
| 260 return MediaDrmBridge::SECURITY_LEVEL_1 == GetSecurityLevel(); | 290 return IsSecureDecoderRequired(GetSecurityLevel()); |
| 261 } | 291 } |
| 262 | 292 |
| 263 } // namespace media | 293 } // namespace media |
| OLD | NEW |