parent
192f012829
commit
b89e46871a
|
@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.SipTransactionInfo;
|
import com.genersoft.iot.vmp.gb28181.bean.SipTransactionInfo;
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
||||||
|
import com.genersoft.iot.vmp.utils.JsonUtil;
|
||||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||||
import gov.nist.javax.sip.message.SIPResponse;
|
import gov.nist.javax.sip.message.SIPResponse;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -133,7 +134,7 @@ public class VideoStreamSessionManager {
|
||||||
List<SsrcTransaction> result= new ArrayList<>();
|
List<SsrcTransaction> result= new ArrayList<>();
|
||||||
for (int i = 0; i < ssrcTransactionKeys.size(); i++) {
|
for (int i = 0; i < ssrcTransactionKeys.size(); i++) {
|
||||||
String key = (String)ssrcTransactionKeys.get(i);
|
String key = (String)ssrcTransactionKeys.get(i);
|
||||||
SsrcTransaction ssrcTransaction = (SsrcTransaction)RedisUtil.get(key);
|
SsrcTransaction ssrcTransaction = JsonUtil.redisJsonToObject(key, SsrcTransaction.class);
|
||||||
result.add(ssrcTransaction);
|
result.add(ssrcTransaction);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -22,6 +22,7 @@ import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||||
import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
|
import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
|
||||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||||
|
import com.genersoft.iot.vmp.utils.JsonUtil;
|
||||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
@ -228,11 +229,10 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
String onlineKey = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId();
|
String onlineKey = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId();
|
||||||
for (Object mediaServerKey : mediaServerKeys) {
|
for (Object mediaServerKey : mediaServerKeys) {
|
||||||
String key = (String) mediaServerKey;
|
String key = (String) mediaServerKey;
|
||||||
JSONObject jsonObject = (JSONObject) RedisUtil.get(key);
|
MediaServerItem mediaServerItem = JsonUtil.redisJsonToObject(key, MediaServerItem.class);
|
||||||
if (Objects.isNull(jsonObject)) {
|
if (Objects.isNull(mediaServerItem)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
MediaServerItem mediaServerItem = JSON.parseObject(jsonObject.toJSONString(), MediaServerItem.class);
|
|
||||||
// 检查状态
|
// 检查状态
|
||||||
Double aDouble = RedisUtil.zScore(onlineKey, mediaServerItem.getId());
|
Double aDouble = RedisUtil.zScore(onlineKey, mediaServerItem.getId());
|
||||||
if (aDouble != null) {
|
if (aDouble != null) {
|
||||||
|
@ -284,7 +284,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerId;
|
String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerId;
|
||||||
return (MediaServerItem)RedisUtil.get(key);
|
return JsonUtil.redisJsonToObject(key, MediaServerItem.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -400,8 +400,10 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
SsrcConfig ssrcConfig = new SsrcConfig(zlmServerConfig.getGeneralMediaServerId(), null, sipConfig.getDomain());
|
SsrcConfig ssrcConfig = new SsrcConfig(zlmServerConfig.getGeneralMediaServerId(), null, sipConfig.getDomain());
|
||||||
serverItem.setSsrcConfig(ssrcConfig);
|
serverItem.setSsrcConfig(ssrcConfig);
|
||||||
}else {
|
}else {
|
||||||
MediaServerItem mediaServerItemInRedis = (MediaServerItem)RedisUtil.get(key);
|
MediaServerItem mediaServerItemInRedis = JsonUtil.redisJsonToObject(key, MediaServerItem.class);
|
||||||
serverItem.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig());
|
if (Objects.nonNull(mediaServerItemInRedis)) {
|
||||||
|
serverItem.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RedisUtil.set(key, serverItem);
|
RedisUtil.set(key, serverItem);
|
||||||
resetOnlineServerItem(serverItem);
|
resetOnlineServerItem(serverItem);
|
||||||
|
|
|
@ -17,6 +17,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||||
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
|
import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
|
||||||
import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
|
import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo;
|
||||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||||
|
import com.genersoft.iot.vmp.utils.JsonUtil;
|
||||||
import com.genersoft.iot.vmp.utils.SystemInfoUtils;
|
import com.genersoft.iot.vmp.utils.SystemInfoUtils;
|
||||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -157,7 +158,10 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
}
|
}
|
||||||
for (Object player : players) {
|
for (Object player : players) {
|
||||||
String key = (String) player;
|
String key = (String) player;
|
||||||
StreamInfo streamInfo = (StreamInfo) RedisUtil.get(key);
|
StreamInfo streamInfo = JsonUtil.redisJsonToObject(key, StreamInfo.class);
|
||||||
|
if (Objects.isNull(streamInfo)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo);
|
streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo);
|
||||||
}
|
}
|
||||||
return streamInfos;
|
return streamInfos;
|
||||||
|
@ -624,8 +628,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
@Override
|
@Override
|
||||||
public ThirdPartyGB queryMemberNoGBId(String queryKey) {
|
public ThirdPartyGB queryMemberNoGBId(String queryKey) {
|
||||||
String key = VideoManagerConstants.WVP_STREAM_GB_ID_PREFIX + queryKey;
|
String key = VideoManagerConstants.WVP_STREAM_GB_ID_PREFIX + queryKey;
|
||||||
JSONObject jsonObject = (JSONObject)RedisUtil.get(key);
|
return JsonUtil.redisJsonToObject(key, ThirdPartyGB.class);
|
||||||
return jsonObject.to(ThirdPartyGB.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -664,7 +667,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
@Override
|
@Override
|
||||||
public Device getDevice(String deviceId) {
|
public Device getDevice(String deviceId) {
|
||||||
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId;
|
String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId;
|
||||||
return (Device)RedisUtil.get(key);
|
return JsonUtil.redisJsonToObject(key, Device.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -676,7 +679,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
@Override
|
@Override
|
||||||
public GPSMsgInfo getGpsMsgInfo(String gbId) {
|
public GPSMsgInfo getGpsMsgInfo(String gbId) {
|
||||||
String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gbId;
|
String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gbId;
|
||||||
return (GPSMsgInfo)RedisUtil.get(key);
|
return JsonUtil.redisJsonToObject(key, GPSMsgInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -686,9 +689,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
List<Object> keys = RedisUtil.scan(scanKey);
|
List<Object> keys = RedisUtil.scan(scanKey);
|
||||||
for (Object o : keys) {
|
for (Object o : keys) {
|
||||||
String key = (String) o;
|
String key = (String) o;
|
||||||
GPSMsgInfo gpsMsgInfo = (GPSMsgInfo) RedisUtil.get(key);
|
GPSMsgInfo gpsMsgInfo = JsonUtil.redisJsonToObject(key, GPSMsgInfo.class);
|
||||||
if (!gpsMsgInfo.isStored()) { // 只取没有存过得
|
if (Objects.nonNull(gpsMsgInfo) && !gpsMsgInfo.isStored()) { // 只取没有存过得
|
||||||
result.add((GPSMsgInfo) RedisUtil.get(key));
|
result.add(JsonUtil.redisJsonToObject(key, GPSMsgInfo.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +713,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
@Override
|
@Override
|
||||||
public StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream) {
|
public StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream) {
|
||||||
String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
|
String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
|
||||||
return (StreamAuthorityInfo) RedisUtil.get(key);
|
return JsonUtil.redisJsonToObject(key, StreamAuthorityInfo.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -721,7 +724,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
List<Object> keys = RedisUtil.scan(scanKey);
|
List<Object> keys = RedisUtil.scan(scanKey);
|
||||||
for (Object o : keys) {
|
for (Object o : keys) {
|
||||||
String key = (String) o;
|
String key = (String) o;
|
||||||
result.add((StreamAuthorityInfo) RedisUtil.get(key));
|
result.add(JsonUtil.redisJsonToObject(key, StreamAuthorityInfo.class));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -735,7 +738,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
|
||||||
List<Object> keys = RedisUtil.scan(scanKey);
|
List<Object> keys = RedisUtil.scan(scanKey);
|
||||||
if (keys.size() > 0) {
|
if (keys.size() > 0) {
|
||||||
String key = (String) keys.get(0);
|
String key = (String) keys.get(0);
|
||||||
result = (OnStreamChangedHookParam)RedisUtil.get(key);
|
result = JsonUtil.redisJsonToObject(key, OnStreamChangedHookParam.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.genersoft.iot.vmp.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JsonUtil
|
||||||
|
*
|
||||||
|
* @author KunLong-Luo
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/2/2 15:24
|
||||||
|
*/
|
||||||
|
public final class JsonUtil {
|
||||||
|
|
||||||
|
private JsonUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* safe json type conversion
|
||||||
|
*
|
||||||
|
* @param key redis key
|
||||||
|
* @param clazz cast type
|
||||||
|
* @param <T>
|
||||||
|
* @return result type
|
||||||
|
*/
|
||||||
|
public static <T> T redisJsonToObject(String key, Class<T> clazz) {
|
||||||
|
JSONObject jsonObject = (JSONObject) RedisUtil.get(key);
|
||||||
|
if (Objects.isNull(jsonObject)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return JSON.parseObject(jsonObject.toJSONString(), clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue