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( | |
qinmin
2013/08/27 21:41:12
this doesn't needs to be a class member function,
xhwang
2013/08/28 01:21:24
This is already a helper function and not a class
| |
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 void MediaDrmBridge::OnKeyAdded(JNIEnv* env, jobject, jstring j_session_id) { | 264 void MediaDrmBridge::OnKeyAdded(JNIEnv* env, jobject, jstring j_session_id) { |
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 std::string session_id = ConvertJavaStringToUTF8(env, j_session_id); | 270 std::string session_id = ConvertJavaStringToUTF8(env, j_session_id); |
241 manager_->OnKeyError(media_keys_id_, session_id, MediaKeys::kUnknownError, 0); | 271 manager_->OnKeyError(media_keys_id_, session_id, MediaKeys::kUnknownError, 0); |
242 } | 272 } |
243 | 273 |
274 // static | |
275 bool MediaDrmBridge::IsSecureDecoderRequired(SecurityLevel security_level) { | |
276 return MediaDrmBridge::SECURITY_LEVEL_1 == security_level; | |
277 } | |
278 | |
244 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { | 279 MediaDrmBridge::SecurityLevel MediaDrmBridge::GetSecurityLevel() { |
245 JNIEnv* env = AttachCurrentThread(); | 280 JNIEnv* env = AttachCurrentThread(); |
246 ScopedJavaLocalRef<jstring> j_security_level = | 281 ScopedJavaLocalRef<jstring> j_security_level = |
247 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); | 282 Java_MediaDrmBridge_getSecurityLevel(env, j_media_drm_.obj()); |
248 std::string security_level = | 283 std::string security_level_str = |
249 ConvertJavaStringToUTF8(env, j_security_level.obj()); | 284 ConvertJavaStringToUTF8(env, j_security_level.obj()); |
250 if (0 == security_level.compare("L1")) | 285 return GetSecurityLevelFromString(security_level_str); |
251 return SECURITY_LEVEL_1; | |
252 if (0 == security_level.compare("L3")) | |
253 return SECURITY_LEVEL_3; | |
254 DCHECK(security_level.empty()); | |
255 return SECURITY_LEVEL_NONE; | |
256 } | 286 } |
257 | 287 |
258 bool MediaDrmBridge::IsProtectedSurfaceRequired() { | 288 bool MediaDrmBridge::IsProtectedSurfaceRequired() { |
259 return MediaDrmBridge::SECURITY_LEVEL_1 == GetSecurityLevel(); | 289 return IsSecureDecoderRequired(GetSecurityLevel()); |
260 } | 290 } |
261 | 291 |
262 } // namespace media | 292 } // namespace media |
OLD | NEW |