您的位置:首页 > 其它

我的第一篇博客

2015-10-08 21:47 405 查看
注册csdn到现在已经很长一段时间了,从未想过自己会写博客,一直处于学习与寻找阶段,莽莽撞撞,浮于表面。

十一假期刚过,想以此作为一个转折点,静下心来做一些事情,为以后的自己留下点记忆。

这是我的第一篇博客,如果不出意外的话,我会把这个习惯坚持下去,最近涉及到一些关于流媒体服务器的相关工作,下面贴上一篇live555的简要分析(摘自他处)。


The RTSP server instance live555 source code analysis

RTSP connection process of establishing

RTSPServer class is used to build a RTSP server, the class defined in its internal a class RTSPClientSession, for processing individual client session.

First create a RTSP server the (specific the implementation class DynamicRTSPServer), in the creation process, first create Socket (ourSocket) listens at TCP port 554, then the connection handler function handle (RTSPServer
:: incomingConnectionHandle r) and socket handle passed to the task scheduler (TaskScheduler).

The task scheduler socket handle into the socket handle set (fReadSet) used in the back of select call, at the same time associate the socket handle and incomingConnectionHandle of r handle. Then, the main program began to enter the the task scheduler main
loop (doEventLoop)
call the system function select obstruction in the main loop, waiting for a network connection.

When the RTSP client input (rtsp :/ / 192.168.0.1/1.mpg) to connect to the server, select returns the corresponding socket in turn based on the correspondence between the previously saved, can be found in the corresponding processing function handle,
here is the aforementioned incomingConnectionHandle r. Created in incomingConnectionHandle r RTSPClientSession
start processing client session.



DESCRIBE request message processing


The RTSP DESCRIBE server receives the client's request, according to the request URL (rtsp :/ / 192.168.0.1/1.mpg), find the corresponding stream media resources, and returns a response message. The live555 ServerMediaSession class is used
to handle the session description, it contains a sub-multiple (audio or video) Session Description (ServerMediaSubsession).

The RTSP server receives a client connection requests, established RTSPClientSession class to deal with a separate client session. In creation RTSPClientSession the process, the newly created socket handle (clientSocket) and RTSP request processing function
handle RTSPClientSession :: incomingRequestHandler passed to the task scheduler, both one-to-one association by the task scheduler.

RTSP requests issued when the client, the server main loop select call returns, according to the socket handle to find the corresponding incomingRequestHandler start message processing.First news analysis, if the discovery request is the DESCRIBE
enter handleCmd_DESCRIBE function. Based on the client request URL suffix 1.mpg call the the member function DynamicRTSPServer :: lookupServerMediaSession Find the corresponding streaming information ServerMediaSession. If the ServerMediaSession
does not exist, but the local 1.mpg file, create a new ServerMediaSession. In in create ServerMediaSession process, file suffix mpg, create media MPEG-the 1or2 the demultiplexer (MPEG1or2FileServerDemux of). Created by the MPEG1or2FileServerDemux a child session
Description MPEG1or2DemuxedServerMed iaSubsession. Complete assembly by ServerMediaSession SDP information in the response message the (SDP assembly process, see the following description), then the response message to the client, the completion of
a message exchange.


SDP message assembly process:

ServerMediaSession is responsible for to generate public description of the session, the sub-session description generated by MPEG1or2DemuxedServerMed iaSubsession.MPEG1or2DemuxedServerMed iaSubsession in the parent class members the function OnDemandServerMediaSubse
ssion the :: sdpLines () generates a session description information. Inside in sdpLines () to create a fictitious (dummy) FramedSource (specific the implementation class for MPEG1or2AudioStreamFrame R and MPEG1or2VideoStreamFrame r) and RTPSink
(specific implementation class MPEG1or2AudioRTPSink and MPEG1or2VideoRTPSink) Last call setSDPLinesFromRTPSink () member function to generate sub- The session description.

The Live555 library is a open standard protocols such as RTP
/ RTCP, RTSP, SIP multimedia streaming open source C library
set. These libraries can be in Unix, Windows, QNX operating
system compiler used to achieve the transmission of multimedia streams based on established RTSP / SIP server
and the client.
Here are the specific implementation process [4]:

(1) client-initiated RTSP OPTION request,
the purpose is to get the server what. RTSP provides methods generally include OPTIONS,
DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, SCALE, GET_PARAMETER.


(2) server on RTSP OPTION response,
in response to which server implementation. In this system, we only DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE method
to achieve.


(3) The client initiates the RTSP DESCRIBE request,
the server receives the information media name, description decoding type, video resolution, in order to get from the server session description (SDP).


(4) The server RTSP DESCRIBE response,
send the necessary media parameters in the the H.264 file transfer, including the SPS
/ PPS, media name, transport protocol information.


(5) The client initiates the RTSP
SETUP request, the purpose is to request the session is established and ready for transmission.
Request
information including the transport protocol and client port.


(6) server, issue the appropriate server-side port number and the session identifier RTSP
SETUP response.


(7) The client makes RTSP
Play the request, the request to play a video stream.


(8) server on the RTSP PLAY response,
the response message includes the session identifier, the sequence number of the RTP packet, the timestamp. The
server H264 video streaming package packaged for transmission.


(9) issued by the client the RTSP TEARDOWN request
to close the connection terminated transmission.


(10) server closes the connection to stop transmission.

SETUP request message processing

RTSPClientSession class is used to handle individual client session. Members of the class the function handleCmd_SETUP () handles client SETUP request. Call parseTransportHeader () SETUP request transport header parsing, call the sub-session (in this specific
implementation class for the OnDemandServerMediaSubse ssion) getStreamParameters () function to get the send streaming media transmission parameters. These parameters are assembled into a response message back to the client.

The the gets sent transmission parameters: call sub-sessions (specific implementation class MPEG1or2DemuxedServerMed iaSubsession) createNewStreamSource (...) create MPEG1or2VideoStreamFrame r choose to send the transmission parameters, call the the child session
createNewRTPSink (...) to create MPEG1or2VideoRTPSink. While the information is saved in Class StreamState object for recording flow state.

The client sends a SETUP request, respectively, is used to create the audio and video RTP reception.

PLAY request message processing

HandleCmd_PLAY members of the RTSPClientSession class function () play request processing client. The first call sub-sessions startStream (), internal to call MediaSink :: startPlaying (...), then is MultiFramedRTPSink to :: continuePlaying (), then calls MultiFramedRTPSink
the :: buildAndSendPacket (...). buildAndSendPacke be set within the RTP header, internal call MultiFramedRTPSink :: packFrame () fill coded frame data.

within packFrame by FramedSource :: to the GetNextFrame (), and then MPEGVideoStreamFramer :: doGetNextFrame (), followed by after MPEGVideoStreamFramer :: continueReadProcessing (), FramedSource :: afterGetting (...), MultiFramedRTPSink :: afterGettingFrame
(...), MultiFramedRTPSink: : afterGettingFrame1 (...) and a series of tedious calls, and finally to MultiFramedRTPSink :: sendPacketIfNecessary () really send RTP packets. And then calculate the next packet transmission time, to :: sendNext MultiFramedRTPSink
(...) handler function is passed to the task scheduler event scheduler as a delay. In the main loop, when the MultiFramedRTPSink :: sendNext () is scheduled to start calling MultiFramedRTPSink :: buildAndSendPacket (...) to start a new process of sending data,
so that the client can receive a steady stream of RTP packets transmitted by the server the.

Sending RTP packet interval calculating method:

Update the time at which the next packet should be sent, based on the duration of the frame that we just packed into it.

以此作为一个新的开始!

热爱生活,知足常乐。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: