Commit 375cd035755ca4485893a9524b4ce670ac46732d
Merge remote-tracking branch 'origin/wvp-28181-2.0' into wvp-28181-2.0
Showing
5 changed files
with
64 additions
and
17 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java
| ... | ... | @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 4 | 4 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.bean.SipTransactionInfo; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; |
| 7 | +import com.genersoft.iot.vmp.utils.JsonUtil; | |
| 7 | 8 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| 8 | 9 | import gov.nist.javax.sip.message.SIPResponse; |
| 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -133,7 +134,7 @@ public class VideoStreamSessionManager { |
| 133 | 134 | List<SsrcTransaction> result= new ArrayList<>(); |
| 134 | 135 | for (int i = 0; i < ssrcTransactionKeys.size(); i++) { |
| 135 | 136 | String key = (String)ssrcTransactionKeys.get(i); |
| 136 | - SsrcTransaction ssrcTransaction = (SsrcTransaction)RedisUtil.get(key); | |
| 137 | + SsrcTransaction ssrcTransaction = JsonUtil.redisJsonToObject(key, SsrcTransaction.class); | |
| 137 | 138 | result.add(ssrcTransaction); |
| 138 | 139 | } |
| 139 | 140 | return result; | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
| ... | ... | @@ -36,7 +36,7 @@ public class ZLMRESTfulUtils { |
| 36 | 36 | // 设置连接超时时间 |
| 37 | 37 | httpClientBuilder.connectTimeout(5,TimeUnit.SECONDS); |
| 38 | 38 | // 设置读取超时时间 |
| 39 | - httpClientBuilder.readTimeout(5,TimeUnit.SECONDS); | |
| 39 | + httpClientBuilder.readTimeout(10,TimeUnit.SECONDS); | |
| 40 | 40 | // 设置连接池 |
| 41 | 41 | httpClientBuilder.connectionPool(new ConnectionPool(16, 5, TimeUnit.MINUTES)); |
| 42 | 42 | if (logger.isDebugEnabled()) { |
| ... | ... | @@ -186,6 +186,7 @@ public class ZLMRESTfulUtils { |
| 186 | 186 | FileOutputStream outStream = new FileOutputStream(snapFile); |
| 187 | 187 | |
| 188 | 188 | outStream.write(Objects.requireNonNull(response.body()).bytes()); |
| 189 | + outStream.flush(); | |
| 189 | 190 | outStream.close(); |
| 190 | 191 | } else { |
| 191 | 192 | logger.error(String.format("[ %s ]请求失败: %s %s", url, response.code(), response.message())); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
| ... | ... | @@ -22,6 +22,7 @@ import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 22 | 22 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 23 | 23 | import com.genersoft.iot.vmp.storager.dao.MediaServerMapper; |
| 24 | 24 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 25 | +import com.genersoft.iot.vmp.utils.JsonUtil; | |
| 25 | 26 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| 26 | 27 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 27 | 28 | import okhttp3.OkHttpClient; |
| ... | ... | @@ -228,7 +229,10 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 228 | 229 | String onlineKey = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId(); |
| 229 | 230 | for (Object mediaServerKey : mediaServerKeys) { |
| 230 | 231 | String key = (String) mediaServerKey; |
| 231 | - MediaServerItem mediaServerItem = (MediaServerItem) RedisUtil.get(key); | |
| 232 | + MediaServerItem mediaServerItem = JsonUtil.redisJsonToObject(key, MediaServerItem.class); | |
| 233 | + if (Objects.isNull(mediaServerItem)) { | |
| 234 | + continue; | |
| 235 | + } | |
| 232 | 236 | // 检查状态 |
| 233 | 237 | Double aDouble = RedisUtil.zScore(onlineKey, mediaServerItem.getId()); |
| 234 | 238 | if (aDouble != null) { |
| ... | ... | @@ -280,7 +284,7 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 280 | 284 | return null; |
| 281 | 285 | } |
| 282 | 286 | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerId; |
| 283 | - return (MediaServerItem)RedisUtil.get(key); | |
| 287 | + return JsonUtil.redisJsonToObject(key, MediaServerItem.class); | |
| 284 | 288 | } |
| 285 | 289 | |
| 286 | 290 | @Override |
| ... | ... | @@ -396,8 +400,10 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 396 | 400 | SsrcConfig ssrcConfig = new SsrcConfig(zlmServerConfig.getGeneralMediaServerId(), null, sipConfig.getDomain()); |
| 397 | 401 | serverItem.setSsrcConfig(ssrcConfig); |
| 398 | 402 | }else { |
| 399 | - MediaServerItem mediaServerItemInRedis = (MediaServerItem)RedisUtil.get(key); | |
| 400 | - serverItem.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig()); | |
| 403 | + MediaServerItem mediaServerItemInRedis = JsonUtil.redisJsonToObject(key, MediaServerItem.class); | |
| 404 | + if (Objects.nonNull(mediaServerItemInRedis)) { | |
| 405 | + serverItem.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig()); | |
| 406 | + } | |
| 401 | 407 | } |
| 402 | 408 | RedisUtil.set(key, serverItem); |
| 403 | 409 | resetOnlineServerItem(serverItem); | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
| ... | ... | @@ -17,6 +17,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 17 | 17 | import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; |
| 18 | 18 | import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo; |
| 19 | 19 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 20 | +import com.genersoft.iot.vmp.utils.JsonUtil; | |
| 20 | 21 | import com.genersoft.iot.vmp.utils.SystemInfoUtils; |
| 21 | 22 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| 22 | 23 | import org.slf4j.Logger; |
| ... | ... | @@ -157,7 +158,10 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 157 | 158 | } |
| 158 | 159 | for (Object player : players) { |
| 159 | 160 | String key = (String) player; |
| 160 | - StreamInfo streamInfo = (StreamInfo) RedisUtil.get(key); | |
| 161 | + StreamInfo streamInfo = JsonUtil.redisJsonToObject(key, StreamInfo.class); | |
| 162 | + if (Objects.isNull(streamInfo)) { | |
| 163 | + continue; | |
| 164 | + } | |
| 161 | 165 | streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo); |
| 162 | 166 | } |
| 163 | 167 | return streamInfos; |
| ... | ... | @@ -624,8 +628,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 624 | 628 | @Override |
| 625 | 629 | public ThirdPartyGB queryMemberNoGBId(String queryKey) { |
| 626 | 630 | String key = VideoManagerConstants.WVP_STREAM_GB_ID_PREFIX + queryKey; |
| 627 | - JSONObject jsonObject = (JSONObject)RedisUtil.get(key); | |
| 628 | - return jsonObject.to(ThirdPartyGB.class); | |
| 631 | + return JsonUtil.redisJsonToObject(key, ThirdPartyGB.class); | |
| 629 | 632 | } |
| 630 | 633 | |
| 631 | 634 | @Override |
| ... | ... | @@ -664,7 +667,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 664 | 667 | @Override |
| 665 | 668 | public Device getDevice(String deviceId) { |
| 666 | 669 | String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId; |
| 667 | - return (Device)RedisUtil.get(key); | |
| 670 | + return JsonUtil.redisJsonToObject(key, Device.class); | |
| 668 | 671 | } |
| 669 | 672 | |
| 670 | 673 | @Override |
| ... | ... | @@ -676,7 +679,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 676 | 679 | @Override |
| 677 | 680 | public GPSMsgInfo getGpsMsgInfo(String gbId) { |
| 678 | 681 | String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gbId; |
| 679 | - return (GPSMsgInfo)RedisUtil.get(key); | |
| 682 | + return JsonUtil.redisJsonToObject(key, GPSMsgInfo.class); | |
| 680 | 683 | } |
| 681 | 684 | |
| 682 | 685 | @Override |
| ... | ... | @@ -686,9 +689,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 686 | 689 | List<Object> keys = RedisUtil.scan(scanKey); |
| 687 | 690 | for (Object o : keys) { |
| 688 | 691 | String key = (String) o; |
| 689 | - GPSMsgInfo gpsMsgInfo = (GPSMsgInfo) RedisUtil.get(key); | |
| 690 | - if (!gpsMsgInfo.isStored()) { // 只取没有存过得 | |
| 691 | - result.add((GPSMsgInfo) RedisUtil.get(key)); | |
| 692 | + GPSMsgInfo gpsMsgInfo = JsonUtil.redisJsonToObject(key, GPSMsgInfo.class); | |
| 693 | + if (Objects.nonNull(gpsMsgInfo) && !gpsMsgInfo.isStored()) { // 只取没有存过得 | |
| 694 | + result.add(JsonUtil.redisJsonToObject(key, GPSMsgInfo.class)); | |
| 692 | 695 | } |
| 693 | 696 | } |
| 694 | 697 | |
| ... | ... | @@ -710,7 +713,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 710 | 713 | @Override |
| 711 | 714 | public StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream) { |
| 712 | 715 | String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ; |
| 713 | - return (StreamAuthorityInfo) RedisUtil.get(key); | |
| 716 | + return JsonUtil.redisJsonToObject(key, StreamAuthorityInfo.class); | |
| 714 | 717 | |
| 715 | 718 | } |
| 716 | 719 | |
| ... | ... | @@ -721,7 +724,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 721 | 724 | List<Object> keys = RedisUtil.scan(scanKey); |
| 722 | 725 | for (Object o : keys) { |
| 723 | 726 | String key = (String) o; |
| 724 | - result.add((StreamAuthorityInfo) RedisUtil.get(key)); | |
| 727 | + result.add(JsonUtil.redisJsonToObject(key, StreamAuthorityInfo.class)); | |
| 725 | 728 | } |
| 726 | 729 | return result; |
| 727 | 730 | } |
| ... | ... | @@ -735,7 +738,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 735 | 738 | List<Object> keys = RedisUtil.scan(scanKey); |
| 736 | 739 | if (keys.size() > 0) { |
| 737 | 740 | String key = (String) keys.get(0); |
| 738 | - result = (OnStreamChangedHookParam)RedisUtil.get(key); | |
| 741 | + result = JsonUtil.redisJsonToObject(key, OnStreamChangedHookParam.class); | |
| 739 | 742 | } |
| 740 | 743 | |
| 741 | 744 | return result; | ... | ... |
src/main/java/com/genersoft/iot/vmp/utils/JsonUtil.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.utils; | |
| 2 | + | |
| 3 | +import com.alibaba.fastjson2.JSON; | |
| 4 | +import com.alibaba.fastjson2.JSONObject; | |
| 5 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | |
| 6 | + | |
| 7 | +import java.util.Objects; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * JsonUtil | |
| 11 | + * | |
| 12 | + * @author KunLong-Luo | |
| 13 | + * @version 1.0.0 | |
| 14 | + * @since 2023/2/2 15:24 | |
| 15 | + */ | |
| 16 | +public final class JsonUtil { | |
| 17 | + | |
| 18 | + private JsonUtil() { | |
| 19 | + } | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * safe json type conversion | |
| 23 | + * | |
| 24 | + * @param key redis key | |
| 25 | + * @param clazz cast type | |
| 26 | + * @param <T> | |
| 27 | + * @return result type | |
| 28 | + */ | |
| 29 | + public static <T> T redisJsonToObject(String key, Class<T> clazz) { | |
| 30 | + Object jsonObject = RedisUtil.get(key); | |
| 31 | + if (Objects.isNull(jsonObject)) { | |
| 32 | + return null; | |
| 33 | + } | |
| 34 | + return clazz.cast(jsonObject); | |
| 35 | + } | |
| 36 | +} | |
| 0 | 37 | \ No newline at end of file | ... | ... |