3.2. FILTER GRAPH and its components describe the main components of DirectShow, providing a DirectShow application and DirectShow Filter developers. Application developers can ignore a lot of underlying parts, however, understand the bottom layer is still very helpful for understanding the DirectShow architecture. 3.2.1. About DirectShow Filter DirectShow Using a modular architecture, each processing process is implemented by a COM object called Filter. DirectShow provides a series of standard Filter for the application, and developers can also write their own Filter to extend the functionality of DirectShow. Below is the steps of playing an AVI file: * Read the data from the file and convert a File Source Filter * Check the AVI header, analyze the word stream and separate them into video and audio (AVI Aplitter Filter) * Decoding video (Different Decoding Filter, depending on different compression formats) * Show video rendere file * * DEFAULT DIRECTSOUND DEVICE FILTER
As shown, each Filter is connected to one or more other filters, where the connection point is also a COM object, called the PIN, Filter uses the PIN to transfer the data from one filter to another, the arrow in the figure indicates Direction of data flow. In DirectShow, this series of FILTERs are called Filter Graph. Filter may be in three different states: operation, stop and pause status. Filter processes data when running, stop processing data, and paused status is ready and can begin to enter the running state. In addition to the extreme case, all Filter in a FILTER GRAPH usually handles the same state, so Filter Graph can also be called it in operation, stop, and suspend state. Filter can be divided into several large types: * Source Filter - Filter GRAPH data source, which can come from files, networks, cameras, or anything else. Each Source Filter manipulates different types of data sources. * Transform Filter - Receive data, processing data and feed it into the next filter. Both the encoding filter and decoding Filter belong to this kind. * RENDERER FILTER - Over the Filter chain, accepts data and presents it to the user. For example, a video rendrer draws a video image on the monitor; an audio render is sent to the audio data; a write file filter (file-write filter) puts the data store. * Splitter filter - Analyze the input data stream and break it into two or more, for example, AVI Splitter analyzes the word stream and breaks down into video streams and audio streams. * MUX Filter - Combine multiple input streams into all the way. For example, AVI MUX is just in the opposite work with AVI Splitter, which flows through video and audio into a AVI format byte stream. The above classification is not absolute, for example, Asf Reader Filter acts as a role of Source Filter and Splitter Filter. All DirectShow Filter offers an IBaseFilter interface, and all PINs also provide an IPIN interface. DirectShow also defines a number of other interfaces to achieve specific features.
3.2.2. About Filter Graph Manager Filter Graph Manager is a COM object for controlling Filter in Filter Graph. It provides a number of features, including: * Coordination Filter State Change * Establish a Reference Clock * Returns the event to the application * Provides an application to establish a Filter Graph method here to simply describe one of these features. Status changes: Filter's status changes must follow a specific order, so the application cannot send the status of the status to the filter, but send a simple command to the Filter Graph Manager, by it to send the command to Each filter. The positioning command also uses this way, the application sends a positioning command to the Filter Graph Manager, which is distributed by it. Reference Clock: All filters in Filter Graph use one of the same clock, called a reference clock (Reference Clock). The reference clock guarantees synchronization of all streams. A video frame or a period of audio sample is played as a presentation time. The presentation time is accurately relative to the reference clock. Filter Graph Manager Normally selected reference clock is a sound card reference clock or system clock. Graph event: Filter Graph Manager uses a message queue to notify the application to occur in the Filter Graph in the Filter Graph. GRAPH-BULIDING METHOD: FILTER GRAPH Manager provides the application to add FILTER to the Filter Graph, and how the Filter is connected or disconnected from the FILTER. Filter Graph Manager does not provide functions that manipulate flow data between Filter, which is completed in a separate thread by FILTER. 3.2.3. MEDIA TYPE) Because DirectShow is modular, there is a need to have a method of describing the format between the Filter Graph points. For example, AVI playback, data input is a stream of RIFF blocks, and then decomposed into video and audio streams. The video stream consists of one by one possible compressed video frame, after decompression, the video stream has become a series of uncompressed bitmaps. Audio is similar to video. Media Type: How to describe the format Media Type is a common way to describe digital media formats. When two FILTER connects, they need to negotiate to determine the same Media Type. The Media Type identifies the data stream format that is submitted from the previous Filter to the next Filter or physical layer. If the two FILTERs are unable to negotiate with Media Type, they cannot be connected. For some applications, you don't have to care for Media Type, such as file playback, DirectShow has made all things about it. Media Type defines using the am_media_type structure that contains the following: * Major Type: Main type, is a GUID that defines the overall type of data, including: video, audio, unsatisfactory byte stream, MIDI Wait. * Subtype: Subtype, another GUID, further define the data format.
For example, if the primary type is video, the child type can be RGB-24, RGB-32, Uyvy format, and if the main type is audio, it may be PCM or MPEG-1 PayLoad, etc. The subtype provides more content than the main type, but there is still no complete format definition, for example, the subtype does not define an image size and frame rate, which will be defined in the Format Block. * Format Block: Format block defines a specific format. The format block is a separately assigned memory space in the AM_MEDIA_TYPE structure, and the PBFormat member points to this memory space. Because different formats have different formats, the type of PBFormat member is Void *. For example, PCM audio uses Waveformatex structures, and video uses different structures including: VideoInfoHeader and VideoInfoHeader2. The FormatType member is a GUID that specifies which structured body contains which structure, and each format is assigned a GUID. CBFormat members define the length of the format block. When the format block is defined, the information containing the primary and subtypes is a bit more than. In fact, main types and subtypes provide a convenient way for identification format, saying that you can specify an ordinary 24-bit RGB format (MediaSubtype_RGB24) without having to care about the video size and frame rate in the videoInfoheader structure. . Below is an example of a Filter Check the media type: HRESULT Checkmediatype (AM_MEDIA_TYPE * PMT) {if (PMT == Null) Return E_POINTER; / / Check the main type, we need video IF (PMT-> Majortype! = MediaTyPE_Video) { Return VFW_E_INVALIDMEDIATYPE;} // Check subtype, we need 24-bit RGB. if (PMT-> Subtype! = MediaSubType_RGB24) {Return VFW_E_INVALIDITYPE;} // Check the size of the format type and format block. IF ((PMT- > formattype == format_videoInfo && (PMT-> CBFORMAT> = SizeOf (VIDEOINFOHEADER) && (PMT-> PBFORMAT! = NULL) {// Now you can safely point the format block pointer to the correct structure. VideoInfoHeader * PVIH = (VideoInfoHeader *) PMT-> PBFORMAT; / / Check PVIH (not shown). If it is correct, return to S_ok. Return S_OK;} return vfw_e_invalidiType;}
The AM_MEDIA_TYPE structure also contains some options to provide additional information, and Filter does not need this information:
* IsampleSize, if this field is non-zero, indicating that this is the size of each Sample, if it is zero, indicating that the size of the Sample will change.
* Bfixdsizesamples, if this Boolean tag is TRUE, indicating that ISampleSize is valid, otherwise you can ignore IsampleSize. * BtemPoralcompression, if this Boolean tag is false, indicating that all frames are keyframes.
3.2.4. About Media Samples and Distributors (Allocator) Filter submits data through connections between PIN and PIN, and data from a Filter output PIN to another filter input PIN, except for individual cases, Implementing this functionality is to call the IMEMINPUTPIN :: Receive method on the input PIN. Relying on Filter, the memory space of media data can be assigned through multiple ways: on the heap, on the DirectDraw surface, in sharing GDI memory or other allocation mechanisms. This object responsible for allocating memory space is called a dispenser, is a COM object exposing the IMallocator interface. When two PINs are connected, one of the PIN must provide a dispenser. DirectShow defines a method call sequence to determine which PIN is provided to provide a dispenser. The PIN is also responsible for negotiating the buffers created by the dispenser and the size of each buffer. Before the data stream begins, the dispenser creates a buffer pool. During data flow, upstream file fill in data in the buffer and deliver it to the downstream file, but upstream filter is not the original buffer pointer to the downstream file, but a COM called Media Sample). Object, it is created by the dispenser and is used to manage buffers to expose the IMEDISAMPLE interface. A media sample contains: * Pointer * Timestamp * Timestamp * Various tag * The optional media type timestamp defines the presentation time, allowing the renderer filter to determine the appropriate timing of playback. Various tags can be used to indicate a lot of things, for example, whether the data is smashed (such as repositioning, dropping), and so on after the previous SAMPLE. The media type provides a way for the flow intermediate change data format, usually, there is no media type SAMPLE, is considered to have not been changed from the previous Sample. When Filter uses a buffer, it saves the reference count on the Sample. The distributor uses the reference count to determine when you can reuse this buffer, which prevents another filter from writing a buffer while another filter is still using this buffer unless all Filter releases this buffer, otherwise Sample will not return it. Buffer pool to the dispenser. 3.2.5. How to participate in the Filter Graph This section describes how DirectShow interacts with audio and video hardware. All DirectShow Filter of the casing filter (Wrapper Filter) is software components of user mode. To make the hardware driver of the kernel mode such as a video capture card to the Filter Graph, you must make it like the Filter of the user mode. DirectShow provides a shell FILTER to complete this feature, including: Audio Capture Filter, VFW Capture Filter, TV Tuner Filter, TV Audio Filter and Analog Video Crossbar Filter. DirectShow also provides a Filter called KsProxy that implements any type of WDM stream driver. The hardware operator expands KsProxy by providing a KSProxy Plug-in to support their functions, KsProxy Plug-in is a COM object that is aggregated by KsProxy.
The shell FILTER implements the function of the device by exposing the COM interface. The application uses these interfaces to the filter, and the filter transforms these COM calls to the device driver call, passes the information to the device in kernel mode, and then returns the result to the application. Both TV Tuner, TV Audio, Analog Video Crossbar and Ksproxy Filter support drive-driven custom properties, VFW Capture Filter and Audio Capture Filter do not support this approach. Shell Filter allows applications to control devices like controlling other DirectShow Filter, and Filter has packaged details with kernel-driven communications. Video for Windows Devices VFW Capture Filter supports an early VFW capture card. When a device is added to the target system, it can be discovered by DirectShow using the System Device Enumerator, and is added to the Filter Graph. Audio Capture and Mixing Device / Sound Card have a socket with a microphone and other devices, and most of these sound cards have a plate-level mixed capability that can be individually controlled. Each connection device is measured and high. In DirectShow, the input and mixing devices of the sound card are encapsulated by the Audio Capture Filter. Each sound card can be discovered by the system device enumerator. To view all the sound cards in your system, simply open the graphedit, select from the Audio Capture Sources, each of which filters in this class is a separate Audio Capture Filter.