-
Notifications
You must be signed in to change notification settings - Fork 5k
Handling KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE on avscamera DMFT #1325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
68cc5fa
bc6eda8
93a1488
4a380c3
0960a1e
4ff5b33
efb9311
9ce1c2f
984a42b
0f0734b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,13 @@ | |||||||||||||||
| #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 | ||||||||||||||||
| { | ||||||||||||||||
| 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 | ||||||||||||||||
|
|
@@ -18,8 +25,13 @@ 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 }, | ||||||||||||||||
| m_profileCallback {this, &CMultipinMft::ProfileAsyncResultCallback }, | ||||||||||||||||
| m_profileAsyncResult {nullptr} | ||||||||||||||||
| { | ||||||||||||||||
| HRESULT hr = S_OK; | ||||||||||||||||
| ComPtr<IMFAttributes> pAttributes = nullptr; | ||||||||||||||||
|
|
@@ -637,7 +649,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 +1005,17 @@ IFACEMETHODIMP CMultipinMft::KsProperty( | |||||||||||||||
| --*/ | ||||||||||||||||
| { | ||||||||||||||||
| HRESULT hr = S_OK; | ||||||||||||||||
|
|
||||||||||||||||
| DMFTCHECKHR_GOTO(m_spIkscontrol->KsProperty(pProperty, | ||||||||||||||||
| ulPropertyLength, | ||||||||||||||||
| pvPropertyData, | ||||||||||||||||
| ulDataLength, | ||||||||||||||||
| pulBytesReturned),done); | ||||||||||||||||
| if (pProperty->Set == KSPROPERTYSETID_ExtendedCameraControl && pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE) | ||||||||||||||||
| { | ||||||||||||||||
| DMFTCHECKHR_GOTO(ProfilePropertyHandler(pProperty, ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned), done); | ||||||||||||||||
| } | ||||||||||||||||
| else | ||||||||||||||||
| { | ||||||||||||||||
| DMFTCHECKHR_GOTO(m_spIkscontrol->KsProperty(pProperty, ulPropertyLength, pvPropertyData, | ||||||||||||||||
| ulDataLength, pulBytesReturned), done); | ||||||||||||||||
| } | ||||||||||||||||
| done: | ||||||||||||||||
| DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr); | ||||||||||||||||
| return hr; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -1039,14 +1058,57 @@ IFACEMETHODIMP CMultipinMft::KsEvent( | |||||||||||||||
| Implements IKSProperty::KsEvent function. | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to handle the event? It complicates the sample, I would just grab the control set it would make the change a lot smaller. |
||||||||||||||||
| --*/ | ||||||||||||||||
| { | ||||||||||||||||
|
|
||||||||||||||||
| CAutoLock Lock(m_critSec); | ||||||||||||||||
| 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); | ||||||||||||||||
| // handle the event if it is to set profile | ||||||||||||||||
| if (pEvent != nullptr | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if this gets called twice before the first completes? |
||||||||||||||||
| && ulEventLength >= sizeof(KSEVENT) | ||||||||||||||||
| && pEvent->Set == KSEVENTSETID_ExtendedCameraControl | ||||||||||||||||
| && pEventData != nullptr | ||||||||||||||||
| && ulDataLength >= sizeof(KSEVENTDATA) | ||||||||||||||||
| && (pEvent->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE)) | ||||||||||||||||
| { | ||||||||||||||||
|
|
||||||||||||||||
| m_hSelectedProfileKSEvent.reset(); | ||||||||||||||||
| if (DuplicateHandle( | ||||||||||||||||
| GetCurrentProcess(), | ||||||||||||||||
| ((KSEVENTDATA*)(pEventData))->EventHandle.Event, | ||||||||||||||||
| GetCurrentProcess(), | ||||||||||||||||
| &m_hSelectedProfileKSEvent, | ||||||||||||||||
| 0, | ||||||||||||||||
| FALSE, | ||||||||||||||||
| DUPLICATE_SAME_ACCESS) == false) | ||||||||||||||||
| { | ||||||||||||||||
| hr = E_INVALIDARG; | ||||||||||||||||
| DMFTCHECKHR_GOTO(hr, done); | ||||||||||||||||
| } | ||||||||||||||||
| if (m_isProfileDDISupportedInBaseDriver.value_or(true)) | ||||||||||||||||
| { | ||||||||||||||||
| hr = m_hSelectedProfileKSEventSentToDriver.create(); | ||||||||||||||||
| DMFTCHECKHR_GOTO(hr, done); | ||||||||||||||||
|
Comment on lines
+1087
to
+1088
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DMFTCHECKHR_GOTO(m_hSelectedProfileKSEventSentToDriver.create(), done); |
||||||||||||||||
| KSEVENTDATA driverEventData = {}; | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing size and data from original call |
||||||||||||||||
| 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 | ||||||||||||||||
| HRESULT hr2 = m_spIkscontrol->KsEvent(pEvent, ulEventLength, (void*)(&driverEventData), ulDataLength, pBytesReturned); | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code will show success while actually failing |
||||||||||||||||
| if (FAILED(hr2)) | ||||||||||||||||
| { | ||||||||||||||||
| 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 | ||||||||||||||||
| hr = m_spIkscontrol->KsEvent(pEvent, | ||||||||||||||||
| ulEventLength, | ||||||||||||||||
| pEventData, | ||||||||||||||||
| ulDataLength, | ||||||||||||||||
| pBytesReturned); | ||||||||||||||||
| DMFTCHECKHR_GOTO(hr, done); | ||||||||||||||||
|
Comment on lines
+1105
to
+1110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
remove tabs |
||||||||||||||||
| } | ||||||||||||||||
| done: | ||||||||||||||||
| return hr; | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -1293,6 +1355,111 @@ IFACEMETHODIMP CMultipinMft::Shutdown( | |||||||||||||||
| return ShutdownEventGenerator(); | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to handle canceling event and outstanding controls in shutdown
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referring to the doc. above, extended profile is not cancelable. |
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /*++ | ||||||||||||||||
| Description: | ||||||||||||||||
| Implements the KsProperty KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE handler. | ||||||||||||||||
| --*/ | ||||||||||||||||
|
|
||||||||||||||||
| HRESULT CMultipinMft::ProfilePropertyHandler( | ||||||||||||||||
| _In_reads_bytes_(ulPropertyLength) PKSPROPERTY pProperty, | ||||||||||||||||
| _In_ ULONG ulPropertyLength, | ||||||||||||||||
| _Inout_updates_to_(ulDataLength, *pulBytesReturned) LPVOID pPropertyData, | ||||||||||||||||
| _In_ ULONG ulDataLength, | ||||||||||||||||
| _Inout_ PULONG pulBytesReturned) try | ||||||||||||||||
| { | ||||||||||||||||
| UNREFERENCED_PARAMETER(ulPropertyLength); | ||||||||||||||||
| HRESULT hr = S_OK; | ||||||||||||||||
| CAutoLock Lock(m_critSec); | ||||||||||||||||
| if (pProperty->Flags & KSPROPERTY_TYPE_SET) | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check size |
||||||||||||||||
| { | ||||||||||||||||
| DMFTCHECKNULL_GOTO(pulBytesReturned, done, E_POINTER); | ||||||||||||||||
| *pulBytesReturned = sizeof(KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED) + sizeof(KSCAMERA_EXTENDEDPROP_PROFILE); | ||||||||||||||||
| if (ulDataLength < *pulBytesReturned) | ||||||||||||||||
| { | ||||||||||||||||
| DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done); | ||||||||||||||||
| } | ||||||||||||||||
| 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; | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This information is never forwarded to the driver so the SentToDriver event will never signal. |
||||||||||||||||
|
|
||||||||||||||||
| 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 }; | ||||||||||||||||
| } | ||||||||||||||||
| // if we should relay this SET call down to base driver | ||||||||||||||||
| if (m_isProfileDDISupportedInBaseDriver.value_or(true)) | ||||||||||||||||
| { | ||||||||||||||||
| hr = m_spIkscontrol->KsProperty(pProperty, ulPropertyLength, pPropertyData, ulDataLength, pulBytesReturned); | ||||||||||||||||
| // if base camera does not support the provided profile, set the base camera ksevent right away in case it did accept it so that we don't await it later on | ||||||||||||||||
| if (FAILED(hr)) | ||||||||||||||||
| { | ||||||||||||||||
| DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_WARNING, "Failed Profile DDI SET, base camera hr=0x%08x", hr); | ||||||||||||||||
| if (m_hSelectedProfileKSEventSentToDriver != nullptr) | ||||||||||||||||
| { | ||||||||||||||||
| DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Completing driver profile KsEvent handle: %p", m_hSelectedProfileKSEventSentToDriver.get()); | ||||||||||||||||
| m_hSelectedProfileKSEventSentToDriver.SetEvent(); | ||||||||||||||||
| m_hSelectedProfileKSEventSentToDriver.reset(); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| // signal we are done | ||||||||||||||||
| // Queue an MF work item which will get invoked when the event is fired | ||||||||||||||||
| DMFTCHECKNULL_GOTO(m_hSelectedProfileKSEvent, done, E_POINTER); | ||||||||||||||||
| if (m_hSelectedProfileKSEventSentToDriver != nullptr) | ||||||||||||||||
| { | ||||||||||||||||
| m_profileAsyncResult.Reset(); | ||||||||||||||||
| DMFTCHECKHR_GOTO(MFCreateAsyncResult(nullptr, &m_profileCallback, nullptr, &m_profileAsyncResult), done); | ||||||||||||||||
| //KSCAMERAPROFILE is not cancelable. Not need to track MFWORKITEM_KEY | ||||||||||||||||
| DMFTCHECKHR_GOTO(MFPutWaitingWorkItem(m_hSelectedProfileKSEventSentToDriver.get(), 0, m_profileAsyncResult.Get(), nullptr), done); | ||||||||||||||||
| } | ||||||||||||||||
| else | ||||||||||||||||
| { | ||||||||||||||||
| // if the profile set event was not sent to the driver, we can set our event right away | ||||||||||||||||
| DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "Completing profile KsEvent handle: %p", m_hSelectedProfileKSEvent.get()); | ||||||||||||||||
| m_hSelectedProfileKSEvent.SetEvent(); | ||||||||||||||||
| m_hSelectedProfileKSEvent.reset(); | ||||||||||||||||
| } | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait should not block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using MFPutWaitingWorkItem to signal the m_hSelectedProfileKSEvent (using m_hSelectedProfileKSEventSentToDriver as the event handle to the API in question). This doesn't afford you the ability to use a timeout, but the spec requires drivers to signal the event both in the case of success or if the operation can't complete. |
||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| 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) | ||||||||||||||||
| { | ||||||||||||||||
| DMFTCHECKHR_GOTO(HRESULT_FROM_WIN32(ERROR_MORE_DATA), done); | ||||||||||||||||
| } | ||||||||||||||||
| 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) | ||||||||||||||||
| { | ||||||||||||||||
| 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() | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catch returns are only needed on the external com interfaces since the caller cannot not handle exceptions from external module. |
||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| // | ||||||||||||||||
| // Static method to create an instance of the MFT. | ||||||||||||||||
| // | ||||||||||||||||
|
|
@@ -1309,3 +1476,21 @@ HRESULT CMultipinMft::CreateInstance(REFIID iid, void **ppMFT) | |||||||||||||||
| DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr); | ||||||||||||||||
| return hr; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| HRESULT CMultipinMft::ProfileAsyncResultCallback(_In_ IMFAsyncResult* pResult) | ||||||||||||||||
| { | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No lock? |
||||||||||||||||
| HRESULT hr = S_OK; | ||||||||||||||||
| if (FAILED(pResult->GetStatus())) | ||||||||||||||||
| { | ||||||||||||||||
| DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_ERROR, | ||||||||||||||||
| "Waiting for driver profile KsEvent handle: %p timed out, failing", | ||||||||||||||||
| m_hSelectedProfileKSEventSentToDriver.get()); | ||||||||||||||||
| m_hSelectedProfileKSEvent.SetEvent(); | ||||||||||||||||
| m_hSelectedProfileKSEvent.reset(); | ||||||||||||||||
| hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT); | ||||||||||||||||
| } | ||||||||||||||||
| m_hSelectedProfileKSEventSentToDriver.reset(); | ||||||||||||||||
| return hr; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove it is defined in ksmedia.h which should be already included