Packet-based DMA in AVStream
Packet-based direct memory access (DMA) occurs when your minidriver reads data directly from and writes data directly to capture buffers received from user mode. The AVStream Simulated Hardware Sample Driver (AVSHwS) in the MSDN Code Gallery demonstrates how to build an AVStream minidriver that performs this type of DMA.
To implement a packet-based DMA scheme:
Specify KSPIN_FLAG_GENERATE_MAPPINGS in the Flags member of relevant KSPIN_DESCRIPTOR_EX structures. Note that this flag should only be used by a bus master with scatter/gather support.
Register an interrupt service routine (ISR) as described in Writing AVStream Minidrivers for Hardware.
Then in the AVStrMiniDeviceStart start dispatch:
Set up a DMA adapter object using IoGetDmaAdapter.
Register the DMA adapter object with AVStream by calling KsDeviceRegisterAdapterObject.
The minidriver specifies the maximum size for a single scatter/gather mapping by providing a MaxMappingByteCount parameter in the call to KsDeviceRegisterAdapterObject.
If any scatter/gather mapping exceeds this maximum size, AVStream automatically breaks the mapping into several scatter/gather mappings, each of which is no larger than the size specified in MaxMappingByteCount.
You must also provide an AVStrMiniPinProcess callback routine. The driver writer should choose appropriate functionality for this callback. As one example, you could do the following:
Clone the leading edge by calling KsStreamPointerClone.
Program DMA hardware based on the clone.
Repeat from step 2 as needed for additional frames.
When the hardware interrupts for DMA completion, the kernel calls the ISR that the vendor has previously registered. In the ISR, the minidriver queues a deferred procedure call (DPC).
Alternatively, the DPC could advance the clone pointer if only part of the frame is completed. To do this, call KsStreamPointerAdvanceOffsets.
If necessary to resume processing, call KsPinAttemptProcessing.
Note that if a mapping is less than one physical page in length, it is not guaranteed to reside on a single physical page.