首页 > 代码库 > 第二十一篇:基?于?W?D?M?模?型?的?A?V?S?t?r?e?a?m?驱?动?架?构?研?究
第二十一篇:基?于?W?D?M?模?型?的?A?V?S?t?r?e?a?m?驱?动?架?构?研?究
基?于?W?D?M?模?型?的?A?V?S?t?r?e?a?m?驱?动?架?构?研?
这篇论文2006年早就发表, 与当时开发这个驱动正好差不多的时间.
最近实际项目需要, 又回过头来将AVStream中的主要框架列举一下.
整个框架由:
KSDevice
KSFilter
KSPin所构成
KSDevice负责了PNP相关的DISPATCH, 如START, STOP, ADD, REMOVE
KSFilter构成软件AVSTREAM设备的DISPATCH, 这就是所谓的FILTER CENTRIC
而KSPin构成实际硬件AVSTREAM设备的DISPATCH, 这就是所谓的PIN CENTRIC
无论哪一种, 都是在这些FILTER/PIN DISPATCH中处理相应的数据流
而每个FILTER都有对应的属性,事件与方法
这就由AUTOMATION TABLE来构建
AUTOMATION TABLE一级级往下分别是: Property Sets/Set/Item, Method Set/Set/Item, Event Set/Set/Item.
举个以前讲过的例子,USB VIDEO CLASS驱动, 它就是一个典型的AVSTREAM架构的AVSTREAM miniport驱动.
相对一个PCTV ATV AVSTREAM miniport驱动需要实现, TUNER, CROSS BAR, CAPTURE, AUDIO这四个FILTER(相应的AUTOMATION TABLE)及其相应的PIN(CAPTURE PIN, PREVIEW PIN, AUDIO OUT PIN),
USB Video相对来讲, 则更加简单一些, 因为, 往往,它只有一个FILTER(以及FILTER上的PROPERTY), 需要实际实现的则是一个CAPTURE PIN(根据 USB DEVICE DESCRIPTOR中的 IT/OUT TERMINALS的描述符来建立相应的PIN 实例)
例如:
这个WDM STREAMING CAPTURE DEVICE FILTER, 在它的PIN上实现了视频数据流的管理,
以及FILTER PROPERTY中对于
VIDEO的属性如, BRIGHTNESS, CONTRAST, HUE, SATURATION, SHARPNESS, GAMMA, WHITE BALANCE BACKLIGHT COMP
CAMERA的属性控制,如ZOOM, FOCUS, EXPOSURE, PAN, APERURE, PAN, TILT, ROLL, LOW LIGHT COMPENSATION.
而这个USB VIDEO CLASS 驱动的难度, 不仅仅在于KSDEVICE, KSFILTER, KSPIN以及DISPATCH, AUTOMATION TABLE的建立
而是根据USB VIDEO DEVICE的DESCRIPTOR中描述的TOPOLOGY动态地建立一张由KSFILTER/KSPIN构成的KS GRAPH, 同时, 在这些KSFILTER/KSPIN中实现相应的属性,事件,方法及它们的DISPATCH.
同时, 需要完成PIN与PIN之间, DATA RANGE, DATA INTERSECTION的处理.
动态地转化过程, 是USB VIDEO CLASS DRIVER的一个主要与重要的部分, 相对较一电视卡的固定GRAPH结构.
也有人对AVSTREAM架构的复杂产生怀疑, 感觉没有必要采用这种框架去实际设备驱动, 但它的好处就在于, 你所实现的设备驱动, 是完全符合DSHOW COM接口的, 可以与市面上所有符合DSHOW的应用程序去配合工作.
这就是微软为什么要设计这样一个复杂的AVSTREAM架构的根本原因.
USB Video Class Implementation
The Microsoft-provided USB Video Class driver (usbvideo.sys) is a pin-centric AVStream minidriver. It creates a filter factory for each USB Video Class–compliant device instance enumerated by the operating system. The driver also creates a pin factory for each input or output terminal on the device, with the DataFlow member of the KSPIN_DESCRIPTOR structure set to the relevant value.
The USB Video Class driver uses the internal device topology reported by the device descriptors to construct a kernel streaming (KS) topology graph comprised of filters, nodes, and connections.
Based on the number and types of controls supported by the device, USB Video Class dynamically reports filter, pin, and node property sets through the KS automation tables in the AVStream filter and pin descriptors.
Based on the data formats supported by each video or still image data endpoint on the device, USB Video Class reports the corresponding list of KS data ranges supported and a data intersection handler in the respective AVStream pin descriptor. The USB Video Class driver exports the information through the Kernel Streaming Proxy module.
The USB Video Class driver also supports audio/video stream synchronization; usbvideo.sys can serve as a KS master clock and add time stamps to video samples. The USB Video Class specification includes details about how the hardware should provide timing information to the class driver.
To communicate with USB Video Class, user-mode clients call DirectShow or Media Foundation interfaces. These interfaces are COM interface wrappers defined by thekernel streaming proxy as plug-ins. See the Microsoft Windows SDK documentation for more information about Media Foundation.