Step 1: Learn about Windows architecture and drivers
AVStream:
AVStream is a Microsoft-provided multimedia class driver that supportsvideo-only streaming and integrated audio/video streaming. Microsoft providesAVStream as part of the operating system, in the export driver Ks.sys.Hardware vendors write minidrivers that run under Ks.sys.
The preferred class driver for audio drivers is the Microsoft-providedaudio port class driver. Audio vendors should write minidrivers that run under Portcls.sys.
Microsoft supports the stream class driver only for existing minidrivers.
AVStream drivers build on Microsoft Windows XP, Microsoft WindowsServer 2003, or any platform Windows 98 Gold or later version thathas DirectX 8.0 or later version installed.
If you build on an operating system earlier than Windows XP, make surethat you use the latest available DirectX Driver Development Kit (DDK). DirectX9.0 contains updates for AVStream, kernel streaming components, and streamclass.
AVStream offers significant advantages to the vendor by:
- Requiring minidriver writers to produce less code.
- Providing a unified kernel streaming class model for both audio and video minidrivers.
- Providing support for vendors to write user-mode plug-ins. These are COM interfaces that provide methods to access property values. You can provide plug-ins without altering existing minidriver binaries. For more information, see Kernel Streaming Proxy Plug-ins.
In the AVStream driver model, vendors provide a minidriver that interactswith a Microsoft-provided class driver, as shown in the following diagram:
Relationship Between AVStream and KS Services
All kernel streaming andAVStream reference material covers structures and functions that are declaredin ks.h. This is the header that the minidriver must include in order toaccess the Microsoft-supplied KS and AVStream class driver support.
An AVStream minidriver describes itself and the filter types itsupports by providing nested descriptor structures in the call toKsInitializeDriver. Each key component — the device, the filter factory, andthe pin factory — has an associated descriptor.
As shown in AVStream Object Hierarchy, the highest leveldescriptor for an AVStream minidriver is the device descriptor,KSDEVICE_DESCRIPTOR.
In the device descriptor, the FilterDescriptors member points toan array of KSFILTER_DESCRIPTOR structures that describe the types of filtersthis device can create. AVStream clients can call KsCreateFilterFactory todynamically add filter factories.
A KSFILTER_DESCRIPTOR indicates how many pin types the filtersupports, the KS categories under which the filter is to be registered, and thetopology of the filter. Inside each filter descriptor, the minidriver providesa pointer to an array of KSPIN_DESCRIPTOR_EX structures. Each of these pindescriptors describes a pin type that this filter can instantiate. You cancreate additional pin factories by calling KsFilterCreatePinFactory.
Typically, AVStream minidrivers lay out static descriptor tablesin their source and call KsInitializeDriver to perform the setup work. For moreinformation about initializing your driver, see Initializing an AVStreamMinidriver.
There are other types of descriptors as well, such as the nodedescriptor KSNODE_DESCRIPTOR, which describes a given topology node.
The dispatch table is common to each of the three maindescriptor types. See AVStream Dispatch Tables.
The AVStream dispatch table, KSDEVICE_DISPATCH,is a set of function pointers to dispatch functions. A minidriver can extendthe behavior provided by AVStream by providing callback routines that performdriver-specific tasks.
These minidriver-provided routines receive notifications ofcertain events and may extend or modify the default event handling provided byAVStream.
Both KSFILTER_DISPATCHand KSPIN_DISPATCHstructures provide a dispatch called Process. Use this dispatch todifferentiate a filter-centricfilter from a pin-centricfilter.To specify a filter-centric filter, supply a pointer to a processdispatch callback routine in the filter dispatch table. A pin-centric filterprovides a process dispatch in each of the pin descriptor tables.
You can register filters to be notified about creations,deletions, the need to process data, and resets. You can register pins to benotified of events such as creations, closure, the need to process data,resets, setting of data formats, and state changes. To register objects fornotification, supply a pointer to a vendor-supplied dispatch routine in therelevant dispatch structure.
For more information about dispatch functions, see KSFILTER_DISPATCH,KSPIN_DISPATCH,and KSALLOCATOR_DISPATCH.
链接地址Initializing an AVStream Minidriver
An AVStream minidriver that does not handle device initialization on itsown calls KsInitializeDriver from theminidriver's DriverEntry routine. KsInitializeDriverinitializes the driver object of an AVStream driver, in addition to IRPdispatching, PnP add device messages, and unloading.
In calling KsInitializeDriver, the minidriver passes a pointer tothe driver object to initialize a pointer to the registry path, and optionally,a device descriptor object. Note that passing the KSDEVICE_DESCRIPTOR object isnot required. If the minidriver does pass a device descriptor, AVStream createsa device with the specified characteristics at AddDevice time.
The device descriptor object contains a pointer to a KSDEVICE_DISPATCH structure as wellas an array of filter descriptors. Provide a KSFILTER_DESCRIPTOR for eachfilter type that your minidriver supports. When the minidriver calls KsInitializeDriver, AVStreamcreates a filter factory object for each type of filter exposed by theminidriver. Individual filters are then instantiated by the filter factory uponreceipt of a create IRP for the associated create item. Each filter descriptorcontains a pointer to an array of KSPIN_DESCRIPTOR_EX objects.AVStream creates a pin factory on the relevant filter for each type of pin theminidriver exposes through that filter.
When a connection is made to a given pi n type on a filter, the AVStreampin factory creates a pin object. Note that each filter must expose at leastone pin. The minidriver uses the InstancesNecessary member ofKSPIN_DESCRIPTOR_EX to identify the number of instances of this pin type thatare necessary for the filter to function correctly. Similarly, the minidrivercan impose a maximum on the number of pins that the pin factory can instantiateby using the InstancesPossible member of this structure.
AVStream supports two types of processing: filter-centric processing, and pin-centric processing. Whenlaying out the descriptors, decide which type of processing each filter typewill perform.
链接地址Installing an AVStream Minidriver
An AVStream minidriver must have an INF file that the system uses toinstall the driver. An AVStream INF file is based on the common INF format,which is described in Creating an INF File. You canalso refer to the INF files supplied with AVStream sample drivers in the WindowsDriver Kit (WDK). Keep in mind the following AVStream-specific guidelines.
If you are writing a minidriver for a parent device, the AddRegsection of your INF file should contain:
[ParentName.AddReg]
HKR,"ENUM\[DeviceName]",pnpid,,"[string]"
If you are writing a minidriver for a child device, the AddRegsection should contain:
[Manufacturer]
...=ChildName
[ChildName]
...=ChildName.Device,AVStream\[string]
Note that "AVStream" would be "Stream" for a streamclass driver.
For all AVStream minidrivers, the filter-specific reference string in theINF file must match the ReferenceGuid member of the KSFILTER_DESCRIPTOR structure.
For more information about descriptors, see AVStream Descriptors.
链接地址Pin-Centric Processing
When writing an AVStream minidriver, you provide filters that use one oftwo processing paradigms: pin-centric processing or filter-centric processing.
Pin-centric processing means that AVStream calls the minidriver's pinprocess dispatch routine when new frames arrive in the pin queue.
Filter-centric processing means that AVStream calls the minidriver'sfilter process dispatch routine when there are data frames available on eachinstantiated pin. Note that these definitions specify default behavior;minidrive