Handling KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE on avscamera DMFT#1325
Handling KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE on avscamera DMFT#1325welljeng wants to merge 10 commits intomicrosoft:mainfrom
Conversation
…ng behavior on camera DMFT.
| } | ||
| done: | ||
| return hr; | ||
| return S_OK; |
There was a problem hiding this comment.
If source device return failed on the following, hr won't hold S_OK here. I would assume if source device returned failed, but the DMFT itself supports the KsEvent, it should reply OK.
There was a problem hiding this comment.
The issue is with style there is multiple exit points in this new function while the rest of the code has single exit point I would keep the styling the same as the rest of the code
| && (pEvent->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE)) | ||
| { | ||
|
|
||
| m_hSelectedProfileKSEvent = nullptr; |
| FALSE, | ||
| DUPLICATE_SAME_ACCESS) == false) | ||
| { | ||
| return E_INVALIDARG; |
| if (pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE) | ||
| { | ||
| DMFTCHECKHR_GOTO(ProfilePropertyHandler(pProperty, ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned), done); | ||
| goto done; |
| } | ||
| if (m_isProfileDDISupportedInBaseDriver.value_or(true)) | ||
| { | ||
| m_hSelectedProfileKSEventSentToDriver = CreateEventExW( |
| UNREFERENCED_PARAMETER(ulPropertyLength); | ||
| HRESULT hr = S_OK; | ||
|
|
||
| if (pProperty->Flags & KSPROPERTY_TYPE_SET) |
| @@ -1293,6 +1371,102 @@ IFACEMETHODIMP CMultipinMft::Shutdown( | |||
| return ShutdownEventGenerator(); | |||
There was a problem hiding this comment.
Need to handle canceling event and outstanding controls in shutdown
There was a problem hiding this comment.
Referring to the doc. above, extended profile is not cancelable.
| <ClCompile> | ||
| <PreprocessorDefinitions>%(PreprocessorDefinitions);UNICODE;MF_WPP;SECURITY_WIN32;MFT_UNIQUE_METHOD_NAMES;MF_DEVICEMFT_ALLOW_MFT0_LOAD</PreprocessorDefinitions> | ||
| <AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories);..\..\common;..\common</AdditionalIncludeDirectories> | ||
| <LanguageStandard>stdcpp17</LanguageStandard> |
| } | ||
| SetEvent(m_hSelectedProfileKSEvent); | ||
| m_hSelectedProfileKSEvent = nullptr; | ||
| } |
There was a problem hiding this comment.
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.
|
|
||
| /// PDMFT only cares about ExtendedCameraControls, all others | ||
| /// are just blindly forwarded to the upstream DMFTs. | ||
| if (!IsEqualCLSID(pProperty->Set, KSPROPERTYSETID_ExtendedCameraControl)) |
| PWCHAR m_SymbolicLink; | ||
| HANDLE m_hSelectedProfileKSEvent; | ||
| HANDLE m_hSelectedProfileKSEventSentToDriver; | ||
| std::optional<bool> m_isProfileDDISupportedInBaseDriver; |
There was a problem hiding this comment.
We don't want drivers querying static info if they are shipped with specific HW if this changes dynamically it is probably a bug
|
|
||
| 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 |
There was a problem hiding this comment.
The constant is removed due to migrate to MFPutWaitingWorkItem instead of blocking wait.
| // TODO: required to avoid bug OS bug 36971659 in extended property handling that introduces a 16 bytes cookie | ||
| typedef struct | ||
| { | ||
| //byte cookieBuffer[16]; |
| 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; | ||
|
|
| pvPropertyData, | ||
| ulDataLength, | ||
| pulBytesReturned),done); | ||
| if (pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE) |
There was a problem hiding this comment.
if (pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE)
This is incorrect. You're only checking against the Id. The combination should always be Set + Id to determine the control.
In this particular case, you're going to intercept any control whose Id is 34 regardless of whether that Id belongs to the KSPROPERTYSETID_ExtendedCameraControl or not. I think what you meant to do here is to intercept and call ProfilePropertyHandler only if the Set == KSPROPERTYSETID_ExtendedCameraControl && Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE.
|
|
||
| m_selectedProfileId.Type = pProfile->ProfileId; | ||
| m_selectedProfileId.Index = pProfile->Index; | ||
| m_selectedProfileId.Unused = pProfile->Reserved; |
There was a problem hiding this comment.
This information is never forwarded to the driver so the SentToDriver event will never signal.
2. On event handling, removed blocking wait, use MFPutWaitingWorkItem instead.
| KSCAMERA_EXTENDEDPROP_HEADER header; | ||
| } KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED, * PKSCAMERA_EXTENDEDPROP_HEADER_BUFFERED; | ||
|
|
||
| // |
There was a problem hiding this comment.
Remove it is defined in ksmedia.h which should be already included
| } | ||
|
|
||
| HRESULT CMultipinMft::ProfileAsyncResultCallback(_In_ IMFAsyncResult* pResult) | ||
| { |
| wil::unique_event_nothrow m_hSelectedProfileKSEventSentToDriver; | ||
| std::optional<bool> m_isProfileDDISupportedInBaseDriver; | ||
| SENSORPROFILEID m_selectedProfileId; | ||
| MFAsyncCallback<CMultipinMft>m_profileCallback; |
There was a problem hiding this comment.
This code is going to break if parent class goes away
| ulDataLength, | ||
| pBytesReturned), done); | ||
| // handle the event if it is to set profile | ||
| if (pEvent != nullptr |
There was a problem hiding this comment.
what happens if this gets called twice before the first completes?
| hr = m_spIkscontrol->KsEvent(pEvent, | ||
| ulEventLength, | ||
| pEventData, | ||
| ulDataLength, | ||
| pBytesReturned); | ||
| DMFTCHECKHR_GOTO(hr, done); |
There was a problem hiding this comment.
| hr = m_spIkscontrol->KsEvent(pEvent, | |
| ulEventLength, | |
| pEventData, | |
| ulDataLength, | |
| pBytesReturned); | |
| DMFTCHECKHR_GOTO(hr, done); | |
| DMFTCHECKHR_GOTO(m_spIkscontrol->KsEvent(pEvent, ulEventLength, pEventData, ulDataLength, pBytesReturned), done); |
| hr = m_hSelectedProfileKSEventSentToDriver.create(); | ||
| DMFTCHECKHR_GOTO(hr, done); |
There was a problem hiding this comment.
DMFTCHECKHR_GOTO(m_hSelectedProfileKSEventSentToDriver.create(), done);
| 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.
this code will show success while actually failing
| { | ||
| hr = m_hSelectedProfileKSEventSentToDriver.create(); | ||
| DMFTCHECKHR_GOTO(hr, done); | ||
| KSEVENTDATA driverEventData = {}; |
There was a problem hiding this comment.
Missing size and data from original call
| @@ -1039,14 +1058,57 @@ IFACEMETHODIMP CMultipinMft::KsEvent( | |||
| Implements IKSProperty::KsEvent function. | |||
There was a problem hiding this comment.
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.
| done: | ||
| DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr); | ||
| return hr; | ||
| } CATCH_RETURN() |
There was a problem hiding this comment.
Catch returns are only needed on the external com interfaces since the caller cannot not handle exceptions from external module.
| pEventData, | ||
| ulDataLength, | ||
| pBytesReturned); | ||
| DMFTCHECKHR_GOTO(hr, done); |
There was a problem hiding this comment.
[](http://example.com/codeflow?start=0&length=2)
remove tabs

In avscamera DMFT, its KsEvent and KsProperty functions handle KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE property to allow DMFT to behave appropriately in response of various camera streaming profile selected.