C++音视频

代码改变世界

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

对大华和海康的设备使用VLC播放抓包,分析如下

大华IPC的RTSP抓包

使用vlc(V3.0.4)播放抓包

#<<<<<< client发起OPTIONS请求
OPTIONS rtsp://192.168.35.52:554/stream/live?channel=1&type=0 RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.4 (LIVE555 Streaming Media v2016.11.28)

#>>>>>> server返回401需要鉴权,返回了Digest鉴权需要的realm和nonce信息
#大部分的鉴权都是在DESCRIBE请求中,大华的是在OPTIONS
RTSP/1.0 401 Unauthorized
CSeq: 5
WWW-Authenticate: Digest realm="Login to 210235H0211199A00001", nonce="98c6f819e476abd44cbcf2847f760364"

#<<<<<< client再次发起请求,根据realm,nonce,uri,method,user,passwd计算出response
OPTIONS rtsp://192.168.35.52:554/stream/live?channel=1&type=0 RTSP/1.0
CSeq: 6
Authorization: Digest username="admin", realm="Login to 210235H0211199A00001", nonce="98c6f819e476abd44cbcf2847f760364", uri="rtsp://192.168.35.52:554/stream/live?channel=1&type=0", response="c968a1a0e0584581f4e8444931063492"
User-Agent: LibVLC/3.0.4 (LIVE555 Streaming Media v2016.11.28)

#>>>>>> server使用鉴权信息进行鉴权,鉴权通过后,正常返回OPTIONS请求,Public字段标识了server能接受处理的method
RTSP/1.0 200 OK
CSeq: 6
Server: Rtsp Server/3.0
Public: OPTIONS, DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, TEARDOWN, SET_PARAMETER, GET_PARAMETER

#<<<<<< client使用DESCRIBE方法请求SDP信息,后续的每次请求都要带上鉴权信息,因为计算response的method每次不一样,所以response每次不一样
DESCRIBE rtsp://192.168.35.52:554/stream/live?channel=1&type=0 RTSP/1.0
CSeq: 7
Authorization: Digest username="admin", realm="Login to 210235H0211199A00001", nonce="98c6f819e476abd44cbcf2847f760364", uri="rtsp://192.168.35.52:554/stream/live?channel=1&type=0", response="8ee8c308cd7e31c3f06ca6e56cfbd61c"
User-Agent: LibVLC/3.0.4 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp

#>>>>>> server内部产生SDP信息完成,返回200 OK,通过content携带SDP
RTSP/1.0 200 OK
CSeq: 7
x-Accept-Dynamic-Rate: 1
Content-Base: rtsp://192.168.35.52:554/stream/live?channel=1&type=0/
Cache-Control: must-revalidate
Content-Length: 473
Content-Type: application/sdp

v=0               #sdp协议版本,一般为0
o=- 2252219884 2252219884 IN IP4 0.0.0.0   #owner,必选字段,对会话发起者的一个信息描述,其中包含了用户名、会话ID、网络地址等信息,格式是o=<username> <session id> <version> <network type> <address>
s=server          #session name,表示的会话名称,必选字段。在整个SDP里面只有一个会话名称,有且仅有一个这样的字段
c=IN IP4 0.0.0.0  #连接信息,c=<network type> <address type> <connection address>
t=0 0             #time the session is active,必选字段,表示的是该会话的开始到结束时间,如果是持久会话,则时间值填0,NTP时间,单位是秒,t=<start time> <stop time>
a=control:*
a=packetization-supported:dahua
a=rtppayload-supported:dahua
a=range:npt=now-
m=video 0 RTP/AVP 96    #视频信息,m=<media> <port> <transport> <fmt list>
a=control:trackID=0     #控制标识符,setup的时候会用上
a=framerate:25.000000   #帧率
a=rtpmap:96 H264/90000  #rtpmap信息
a=fmtp:96 packetization-mode=1;profile-level-id=64002A;sprop-parameter-sets=Z2QAKqwsaoHgCJ+WbgICAoAAA4QAAK/IQgA=,aO48sAA=   #视频编码和封装信息,来自于SPS和PPS
a=recvonly              #接收SDP的一方(client)只能接收media而不能发送和控制,【不知道这样理解是否正确!】
m=audio 0 RTP/AVP 97
a=control:trackID=2
a=rtpmap:97 PCMA/8000   #audio payload=97,G711A,采样率8KHz
a=recvonly              #接收SDP的一方(client)只能接收media而不能发送和控制,【不知道这样理解是否正确!】

#<<<<<< client使用trackID=0来setup视频
SETUP rtsp://192.168.35.52:554/stream/live?channel=1&type=0/trackID=0 RTSP/1.0
CSeq: 8
Authorization: Digest username="admin", realm="Login to 210235H0211199A00001", nonce="98c6f819e476abd44cbcf2847f760364", uri="rtsp://192.168.35.52:554/stream/live?channel=1&type=0/", response="182e5b239cd41d67a9be3841c7182042"
User-Agent: LibVLC/3.0.4 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP/TCP;unicast;interleaved=0-1  #传输方式TCP,rtp的交织通道0-1,即0传输rtp,1传输rtcp

#>>>>>> server应答200 OK
RTSP/1.0 200 OK
CSeq: 8
Session: 281711850569;timeout=60  #setup后产生session Id,后续使用此session来控制此会话,会话超时时间是60秒
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=7D049D12  #返回视频rtp中的SSRC
x-Dynamic-Rate: 1

#<<<<<< client使用trackID=2来setup音频
SETUP rtsp://192.168.35.52:554/stream/live?channel=1&type=0/trackID=2 RTSP/1.0
CSeq: 9
Authorization: Digest username="admin", realm="Login to 210235H0211199A00001", nonce="98c6f819e476abd44cbcf2847f760364", uri="rtsp://192.168.35.52:554/stream/live?channel=1&type=0/", response="182e5b239cd41d67a9be3841c7182042"
User-Agent: LibVLC/3.0.4 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
Session: 281711850569   #带上之前的session

#>>>>>> server返回200 OK
RTSP/1.0 200 OK
CSeq: 9
Session: 281711850569;timeout=60
Transport: RTP/AVP/TCP;unicast;interleaved=4-5;ssrc=285981E4   #返回音频RTP中的SSRC
x-Dynamic-Rate: 1

#<<<<<< client发起PLAY请求,开始播放
PLAY rtsp://192.168.35.52:554/stream/live?channel=1&type=0/ RTSP/1.0
CSeq: 10
Authorization: Digest username="admin", realm="Login to 210235H0211199A00001", nonce="98c6f819e476abd44cbcf2847f760364", uri="rtsp://192.168.35.52:554/stream/live?channel=1&type=0/", response="cc8c5e07d13d8b62f2291222de2c81d1"
User-Agent: LibVLC/3.0.4 (LIVE555 Streaming Media v2016.11.28)
Session: 281711850569
Range: npt=0.000-  #时间从0开始一直播

#>>>>>> server返回成功,并携带当前音视频rtp包的seq和rtp时间
RTSP/1.0 200 OK
CSeq: 10
Session: 281711850569
Range: npt=0.000000-
RTP-Info: url=trackID=0;seq=40210;rtptime=40210,url=trackID=2;seq=40210;rtptime=40210  #这个时间有用的,播放器将这个rtp时间作为时间0的基准,后续rtp时间在这个时间上累加

#>>>>>> server发送rtp over tcp数据,client解码播放
$..0....}....pu..&.x................}.....(none)....$..0....(Y...pu..&.x................(Y....(none)....$..&.`......}...gd.*.,j.....n...........B.$....`......}...h.<..$....`......}.........$....`......}...|....V.......,..L..........J-.(~..s$b.....r..H...@..mG.[ut....i....S.dK.. *IsN6..-.1...L.."...........w5cl.{.1......8.]sk.W..{M.......a$=!.C.h)...o.h%2.s\=.f..p....^.@d.....
..2.+tSh..h...7.?..;.....uN.y...f.j.Y.......

#在播放中client会使用GET_PARAMETER来保活,由于播放时间短,没有抓到GET_PARAMETER

#<<<<<< client发起teardown
TEARDOWN rtsp://192.168.35.52:554/stream/live?channel=1&type=0/ RTSP/1.0
CSeq: 11
Authorization: Digest username="admin", realm="Login to 210235H0211199A00001", nonce="98c6f819e476abd44cbcf2847f760364", uri="rtsp://192.168.35.52:554/stream/live?channel=1&type=0/", response="aa8368588a8c24ab119df2417c7c5365"
User-Agent: LibVLC/3.0.4 (LIVE555 Streaming Media v2016.11.28)
Session: 281711850569

#>>>>>> server应答:有些服务端没有发动这个应答;客户端在发送了teardown之后可以直接关闭了socket,如果server应答,可以会收一个scoket RST错误,需要服务端正常处理这个错误。
RTSP/1.0 200 OK
CSeq: 11
Session: 281711850569

海康球机RTSP抓包

使用vlc(V3.0.12)播放抓包

OPTIONS rtsp://192.168.16.34:554/h264/ch33/main/av_stream RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.12 (LIVE555 Streaming Media v2016.11.28)

RTSP/1.0 200 OK
CSeq: 2
Public: OPTIONS, DESCRIBE, PLAY, PAUSE, SETUP, TEARDOWN, SET_PARAMETER, GET_PARAMETER
Date:  Tue, Feb 22 2022 10:14:29 GMT

DESCRIBE rtsp://192.168.16.34:554/h264/ch33/main/av_stream RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.12 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp

RTSP/1.0 401 Unauthorized
CSeq: 3
WWW-Authenticate: Digest realm="IP Camera(F4938)", nonce="31277f661a3c0f81357fb5e1e8d750fb", stale="FALSE"
Date:  Tue, Feb 22 2022 10:14:29 GMT

DESCRIBE rtsp://192.168.16.34:554/h264/ch33/main/av_stream RTSP/1.0
CSeq: 4
Authorization: Digest username="admin", realm="IP Camera(F4938)", nonce="31277f661a3c0f81357fb5e1e8d750fb", uri="rtsp://192.168.16.34:554/h264/ch33/main/av_stream", response="02ab03079911d3310c0e27381f53be86"
User-Agent: LibVLC/3.0.12 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp

RTSP/1.0 200 OK
CSeq: 4
Content-Type: application/sdp
Content-Base: rtsp://192.168.16.34:554/h264/ch33/main/av_stream/
Content-Length: 913

v=0
o=- 1645524869629081 1645524869629081 IN IP4 192.168.16.34
s=Media Presentation
e=NONE
b=AS:5100
t=0 0
a=control:rtsp://192.168.16.34:554/h264/ch33/main/av_stream/
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:5000
a=recvonly
a=x-dimensions:1920,1080
a=control:rtsp://192.168.16.34:554/h264/ch33/main/av_stream/trackID=1
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=420029; packetization-mode=1; sprop-parameter-sets=Z00AKp2oHgCJ+WbgICAoAAADAAgAAAMBlCA=,aO48gA==
m=audio 0 RTP/AVP 104
c=IN IP4 0.0.0.0
b=AS:50
a=recvonly
a=control:rtsp://192.168.16.34:554/h264/ch33/main/av_stream/trackID=2
a=rtpmap:104 mpeg4-generic/16000/1
a=fmtp:104 profile-level-id=15; streamtype=5; mode=AAC-hbr; config=1408;SizeLength=13; IndexLength=3; IndexDeltaLength=3; Profile=1;
a=Media_header:MEDIAINFO=494D4B48010300000400000101200110803E0000803E000000000000000000000000000000000000;
a=appversion:1.0

SETUP rtsp://192.168.16.34:554/h264/ch33/main/av_stream/trackID=1 RTSP/1.0
CSeq: 5
Authorization: Digest username="admin", realm="IP Camera(F4938)", nonce="31277f661a3c0f81357fb5e1e8d750fb", uri="rtsp://192.168.16.34:554/h264/ch33/main/av_stream/", response="daa3a88726f594e6259397a926e9b8bf"
User-Agent: LibVLC/3.0.12 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP/TCP;unicast;interleaved=0-1

RTSP/1.0 200 OK
CSeq: 5
Session:       1634182432;timeout=60
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=2b9d9e4d;mode="play"
Date:  Tue, Feb 22 2022 10:14:29 GMT

SETUP rtsp://192.168.16.34:554/h264/ch33/main/av_stream/trackID=2 RTSP/1.0
CSeq: 6
Authorization: Digest username="admin", realm="IP Camera(F4938)", nonce="31277f661a3c0f81357fb5e1e8d750fb", uri="rtsp://192.168.16.34:554/h264/ch33/main/av_stream/", response="daa3a88726f594e6259397a926e9b8bf"
User-Agent: LibVLC/3.0.12 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP/TCP;unicast;interleaved=2-3
Session: 1634182432

RTSP/1.0 200 OK
CSeq: 6
Session:       1634182432;timeout=60
Transport: RTP/AVP/TCP;unicast;interleaved=2-3;ssrc=04ec6f8a;mode="play"
Date:  Tue, Feb 22 2022 10:14:29 GMT

PLAY rtsp://192.168.16.34:554/h264/ch33/main/av_stream/ RTSP/1.0
CSeq: 7
Authorization: Digest username="admin", realm="IP Camera(F4938)", nonce="31277f661a3c0f81357fb5e1e8d750fb", uri="rtsp://192.168.16.34:554/h264/ch33/main/av_stream/", response="1eba337b05b43cf2f4871f45e2238335"
User-Agent: LibVLC/3.0.12 (LIVE555 Streaming Media v2016.11.28)
Session: 1634182432
Range: npt=0.000-

RTSP/1.0 200 OK
CSeq: 7
Session:       1634182432
RTP-Info: url=rtsp://192.168.16.34:554/h264/ch33/main/av_stream/trackID=1;seq=46133;rtptime=860427054,url=rtsp://192.168.16.34:554/h264/ch33/main/av_stream/trackID=2;seq=22405;rtptime=1870951888
Date:  Tue, Feb 22 2022 10:14:29 GMT

$..(.`.53I..+..MgM.*......f.  (.......... ..$....`.63I..+..Mh.<.$....`.73I..+..M........$....`.83I..+..M|......../..f....:.+.|.{"|..U..........$y>mg+m.@.1..y.}.z~.....]..b.L....|Dr...o....o....@..A..b..!...AL.#...Px..nag.......SiB. .g...z@.........4O.Ug..N{....N..G...-|.......-E.........o+.......>.q...._..<.2...5q..S..YR_|.\2-....^..._.[.......e|~..$..l..G.......k..{*H..p	29..5.:U.W.;w...-.+.
.j..;.UR>../*..G.Y.gaL..x......d..w.5F..?C...P.{..	t.. sl.t.`%'.8.p=........b0..}.nLt........0....9B....M.No....c."}.c

TEARDOWN rtsp://192.168.16.34:554/h264/ch33/main/av_stream/ RTSP/1.0
CSeq: 8
Authorization: Digest username="admin", realm="IP Camera(F4938)", nonce="31277f661a3c0f81357fb5e1e8d750fb", uri="rtsp://192.168.16.34:554/h264/ch33/main/av_stream/", response="a19c25d9aaf6fc479ffc2c29702d1e9f"
User-Agent: LibVLC/3.0.12 (LIVE555 Streaming Media v2016.11.28)
Session: 1634182432
#未看到TEARSOWN的应答
posted on 2022-02-22 10:35  shunxiang  阅读(1002)  评论(0编辑  收藏  举报