拆分redis中device与channel的存储方式

支持分页
接口直接返回播放地址
This commit is contained in:
648540858
2020-09-25 17:22:22 +08:00
parent 956fd47ed6
commit da14c7f24c
21 changed files with 1445 additions and 78 deletions

View File

@@ -49,7 +49,9 @@ public class Device {
/**
* 通道列表
*/
private Map<String,DeviceChannel> channelMap;
// private Map<String,DeviceChannel> channelMap;
private int channelCount;
public String getDeviceId() {
@@ -84,13 +86,13 @@ public class Device {
this.host = host;
}
public Map<String, DeviceChannel> getChannelMap() {
return channelMap;
}
public void setChannelMap(Map<String, DeviceChannel> channelMap) {
this.channelMap = channelMap;
}
// public Map<String, DeviceChannel> getChannelMap() {
// return channelMap;
// }
//
// public void setChannelMap(Map<String, DeviceChannel> channelMap) {
// this.channelMap = channelMap;
// }
public String getManufacturer() {
return manufacturer;
@@ -123,4 +125,12 @@ public class Device {
public void setOnline(int online) {
this.online = online;
}
public int getChannelCount() {
return channelCount;
}
public void setChannelCount(int channelCount) {
this.channelCount = channelCount;
}
}

View File

@@ -100,7 +100,12 @@ public class DeviceChannel {
/**
* 密码
*/
private String password;
private String password;
/**
* 云台控制
*/
private int PTZType;
/**
* 在线/离线
@@ -123,6 +128,11 @@ public class DeviceChannel {
*/
private double latitude;
/**
* 流唯一编号,存在表示正在直播
*/
private String ssrc;
public String getChannelId() {
return channelId;
}
@@ -306,4 +316,20 @@ public class DeviceChannel {
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public int getPTZType() {
return PTZType;
}
public void setPTZType(int PTZType) {
this.PTZType = PTZType;
}
public String getSsrc() {
return ssrc;
}
public void setSsrc(String ssrc) {
this.ssrc = ssrc;
}
}

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.gb28181.bean.Device;
/**
@@ -69,7 +70,7 @@ public interface ISIPCommander {
* @param device 视频设备
* @param channelId 预览通道
*/
public String playStreamCmd(Device device,String channelId);
public StreamInfo playStreamCmd(Device device, String channelId);
/**
* 请求回放视频流

View File

@@ -15,8 +15,14 @@ import javax.sip.address.SipURI;
import javax.sip.header.ViaHeader;
import javax.sip.message.Request;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.MediaServerConfig;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.genersoft.iot.vmp.conf.SipConfig;
@@ -42,6 +48,9 @@ public class SIPCommander implements ISIPCommander {
@Autowired
private VideoStreamSessionManager streamSession;
@Autowired
private IVideoManagerStorager storager;
@Autowired
@Qualifier(value="tcpSipProvider")
@@ -50,6 +59,9 @@ public class SIPCommander implements ISIPCommander {
@Autowired
@Qualifier(value="udpSipProvider")
private SipProvider udpSipProvider;
@Value("${media.ip}")
private String mediaIp;
/**
* 云台方向放控制,使用配置文件中的默认镜头移动速度
@@ -58,7 +70,6 @@ public class SIPCommander implements ISIPCommander {
* @param channelId 预览通道
* @param leftRight 镜头左移右移 0:停止 1:左移 2:右移
* @param upDown 镜头上移下移 0:停止 1:上移 2:下移
* @param moveSpeed 镜头移动速度
*/
@Override
public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown) {
@@ -191,7 +202,7 @@ public class SIPCommander implements ISIPCommander {
* @param channelId 预览通道
*/
@Override
public String playStreamCmd(Device device, String channelId) {
public StreamInfo playStreamCmd(Device device, String channelId) {
try {
String ssrc = streamSession.createPlaySsrc();
@@ -223,7 +234,24 @@ public class SIPCommander implements ISIPCommander {
ClientTransaction transaction = transmitRequest(device, request);
streamSession.put(ssrc, transaction);
return ssrc;
DeviceChannel deviceChannel = storager.queryChannel(device.getDeviceId(), channelId);
if (deviceChannel != null) {
deviceChannel.setSsrc(ssrc);
storager.updateChannel(device.getDeviceId(), deviceChannel);
}
MediaServerConfig mediaInfo = storager.getMediaInfo();
StreamInfo streamInfo = new StreamInfo();
streamInfo.setSsrc(ssrc);
// String streamId = Integer.toHexString(Integer.parseInt(streamInfo.getSsrc()));
String streamId = String.format("%08x", Integer.parseInt(streamInfo.getSsrc())).toUpperCase(); // ZLM 要求大写且首位补零
streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaIp, mediaInfo.getHttpPort(), streamId));
streamInfo.setWS_FLV(String.format("ws://%s:%s/rtp/%s.flv", mediaIp, mediaInfo.getHttpPort(), streamId));
streamInfo.setRTMP(String.format("rtmp://%s:%s/rtp/%s", mediaIp, mediaInfo.getRtmpPort(), streamId));
streamInfo.setHLS(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaIp, mediaInfo.getHttpPort(), streamId));
streamInfo.setRTSP(String.format("rtsp://%s:%s/rtp/%s", mediaIp, mediaInfo.getRtspPort(), streamId));
storager.startPlay(device.getDeviceId(), channelId, streamInfo);
return streamInfo;
} catch ( SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace();
return null;
@@ -281,8 +309,6 @@ public class SIPCommander implements ISIPCommander {
/**
* 视频流停止
*
* @param device 视频设备
* @param channelId 预览通道
*/
@Override
public void streamByeCmd(String ssrc) {

View File

@@ -76,8 +76,6 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
* 处理MESSAGE请求
*
* @param evt
* @param layer
* @param transaction
*/
@Override
public void process(RequestEvent evt) {
@@ -127,7 +125,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
device.setManufacturer(XmlUtil.getText(rootElement,"Manufacturer"));
device.setModel(XmlUtil.getText(rootElement,"Model"));
device.setFirmware(XmlUtil.getText(rootElement,"Firmware"));
storager.update(device);
storager.updateDevice(device);
RequestMessage msg = new RequestMessage();
msg.setDeviceId(deviceId);
@@ -158,11 +156,6 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
if (device == null) {
return;
}
Map<String, DeviceChannel> channelMap = device.getChannelMap();
if (channelMap == null) {
channelMap = new HashMap<String, DeviceChannel>(5);
device.setChannelMap(channelMap);
}
// 遍历DeviceList
while (deviceListIterator.hasNext()) {
Element itemDevice = deviceListIterator.next();
@@ -175,7 +168,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
String channelName = channdelNameElement != null ? channdelNameElement.getText().toString() : "";
Element statusElement = itemDevice.element("Status");
String status = statusElement != null ? statusElement.getText().toString() : "ON";
DeviceChannel deviceChannel = channelMap.containsKey(channelDeviceId) ? channelMap.get(channelDeviceId) : new DeviceChannel();
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setName(channelName);
deviceChannel.setChannelId(channelDeviceId);
if(status.equals("ON")) {
@@ -205,10 +198,12 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
deviceChannel.setPassword(XmlUtil.getText(itemDevice,"Password"));
deviceChannel.setLongitude(itemDevice.element("Longitude") == null? 0.00:Double.parseDouble(XmlUtil.getText(itemDevice,"Longitude")));
deviceChannel.setLatitude(itemDevice.element("Latitude") == null? 0.00:Double.parseDouble(XmlUtil.getText(itemDevice,"Latitude")));
channelMap.put(channelDeviceId, deviceChannel);
deviceChannel.setPTZType(itemDevice.element("PTZType") == null? 0:Integer.parseInt(XmlUtil.getText(itemDevice,"PTZType")));
storager.updateChannel(device.getDeviceId(), deviceChannel);
}
// 更新
storager.update(device);
storager.updateDevice(device);
RequestMessage msg = new RequestMessage();
msg.setDeviceId(deviceId);
msg.setType(DeferredResultHolder.CALLBACK_CMD_CATALOG);
@@ -232,13 +227,15 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
// TODO 也可能是通道
// storager.queryChannel(deviceId)
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);
storager.updateDevice(device);
cmder.catalogQuery(device);
} catch (DocumentException e) {
e.printStackTrace();

View File

@@ -138,7 +138,7 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
// 下发catelog查询目录
if (registerFlag == 1 && device != null) {
System.out.println("注册成功! deviceId:" + device.getDeviceId());
storager.update(device);
storager.updateDevice(device);
publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER);
handler.onRegister(device);
} else if (registerFlag == 2) {