优化代码结构,提供NVR录像检索接口

pull/1/head
songww 2020-05-08 21:57:07 +08:00
parent ab45f1a13f
commit bf7ab3fe2b
18 changed files with 871 additions and 237 deletions

View File

@ -12,20 +12,19 @@ import com.alibaba.fastjson.parser.ParserConfig;
import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer; import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer;
/** /**
* @Description:Redis * @Description:Redis使spring-data-redisapplication.ymlredis
* @author: songww * @author: songww
* @date: 2019530 10:58:25 * @date: 2019530 10:58:25
* *
*/ */
@Configuration @Configuration
// @EnableCaching
public class RedisConfig extends CachingConfigurerSupport { public class RedisConfig extends CachingConfigurerSupport {
@Bean("redisTemplate") @Bean("redisTemplate")
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<Object, Object> template = new RedisTemplate<>(); RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory); template.setConnectionFactory(redisConnectionFactory);
ParserConfig.getGlobalInstance().setAutoTypeSupport(true); // 使用fastjson进行序列化处理提高解析效率
FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<Object>(Object.class); FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<Object>(Object.class);
// value值的序列化采用fastJsonRedisSerializer // value值的序列化采用fastJsonRedisSerializer
template.setValueSerializer(serializer); template.setValueSerializer(serializer);
@ -33,8 +32,9 @@ public class RedisConfig extends CachingConfigurerSupport {
// key的序列化采用StringRedisSerializer // key的序列化采用StringRedisSerializer
template.setKeySerializer(new StringRedisSerializer()); template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer());
template.setConnectionFactory(redisConnectionFactory); template.setConnectionFactory(redisConnectionFactory);
// 使用fastjson时需设置此项否则会报异常not support type
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
return template; return template;
} }
@ -53,27 +53,5 @@ public class RedisConfig extends CachingConfigurerSupport {
container.setConnectionFactory(connectionFactory); container.setConnectionFactory(connectionFactory);
return container; return container;
} }
// @Bean
// RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
// MessageListenerAdapter listenerAdapter) {
//
// RedisMessageListenerContainer container = new RedisMessageListenerContainer();
// container.setConnectionFactory(connectionFactory);
// // 订阅了一个叫通道
// container.addMessageListener(listenerAdapter, new PatternTopic(VideoManagerConstants.KEEPLIVEKEY_PREFIX+"*"));
// // 这个container 可以添加多个 messageListener
// return container;
// }
// /**
// * 消息监听器适配器,绑定消息处理器,利用反射技术调用消息处理器的业务方法
// * @param receiver
// * @return
// */
// @Bean
// MessageListenerAdapter listenerAdapter(MessageReceiver receiver) {
// //这个地方 是给messageListenerAdapter 传入一个消息接受的处理器利用反射的方法调用“receiveMessage”
// //也有好几个重载方法,这边默认调用处理器的方法 叫handleMessage 可以自己到源码里面看
// return new MessageListenerAdapter(receiver, "receiveMessage");
// }
} }

View File

@ -16,7 +16,6 @@ public class SipConfig {
String sipPassword; String sipPassword;
@Value("${media.ip}") @Value("${media.ip}")
String mediaIp; String mediaIp;
@Value("${media.port}") @Value("${media.port}")
Integer mediaPort; Integer mediaPort;

View File

@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181;
import java.util.Properties; import java.util.Properties;
import javax.annotation.PostConstruct;
import javax.sip.DialogTerminatedEvent; import javax.sip.DialogTerminatedEvent;
import javax.sip.IOExceptionEvent; import javax.sip.IOExceptionEvent;
import javax.sip.ListeningPoint; import javax.sip.ListeningPoint;
@ -26,7 +27,6 @@ import javax.sip.message.Response;
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.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.SipConfig;
@ -37,70 +37,78 @@ import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor;
import gov.nist.javax.sip.SipStackImpl; import gov.nist.javax.sip.SipStackImpl;
@Component @Component
public class SipLayer implements SipListener{ public class SipLayer implements SipListener, Runnable {
private final static Logger logger = LoggerFactory.getLogger(SipLayer.class); private final static Logger logger = LoggerFactory.getLogger(SipLayer.class);
@Autowired @Autowired
private SipConfig config; private SipConfig config;
private SipProvider tcpSipProvider; private SipProvider tcpSipProvider;
private SipProvider udpSipProvider; private SipProvider udpSipProvider;
@Autowired @Autowired
private SIPProcessorFactory processorFactory; private SIPProcessorFactory processorFactory;
private SipStack sipStack; private SipStack sipStack;
private AddressFactory addressFactory; private AddressFactory addressFactory;
private HeaderFactory headerFactory; private HeaderFactory headerFactory;
private MessageFactory messageFactory; private MessageFactory messageFactory;
@Bean @PostConstruct
private boolean initSipServer() throws Exception { private void initSipServer() {
Thread thread=new Thread(this);
thread.setDaemon(true);
thread.setName("sip server thread start");
thread.start();
}
@Override
public void run() {
SipFactory sipFactory = SipFactory.getInstance(); SipFactory sipFactory = SipFactory.getInstance();
sipFactory.setPathName("gov.nist"); sipFactory.setPathName("gov.nist");
headerFactory = sipFactory.createHeaderFactory();
addressFactory = sipFactory.createAddressFactory();
messageFactory = sipFactory.createMessageFactory();
Properties properties = new Properties();
properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
properties.setProperty("javax.sip.IP_ADDRESS", config.getSipIp());
/**
* sip_server_log.log sip_debug_log.log public static final int TRACE_NONE =
* 0; public static final int TRACE_MESSAGES = 16; public static final int
* TRACE_EXCEPTION = 17; public static final int TRACE_DEBUG = 32;
*/
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "16");
properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "sip_server_log");
properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log");
sipStack = (SipStackImpl) sipFactory.createSipStack(properties);
try { try {
headerFactory = sipFactory.createHeaderFactory();
addressFactory = sipFactory.createAddressFactory();
messageFactory = sipFactory.createMessageFactory();
Properties properties = new Properties();
properties.setProperty("javax.sip.STACK_NAME", "GB28181_SIP");
properties.setProperty("javax.sip.IP_ADDRESS", config.getSipIp());
properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT", "false");
/**
* sip_server_log.log sip_debug_log.log public static final int TRACE_NONE =
* 0; public static final int TRACE_MESSAGES = 16; public static final int
* TRACE_EXCEPTION = 17; public static final int TRACE_DEBUG = 32;
*/
properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "0");
properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "sip_server_log");
properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "sip_debug_log");
sipStack = (SipStackImpl) sipFactory.createSipStack(properties);
startTcpListener(); startTcpListener();
startUdpListener(); startUdpListener();
} catch (Exception e) { } catch (Exception e) {
logger.error("Sip Server 启动失败! port {"+config.getSipPort()+"}"); logger.error("Sip Server 启动失败! port {" + config.getSipPort() + "}");
e.printStackTrace(); e.printStackTrace();
throw e;
} }
logger.info("Sip Server 启动成功 port {"+config.getSipPort()+"}"); logger.info("Sip Server 启动成功 port {" + config.getSipPort() + "}");
return true;
} }
private void startTcpListener() throws Exception { private void startTcpListener() throws Exception {
ListeningPoint tcpListeningPoint = sipStack.createListeningPoint(config.getSipIp(), config.getSipPort(), "TCP"); ListeningPoint tcpListeningPoint = sipStack.createListeningPoint(config.getSipIp(), config.getSipPort(), "TCP");
tcpSipProvider = sipStack.createSipProvider(tcpListeningPoint); tcpSipProvider = sipStack.createSipProvider(tcpListeningPoint);
tcpSipProvider.addSipListener(this); tcpSipProvider.addSipListener(this);
} }
private void startUdpListener() throws Exception { private void startUdpListener() throws Exception {
ListeningPoint udpListeningPoint = sipStack.createListeningPoint(config.getSipIp(), config.getSipPort(), "UDP"); ListeningPoint udpListeningPoint = sipStack.createListeningPoint(config.getSipIp(), config.getSipPort(), "UDP");
udpSipProvider = sipStack.createSipProvider(udpListeningPoint); udpSipProvider = sipStack.createSipProvider(udpListeningPoint);
udpSipProvider.addSipListener(this); udpSipProvider.addSipListener(this);
} }
/** /**
* SIP Content GBK This method is called by the SIP stack when a * SIP Content GBK This method is called by the SIP stack when a
@ -118,60 +126,80 @@ public class SipLayer implements SipListener{
int status = response.getStatusCode(); int status = response.getStatusCode();
if ((status >= 200) && (status < 300)) { // Success! if ((status >= 200) && (status < 300)) { // Success!
ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt); ISIPResponseProcessor processor = processorFactory.createResponseProcessor(evt);
processor.process(evt,this,config); processor.process(evt, this, config);
} else { } else {
logger.warn("接收到失败的response响应status"+status+",message:"+response.getContent().toString()); logger.warn("接收到失败的response响应status" + status + ",message:" + response.getContent().toString());
} }
//trying不会回复 // trying不会回复
if(status == Response.TRYING){ if (status == Response.TRYING) {
} }
} }
/** /**
* <p>Title: processTimeout</p> * <p>
* <p>Description: </p> * Title: processTimeout
* @param timeoutEvent * </p>
*/ * <p>
* Description:
* </p>
*
* @param timeoutEvent
*/
@Override @Override
public void processTimeout(TimeoutEvent timeoutEvent) { public void processTimeout(TimeoutEvent timeoutEvent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/** /**
* <p>Title: processIOException</p> * <p>
* <p>Description: </p> * Title: processIOException
* @param exceptionEvent * </p>
*/ * <p>
* Description:
* </p>
*
* @param exceptionEvent
*/
@Override @Override
public void processIOException(IOExceptionEvent exceptionEvent) { public void processIOException(IOExceptionEvent exceptionEvent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/** /**
* <p>Title: processTransactionTerminated</p> * <p>
* <p>Description: </p> * Title: processTransactionTerminated
* @param transactionTerminatedEvent * </p>
*/ * <p>
* Description:
* </p>
*
* @param transactionTerminatedEvent
*/
@Override @Override
public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) { public void processTransactionTerminated(TransactionTerminatedEvent transactionTerminatedEvent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/** /**
* <p>Title: processDialogTerminated</p> * <p>
* <p>Description: </p> * Title: processDialogTerminated
* @param dialogTerminatedEvent * </p>
*/ * <p>
* Description:
* </p>
*
* @param dialogTerminatedEvent
*/
@Override @Override
public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) { public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
private ServerTransaction getServerTransaction(RequestEvent evt) { private ServerTransaction getServerTransaction(RequestEvent evt) {
Request request = evt.getRequest(); Request request = evt.getRequest();
ServerTransaction serverTransaction = evt.getServerTransaction(); ServerTransaction serverTransaction = evt.getServerTransaction();
@ -185,11 +213,11 @@ public class SipLayer implements SipListener{
if (serverTransaction == null) { if (serverTransaction == null) {
try { try {
if (isTcp) { if (isTcp) {
serverTransaction = tcpSipProvider.getNewServerTransaction(request); serverTransaction = tcpSipProvider.getNewServerTransaction(request);
} else { } else {
serverTransaction = udpSipProvider.getNewServerTransaction(request); serverTransaction = udpSipProvider.getNewServerTransaction(request);
} }
} catch (TransactionAlreadyExistsException e) { } catch (TransactionAlreadyExistsException e) {
e.printStackTrace(); e.printStackTrace();
} catch (TransactionUnavailableException e) { } catch (TransactionUnavailableException e) {
@ -199,7 +227,6 @@ public class SipLayer implements SipListener{
return serverTransaction; return serverTransaction;
} }
public AddressFactory getAddressFactory() { public AddressFactory getAddressFactory() {
return addressFactory; return addressFactory;
} }
@ -219,5 +246,5 @@ public class SipLayer implements SipListener{
public SipProvider getUdpSipProvider() { public SipProvider getUdpSipProvider() {
return udpSipProvider; return udpSipProvider;
} }
} }

View File

@ -0,0 +1,26 @@
package com.genersoft.iot.vmp.gb28181.auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
/**
* @Description:
* @author: songww
* @date: 202058 9:41:46
*/
@Component
public class RegisterLogicHandler {
@Autowired
private SIPCommander cmder;
public void onRegister(Device device) {
// TODO 后续处理只有第一次注册时调用查询设备信息如需更新调用更新API接口
cmder.deviceInfoQuery(device);
cmder.catalogQuery(device);
}
}

View File

@ -0,0 +1,51 @@
package com.genersoft.iot.vmp.gb28181.bean;
import java.util.List;
/**
* @Description:bean
* @author: songww
* @date: 202058 2:05:56
*/
public class RecordInfo {
private String deviceId;
private String name;
private int sumNum;
private List<RecordItem> recordList;
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSumNum() {
return sumNum;
}
public void setSumNum(int sumNum) {
this.sumNum = sumNum;
}
public List<RecordItem> getRecordList() {
return recordList;
}
public void setRecordList(List<RecordItem> recordList) {
this.recordList = recordList;
}
}

View File

@ -0,0 +1,99 @@
package com.genersoft.iot.vmp.gb28181.bean;
/**
* @Description:bean
* @author: songww
* @date: 202058 2:06:54
*/
public class RecordItem {
private String deviceId;
private String name;
private String filePath;
private String address;
private String startTime;
private String endTime;
private int secrecy;
private String type;
private String recordId;
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public int getSecrecy() {
return secrecy;
}
public void setSecrecy(int secrecy) {
this.secrecy = secrecy;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getRecordId() {
return recordId;
}
public void setRecordId(String recordId) {
this.recordId = recordId;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
}

View File

@ -0,0 +1,42 @@
package com.genersoft.iot.vmp.gb28181.transmit.callback;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.async.DeferredResult;
/**
* @Description:TODO()
* @author: songww
* @date: 202058 7:59:05
*/
@Component
public class DeferredResultHolder {
public static final String CALLBACK_CMD_DEVICEINFO = "CALLBACK_DEVICEINFO";
public static final String CALLBACK_CMD_CATALOG = "CALLBACK_CATALOG";
public static final String CALLBACK_CMD_RECORDINFO = "CALLBACK_RECORDINFO";
private Map<String, DeferredResult> map = new HashMap<String, DeferredResult>();
public void put(String key, DeferredResult result) {
map.put(key, result);
}
public DeferredResult get(String key) {
return map.get(key);
}
public void invokeResult(RequestMessage msg) {
DeferredResult result = map.get(msg.getId());
if (result == null) {
return;
}
result.setResult(new ResponseEntity<>(msg.getData(),HttpStatus.OK));
}
}

View File

@ -0,0 +1,51 @@
package com.genersoft.iot.vmp.gb28181.transmit.callback;
/**
* @Description:TODO()
* @author: songww
* @date: 202058 1:09:18
*/
public class RequestMessage {
private String id;
private String deviceId;
private String type;
private Object data;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
this.id = type + deviceId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
this.id = type + deviceId;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}

View File

@ -12,48 +12,48 @@ public interface ISIPCommander {
/** /**
* 使 * 使
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param leftRight 0: 1: 2: * @param leftRight 0: 1: 2:
* @param upDown 0: 1: 2: * @param upDown 0: 1: 2:
* @param moveSpeed * @param moveSpeed
*/ */
public boolean ptzdirectCmd(String deviceId,String channelId,int leftRight, int upDown); public boolean ptzdirectCmd(Device device,String channelId,int leftRight, int upDown);
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param leftRight 0: 1: 2: * @param leftRight 0: 1: 2:
* @param upDown 0: 1: 2: * @param upDown 0: 1: 2:
* @param moveSpeed * @param moveSpeed
*/ */
public boolean ptzdirectCmd(String deviceId,String channelId,int leftRight, int upDown, int moveSpeed); public boolean ptzdirectCmd(Device device,String channelId,int leftRight, int upDown, int moveSpeed);
/** /**
* 使 * 使
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param inOut 0: 1: 2: * @param inOut 0: 1: 2:
*/ */
public boolean ptzZoomCmd(String deviceId,String channelId,int inOut); public boolean ptzZoomCmd(Device device,String channelId,int inOut);
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param inOut 0: 1: 2: * @param inOut 0: 1: 2:
* @param zoomSpeed * @param zoomSpeed
*/ */
public boolean ptzZoomCmd(String deviceId,String channelId,int inOut, int moveSpeed); public boolean ptzZoomCmd(Device device,String channelId,int inOut, int moveSpeed);
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param leftRight 0: 1: 2: * @param leftRight 0: 1: 2:
* @param upDown 0: 1: 2: * @param upDown 0: 1: 2:
@ -61,67 +61,67 @@ public interface ISIPCommander {
* @param moveSpeed * @param moveSpeed
* @param zoomSpeed * @param zoomSpeed
*/ */
public boolean ptzCmd(String deviceId,String channelId,int leftRight, int upDown, int inOut, int moveSpeed, int zoomSpeed); public boolean ptzCmd(Device device,String channelId,int leftRight, int upDown, int inOut, int moveSpeed, int zoomSpeed);
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
*/ */
public String playStreamCmd(String deviceId,String channelId); public String playStreamCmd(Device device,String channelId);
/** /**
* 广 * 广
* *
* @param deviceId * @param device
* @param channelId * @param channelId
*/ */
public String audioBroadcastCmd(String deviceId,String channelId); public boolean audioBroadcastCmd(Device device,String channelId);
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
*/ */
public String recordCmd(String deviceId,String channelId); public boolean recordCmd(Device device,String channelId);
/** /**
* / * /
* *
* @param deviceId * @param device
*/ */
public String guardCmd(String deviceId); public boolean guardCmd(Device device);
/** /**
* *
* *
* @param deviceId * @param device
*/ */
public String alarmCmd(String deviceId); public boolean alarmCmd(Device device);
/** /**
* ,IDR * ,IDR
* *
* @param deviceId * @param device
* @param channelId * @param channelId
*/ */
public String iFameCmd(String deviceId,String channelId); public boolean iFameCmd(Device device,String channelId);
/** /**
* *
* *
* @param deviceId * @param device
*/ */
public String homePositionCmd(String deviceId); public boolean homePositionCmd(Device device);
/** /**
* *
* *
* @param deviceId * @param device
*/ */
public String deviceConfigCmd(String deviceId); public boolean deviceConfigCmd(Device device);
/** /**
@ -150,8 +150,10 @@ public interface ISIPCommander {
* *
* *
* @param device * @param device
* @param startTime ,yyyy-MM-dd HH:mm:ss
* @param endTime ,yyyy-MM-dd HH:mm:ss
*/ */
public boolean recordInfoQuery(Device device); public boolean recordInfoQuery(Device device, String startTime, String endTime);
/** /**
* *

View File

@ -8,6 +8,7 @@ import javax.sip.SipException;
import javax.sip.message.Request; import javax.sip.message.Request;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.SipConfig;
@ -15,7 +16,7 @@ import com.genersoft.iot.vmp.gb28181.SipLayer;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
/** /**
* @Description: * @Description:
@ -34,66 +35,63 @@ public class SIPCommander implements ISIPCommander {
@Autowired @Autowired
private SipLayer sipLayer; private SipLayer sipLayer;
@Autowired
private IVideoManagerStorager storager;
/** /**
* 使 * 使
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param leftRight 0: 1: 2: * @param leftRight 0: 1: 2:
* @param upDown 0: 1: 2: * @param upDown 0: 1: 2:
* @param moveSpeed * @param moveSpeed
*/ */
@Override @Override
public boolean ptzdirectCmd(String deviceId, String channelId, int leftRight, int upDown) { public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown) {
return ptzCmd(deviceId, channelId, leftRight, upDown, 0, config.getSpeed(), 0); return ptzCmd(device, channelId, leftRight, upDown, 0, config.getSpeed(), 0);
} }
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param leftRight 0: 1: 2: * @param leftRight 0: 1: 2:
* @param upDown 0: 1: 2: * @param upDown 0: 1: 2:
* @param moveSpeed * @param moveSpeed
*/ */
@Override @Override
public boolean ptzdirectCmd(String deviceId, String channelId, int leftRight, int upDown, int moveSpeed) { public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown, int moveSpeed) {
return ptzCmd(deviceId, channelId, leftRight, upDown, 0, moveSpeed, 0); return ptzCmd(device, channelId, leftRight, upDown, 0, moveSpeed, 0);
} }
/** /**
* 使 * 使
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param inOut 0: 1: 2: * @param inOut 0: 1: 2:
*/ */
@Override @Override
public boolean ptzZoomCmd(String deviceId, String channelId, int inOut) { public boolean ptzZoomCmd(Device device, String channelId, int inOut) {
return ptzCmd(deviceId, channelId, 0, 0, inOut, 0, config.getSpeed()); return ptzCmd(device, channelId, 0, 0, inOut, 0, config.getSpeed());
} }
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param inOut 0: 1: 2: * @param inOut 0: 1: 2:
* @param zoomSpeed * @param zoomSpeed
*/ */
@Override @Override
public boolean ptzZoomCmd(String deviceId, String channelId, int inOut, int zoomSpeed) { public boolean ptzZoomCmd(Device device, String channelId, int inOut, int zoomSpeed) {
return ptzCmd(deviceId, channelId, 0, 0, inOut, 0, zoomSpeed); return ptzCmd(device, channelId, 0, 0, inOut, 0, zoomSpeed);
} }
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
* @param leftRight 0: 1: 2: * @param leftRight 0: 1: 2:
* @param upDown 0: 1: 2: * @param upDown 0: 1: 2:
@ -102,10 +100,9 @@ public class SIPCommander implements ISIPCommander {
* @param zoomSpeed * @param zoomSpeed
*/ */
@Override @Override
public boolean ptzCmd(String deviceId, String channelId, int leftRight, int upDown, int inOut, int moveSpeed, public boolean ptzCmd(Device device, String channelId, int leftRight, int upDown, int inOut, int moveSpeed,
int zoomSpeed) { int zoomSpeed) {
try { try {
Device device = storager.queryVideoDevice(deviceId);
StringBuffer ptzXml = new StringBuffer(200); StringBuffer ptzXml = new StringBuffer(200);
ptzXml.append("<?xml version=\"1.0\" ?>"); ptzXml.append("<?xml version=\"1.0\" ?>");
ptzXml.append("<Control>"); ptzXml.append("<Control>");
@ -119,7 +116,7 @@ public class SIPCommander implements ISIPCommander {
Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag"); Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag");
transmitRequest(device.getTransport(), request); transmitRequest(device, request);
return true; return true;
} catch (SipException | ParseException | InvalidArgumentException e) { } catch (SipException | ParseException | InvalidArgumentException e) {
@ -131,15 +128,13 @@ public class SIPCommander implements ISIPCommander {
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
*/ */
@Override @Override
public String playStreamCmd(String deviceId, String channelId) { public String playStreamCmd(Device device, String channelId) {
try { try {
Device device = storager.queryVideoDevice(deviceId);
//生成ssrc标识数据流 10位数字 //生成ssrc标识数据流 10位数字
String ssrc = ""; String ssrc = "";
Random random = new Random(); Random random = new Random();
@ -170,7 +165,7 @@ public class SIPCommander implements ISIPCommander {
Request request = headerProvider.createInviteRequest(device, content.toString(), null, "live", null); Request request = headerProvider.createInviteRequest(device, content.toString(), null, "live", null);
transmitRequest(device.getTransport(), request); transmitRequest(device, request);
return ssrc; return ssrc;
} catch ( SipException | ParseException | InvalidArgumentException e) { } catch ( SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace(); e.printStackTrace();
@ -181,81 +176,81 @@ public class SIPCommander implements ISIPCommander {
/** /**
* 广 * 广
* *
* @param deviceId * @param device
* @param channelId * @param channelId
*/ */
@Override @Override
public String audioBroadcastCmd(String deviceId, String channelId) { public boolean audioBroadcastCmd(Device device, String channelId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
/** /**
* *
* *
* @param deviceId * @param device
* @param channelId * @param channelId
*/ */
@Override @Override
public String recordCmd(String deviceId, String channelId) { public boolean recordCmd(Device device, String channelId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
/** /**
* / * /
* *
* @param deviceId * @param device
*/ */
@Override @Override
public String guardCmd(String deviceId) { public boolean guardCmd(Device device) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
/** /**
* *
* *
* @param deviceId * @param device
*/ */
@Override @Override
public String alarmCmd(String deviceId) { public boolean alarmCmd(Device device) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
/** /**
* ,IDR * ,IDR
* *
* @param deviceId * @param device
* @param channelId * @param channelId
*/ */
@Override @Override
public String iFameCmd(String deviceId, String channelId) { public boolean iFameCmd(Device device, String channelId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
/** /**
* *
* *
* @param deviceId * @param device
*/ */
@Override @Override
public String homePositionCmd(String deviceId) { public boolean homePositionCmd(Device device) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
/** /**
* *
* *
* @param deviceId * @param device
*/ */
@Override @Override
public String deviceConfigCmd(String deviceId) { public boolean deviceConfigCmd(Device device) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return false;
} }
/** /**
@ -286,8 +281,8 @@ public class SIPCommander implements ISIPCommander {
catalogXml.append("</Query>"); catalogXml.append("</Query>");
Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", "ToDeviceInfoTag"); Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", "ToDeviceInfoTag");
transmitRequest(device, request);
transmitRequest(device.getTransport(), request);
} catch (SipException | ParseException | InvalidArgumentException e) { } catch (SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
@ -312,9 +307,7 @@ public class SIPCommander implements ISIPCommander {
catalogXml.append("</Query>"); catalogXml.append("</Query>");
Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCatalogTag", "ToCatalogTag"); Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCatalogTag", "ToCatalogTag");
transmitRequest(device, request);
transmitRequest(device.getTransport(), request);
} catch (SipException | ParseException | InvalidArgumentException e) { } catch (SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
@ -326,11 +319,32 @@ public class SIPCommander implements ISIPCommander {
* *
* *
* @param device * @param device
* @param startTime ,yyyy-MM-dd HH:mm:ss
* @param endTime ,yyyy-MM-dd HH:mm:ss
*/ */
@Override @Override
public boolean recordInfoQuery(Device device) { public boolean recordInfoQuery(Device device, String startTime, String endTime) {
// TODO Auto-generated method stub
return false; try {
StringBuffer catalogXml = new StringBuffer(200);
catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>");
catalogXml.append("<Query>");
catalogXml.append("<CmdType>RecordInfo</CmdType>");
catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>");
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>");
catalogXml.append("<StartTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(startTime) + "</StartTime>");
catalogXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(endTime) + "</EndTime>");
// 大华NVR要求必须增加一个值为all的文本元素节点Type
catalogXml.append("<Type>all</Type>");
catalogXml.append("</Query>");
Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", "ToRecordInfoTag");
transmitRequest(device, request);
} catch (SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace();
return false;
}
return true;
} }
/** /**
@ -377,10 +391,10 @@ public class SIPCommander implements ISIPCommander {
return false; return false;
} }
private void transmitRequest(String transport, Request request) throws SipException { private void transmitRequest(Device device, Request request) throws SipException {
if(transport.equals("TCP")) { if(device.getTransport().equals("TCP")) {
sipLayer.getTcpSipProvider().sendRequest(request); sipLayer.getTcpSipProvider().sendRequest(request);
} else if(transport.equals("UDP")) { } else if(device.getTransport().equals("UDP")) {
sipLayer.getUdpSipProvider().sendRequest(request); sipLayer.getUdpSipProvider().sendRequest(request);
} }
} }

View File

@ -2,8 +2,10 @@ package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.sip.InvalidArgumentException; import javax.sip.InvalidArgumentException;
@ -24,9 +26,14 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.gb28181.SipLayer; import com.genersoft.iot.vmp.gb28181.SipLayer;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
import com.genersoft.iot.vmp.gb28181.bean.RecordItem;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.request.ISIPRequestProcessor; import com.genersoft.iot.vmp.gb28181.transmit.request.ISIPRequestProcessor;
import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
@ -51,6 +58,9 @@ public class MessageRequestProcessor implements ISIPRequestProcessor {
@Autowired @Autowired
private EventPublisher publisher; private EventPublisher publisher;
@Autowired
private DeferredResultHolder deferredResultHolder;
/** /**
* MESSAGE * MESSAGE
* *
@ -74,21 +84,49 @@ public class MessageRequestProcessor implements ISIPRequestProcessor {
processMessageDeviceInfo(evt); processMessageDeviceInfo(evt);
} else if (new String(request.getRawContent()).contains("<CmdType>Alarm</CmdType>")) { } else if (new String(request.getRawContent()).contains("<CmdType>Alarm</CmdType>")) {
processMessageAlarm(evt); processMessageAlarm(evt);
} else if (new String(request.getRawContent()).contains("<CmdType>recordInfo</CmdType>")) {
processMessageRecordInfo(evt);
} }
} }
/**
* deviceInfo
* @param evt
*/
private void processMessageDeviceInfo(RequestEvent evt) {
try {
Element rootElement = getRootElement(evt);
Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText().toString();
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
return;
}
device.setName(XmlUtil.getText(rootElement,"DeviceName"));
device.setManufacturer(XmlUtil.getText(rootElement,"Manufacturer"));
device.setModel(XmlUtil.getText(rootElement,"Model"));
device.setFirmware(XmlUtil.getText(rootElement,"Firmware"));
storager.update(device);
RequestMessage msg = new RequestMessage();
msg.setDeviceId(deviceId);
msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICEINFO);
msg.setData(device);
deferredResultHolder.invokeResult(msg);
} catch (DocumentException e) {
e.printStackTrace();
}
}
/*** /***
* catalog * catalog
* @param evt * @param evt
*/ */
private void processMessageCatalogList(RequestEvent evt) { private void processMessageCatalogList(RequestEvent evt) {
try { try {
Request request = evt.getRequest(); Element rootElement = getRootElement(evt);
SAXReader reader = new SAXReader();
reader.setEncoding("GB2312");
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
Element rootElement = xml.getRootElement();
Element deviceIdElement = rootElement.element("DeviceID"); Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText().toString(); String deviceId = deviceIdElement.getText().toString();
Element deviceListElement = rootElement.element("DeviceList"); Element deviceListElement = rootElement.element("DeviceList");
@ -152,52 +190,24 @@ public class MessageRequestProcessor implements ISIPRequestProcessor {
} }
// 更新 // 更新
storager.update(device); storager.update(device);
RequestMessage msg = new RequestMessage();
msg.setDeviceId(deviceId);
msg.setType(DeferredResultHolder.CALLBACK_CMD_CATALOG);
msg.setData(device);
deferredResultHolder.invokeResult(msg);
} }
} catch (DocumentException e) { } catch (DocumentException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/***
* deviceInfo
* @param evt
*/
private void processMessageDeviceInfo(RequestEvent evt) {
try {
Request request = evt.getRequest();
SAXReader reader = new SAXReader();
// reader.setEncoding("GB2312");
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
Element rootElement = xml.getRootElement();
Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText().toString();
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
return;
}
device.setName(XmlUtil.getText(rootElement,"DeviceName"));
device.setManufacturer(XmlUtil.getText(rootElement,"Manufacturer"));
device.setModel(XmlUtil.getText(rootElement,"Model"));
device.setFirmware(XmlUtil.getText(rootElement,"Firmware"));
storager.update(device);
cmder.catalogQuery(device);
} catch (DocumentException e) {
e.printStackTrace();
}
}
/*** /***
* alarm * alarm
* @param evt * @param evt
*/ */
private void processMessageAlarm(RequestEvent evt) { private void processMessageAlarm(RequestEvent evt) {
try { try {
Request request = evt.getRequest(); Element rootElement = getRootElement(evt);
SAXReader reader = new SAXReader();
// reader.setEncoding("GB2312");
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
Element rootElement = xml.getRootElement();
Element deviceIdElement = rootElement.element("DeviceID"); Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText().toString(); String deviceId = deviceIdElement.getText().toString();
@ -224,10 +234,7 @@ public class MessageRequestProcessor implements ISIPRequestProcessor {
try { try {
Request request = evt.getRequest(); Request request = evt.getRequest();
Response response = layer.getMessageFactory().createResponse(Response.OK,request); Response response = layer.getMessageFactory().createResponse(Response.OK,request);
SAXReader reader = new SAXReader(); Element rootElement = getRootElement(evt);
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
// reader.setEncoding("GB2312");
Element rootElement = xml.getRootElement();
Element deviceIdElement = rootElement.element("DeviceID"); Element deviceIdElement = rootElement.element("DeviceID");
transaction.sendResponse(response); transaction.sendResponse(response);
publisher.onlineEventPublish(deviceIdElement.getText(), VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); publisher.onlineEventPublish(deviceIdElement.getText(), VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
@ -235,5 +242,68 @@ public class MessageRequestProcessor implements ISIPRequestProcessor {
e.printStackTrace(); e.printStackTrace();
} }
} }
/***
* catalog
* @param evt
*/
private void processMessageRecordInfo(RequestEvent evt) {
try {
RecordInfo recordInfo = new RecordInfo();
Element rootElement = getRootElement(evt);
Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText().toString();
recordInfo.setDeviceId(deviceId);
recordInfo.setName(XmlUtil.getText(rootElement,"Name"));
recordInfo.setSumNum(Integer.parseInt(XmlUtil.getText(rootElement,"SumNum")));
Element recordListElement = rootElement.element("RecordList");
if (recordListElement == null) {
return;
}
Iterator<Element> recordListIterator = recordListElement.elementIterator();
if (recordListIterator != null) {
List<RecordItem> recordList = new ArrayList<RecordItem>();
RecordItem record = new RecordItem();
// 遍历DeviceList
while (recordListIterator.hasNext()) {
Element itemRecord = recordListIterator.next();
Element recordElement = itemRecord.element("DeviceID");
if (recordElement == null) {
continue;
}
record.setDeviceId(XmlUtil.getText(itemRecord,"DeviceID"));
record.setName(XmlUtil.getText(itemRecord,"Name"));
record.setFilePath(XmlUtil.getText(itemRecord,"FilePath"));
record.setAddress(XmlUtil.getText(itemRecord,"Address"));
record.setStartTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(XmlUtil.getText(itemRecord,"StartTime")));
record.setEndTime(DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(XmlUtil.getText(itemRecord,"EndTime")));
record.setSecrecy(itemRecord.element("Secrecy") == null? 0:Integer.parseInt(XmlUtil.getText(itemRecord,"Secrecy")));
record.setType(XmlUtil.getText(itemRecord,"Type"));
record.setRecordId(XmlUtil.getText(itemRecord,"RecordID"));
recordList.add(record);
}
recordInfo.setRecordList(recordList);
}
RequestMessage msg = new RequestMessage();
msg.setDeviceId(deviceId);
msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO);
msg.setData(recordInfo);
deferredResultHolder.invokeResult(msg);
} catch (DocumentException e) {
e.printStackTrace();
}
}
private Element getRootElement(RequestEvent evt) throws DocumentException {
Request request = evt.getRequest();
SAXReader reader = new SAXReader();
reader.setEncoding("GB2312");
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
return xml.getRootElement();
}
} }

View File

@ -25,10 +25,10 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.gb28181.SipLayer; import com.genersoft.iot.vmp.gb28181.SipLayer;
import com.genersoft.iot.vmp.gb28181.auth.DigestServerAuthenticationHelper; import com.genersoft.iot.vmp.gb28181.auth.DigestServerAuthenticationHelper;
import com.genersoft.iot.vmp.gb28181.auth.RegisterLogicHandler;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.Host; import com.genersoft.iot.vmp.gb28181.bean.Host;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.request.ISIPRequestProcessor; import com.genersoft.iot.vmp.gb28181.transmit.request.ISIPRequestProcessor;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
@ -48,7 +48,7 @@ public class RegisterRequestProcessor implements ISIPRequestProcessor {
private SipConfig config; private SipConfig config;
@Autowired @Autowired
private SIPCommander cmder; private RegisterLogicHandler handler;
@Autowired @Autowired
private IVideoManagerStorager storager; private IVideoManagerStorager storager;
@ -149,7 +149,7 @@ public class RegisterRequestProcessor implements ISIPRequestProcessor {
System.out.println("注册成功! deviceId:" + device.getDeviceId()); System.out.println("注册成功! deviceId:" + device.getDeviceId());
storager.update(device); storager.update(device);
publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER); publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER);
cmder.deviceInfoQuery(device); handler.onRegister(device);
} else if (registerFlag == 2) { } else if (registerFlag == 2) {
System.out.println("注销成功! deviceId:" + device.getDeviceId()); System.out.println("注销成功! deviceId:" + device.getDeviceId());
publisher.outlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_OUTLINE_UNREGISTER); publisher.outlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_OUTLINE_UNREGISTER);

View File

@ -0,0 +1,40 @@
package com.genersoft.iot.vmp.gb28181.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
/**
* @Description:ISO 8601
* @author: songww
* @date: 202058 3:24:42
*/
public class DateUtil {
private static final String yyyy_MM_dd_T_HH_mm_ss_SSSXXX = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
private static final String yyyy_MM_dd_HH_mm_ss = "yyyy-MM-dd HH:mm:ss";
public static String yyyy_MM_dd_HH_mm_ssToISO8601(String formatTime) {
SimpleDateFormat oldsdf = new SimpleDateFormat(yyyy_MM_dd_HH_mm_ss, Locale.getDefault());
SimpleDateFormat newsdf = new SimpleDateFormat(yyyy_MM_dd_T_HH_mm_ss_SSSXXX, Locale.getDefault());
try {
return newsdf.format(oldsdf.parse(formatTime));
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
public static String ISO8601Toyyyy_MM_dd_HH_mm_ss(String formatTime) {
SimpleDateFormat oldsdf = new SimpleDateFormat(yyyy_MM_dd_T_HH_mm_ss_SSSXXX, Locale.getDefault());
SimpleDateFormat newsdf = new SimpleDateFormat(yyyy_MM_dd_HH_mm_ss, Locale.getDefault());
try {
return newsdf.format(oldsdf.parse(formatTime));
} catch (ParseException e) {
e.printStackTrace();
}
return "";
}
}

View File

@ -0,0 +1,152 @@
package com.genersoft.iot.vmp.media.zlm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Description: ZLMediaServerhook
* @author: songww
* @date: 202058 10:46:48
*/
@RestController
@RequestMapping("/hook/zlm")
public class ZLMHttpHookListener {
private final static Logger logger = LoggerFactory.getLogger(ZLMHttpHookListener.class);
/**
* general.flowThreshold
*
*/
@PostMapping("/on_flow_report")
public ResponseEntity onFlowReport(){
// TODO Auto-generated method stub
return null;
}
/**
* 访httphls
*
*/
@PostMapping("/on_http_access")
public ResponseEntity onHttpAccess(){
// TODO Auto-generated method stub
return null;
}
/**
* rtsp/rtmp/http-flv/ws-flv/hls
*
*/
@PostMapping("/on_play")
public ResponseEntity onPlay(){
// TODO Auto-generated method stub
return null;
}
/**
* rtsp/rtmp/rtp
*
*/
@PostMapping("/on_publish")
public ResponseEntity onPublish(){
// TODO Auto-generated method stub
return null;
}
/**
* mp4
*
*/
@PostMapping("/on_record_mp4")
public ResponseEntity onRecordMp4(){
// TODO Auto-generated method stub
return null;
}
/**
* rtsprtspon_rtsp_authrtspurl
*
*/
@PostMapping("/on_rtsp_auth")
public ResponseEntity onRtspAuth(){
// TODO Auto-generated method stub
return null;
}
/**
* rtspon_rtsp_realmon_rtsp_auth
*
*/
@PostMapping("/on_rtsp_realm")
public ResponseEntity onRtspRealm(){
// TODO Auto-generated method stub
return null;
}
/**
* shellZLMediaKittelnet使telnet 127.0.0.1 9000MediaServershell
*
*/
@PostMapping("/on_shell_login")
public ResponseEntity onShellLogin(){
// TODO Auto-generated method stub
return null;
}
/**
* rtsp/rtmp
*
*/
@PostMapping("/on_stream_changed")
public ResponseEntity onStreamChanged(){
// TODO Auto-generated method stub
return null;
}
/**
*
*
*/
@PostMapping("/on_stream_none_reader")
public ResponseEntity onStreamNoneReader(){
// TODO Auto-generated method stub
return null;
}
/**
*
*
*/
@PostMapping("/on_stream_not_found")
public ResponseEntity onStreamNotFound(){
// TODO Auto-generated method stub
return null;
}
/**
*
*
*/
@PostMapping("/on_server_started")
public ResponseEntity onServerStarted(){
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,7 +1,8 @@
package com.genersoft.iot.vmp.vmanager.device; package com.genersoft.iot.vmp.vmanager.device;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -10,10 +11,14 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
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;
import org.springframework.web.context.request.async.DeferredResult;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
@RestController @RestController
@ -25,16 +30,21 @@ public class DeviceController {
@Autowired @Autowired
private IVideoManagerStorager storager; private IVideoManagerStorager storager;
@Autowired
private SIPCommander cmder;
@Autowired
private DeferredResultHolder resultHolder;
@GetMapping("/devices/{deviceId}") @GetMapping("/devices/{deviceId}")
public ResponseEntity<List<Device>> devices(@PathVariable String deviceId){ public ResponseEntity<Device> devices(@PathVariable String deviceId){
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("查询视频设备API调用deviceId" + deviceId); logger.debug("查询视频设备API调用deviceId" + deviceId);
} }
List<Device> deviceList = new ArrayList<>(); Device device = storager.queryVideoDevice(deviceId);
deviceList.add(storager.queryVideoDevice(deviceId)); return new ResponseEntity<>(device,HttpStatus.OK);
return new ResponseEntity<>(deviceList,HttpStatus.OK);
} }
@GetMapping("/devices") @GetMapping("/devices")
@ -47,4 +57,18 @@ public class DeviceController {
List<Device> deviceList = storager.queryVideoDeviceList(null); List<Device> deviceList = storager.queryVideoDeviceList(null);
return new ResponseEntity<>(deviceList,HttpStatus.OK); return new ResponseEntity<>(deviceList,HttpStatus.OK);
} }
@PostMapping("/devices/{deviceId}/sync")
public DeferredResult<ResponseEntity<Device>> devicesSync(@PathVariable String deviceId){
if (logger.isDebugEnabled()) {
logger.debug("设备信息同步API调用deviceId" + deviceId);
}
Device device = storager.queryVideoDevice(deviceId);
cmder.catalogQuery(device);
DeferredResult<ResponseEntity<Device>> result = new DeferredResult<ResponseEntity<Device>>();
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId, result);
return result;
}
} }

View File

@ -10,7 +10,9 @@ import org.springframework.web.bind.annotation.PathVariable;
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;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
@RestController @RestController
@RequestMapping("/api") @RequestMapping("/api")
@ -21,10 +23,14 @@ public class PlayController {
@Autowired @Autowired
private SIPCommander cmder; private SIPCommander cmder;
@Autowired
private IVideoManagerStorager storager;
@GetMapping("/play/{deviceId}_{channelId}") @GetMapping("/play/{deviceId}_{channelId}")
public ResponseEntity<String> play(@PathVariable String deviceId,@PathVariable String channelId){ public ResponseEntity<String> play(@PathVariable String deviceId,@PathVariable String channelId){
String ssrc = cmder.playStreamCmd(deviceId, channelId); Device device = storager.queryVideoDevice(deviceId);
String ssrc = cmder.playStreamCmd(device, channelId);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("设备预览 API调用deviceId%s channelId%s",deviceId, channelId)); logger.debug(String.format("设备预览 API调用deviceId%s channelId%s",deviceId, channelId));

View File

@ -10,7 +10,9 @@ import org.springframework.web.bind.annotation.PathVariable;
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;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
@RestController @RestController
@RequestMapping("/api") @RequestMapping("/api")
@ -20,6 +22,9 @@ public class PtzController {
@Autowired @Autowired
private SIPCommander cmder; private SIPCommander cmder;
@Autowired
private IVideoManagerStorager storager;
/*** /***
* http://localhost:8080/api/ptz/34020000001320000002_34020000001320000008?leftRight=1&upDown=0&inOut=0&moveSpeed=50&zoomSpeed=0 * http://localhost:8080/api/ptz/34020000001320000002_34020000001320000008?leftRight=1&upDown=0&inOut=0&moveSpeed=50&zoomSpeed=0
@ -38,8 +43,9 @@ public class PtzController {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(String.format("设备云台控制 API调用deviceId%s channelId%s leftRight%d upDown%d inOut%d moveSpeed%d zoomSpeed%d",deviceId, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed)); logger.debug(String.format("设备云台控制 API调用deviceId%s channelId%s leftRight%d upDown%d inOut%d moveSpeed%d zoomSpeed%d",deviceId, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed));
} }
Device device = storager.queryVideoDevice(deviceId);
cmder.ptzCmd(deviceId, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed); cmder.ptzCmd(device, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed);
return new ResponseEntity<String>("success",HttpStatus.OK); return new ResponseEntity<String>("success",HttpStatus.OK);
} }
} }

View File

@ -0,0 +1,47 @@
package com.genersoft.iot.vmp.vmanager.record;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
@RestController
@RequestMapping("/api")
public class RecordController {
private final static Logger logger = LoggerFactory.getLogger(RecordController.class);
@Autowired
private SIPCommander cmder;
@Autowired
private IVideoManagerStorager storager;
@Autowired
private DeferredResultHolder resultHolder;
@GetMapping("/recordinfo/{deviceId}")
public DeferredResult<ResponseEntity<RecordInfo>> recordinfo(@PathVariable String deviceId, String startTime, String endTime){
if (logger.isDebugEnabled()) {
logger.debug(String.format("录像信息 API调用deviceId%s startTime%s startTime%s",deviceId, startTime, endTime));
}
Device device = storager.queryVideoDevice(deviceId);
cmder.recordInfoQuery(device, startTime, endTime);
DeferredResult<ResponseEntity<RecordInfo>> result = new DeferredResult<ResponseEntity<RecordInfo>>();
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CATALOG+deviceId, result);
return result;
}
}