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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, | 66 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, |
67 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; | 67 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED }; |
68 | 68 |
69 typedef std::vector<uint8> UUID; | 69 typedef std::vector<uint8> UUID; |
70 | 70 |
71 class KeySystemUuidManager { | 71 class KeySystemUuidManager { |
72 public: | 72 public: |
73 KeySystemUuidManager(); | 73 KeySystemUuidManager(); |
74 UUID GetUUID(const std::string& key_system); | 74 UUID GetUUID(const std::string& key_system); |
75 void AddMapping(const std::string& key_system, const UUID& uuid); | 75 void AddMapping(const std::string& key_system, const UUID& uuid); |
| 76 std::vector<std::string> GetPlatformKeySystemNames(); |
76 | 77 |
77 private: | 78 private: |
78 typedef base::hash_map<std::string, UUID> KeySystemUuidMap; | 79 typedef base::hash_map<std::string, UUID> KeySystemUuidMap; |
79 | 80 |
80 KeySystemUuidMap key_system_uuid_map_; | 81 KeySystemUuidMap key_system_uuid_map_; |
81 | 82 |
82 DISALLOW_COPY_AND_ASSIGN(KeySystemUuidManager); | 83 DISALLOW_COPY_AND_ASSIGN(KeySystemUuidManager); |
83 }; | 84 }; |
84 | 85 |
85 KeySystemUuidManager::KeySystemUuidManager() { | 86 KeySystemUuidManager::KeySystemUuidManager() { |
(...skipping 12 matching lines...) Expand all Loading... |
98 void KeySystemUuidManager::AddMapping(const std::string& key_system, | 99 void KeySystemUuidManager::AddMapping(const std::string& key_system, |
99 const UUID& uuid) { | 100 const UUID& uuid) { |
100 KeySystemUuidMap::iterator it = key_system_uuid_map_.find(key_system); | 101 KeySystemUuidMap::iterator it = key_system_uuid_map_.find(key_system); |
101 DCHECK(it == key_system_uuid_map_.end()) | 102 DCHECK(it == key_system_uuid_map_.end()) |
102 << "Shouldn't overwrite an existing key system."; | 103 << "Shouldn't overwrite an existing key system."; |
103 if (it != key_system_uuid_map_.end()) | 104 if (it != key_system_uuid_map_.end()) |
104 return; | 105 return; |
105 key_system_uuid_map_[key_system] = uuid; | 106 key_system_uuid_map_[key_system] = uuid; |
106 } | 107 } |
107 | 108 |
| 109 std::vector<std::string> KeySystemUuidManager::GetPlatformKeySystemNames() { |
| 110 std::vector<std::string> key_systems; |
| 111 for (KeySystemUuidMap::iterator it = key_system_uuid_map_.begin(); |
| 112 it != key_system_uuid_map_.end(); ++it) { |
| 113 // Rule out the key system handled by Chrome explicitly. |
| 114 if (it->first != kWidevineKeySystem) |
| 115 key_systems.push_back(it->first); |
| 116 } |
| 117 return key_systems; |
| 118 } |
| 119 |
108 base::LazyInstance<KeySystemUuidManager>::Leaky g_key_system_uuid_manager = | 120 base::LazyInstance<KeySystemUuidManager>::Leaky g_key_system_uuid_manager = |
109 LAZY_INSTANCE_INITIALIZER; | 121 LAZY_INSTANCE_INITIALIZER; |
110 | 122 |
111 // Tries to find a PSSH box whose "SystemId" is |uuid| in |data|, parses the | 123 // Tries to find a PSSH box whose "SystemId" is |uuid| in |data|, parses the |
112 // "Data" of the box and put it in |pssh_data|. Returns true if such a box is | 124 // "Data" of the box and put it in |pssh_data|. Returns true if such a box is |
113 // found and successfully parsed. Returns false otherwise. | 125 // found and successfully parsed. Returns false otherwise. |
114 // Notes: | 126 // Notes: |
115 // 1, If multiple PSSH boxes are found,the "Data" of the first matching PSSH box | 127 // 1, If multiple PSSH boxes are found,the "Data" of the first matching PSSH box |
116 // will be set in |pssh_data|. | 128 // will be set in |pssh_data|. |
117 // 2, Only PSSH and TENC boxes are allowed in |data|. TENC boxes are skipped. | 129 // 2, Only PSSH and TENC boxes are allowed in |data|. TENC boxes are skipped. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 return false; | 269 return false; |
258 | 270 |
259 scoped_ptr<MediaDrmBridge> media_drm_bridge = | 271 scoped_ptr<MediaDrmBridge> media_drm_bridge = |
260 MediaDrmBridge::CreateSessionless(key_system); | 272 MediaDrmBridge::CreateSessionless(key_system); |
261 if (!media_drm_bridge) | 273 if (!media_drm_bridge) |
262 return false; | 274 return false; |
263 | 275 |
264 return media_drm_bridge->SetSecurityLevel(security_level); | 276 return media_drm_bridge->SetSecurityLevel(security_level); |
265 } | 277 } |
266 | 278 |
267 //static | 279 // static |
268 void MediaDrmBridge::AddKeySystemUuidMapping(const std::string& key_system, | 280 void MediaDrmBridge::AddKeySystemUuidMapping(const std::string& key_system, |
269 const std::vector<uint8>& uuid) { | 281 const std::vector<uint8>& uuid) { |
270 g_key_system_uuid_manager.Get().AddMapping(key_system, uuid); | 282 g_key_system_uuid_manager.Get().AddMapping(key_system, uuid); |
271 } | 283 } |
272 | 284 |
273 // static | 285 // static |
| 286 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { |
| 287 return g_key_system_uuid_manager.Get().GetPlatformKeySystemNames(); |
| 288 } |
| 289 |
| 290 // static |
274 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { | 291 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { |
275 DCHECK(!key_system.empty()); | 292 DCHECK(!key_system.empty()); |
276 return IsKeySystemSupportedWithTypeImpl(key_system, ""); | 293 return IsKeySystemSupportedWithTypeImpl(key_system, ""); |
277 } | 294 } |
278 | 295 |
279 // static | 296 // static |
280 bool MediaDrmBridge::IsKeySystemSupportedWithType( | 297 bool MediaDrmBridge::IsKeySystemSupportedWithType( |
281 const std::string& key_system, | 298 const std::string& key_system, |
282 const std::string& container_mime_type) { | 299 const std::string& container_mime_type) { |
283 DCHECK(!key_system.empty() && !container_mime_type.empty()); | 300 DCHECK(!key_system.empty() && !container_mime_type.empty()); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 JNIEnv* env = AttachCurrentThread(); | 559 JNIEnv* env = AttachCurrentThread(); |
543 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 560 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
544 } | 561 } |
545 | 562 |
546 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( | 563 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( |
547 JNIEnv* env, jobject, bool success) { | 564 JNIEnv* env, jobject, bool success) { |
548 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 565 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
549 } | 566 } |
550 | 567 |
551 } // namespace media | 568 } // namespace media |
OLD | NEW |