From 68cc5fa78e1c7cdf8841bee497594d0478b15033 Mon Sep 17 00:00:00 2001 From: Frank Cheng Date: Wed, 24 Sep 2025 14:18:02 +0800 Subject: [PATCH 1/3] Handling KsEvent, KSCAMERAPROFILE_FaceAuth_Mode for different streaming behavior on camera DMFT. --- avstream/avscamera/DMFT/AvsCameraDMFT.cpp | 185 ++++++++++++++++-- avstream/avscamera/DMFT/AvsCameraDMFT.h | 21 ++ avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj | 12 ++ .../DMFT/AvsCameraDMFT.vcxproj.Filters | 3 + avstream/avscamera/DMFT/packages.config | 2 +- 5 files changed, 208 insertions(+), 15 deletions(-) diff --git a/avstream/avscamera/DMFT/AvsCameraDMFT.cpp b/avstream/avscamera/DMFT/AvsCameraDMFT.cpp index e12cff652..e0417769b 100644 --- a/avstream/avscamera/DMFT/AvsCameraDMFT.cpp +++ b/avstream/avscamera/DMFT/AvsCameraDMFT.cpp @@ -6,6 +6,14 @@ #ifdef MF_WPP #include "AvsCameraDMFT.tmh" //--REF_ANALYZER_DONT_REMOVE-- #endif + +// TODO: required to avoid bug OS bug 36971659 in extended property handling that introduces a 16 bytes cookie +typedef struct +{ + //byte cookieBuffer[16]; + KSCAMERA_EXTENDEDPROP_HEADER header; +} KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED, * PKSCAMERA_EXTENDEDPROP_HEADER_BUFFERED; + // // This DeviceMFT is a stripped down implementation of the device MFT Sample present in the sample Repo // The original DMFT is present at https://github.com/microsoft/Windows-driver-samples/tree/main/avstream/sampledevicemft @@ -29,6 +37,7 @@ CMultipinMft::CMultipinMft() DMFTCHECKHR_GOTO(pAttributes->SetUINT32( MF_SA_D3D_AWARE, TRUE ), done); DMFTCHECKHR_GOTO(pAttributes->SetString( MFT_ENUM_HARDWARE_URL_Attribute, L"SampleMultiPinMft" ),done); m_spAttributes = pAttributes; + m_selectedProfileId = { KSCAMERAPROFILE_Legacy, 0, 0 }; done: DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr); } @@ -638,6 +647,10 @@ IFACEMETHODIMP CMultipinMft::ProcessInput( goto done; } + if (m_selectedProfileId.Type == KSCAMERAPROFILE_FaceAuth_Mode) + { + // DMFT might switch to different behavior when profile, KSCAMERAPROFILE_FaceAuth_Mode is selected. + } DMFTCHECKHR_GOTO(spInPin->SendSample( pSample ), done ); done: DMFTRACE( DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr ); @@ -990,13 +1003,23 @@ IFACEMETHODIMP CMultipinMft::KsProperty( --*/ { HRESULT hr = S_OK; + + /// PDMFT only cares about ExtendedCameraControls, all others + /// are just blindly forwarded to the upstream DMFTs. + if (!IsEqualCLSID(pProperty->Set, KSPROPERTYSETID_ExtendedCameraControl)) + { + DMFTCHECKHR_GOTO(m_spIkscontrol->KsProperty(pProperty, ulPropertyLength, pvPropertyData, + ulDataLength, pulBytesReturned), done); + goto done; + } - DMFTCHECKHR_GOTO(m_spIkscontrol->KsProperty(pProperty, - ulPropertyLength, - pvPropertyData, - ulDataLength, - pulBytesReturned),done); + if (pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE) + { + DMFTCHECKHR_GOTO(ProfilePropertyHandler(pProperty, ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned), done); + goto done; + } done: + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr); return hr; } @@ -1040,15 +1063,53 @@ IFACEMETHODIMP CMultipinMft::KsEvent( --*/ { - HRESULT hr = S_OK; - // Handle the events here if you want, This sample passes the events to the driver - DMFTCHECKHR_GOTO(m_spIkscontrol->KsEvent(pEvent, - ulEventLength, - pEventData, - ulDataLength, - pBytesReturned), done); -done: - return hr; + //HRESULT hr = S_OK; + // handle the event if it is to set profile + if (pEvent != nullptr + && ulEventLength >= sizeof(KSEVENT) + && pEvent->Set == KSEVENTSETID_ExtendedCameraControl + && pEventData != nullptr + && ulDataLength >= sizeof(KSEVENTDATA) + && (pEvent->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE)) + { + + m_hSelectedProfileKSEvent.reset(); + RETURN_IF_WIN32_BOOL_FALSE(DuplicateHandle( + GetCurrentProcess(), + ((KSEVENTDATA*)(pEventData))->EventHandle.Event, + GetCurrentProcess(), + &m_hSelectedProfileKSEvent, + 0, + FALSE, + DUPLICATE_SAME_ACCESS)); + + if (m_isProfileDDISupportedInBaseDriver.value_or(true)) + { + RETURN_IF_FAILED(m_hSelectedProfileKSEventSentToDriver.create()); + KSEVENTDATA driverEventData = {}; + driverEventData.NotificationType = KSEVENTF_EVENT_HANDLE; + driverEventData.EventHandle.Event = m_hSelectedProfileKSEventSentToDriver.get(); + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Handling profile set KsEvent, created profile KsEvent handle for driver: %p", m_hSelectedProfileKSEventSentToDriver.get()); + + // defer to source device + auto hr = m_spIkscontrol->KsEvent(pEvent, ulEventLength, (void*)(&driverEventData), ulDataLength, pBytesReturned); + if (FAILED(hr)) + { + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Failed to send profile KsEvent handle to driver: %p | hr=0x%08x", m_hSelectedProfileKSEventSentToDriver.get(), hr); + m_hSelectedProfileKSEventSentToDriver.reset(); + m_isProfileDDISupportedInBaseDriver = false; + } + } + } + else { + // Pass the events to the driver + RETURN_IF_FAILED(m_spIkscontrol->KsEvent(pEvent, + ulEventLength, + pEventData, + ulDataLength, + pBytesReturned)); + } + return S_OK; } // @@ -1293,6 +1354,102 @@ IFACEMETHODIMP CMultipinMft::Shutdown( return ShutdownEventGenerator(); } +/*++ +Description: +Implements the KsProperty KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE handler. +--*/ + +HRESULT CMultipinMft::ProfilePropertyHandler( + _In_reads_bytes_(ulPropertyLength) PKSPROPERTY pProperty, + _In_ ULONG ulPropertyLength, + _In_ LPVOID pPropertyData, + _In_ ULONG ulDataLength, + _Inout_ PULONG pulBytesReturned) try +{ + + UNREFERENCED_PARAMETER(ulPropertyLength); + HRESULT hr = S_OK; + + if (pProperty->Flags & KSPROPERTY_TYPE_SET) + { + DMFTCHECKNULL_GOTO(pulBytesReturned, done, E_POINTER); + *pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED) + sizeof(KSCAMERA_EXTENDEDPROP_PROFILE); + if (ulDataLength < *pulBytesReturned) + { + return HRESULT_FROM_WIN32(ERROR_MORE_DATA); + } + if (pPropertyData) + { + + PBYTE pPayload = (PBYTE)pPropertyData; + PKSCAMERA_EXTENDEDPROP_HEADER pExtendedHeader = &((PKSCAMERA_EXTENDEDPROP_HEADER_BUFFERED)pPayload)->header; + KSCAMERA_EXTENDEDPROP_PROFILE* pProfile = (PKSCAMERA_EXTENDEDPROP_PROFILE)(pExtendedHeader + 1); + + m_selectedProfileId.Type = pProfile->ProfileId; + m_selectedProfileId.Index = pProfile->Index; + m_selectedProfileId.Unused = pProfile->Reserved; + + if (m_selectedProfileId.Type == GUID_NULL) + { + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_WARNING, "The caller incorrectly sets GUID_NULL, default back to legacy."); + m_selectedProfileId = { KSCAMERAPROFILE_Legacy, 0, 0 }; + } + + // signal we are done + if (m_hSelectedProfileKSEvent.get() != nullptr) + { + if (m_hSelectedProfileKSEventSentToDriver != nullptr) + { + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Waiting for driver profile KsEvent handle: %p", m_hSelectedProfileKSEventSentToDriver.get()); + if (!m_hSelectedProfileKSEventSentToDriver.wait(kMAX_WAIT_TIME_DRIVER_PROFILE_KSEVENT)) + { + + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_ERROR, + "Waiting for driver profile KsEvent handle: %p timed out after %i ms, failing", + m_hSelectedProfileKSEventSentToDriver.get(), + kMAX_WAIT_TIME_DRIVER_PROFILE_KSEVENT); + m_hSelectedProfileKSEvent.SetEvent(); + RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_TIMEOUT)); + } + m_hSelectedProfileKSEventSentToDriver.reset(); + } + m_hSelectedProfileKSEvent.SetEvent(); + m_hSelectedProfileKSEvent.reset(); + } + } + } + else if (pProperty->Flags & KSPROPERTY_TYPE_GET) + { + DMFTCHECKNULL_GOTO(pulBytesReturned, done, E_POINTER); + *pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED) + sizeof(KSCAMERA_EXTENDEDPROP_PROFILE); + if (ulDataLength < *pulBytesReturned) + { + return HRESULT_FROM_WIN32(ERROR_MORE_DATA); + } + if (pPropertyData) + { + if (!m_isProfileDDISupportedInBaseDriver.has_value()) + { + hr = m_spIkscontrol->KsProperty(pProperty, ulPropertyLength, pPropertyData, ulDataLength, pulBytesReturned); + m_isProfileDDISupportedInBaseDriver = SUCCEEDED(hr); + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Profile DDI GET support on base driver: %d, hr=0x%08x", m_isProfileDDISupportedInBaseDriver.value(), hr); + *pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED) + sizeof(KSCAMERA_EXTENDEDPROP_PROFILE); + } + } + } + // --GETPAYLOAD-- + else if (pProperty->Flags & KSPROPERTY_TYPE_GETPAYLOADSIZE) + { + RETURN_HR_IF_NULL(E_POINTER, pulBytesReturned); + *pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED) + sizeof(PKSCAMERA_EXTENDEDPROP_PROFILE); + } + +done: + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr); + return hr; +} CATCH_RETURN() + + // // Static method to create an instance of the MFT. // diff --git a/avstream/avscamera/DMFT/AvsCameraDMFT.h b/avstream/avscamera/DMFT/AvsCameraDMFT.h index 27b8607b5..3c51571af 100644 --- a/avstream/avscamera/DMFT/AvsCameraDMFT.h +++ b/avstream/avscamera/DMFT/AvsCameraDMFT.h @@ -7,6 +7,10 @@ #include "mftpeventgenerator.h" #include "basepin.h" +#include +#include +#include + // // The Below GUID is needed to transfer photoconfirmation sample successfully in the pipeline // It is used to propagate the mediatype of the sample to the pipeline which will consume the sample @@ -19,6 +23,8 @@ DEFINE_GUID(MFSourceReader_SampleAttribute_MediaType_priv, interface IDirect3DDeviceManager9; +constexpr int kMAX_WAIT_TIME_DRIVER_PROFILE_KSEVENT = 3000;// ms, amount of time to wait for the profile DDI KsEvent sent to the driver + // // Forward declarations // @@ -275,9 +281,18 @@ class CMultipinMft : _In_opt_ IMFMediaType *pMediaType, _In_ DeviceStreamState newState ); + HRESULT BridgeInputPinOutputPin( _In_ CInPin* pInPin, _In_ COutPin* pOutPin); + + HRESULT ProfilePropertyHandler( + _In_reads_bytes_(ulPropertyLength) PKSPROPERTY pProperty, + _In_ ULONG ulPropertyLength, + _Inout_updates_to_(ulDataLength, *pulBytesReturned) LPVOID pPropertyData, + _In_ ULONG ulDataLength, + _Inout_ PULONG pulBytesReturned); + // //Inline functions // @@ -320,8 +335,14 @@ class CMultipinMft : UINT32 m_punValue; ComPtr m_spIkscontrol; ComPtr m_spAttributes; + map m_outputPinMap; // How output pins are connected to input pins i-><0..outpins> PWCHAR m_SymbolicLink; + wil::unique_event_nothrow m_hSelectedProfileKSEvent; + wil::unique_event_nothrow m_hSelectedProfileKSEventSentToDriver; + std::optional m_isProfileDDISupportedInBaseDriver; + SENSORPROFILEID m_selectedProfileId; + }; diff --git a/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj b/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj index 3f6180f26..a27ea60d0 100644 --- a/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj +++ b/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj @@ -162,6 +162,7 @@ %(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD $(IntDir);%(AdditionalIncludeDirectories);..\..\common;..\common + stdcpp17 %(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD @@ -178,6 +179,7 @@ %(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD $(IntDir);%(AdditionalIncludeDirectories);..\..\common;..\common + stdcpp17 %(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD @@ -194,6 +196,7 @@ %(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD $(IntDir);%(AdditionalIncludeDirectories);..\..\common;..\common + stdcpp17 %(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD @@ -210,6 +213,7 @@ %(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD $(IntDir);%(AdditionalIncludeDirectories);..\..\common;..\common + stdcpp17 %(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD @@ -237,6 +241,7 @@ + @@ -247,4 +252,11 @@ + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj.Filters b/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj.Filters index c3679c843..854d9e635 100644 --- a/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj.Filters +++ b/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj.Filters @@ -54,4 +54,7 @@ Header Files + + + \ No newline at end of file diff --git a/avstream/avscamera/DMFT/packages.config b/avstream/avscamera/DMFT/packages.config index 26065b144..d690ede8a 100644 --- a/avstream/avscamera/DMFT/packages.config +++ b/avstream/avscamera/DMFT/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From bc6eda8cc2497829a8c5f14ced38195b80c4a1a2 Mon Sep 17 00:00:00 2001 From: Frank Cheng Date: Thu, 25 Sep 2025 04:21:10 +0800 Subject: [PATCH 2/3] Remove Wil dependancy from AvsCameraDMFT.vcxproj to fix CI/CD issue. --- avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj | 7 ------- 1 file changed, 7 deletions(-) diff --git a/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj b/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj index a27ea60d0..7970a1d77 100644 --- a/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj +++ b/avstream/avscamera/DMFT/AvsCameraDMFT.vcxproj @@ -252,11 +252,4 @@ - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file From 93a14884c8a54775766b1ad41b7f0d20db7331d8 Mon Sep 17 00:00:00 2001 From: Frank Cheng Date: Thu, 25 Sep 2025 11:45:54 +0800 Subject: [PATCH 3/3] Eliminate WIL dependancy on AvsCameraDMFT.h/cpp. --- avstream/avscamera/DMFT/AvsCameraDMFT.cpp | 73 ++++++++++++++--------- avstream/avscamera/DMFT/AvsCameraDMFT.h | 7 +-- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/avstream/avscamera/DMFT/AvsCameraDMFT.cpp b/avstream/avscamera/DMFT/AvsCameraDMFT.cpp index e0417769b..0e36af0d0 100644 --- a/avstream/avscamera/DMFT/AvsCameraDMFT.cpp +++ b/avstream/avscamera/DMFT/AvsCameraDMFT.cpp @@ -26,8 +26,11 @@ CMultipinMft::CMultipinMft() m_lWorkQueuePriority ( 0 ), m_spAttributes( nullptr ), m_spSourceTransform( nullptr ), - m_SymbolicLink(nullptr) - + m_SymbolicLink(nullptr), + m_hSelectedProfileKSEvent { nullptr }, + m_hSelectedProfileKSEventSentToDriver { nullptr}, + m_isProfileDDISupportedInBaseDriver{}, + m_selectedProfileId { KSCAMERAPROFILE_Legacy, 0, 0 } { HRESULT hr = S_OK; ComPtr pAttributes = nullptr; @@ -37,7 +40,7 @@ CMultipinMft::CMultipinMft() DMFTCHECKHR_GOTO(pAttributes->SetUINT32( MF_SA_D3D_AWARE, TRUE ), done); DMFTCHECKHR_GOTO(pAttributes->SetString( MFT_ENUM_HARDWARE_URL_Attribute, L"SampleMultiPinMft" ),done); m_spAttributes = pAttributes; - m_selectedProfileId = { KSCAMERAPROFILE_Legacy, 0, 0 }; + done: DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr); } @@ -1063,7 +1066,7 @@ IFACEMETHODIMP CMultipinMft::KsEvent( --*/ { - //HRESULT hr = S_OK; + HRESULT hr = S_OK; // handle the event if it is to set profile if (pEvent != nullptr && ulEventLength >= sizeof(KSEVENT) @@ -1073,42 +1076,56 @@ IFACEMETHODIMP CMultipinMft::KsEvent( && (pEvent->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE)) { - m_hSelectedProfileKSEvent.reset(); - RETURN_IF_WIN32_BOOL_FALSE(DuplicateHandle( + m_hSelectedProfileKSEvent = nullptr; + if (DuplicateHandle( GetCurrentProcess(), ((KSEVENTDATA*)(pEventData))->EventHandle.Event, GetCurrentProcess(), &m_hSelectedProfileKSEvent, 0, FALSE, - DUPLICATE_SAME_ACCESS)); - + DUPLICATE_SAME_ACCESS) == false) + { + return E_INVALIDARG; + } if (m_isProfileDDISupportedInBaseDriver.value_or(true)) { - RETURN_IF_FAILED(m_hSelectedProfileKSEventSentToDriver.create()); + m_hSelectedProfileKSEventSentToDriver = CreateEventExW( + nullptr, + nullptr, + 0, + EVENT_ALL_ACCESS); + + DMFTCHECKNULL_GOTO(m_hSelectedProfileKSEventSentToDriver, done, E_INVALIDARG); + KSEVENTDATA driverEventData = {}; driverEventData.NotificationType = KSEVENTF_EVENT_HANDLE; - driverEventData.EventHandle.Event = m_hSelectedProfileKSEventSentToDriver.get(); - DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Handling profile set KsEvent, created profile KsEvent handle for driver: %p", m_hSelectedProfileKSEventSentToDriver.get()); + driverEventData.EventHandle.Event = m_hSelectedProfileKSEventSentToDriver; + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Handling profile set KsEvent, created profile KsEvent handle for driver: %p", m_hSelectedProfileKSEventSentToDriver); // defer to source device - auto hr = m_spIkscontrol->KsEvent(pEvent, ulEventLength, (void*)(&driverEventData), ulDataLength, pBytesReturned); + hr = m_spIkscontrol->KsEvent(pEvent, ulEventLength, (void*)(&driverEventData), ulDataLength, pBytesReturned); if (FAILED(hr)) { - DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Failed to send profile KsEvent handle to driver: %p | hr=0x%08x", m_hSelectedProfileKSEventSentToDriver.get(), hr); - m_hSelectedProfileKSEventSentToDriver.reset(); + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Failed to send profile KsEvent handle to driver: %p | hr=0x%08x", m_hSelectedProfileKSEventSentToDriver, hr); + m_hSelectedProfileKSEventSentToDriver = nullptr; m_isProfileDDISupportedInBaseDriver = false; } } } else { // Pass the events to the driver - RETURN_IF_FAILED(m_spIkscontrol->KsEvent(pEvent, + hr = m_spIkscontrol->KsEvent(pEvent, ulEventLength, pEventData, ulDataLength, - pBytesReturned)); + pBytesReturned); + if FAILED(hr) + { + return hr; + } } +done: return S_OK; } @@ -1364,7 +1381,7 @@ HRESULT CMultipinMft::ProfilePropertyHandler( _In_ ULONG ulPropertyLength, _In_ LPVOID pPropertyData, _In_ ULONG ulDataLength, - _Inout_ PULONG pulBytesReturned) try + _Inout_ PULONG pulBytesReturned) { UNREFERENCED_PARAMETER(ulPropertyLength); @@ -1396,25 +1413,25 @@ HRESULT CMultipinMft::ProfilePropertyHandler( } // signal we are done - if (m_hSelectedProfileKSEvent.get() != nullptr) + if (m_hSelectedProfileKSEvent != nullptr) { if (m_hSelectedProfileKSEventSentToDriver != nullptr) { - DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Waiting for driver profile KsEvent handle: %p", m_hSelectedProfileKSEventSentToDriver.get()); - if (!m_hSelectedProfileKSEventSentToDriver.wait(kMAX_WAIT_TIME_DRIVER_PROFILE_KSEVENT)) + DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Waiting for driver profile KsEvent handle: %p", m_hSelectedProfileKSEventSentToDriver); + if ( WaitForSingleObjectEx(m_hSelectedProfileKSEventSentToDriver, kMAX_WAIT_TIME_DRIVER_PROFILE_KSEVENT, FALSE) != WAIT_OBJECT_0) { DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_ERROR, "Waiting for driver profile KsEvent handle: %p timed out after %i ms, failing", - m_hSelectedProfileKSEventSentToDriver.get(), + m_hSelectedProfileKSEventSentToDriver, kMAX_WAIT_TIME_DRIVER_PROFILE_KSEVENT); - m_hSelectedProfileKSEvent.SetEvent(); - RETURN_IF_FAILED(HRESULT_FROM_WIN32(ERROR_TIMEOUT)); + SetEvent(m_hSelectedProfileKSEvent); + return HRESULT_FROM_WIN32(ERROR_TIMEOUT); } - m_hSelectedProfileKSEventSentToDriver.reset(); + m_hSelectedProfileKSEventSentToDriver = nullptr; } - m_hSelectedProfileKSEvent.SetEvent(); - m_hSelectedProfileKSEvent.reset(); + SetEvent(m_hSelectedProfileKSEvent); + m_hSelectedProfileKSEvent = nullptr; } } } @@ -1440,14 +1457,14 @@ HRESULT CMultipinMft::ProfilePropertyHandler( // --GETPAYLOAD-- else if (pProperty->Flags & KSPROPERTY_TYPE_GETPAYLOADSIZE) { - RETURN_HR_IF_NULL(E_POINTER, pulBytesReturned); + DMFTCHECKNULL_GOTO(pulBytesReturned, done, E_POINTER); *pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED) + sizeof(PKSCAMERA_EXTENDEDPROP_PROFILE); } done: DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr); return hr; -} CATCH_RETURN() +} // diff --git a/avstream/avscamera/DMFT/AvsCameraDMFT.h b/avstream/avscamera/DMFT/AvsCameraDMFT.h index 3c51571af..7de644d1b 100644 --- a/avstream/avscamera/DMFT/AvsCameraDMFT.h +++ b/avstream/avscamera/DMFT/AvsCameraDMFT.h @@ -6,9 +6,6 @@ #include "common.h" #include "mftpeventgenerator.h" #include "basepin.h" - -#include -#include #include // @@ -338,8 +335,8 @@ class CMultipinMft : map m_outputPinMap; // How output pins are connected to input pins i-><0..outpins> PWCHAR m_SymbolicLink; - wil::unique_event_nothrow m_hSelectedProfileKSEvent; - wil::unique_event_nothrow m_hSelectedProfileKSEventSentToDriver; + HANDLE m_hSelectedProfileKSEvent; + HANDLE m_hSelectedProfileKSEventSentToDriver; std::optional m_isProfileDDISupportedInBaseDriver; SENSORPROFILEID m_selectedProfileId;