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/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 const std::string& security_level_str) { | 145 const std::string& security_level_str) { |
146 if (0 == security_level_str.compare("L1")) | 146 if (0 == security_level_str.compare("L1")) |
147 return MediaDrmBridge::SECURITY_LEVEL_1; | 147 return MediaDrmBridge::SECURITY_LEVEL_1; |
148 if (0 == security_level_str.compare("L3")) | 148 if (0 == security_level_str.compare("L3")) |
149 return MediaDrmBridge::SECURITY_LEVEL_3; | 149 return MediaDrmBridge::SECURITY_LEVEL_3; |
150 DCHECK(security_level_str.empty()); | 150 DCHECK(security_level_str.empty()); |
151 return MediaDrmBridge::SECURITY_LEVEL_NONE; | 151 return MediaDrmBridge::SECURITY_LEVEL_NONE; |
152 } | 152 } |
153 | 153 |
154 // static | 154 // static |
155 MediaDrmBridge* MediaDrmBridge::Create(int media_keys_id, | 155 scoped_ptr<MediaDrmBridge> MediaDrmBridge::Create( |
156 const std::vector<uint8>& scheme_uuid, | 156 int media_keys_id, |
157 const std::string& security_level, | 157 const std::vector<uint8>& scheme_uuid, |
158 MediaPlayerManager* manager) { | 158 const std::string& security_level, |
159 if (!IsAvailable() || scheme_uuid.empty()) | 159 MediaPlayerManager* manager) { |
160 return NULL; | 160 scoped_ptr<MediaDrmBridge> media_drm_bridge; |
161 | 161 |
162 // TODO(qinmin): check whether the uuid is valid. | 162 if (IsAvailable() && !scheme_uuid.empty()) { |
163 return new MediaDrmBridge( | 163 // TODO(qinmin): check whether the uuid is valid. |
164 media_keys_id, scheme_uuid, security_level, manager); | 164 media_drm_bridge.reset( |
165 new MediaDrmBridge(media_keys_id, scheme_uuid, security_level, manager)); | |
166 if (media_drm_bridge->j_media_drm_.is_null()) | |
167 media_drm_bridge.reset(); | |
168 } | |
169 | |
170 return media_drm_bridge.Pass(); | |
165 } | 171 } |
166 | 172 |
167 // static | 173 // static |
168 bool MediaDrmBridge::IsAvailable() { | 174 bool MediaDrmBridge::IsAvailable() { |
169 return base::android::BuildInfo::GetInstance()->sdk_int() >= 18; | 175 return base::android::BuildInfo::GetInstance()->sdk_int() >= 18; |
170 } | 176 } |
171 | 177 |
172 // static | 178 // static |
173 bool MediaDrmBridge::IsSecureDecoderRequired( | 179 bool MediaDrmBridge::IsSecureDecoderRequired( |
174 const std::string& security_level_str) { | 180 const std::string& security_level_str) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 212 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
207 ScopedJavaLocalRef<jstring> j_security_level = | 213 ScopedJavaLocalRef<jstring> j_security_level = |
208 ConvertUTF8ToJavaString(env, security_level); | 214 ConvertUTF8ToJavaString(env, security_level); |
209 j_media_drm_.Reset(Java_MediaDrmBridge_create( | 215 j_media_drm_.Reset(Java_MediaDrmBridge_create( |
210 env, j_scheme_uuid.obj(), j_security_level.obj(), | 216 env, j_scheme_uuid.obj(), j_security_level.obj(), |
211 reinterpret_cast<intptr_t>(this))); | 217 reinterpret_cast<intptr_t>(this))); |
212 } | 218 } |
213 | 219 |
214 MediaDrmBridge::~MediaDrmBridge() { | 220 MediaDrmBridge::~MediaDrmBridge() { |
215 JNIEnv* env = AttachCurrentThread(); | 221 JNIEnv* env = AttachCurrentThread(); |
216 Java_MediaDrmBridge_release(env, j_media_drm_.obj()); | 222 if (!j_media_drm_.is_null()) { |
223 Java_MediaDrmBridge_release(env, j_media_drm_.obj()); | |
224 j_media_drm_.Reset(); | |
qinmin
2013/09/05 22:15:31
ScopedJavaGlobalRef will do this for you
xhwang
2013/09/06 02:17:47
Done.
| |
225 } | |
217 } | 226 } |
218 | 227 |
219 bool MediaDrmBridge::GenerateKeyRequest(const std::string& type, | 228 bool MediaDrmBridge::GenerateKeyRequest(const std::string& type, |
220 const uint8* init_data, | 229 const uint8* init_data, |
221 int init_data_length) { | 230 int init_data_length) { |
222 std::vector<uint8> pssh_data; | 231 std::vector<uint8> pssh_data; |
223 if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) | 232 if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) |
224 return false; | 233 return false; |
225 | 234 |
226 JNIEnv* env = AttachCurrentThread(); | 235 JNIEnv* env = AttachCurrentThread(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 std::string security_level_str = | 324 std::string security_level_str = |
316 ConvertJavaStringToUTF8(env, j_security_level.obj()); | 325 ConvertJavaStringToUTF8(env, j_security_level.obj()); |
317 return GetSecurityLevelFromString(security_level_str); | 326 return GetSecurityLevelFromString(security_level_str); |
318 } | 327 } |
319 | 328 |
320 bool MediaDrmBridge::IsProtectedSurfaceRequired() { | 329 bool MediaDrmBridge::IsProtectedSurfaceRequired() { |
321 return IsSecureDecoderRequired(GetSecurityLevel()); | 330 return IsSecureDecoderRequired(GetSecurityLevel()); |
322 } | 331 } |
323 | 332 |
324 } // namespace media | 333 } // namespace media |
OLD | NEW |