|
@@ -1,5 +1,6 @@
|
|
|
package org.jetlinks.community.media.storage.impl;
|
|
package org.jetlinks.community.media.storage.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -10,6 +11,7 @@ import org.jetlinks.community.media.contanst.VideoManagerConstants;
|
|
|
import org.jetlinks.community.media.entity.MediaDevice;
|
|
import org.jetlinks.community.media.entity.MediaDevice;
|
|
|
import org.jetlinks.community.media.bean.ParentPlatform;
|
|
import org.jetlinks.community.media.bean.ParentPlatform;
|
|
|
import org.jetlinks.community.media.entity.MediaDeviceChannel;
|
|
import org.jetlinks.community.media.entity.MediaDeviceChannel;
|
|
|
|
|
+import org.jetlinks.community.media.sip.SipContext;
|
|
|
import org.jetlinks.community.media.zlm.dto.MediaItem;
|
|
import org.jetlinks.community.media.zlm.dto.MediaItem;
|
|
|
import org.jetlinks.community.media.zlm.entity.MediaServerItem;
|
|
import org.jetlinks.community.media.zlm.entity.MediaServerItem;
|
|
|
import org.jetlinks.community.utils.RedisUtil;
|
|
import org.jetlinks.community.utils.RedisUtil;
|
|
@@ -17,10 +19,7 @@ import org.jetlinks.core.cluster.ClusterManager;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
@SuppressWarnings("rawtypes")
|
|
@SuppressWarnings("rawtypes")
|
|
|
@Component
|
|
@Component
|
|
@@ -97,7 +96,7 @@ public class RedisCacheStorageImpl {
|
|
|
*/
|
|
*/
|
|
|
public boolean startPlay(StreamInfo stream) {
|
|
public boolean startPlay(StreamInfo stream) {
|
|
|
return redis.set(String.format("%S_%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,serverId, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
|
|
return redis.set(String.format("%S_%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,serverId, stream.getStreamId(),stream.getDeviceID(), stream.getChannelId()),
|
|
|
- stream);
|
|
|
|
|
|
|
+ stream);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -111,9 +110,9 @@ public class RedisCacheStorageImpl {
|
|
|
}
|
|
}
|
|
|
return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
|
|
return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
|
|
|
serverId,
|
|
serverId,
|
|
|
- streamInfo.getStreamId(),
|
|
|
|
|
- streamInfo.getDeviceID(),
|
|
|
|
|
- streamInfo.getChannelId()));
|
|
|
|
|
|
|
+ streamInfo.getStreamId(),
|
|
|
|
|
+ streamInfo.getDeviceID(),
|
|
|
|
|
+ streamInfo.getChannelId()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -123,11 +122,11 @@ public class RedisCacheStorageImpl {
|
|
|
|
|
|
|
|
public StreamInfo queryPlay(StreamInfo streamInfo) {
|
|
public StreamInfo queryPlay(StreamInfo streamInfo) {
|
|
|
return (StreamInfo)redis.get(String.format("%S_%s_%s_%s_%s",
|
|
return (StreamInfo)redis.get(String.format("%S_%s_%s_%s_%s",
|
|
|
- VideoManagerConstants.PLAYER_PREFIX,
|
|
|
|
|
- serverId,
|
|
|
|
|
- streamInfo.getStreamId(),
|
|
|
|
|
- streamInfo.getDeviceID(),
|
|
|
|
|
- streamInfo.getChannelId()));
|
|
|
|
|
|
|
+ VideoManagerConstants.PLAYER_PREFIX,
|
|
|
|
|
+ serverId,
|
|
|
|
|
+ streamInfo.getStreamId(),
|
|
|
|
|
+ streamInfo.getDeviceID(),
|
|
|
|
|
+ streamInfo.getChannelId()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public StreamInfo queryPlayByStreamId(String streamId) {
|
|
public StreamInfo queryPlayByStreamId(String streamId) {
|
|
@@ -151,8 +150,8 @@ public class RedisCacheStorageImpl {
|
|
|
public StreamInfo queryPlayByDevice(String deviceId, String channelId) {
|
|
public StreamInfo queryPlayByDevice(String deviceId, String channelId) {
|
|
|
List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
|
|
List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
|
|
|
serverId,
|
|
serverId,
|
|
|
- deviceId,
|
|
|
|
|
- channelId));
|
|
|
|
|
|
|
+ deviceId,
|
|
|
|
|
+ channelId));
|
|
|
if (playLeys == null || playLeys.size() == 0){
|
|
if (playLeys == null || playLeys.size() == 0){
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -177,13 +176,13 @@ public class RedisCacheStorageImpl {
|
|
|
|
|
|
|
|
public boolean startPlayback(StreamInfo stream) {
|
|
public boolean startPlayback(StreamInfo stream) {
|
|
|
return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,serverId,stream.getStreamId(),
|
|
return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,serverId,stream.getStreamId(),
|
|
|
- stream.getDeviceID(), stream.getChannelId()), stream);
|
|
|
|
|
|
|
+ stream.getDeviceID(), stream.getChannelId()), stream);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean startDownload(StreamInfo streamInfo) {
|
|
public boolean startDownload(StreamInfo streamInfo) {
|
|
|
return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, serverId,streamInfo.getStreamId(),
|
|
return redis.set(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, serverId,streamInfo.getStreamId(),
|
|
|
- streamInfo.getDeviceID(), streamInfo.getChannelId()), streamInfo);
|
|
|
|
|
|
|
+ streamInfo.getDeviceID(), streamInfo.getChannelId()), streamInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -197,9 +196,9 @@ public class RedisCacheStorageImpl {
|
|
|
// }
|
|
// }
|
|
|
return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
|
return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
|
|
serverId,
|
|
serverId,
|
|
|
- streamInfo.getStreamId(),
|
|
|
|
|
- streamInfo.getDeviceID(),
|
|
|
|
|
- streamInfo.getChannelId()));
|
|
|
|
|
|
|
+ streamInfo.getStreamId(),
|
|
|
|
|
+ streamInfo.getDeviceID(),
|
|
|
|
|
+ streamInfo.getChannelId()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -209,12 +208,12 @@ public class RedisCacheStorageImpl {
|
|
|
// code);
|
|
// code);
|
|
|
List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
|
List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
|
|
serverId,
|
|
serverId,
|
|
|
- deviceId,
|
|
|
|
|
- code));
|
|
|
|
|
|
|
+ deviceId,
|
|
|
|
|
+ code));
|
|
|
if (playLeys == null || playLeys.size() == 0) {
|
|
if (playLeys == null || playLeys.size() == 0) {
|
|
|
playLeys = redis.scan(String.format("%S_%s_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
|
playLeys = redis.scan(String.format("%S_%s_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
|
|
serverId,
|
|
serverId,
|
|
|
- deviceId));
|
|
|
|
|
|
|
+ deviceId));
|
|
|
}
|
|
}
|
|
|
if (playLeys == null || playLeys.size() == 0) {
|
|
if (playLeys == null || playLeys.size() == 0) {
|
|
|
return null;
|
|
return null;
|
|
@@ -338,38 +337,8 @@ public class RedisCacheStorageImpl {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- public void clearCacheByDeviceId(String deviceId) {
|
|
|
|
|
- List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX,
|
|
|
|
|
- serverId,
|
|
|
|
|
- deviceId));
|
|
|
|
|
- if (playLeys.size() > 0) {
|
|
|
|
|
- for (Object key : playLeys) {
|
|
|
|
|
- redis.del(key.toString());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- List<Object> playBackers = redis.scan(String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
|
|
|
|
|
- serverId,
|
|
|
|
|
- deviceId));
|
|
|
|
|
- if (playBackers.size() > 0) {
|
|
|
|
|
- for (Object key : playBackers) {
|
|
|
|
|
- redis.del(key.toString());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- List<Object> deviceCache = redis.scan(String.format("%S%s_%s", VideoManagerConstants.DEVICE_PREFIX,
|
|
|
|
|
- serverId,
|
|
|
|
|
- deviceId));
|
|
|
|
|
- if (deviceCache.size() > 0) {
|
|
|
|
|
- for (Object key : deviceCache) {
|
|
|
|
|
- redis.del(key.toString());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
public void outlineForAll() {
|
|
public void outlineForAll() {
|
|
|
- List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + serverId + "_" + "*" );
|
|
|
|
|
|
|
+ List<Object> onlineDevices = redis.scan("*"+VideoManagerConstants.DEVICE_PREFIX + serverId + "_" + "*" );
|
|
|
for (int i = 0; i < onlineDevices.size(); i++) {
|
|
for (int i = 0; i < onlineDevices.size(); i++) {
|
|
|
String key = (String) onlineDevices.get(i);
|
|
String key = (String) onlineDevices.get(i);
|
|
|
redis.del(key);
|
|
redis.del(key);
|
|
@@ -379,10 +348,16 @@ public class RedisCacheStorageImpl {
|
|
|
|
|
|
|
|
public List<String> getOnlineForAll() {
|
|
public List<String> getOnlineForAll() {
|
|
|
List<String> result = new ArrayList<>();
|
|
List<String> result = new ArrayList<>();
|
|
|
- List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + serverId + "_" + "*" );
|
|
|
|
|
- for (int i = 0; i < onlineDevices.size(); i++) {
|
|
|
|
|
- String key = (String) onlineDevices.get(i);
|
|
|
|
|
- result.add((String) redis.get(key));
|
|
|
|
|
|
|
+ List<Object> onlineDeviceIds = redis.scan("*"+VideoManagerConstants.DEVICE_PREFIX + serverId + "_" + "*" );
|
|
|
|
|
+ if (CollectionUtil.isNotEmpty(onlineDeviceIds)) {
|
|
|
|
|
+ onlineDeviceIds.forEach(deviceIdKey->{
|
|
|
|
|
+ if(Objects.isNull(deviceIdKey)){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String strKey = String.valueOf(deviceIdKey);
|
|
|
|
|
+ String key = strKey.substring(strKey.indexOf(VideoManagerConstants.DEVICE_PREFIX));
|
|
|
|
|
+ result.add(key.substring(key.lastIndexOf("_")+1));
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -452,8 +427,7 @@ public class RedisCacheStorageImpl {
|
|
|
|
|
|
|
|
public void updateDevice(MediaDevice device) {
|
|
public void updateDevice(MediaDevice device) {
|
|
|
String key = VideoManagerConstants.DEVICE_PREFIX + serverId + "_" + device.getId();
|
|
String key = VideoManagerConstants.DEVICE_PREFIX + serverId + "_" + device.getId();
|
|
|
- redis.set(key, device);
|
|
|
|
|
- redis.expire(key,device.getExpires());
|
|
|
|
|
|
|
+ redis.set(key, device, Optional.ofNullable(device.getExpires()).orElse(SipContext.getConfig().getTimeout().intValue()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -476,13 +450,6 @@ public class RedisCacheStorageImpl {
|
|
|
return (MediaServerItem)redis.get(key);
|
|
return (MediaServerItem)redis.get(key);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public List<MediaDevice> getAllOnlineDevice() {
|
|
|
|
|
- List<Object> scan = redis.scan(VideoManagerConstants.DEVICE_PREFIX + "*");
|
|
|
|
|
- List<MediaDevice> mediaDevices = new ArrayList<>();
|
|
|
|
|
- scan.stream().filter(result-> result instanceof MediaDevice).forEach(result->mediaDevices.add((MediaDevice) result));
|
|
|
|
|
- return mediaDevices;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) {
|
|
// public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) {
|
|
|
// String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + serverId + "_" + gpsMsgInfo.getId();
|
|
// String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + serverId + "_" + gpsMsgInfo.getId();
|
|
|
// redis.set(key, gpsMsgInfo, 60); // 默认GPS消息保存1分钟
|
|
// redis.set(key, gpsMsgInfo, 60); // 默认GPS消息保存1分钟
|
|
@@ -539,4 +506,28 @@ public class RedisCacheStorageImpl {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发起点播请求的设备流信息
|
|
|
|
|
+ * @param streamId
|
|
|
|
|
+ * @param deviceId
|
|
|
|
|
+ * @param channelId
|
|
|
|
|
+ */
|
|
|
|
|
+ public void addRequestStream(String streamId,String deviceId,String channelId) {
|
|
|
|
|
+ MediaDeviceChannel mediaDeviceChannel = new MediaDeviceChannel();
|
|
|
|
|
+ mediaDeviceChannel.setDeviceId(deviceId);
|
|
|
|
|
+ mediaDeviceChannel.setChannelId(channelId);
|
|
|
|
|
+ String key = VideoManagerConstants.PLAY_REQUEST_PREFIX + serverId + "_" + streamId;
|
|
|
|
|
+ redis.set(key,mediaDeviceChannel);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void removeRequestStream(String streamId){
|
|
|
|
|
+ String key = VideoManagerConstants.PLAY_REQUEST_PREFIX + serverId + "_" + streamId;
|
|
|
|
|
+ redis.del(key);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public MediaDeviceChannel getRequestStream(String streamId){
|
|
|
|
|
+ String key = VideoManagerConstants.PLAY_REQUEST_PREFIX + serverId + "_" + streamId;
|
|
|
|
|
+ return (MediaDeviceChannel) redis.get(key);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|