mirror of https://github.com/swwheihei/wvp.git
修复回放、停止预览bug,增加ZLM hook监听,长时间无人观看,停止摄像头推流。需开启ZLM的hook并配置url
parent
1b6f0137b9
commit
805fa42a2c
1
pom.xml
1
pom.xml
|
@ -123,7 +123,6 @@
|
||||||
<groupId>javax.sip</groupId>
|
<groupId>javax.sip</groupId>
|
||||||
<artifactId>jain-sip-ri</artifactId>
|
<artifactId>jain-sip-ri</artifactId>
|
||||||
<version>1.3.0-91</version>
|
<version>1.3.0-91</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.dom4j</groupId>
|
<groupId>org.dom4j</groupId>
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class SsrcUtil {
|
||||||
|
|
||||||
private static void init() {
|
private static void init() {
|
||||||
SipConfig sipConfig = (SipConfig) SpringBeanFactory.getBean("sipConfig");
|
SipConfig sipConfig = (SipConfig) SpringBeanFactory.getBean("sipConfig");
|
||||||
ssrcPrefix = sipConfig.getSipDomain().substring(4, 9);
|
ssrcPrefix = sipConfig.getSipDomain().substring(3, 8);
|
||||||
isUsed = new ArrayList<String>();
|
isUsed = new ArrayList<String>();
|
||||||
notUsed = new ArrayList<String>();
|
notUsed = new ArrayList<String>();
|
||||||
for (int i = 1; i < 10000; i++) {
|
for (int i = 1; i < 10000; i++) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.Host;
|
import com.genersoft.iot.vmp.gb28181.bean.Host;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:TODO(这里用一句话描述这个类的作用)
|
* @Description:摄像头命令request创造器 TODO 冗余代码太多待优化
|
||||||
* @author: songww
|
* @author: songww
|
||||||
* @date: 2020年5月6日 上午9:29:02
|
* @date: 2020年5月6日 上午9:29:02
|
||||||
*/
|
*/
|
||||||
|
@ -72,50 +72,50 @@ public class SIPRequestHeaderProvider {
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Request createInviteRequest(Device device, String content, String viaTag, String fromTag, String toTag) throws ParseException, InvalidArgumentException {
|
public Request createInviteRequest(Device device, String channelId, String content, String viaTag, String fromTag, String toTag) throws ParseException, InvalidArgumentException {
|
||||||
// Request request = null;
|
Request request = null;
|
||||||
// Host host = device.getHost();
|
Host host = device.getHost();
|
||||||
// //请求行
|
//请求行
|
||||||
// SipURI requestLine = layer.getAddressFactory().createSipURI(device.getDeviceId(), host.getAddress());
|
SipURI requestLine = layer.getAddressFactory().createSipURI(channelId, host.getAddress());
|
||||||
// //via
|
//via
|
||||||
// ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||||
// ViaHeader viaHeader = layer.getHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag);
|
ViaHeader viaHeader = layer.getHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), device.getTransport(), viaTag);
|
||||||
// viaHeader.setRPort();
|
viaHeader.setRPort();
|
||||||
// viaHeaders.add(viaHeader);
|
viaHeaders.add(viaHeader);
|
||||||
// //from
|
//from
|
||||||
// SipURI fromSipURI = layer.getAddressFactory().createSipURI(device.getDeviceId(),sipConfig.getSipIp()+":"+sipConfig.getSipPort());
|
SipURI fromSipURI = layer.getAddressFactory().createSipURI(sipConfig.getSipId(),sipConfig.getSipDomain());
|
||||||
// Address fromAddress = layer.getAddressFactory().createAddress(fromSipURI);
|
Address fromAddress = layer.getAddressFactory().createAddress(fromSipURI);
|
||||||
// FromHeader fromHeader = layer.getHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
|
FromHeader fromHeader = layer.getHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
|
||||||
// //to
|
//to
|
||||||
// SipURI toSipURI = layer.getAddressFactory().createSipURI(device.getDeviceId(),host.getAddress());
|
SipURI toSipURI = layer.getAddressFactory().createSipURI(channelId,sipConfig.getSipDomain());
|
||||||
// Address toAddress = layer.getAddressFactory().createAddress(toSipURI);
|
Address toAddress = layer.getAddressFactory().createAddress(toSipURI);
|
||||||
// ToHeader toHeader = layer.getHeaderFactory().createToHeader(toAddress,null);
|
ToHeader toHeader = layer.getHeaderFactory().createToHeader(toAddress,null);
|
||||||
//
|
|
||||||
// //callid
|
//callid
|
||||||
// CallIdHeader callIdHeader = null;
|
CallIdHeader callIdHeader = null;
|
||||||
// if(device.getTransport().equals("TCP")) {
|
if(device.getTransport().equals("TCP")) {
|
||||||
// callIdHeader = layer.getTcpSipProvider().getNewCallId();
|
callIdHeader = layer.getTcpSipProvider().getNewCallId();
|
||||||
// }
|
}
|
||||||
// if(device.getTransport().equals("UDP")) {
|
if(device.getTransport().equals("UDP")) {
|
||||||
// callIdHeader = layer.getUdpSipProvider().getNewCallId();
|
callIdHeader = layer.getUdpSipProvider().getNewCallId();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// //Forwards
|
//Forwards
|
||||||
// MaxForwardsHeader maxForwards = layer.getHeaderFactory().createMaxForwardsHeader(70);
|
MaxForwardsHeader maxForwards = layer.getHeaderFactory().createMaxForwardsHeader(70);
|
||||||
//
|
|
||||||
// //ceq
|
//ceq
|
||||||
// CSeqHeader cSeqHeader = layer.getHeaderFactory().createCSeqHeader(1L, Request.INVITE);
|
CSeqHeader cSeqHeader = layer.getHeaderFactory().createCSeqHeader(1L, Request.INVITE);
|
||||||
// request = layer.getMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
|
request = layer.getMessageFactory().createRequest(requestLine, Request.INVITE, callIdHeader, cSeqHeader,fromHeader, toHeader, viaHeaders, maxForwards);
|
||||||
//
|
|
||||||
// Address concatAddress = layer.getAddressFactory().createAddress(layer.getAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort()));
|
Address concatAddress = layer.getAddressFactory().createAddress(layer.getAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort()));
|
||||||
// request.addHeader(layer.getHeaderFactory().createContactHeader(concatAddress));
|
request.addHeader(layer.getHeaderFactory().createContactHeader(concatAddress));
|
||||||
//
|
|
||||||
// ContentTypeHeader contentTypeHeader = layer.getHeaderFactory().createContentTypeHeader("Application", "SDP");
|
ContentTypeHeader contentTypeHeader = layer.getHeaderFactory().createContentTypeHeader("Application", "SDP");
|
||||||
// request.setContent(content, contentTypeHeader);
|
request.setContent(content, contentTypeHeader);
|
||||||
// return request;
|
return request;
|
||||||
// }
|
}
|
||||||
|
|
||||||
public Request createInviteRequest(Device device, String content, String viaTag, String fromTag, String toTag) throws ParseException, InvalidArgumentException {
|
public Request createPlaybackInviteRequest(Device device, String channelId, String content, String viaTag, String fromTag, String toTag) throws ParseException, InvalidArgumentException {
|
||||||
Request request = null;
|
Request request = null;
|
||||||
Host host = device.getHost();
|
Host host = device.getHost();
|
||||||
//请求行
|
//请求行
|
||||||
|
@ -130,7 +130,7 @@ public class SIPRequestHeaderProvider {
|
||||||
Address fromAddress = layer.getAddressFactory().createAddress(fromSipURI);
|
Address fromAddress = layer.getAddressFactory().createAddress(fromSipURI);
|
||||||
FromHeader fromHeader = layer.getHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
|
FromHeader fromHeader = layer.getHeaderFactory().createFromHeader(fromAddress, fromTag); //必须要有标记,否则无法创建会话,无法回应ack
|
||||||
//to
|
//to
|
||||||
SipURI toSipURI = layer.getAddressFactory().createSipURI(device.getDeviceId(),sipConfig.getSipDomain());
|
SipURI toSipURI = layer.getAddressFactory().createSipURI(channelId,sipConfig.getSipDomain());
|
||||||
Address toAddress = layer.getAddressFactory().createAddress(toSipURI);
|
Address toAddress = layer.getAddressFactory().createAddress(toSipURI);
|
||||||
ToHeader toHeader = layer.getHeaderFactory().createToHeader(toAddress,null);
|
ToHeader toHeader = layer.getHeaderFactory().createToHeader(toAddress,null);
|
||||||
|
|
||||||
|
|
|
@ -142,30 +142,31 @@ public class SIPCommander implements ISIPCommander {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String ssrc = streamSession.createPlaySsrc();
|
String ssrc = streamSession.createPlaySsrc();
|
||||||
|
String transport = device.getTransport();
|
||||||
//
|
//
|
||||||
StringBuffer content = new StringBuffer(200);
|
StringBuffer content = new StringBuffer(200);
|
||||||
content.append("v=0\r\n");
|
content.append("v=0\r\n");
|
||||||
content.append("o="+channelId+" 0 0 IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
content.append("o="+channelId+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
|
||||||
content.append("s=Play\r\n");
|
content.append("s=Play\r\n");
|
||||||
content.append("c=IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
content.append("c=IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
||||||
content.append("t=0 0\r\n");
|
content.append("t=0 0\r\n");
|
||||||
if(device.getTransport().equals("TCP")) {
|
if("TCP".equals(transport)) {
|
||||||
content.append("m=video "+sipConfig.getMediaPort()+" TCP/RTP/AVP 96 98 97\r\n");
|
content.append("m=video "+sipConfig.getMediaPort()+" TCP/RTP/AVP 96 98 97\r\n");
|
||||||
}
|
}
|
||||||
if(device.getTransport().equals("UDP")) {
|
if("UDP".equals(transport)) {
|
||||||
content.append("m=video "+sipConfig.getMediaPort()+" RTP/AVP 96 98 97\r\n");
|
content.append("m=video "+sipConfig.getMediaPort()+" RTP/AVP 96 98 97\r\n");
|
||||||
}
|
}
|
||||||
content.append("a=sendrecv\r\n");
|
content.append("a=recvonly\r\n");
|
||||||
content.append("a=rtpmap:96 PS/90000\r\n");
|
content.append("a=rtpmap:96 PS/90000\r\n");
|
||||||
content.append("a=rtpmap:98 H264/90000\r\n");
|
content.append("a=rtpmap:98 H264/90000\r\n");
|
||||||
content.append("a=rtpmap:97 MPEG4/90000\r\n");
|
content.append("a=rtpmap:97 MPEG4/90000\r\n");
|
||||||
if(device.getTransport().equals("TCP")){
|
if("TCP".equals(transport)){
|
||||||
content.append("a=setup:passive\r\n");
|
content.append("a=setup:passive\r\n");
|
||||||
content.append("a=connection:new\r\n");
|
content.append("a=connection:new\r\n");
|
||||||
}
|
}
|
||||||
content.append("y="+ssrc+"\r\n");//ssrc
|
content.append("y="+ssrc+"\r\n");//ssrc
|
||||||
|
|
||||||
Request request = headerProvider.createInviteRequest(device, content.toString(), null, "live", null);
|
Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null);
|
||||||
|
|
||||||
ClientTransaction transaction = transmitRequest(device, request);
|
ClientTransaction transaction = transmitRequest(device, request);
|
||||||
streamSession.put(ssrc, transaction);
|
streamSession.put(ssrc, transaction);
|
||||||
|
@ -192,9 +193,9 @@ public class SIPCommander implements ISIPCommander {
|
||||||
//
|
//
|
||||||
StringBuffer content = new StringBuffer(200);
|
StringBuffer content = new StringBuffer(200);
|
||||||
content.append("v=0\r\n");
|
content.append("v=0\r\n");
|
||||||
content.append("o="+device.getDeviceId()+" 0 0 IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
|
||||||
content.append("s=Playback\r\n");
|
content.append("s=Playback\r\n");
|
||||||
content.append("u="+channelId+":3\r\n");
|
content.append("u="+channelId+":0\r\n");
|
||||||
content.append("c=IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
content.append("c=IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
||||||
content.append("t="+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime)+" "+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) +"\r\n");
|
content.append("t="+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime)+" "+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) +"\r\n");
|
||||||
if(device.getTransport().equals("TCP")) {
|
if(device.getTransport().equals("TCP")) {
|
||||||
|
@ -213,7 +214,7 @@ public class SIPCommander implements ISIPCommander {
|
||||||
}
|
}
|
||||||
content.append("y="+ssrc+"\r\n");//ssrc
|
content.append("y="+ssrc+"\r\n");//ssrc
|
||||||
|
|
||||||
Request request = headerProvider.createInviteRequest(device, content.toString(), null, "live", null);
|
Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "playback", null);
|
||||||
|
|
||||||
ClientTransaction transaction = transmitRequest(device, request);
|
ClientTransaction transaction = transmitRequest(device, request);
|
||||||
streamSession.put(ssrc, transaction);
|
streamSession.put(ssrc, transaction);
|
||||||
|
@ -245,7 +246,7 @@ public class SIPCommander implements ISIPCommander {
|
||||||
}
|
}
|
||||||
Request byeRequest = dialog.createRequest(Request.BYE);
|
Request byeRequest = dialog.createRequest(Request.BYE);
|
||||||
ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
|
ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
|
||||||
String protocol = viaHeader.getTransport();
|
String protocol = viaHeader.getTransport().toUpperCase();
|
||||||
ClientTransaction clientTransaction = null;
|
ClientTransaction clientTransaction = null;
|
||||||
if("TCP".equals(protocol)) {
|
if("TCP".equals(protocol)) {
|
||||||
clientTransaction = sipLayer.getTcpSipProvider().getNewClientTransaction(byeRequest);
|
clientTransaction = sipLayer.getTcpSipProvider().getNewClientTransaction(byeRequest);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class DateUtil {
|
||||||
Date date;
|
Date date;
|
||||||
try {
|
try {
|
||||||
date = format.parse(formatTime);
|
date = format.parse(formatTime);
|
||||||
Long timestamp=date.getTime();
|
Long timestamp=date.getTime()/1000;
|
||||||
//转换为Date类
|
//转换为Date类
|
||||||
return timestamp;
|
return timestamp;
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
|
|
|
@ -1,12 +1,21 @@
|
||||||
package com.genersoft.iot.vmp.media.zlm;
|
package com.genersoft.iot.vmp.media.zlm;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:针对 ZLMediaServer的hook事件监听
|
* @Description:针对 ZLMediaServer的hook事件监听
|
||||||
* @author: songww
|
* @author: songww
|
||||||
|
@ -18,135 +27,247 @@ public class ZLMHttpHookListener {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(ZLMHttpHookListener.class);
|
private final static Logger logger = LoggerFactory.getLogger(ZLMHttpHookListener.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SIPCommander cmder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流量统计事件,播放器或推流器断开时并且耗用流量超过特定阈值时会触发此事件,阈值通过配置文件general.flowThreshold配置;此事件对回复不敏感。
|
* 流量统计事件,播放器或推流器断开时并且耗用流量超过特定阈值时会触发此事件,阈值通过配置文件general.flowThreshold配置;此事件对回复不敏感。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_flow_report")
|
@ResponseBody
|
||||||
public ResponseEntity onFlowReport(){
|
@PostMapping(value = "/on_flow_report", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onFlowReport(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_flow_report API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
|
||||||
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("msg", "success");
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 访问http文件服务器上hls之外的文件时触发。
|
* 访问http文件服务器上hls之外的文件时触发。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_http_access")
|
@ResponseBody
|
||||||
public ResponseEntity onHttpAccess(){
|
@PostMapping(value = "/on_http_access", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onHttpAccess(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_http_access API 调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("err", "");
|
||||||
|
json.put("path", "");
|
||||||
|
json.put("second", 600);
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 播放器鉴权事件,rtsp/rtmp/http-flv/ws-flv/hls的播放都将触发此鉴权事件。
|
* 播放器鉴权事件,rtsp/rtmp/http-flv/ws-flv/hls的播放都将触发此鉴权事件。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_play")
|
@ResponseBody
|
||||||
public ResponseEntity onPlay(){
|
@PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onPlay(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_play API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("msg", "success");
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rtsp/rtmp/rtp推流鉴权事件。
|
* rtsp/rtmp/rtp推流鉴权事件。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_publish")
|
@ResponseBody
|
||||||
public ResponseEntity onPublish(){
|
@PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onPublish(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_publish API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("msg", "success");
|
||||||
|
json.put("enableHls", true);
|
||||||
|
json.put("enableMP4", false);
|
||||||
|
json.put("enableRtxp", true);
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 录制mp4完成后通知事件;此事件对回复不敏感。
|
* 录制mp4完成后通知事件;此事件对回复不敏感。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_record_mp4")
|
@ResponseBody
|
||||||
public ResponseEntity onRecordMp4(){
|
@PostMapping(value = "/on_record_mp4", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onRecordMp4(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_record_mp4 API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
}
|
json.put("code", 0);
|
||||||
|
json.put("msg", "success");
|
||||||
/**
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
* 该rtsp流是否开启rtsp专用方式的鉴权事件,开启后才会触发on_rtsp_auth事件。需要指出的是rtsp也支持url参数鉴权,它支持两种方式鉴权。
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@PostMapping("/on_rtsp_auth")
|
|
||||||
public ResponseEntity onRtspAuth(){
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rtsp专用的鉴权事件,先触发on_rtsp_realm事件然后才会触发on_rtsp_auth事件。
|
* rtsp专用的鉴权事件,先触发on_rtsp_realm事件然后才会触发on_rtsp_auth事件。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_rtsp_realm")
|
@ResponseBody
|
||||||
public ResponseEntity onRtspRealm(){
|
@PostMapping(value = "/on_rtsp_realm", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onRtspRealm(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_rtsp_realm API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("realm", "");
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 该rtsp流是否开启rtsp专用方式的鉴权事件,开启后才会触发on_rtsp_auth事件。需要指出的是rtsp也支持url参数鉴权,它支持两种方式鉴权。
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@ResponseBody
|
||||||
|
@PostMapping(value = "/on_rtsp_auth", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onRtspAuth(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_rtsp_auth API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("encrypted", false);
|
||||||
|
json.put("passwd", "test");
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shell登录鉴权,ZLMediaKit提供简单的telnet调试方式,使用telnet 127.0.0.1 9000能进入MediaServer进程的shell界面。
|
* shell登录鉴权,ZLMediaKit提供简单的telnet调试方式,使用telnet 127.0.0.1 9000能进入MediaServer进程的shell界面。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_shell_login")
|
@ResponseBody
|
||||||
public ResponseEntity onShellLogin(){
|
@PostMapping(value = "/on_shell_login", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onShellLogin(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_shell_login API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("msg", "success");
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rtsp/rtmp流注册或注销时触发此事件;此事件对回复不敏感。
|
* rtsp/rtmp流注册或注销时触发此事件;此事件对回复不敏感。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_stream_changed")
|
@ResponseBody
|
||||||
public ResponseEntity onStreamChanged(){
|
@PostMapping(value = "/on_stream_changed", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onStreamChanged(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_stream_changed API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("msg", "success");
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流无人观看时事件,用户可以通过此事件选择是否关闭无人看的流。
|
* 流无人观看时事件,用户可以通过此事件选择是否关闭无人看的流。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_stream_none_reader")
|
@ResponseBody
|
||||||
public ResponseEntity onStreamNoneReader(){
|
@PostMapping(value = "/on_stream_none_reader", produces = "application/json;charset=UTF-8")
|
||||||
// TODO Auto-generated method stub
|
public ResponseEntity<String> onStreamNoneReader(@RequestBody JSONObject json){
|
||||||
|
|
||||||
return null;
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_stream_none_reader API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
BigInteger bigint=new BigInteger(json.getString("stream"), 16);
|
||||||
|
int numb=bigint.intValue();
|
||||||
|
String ssrc = String.format("%010d", numb);
|
||||||
|
|
||||||
|
cmder.streamByeCmd(ssrc);
|
||||||
|
|
||||||
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("close", true);
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 流未找到事件,用户可以在此事件触发时,立即去拉流,这样可以实现按需拉流;此事件对回复不敏感。
|
* 流未找到事件,用户可以在此事件触发时,立即去拉流,这样可以实现按需拉流;此事件对回复不敏感。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_stream_not_found")
|
@ResponseBody
|
||||||
public ResponseEntity onStreamNotFound(){
|
@PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onStreamNotFound(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_stream_not_found API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("msg", "success");
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器启动事件,可以用于监听服务器崩溃重启;此事件对回复不敏感。
|
* 服务器启动事件,可以用于监听服务器崩溃重启;此事件对回复不敏感。
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@PostMapping("/on_server_started")
|
@ResponseBody
|
||||||
public ResponseEntity onServerStarted(){
|
@PostMapping(value = "/on_server_started", produces = "application/json;charset=UTF-8")
|
||||||
|
public ResponseEntity<String> onServerStarted(@RequestBody JSONObject json){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("ZLM HOOK on_server_started API调用,参数:" + json.toString());
|
||||||
|
}
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
return null;
|
JSONObject ret = new JSONObject();
|
||||||
|
json.put("code", 0);
|
||||||
|
json.put("msg", "success");
|
||||||
|
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,10 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@ -30,12 +32,21 @@ public class PlaybackController {
|
||||||
@GetMapping("/playback/{deviceId}/{channelId}")
|
@GetMapping("/playback/{deviceId}/{channelId}")
|
||||||
public ResponseEntity<String> play(@PathVariable String deviceId,@PathVariable String channelId, String startTime, String endTime){
|
public ResponseEntity<String> play(@PathVariable String deviceId,@PathVariable String channelId, String startTime, String endTime){
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s",deviceId, channelId));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(channelId)) {
|
||||||
|
String log = String.format("设备回放 API调用失败,deviceId:%s ,channelId:%s",deviceId, channelId);
|
||||||
|
logger.warn(log);
|
||||||
|
return new ResponseEntity<String>(log,HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
Device device = storager.queryVideoDevice(deviceId);
|
Device device = storager.queryVideoDevice(deviceId);
|
||||||
String ssrc = cmder.playbackStreamCmd(device, channelId, startTime, endTime);
|
String ssrc = cmder.playbackStreamCmd(device, channelId, startTime, endTime);
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(String.format("设备预览 API调用,deviceId:%s ,channelId:%s",deviceId, channelId));
|
logger.debug("设备回放 API调用,ssrc:"+ssrc+",ZLMedia streamId:"+Integer.toHexString(Integer.parseInt(ssrc)));
|
||||||
logger.debug("设备预览 API调用,ssrc:"+ssrc+",ZLMedia streamId:"+Integer.toHexString(Integer.parseInt(ssrc)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ssrc!=null) {
|
if(ssrc!=null) {
|
||||||
|
@ -43,7 +54,26 @@ public class PlaybackController {
|
||||||
json.put("ssrc", ssrc);
|
json.put("ssrc", ssrc);
|
||||||
return new ResponseEntity<String>(json.toString(),HttpStatus.OK);
|
return new ResponseEntity<String>(json.toString(),HttpStatus.OK);
|
||||||
} else {
|
} else {
|
||||||
logger.warn("设备预览API调用失败!");
|
logger.warn("设备回放API调用失败!");
|
||||||
|
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/playback/{ssrc}/stop")
|
||||||
|
public ResponseEntity<String> playStop(@PathVariable String ssrc){
|
||||||
|
|
||||||
|
cmder.streamByeCmd(ssrc);
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug(String.format("设备录像回放停止 API调用,ssrc:%s", ssrc));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ssrc!=null) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("ssrc", ssrc);
|
||||||
|
return new ResponseEntity<String>(json.toString(),HttpStatus.OK);
|
||||||
|
} else {
|
||||||
|
logger.warn("设备录像回放停止API调用失败!");
|
||||||
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue