0 Preface
The DirectShow application framework completes the underlying work of streaming, so that the programmer does not need to care about how the data is input, and how to output it after processing, and just care about how to process the input data. The H.264 video codec standard has high compression ratio and excellent network affinity, and is generally considered to be the most influential stream video compression standard. The streaming media player combined with Direct-Show and H.264 will undoubtedly have very good performance.
1DIRECTSHOW Technology and H.264 Video Compression Standard
DirectShow is a set of stream media development packages provided by Microsoft, providing a complete solution for multimedia applications for the playback of media files in various formats on the Windows platform.
DirectShow is a completely COM-based application, which is located in the application layer. It uses FilterGraph's model to manage the processing of the entire data stream; the various functional modules of participating data processing are called filter; each filter is in FilterGraph. The sequence is connected as a "pipeline" synergistic work. Filter is a COM component that can be implemented by the user, and DirectShowsDK also provides users with some standard Filter for users. Each Filter is connected to each other in a certain order in Filtergraph, and the PIN is also a COM object.
H.264 is the latest international video coding standard developed by the Joint Development Group of ITU-T and ISO / IEC. The H.264 / AVC video coding standard has significantly improved compared with the original video coding standards than the original video coding standards. In the same visual sensing quality, the encoding efficiency is about 50% higher than H.263, MPEG-2 and MPEG-4. H.264 does not only have excellent compression properties, but also have good network affinity. Therefore, H.264 is generally considered to be the most influential stream video compression standard.
2 system design framework
The system is based on the DireotShow application framework and H.264 video compression standard, which implements streaming media data from the network, and plays in the client. The streaming media file is an AVI file encoded by H.264. Since DirectShow provides AvisplitterFilter, Audiodecoder, and standard Video / Audiorenderer, this system only needs to design a custom network source Filter, H.264 decoded Filter.
Multimedia streaming is actually involved in two technologies. One is the communication technology of the server and the client, including the transmission of multimedia data, command control, etc .; it is the technique that the client is decoded after the received multimedia flies. Obviously, network communication can use WindowsSocket technology, multimedia stream decoding playback can use Direct-Show technology. This article uses the DireetShow application framework, and the network source Filter and H.264 are designed to decode the Filter and build a streaming media player via FilterGraph.
Play the FilterGraph of the local H.264 encoded AVI file as shown in Figure 1. Simply replace local FilesourceFilter to network source Filter, replace the CoreavCVIdeDe-Coder to H.264 Decode Filter to implement a network H.264 video player.
Be
Be
3 system design and implementation
3.1filter design process
Filter's encoding implementation includes Filter's registration information, Frame function implementation, logical control class implementation, custom interface implementation, property page implementation, property rights protection, etc.
First, you must analyze the features you want to complete with the Filter and it analyzes the location in FilterGraph to determine the Filter model, select a suitable base class; then, then define the input and output PIN and the custom interface, register Filter information; finally All pure virtual functions and custom interface functions, and rewrite the relevant functions of the base class to customize the Filter function.
3.2 Design of Network Source Filter
The source FILTER main function is to receive streaming data sent by the server and is provided to other Filter in FilterGraph.
Since DirectShow comes with AvisPlitter working in pull mode, the source filter is also working in the pull mode.
This source FILTER uses a dual buffer cycle queue technology to receive data from the reception of data and the next level FILTER. This technology has the following reasons:
(1) During the SourceFilter and the SPLIRER connection, part of the data will be read from the SourceFilter to obtain the format description of the data, otherwise FilterGraph cannot complete the connection. Before the source filter is connected to the splitterfilter, you should start a wait thread. When the SourceFilter's data cache receives enough data, the complete FILTERGRAPH is built.
(2) When the complete FILTERGRAPH build is completed, the SourceFilter must dynamically receive data, and continuously provide new data to the splitterfilter, and the dual buffer cycle queue makes it full of memory space, and provides stable SplitterFilter. data source.
(3) The buffer queue can stabilize the code rate, effectively reduce the impact of network delay, blocking, and jitter.
The work of the source FILTER is as follows: Create a loop buffer queue, the queue tail pointer is used to buffer data received from the network, the queue head pointer is used to read the data, and the audio and video is separated, and the next level decoder process; when socket After receiving the network data, insert the data into the tail of the queue and move the tail pointer back; when the splitter needs to read the data, read the data from the queue header and move the head pointer behind.
Streaming media transmission adopts the client / server architecture, there is a Socket communication protocol issue between the server and the client, since the streaming is continuous, its synchronization point cannot be selected casually, so in order to transmit streaming data, you must use Connected Reliable Transmission Protocol (TCP). The client and the server side control and feedback messages can be transmitted using (UDP). The server side first creates a listening socket to listen for connection requests from the client. Once the client's request is listened, the server is created for the Socket for data transfer, and binds to the client requested, at which point the server is in the ready state of data transfer. When the client issues a command, the server will perform the appropriate operation according to the type of command, such as data transmission, stop, disconnection, etc.
The server side first divides the continuous H.264 stream into a piece of packet load data, and adds a TCP protocol to use the TCP protocol to simply assemble the packet load data according to the information header, and then H. The decoding playback of .264. The Socket data transfer structure is: load type (8bit), load data length (16bit), and load data packet (2324byte).
The client's implementation can refer to the MemfileFilter in the SDK, copy AsyncRDr.cpp, asyncr.h, asyncio.cpp, asyncrdr.h, asyncio.cpp, asyneio.h directly from the SDK example, and then derived streaming CasyncStream from the Memfilter.h file. Customize the source of data and perform data; from the CasyncReader derived filter class CMEMReader, implement the SourceFilter framework containing 1 output PIN to complete the connection with the splitterfilter.
The network source filter class data flow is shown in Figure 2, the next FILTER "pull" thread data flow is shown in Figure 3. Where: CasyneStream is used to mark the data stream; the CasyneRequest indicates the input and output request; Casyncio implements the control of data input and output. Programming mainly implements the CMemStream: Read () function to read data from a specific data source to the next level of Filter's Sample. Technology area
World premiere! Rohm develops high-quality audio IC "BD372xx series"
Home Wireless Router Practical Guide
I understand audio circuit diagram and working principle
Talking about the "Sudok Curve" in the sound
Snapers M0PRO Speaker Deep Disassembly Report: Internal and External
Our other product: