DirectShow streaming media API Programming

Source: Internet
Author: User

Microsoft has made a lot of interfaces for programming with DirectX brothers. We can see below ildasm that there is only one class named filgraphmanagerclass. In fact, I have read it carefully, there are not many large functions. DirectX is divided into four layers in abstraction,

Hardware/network layer: multimedia devices, including Graphics accelerators, sound cards, input devices, and network communication devices;

DirectX base layer: provides basic multimedia services for images, sounds, and devices;

  DirectX Media layer:

Provides API functions for animation production, audio and video;

Component layer: Includes ActiveX Control and applications. It uses the advantages of DirectX APIs to provide multimedia services for users.

DirectShow
Is a technology built on the DirectX Media layer, its predecessor is activemovie2.0. It uses
An API function or ActiveX control is used to enable developers to transmit high-quality audio and video signals over the network. It is worth mentioning that DirectShow provides us with
In an open development environment, we can customize components as needed.

DirectShow
Defines how to use standard components to process streaming media data. These components are called filters. Filters with input and output needle angles
(PIN), or both. In DirectShow technology, the core component is the pluggable standard component used as a "filter". It is a COM object that executes a specific task. Filter
It can also be subdivided into source filter, transform filter, and Renderer Filter)
. The filter operates streaming media by reading, writing, modifying, and displaying data to the output device. The filter pins are negotiated to determine the form of multimedia they will support. Because
DirectShow supports reconfigurable filter chart structures. Therefore, multiple types of media can be played using the same software component. developers can define their own filters to expand.
DirectShow supports media.

The source filter is used to obtain data from the data source and transmit the data to the filter chart. The data source can be a camera, Internet, or disk file;

The conversion filter is used to obtain, process, and transmit media data. It includes the splitter transform filter, and extract the video.
Video transform filter and audio conversion filter for extracting audio data
(Audio transform filter)

A performance filter is used to represent media data on hardware, such as a video card or sound card, or wherever media data is accepted, such as a disk file. It includes a video performance filter used to display images.
(Video Renderer Filter), audio performance filter (audio Renderer Filter) that sends audio data to the sound card ).

Simply put, it is to read information and use a "Needle" technology to convert changes and then output them to hardware.

DirectShow
Based on the COM component technology, you must master the COM component technology to develop the DirectShow program.
. DirectShow is closely connected with COM. all its components and functions are constructed and implemented by the COM interface. Its development method is quite flexible and there is no fixed mode. It is usually used as needed
Different com interfaces. However, several important interfaces are frequently used: The igraphbuilder interface, which is the most reusable COM interface used to create
Filter graph manager; imediacontrol interface, used to control the flow of streaming media in filter charts, such as streams
Media Start and Stop; imediaevent interface, which is used to create event flag information when filter graph has some events and send it to the application.

The development of a typical DirectShow application follows the following steps:

1) create a filter graph manager instance using the cocreateinstance () function;

2) Call the QueryInterface () function to obtain the pointer of the filter graph and imediaevent components;

3) control filter graph and respond to events.

 

For example, first generate a single-document application named mediaplay and define a function named mediaplay. The specific implementation code of this function is:

Void playmovie (lptstr lpszmovie)
{
Imediacontrol * PMC = NULL;
Igraphbuilder * pgb = NULL;
Imediaeventex * PME = NULL;
Long evcode; // something to hold a returned Event code
HR = cocreateinstance (clsid_filtergraph, null, clsctx_inproc,
Iid_imediacontrol, (void **) & PMC );
HR = PMC-> QueryInterface (iid_igraphbuilder, (void **) & pgb );
HR = PMC-> QueryInterface (iid_imediaeventex, (void **) & PME );
HR = pgb-> renderfile (lpszmovie, null );
HR = PMC-> Run ();
HR = PME-> waitforcompletion (infinite, & evcode );
If (PMC) PMC-> release ();
If (pgb) pgb-> release ();
If (PME) PME-> release ();
}

In the code above, the cocreateinstance () function creates a filter graph object and returns a media control.
(Imediacontrol) interface, which uses a filter to enable playback, pause, stop, and other media display functions. However, the chart object does not contain a specific filter at this time.
DirectX does not know what type of media to play. Next, create a chart building interface that allows you to create a filter chart, add a filter to a chart object, delete various filters, and list the current
All filters in the filter chart, and various filters in the chart object are connected. In this example, the renderfile () function of the igraphbuilder interface is used to tell
The name of the media file to be played by DirectX. In this case, the igraphbuilder object interface automatically adds various types of media files required for playing this type to the filter Chart Based on the multimedia file type.
Filter, and realize its connection.

Finally, the function calls the run () function of the imediacontrol interface object to start playing media files. You must call
The waitforcompletion () blocking function of the imediaeventex object interface runs until the media file ends.
Line.

Appendix:

All Event Notification codes:

Ec_activate video window is activated or converted to inactive status
Ec_buffering_data: Filter images that contain buffered data
Ec_clock_changed reference clock Changed
Ec_clock_unset the clock provider is disconnected.
Ec_complete: all data is rendered
Ec_device_lost a plug-and-play device is removed or becomes valid.
Ec_display_changed: The display mode is changed.
Ec_end_of_segment arrives at the end of the segment.
Ec_error_stillplaying an asynchronous command failed
Ec_errorabort an operation is abandoned
Ec_extdevice_mode_change is not supported
Ec_fullscreen_lost: A Video rendering window is switched to full screen mode.
Ec_graph_changed filter chart changed
The length of the ec_length_changed source is changed.
The ec_need_restart filter requests the filter chart to start again.
Ec_policy_window: Specifies the filter of a video rendering window.
The ec_ole_event filter passes a string to the application ..
Ec_opening_file: open a file or open the file.
Ec_palette_changed the video palette.
Ec_paused A paused request is processed.
Ec_quality_change
Ec_repaint a video Renderer requires repainting.
Ec_segment_started starts with a new segment
The ec_shutting_down filter chart is disabled.
Ec_snddev_in_error the input pin of an audio device is incorrect.
Ec_snddev_out_error the output pin of an audio device is incorrect.
The ec_starvation filter does not obtain sufficient data.
Ec_state_change filter chart status change
Ec_step_complete a filter executes a single shard progressively
Ec_stream_control_started start command to produce results.
Ec_stream_control_stopped: A traffic control stop command produces results.
Ec_stream_error_stillplaying produces an error in the stream, but the stream is still running.
Ec_stream_error_stopped a stream stops due to an error
Ec_timecode_available is not supported
Ec_userabort user interrupted playback.
Ec_video_size_changed the size of the local video.
Ec_window_destroyed: the video Renderer is destroyed or removed from the filter graph.

Related Article

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.