Chromium Code Reviews| 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 if (it->first.compare(kWidevineKeySystem) != 0) | |
|
ddorwin
2014/06/11 01:54:02
This should be commented.
ycheo (away)
2014/06/11 07:43:43
Done.
| |
| 114 key_systems.push_back(it->first); | |
| 115 } | |
| 116 return key_systems; | |
| 117 } | |
| 118 | |
| 108 base::LazyInstance<KeySystemUuidManager>::Leaky g_key_system_uuid_manager = | 119 base::LazyInstance<KeySystemUuidManager>::Leaky g_key_system_uuid_manager = |
| 109 LAZY_INSTANCE_INITIALIZER; | 120 LAZY_INSTANCE_INITIALIZER; |
| 110 | 121 |
| 111 // Tries to find a PSSH box whose "SystemId" is |uuid| in |data|, parses the | 122 // 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 | 123 // "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. | 124 // found and successfully parsed. Returns false otherwise. |
| 114 // Notes: | 125 // Notes: |
| 115 // 1, If multiple PSSH boxes are found,the "Data" of the first matching PSSH box | 126 // 1, If multiple PSSH boxes are found,the "Data" of the first matching PSSH box |
| 116 // will be set in |pssh_data|. | 127 // will be set in |pssh_data|. |
| 117 // 2, Only PSSH and TENC boxes are allowed in |data|. TENC boxes are skipped. | 128 // 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; | 268 return false; |
| 258 | 269 |
| 259 scoped_ptr<MediaDrmBridge> media_drm_bridge = | 270 scoped_ptr<MediaDrmBridge> media_drm_bridge = |
| 260 MediaDrmBridge::CreateSessionless(key_system); | 271 MediaDrmBridge::CreateSessionless(key_system); |
| 261 if (!media_drm_bridge) | 272 if (!media_drm_bridge) |
| 262 return false; | 273 return false; |
| 263 | 274 |
| 264 return media_drm_bridge->SetSecurityLevel(security_level); | 275 return media_drm_bridge->SetSecurityLevel(security_level); |
| 265 } | 276 } |
| 266 | 277 |
| 267 //static | 278 // static |
| 268 void MediaDrmBridge::AddKeySystemUuidMapping(const std::string& key_system, | 279 void MediaDrmBridge::AddKeySystemUuidMapping(const std::string& key_system, |
| 269 const std::vector<uint8>& uuid) { | 280 const std::vector<uint8>& uuid) { |
| 270 g_key_system_uuid_manager.Get().AddMapping(key_system, uuid); | 281 g_key_system_uuid_manager.Get().AddMapping(key_system, uuid); |
| 271 } | 282 } |
| 272 | 283 |
| 273 // static | 284 // static |
| 285 std::vector<std::string> MediaDrmBridge::GetPlatformKeySystemNames() { | |
| 286 return g_key_system_uuid_manager.Get().GetPlatformKeySystemNames(); | |
|
ddorwin
2014/06/11 01:54:01
This indirection makes an extra copy. :(
ycheo (away)
2014/06/11 07:43:43
As I tested, GCC does the return value optimizatio
| |
| 287 } | |
| 288 | |
| 289 // static | |
| 274 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { | 290 bool MediaDrmBridge::IsKeySystemSupported(const std::string& key_system) { |
| 275 DCHECK(!key_system.empty()); | 291 DCHECK(!key_system.empty()); |
| 276 return IsKeySystemSupportedWithTypeImpl(key_system, ""); | 292 return IsKeySystemSupportedWithTypeImpl(key_system, ""); |
| 277 } | 293 } |
| 278 | 294 |
| 279 // static | 295 // static |
| 280 bool MediaDrmBridge::IsKeySystemSupportedWithType( | 296 bool MediaDrmBridge::IsKeySystemSupportedWithType( |
| 281 const std::string& key_system, | 297 const std::string& key_system, |
| 282 const std::string& container_mime_type) { | 298 const std::string& container_mime_type) { |
| 283 DCHECK(!key_system.empty() && !container_mime_type.empty()); | 299 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(); | 558 JNIEnv* env = AttachCurrentThread(); |
| 543 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); | 559 Java_MediaDrmBridge_resetDeviceCredentials(env, j_media_drm_.obj()); |
| 544 } | 560 } |
| 545 | 561 |
| 546 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( | 562 void MediaDrmBridge::OnResetDeviceCredentialsCompleted( |
| 547 JNIEnv* env, jobject, bool success) { | 563 JNIEnv* env, jobject, bool success) { |
| 548 base::ResetAndReturn(&reset_credentials_cb_).Run(success); | 564 base::ResetAndReturn(&reset_credentials_cb_).Run(success); |
| 549 } | 565 } |
| 550 | 566 |
| 551 } // namespace media | 567 } // namespace media |
| OLD | NEW |