MFPMPHostWrapper.cpp (2876B)
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 "MFPMPHostWrapper.h" 6 7 #include "MFMediaEngineUtils.h" 8 #include "WMF.h" 9 #include "mozilla/EMEUtils.h" 10 11 namespace mozilla { 12 13 using Microsoft::WRL::ComPtr; 14 15 #define LOG(msg, ...) EME_LOG("MFPMPHostWrapper=%p, " msg, this, ##__VA_ARGS__) 16 17 HRESULT MFPMPHostWrapper::RuntimeClassInitialize( 18 Microsoft::WRL::ComPtr<IMFPMPHost>& aHost) { 19 mPMPHost = aHost; 20 return S_OK; 21 } 22 23 MFPMPHostWrapper::MFPMPHostWrapper() { 24 MOZ_COUNT_CTOR(MFPMPHostWrapper); 25 LOG("MFPMPHostWrapper created"); 26 } 27 28 MFPMPHostWrapper::~MFPMPHostWrapper() { 29 MOZ_COUNT_DTOR(MFPMPHostWrapper); 30 LOG("MFPMPHostWrapper destroyed"); 31 }; 32 33 STDMETHODIMP MFPMPHostWrapper::LockProcess() { 34 LOG("LockProcess"); 35 return mPMPHost->LockProcess(); 36 } 37 38 STDMETHODIMP MFPMPHostWrapper::UnlockProcess() { 39 LOG("UnlockProcess"); 40 return mPMPHost->UnlockProcess(); 41 } 42 43 STDMETHODIMP MFPMPHostWrapper::ActivateClassById(LPCWSTR aId, IStream* aStream, 44 REFIID aRiid, 45 void** aActivatedClass) { 46 LOG("ActivateClassById, id=%ls", aId); 47 ComPtr<IMFAttributes> creationAttributes; 48 RETURN_IF_FAILED(wmf::MFCreateAttributes(&creationAttributes, 2)); 49 RETURN_IF_FAILED(creationAttributes->SetString(GUID_ClassName, aId)); 50 51 if (aStream) { 52 STATSTG statstg; 53 RETURN_IF_FAILED( 54 aStream->Stat(&statstg, STATFLAG_NOOPEN | STATFLAG_NONAME)); 55 nsTArray<uint8_t> streamBlob; 56 streamBlob.SetLength(statstg.cbSize.LowPart); 57 unsigned long readSize = 0; 58 RETURN_IF_FAILED( 59 aStream->Read(&streamBlob[0], streamBlob.Length(), &readSize)); 60 RETURN_IF_FAILED(creationAttributes->SetBlob(GUID_ObjectStream, 61 &streamBlob[0], readSize)); 62 } 63 64 ComPtr<IStream> outputStream; 65 RETURN_IF_FAILED(CreateStreamOnHGlobal(nullptr, TRUE, &outputStream)); 66 RETURN_IF_FAILED(wmf::MFSerializeAttributesToStream(creationAttributes.Get(), 67 0, outputStream.Get())); 68 RETURN_IF_FAILED(outputStream->Seek({}, STREAM_SEEK_SET, nullptr)); 69 70 ComPtr<IMFActivate> activator; 71 RETURN_IF_FAILED(mPMPHost->CreateObjectByCLSID( 72 CLSID_EMEStoreActivate, outputStream.Get(), IID_PPV_ARGS(&activator))); 73 RETURN_IF_FAILED(activator->ActivateObject(aRiid, aActivatedClass)); 74 if (aActivatedClass) { 75 LOG("Get class %p for id=%ls", *aActivatedClass, aId); 76 } else { 77 LOG("No class for id=%ls", aId); 78 } 79 LOG("Done ActivateClassById, id=%ls", aId); 80 return S_OK; 81 } 82 83 void MFPMPHostWrapper::Shutdown() { 84 LOG("Shutdown"); 85 if (mPMPHost) { 86 mPMPHost = nullptr; 87 } 88 } 89 90 #undef LOG 91 92 } // namespace mozilla