Pin回调DispatchSetFormat
2025-02-26
10
0
对于每个PIN,都可以有一组回调函数KSPIN_DISPATCH:
typedef struct {
PFNKSPINIRP Create;
PFNKSPINIRP Close;
PFNKSPIN Process;
PFNKSPINVOID Reset;
PFNKSPINSETDATAFORMAT SetDataFormat;//设置数据流格式
PFNKSPINSETDEVICESTATE SetDeviceState;
PFNKSPIN Connect;
PFNKSPINVOID Disconnect;
const KSCLOCK_DISPATCH* Clock;
const KSALLOCATOR_DISPATCH* Allocator;
} KSPIN_DISPATCH, *PKSPIN_DISPATCH;
SetDataFormat用于在创建Pin实例时,用于校验之前通过IntersectHandler协商的数据格式是否适用于本KSPIN和与KSDATARANGE相匹配。当动态改变格式时,也会调用此例程。
当动态改变格式时,OldFormat不为空。
比较的参数:
CCapturePin *CapPin = NULL;
if (OldFormat)
{
CapPin = reinterpret_cast <CCapturePin *> (Pin->Context);
}
if (IsEqualGUID (Pin->ConnectionFormat->Specifier,VideoInfoSpecifier)
&& Pin->ConnectionFormat->FormatSize >= sizeof (KS_DATAFORMAT_VIDEOINFOHEADER))
{
PKS_DATAFORMAT_VIDEOINFOHEADER ConnectionFormat = reinterpret_cast <PKS_DATAFORMAT_VIDEOINFOHEADER>(Pin->ConnectionFormat);
const KS_DATARANGE_VIDEO *VIRange = reinterpret_cast <const KS_DATARANGE_VIDEO *>(DataRange);
ULONG VideoHeaderSize = KS_SIZE_VIDEOHEADER(&ConnectionFormat->VideoInfoHeader);
ULONG DataFormatSize = FIELD_OFFSET(KS_DATAFORMAT_VIDEOINFOHEADER, VideoInfoHeader) + VideoHeaderSize;
if (VideoHeaderSize < ConnectionFormat->VideoInfoHeader.bmiHeader.biSize
|| DataFormatSize < VideoHeaderSize
|| DataFormatSize > ConnectionFormat->DataFormat.FormatSize
)
{
Status = STATUS_INVALID_PARAMETER;
}
else if ((ConnectionFormat->VideoInfoHeader.bmiHeader.biWidth != VIRange -> VideoInfoHeader.bmiHeader.biWidth)
||(ConnectionFormat->VideoInfoHeader.bmiHeader.biHeight != VIRange -> VideoInfoHeader.bmiHeader.biHeight)
||(ConnectionFormat->VideoInfoHeader.bmiHeader.biCompression !=VIRange -> VideoInfoHeader.bmiHeader.biCompression)
)
{
Status = STATUS_NO_MATCH;
}
else
{
ULONG ImageSize = ConnectionFormat->VideoInfoHeader.bmiHeader.biWidth
* ConnectionFormat->VideoInfoHeader.bmiHeader.biHeight
* ConnectionFormat->VideoInfoHeader.bmiHeader.biBitCount/8;
if (ConnectionFormat->VideoInfoHeader.bmiHeader.biSizeImage < ImageSize)
{
Status = STATUS_INVALID_PARAMETER;
}
else
{
// We can accept the format.
Status = STATUS_SUCCESS;
//
// OldFormat is an indication that this is a format change.
// Since I do not implement the
// KSPROPERTY_CONNECTION_PROPOSEDATAFORMAT, by default, I do
// not handle dynamic format changes.
//
// If something changes while we're in the stop state, we're
// fine to handle it since we haven't "configured the hardware"
// yet.
//
//在相机运行过程中动态修改参数,这里不支持
if (OldFormat)
{
//
// If we're in the stop state, we can handle just about any
// change. We don't support dynamic format changes.
//
if (Pin -> DeviceState == KSSTATE_STOP)
{
if (!CapPin ->DumpCaptureVideoInfoHeader())
{
Status = STATUS_INSUFFICIENT_RESOURCES;
}
} else {
//
// Because we don't accept dynamic format changes, we
// should never get here. Just being over-protective.
//
Status = STATUS_INVALID_DEVICE_STATE;
}
}
}
}
}