WMFClearKeyInputTrustAuthority.cpp (3587B)
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 "WMFClearKeyInputTrustAuthority.h" 6 7 #include <mfapi.h> 8 #include <mferror.h> 9 10 #include "WMFClearKeyActivate.h" 11 #include "WMFClearKeyCDM.h" 12 // #include "WMFClearKeyDecryptor.h" 13 #include "WMFClearKeyUtils.h" 14 #include "WMFClearKeyOutputPolicy.h" 15 16 namespace mozilla { 17 18 using Microsoft::WRL::ComPtr; 19 using Microsoft::WRL::MakeAndInitialize; 20 21 HRESULT WMFClearKeyInputTrustAuthority::RuntimeClassInitialize( 22 UINT32 aStreamId, SessionManagerWrapper* aSessionManager) { 23 ENTRY_LOG(); 24 mSessionManager = aSessionManager; 25 return S_OK; 26 } 27 28 STDMETHODIMP WMFClearKeyInputTrustAuthority::GetDecrypter(REFIID aRiid, 29 void** aPpv) { 30 ENTRY_LOG(); 31 ComPtr<IMFTransform> decryptor; 32 // TODO : As currently we are still not able to make decryption working in the 33 // media foundation pipeline, we will finish the implementation for 34 // WMFClearKeyDecryptor later. 35 // RETURN_IF_FAILED((MakeAndInitialize<WMFClearKeyDecryptor, IMFTransform>( 36 // &decryptor, mSessionManager))); 37 RETURN_IF_FAILED(decryptor.CopyTo(aRiid, aPpv)); 38 return S_OK; 39 } 40 41 STDMETHODIMP WMFClearKeyInputTrustAuthority::RequestAccess( 42 MFPOLICYMANAGER_ACTION aAction, IMFActivate** aContentEnablerActivate) { 43 ENTRY_LOG_ARGS("aAction=%d", aAction); 44 // The ITA only allows the PLAY, EXTRACT and NO actions 45 // NOTE: Topology created only on the basis of EXTRACT or NO action will NOT 46 // decrypt content. 47 if (PEACTION_EXTRACT == aAction || PEACTION_NO == aAction) { 48 return S_OK; 49 } 50 if (PEACTION_PLAY != aAction) { 51 ENTRY_LOG_ARGS("Unsupported action"); 52 return MF_E_ITA_UNSUPPORTED_ACTION; 53 } 54 ComPtr<IMFActivate> activate; 55 RETURN_IF_FAILED(MakeAndInitialize<WMFClearKeyActivate>(&activate)); 56 *aContentEnablerActivate = activate.Detach(); 57 return S_OK; 58 } 59 60 STDMETHODIMP WMFClearKeyInputTrustAuthority::GetPolicy( 61 MFPOLICYMANAGER_ACTION aAction, IMFOutputPolicy** aPolicy) { 62 ENTRY_LOG(); 63 // For testing purpose, we don't need to set the output policy/ 64 *aPolicy = nullptr; 65 return S_OK; 66 } 67 68 STDMETHODIMP WMFClearKeyInputTrustAuthority::BindAccess( 69 MFINPUTTRUSTAUTHORITY_ACCESS_PARAMS* aParams) { 70 ENTRY_LOG(); 71 if (aParams == nullptr || aParams->dwVer != 0) { 72 return E_INVALIDARG; 73 } 74 for (DWORD i = 0; i < aParams->cActions; ++i) { 75 MFPOLICYMANAGER_ACTION action = aParams->rgOutputActions[i].Action; 76 if (action != PEACTION_PLAY && action != PEACTION_EXTRACT && 77 action != PEACTION_NO) { 78 ENTRY_LOG_ARGS("Unexpected action!"); 79 return MF_E_UNEXPECTED; 80 } 81 } 82 return S_OK; 83 } 84 85 STDMETHODIMP WMFClearKeyInputTrustAuthority::UpdateAccess( 86 MFINPUTTRUSTAUTHORITY_ACCESS_PARAMS* aParams) { 87 ENTRY_LOG(); 88 return BindAccess(aParams); 89 } 90 91 STDMETHODIMP WMFClearKeyInputTrustAuthority::Reset() { 92 NOT_IMPLEMENTED(); 93 return E_NOTIMPL; 94 } 95 96 STDMETHODIMP WMFClearKeyInputTrustAuthority::GetShutdownStatus( 97 MFSHUTDOWN_STATUS* aStatus) { 98 ENTRY_LOG(); 99 // https://learn.microsoft.com/en-us/windows/win32/api/mfidl/nf-mfidl-imfshutdown-getshutdownstatus#return-value 100 if (mSessionManager->IsShutdown()) { 101 return MF_E_INVALIDREQUEST; 102 } 103 return S_OK; 104 } 105 106 STDMETHODIMP WMFClearKeyInputTrustAuthority::Shutdown() { 107 ENTRY_LOG(); 108 if (mSessionManager->IsShutdown()) { 109 return MF_E_SHUTDOWN; 110 } 111 mSessionManager->Shutdown(); 112 return S_OK; 113 } 114 115 } // namespace mozilla