DirectShow-Filter Principle

Source: Internet
Author: User
11 , Filter Principle-OverviewFilter is the most basic concept in DirectShow. DirectShow uses filter graph to manage filters (the manager is called filter graph manager ). The filter graph is the "Container" of the filter, and the filter is the smallest functional module in the filter graph. Filter is a COM component. To implement unified operations in the filter graph, each filter must implement at least the ibasefilter interface. Ibasefilter inherits from imediafilter. Filter graph manager controls the status (running, paused, and stopped) Conversion of the filter graph through the imediafilter interface. Filter category: Source FiltersData sources can be files or devices. Only the output pin is used. Transform FiltersIt is mainly responsible for data format conversion, such as data stream separation/synthesis, encoding/decoding, and further data transmission. Both the input pin and the output pin are supported. Rendering FiltersIt is mainly responsible for the final destination of data and delivery to devices or files. Only the output pin is used. 12 , Filter Principle-registrationThe file that implements the filter is generally a DLL, And the extension can be. dll, but more often it is. Ax. Generally, a filter project contains a. Def file, which is used to define four export functions. Since filter is a COM component, you must register it before use. The registration information of the filter generally includes the basic com Information and the unique information of the filter. In. four export functions defined in the def file: dllgetclassobject is called when a filter object is created, and the corresponding class factory object is returned Based on CLSID; dllcanunloadnow is used to determine whether filter dll can be detached from memory, that is, whether all COM objects implemented in the DLL have been released. The dllregisterserver and dllunregisterserver call the amoviedllregisterserver2 function to complete the self-registration function of the COM component. 13 , Filter Principle-connectionFilters are generally composed of one or more pins. filters are connected to each other through pins to form an ordered link. The filter connection is actually the connection of the filter pin. The connection of the pin is actually a "negotiation" Process of the media type used by both parties. The two filters to be connected must be in the same filter graph. You can call the interface method ifiltergraph: addfilter to add the specified filter to the filter graph. The steps for the entire connection process are roughly as follows: A. filter graph manager calls ipin: connect on the output pin; B. If the output pin accepts the connection, it calls ipin on the input pin :: receiveconnection; C. If you enter a pin to accept the connection, the connection is successful. 14 , Filter Principle --For some reasons, we need to modify the existing filter graph. The common practice is to stop the filter graph, modify it, and restart it. In addition, it can achieve dynamic reconstruction while maintaining the running status of the filter graph. Filter graph Reconstruction involves the following situations: A. Only change the media type connected between filters; B. add or delete filters and re-connect related filters; c. operate a filter chain. 15 , Filter Principle-Data TransmissionEach pin implements the ipin interface, which is mainly used for pin connection rather than data transmission. The imeminputpin interface implemented on the input pin and iasyncreader interface implemented on the output pin are generally used for data transmission. The successful connection between filters is ready for data transmission. Filters transmit data in the form of samples. sample is a COM component that encapsulates a certain size of data memory. Samplle is managed by the alicator (also a COM component. The pin on both sides of the connection must use the same distributor, but the pin on which the distributor is created also needs to be negotiated. There are two main data transmission modes: Push model and pull model ). DirectShow always uses a dedicated thread to transmit data. Therefore, the DirectShow application contains at least two threads, one main thread of the application and at least one data transmission subthread. 16 , Filter Principle-State ConversionFilter has three statuses: Stop, paused, and running ). The pause can be understood as the data readiness state, designed to quickly switch to the running state. As an intermediate state, pausing is also a necessary State for switching between stopping and running. 17 , Filter Principle-Implementation of media PositioningApplications can use the imediaseeking interface obtained on filter graph manager to randomly locate streaming media and adjust the playback speed of media files. In fact, the imediaseeking interface is actually implemented on the filter. Another interface for media positioning is imediaposition, which supports automation and is designed for developing DirectShow applications for weak programming languages such as VB. For filter developers, imediaposition is not required. Filter graph manager automatically converts the imediaposition interface method call to the imediaseeking interface method call. 18 , Filter Principle-Implementation of Quality ControlA Data thread transmits data in an "compression" mode. Although after the video Renderer receives the sample, it will correctly arrange the display time based on the time stamp on the sample, but this is not enough, it does not improve the performance of the filter graph runtime. Therefore, DirectShow also designs an adaptive feedback mechanism: quality control ). Quality control is implemented through the iqualitycontrol interface. The implementation of specific quality control policies depends on the specific filter implementation, which may adjust the sending speed or lose part of the data. 19 , Filter Principle-Audio and Video Synchronization SolutionIn any system design, the most critical part is the system framework and control part. DirectShow is no exception. The important part is the filter graph manager, which directly controls all filters in the filter graph and provides programming interfaces to the application. Unfortunately, Microsoft does not provide source code for these functions. DirectShow's Audio/Video Synchronization solution is to select a public reference clock (reference clock) for the filter graph, and each sample sent to the Renderer Filter must be timestamp ); video Renderer or audio Renderer correctly schedules the playback time of the sample based on the sample Timestamp and the reference time of the reference clock. 20 , Filter Principle-hardware supportTo improve system stability, Windows isolates hardware operations, and applications generally cannot directly access the hardware. How does directshowfilter work in user mode while hardware works in kernel mode? DirectShow's solution is to provide wrapper filters for these hardware. This filter can work in user mode, and its appearance and control methods are the same as ordinary filters, the packaging filter interacts with hardware functions internally. 21 , Filter Principle -- VMR-9 ReleaseVmr (Video mixing Renderer) is a new generation of video Renderer in DirectShow. Vmr has two versions: VMR-7 and VMR-9. The former adopts DirectDraw 7 technology, which can be obtained only in Windows XP and is the default Renderer for video display on XP (instead of the traditional video Renderer ); the latter adopts the direct3d 9 technology and is released along with directx9.0, but it is not the default Renderer at any time. After directx9.0 is installed, four video Renderer options are available: traditional video Renderer, overlay mixer, VMR-7 and CMR-9. Vmr mainly utilizes the dedicated graphics processing capabilities of the video card (vmr does not occupy the CPU resources of the system for video synthesis and display), and its performance is highly dependent on hardware. 22 , Filter Principle -- Filter graph Construction Method(1) ifiltergraph: addfilter: this parameter provides a filter object and adds it to the filter graph. (2) ifiltergraph: connectdirect: this parameter provides the output pin, input pin, and media type for direct connection. (3) igraphbuilder: addsourcefilter: this parameter provides the source file name and automatically loads a source filter to the filter graph. (4) igraphbuilder: CONNECT: this parameter provides the output pin and the input pin for connection. If the connection fails, the necessary format conversion filter is automatically inserted in the middle. (5) igraphbuilder: render: this parameter provides the output pin and automatically adds the necessary filter to build the remaining filter graph (until it is connected to the rendering filter ). (6) igraphbuilder: rnderfile: this parameter provides the source file name and automatically adds necessary filters to build the filter graph for file playback.

The filter can be connected by pin to create a complete filter graph. The last four construction methods have the "Automatic" function, which is called Intelligent connection ).
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.