All DirectShow filters are user mode software components. In order for a kernel mode hardware device, such as a video capture card, to join a DirectShow filter graph, the device must be represented as a user-mode filter. This function is performed by specialized "wrapper" filters provided with DirectShow. These filters include the Audio Capture filter, the VFW Capture filter, the TV Tuner filter, the TV Audio filter, and the Analog Video Crossbar filter. DirectShow also provides a filter called KsProxy, which can represent any type of Windows Driver Model (WDM) streaming device. Hardware vendors can extend KsProxy to support custom functionality, by providing a Ksproxy plug-in, which is a COM object aggregated by KsProxy.
所有的 DirectShow filter 都是用户模式的组件。像视频采集卡这样的内核模式的硬件设备,如果要加入到 filter graph 中,设备就必须提供用户模式的 filter 。 DirectShow 提供了专门的“ wrapper ” filter 执行这样的功能。 wrapper filter 包括 Audio Capture , VFW Capture , TV Tuner , TV Audio 和 Analog Video Crossbar 。 DirectShow 还提供了叫做 KsProxy 的 filter 来表示 WDM 的流设备。硬件厂商可以通过提供 Ksproxy plug-in 扩展 KsProxy 来支持自定义功能。
The wrapper filters expose COM interfaces that represent the capabilities of the device. The application uses these interfaces to pass information to and from the filter. The filter translates the COM method calls into device driver calls, passes that information to the driver in kernel mode, and then translates the result back to the application. The TV Tuner, TV Audio, Analog Video Crossbar, and KsProxy filters support custom driver properties through the IKsPropertySet interface. The VFW Capture filter and the Audio Capture filter are not extensible in this way.
wrapper filter 暴露展现设备能力的 COM 接口。应用程序使用这些接口发信息到 filter 或者从 filter 得到信息。 filter 把 COM 方式的调用转换成设备驱动方式的调用,把信息传进内核模式的驱动,把转换结果返回给应用程序。 TV Tuner, TV Audio, Analog Video Crossbar, and KsProxy filters 通过 IKsPropertyset 接口支持自定义设备属性。 VFW Capture filter and the Audio Capture filter 不能通过这种方式扩展。
For application developers, wrapper filters enable the application to control devices just as they control any other DirectShow filter. No special programming is required; the details of communicating with the kernel-mode device are encapsulated within the filter.
对于应用程序的开发人员来说, wrapper filters 能够使应用程序像控制其他 DirectShow filter 一样控制设备。不需要特殊的程序,与内核设备通信的细节封装在 filter 里面了。
The VFW Capture filter supports earlier Video for Windows (VfW) capture cards. When a VfW card is present on the target system, it can be discovered and added to the filter graph using the DirectShow System Device Enumerator . For details, see Enumerating Devices and Filters .
VFW Capture filter 支持早期的 VfW 视频采集卡。当在目标系统中发现一个 VfW 卡时,可以使用 DirectShow System Device Enumerator 把它添加到 filter graph 中。
Newer sound cards have input jacks for microphones and other types of devices. Typically these cards also have on-board mixing capabilities for controlling the volume, treble, and bass of each individual input. In DirectShow, the sound card's inputs and mixer are wrapped by the Audio Capture filter. Each sound card can be discovered with the System Device Enumerator. To view the sound cards in your system, run GraphEdit and select from the Audio Capture Sources category. Each filter in that category is a separate instance of the Audio Capture filter. (See Using GraphEdit .)
Newer hardware decoders and capture cards conform to the Windows Driver Model (WDM) specification. These devices have greater functionality than VfW devices and are portable between Windows XP, Windows NT, Windows 2000 and Windows 98/Me. WDM video capture cards can supporting features that are not available under VfW, including the enumeration of capture formats, programmatic control of video parameters such as hue and brightness, programmatic input selection, and TV Tuner support.
新的硬件解码和采集卡遵循 WDM 规范。 WDM 设备比 VfW 设备功能强大,并且能在多系统中使用。 WDM 视频采集卡能支持在 VfW 下无效的特性,包括列举采集格式,编程控制视频参数。
To support WDM streaming devices, DirectShow provides the KsProxy filter (ksproxy.ax). KsProxy has been called the "Swiss Army Knife filter" because it does so many different things. The number of pins on the filter, and the number of COM interfaces exposed by the filter, depend on the capabilities of the underlying driver. KsProxy does not appear in the filter graph under the name "KsProxy." It always takes the friendly name of the device, which is found in the registry. To view the WDM devices on your system, run GraphEdit and select from the WDM Streaming categories. Even if you have only one WDM card on your system, that card might contain more than one device. Each device is represented as a separate filter, and each of these filters is actually KsProxy.
为支持 WDM 流设备, DirectShow 提供了 KsProxy filter 。 KsProxy 被叫做“瑞士军刀 filter ”。 filter 的 pin 的数量, filter 暴露的接口的数据都取决于设备的基本性能。在 filter graph 中, KsProxy 没有以 KsProxy 为名出现。在注册表中可以以设备的 friendly name 找到。运行 GraphEdit 选择 WDM Streaming categories 可以看到系统中的 WDM 设备。即使在系统中只有一块 WDM 卡,这个卡也可能会包含一个以上的设备。一个 separate filter 代表一个设备,每一个这样的 filter 就是一个活动的 KsProxy 。
(注:在 WDM 中, KsProxy 是一类 filter 的称呼。)
An application uses the System Device Enumerator to find WDM device monikers on the system. KsProxy is instantiated by calling BindToObject on the moniker. Because KsProxy can represent all kinds of WDM devices, it must query the driver to determine which property sets the driver supports. Property sets are collections of data structures used by WDM drivers, and also by some user mode filters, such as MPEG-2 software decoders. KsProxy configures itself to expose the COM interfaces that correspond to those property sets. KsProxy translates the COM method calls into property sets and sends these to the driver. Hardware vendors can extend KsProxy by supplying plug-ins, which are vendor-specific interfaces that expose the special capabilities of a device. All these details are hidden from application. The application controls the device by way of KsProxy, in the same way as any other DirectShow filter.
应用程序使用系统设备枚举器来找到系统中的 WDM 设备别名。在设备别名上调用 BindtoObject 函数实例化 KsProxy 。 KsProxy 可以代表所有种类的 WDM 设备,它必须询问驱动来决定驱动支持哪些属性集。属性集是 WDM 驱动使用的数据结构的一个集合,有一些也由用户模式 filter 使用,例如 MPEG-2 解码器。 KsProxy 暴露 COM 接口来配置这些属性集。 KsProxy 把 COM 函数的调用转换为属性集,并把这些属性集发送到驱动中。硬件生产商通过提供 plug-ins 来扩展 KsProxy , plus-ins 是由厂商定义的接口,用来扩展设备的特殊性能。所有这些细节对应用程序都是隐藏的。应用程序通过 KsProxy 控制设备。
WDM devices support kernel streaming, in which data is streamed entirely in kernel mode without ever switching to user mode. Switching between kernel mode and user mode is computationally expensive; kernel streaming allows for high bit rates without burdening the host CPU. WDM-based filters can use kernel streaming to pass multimedia data directly from one hardware device to another, either on the same card or on a different card, without copying the data into the system's main memory.
WDM 设备支持内核流,数据的整个流动都在内核模式下进行,不会被切换到用户模式。在内核模式和用户模式之间切换是非常昂贵的计算;内核流能在不加重 CPU 负担的情况下允许高字节率。基于 WDM 的 filter 可以使用内核流把多媒体数据直接从一个设备传输到另外一个设备,无论是同一个卡还是不同的卡都不要把数据拷贝到系统的内存中。
From an application's point of view, it appears as if the data moves from one user-mode filter to the next. In reality, the data might never pass into user mode at all, but instead might be streamed directly from one kernel-mode device to another until it is rendered on the video graphics card. Some scenarios, such as capture to a file, require that the data pass from kernel mode to user mode at some point. However, this switch does not necessarily require the data to be copied to a new location in memory.
从应用程序的角度看,数据好像是从一个用户模式的 filter 移动到另外一个。实施上,数据根本没有进入过用户模式,数据直接从一个内核设备流到另外一个直到在视频图像卡上显示出来。像把数据采集到文件这样的情况,就要求数据从内核模式流到用户模式。然后,这些交换几乎不需要把数据拷贝到本地新的内存中。
Application developers generally do not need to be concerned with the details of kernel streaming, except as background information. See the Microsoft DDK for more detailed information about WDM, kernel streaming, KsProxy, and related topics.