Here is the main analysis of thelive555 in the RTP package sent parts . After the play command has been processed , the RTP packet is sent (in fact, before the response packet of the play command is sent, a RTP packet is sent, where the transfer is already started )
The main flow is introduced first: theRTP packet is sent from the mediasink::startplaying function call, and the function continueplaying is called at the end of the Startplaying function .
continueplaying function is defined in mediasink class needs to be implemented in the sink h264 is implemented in h264videortpsink. h264videortpsink: An auxiliary class is created in Continueplaying h264fuafragmenter for h264 RTP packaging. Because h264 RTP package, some special needs to be further processed. It then calls its parent class multiframedrtpsink::continueplaying implementation.
In the function multiframedrtpsink::continueplaying is mainly the multiframedrtpsink::buildandsendpacket function.
Just look at the name and know that the Multiframedrtpsink::buildandsendpacket () function will complete the package and send the work. Passed a true parameter, which indicates that this is the first packet. At the end of the function called multiframedrtpsink::p ackframe (), further work, in the packframe function ,
multiframedrtpsink::p ackframe () will populate the data for RTP packets. packframe functions require handling of two cases:
1). the overflow data is present in buffer , and the AFTERGETTINGFRAME1 function can be called for subsequent processing. 2). Buffer does not have data, you need to call the getnextframe function on source to get the data. when GetNextFrame is called, there are two callback functions in the argument: theaftergettingframe function is called after fetching the data, which simply calls the afterGettingFrame1 function; The ourhandleclosure function is called when the data has been processed, such as the end of the file. As you can see, in both cases, the last is to call the afterGettingFrame1 function,
The complexity of the AFTERGETTINGFRAME1 function is to handleThe Shard of a frame, if aFrame greater thanTCP/UDP payload(defined in the program as 1448 bytes ), it is necessary to shard. The simplest case is a packet (RTP packet ) up to a maximum of one frame, that is, a RTP package there is a frame or frame a shard, h264 is handled as follows: The method is to record the remaining data as an overflow part of buffer. The next time the packframe function is called, it is copied directly from the overflow section to packet. However, it should be noted that a frame size cannot exceed buffer size 60000), otherwise it will actually overflow , that should be considered to increase buffer size.
When the relevant shard information is processed, the function multiframedrtpsink::sendpacketifnecessary () is called to send the packet. The sendpacketifnecessary () function handles some of the sent details, such as packet that contain a frame that calls the rtpinterface::sendpacket function to send packet. and add the next RTP send operation to the Task Scheduler:nexttask () = EnviR (). TaskScheduler ().
Scheduledelayedtask. The Sendnext function pointer is passed in the function parameter . Sendnext function again called the buildandsendpacket function, reincarnation ...!
Finally, take a look at the rtpinterface::sendpacket function. If you send using UDP, the Groupsock::output function will be called and the multicast function can be implemented. Groupsock only implements the UDP send function, when the TCP method is transferred when the sendrtpovertcp function is called, this function directly calls the socket's send function. At this point about the RTP package sent the main process analysis is almost, the specific details of implementation, can refer to the source code.
Analysis of packaging and sending process of RTP packets in Live555