Commit bc38f5ef299f44f65fd34258b84272a027c10cb6
1 parent
76dedb11
修复流地址返回错误
Showing
5 changed files
with
99 additions
and
61 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
| ... | ... | @@ -92,39 +92,36 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements |
| 92 | 92 | @Override |
| 93 | 93 | public void process(RequestEvent evt) { |
| 94 | 94 | try { |
| 95 | - | |
| 96 | 95 | taskQueue.offer(new HandlerCatchData(evt, null, null)); |
| 97 | 96 | responseAck(evt, Response.OK); |
| 98 | 97 | if (!taskQueueHandlerRun) { |
| 99 | 98 | taskQueueHandlerRun = true; |
| 100 | 99 | taskExecutor.execute(()-> { |
| 101 | - while (!taskQueue.isEmpty()) { | |
| 102 | - try { | |
| 103 | - HandlerCatchData take = taskQueue.poll(); | |
| 104 | - Element rootElement = getRootElement(take.getEvt()); | |
| 105 | - String cmd = XmlUtil.getText(rootElement, "CmdType"); | |
| 106 | - | |
| 107 | - if (CmdType.CATALOG.equals(cmd)) { | |
| 108 | - logger.info("接收到Catalog通知"); | |
| 109 | - processNotifyCatalogList(take.getEvt()); | |
| 110 | - } else if (CmdType.ALARM.equals(cmd)) { | |
| 111 | - logger.info("接收到Alarm通知"); | |
| 112 | - processNotifyAlarm(take.getEvt()); | |
| 113 | - } else if (CmdType.MOBILE_POSITION.equals(cmd)) { | |
| 114 | - logger.info("接收到MobilePosition通知"); | |
| 115 | - processNotifyMobilePosition(take.getEvt()); | |
| 116 | - } else { | |
| 117 | - logger.info("接收到消息:" + cmd); | |
| 118 | - } | |
| 119 | - } catch (DocumentException e) { | |
| 120 | - throw new RuntimeException(e); | |
| 121 | - } | |
| 100 | + while (!taskQueue.isEmpty()) { | |
| 101 | + try { | |
| 102 | + HandlerCatchData take = taskQueue.poll(); | |
| 103 | + Element rootElement = getRootElement(take.getEvt()); | |
| 104 | + String cmd = XmlUtil.getText(rootElement, "CmdType"); | |
| 105 | + | |
| 106 | + if (CmdType.CATALOG.equals(cmd)) { | |
| 107 | + logger.info("接收到Catalog通知"); | |
| 108 | + processNotifyCatalogList(take.getEvt()); | |
| 109 | + } else if (CmdType.ALARM.equals(cmd)) { | |
| 110 | + logger.info("接收到Alarm通知"); | |
| 111 | + processNotifyAlarm(take.getEvt()); | |
| 112 | + } else if (CmdType.MOBILE_POSITION.equals(cmd)) { | |
| 113 | + logger.info("接收到MobilePosition通知"); | |
| 114 | + processNotifyMobilePosition(take.getEvt()); | |
| 115 | + } else { | |
| 116 | + logger.info("接收到消息:" + cmd); | |
| 122 | 117 | } |
| 123 | - taskQueueHandlerRun = false; | |
| 124 | - }); | |
| 118 | + } catch (DocumentException e) { | |
| 119 | + throw new RuntimeException(e); | |
| 120 | + } | |
| 121 | + } | |
| 122 | + taskQueueHandlerRun = false; | |
| 123 | + }); | |
| 125 | 124 | } |
| 126 | - | |
| 127 | - | |
| 128 | 125 | } catch (SipException | InvalidArgumentException | ParseException e) { |
| 129 | 126 | e.printStackTrace(); |
| 130 | 127 | } |
| ... | ... | @@ -174,7 +171,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements |
| 174 | 171 | } else { |
| 175 | 172 | mobilePosition.setAltitude(0.0); |
| 176 | 173 | } |
| 177 | - logger.info("[收到 移动位置订阅]:{}/{}->{}.{}", mobilePosition.getDeviceId(), mobilePosition.getChannelId(), | |
| 174 | + logger.info("[收到移动位置订阅通知]:{}/{}->{}.{}", mobilePosition.getDeviceId(), mobilePosition.getChannelId(), | |
| 178 | 175 | mobilePosition.getLongitude(), mobilePosition.getLatitude()); |
| 179 | 176 | mobilePosition.setReportSource("Mobile Position"); |
| 180 | 177 | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java
| ... | ... | @@ -67,9 +67,9 @@ public class MediaServiceImpl implements IMediaService { |
| 67 | 67 | JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class); |
| 68 | 68 | JSONArray tracks = mediaJSON.getJSONArray("tracks"); |
| 69 | 69 | if (authority) { |
| 70 | - streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, streamAuthorityInfo.getCallId()); | |
| 70 | + streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,streamAuthorityInfo.getCallId()); | |
| 71 | 71 | }else { |
| 72 | - streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, null); | |
| 72 | + streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,null); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/RedisGpsMsgListener.java
| 1 | 1 | package com.genersoft.iot.vmp.service.impl; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson.JSON; |
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.HandlerCatchData; | |
| 4 | 5 | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| 5 | 6 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 6 | 7 | import org.jetbrains.annotations.NotNull; |
| 7 | 8 | import org.slf4j.Logger; |
| 8 | 9 | import org.slf4j.LoggerFactory; |
| 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | +import org.springframework.beans.factory.annotation.Qualifier; | |
| 10 | 12 | import org.springframework.data.redis.connection.Message; |
| 11 | 13 | import org.springframework.data.redis.connection.MessageListener; |
| 14 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |
| 12 | 15 | import org.springframework.stereotype.Component; |
| 13 | 16 | |
| 17 | +import java.util.concurrent.ConcurrentLinkedQueue; | |
| 18 | + | |
| 14 | 19 | /** |
| 15 | 20 | * 接收来自redis的GPS更新通知 |
| 16 | 21 | * @author lin |
| ... | ... | @@ -20,13 +25,31 @@ public class RedisGpsMsgListener implements MessageListener { |
| 20 | 25 | |
| 21 | 26 | private final static Logger logger = LoggerFactory.getLogger(RedisGpsMsgListener.class); |
| 22 | 27 | |
| 28 | + private boolean taskQueueHandlerRun = false; | |
| 29 | + | |
| 23 | 30 | @Autowired |
| 24 | 31 | private IRedisCatchStorage redisCatchStorage; |
| 25 | 32 | |
| 33 | + private final ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); | |
| 34 | + | |
| 35 | + @Qualifier("taskExecutor") | |
| 36 | + @Autowired | |
| 37 | + private ThreadPoolTaskExecutor taskExecutor; | |
| 38 | + | |
| 39 | + | |
| 26 | 40 | @Override |
| 27 | 41 | public void onMessage(@NotNull Message message, byte[] bytes) { |
| 28 | - // TODO 加消息队列 | |
| 29 | - GPSMsgInfo gpsMsgInfo = JSON.parseObject(message.getBody(), GPSMsgInfo.class); | |
| 30 | - redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo); | |
| 42 | + taskQueue.offer(message); | |
| 43 | + if (!taskQueueHandlerRun) { | |
| 44 | + taskQueueHandlerRun = true; | |
| 45 | + taskExecutor.execute(() -> { | |
| 46 | + while (!taskQueue.isEmpty()) { | |
| 47 | + Message msg = taskQueue.poll(); | |
| 48 | + GPSMsgInfo gpsMsgInfo = JSON.parseObject(msg.getBody(), GPSMsgInfo.class); | |
| 49 | + redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo); | |
| 50 | + } | |
| 51 | + taskQueueHandlerRun = false; | |
| 52 | + }); | |
| 53 | + } | |
| 31 | 54 | } |
| 32 | 55 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java
| ... | ... | @@ -14,6 +14,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; |
| 14 | 14 | import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; |
| 15 | 15 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| 16 | 16 | import com.genersoft.iot.vmp.service.IStreamPushService; |
| 17 | +import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; | |
| 17 | 18 | import com.genersoft.iot.vmp.service.bean.PushStreamStatusChangeFromRedisDto; |
| 18 | 19 | import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis; |
| 19 | 20 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| ... | ... | @@ -21,14 +22,17 @@ import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 21 | 22 | import org.slf4j.Logger; |
| 22 | 23 | import org.slf4j.LoggerFactory; |
| 23 | 24 | import org.springframework.beans.factory.annotation.Autowired; |
| 25 | +import org.springframework.beans.factory.annotation.Qualifier; | |
| 24 | 26 | import org.springframework.boot.ApplicationArguments; |
| 25 | 27 | import org.springframework.boot.ApplicationRunner; |
| 26 | 28 | import org.springframework.data.redis.connection.Message; |
| 27 | 29 | import org.springframework.data.redis.connection.MessageListener; |
| 30 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |
| 28 | 31 | import org.springframework.stereotype.Component; |
| 29 | 32 | |
| 30 | 33 | import java.util.ArrayList; |
| 31 | 34 | import java.util.List; |
| 35 | +import java.util.concurrent.ConcurrentLinkedQueue; | |
| 32 | 36 | |
| 33 | 37 | |
| 34 | 38 | /** |
| ... | ... | @@ -40,6 +44,8 @@ public class RedisPushStreamStatusMsgListener implements MessageListener, Applic |
| 40 | 44 | |
| 41 | 45 | private final static Logger logger = LoggerFactory.getLogger(RedisPushStreamStatusMsgListener.class); |
| 42 | 46 | |
| 47 | + private boolean taskQueueHandlerRun = false; | |
| 48 | + | |
| 43 | 49 | @Autowired |
| 44 | 50 | private IRedisCatchStorage redisCatchStorage; |
| 45 | 51 | |
| ... | ... | @@ -47,39 +53,51 @@ public class RedisPushStreamStatusMsgListener implements MessageListener, Applic |
| 47 | 53 | private IStreamPushService streamPushService; |
| 48 | 54 | |
| 49 | 55 | @Autowired |
| 50 | - private EventPublisher eventPublisher; | |
| 56 | + private DynamicTask dynamicTask; | |
| 51 | 57 | |
| 52 | - @Autowired | |
| 53 | - private UserSetting userSetting; | |
| 54 | 58 | |
| 59 | + | |
| 60 | + private final ConcurrentLinkedQueue<Message> taskQueue = new ConcurrentLinkedQueue<>(); | |
| 61 | + | |
| 62 | + @Qualifier("taskExecutor") | |
| 55 | 63 | @Autowired |
| 56 | - private DynamicTask dynamicTask; | |
| 64 | + private ThreadPoolTaskExecutor taskExecutor; | |
| 57 | 65 | |
| 58 | 66 | @Override |
| 59 | 67 | public void onMessage(Message message, byte[] bytes) { |
| 60 | 68 | // TODO 增加队列 |
| 61 | 69 | logger.warn("[REDIS 消息-推流设备状态变化]: {}", new String(message.getBody())); |
| 62 | - // | |
| 63 | - PushStreamStatusChangeFromRedisDto statusChangeFromPushStream = JSON.parseObject(message.getBody(), PushStreamStatusChangeFromRedisDto.class); | |
| 64 | - if (statusChangeFromPushStream == null) { | |
| 65 | - logger.warn("[REDIS 消息]推流设备状态变化消息解析失败"); | |
| 66 | - return; | |
| 67 | - } | |
| 68 | - // 取消定时任务 | |
| 69 | - dynamicTask.stop(VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED); | |
| 70 | - if (statusChangeFromPushStream.isSetAllOffline()) { | |
| 71 | - // 所有设备离线 | |
| 72 | - streamPushService.allStreamOffline(); | |
| 73 | - } | |
| 74 | - if (statusChangeFromPushStream.getOfflineStreams() != null | |
| 75 | - && statusChangeFromPushStream.getOfflineStreams().size() > 0) { | |
| 76 | - // 更新部分设备离线 | |
| 77 | - streamPushService.offline(statusChangeFromPushStream.getOfflineStreams()); | |
| 78 | - } | |
| 79 | - if (statusChangeFromPushStream.getOnlineStreams() != null && | |
| 80 | - statusChangeFromPushStream.getOnlineStreams().size() > 0) { | |
| 81 | - // 更新部分设备上线 | |
| 82 | - streamPushService.online(statusChangeFromPushStream.getOnlineStreams()); | |
| 70 | + taskQueue.offer(message); | |
| 71 | + | |
| 72 | + if (!taskQueueHandlerRun) { | |
| 73 | + taskQueueHandlerRun = true; | |
| 74 | + taskExecutor.execute(() -> { | |
| 75 | + while (!taskQueue.isEmpty()) { | |
| 76 | + Message msg = taskQueue.poll(); | |
| 77 | + PushStreamStatusChangeFromRedisDto statusChangeFromPushStream = JSON.parseObject(msg.getBody(), PushStreamStatusChangeFromRedisDto.class); | |
| 78 | + if (statusChangeFromPushStream == null) { | |
| 79 | + logger.warn("[REDIS 消息]推流设备状态变化消息解析失败"); | |
| 80 | + return; | |
| 81 | + } | |
| 82 | + // 取消定时任务 | |
| 83 | + dynamicTask.stop(VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED); | |
| 84 | + if (statusChangeFromPushStream.isSetAllOffline()) { | |
| 85 | + // 所有设备离线 | |
| 86 | + streamPushService.allStreamOffline(); | |
| 87 | + } | |
| 88 | + if (statusChangeFromPushStream.getOfflineStreams() != null | |
| 89 | + && statusChangeFromPushStream.getOfflineStreams().size() > 0) { | |
| 90 | + // 更新部分设备离线 | |
| 91 | + streamPushService.offline(statusChangeFromPushStream.getOfflineStreams()); | |
| 92 | + } | |
| 93 | + if (statusChangeFromPushStream.getOnlineStreams() != null && | |
| 94 | + statusChangeFromPushStream.getOnlineStreams().size() > 0) { | |
| 95 | + // 更新部分设备上线 | |
| 96 | + streamPushService.online(statusChangeFromPushStream.getOnlineStreams()); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + taskQueueHandlerRun = false; | |
| 100 | + }); | |
| 83 | 101 | } |
| 84 | 102 | } |
| 85 | 103 | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
| ... | ... | @@ -688,21 +688,21 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 688 | 688 | @Override |
| 689 | 689 | public void sendMobilePositionMsg(JSONObject jsonObject) { |
| 690 | 690 | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_MOBILE_POSITION; |
| 691 | - logger.info("[redis 移动位置订阅通知] {}: {}", key, jsonObject.toString()); | |
| 691 | + logger.info("[redis发送通知]移动位置 {}: {}", key, jsonObject.toString()); | |
| 692 | 692 | redis.convertAndSend(key, jsonObject); |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | @Override |
| 696 | 696 | public void sendStreamPushRequestedMsg(MessageForPushChannel msg) { |
| 697 | 697 | String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_REQUESTED; |
| 698 | - logger.info("[redis 推流被请求通知] {}: {}/{}", key, msg.getApp(), msg.getStream()); | |
| 698 | + logger.info("[redis发送通知]推流被请求 {}: {}/{}", key, msg.getApp(), msg.getStream()); | |
| 699 | 699 | redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg)); |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | @Override |
| 703 | 703 | public void sendAlarmMsg(AlarmChannelMessage msg) { |
| 704 | 704 | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM; |
| 705 | - logger.info("[redis 报警通知] {}: {}", key, JSON.toJSON(msg)); | |
| 705 | + logger.info("[redis发送通知] 报警{}: {}", key, JSON.toJSON(msg)); | |
| 706 | 706 | redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg)); |
| 707 | 707 | } |
| 708 | 708 | |
| ... | ... | @@ -715,7 +715,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { |
| 715 | 715 | @Override |
| 716 | 716 | public void sendStreamPushRequestedMsgForStatus() { |
| 717 | 717 | String key = VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED; |
| 718 | - logger.info("[redis 通知]获取所有推流设备的状态"); | |
| 718 | + logger.info("[redis通知]获取所有推流设备的状态"); | |
| 719 | 719 | JSONObject jsonObject = new JSONObject(); |
| 720 | 720 | jsonObject.put(key, key); |
| 721 | 721 | redis.convertAndSend(key, jsonObject); | ... | ... |