概述
//推流需要发起invite请求 如果是大华的话这里的所有设备编号要换为通道id编号,所以为了方便起见,直接设置设备编号和通道id编号一样,海康的通道id无法设置,所以直接发设备编号也可以获取到流
INVITE sip:34020000001110000003@192.168.1.8:5060;transport=udp SIP/2.0
Call-ID: 34020000001110000003
CSeq: 1 INVITE
From: <34020000002000000001>;tag=live34020000002000000001>
To: "34020000001110000003" <34020000001110000003> //to这里不要加tag,加了的话海康会返回找到id,大华则没事34020000001110000003>
Via: SIP/2.0/UDP 0.0.0.0:5060;branch=branchlive
Max-Forwards: 70
Content-Type: Application/sdp //消息类型
Contact: <34020000002000000001>34020000002000000001>
Supported: 100re1 //这个好像不影响,百度的
Subject: 34020000001110000003:0100000003,34020000002000000001:0 //海康要加该请求头
User-Agent: fyl //自定义的一些信息
Content-Length: 232 //这里要计算的消息体大小
v=0
o=34020000001110000003 0 0 IN IP4 192.168.1.201
s=Play
c=IN IP4 192.168.1.201 //流媒体服务器ip
t=0 0
m=video 10002 TCP/RTP/AVP 96 98 97 //这里的TCP/RTP/AVP代表是tcp推流模式(tcp分为主动tcp和被动tcp,默认直接就是摄像头推流),udp推流为RTP/AVP 10002是流媒体服务器的端口号,建议偶数端口
a=recvonly
a=rtpmap:96 PS/90000
a=rtpmap:98 H264/90000
a=rtpmap:97 MPEG4/90000
y=0100000003 //这里y是ssrc信息,采用多个设备共享一个推流端口时需要使用这个标识来判断是那个摄像头的流
f=
//当我们发起推流请求之后,摄像头会回复3次信息,海康只回复2次,我们看最后一次信息回复就行
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 0.0.0.0:5060;branch=branchlive;received=192.168.1.201
From: <34020000002000000001>;tag=live34020000002000000001>
To: "34020000001110000003" <34020000001110000003>34020000001110000003>
Call-ID: 34020000001110000003
CSeq: 1 INVITE
User-Agent: Dahua SIP UAS V1.0
Content-Length: 0
//第二次回复,测试的海康摄像头没有这个信息回复
SIP/2.0 101 Dialog Establishement
Via: SIP/2.0/UDP 0.0.0.0:5060;branch=branchlive;received=192.168.1.201
From: <34020000002000000001>;tag=live34020000002000000001>
To: "34020000001110000003" <34020000001110000003>;tag=2993764134020000001110000003>
Call-ID: 34020000001110000003
CSeq: 1 INVITE
Contact: <34020000001110000003>34020000001110000003>
User-Agent: Dahua SIP UAS V1.0
Content-Length: 0
//最后一次回复,注意这次回复,如果是200说明请求成功,只要我们回复ack摄像头就会开始推流,如果不是200说明信息有误,一般都是设备编号或者通道编号,再或者tag的一些信息有误,海康对tag比较敏感
SIP/2.0 200 OK
Via: SIP/2.0/UDP 0.0.0.0:5060;branch=branchlive;received=192.168.1.201
From: <34020000002000000001>;tag=live //这个字段要保存起来34020000002000000001>
To: "34020000001110000003" <34020000001110000003>;tag=29937641 //这个字段要也保存起来,可以看到tag是摄像头生成的34020000001110000003>
Call-ID: 34020000001110000003 //同上
CSeq: 1 INVITE //注意这里的标识,这个标识跟推流请求一样说明是对应推流的回复
Contact: <34020000001110000003>34020000001110000003>
User-Agent: Dahua SIP UAS V1.0
Content-Type: application/sdp
Content-Length: 260
v=0
o=34020000001110000003 0 0 IN IP4 192.168.1.8
s=Play
i=VCam Live Video
c=IN IP4 192.168.1.8
t=0 0
m=video 9702 TCP/RTP/AVP 96
a=sendonly
a=rtpmap:96 PS/90000
a=streamprofile:0
a=setup:active
a=connection:new
y=0100000003
f=v/0/0/0/0/0a/0/0/0
//收到200回复之后,保存from,to和Call-ID 这三个字段在断流时需要用到,如果三个字段有变动都无法进行断流,特别是海康,差一点都不行,会回复找不到callid
ACK sip:34020000001110000003@192.168.1.8:5060 SIP/2.0
Call-ID: 34020000001110000003
CSeq: 1 ACK
Via: SIP/2.0/UDP 34020000002000000001:5060;branch=z9hG4bK-353633-cc1d42f582e2ec40dfedb6812f9ab1b8
From: <34020000002000000001>;tag=live34020000002000000001>
To: "34020000001110000003" <34020000001110000003>;tag=2993764134020000001110000003>
Max-Forwards: 70
Content-Length: 0
//结束推流请求 把上面保存的值放进来
BYE sip:34020000001110000003@192.168.1.8:5060;transport=udp SIP/2.0
Call-ID: 34020000001110000003
CSeq: 6 BYE
From: <34020000002000000001>;tag=live34020000002000000001>
To: "34020000001110000003" <34020000001110000003>;tag=2993764134020000001110000003>
Via: SIP/2.0/UDP 0.0.0.0:5060;branch=branchbye
Contact: <34020000002000000001>34020000002000000001>
Max-Forwards: 70
Content-Length: 0
//摄像头回复200说明断流成功
SIP/2.0 200 OK
Via: SIP/2.0/UDP 0.0.0.0:5060;branch=branchbye;received=192.168.1.201
From: <34020000002000000001>;tag=live34020000002000000001>
To: "34020000001110000003" <34020000001110000003>;tag=2993764134020000001110000003>
Call-ID: 34020000001110000003
CSeq: 6 BYE
User-Agent: Dahua SIP UAS V1.0
Content-Length: 0
最后
以上就是外向硬币为你收集整理的java socket保活_gb28181简单实现sip信令服务器(java版基于springboot):四、sip摄像头心跳保活、推流(tcp/udp)和结束推流...的全部内容,希望文章能够帮你解决java socket保活_gb28181简单实现sip信令服务器(java版基于springboot):四、sip摄像头心跳保活、推流(tcp/udp)和结束推流...所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复