Summary of the emergence of DirectShow, providing strong support for multimedia programming under Windows. He provides the latest technology and tools for multimedia applications. It provides a set of application interface APIs to make programmers to design High performance real-time applications. The latest DirectMedia SDK is available in DirectX8.0. The DirectShow has joined many new features. DirectShow is the original Microsoft ActiveMovie SDK. New features include: audio and video capture and compression, listings, DVD support, devices Support for control and multimedia stream formats. Microsoft DirectShow SDK provides capacity to play back and capture media streams from local files and Internet. His supported file format is very diverse, including MPEG, Apple QuickTime, AVI, WAV, MIDI, Advanced Streaming Format (ASF), and Windows Media Audio (WMA).
Before you start, you need the background knowledge: 1. You should be familiar with C / C or VB.2. In addition, it is the headache to the component object model COM technology. Let me briefly introduce COM technology.
I. Most of the APIs in DirectX and Parts Objects COM1.1, Part Object Model DirectShow are composed of COM-based objects and interfaces. COM is the foundation based on object-based system, which is a core model of COM programming, which is also an interface specification. At the operating system level, it is another object model. Many DirectShow APIs are created as instances of COM objects. You can see an object as a black box, the object communicate with objects through the interface, sending a command received by the COM interface to an object or from an object being called a method. For example, IvideoWindow-> setWindowPosition (Grc.right, grc.bottom); the location of the display window is set by the method of the iVideoWindow interface. The object can be bundled with other objects at runtime, and Use the interfaces of these objects. If you already know an object is a COM object, and you know the interface supported by the object, your application or other object can determine the service that the first object can perform. One way to inherit all COM objects is the Query interface method, which allows you to determine an object supported by an object and create a pointer to these interfaces.
1.2, all COM interfaces of the IUNKNOWN interface are derived from an interface called IUNKNOWN, which provides DirectShow's control and operational multi-interface capability for object survival. IUNKNOWN contains three methods: .addref When an interface or another application is bundled up to an object, use the AddRef method to add the index value of the object to 1. .QueryInterface is queried by the characteristics supported by pointer to a specific interface. .Release reduces the index value of the object, which is released from memory when the index value is 0. The addRef and the release method are responsible for maintaining the index value of the object. For example, if you create an IGRAPHBuilder object, the index value of the object is set to 1. Each time there is a function returns a pointer to the object, the function must be added to the index value of the object by returning the pin. 1. Each ADDREF is called must have a Release call to it. When the index value of the object reaches 0, the object is revoked, and all interfaces of the object are not reused. QueryInterface method Determines whether an object supports the specified interface, if support, QueryInterface returns a pointer to the interface. Then you can use the method to communicate with the object. If QueryInterface successfully returns a pointer to the interface, it automatically invokes the AddRef method to increase the index value of the object. Release Release must be called to reduce the index value of the object before revoking the interface pointer. 1.3, the interface in DirectShow COM interface DirectShow is created with considerable basic COM programming. Each interface of the object is derived from the iUnknown COM interface, such as IGraphBuilder, iMediaControl, and iMediaeventex. The creation of the basic object is handled by the special function in the dynamic link library DLL. Of course there are many other interfaces, will be described later.
1.4, C and COM interfaces For C programmers, the COM interface is like an abstract base class. In the base class of C , all methods are defined as pure, which means that there is no code to be associated with methods. The purely virtual C function and the COM interface use a device called a virtual table (VTABLE). A virtual table contains a declaration for all functions applied to the interface. If you want the program or object to use these functions, you can check the interface where the object exists with the queryinterface method, get the pointer of the interface, after queenterface, the application or object actually receives the pointer of the virtual table from the object, by which The pointer can invoke all interface methods applied to the object. Another similarity of COM objects and C is the first parameter of the method is the name of the interface or class, and C is called this parameter. Because COM objects and C objects are completely binary compatible, the compiler is equipped with the COM interface as the C abstraction class, and has the same syntax, which makes the code simple. DirectShow Infrastructure 1. The architecture of the architecture DirectShow defines how to control and process multimedia data streams with Filters. Filters (filters) have input or output Pins (really is not easy to translate ... leg?), Or both there are. Use a Teaching Filter Graph to connect them with each other. Applications use Filter Graph Manager to assemble and move data. By default, Filter Graph Manager automatically handles data. For example, automatically insert an appropriate CODEC, an automatic connection of the transfer of the Filter's output PIN to the default rendering filter. If you don't want to default, you can specify your own Filter. Filter Graph Manager provides a COM interface so that the application can access Filter Graph. The application can directly call the interface of the FILTER GRAPH Manager to control the media stream or return the Filter event, and they can also use the ActiveMovie control to play back the media files. Therefore, you can access the DirectShow, ActiveMovie controls, or Media Control Interfaces (MCI) through COM, as shown below: II. A Filter Graphs is composed of many different types of Filter. Most filters can be classified as three categories: 1. Source Filter, where data is obtained, such as from hard drives, Internet servers, or VCR (recorders), introducing them into Filter Graph. 2.Transform Filter, get data and process him, and pass forward. 3.Rendering Filter, rendering data; usually a device, you can render local and accepted media inputs (like memory or hard disk files). In addition, in addition to these three, there are other filters, an example, Effect Filter, he does not change the type of data, just handles him, and Parser Filter, he can understand the format of source data, Know how to read data correctly, perform seek, etc. For example, a Filter Graph wants to play back a MPEG video file, you will use the following Filter. 1. Source Filter, read data from disk.
2. MPEG FILTER, parsing the data stream, and separating the MPEG audio and video data stream. 3.Transform Filter, decompress the video data. 4.Transform Filter, decompress the audio data. 5.Video Renderer Filter, display video data to the screen. 6.Audio Renderer Filter, send audio data to the sound card. To work in a Filter Graph, Filter must be connected in the correct order, and the data stream begins and ends in the correct order. Filter Graph Manager is this role. He is responsible for connecting the Filter and controls the media stream. He can also configure Filter to render him for a special media file and build Filter Graph. Filter Graph can also be reconfigured through Filter Graph Manager. When configuring, Filter Graph Manager uses Filter Mapper, first read registration information, and determines a useful filter data type. Then try to connect the filter until a render filter is found. Each filter has a registered variable. Filter Graph Manager allows applications or ActiveX controls to control the start, pause, stop, and play specific time periods of the media stream, specify a specific playback location. By calling the appropriate filter method. Also allow the filter to pass the event to the application. Therefore, an application can receive status information of a special filter, etc.
Third. Filters and Pins are in the stream system, there are two basic components, filters, and PIN. Filter is a COM object that he has at least one PIN. PIN is also a COM object. He is built through FILTER. He is the connection point of each filter. As shown below: Enter the PIN Accept Data into the Filter. Output PIN provides data to other Filter. Usually transmit filters, compression, decompression (CODEC) filters, provide an input, one output PIN. A filter has an IBasefilter interface. The method provided by this interface allows the information on the PIN and the return filter to the filter. Methods from IMEDIAFILTER inherited: These methods allow control status (operation, pause, stop) and synchronization. In addition, FILTER can have several other interfaces depending on the type of media he supported. PIN is responsible for providing an interface to connect other PINs and transmitting data. PIN interface support: 1. Transfer data using shared memory or other resource. 2. In each PIN-TO-PIN connection, the specific format of the data is negotiated. 3. Buffer management and buffering allocation, reach the minimum data copy, the maximum data throughput. The PIN interface also has some subtle differences, divided into input and output PIN. Output PIN usually has some of the following interfaces: 1. The iPin method is called running query PIN, connection, and data type information. When Filter Graph is stopped, you can also send a notification to downstream. 2. IMEDIASEEKING allows information about the start time, stop time and other information about the stream to renderer. Then, the media location information is transmitted to the upstream filter (typically a source filter). 3. QQualityControl transmits the Quality-Control message to the upstream. Entering the PIN usually has some of the following interfaces: 1.ipin allows the PIN connection to output the PIN, and provide information to the output PIN. 2. IMEMINPUTPIN provides shared memory buffer transmission data.
Configure the environment setting of the VC before you make any DirectShow program, you have to set the environment variable value of the VC before you have. It is mainly convenient for future project design.
1. Select Options. 2. Select Directories Tab. 3. Select Include Files4 in the Show Directories FOR box. Select a new item in the Directories box, type x: / dx90sdk / include and x: / DX90SDK / Samples / C / DirectShow / Baseclasses, this directory will contain all related head File. 5. Select Library Files6 in the Show Directories FOR box. Select a new item in the Directories box, type x: / dx90sdk / lib, this directory will contain all related library files. 7. Select OK to establish GUID
If you build your own Filter (filter), you need to build a GUID. You can: Select the tool menu, select Create Guid, Guid default is define_guid, and paste the data to your header file. If there is nothing in your tool menu, you can use the Guidgen.exe under the / common / Tools in your VC directory. For example: // {3FA5D260-AF2F-11D0-AE9C-00A0C91F0841} Define_guid (CLSID_MYFILTER, 0X3FA5D260, 0xAF2F, 0x11D0, 0xAE, 0X9C, 0x0, 0xA0, 0xC9, 0x1F, 0x8, 0x41);