1. 程式人生 > >RTSP協議與G711 AAC

RTSP協議與G711 AAC

文章目錄

文件

如果想要完全理解rtsp相關的技術, 需要閱讀以下文件資料:
rtsp協議 https://tools.ietf.org/html/rfc2326
sdp協議 https://tools.ietf.org/html/rfc2327
rtp/rtcp協議 https://tools.ietf.org/html/rfc3550


rtp H.264資料格式封裝 https://tools.ietf.org/html/rfc6184
rtp/sdp中aac/mpeg4的相關協議 https://tools.ietf.org/html/rfc3640
rtp/sdp中G.711相關協議 https://tools.ietf.org/html/rfc5391
RTSP客戶端工具vlc: https://www.videolan.org/
RTSP服務端工具: 考慮到搭建rtsp伺服器很費事, 可以使用vlc的串流功能
本機的網路抓包工具: https://www.netresec.com/?page=RawCap

RTSP/RTP over TCP + G711

OPTIONS

客戶端傳送

OPTIONS rtsp://192.168.2.232:8456/test RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)

伺服器回覆

RTSP/1.0 200 OK
CSeq: 2
Content-Length: 0
Cache-Control: no-cache
Public: DESCRIBE,SETUP,TEARDOWN,PLAY

DESCRIBE

VLC傳送

DESCRIBE rtsp://192.168.2.232:8456/test RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
method: describe

服務端回覆

RTSP/1.0 200 OK
CSeq: 3
Accept: application/sdp
Cache-Control: no-cache
Content-Length: 522

v=0
o=- 1546226325720 1546226325720 IN IP4 Eques
s=Unnamed
i=N/A
c=IN IP4 0.0.0.0
t=0 0
a=recvonly
a=type:broadcast
a=control:rtsp://192.168.2.232:8456/test/
m=audio 0 RTP/AVP 98
a=rtpmap:98 PCMA/22050/1
a=fmtp:98 complaw=al;
a=control:rtsp://192.168.2.232:8456/test/trackID=0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=42c014;sprop-parameter-sets=Z0LAFKtAoP0IAAADAAgAAAMBRwIABkAAAMgBaxsDxQqo,KM48gA==;
a=control:rtsp://192.168.2.232:8456/test/trackID=1

SETUP

因為有音訊和視訊兩路流, 所以需要setup兩次

SETUP rtsp://192.168.2.232:8456/test/trackID=0 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
method: setup
handle setup request
RTSP/1.0 200 OK
CSeq: 4
Cache-Control: no-cache
Content-Length: 0
Session: uYu2RlouWJBByDn1;timeout=60
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
SETUP rtsp://192.168.2.232:8456/test/trackID=1 RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
Session: uYu2RlouWJBByDn1
method: setup
handle setup request
RTSP/1.0 200 OK
CSeq: 5
Cache-Control: no-cache
Content-Length: 0
Session: uYu2RlouWJBByDn1;timeout=60
Transport: RTP/AVP/TCP;unicast;interleaved=2-3

PLAY

PLAY rtsp://192.168.2.232:8456/test/ RTSP/1.0
CSeq: 6
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Session: uYu2RlouWJBByDn1
Range: npt=0.000-
method: play
RTSP/1.0 200 OK
CSeq: 6
Content-Length: 0
Cache-Control: no-cache
Session: uYu2RlouWJBByDn1;timeout=60
RTP-Info: url=rtsp://192.168.2.232:8456/test/trackID=0;seq=0;rtptime=0,url=rtsp://192.168.2.232:8456/test/trackID=1;seq=0;rtptime=0
Range: npt=0.000-

TEARDOWN

TEARDOWN rtsp://192.168.2.232:8456/test/ RTSP/1.0
CSeq: 7
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Session: uYu2RlouWJBByDn1

RTP over TCP的封裝格式

文件在 https://tools.ietf.org/html/rfc2326#page-40
音視訊資料新增RTP頭之後, 還要再新增4個位元組頭, 它的格式為

       0                   1                      2                   3
   ----------------------------------------------------------------------------------
   | $ (美元符號)  |   channel id    |     rtp包大小(2位元組, 網路位元組序)
   ----------------------------------------------------------------------------------

RTPS/RTP over UDP + AAC

rtsp的基本流程還是一樣的, 只是部分引數的差別

DESCRIBE rtsp://192.168.2.232:8456/test RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
RTSP/1.0 200 OK
CSeq: 3
Accept: application/sdp
Cache-Control: no-cache
Content-Length: 635

v=0
o=- 1546233621391 1546233621391 IN IP4 Eques
s=Unnamed
i=N/A
c=IN IP4 0.0.0.0
t=0 0
a=recvonly
a=type:broadcast
a=control:rtsp://192.168.2.232:8456/test/
m=audio 0 RTP/AVP 97
a=rtpmap:97 mpeg4-generic/22050/1
a=fmtp:97 mode=AAC-hbr;streamtype=5;IndexDeltaLength=3;profile-level-id=15;config=0b88;SizeLength=13;IndexLength=3;Profile=1;
a=control:rtsp://192.168.2.232:8456/test/trackID=0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=42c014;sprop-parameter-sets=Z0LAFKtAoP0IAAADAAgAAAMBRwIABkAAAMgBaxsDxQqo,KM48gA==;
a=control:rtsp://192.168.2.232:8456/test/trackID=1
SETUP rtsp://192.168.2.232:8456/test/trackID=0 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=52122-52123
method: setup
RTSP/1.0 200 OK
CSeq: 4
Cache-Control: no-cache
Content-Length: 0
Session: gixEa5aMd6gd3ZWZ;timeout=60
Transport: RTP/AVP;unicast;client_port=52122-52123;server_port=33697-33698
SETUP rtsp://192.168.2.232:8456/test/trackID=1 RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=52124-52125
Session: gixEa5aMd6gd3ZWZ
    RTSP/1.0 200 OK
    CSeq: 5
    Cache-Control: no-cache
    Content-Length: 0
    Session: gixEa5aMd6gd3ZWZ;timeout=60
    Transport: RTP/AVP;unicast;client_port=52124-52125;server_port=51830-51831
    PLAY rtsp://192.168.2.232:8456/test/ RTSP/1.0
    CSeq: 6
    User-Agent: LibVLC/3.0.5 (LIVE555 Streaming Media v2016.11.28)
    Session: gixEa5aMd6gd3ZWZ
    Range: npt=0.000-
    RTSP/1.0 200 OK
    CSeq: 6
    Content-Length: 0
    Cache-Control: no-cache
    Session: gixEa5aMd6gd3ZWZ;timeout=60
    RTP-Info: url=rtsp://192.168.2.232:8456/test/trackID=0;seq=0;rtptime=0,url=rtsp://192.168.2.232:8456/test/trackID=1;seq=0;rtptime=0
    Range: npt=0.000-