KsPinGetLeadingEdgeStreamPointer
2025-04-16
18
0
对于pin-center的ks架构,KsPinGetLeadingEdgeStreamPointer用于获取pin关联队列的前导流指针。
对于pin的数组结构组成由KSPPROCESSPIPESECTION组成。
KSDDKAPI
PKSSTREAM_POINTER
NTAPI
KsPinGetLeadingEdgeStreamPointer(
IN PKSPIN Pin,
IN KSSTREAM_POINTER_STATE State
)
{
PKSPPROCESSPIPESECTION pipeSection = CONTAINING_RECORD(Pin,KSPIN_EXT,Public)->ProcessPin->PipeSection;
PKSPSTREAM_POINTER result = NULL;
if (pipeSection && pipeSection->Queue)
{
result = pipeSection->Queue->GetLeadingStreamPointer(State);
}
return result ? &result->Public : NULL;
}
GetLeadingStreamPointer的实现如下:
CKsQueue::
GetLeadingStreamPointer(
IN KSSTREAM_POINTER_STATE State
)
{
if ((State == KSSTREAM_POINTER_STATE_LOCKED) && !LockStreamPointer(m_Leading))
{
return NULL;
}
return m_Leading;
}
在CKsQueue队列中,头指针由m_Leading成员保留。
class CKsQueue:
public IKsQueue,
public CBaseUnknown
{
PKSPSTREAM_POINTER m_Leading;
PKSPSTREAM_POINTER m_Trailing;
}
关于m_Leading
在CKsQueue::Init时,会创建
status = CreateStreamPointer(&m_Leading);
if (NT_SUCCESS(status) && (Flags & KSPIN_FLAG_DISTINCT_TRAILING_EDGE)) {
status = CreateStreamPointer(&m_Trailing);
}
CKsQueue::CreateStreamPointer的原理就比较简单,就是申请内存空间并初始化。
NTSTATUS
CKsQueue::
CreateStreamPointer(
OUT PKSPSTREAM_POINTER* StreamPointer
)
{
NTSTATUS status;
PKSPSTREAM_POINTER streamPointer = (PKSPSTREAM_POINTER) ExAllocatePoolWithTag(NonPagedPool,sizeof(KSPSTREAM_POINTER),POOLTAG_STREAMPOINTER);
if (streamPointer)
{
//InterlockedIncrement(&m_StreamPointersPlusOne);
RtlZeroMemory(streamPointer,sizeof(KSPSTREAM_POINTER));
streamPointer->State = KSPSTREAM_POINTER_STATE_UNLOCKED;//默认未锁定
streamPointer->Type = KSPSTREAM_POINTER_TYPE_NORMAL; //非内部
streamPointer->Stride = m_MappingTableStride;
streamPointer->Queue = this;
streamPointer->Public.Pin = m_MasterPin;
if (m_InputData) {
streamPointer->Public.Offset = &streamPointer->Public.OffsetIn;
} else {
streamPointer->Public.Offset = &streamPointer->Public.OffsetOut;
}
*StreamPointer = streamPointer;
status = STATUS_SUCCESS;
} else {
status = STATUS_INSUFFICIENT_RESOURCES;
}
return status;
}