Strategy to merge a vendor WDF driver with Directshow (WDM) example

I have a vendor supplied PCIe driver that performs DMA from card to system memory, written in WDF (Window Driver Foundation) model. I would like to merge this driver’s code with Microsoft Directshow sample driver, AVSHWS so that I can capture video from card and playback on screen using any Directshow players. But this Directshow sample is written using WDM model.

When I simply copy the source code from Directshow driver into PCIe driver, it compiles successfully. However, it crashes Windows 10 when driver is installed.

Anyone can advise how to combine these 2 drivers?

Thanks in advance,

wtneo

I am guessing the DirectShow driver is using a port + miniport driver model (portcls or avstream, i can never remember). If that is true, the port driver is taking over the request dispatching and “fighting” with WDF which is trying to do the same. One solution is to use WDF in miniport mode. This allows you to reuse the DMA code, but you need to remove the WDFQUEUE and IO processing logic and in the WDM/avstream IO processing functions, call into the DMA object.

1 Like

Right. AVStream is a port/miniport model. The driver calls into AVStream in DriverEntry (KsInitializeDevice), and it then handles all the dispatching. WDF in miniport mode is the right answer.

1 Like

Thanks Doron and Tim. In that case I nee to learn what is miniport then. Still new to Windows driver.

After some struggle I am still unable to start merge my PCIe WDF driver into AVStream as a miniport driver. Microsoft documents seems to target NDIS which I find it different from my needs. Also, it reads more like a reference guide than a tutorial.

So I still don’t know where to insert my WdfDriverCreate, EvtDevicePrepareHardware etc :cry: .
Are there other online instruction that can I can refer? Or a better Microsoft example that I may have missed?

You call WdfDriverCreate in DriverEntry. You put a callback to EvtDevicePrepareHardware in your device add callback. If you are mixing models, then you want to implement the WDF driver as a miniport driver (options to WdfDriverCreate) which means it would not have a EvtDevicePrepareHardware callback. The sysvad sample driver is an example of a non-NDIS driver that is both a WDF miniport driver and a different kind of driver (an audio portcls driver). It calls WdfDriverCreate in DriverEntry.

If you really have both a PCIe WDF driver and an AVStream driver, maybe you are better off having two separate drivers: one for PCIe WDF driver, one for AVStream and the AVStream driver communicates with the PCIe WDF driver.