From 3b5a37c270e5b6649b9a168ee753c2b3353a257a Mon Sep 17 00:00:00 2001
From: zouyaoji <370681295@qq.com>
Date: 星期六, 06 八月 2022 11:27:02 +0800
Subject: [PATCH] 前端显示媒体服务器配置时报错修复
---
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java | 200 +++++++++++++++++++++++++++++++++++--------------
1 files changed, 141 insertions(+), 59 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
index 1fb7fd0..31294a0 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -9,18 +9,21 @@
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
+import com.genersoft.iot.vmp.media.zlm.dto.OnPublishHookParam;
+import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
import com.genersoft.iot.vmp.service.bean.ThirdPartyGB;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
+import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
-import java.text.SimpleDateFormat;
import java.util.*;
@SuppressWarnings("rawtypes")
@@ -37,8 +40,6 @@
@Autowired
private UserSetting userSetting;
-
- private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Override
public Long getCSEQ(String method) {
@@ -103,7 +104,9 @@
*/
@Override
public boolean stopPlay(StreamInfo streamInfo) {
- if (streamInfo == null) return false;
+ if (streamInfo == null) {
+ return false;
+ }
return redis.del(String.format("%S_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
userSetting.getServerId(),
streamInfo.getStream(),
@@ -127,7 +130,9 @@
@Override
public StreamInfo queryPlayByStreamId(String streamId) {
List<Object> playLeys = redis.scan(String.format("%S_%s_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId));
- if (playLeys == null || playLeys.size() == 0) return null;
+ if (playLeys == null || playLeys.size() == 0) {
+ return null;
+ }
return (StreamInfo)redis.get(playLeys.get(0).toString());
}
@@ -137,7 +142,9 @@
userSetting.getServerId(),
deviceId,
channelId));
- if (playLeys == null || playLeys.size() == 0) return null;
+ if (playLeys == null || playLeys.size() == 0) {
+ return null;
+ }
return (StreamInfo)redis.get(playLeys.get(0).toString());
}
@@ -146,7 +153,9 @@
Map<String, StreamInfo> streamInfos = new HashMap<>();
// List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId));
List<Object> players = redis.scan(String.format("%S_%s_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId));
- if (players.size() == 0) return streamInfos;
+ if (players.size() == 0) {
+ return streamInfos;
+ }
for (Object player : players) {
String key = (String) player;
StreamInfo streamInfo = (StreamInfo) redis.get(key);
@@ -182,10 +191,18 @@
deviceChannel.setDeviceId(deviceId);
deviceChannelMapper.update(deviceChannel);
}
- if (deviceId == null) deviceId = "*";
- if (channelId == null) channelId = "*";
- if (stream == null) stream = "*";
- if (callId == null) callId = "*";
+ if (deviceId == null) {
+ deviceId = "*";
+ }
+ if (channelId == null) {
+ channelId = "*";
+ }
+ if (stream == null) {
+ stream = "*";
+ }
+ if (callId == null) {
+ callId = "*";
+ }
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
userSetting.getServerId(),
deviceId,
@@ -210,10 +227,18 @@
deviceChannel.setDeviceId(deviceId);
deviceChannelMapper.update(deviceChannel);
}
- if (deviceId == null) deviceId = "*";
- if (channelId == null) channelId = "*";
- if (stream == null) stream = "*";
- if (callId == null) callId = "*";
+ if (deviceId == null) {
+ deviceId = "*";
+ }
+ if (channelId == null) {
+ channelId = "*";
+ }
+ if (stream == null) {
+ stream = "*";
+ }
+ if (callId == null) {
+ callId = "*";
+ }
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetting.getServerId(),
deviceId,
@@ -235,10 +260,18 @@
if (stream == null && callId == null) {
return null;
}
- if (deviceId == null) deviceId = "*";
- if (channelId == null) channelId = "*";
- if (stream == null) stream = "*";
- if (callId == null) callId = "*";
+ if (deviceId == null) {
+ deviceId = "*";
+ }
+ if (channelId == null) {
+ channelId = "*";
+ }
+ if (stream == null) {
+ stream = "*";
+ }
+ if (callId == null) {
+ callId = "*";
+ }
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX,
userSetting.getServerId(),
deviceId,
@@ -328,10 +361,18 @@
@Override
public SendRtpItem querySendRTPServer(String platformGbId, String channelId, String streamId, String callId) {
- if (platformGbId == null) platformGbId = "*";
- if (channelId == null) channelId = "*";
- if (streamId == null) streamId = "*";
- if (callId == null) callId = "*";
+ if (platformGbId == null) {
+ platformGbId = "*";
+ }
+ if (channelId == null) {
+ channelId = "*";
+ }
+ if (streamId == null) {
+ streamId = "*";
+ }
+ if (callId == null) {
+ callId = "*";
+ }
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
+ "_" + channelId + "_" + streamId + "_" + callId;
List<Object> scan = redis.scan(key);
@@ -344,7 +385,9 @@
@Override
public List<SendRtpItem> querySendRTPServer(String platformGbId) {
- if (platformGbId == null) platformGbId = "*";
+ if (platformGbId == null) {
+ platformGbId = "*";
+ }
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId + "_*" + "_*" + "_*";
List<Object> queryResult = redis.scan(key);
List<SendRtpItem> result= new ArrayList<>();
@@ -364,8 +407,12 @@
*/
@Override
public void deleteSendRTPServer(String platformGbId, String channelId, String callId, String streamId) {
- if (streamId == null) streamId = "*";
- if (callId == null) callId = "*";
+ if (streamId == null) {
+ streamId = "*";
+ }
+ if (callId == null) {
+ callId = "*";
+ }
String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + userSetting.getServerId() + "_" + platformGbId
+ "_" + channelId + "_" + streamId + "_" + callId;
List<Object> scan = redis.scan(key);
@@ -424,26 +471,6 @@
}
@Override
- public void outlineForAll() {
- List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + "*" );
- for (int i = 0; i < onlineDevices.size(); i++) {
- String key = (String) onlineDevices.get(i);
- redis.del(key);
- }
- }
-
- @Override
- public List<String> getOnlineForAll() {
- List<String> result = new ArrayList<>();
- List<Object> onlineDevices = redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + "*" );
- for (int i = 0; i < onlineDevices.size(); i++) {
- String key = (String) onlineDevices.get(i);
- result.add((String) redis.get(key));
- }
- return result;
- }
-
- @Override
public void updateWVPInfo(JSONObject jsonObject, int time) {
String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetting.getServerId();
redis.set(key, jsonObject, time);
@@ -452,13 +479,18 @@
@Override
public void sendStreamChangeMsg(String type, JSONObject jsonObject) {
String key = VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + type;
- logger.debug("[redis 娴佸彉鍖栦簨浠禲 {}: {}", key, jsonObject.toString());
+ logger.info("[redis 娴佸彉鍖栦簨浠禲 {}: {}", key, jsonObject.toString());
redis.convertAndSend(key, jsonObject);
}
@Override
public void addStream(MediaServerItem mediaServerItem, String type, String app, String streamId, MediaItem mediaItem) {
+ // 鏌ユ壘鏄惁浣跨敤浜哻allID
+ StreamAuthorityInfo streamAuthorityInfo = getStreamAuthorityInfo(app, streamId);
String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerItem.getId();
+ if (streamAuthorityInfo != null) {
+ mediaItem.setCallId(streamAuthorityInfo.getCallId());
+ }
redis.set(key, mediaItem);
}
@@ -473,10 +505,18 @@
if (stream == null && callId == null) {
return null;
}
- if (deviceId == null) deviceId = "*";
- if (channelId == null) channelId = "*";
- if (stream == null) stream = "*";
- if (callId == null) callId = "*";
+ if (deviceId == null) {
+ deviceId = "*";
+ }
+ if (channelId == null) {
+ channelId = "*";
+ }
+ if (stream == null) {
+ stream = "*";
+ }
+ if (callId == null) {
+ callId = "*";
+ }
String key = String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX,
userSetting.getServerId(),
deviceId,
@@ -555,16 +595,36 @@
String scanKey = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_*";
List<GPSMsgInfo> result = new ArrayList<>();
List<Object> keys = redis.scan(scanKey);
- for (int i = 0; i < keys.size(); i++) {
- String key = (String) keys.get(i);
+ for (Object o : keys) {
+ String key = (String) o;
GPSMsgInfo gpsMsgInfo = (GPSMsgInfo) redis.get(key);
if (!gpsMsgInfo.isStored()) { // 鍙彇娌℃湁瀛樿繃寰�
- result.add((GPSMsgInfo)redis.get(key));
+ result.add((GPSMsgInfo) redis.get(key));
}
}
return result;
}
+
+ @Override
+ public void updateStreamAuthorityInfo(String app, String stream, StreamAuthorityInfo streamAuthorityInfo) {
+ String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream;
+ redis.set(key, streamAuthorityInfo);
+ }
+
+ @Override
+ public void removeStreamAuthorityInfo(String app, String stream) {
+ String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
+ redis.del(key);
+ }
+
+ @Override
+ public StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream) {
+ String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
+ return (StreamAuthorityInfo) redis.get(key);
+
+ }
+
@Override
public MediaItem getStreamInfo(String app, String streamId, String mediaServerId) {
@@ -584,7 +644,7 @@
public void addCpuInfo(double cpuInfo) {
String key = VideoManagerConstants.SYSTEM_INFO_CPU_PREFIX + userSetting.getServerId();
SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>();
- systemInfoDto.setTime(format.format(System.currentTimeMillis()));
+ systemInfoDto.setTime(DateUtil.getNow());
systemInfoDto.setData(cpuInfo);
redis.lSet(key, systemInfoDto);
// 姣忕涓�涓紝鏈�澶氬彧瀛�30涓�
@@ -599,7 +659,7 @@
public void addMemInfo(double memInfo) {
String key = VideoManagerConstants.SYSTEM_INFO_MEM_PREFIX + userSetting.getServerId();
SystemInfoDto<Double> systemInfoDto = new SystemInfoDto<>();
- systemInfoDto.setTime(format.format(System.currentTimeMillis()));
+ systemInfoDto.setTime(DateUtil.getNow());
systemInfoDto.setData(memInfo);
redis.lSet(key, systemInfoDto);
// 姣忕涓�涓紝鏈�澶氬彧瀛�30涓�
@@ -614,7 +674,7 @@
public void addNetInfo(Map<String, String> networkInterfaces) {
String key = VideoManagerConstants.SYSTEM_INFO_NET_PREFIX + userSetting.getServerId();
SystemInfoDto<Map<String, String>> systemInfoDto = new SystemInfoDto<>();
- systemInfoDto.setTime(format.format(System.currentTimeMillis()));
+ systemInfoDto.setTime(DateUtil.getNow());
systemInfoDto.setData(networkInterfaces);
redis.lSet(key, systemInfoDto);
// 姣忕涓�涓紝鏈�澶氬彧瀛�30涓�
@@ -628,14 +688,36 @@
@Override
public void sendMobilePositionMsg(JSONObject jsonObject) {
String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_MOBILE_POSITION;
- logger.info("[redis 绉诲姩浣嶇疆璁㈤槄閫氱煡] {}: {}", key, jsonObject.toString());
+ logger.info("[redis鍙戦�侀�氱煡]绉诲姩浣嶇疆 {}: {}", key, jsonObject.toString());
redis.convertAndSend(key, jsonObject);
}
@Override
public void sendStreamPushRequestedMsg(MessageForPushChannel msg) {
String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_REQUESTED;
- logger.info("[redis 鎺ㄦ祦琚姹傞�氱煡] {}: {}-{}", key, msg.getApp(), msg.getStream());
+ logger.info("[redis鍙戦�侀�氱煡]鎺ㄦ祦琚姹� {}: {}/{}", key, msg.getApp(), msg.getStream());
redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg));
}
+
+ @Override
+ public void sendAlarmMsg(AlarmChannelMessage msg) {
+ String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM;
+ logger.info("[redis鍙戦�侀�氱煡] 鎶ヨ{}: {}", key, JSON.toJSON(msg));
+ redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg));
+ }
+
+ @Override
+ public boolean deviceIsOnline(String deviceId) {
+ return getDevice(deviceId).getOnline() == 1;
+ }
+
+
+ @Override
+ public void sendStreamPushRequestedMsgForStatus() {
+ String key = VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED;
+ logger.info("[redis閫氱煡]鑾峰彇鎵�鏈夋帹娴佽澶囩殑鐘舵��");
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put(key, key);
+ redis.convertAndSend(key, jsonObject);
+ }
}
--
Gitblit v1.8.0