RTSP解复用器

libavformat/rtspdec.c

const FFInputFormat ff_rtsp_demuxer = {
          
          
    .p.name         = "rtsp",
    .p.long_name    = NULL_IF_CONFIG_SMALL("RTSP input"),
    .p.flags        = AVFMT_NOFILE,
    .p.priv_class   = &rtsp_demuxer_class,
    .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,
    .read_play      = rtsp_read_play,
    .read_pause     = rtsp_read_pause,
};
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.

探测输入格式根据URL起始字符进行匹配

static int rtsp_probe(const AVProbeData *p)
{
          
          
    if (
#if CONFIG_TLS_PROTOCOL
        av_strstart(p->filename, "rtsps:", NULL) ||
#endif
        av_strstart(p->filename, "satip:", NULL) ||
        av_strstart(p->filename, "rtsp:", NULL))
        return AVPROBE_SCORE_MAX;
    return 0;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

sdp_parse_line实现SDP分析

libavformat/rtsp.c实现RTSP协议的分析

>	ffplayd.exe!ff_sdp_parse(AVFormatContext * s, const char * content)721	C
 	ffplayd.exe!ff_rtsp_setup_input_streams(AVFormatContext * s, RTSPMessageHeader * reply)643	C
 	ffplayd.exe!ff_rtsp_connect(AVFormatContext * s)1967	C
 	ffplayd.exe!rtsp_read_header(AVFormatContext * s)757	C
 	ffplayd.exe!avformat_open_input(AVFormatContext * * ps, const char * filename, const AVInputFormat * fmt, AVDictionary * * options)305	C
 	ffplayd.exe!read_thread(void * arg)2858	C
 	ffplayd.exe!SDL_RunThread(void * data)283	C
 	ffplayd.exe!RunThread(void * data)91	C
 	ffplayd.exe!RunThreadViaBeginThreadEx(void * data)106	C
 	ucrtbased.dll!00007ff8de7a4fb8()	未知
 	ucrtbased.dll!00007ff8de7a4bf1()	未知
 	kernel32.dll!00007ff92b737c24()	未知
 	ntdll.dll!00007ff92c9ad721()	未知
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

ff_rtsp_setup_input_streams创建rtsp交互连接

ff_rtsp_send_cmd优先发送DESCRIBE指令,海康和大华RTSP指令交互的区别在于,大华在OPTIONS阶段就会请求认证信息RTSP/1.0 401 Unauthorized

int ff_sdp_parse(AVFormatContext *s, const char *content) 解析SDP中的内容,实际上这里就已经完全知道码流的数据格式以及所有的流信息,根本不需要探测码流格式

sdp_parse_rtpmap函数分析出h264码流格式,保存在AVFormatContext中的stream流中