| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/android/build_info.h" | 11 #include "base/android/build_info.h" |
| 12 #include "base/android/jni_array.h" | 12 #include "base/android/jni_array.h" |
| 13 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/callback_helpers.h" | 15 #include "base/callback_helpers.h" |
| 16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
| 17 #include "base/feature_list.h" | 17 #include "base/feature_list.h" |
| 18 #include "base/lazy_instance.h" | |
| 19 #include "base/location.h" | 18 #include "base/location.h" |
| 20 #include "base/logging.h" | 19 #include "base/logging.h" |
| 21 #include "base/macros.h" | 20 #include "base/macros.h" |
| 22 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 25 #include "base/sys_byteorder.h" | 24 #include "base/sys_byteorder.h" |
| 26 #include "base/sys_info.h" | 25 #include "base/sys_info.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "jni/MediaDrmBridge_jni.h" | 27 #include "jni/MediaDrmBridge_jni.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 std::vector<std::string> key_systems; | 160 std::vector<std::string> key_systems; |
| 162 for (KeySystemUuidMap::iterator it = key_system_uuid_map_.begin(); | 161 for (KeySystemUuidMap::iterator it = key_system_uuid_map_.begin(); |
| 163 it != key_system_uuid_map_.end(); ++it) { | 162 it != key_system_uuid_map_.end(); ++it) { |
| 164 // Rule out the key system handled by Chrome explicitly. | 163 // Rule out the key system handled by Chrome explicitly. |
| 165 if (it->first != kWidevineKeySystem) | 164 if (it->first != kWidevineKeySystem) |
| 166 key_systems.push_back(it->first); | 165 key_systems.push_back(it->first); |
| 167 } | 166 } |
| 168 return key_systems; | 167 return key_systems; |
| 169 } | 168 } |
| 170 | 169 |
| 171 base::LazyInstance<KeySystemManager>::Leaky g_key_system_manager = | 170 KeySystemManager* GetKeySystemManager() { |
| 172 LAZY_INSTANCE_INITIALIZER; | 171 static KeySystemManager* ksm = new KeySystemManager(); |
| 172 return ksm; |
| 173 } |
| 173 | 174 |
| 174 // Checks whether |key_system| is supported with |container_mime_type|. Only | 175 // Checks whether |key_system| is supported with |container_mime_type|. Only |
| 175 // checks |key_system| support if |container_mime_type| is empty. | 176 // checks |key_system| support if |container_mime_type| is empty. |
| 176 // TODO(xhwang): The |container_mime_type| is not the same as contentType in | 177 // TODO(xhwang): The |container_mime_type| is not the same as contentType in |
| 177 // the EME spec. Revisit this once the spec issue with initData type is | 178 // the EME spec. Revisit this once the spec issue with initData type is |
| 178 // resolved. | 179 // resolved. |
| 179 bool IsKeySystemSupportedWithTypeImpl(const std::string& key_system, | 180 bool IsKeySystemSupportedWithTypeImpl(const std::string& key_system, |
| 180 const std::string& container_mime_type) { | 181 const std::string& container_mime_type) { |
| 181 DCHECK(MediaDrmBridge::IsAvailable()); | 182 DCHECK(MediaDrmBridge::IsAvailable()); |
| 182 | 183 |
| 183 if (key_system.empty()) { | 184 if (key_system.empty()) { |
| 184 NOTREACHED(); | 185 NOTREACHED(); |
| 185 return false; | 186 return false; |
| 186 } | 187 } |
| 187 | 188 |
| 188 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); | 189 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); |
| 189 if (scheme_uuid.empty()) | 190 if (scheme_uuid.empty()) |
| 190 return false; | 191 return false; |
| 191 | 192 |
| 192 JNIEnv* env = AttachCurrentThread(); | 193 JNIEnv* env = AttachCurrentThread(); |
| 193 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = | 194 ScopedJavaLocalRef<jbyteArray> j_scheme_uuid = |
| 194 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); | 195 base::android::ToJavaByteArray(env, &scheme_uuid[0], scheme_uuid.size()); |
| 195 ScopedJavaLocalRef<jstring> j_container_mime_type = | 196 ScopedJavaLocalRef<jstring> j_container_mime_type = |
| 196 ConvertUTF8ToJavaString(env, container_mime_type); | 197 ConvertUTF8ToJavaString(env, container_mime_type); |
| 197 return Java_MediaDrmBridge_isCryptoSchemeSupported(env, j_scheme_uuid, | 198 return Java_MediaDrmBridge_isCryptoSchemeSupported(env, j_scheme_uuid, |
| 198 j_container_mime_type); | 199 j_container_mime_type); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 return false; | 285 return false; |
| 285 | 286 |
| 286 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); | 287 return IsKeySystemSupportedWithTypeImpl(key_system, container_mime_type); |
| 287 } | 288 } |
| 288 | 289 |
| 289 // static | 290 // static |
| 290 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { | 291 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { |
| 291 if (!MediaDrmBridge::IsAvailable()) | 292 if (!MediaDrmBridge::IsAvailable()) |
| 292 return std::vector<std::string>(); | 293 return std::vector<std::string>(); |
| 293 | 294 |
| 294 return g_key_system_manager.Get().GetPlatformKeySystemNames(); | 295 return GetKeySystemManager()->GetPlatformKeySystemNames(); |
| 295 } | 296 } |
| 296 | 297 |
| 297 // static | 298 // static |
| 298 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( | 299 scoped_refptr<MediaDrmBridge> MediaDrmBridge::CreateInternal( |
| 299 const std::string& key_system, | 300 const std::string& key_system, |
| 300 SecurityLevel security_level, | 301 SecurityLevel security_level, |
| 301 const CreateFetcherCB& create_fetcher_cb, | 302 const CreateFetcherCB& create_fetcher_cb, |
| 302 const SessionMessageCB& session_message_cb, | 303 const SessionMessageCB& session_message_cb, |
| 303 const SessionClosedCB& session_closed_cb, | 304 const SessionClosedCB& session_closed_cb, |
| 304 const SessionKeysChangeCB& session_keys_change_cb, | 305 const SessionKeysChangeCB& session_keys_change_cb, |
| 305 const SessionExpirationUpdateCB& session_expiration_update_cb) { | 306 const SessionExpirationUpdateCB& session_expiration_update_cb) { |
| 306 // All paths requires the MediaDrmApis. | 307 // All paths requires the MediaDrmApis. |
| 307 DCHECK(AreMediaDrmApisAvailable()); | 308 DCHECK(AreMediaDrmApisAvailable()); |
| 308 | 309 |
| 309 UUID scheme_uuid = g_key_system_manager.Get().GetUUID(key_system); | 310 UUID scheme_uuid = GetKeySystemManager()->GetUUID(key_system); |
| 310 if (scheme_uuid.empty()) | 311 if (scheme_uuid.empty()) |
| 311 return nullptr; | 312 return nullptr; |
| 312 | 313 |
| 313 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( | 314 scoped_refptr<MediaDrmBridge> media_drm_bridge(new MediaDrmBridge( |
| 314 scheme_uuid, security_level, create_fetcher_cb, session_message_cb, | 315 scheme_uuid, security_level, create_fetcher_cb, session_message_cb, |
| 315 session_closed_cb, session_keys_change_cb, session_expiration_update_cb)); | 316 session_closed_cb, session_keys_change_cb, session_expiration_update_cb)); |
| 316 | 317 |
| 317 if (media_drm_bridge->j_media_drm_.is_null()) | 318 if (media_drm_bridge->j_media_drm_.is_null()) |
| 318 media_drm_bridge = nullptr; | 319 media_drm_bridge = nullptr; |
| 319 | 320 |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 } | 890 } |
| 890 | 891 |
| 891 void MediaDrmBridge::OnHasAdditionalUsableKey() { | 892 void MediaDrmBridge::OnHasAdditionalUsableKey() { |
| 892 DCHECK(task_runner_->BelongsToCurrentThread()); | 893 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 893 DVLOG(1) << __func__; | 894 DVLOG(1) << __func__; |
| 894 | 895 |
| 895 player_tracker_.NotifyNewKey(); | 896 player_tracker_.NotifyNewKey(); |
| 896 } | 897 } |
| 897 | 898 |
| 898 } // namespace media | 899 } // namespace media |
| OLD | NEW |