rtsp 完整流程 环境---[live555 搭建服务器 / VLC 作为客户端/ RawCap.exe 抓取包]

前言

live555 rtspserver端 创建并且接收客户端数据 环境下,用RawCap 抓取了完整的log
WireShark 打开预览如下
rtsp

从 OPTIONS DESCRIBE SETUP PLAY TEARDOWN 完整的 RTSP协议流程
我在本地的操作,就是播放视频,然后teardown 点击vlc 停止播放,发送的请求

具体协议过程

1. OPTIONS


VLC >>>>>>============= SEND OPTIONS REQUEST===============>>>> RTSPSERVER


    Request: OPTIONS rtsp://10.0.2.15:554/ss1.mkv RTSP/1.0\r\n
    CSeq: 2\r\n
    User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
    \r\n
  • 内容解释 :
    • ”OPTIONS” :表示 当前请求方法
    • “rtsp://10.0.2.15:554/ss1.mkv ” 表示请求连接 ip地址10.0.2.15 、端口554 、流媒体文件 ss1.mkv
    • “User-Agent” 表示 使用的客户端 UA 信息 LibVLC
    • “CSeq” 表示每一次会话的序列号,后面依次增加 OPTIONS请求为2
  • 作用: 获取RTSP服务器支持的请求方法

VLC <<<<================== RESPONSE 200=============<<<<< RTSPSERVER


    Response: RTSP/1.0 200 OK\r\n
    CSeq: 2\r\n
    Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
    Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER\r\n
    \r\n
  • 内容解释 :
    • ”Response” :表示 返回的消息
    • “Date ” 当前服务器的时间
    • “User-Agent” 表示 使用的客户端 UA 信息 LibVLC
    • “Public” 表示 服务器公开支持的请求方法

2. OPTIONS


VLC >>>>>============ SEND DESCRIBE REQUEST==============>>>>>> RTSPSERVER


    Request: DESCRIBE rtsp://10.0.2.15:554/ss1.mkv RTSP/1.0\r\n
    CSeq: 3\r\n
    User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
    Accept: application/sdp\r\n
    \r\n
  • 内容解释 :
    • ”DESCRIBE ” :表示 当前请求方法
    • “Accept” 表示 指定客户端可以接受的媒体类型
  • 作用: 获取请求的 SDP 信息

VLC <<<<================= RESPONSE 200===============<<<<< RTSPSERVER


    Response: RTSP/1.0 200 OK\r\n
    CSeq: 3\r\n
    Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
    Content-Base: rtsp://10.0.2.15/ss1.mkv/\r\n
    Content-type: application/sdp
    Content-length: 796
    \r\n
    Session Description Protocol

SDP信息(有省略):

Session Description Protocol
    Session Description Protocol Version (v): 0
    Owner/Creator, Session Id (o): - 1534399611960795 1 IN IP4 10.0.2.15
        Owner Username: -
        Session ID: 1534399611960795
        Session Version: 1
        Owner Network Type: IN
        Owner Address Type: IP4
        Owner Address: 10.0.2.15
    Session Name (s): Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server
    Session Information (i): ss1.mkv
    Time Description, active time (t): 0 0
    Session Attribute (a): tool:LIVE555 Streaming Media v2018.07.07
    Session Attribute (a): range:npt=0-
    Session Attribute (a): x-qt-text-nam:Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server
    Session Attribute (a): x-qt-text-inf:ss1.mkv
    Media Description, name and address (m): video 0 RTP/AVP 96
        Media Type: video
        Media Port: 0
        Media Protocol: RTP/AVP
        Media Format: DynamicRTP-Type-96
    Connection Information (c): IN IP4 0.0.0.0
        Connection Network Type: IN
        Connection Address Type: IP4
        Connection Address: 0.0.0.0
    Bandwidth Information (b): AS:500
        Bandwidth Modifier: AS [Application Specific (RTP session bandwidth)]
        Bandwidth Value: 500 kb/s
    Media Attribute (a): rtpmap:96 H264/90000
        Media Attribute Fieldname: rtpmap
        Media Format: 96
        MIME Type: H264
        Sample Rate: 90000
 ...
    Media Attribute (a): control:track1
        Media Attribute Fieldname: control
        Media Attribute Value: track1
    Media Description, name and address (m): audio 0 RTP/AVP 97
        Media Type: audio
        Media Port: 0
        Media Protocol: RTP/AVP
        Media Format: DynamicRTP-Type-97
    Connection Information (c): IN IP4 0.0.0.0
        Connection Network Type: IN
        Connection Address Type: IP4
        Connection Address: 0.0.0.0
    Bandwidth Information (b): AS:96
        Bandwidth Modifier: AS [Application Specific (RTP session bandwidth)]
        Bandwidth Value: 96 kb/s
    Media Attribute (a): rtpmap:97 MPEG4-GENERIC/48000/2
        Media Attribute Fieldname: rtpmap
        Media Format: 97
        MIME Type: MPEG4-GENERIC
        Sample Rate: 48000
  ....
    Media Attribute (a): control:track2
        Media Attribute Fieldname: control
        Media Attribute Value: track2

  • 内容解释 :

    • ”Matroska ” :表示 因为获取的是*.mkv 格式所以 媒体类型是Matroska
    • “range” npt=0- 表示时间参数 从0开始播放 ,如果拖动则会值不同
  • 主要关注:
    上面有两个轨道 track1 track2

    扫描二维码关注公众号,回复: 2832135 查看本文章

    track1:是发送video 、负载 96、 编码方式 H264 、传输方式 RTP/AVP 、RTP 会话的带宽 500kb/s 、采样率 90 KHz
    track2: 发送 audio、负载 97 、编码方式 MPEG4-GENERIC、传输方式 RTP/AVP、RTP 会话的带宽 96 kb/s 、采样率 48000 KHz

3. SETUP Video & Audio
同时传输音频和视频两个轨道所以需要建立两个socket


VLC >>>>>============= SEND SETUP REQUEST==============>>>>> RTSPSERVER


视频

    Request: SETUP rtsp://10.0.2.15/ss1.mkv/track1 RTSP/1.0\r\n
    CSeq: 4\r\n
    User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
    Transport: RTP/AVP;unicast;client_port=49774-49775
    \r\n

音频

    Request: SETUP rtsp://10.0.2.15/ss1.mkv/track2 RTSP/1.0\r\n
    CSeq: 5\r\n
    User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
    Transport: RTP/AVP;unicast;client_port=49776-49777
    Session: AEB76530
    \r\n
  • 内容解释 :
    • ”Transport” 表示 传输模式 RTP/AVP、 unicast单播形式 、客户端接收流的端口是49774-49775
    • “CSeq” 表示每一次会话的序列号,后面依次增加 OPTIONS请求为2
  • 作用: 客户端提醒建立会话,并且确定传输模式

VLC <<<<<================= RESPONSE 200=================<<<<< RTSPSERVER


视频

    Response: RTSP/1.0 200 OK\r\n
    CSeq: 4\r\n
    Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
    Transport: RTP/AVP;unicast;destination=10.0.2.15;source=10.0.2.15;client_port=49774-49775;server_port=6970-6971
    Session: AEB76530;timeout=65
    \r\n

音频

    Response: RTSP/1.0 200 OK\r\n
    CSeq: 5\r\n
    Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
    Transport: RTP/AVP;unicast;destination=10.0.2.15;source=10.0.2.15;client_port=49776-49777;server_port=6972-6973
    Session: AEB76530;timeout=65
    \r\n
  • 内容解释 :
    • ”Transport” :表示 告诉客户端流传输模式 以及客户端和服务器的地址和端口
    • “Session” 创建好会话的唯一id
    • “timeout” 超时时间

PS: 此时 Transport 确定,表示服务器端传输 RTP 视频流的包 的socket 已经准备好了

4. PLAY


VLC >>>>>============ SEND PLAY REQUEST=============>>>>> RTSPSERVER


    Request: PLAY rtsp://10.0.2.15/ss1.mkv/ RTSP/1.0\r\n
    CSeq: 6\r\n
    User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
    Session: AEB76530
    Range: npt=0.000-\r\n
    \r\n

  • 作用: 请求服务器开始传RTP数据包了

VLC <<<<<================= RESPONSE 200==============>>>>> RTSPSERVER


    Response: RTSP/1.0 200 OK\r\n
    CSeq: 6\r\n
    Date: Thu, Aug 16 2018 06:06:51 GMT\r\n
    Range: npt=0.000-\r\n
    Session: AEB76530
    RTP-Info: url=rtsp://10.0.2.15/ss1.mkv/track1;seq=57885;rtptime=4285367567,url=rtsp://10.0.2.15/ss1.mkv/track2;seq=41406;rtptime=1364100230\r\n
    \r\n
  • 内容解释 :
    • ”RTP-Info” :表示 告诉客户端VLC 第一个视频RTP包的信息 seq 序列号 rtptime 时间戳 和第一个音频 RTP包的信息

5. TEARDOWN


VLC >>>>>============ SEND TEARDOWN REQUEST============>>>>> RTSPSERVER


    Request: TEARDOWN rtsp://10.0.2.15/ss1.mkv/ RTSP/1.0\r\n
    CSeq: 7\r\n
    User-Agent: LibVLC/3.0.3 (LIVE555 Streaming Media v2016.11.28)\r\n
    Session: AEB76530
    \r\n
  • 作用: 获取 告诉服务器 VLC 准备不接收 RTP数据,请求关闭会话AEB76530

VLC <<<<<================= RESPONSE 200================<<<<< RTSPSERVER


    Response: RTSP/1.0 200 OK\r\n
    CSeq: 7\r\n
    Date: Thu, Aug 16 2018 06:06:54 GMT\r\n
    \r\n

以上就是我测试环境的完整RTSP 协商过程
RTP : Real Time Protocol


猜你喜欢

转载自blog.csdn.net/engineer_james/article/details/81743571
今日推荐