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

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

<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


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

// 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 jiteshkris and a team 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.

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