MFContentProtectionManager.cpp (5445B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "MFContentProtectionManager.h" 6 7 #include <winnt.h> 8 9 #include "MFMediaEngineUtils.h" 10 #include "WMF.h" 11 #include "WMFUtils.h" 12 13 namespace mozilla { 14 15 using Microsoft::WRL::ComPtr; 16 17 #define LOG(msg, ...) \ 18 MOZ_LOG(gMFMediaEngineLog, LogLevel::Debug, \ 19 ("MFContentProtectionManager=%p, " msg, this, ##__VA_ARGS__)) 20 21 MFContentProtectionManager::MFContentProtectionManager() { 22 MOZ_COUNT_CTOR(MFContentProtectionManager); 23 LOG("MFContentProtectionManager created"); 24 } 25 26 MFContentProtectionManager::~MFContentProtectionManager() { 27 MOZ_COUNT_DTOR(MFContentProtectionManager); 28 LOG("MFContentProtectionManager destroyed"); 29 } 30 31 HRESULT MFContentProtectionManager::RuntimeClassInitialize() { 32 ScopedHString propertyId( 33 RuntimeClass_Windows_Foundation_Collections_PropertySet); 34 RETURN_IF_FAILED(RoActivateInstance(propertyId.Get(), &mPMPServerSet)); 35 return S_OK; 36 } 37 38 HRESULT MFContentProtectionManager::BeginEnableContent( 39 IMFActivate* aEnablerActivate, IMFTopology* aTopology, 40 IMFAsyncCallback* aCallback, IUnknown* aState) { 41 LOG("BeginEnableContent"); 42 ComPtr<IUnknown> unknownObject; 43 ComPtr<IMFAsyncResult> asyncResult; 44 RETURN_IF_FAILED( 45 wmf::MFCreateAsyncResult(nullptr, aCallback, aState, &asyncResult)); 46 RETURN_IF_FAILED( 47 aEnablerActivate->ActivateObject(IID_PPV_ARGS(&unknownObject))); 48 49 GUID enablerType = GUID_NULL; 50 ComPtr<IMFContentEnabler> contentEnabler; 51 if (SUCCEEDED(unknownObject.As(&contentEnabler))) { 52 RETURN_IF_FAILED(contentEnabler->GetEnableType(&enablerType)); 53 } else { 54 ComPtr<ABI::Windows::Media::Protection::IMediaProtectionServiceRequest> 55 serviceRequest; 56 RETURN_IF_FAILED(unknownObject.As(&serviceRequest)); 57 RETURN_IF_FAILED(serviceRequest->get_Type(&enablerType)); 58 } 59 60 if (enablerType == MFENABLETYPE_MF_RebootRequired) { 61 LOG("Error - MFENABLETYPE_MF_RebootRequired"); 62 return MF_E_REBOOT_REQUIRED; 63 } else if (enablerType == MFENABLETYPE_MF_UpdateRevocationInformation) { 64 LOG("Error - MFENABLETYPE_MF_UpdateRevocationInformation"); 65 return MF_E_GRL_VERSION_TOO_LOW; 66 } else if (enablerType == MFENABLETYPE_MF_UpdateUntrustedComponent) { 67 LOG("Error - MFENABLETYPE_MF_UpdateUntrustedComponent"); 68 return HRESULT_FROM_WIN32(ERROR_INVALID_IMAGE_HASH); 69 } 70 71 if (!mCDMProxy) { 72 return MF_E_SHUTDOWN; 73 } 74 RETURN_IF_FAILED( 75 mCDMProxy->SetContentEnabler(unknownObject.Get(), asyncResult.Get())); 76 77 // TODO : maybe need to notify waiting for key status? 78 LOG("Finished BeginEnableContent"); 79 return S_OK; 80 } 81 82 HRESULT MFContentProtectionManager::EndEnableContent( 83 IMFAsyncResult* aAsyncResult) { 84 HRESULT hr = aAsyncResult->GetStatus(); 85 if (FAILED(hr)) { 86 // Follow Chromium to not to return failure, which avoid doing additional 87 // work here. 88 LOG("Content enabling failed. hr=%lx", hr); 89 } else { 90 LOG("Content enabling succeeded"); 91 } 92 return S_OK; 93 } 94 95 HRESULT MFContentProtectionManager::add_ServiceRequested( 96 ABI::Windows::Media::Protection::IServiceRequestedEventHandler* aHandler, 97 EventRegistrationToken* aCookie) { 98 return E_NOTIMPL; 99 } 100 101 HRESULT MFContentProtectionManager::remove_ServiceRequested( 102 EventRegistrationToken aCookie) { 103 return E_NOTIMPL; 104 } 105 106 HRESULT MFContentProtectionManager::add_RebootNeeded( 107 ABI::Windows::Media::Protection::IRebootNeededEventHandler* aHandler, 108 EventRegistrationToken* aCookie) { 109 return E_NOTIMPL; 110 } 111 112 HRESULT MFContentProtectionManager::remove_RebootNeeded( 113 EventRegistrationToken aCookie) { 114 return E_NOTIMPL; 115 } 116 117 HRESULT MFContentProtectionManager::add_ComponentLoadFailed( 118 ABI::Windows::Media::Protection::IComponentLoadFailedEventHandler* aHandler, 119 EventRegistrationToken* aCookie) { 120 return E_NOTIMPL; 121 } 122 123 HRESULT MFContentProtectionManager::remove_ComponentLoadFailed( 124 EventRegistrationToken aCookie) { 125 return E_NOTIMPL; 126 } 127 128 HRESULT MFContentProtectionManager::get_Properties( 129 ABI::Windows::Foundation::Collections::IPropertySet** properties) { 130 if (!mPMPServerSet) { 131 return E_POINTER; 132 } 133 return mPMPServerSet.CopyTo(properties); 134 } 135 136 HRESULT MFContentProtectionManager::SetCDMProxy(MFCDMProxy* aCDMProxy) { 137 MOZ_ASSERT(aCDMProxy); 138 mCDMProxy = aCDMProxy; 139 ComPtr<ABI::Windows::Media::Protection::IMediaProtectionPMPServer> pmpServer; 140 RETURN_IF_FAILED(mCDMProxy->GetPMPServer(IID_PPV_ARGS(&pmpServer))); 141 RETURN_IF_FAILED(SetPMPServer(pmpServer.Get())); 142 return S_OK; 143 } 144 145 HRESULT MFContentProtectionManager::SetPMPServer( 146 ABI::Windows::Media::Protection::IMediaProtectionPMPServer* aPMPServer) { 147 MOZ_ASSERT(aPMPServer); 148 149 ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable*>> 150 serverMap; 151 RETURN_IF_FAILED(mPMPServerSet.As(&serverMap)); 152 153 // MFMediaEngine uses |serverKey| to get the Protected Media Path (PMP) 154 // server used for playing protected content. This is not currently documented 155 // in MSDN. 156 boolean replaced = false; 157 ScopedHString serverKey{L"Windows.Media.Protection.MediaProtectionPMPServer"}; 158 RETURN_IF_FAILED(serverMap->Insert(serverKey.Get(), aPMPServer, &replaced)); 159 return S_OK; 160 } 161 162 void MFContentProtectionManager::Shutdown() { mCDMProxy = nullptr; } 163 164 #undef LOG 165 166 } // namespace mozilla