Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/cdm/cdm_adapter_factory.h" | |
| 6 | |
| 7 #include "base/base_paths.h" | |
| 8 #include "base/bind.h" | |
| 9 #include "base/feature_list.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/path_service.h" | |
| 12 #include "base/threading/thread_task_runner_handle.h" | |
| 13 #include "media/base/cdm_factory.h" | |
| 14 #include "media/base/key_systems.h" | |
| 15 #include "media/cdm/cdm_adapter.h" | |
| 16 #include "media/cdm/cdm_paths.h" | |
| 17 #include "third_party/widevine/cdm/widevine_cdm_common.h" | |
| 18 | |
| 19 namespace media { | |
| 20 | |
| 21 CdmAdapterFactory::CdmAdapterFactory( | |
| 22 CdmAllocator::CreationCB allocator_creation_cb) | |
| 23 : allocator_creation_cb_(std::move(allocator_creation_cb)) { | |
| 24 DCHECK(allocator_creation_cb_); | |
| 25 } | |
| 26 | |
| 27 CdmAdapterFactory::~CdmAdapterFactory() {} | |
| 28 | |
| 29 void CdmAdapterFactory::Create( | |
| 30 const std::string& key_system, | |
| 31 const GURL& security_origin, | |
| 32 const CdmConfig& cdm_config, | |
| 33 const SessionMessageCB& session_message_cb, | |
| 34 const SessionClosedCB& session_closed_cb, | |
| 35 const SessionKeysChangeCB& session_keys_change_cb, | |
| 36 const SessionExpirationUpdateCB& session_expiration_update_cb, | |
| 37 const CdmCreatedCB& cdm_created_cb) { | |
| 38 DVLOG(1) << __FUNCTION__ << ": key_system=" << key_system; | |
| 39 | |
| 40 if (!security_origin.is_valid()) { | |
| 41 LOG(ERROR) << "Invalid Origin: " << security_origin; | |
| 42 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 43 FROM_HERE, base::Bind(cdm_created_cb, nullptr, "Invalid origin.")); | |
| 44 return; | |
| 45 } | |
| 46 | |
| 47 base::FilePath cdm_path; | |
| 48 | |
| 49 #if defined(WIDEVINE_CDM_AVAILABLE) | |
| 50 // TODO(xhwang): Remove key-system-specific logic here. We should have the | |
| 51 // CDM path forwarded from the browser already. See http://crbug.com/510604 | |
| 52 if (key_system == kWidevineKeySystem) { | |
| 53 // Build the library path for Widevine CDM. | |
| 54 // TODO(xhwang): We should have the CDM path forwarded from the browser | |
| 55 // already. See http://crbug.com/510604 | |
| 56 base::FilePath cdm_base_path; | |
| 57 base::PathService::Get(base::DIR_MODULE, &cdm_base_path); | |
| 58 cdm_base_path = cdm_base_path.Append( | |
| 59 GetPlatformSpecificDirectory(kWidevineCdmBaseDirectory)); | |
|
jrummell
2017/05/23 22:23:28
Can you use DIR_COMPONENT_WIDEVINE_CDM to get the
xhwang
2017/05/23 22:31:12
DIR_COMPONENT_WIDEVINE_CDM points to the component
| |
| 60 cdm_path = cdm_base_path.AppendASCII( | |
| 61 base::GetNativeLibraryName(kWidevineCdmLibraryName)); | |
| 62 } | |
| 63 #endif // defined(WIDEVINE_CDM_AVAILABLE) | |
| 64 | |
| 65 if (cdm_path.empty()) { | |
| 66 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 67 FROM_HERE, | |
| 68 base::Bind(cdm_created_cb, nullptr, "Unsupported key system.")); | |
| 69 return; | |
| 70 } | |
| 71 | |
| 72 std::unique_ptr<CdmAllocator> cdm_allocator = allocator_creation_cb_.Run(); | |
| 73 if (!cdm_allocator) { | |
| 74 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 75 FROM_HERE, | |
| 76 base::Bind(cdm_created_cb, nullptr, "CDM allocator creation failed.")); | |
| 77 return; | |
| 78 } | |
| 79 | |
| 80 // TODO(xhwang): Hook up auxiliary services, e.g. File IO, output protection, | |
| 81 // and platform verification. | |
| 82 CdmAdapter::Create(key_system, cdm_path, cdm_config, std::move(cdm_allocator), | |
| 83 CreateCdmFileIOCB(), session_message_cb, session_closed_cb, | |
| 84 session_keys_change_cb, session_expiration_update_cb, | |
| 85 cdm_created_cb); | |
| 86 } | |
| 87 | |
| 88 } // namespace media | |
| OLD | NEW |