Analysis of FFmpeg rtsp playback Code
When playing rtsp url, it will judge whether to call ff_rtsp_demuxer to read network data according to whether there is rtsp in url.
AVInputFormatff_rtsp_demuxer = {
.name = "rtsp"
.long _ name = NULL_IF_CONFIG_SMALL ("RTSP input")
.priv _ data_size = sizeof (RTSPState)
.read _ probe = rtsp_probe
.read _ header = rtsp_read_header
.read _ packet = rtsp_read_packet
.read _ close = rtsp_read_close
.read _ seek = rtsp_read_seek
.flags = AVFMT_NOFILE
.read _ play = rtsp_read_play
.read _ pause = rtsp_read_pause
.priv _ class = & rtsp_demuxer_class
}
Code stream format detection and analysis
> ffplayd.exeroomrtpaired read (URLContext * h, unsigned char * buf, int size) line 377 C
(call recvfrom to read RTP transmission data, and transfer_func points to the implementation of rtp_read)
Line 376 C (URLContext * h, unsigned char * buf, int size, int size_min, int (URLContext *, unsigned char *, int) * transfer_func)
Line 412 C for URLContext * h, unsigned char * buf, int size)
Line 2033 C: ffplayd.exeroomudp readreadable packet (AVFormatContext * s, RTSPStream * * prtsp_st, unsigned char * buf, int buf_size, _ _ int64 wait_end)
Line 2116 C: ffplayd.exeneighbor readreadable packet (AVFormatContext * s, RTSPStream * * rtsp_st, RTSPStream * first_queue_st, _ _ int64 wait_end)
AVFormatContext * s, AVPacket * pkt) line 2202 C
Ffplayd.exeroomrtspinner readbasket packet (AVFormatContext * s, AVPacket * pkt) Line 879 C
AVFormatContext * s, AVPacket * pkt) line 856 C
FF playd.exe read frames internal (AVFormatContext * s, AVPacket * pkt) line 1582 C
Fffplayd.exeroomavformatting findstreams streamlines info (AVFormatContext * ic, AVDictionary * * options) line 3772 C
Line 2805 C of ffplayd.exeroomreadreadread thread (void * arg)
Ffplayd.exethanks SDLING RunThread (void * data) line 283 C
Ffplayd.exeroomRunThread (void * data) line 91 C
Ffplayd.exekeeper RunThreadViaBeginThreadEx (void * data) line 106
Focus on the analysis function ff_rtsp_fetch_packet, which calls read_packet to get RTP data, calls ff_rtp_parse_packet to analyze RTP data, removes the RTP header, adds the starting code, and then encapsulates it into AVPacket, but the encapsulated AVPacket is not a complete NAL unit video stream. For FU-A subpackaged data, multiple AVPacket still need to be reassembled.
> ffplayd.exeroomh364 handlepacketfuzza (AVFormatContext * ctx, PayloadContext * data, AVPacket * pkt, const unsigned char * buf, int len, int * nal_counters, int nal_mask) line 291 C
(for the RTP format data of FU-A subpackage, the starting code will be added according to whether it is the first package, the key is start_bit = fu_header > > 7;)
Fffplayd.exeroomh364 handlebags packet (AVFormatContext * ctx, PayloadContext * data, AVStream * st, AVPacket * pkt, unsigned int * timestamp, const unsigned char * buf, int len, unsigned short seq, int flags) line 359 C
Line 692 C (RTPDemuxContext * s, AVPacket * pkt, const unsigned char * buf, int len) line 692 C
Line 841 C (RTPDemuxContext * s, AVPacket * pkt, unsigned char * * bufptr, int len)
Line 875 C (RTPDemuxContext * s, AVPacket * pkt, unsigned char * * bufptr, int len)
AVFormatContext * s, AVPacket * pkt) line 2217 C
Ffplayd.exeroomrtspinner readbasket packet (AVFormatContext * s, AVPacket * pkt) Line 879 C
AVFormatContext * s, AVPacket * pkt) line 856 C
FF playd.exe read frames internal (AVFormatContext * s, AVPacket * pkt) line 1582 C
Line 1776 C of ffplayd.exeupload avenue readloaded frame (AVFormatContext * s, AVPacket * pkt)
Line 3008 C of ffplayd.exeroomreadreadread thread (void * arg)
Ffplayd.exethanks SDLING RunThread (void * data) line 283 C
Ffplayd.exeroomRunThread (void * data) line 91 C
Ffplayd.exekeeper RunThreadViaBeginThreadEx (void * data) line 106 C
Analysis of av_read_frame subcontract Code
Line 265 C of the const unsigned char * pc, int next, const unsigned char * * buf, int * frame
> ffplayd.exeroomh364roomparse (AVCodecParserContext * s, AVCodecContext * avctx, const unsigned char * * poutbuf, int * poutbuf_size, const unsigned char * buf, int buf_size) line 595 C
Fffplayd.exeroomavail parserconversation parse2 (AVCodecParserContext * s, AVCodecContext * avctx, unsigned char * * poutbuf, int * poutbuf_size, const unsigned char * buf, int buf_size, _ _ int64 pts, _ _ int64 dts, _ _ int64 pos) line 166C
Line 1461 C of ffplayd.exeroomparsepackets packet (AVFormatContext * s, AVPacket * pkt, int stream_index)
FF playd.exe read frames internal (AVFormatContext * s, AVPacket * pkt) line 1675 C
Line 1776 C of ffplayd.exeupload avenue readloaded frame (AVFormatContext * s, AVPacket * pkt)
Line 3008 C of ffplayd.exeroomreadreadread thread (void * arg)
Ffplayd.exethanks SDLING RunThread (void * data) line 283 C
Ffplayd.exeroomRunThread (void * data) line 91 C
Ffplayd.exekeeper RunThreadViaBeginThreadEx (void * data) line 106 C
[external code]