Skip to content

Conversation

@welljeng
Copy link

@welljeng welljeng commented Sep 24, 2025

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.

@welljeng welljeng changed the title Handling KsEvent, KSCAMERAPROFILE_FaceAuth_Mode for different streami… Handling KSCAMERAPROFILE_FaceAuth_Mode on avscamera DMFT Sep 25, 2025
@welljeng welljeng changed the title Handling KSCAMERAPROFILE_FaceAuth_Mode on avscamera DMFT Handling KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE on avscamera DMFT Sep 25, 2025
@welljeng welljeng marked this pull request as ready for review September 25, 2025 18:02
@welljeng welljeng requested a review from a team as a code owner September 25, 2025 18:02
}
done:
return hr;
return S_OK;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S_OK

return hr

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

https://github.com/welljeng/Windows-driver-samples/blob/4a380c3ff93f2227e40865cb472638954b3c31a1/avstream/avscamera/DMFT/AvsCameraDMFT.cpp#L1107

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_hSelectedProfileKSEvent

use WIL handle object looks like this code leaks handles

@chrilaMSFT
Copy link

IFACEMETHODIMP CMultipinMft::KsEvent(

no lock?


Refers to: avstream/avscamera/DMFT/AvsCameraDMFT.cpp:1055 in 4a380c3. [](commit_id = 4a380c3, deletion_comment = False)

FALSE,
DUPLICATE_SAME_ACCESS) == false)
{
return E_INVALIDARG;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return E_INVALIDARG;

match coding style of the rest of the code with macro checks

if (pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE)
{
DMFTCHECKHR_GOTO(ProfilePropertyHandler(pProperty, ulPropertyLength, pvPropertyData, ulDataLength, pulBytesReturned), done);
goto done;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: only use goto for error case

}
if (m_isProfileDDISupportedInBaseDriver.value_or(true))
{
m_hSelectedProfileKSEventSentToDriver = CreateEventExW(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_hSelectedProfileKSEventSentToDriver

use WIL event

UNREFERENCED_PARAMETER(ulPropertyLength);
HRESULT hr = S_OK;

if (pProperty->Flags & KSPROPERTY_TYPE_SET)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check size

// Deref on the connected outpins to break reference loop
(VOID)pInPin->ShutdownPin();
}
return ShutdownEventGenerator();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to handle canceling event and outstanding controls in shutdown

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stdcpp17

I would recommend minimizing the $(Configuration)|$(Platform) unique configs move the common ones to a global setting

}
SetEvent(m_hSelectedProfileKSEvent);
m_hSelectedProfileKSEvent = nullptr;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait should not block

Choose a reason for hiding this comment

The 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.


/// PDMFT only cares about ExtendedCameraControls, all others
/// are just blindly forwarded to the upstream DMFTs.
if (!IsEqualCLSID(pProperty->Set, KSPROPERTYSETID_ExtendedCameraControl))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsEqualCLSID

requires a lock

PWCHAR m_SymbolicLink;
HANDLE m_hSelectedProfileKSEvent;
HANDLE m_hSelectedProfileKSEventSentToDriver;
std::optional<bool> m_isProfileDDISupportedInBaseDriver;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_isProfileDDISupportedInBaseDriver

this should be a static property of the DMFT since it ideally is developed with the camera/driver it is being used with

Copy link
Author

@welljeng welljeng Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am hesitate of make it static since if the same DMFT is being applied on multiple camera DMFT chain, all the DMFT instances will share the same m_isProfileDDISupportedInBaseDriver value, which might not be the ideal case.
Correct me if I were wong.

image

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kMAX_WAIT_TIME_DRIVER_PROFILE_KSEVENT

I think pipeline should handle max wait

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented out code

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: remove

@chrilaMSFT chrilaMSFT requested review from a team and jiteshkris September 25, 2025 21:26
pvPropertyData,
ulDataLength,
pulBytesReturned),done);
if (pProperty->Id == KSPROPERTY_CAMERACONTROL_EXTENDED_PROFILE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent poinnt!!


m_selectedProfileId.Type = pProfile->ProfileId;
m_selectedProfileId.Index = pProfile->Index;
m_selectedProfileId.Unused = pProfile->Reserved;

Choose a reason for hiding this comment

The 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.

Frank Cheng and others added 3 commits October 1, 2025 14:29
2. On event handling, removed blocking wait, use MFPutWaitingWorkItem
   instead.
KSCAMERA_EXTENDEDPROP_HEADER header;
} KSCAMERA_EXTENDEDPROP_HEADER_BUFFERED, * PKSCAMERA_EXTENDEDPROP_HEADER_BUFFERED;

//

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

}

HRESULT CMultipinMft::ProfileAsyncResultCallback(_In_ IMFAsyncResult* pResult)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No lock?

wil::unique_event_nothrow m_hSelectedProfileKSEventSentToDriver;
std::optional<bool> m_isProfileDDISupportedInBaseDriver;
SENSORPROFILEID m_selectedProfileId;
MFAsyncCallback<CMultipinMft>m_profileCallback;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if this gets called twice before the first completes?

Comment on lines +1105 to +1110
hr = m_spIkscontrol->KsEvent(pEvent,
ulEventLength,
pEventData,
ulDataLength,
pBytesReturned);
DMFTCHECKHR_GOTO(hr, done);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hr = m_spIkscontrol->KsEvent(pEvent,
ulEventLength,
pEventData,
ulDataLength,
pBytesReturned);
DMFTCHECKHR_GOTO(hr, done);
DMFTCHECKHR_GOTO(m_spIkscontrol->KsEvent(pEvent, ulEventLength, pEventData, ulDataLength, pBytesReturned), done);

Comment on lines +1087 to +1088
hr = m_hSelectedProfileKSEventSentToDriver.create();
DMFTCHECKHR_GOTO(hr, done);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code will show success while actually failing

{
hr = m_hSelectedProfileKSEventSentToDriver.create();
DMFTCHECKHR_GOTO(hr, done);
KSEVENTDATA driverEventData = {};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing size and data from original call

/*++
Description:
Implements IKSProperty::KsEvent function.

Choose a reason for hiding this comment

The 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.

done:
DMFTRACE(DMFT_GENERAL, TRACE_LEVEL_INFORMATION, "%!FUNC! exiting %x = %!HRESULT!", hr, hr);
return hr;
} CATCH_RETURN()

Choose a reason for hiding this comment

The 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.

pEventData,
ulDataLength,
pBytesReturned);
DMFTCHECKHR_GOTO(hr, done);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   [](http://example.com/codeflow?start=0&length=2)

remove tabs

@chrilaMSFT chrilaMSFT requested review from LPBourret and removed request for SangChoe October 17, 2025 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants