拆分redis中device与channel的存储方式
支持分页 接口直接返回播放地址
This commit is contained in:
@@ -2,7 +2,12 @@ package com.genersoft.iot.vmp.storager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.PageResult;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
|
||||
/**
|
||||
* @Description:视频设备数据存储接口
|
||||
@@ -10,7 +15,20 @@ import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
* @date: 2020年5月6日 下午2:14:31
|
||||
*/
|
||||
public interface IVideoManagerStorager {
|
||||
|
||||
|
||||
/**
|
||||
* 更新流媒体信息
|
||||
* @param mediaServerConfig
|
||||
* @return
|
||||
*/
|
||||
public boolean updateMediaInfo(MediaServerConfig mediaServerConfig);
|
||||
|
||||
/**
|
||||
* 获取流媒体信息
|
||||
* @return
|
||||
*/
|
||||
public MediaServerConfig getMediaInfo();
|
||||
|
||||
/**
|
||||
* 根据设备ID判断设备是否存在
|
||||
*
|
||||
@@ -33,7 +51,15 @@ public interface IVideoManagerStorager {
|
||||
* @param device 设备对象
|
||||
* @return true:创建成功 false:创建失败
|
||||
*/
|
||||
public boolean update(Device device);
|
||||
public boolean updateDevice(Device device);
|
||||
|
||||
/**
|
||||
* 添加设备通道
|
||||
*
|
||||
* @param deviceId 设备id
|
||||
* @param channel 通道
|
||||
*/
|
||||
public void updateChannel(String deviceId, DeviceChannel channel);
|
||||
|
||||
/**
|
||||
* 获取设备
|
||||
@@ -42,15 +68,47 @@ public interface IVideoManagerStorager {
|
||||
* @return DShadow 设备对象
|
||||
*/
|
||||
public Device queryVideoDevice(String deviceId);
|
||||
|
||||
|
||||
/**
|
||||
* 获取某个设备的通道列表
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param page 分页 当前页
|
||||
* @param count 每页数量
|
||||
* @return
|
||||
*/
|
||||
public PageResult queryChannelsByDeviceId(String deviceId, int page, int count);
|
||||
|
||||
/**
|
||||
* 获取某个设备的通道列表
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @return
|
||||
*/
|
||||
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId);
|
||||
/**
|
||||
* 获取某个设备的通道
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
*/
|
||||
public DeviceChannel queryChannel(String deviceId, String channelId);
|
||||
|
||||
/**
|
||||
* 获取多个设备
|
||||
*
|
||||
* @param deviceIds 设备ID数组
|
||||
* @return List<Device> 设备对象数组
|
||||
*/
|
||||
public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count);
|
||||
|
||||
/**
|
||||
* 获取多个设备
|
||||
*
|
||||
* @param deviceIds 设备ID数组
|
||||
* @return List<Device> 设备对象数组
|
||||
*/
|
||||
public List<Device> queryVideoDeviceList(String[] deviceIds);
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
*
|
||||
@@ -74,4 +132,35 @@ public interface IVideoManagerStorager {
|
||||
* @return true:更新成功 false:更新失败
|
||||
*/
|
||||
public boolean outline(String deviceId);
|
||||
|
||||
/**
|
||||
* 开始播放时将流存入
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
* @param stream 流信息
|
||||
* @return
|
||||
*/
|
||||
public boolean startPlay(String deviceId, String channelId, StreamInfo stream);
|
||||
|
||||
/**
|
||||
* 停止播放时删除
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
* @return
|
||||
*/
|
||||
public boolean stopPlay(String deviceId, String channelId);
|
||||
|
||||
/**
|
||||
* 查找视频流
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
* @return
|
||||
*/
|
||||
public StreamInfo queryPlay(String deviceId, String channelId);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.genersoft.iot.vmp.storager.jdbc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.genersoft.iot.vmp.common.PageResult;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -17,7 +21,17 @@ import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
@Component("jdbcStorager")
|
||||
public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager {
|
||||
|
||||
/**
|
||||
@Override
|
||||
public boolean updateMediaInfo(MediaServerConfig mediaServerConfig) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaServerConfig getMediaInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据设备ID判断设备是否存在
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
@@ -40,19 +54,18 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 视频设备更新
|
||||
*
|
||||
* @param device 设备对象
|
||||
* @return true:更新成功 false:更新失败
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean update(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
public boolean updateDevice(Device device) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateChannel(String deviceId, DeviceChannel channel) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取设备
|
||||
*
|
||||
@@ -65,6 +78,26 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult queryChannelsByDeviceId(String deviceId, int page, int count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceChannel queryChannel(String deviceId, String channelId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个设备
|
||||
*
|
||||
@@ -113,4 +146,19 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startPlay(String deviceId, String channelId, StreamInfo stream) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopPlay(String deviceId, String channelId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamInfo queryPlay(String deviceId, String channelId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,12 @@ package com.genersoft.iot.vmp.storager.redis;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.PageResult;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -21,7 +27,8 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redis;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据设备ID判断设备是否存在
|
||||
*
|
||||
@@ -30,7 +37,7 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public boolean exists(String deviceId) {
|
||||
return redis.hasKey(VideoManagerConstants.CACHEKEY_PREFIX+deviceId);
|
||||
return redis.hasKey(VideoManagerConstants.DEVICE_PREFIX+deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,9 +48,11 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public boolean create(Device device) {
|
||||
return redis.set(VideoManagerConstants.CACHEKEY_PREFIX+device.getDeviceId(), device);
|
||||
return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 视频设备更新
|
||||
*
|
||||
@@ -51,8 +60,26 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
* @return true:更新成功 false:更新失败
|
||||
*/
|
||||
@Override
|
||||
public boolean update(Device device) {
|
||||
return redis.set(VideoManagerConstants.CACHEKEY_PREFIX+device.getDeviceId(), device);
|
||||
public boolean updateDevice(Device device) {
|
||||
List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + device.getDeviceId() + "_" + "*");
|
||||
// 更新device中的通道数量
|
||||
device.setChannelCount(deviceChannelList.size());
|
||||
// 存储device
|
||||
return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateChannel(String deviceId, DeviceChannel channel) {
|
||||
// 存储通道
|
||||
redis.set(VideoManagerConstants.CACHEKEY_PREFIX+deviceId + "_" + channel.getChannelId(),
|
||||
channel);
|
||||
List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
|
||||
// 更新device中的通道数量
|
||||
Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId);
|
||||
device.setChannelCount(deviceChannelList.size());
|
||||
redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,26 +90,94 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public Device queryVideoDevice(String deviceId) {
|
||||
return (Device)redis.get(VideoManagerConstants.CACHEKEY_PREFIX+deviceId);
|
||||
return (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
@Override
|
||||
public PageResult queryChannelsByDeviceId(String deviceId, int page, int count) {
|
||||
List<DeviceChannel> result = new ArrayList<>();
|
||||
PageResult pageResult = new PageResult<DeviceChannel>();
|
||||
List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
|
||||
pageResult.setPage(page);
|
||||
pageResult.setCount(count);
|
||||
pageResult.setTotal(deviceChannelList.size());
|
||||
int maxCount = (page + 1 ) * count;
|
||||
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
|
||||
for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) {
|
||||
result.add((DeviceChannel)redis.get((String)deviceChannelList.get(i)));
|
||||
}
|
||||
pageResult.setData(result);
|
||||
}
|
||||
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) {
|
||||
List<DeviceChannel> result = new ArrayList<>();
|
||||
List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*");
|
||||
if (deviceChannelList != null && deviceChannelList.size() > 0 ) {
|
||||
for (int i = 0; i < deviceChannelList.size(); i++) {
|
||||
result.add((DeviceChannel)redis.get((String)deviceChannelList.get(i)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceChannel queryChannel(String deviceId, String channelId) {
|
||||
return (DeviceChannel)redis.get(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + channelId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取多个设备
|
||||
*
|
||||
* @param deviceIds 设备ID数组
|
||||
* @return List<Device> 设备对象数组
|
||||
*/
|
||||
@Override
|
||||
public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) {
|
||||
List<Device> devices = new ArrayList<>();
|
||||
PageResult pageResult = new PageResult<Device>();
|
||||
pageResult.setPage(page);
|
||||
pageResult.setCount(count);
|
||||
|
||||
if (deviceIds == null || deviceIds.length == 0) {
|
||||
|
||||
List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*");
|
||||
pageResult.setTotal(deviceIdList.size());
|
||||
int maxCount = (page + 1)* count;
|
||||
for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) {
|
||||
devices.add((Device)redis.get((String)deviceIdList.get(i)));
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < deviceIds.length; i++) {
|
||||
devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]));
|
||||
}
|
||||
}
|
||||
pageResult.setData(devices);
|
||||
return pageResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多个设备
|
||||
*
|
||||
* @param deviceIds 设备ID数组
|
||||
* @return List<Device> 设备对象数组
|
||||
*/
|
||||
@Override
|
||||
public List<Device> queryVideoDeviceList(String[] deviceIds) {
|
||||
List<Device> devices = new ArrayList<>();
|
||||
|
||||
if (deviceIds == null || deviceIds.length == 0) {
|
||||
List<Object> deviceIdList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX+"*");
|
||||
List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*");
|
||||
for (int i = 0; i < deviceIdList.size(); i++) {
|
||||
devices.add((Device)redis.get((String)deviceIdList.get(i)));
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < deviceIds.length; i++) {
|
||||
devices.add((Device)redis.get(VideoManagerConstants.CACHEKEY_PREFIX+deviceIds[i]));
|
||||
devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]));
|
||||
}
|
||||
}
|
||||
return devices;
|
||||
@@ -96,7 +191,7 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public boolean delete(String deviceId) {
|
||||
return redis.del(VideoManagerConstants.CACHEKEY_PREFIX+deviceId);
|
||||
return redis.del(VideoManagerConstants.DEVICE_PREFIX+deviceId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,9 +202,9 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public boolean online(String deviceId) {
|
||||
Device device = (Device)redis.get(VideoManagerConstants.CACHEKEY_PREFIX+deviceId);
|
||||
Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId);
|
||||
device.setOnline(1);
|
||||
return redis.set(VideoManagerConstants.CACHEKEY_PREFIX+device.getDeviceId(), device);
|
||||
return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,9 +215,64 @@ public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager {
|
||||
*/
|
||||
@Override
|
||||
public boolean outline(String deviceId) {
|
||||
Device device = (Device)redis.get(VideoManagerConstants.CACHEKEY_PREFIX+deviceId);
|
||||
Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId);
|
||||
if (device == null) return false;
|
||||
device.setOnline(0);
|
||||
return redis.set(VideoManagerConstants.CACHEKEY_PREFIX+device.getDeviceId(), device);
|
||||
return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始播放时将流存入redis
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean startPlay(String deviceId, String channelId, StreamInfo stream) {
|
||||
return redis.set(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId),
|
||||
stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止播放时从redis删除
|
||||
*
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean stopPlay(String deviceId, String channelId) {
|
||||
return redis.del(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询播放列表
|
||||
* @param deviceId 设备ID
|
||||
* @param channelId 通道ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public StreamInfo queryPlay(String deviceId, String channelId) {
|
||||
return (StreamInfo)redis.get(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新流媒体信息
|
||||
* @param mediaServerConfig
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean updateMediaInfo(MediaServerConfig mediaServerConfig) {
|
||||
return redis.set(VideoManagerConstants.MEDIA_SERVER_PREFIX,mediaServerConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流媒体信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public MediaServerConfig getMediaInfo() {
|
||||
return (MediaServerConfig)redis.get(VideoManagerConstants.MEDIA_SERVER_PREFIX);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user