Commit 275b272160679beaf19147764b73c1c439880593
1 parent
2de4c322
hook订阅曾增加过期清除功能,防止内存溢出
Showing
12 changed files
with
73 additions
and
77 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
| ... | ... | @@ -3,7 +3,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd; |
| 3 | 3 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| 6 | -import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | |
| 6 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 7 | 7 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 8 | 8 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 9 | 9 | |
| ... | ... | @@ -93,7 +93,7 @@ public interface ISIPCommander { |
| 93 | 93 | * @param device 视频设备 |
| 94 | 94 | * @param channelId 预览通道 |
| 95 | 95 | */ |
| 96 | - void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent); | |
| 96 | + void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent); | |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * 请求回放视频流 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
| ... | ... | @@ -13,10 +13,9 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; |
| 13 | 13 | import com.genersoft.iot.vmp.gb28181.utils.HeaderUtils; |
| 14 | 14 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 15 | 15 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| 16 | -import com.genersoft.iot.vmp.media.zlm.dto.HookType; | |
| 17 | 16 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 18 | 17 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 19 | -import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | |
| 18 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 20 | 19 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 21 | 20 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 22 | 21 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| ... | ... | @@ -34,19 +33,15 @@ import org.springframework.beans.factory.annotation.Qualifier; |
| 34 | 33 | import org.springframework.context.annotation.DependsOn; |
| 35 | 34 | import org.springframework.stereotype.Component; |
| 36 | 35 | import org.springframework.util.ObjectUtils; |
| 37 | -import org.springframework.util.StringUtils; | |
| 38 | 36 | |
| 39 | 37 | import javax.sip.*; |
| 40 | 38 | import javax.sip.address.Address; |
| 41 | 39 | import javax.sip.address.SipURI; |
| 42 | -import javax.sip.address.URI; | |
| 43 | 40 | import javax.sip.header.*; |
| 44 | 41 | import javax.sip.message.Request; |
| 45 | 42 | import java.lang.reflect.Field; |
| 46 | 43 | import java.text.ParseException; |
| 47 | -import java.util.ArrayList; | |
| 48 | 44 | import java.util.HashSet; |
| 49 | -import java.util.List; | |
| 50 | 45 | |
| 51 | 46 | /** |
| 52 | 47 | * @description:设备能力接口,用于定义设备的控制、查询能力 |
| ... | ... | @@ -89,7 +84,7 @@ public class SIPCommander implements ISIPCommander { |
| 89 | 84 | private UserSetting userSetting; |
| 90 | 85 | |
| 91 | 86 | @Autowired |
| 92 | - private ZLMHttpHookSubscribe subscribe; | |
| 87 | + private ZlmHttpHookSubscribe subscribe; | |
| 93 | 88 | |
| 94 | 89 | @Autowired |
| 95 | 90 | private SipSubscribe sipSubscribe; |
| ... | ... | @@ -352,7 +347,7 @@ public class SIPCommander implements ISIPCommander { |
| 352 | 347 | */ |
| 353 | 348 | @Override |
| 354 | 349 | public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, |
| 355 | - ZLMHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) { | |
| 350 | + ZlmHttpHookSubscribe.Event event, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) { | |
| 356 | 351 | String stream = ssrcInfo.getStream(); |
| 357 | 352 | try { |
| 358 | 353 | if (device == null) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; |
| 2 | 2 | |
| 3 | -import com.alibaba.fastjson.JSON; | |
| 4 | 3 | import com.alibaba.fastjson.JSONObject; |
| 5 | -import com.genersoft.iot.vmp.common.StreamInfo; | |
| 6 | 4 | import com.genersoft.iot.vmp.conf.DynamicTask; |
| 7 | -import com.genersoft.iot.vmp.gb28181.bean.InviteStreamType; | |
| 8 | 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 9 | 6 | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| 10 | 7 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| ... | ... | @@ -12,7 +9,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; |
| 12 | 9 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| 13 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; |
| 14 | 11 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| 15 | -import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | |
| 12 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 16 | 13 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 17 | 14 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 18 | 15 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| ... | ... | @@ -21,7 +18,6 @@ import com.genersoft.iot.vmp.service.impl.RedisGbPlayMsgListener; |
| 21 | 18 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 22 | 19 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 23 | 20 | import com.genersoft.iot.vmp.utils.SerializeUtils; |
| 24 | -import org.ehcache.shadow.org.terracotta.offheapstore.storage.IntegerStorageEngine; | |
| 25 | 21 | import org.slf4j.Logger; |
| 26 | 22 | import org.slf4j.LoggerFactory; |
| 27 | 23 | import org.springframework.beans.factory.InitializingBean; |
| ... | ... | @@ -69,7 +65,7 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In |
| 69 | 65 | private IMediaServerService mediaServerService; |
| 70 | 66 | |
| 71 | 67 | @Autowired |
| 72 | - private ZLMHttpHookSubscribe subscribe; | |
| 68 | + private ZlmHttpHookSubscribe subscribe; | |
| 73 | 69 | |
| 74 | 70 | @Autowired |
| 75 | 71 | private DynamicTask dynamicTask; | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -13,7 +13,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; |
| 13 | 13 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; |
| 14 | 14 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| 15 | 15 | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| 16 | -import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | |
| 16 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 17 | 17 | import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; |
| 18 | 18 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 19 | 19 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| ... | ... | @@ -40,7 +40,6 @@ import org.springframework.stereotype.Component; |
| 40 | 40 | |
| 41 | 41 | import javax.sdp.*; |
| 42 | 42 | import javax.sip.*; |
| 43 | -import javax.sip.address.SipURI; | |
| 44 | 43 | import javax.sip.header.CallIdHeader; |
| 45 | 44 | import javax.sip.message.Request; |
| 46 | 45 | import javax.sip.message.Response; |
| ... | ... | @@ -307,7 +306,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 307 | 306 | |
| 308 | 307 | Long finalStartTime = startTime; |
| 309 | 308 | Long finalStopTime = stopTime; |
| 310 | - ZLMHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> { | |
| 309 | + ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> { | |
| 311 | 310 | String app = responseJSON.getString("app"); |
| 312 | 311 | String stream = responseJSON.getString("stream"); |
| 313 | 312 | logger.info("[上级点播]下级已经开始推流。 回复200OK(SDP), {}/{}", app, stream); | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| ... | ... | @@ -22,9 +22,7 @@ import org.springframework.beans.factory.annotation.Qualifier; |
| 22 | 22 | import org.springframework.http.HttpStatus; |
| 23 | 23 | import org.springframework.http.ResponseEntity; |
| 24 | 24 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 25 | -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | |
| 26 | 25 | import org.springframework.util.ObjectUtils; |
| 27 | -import org.springframework.util.StringUtils; | |
| 28 | 26 | import org.springframework.web.bind.annotation.PostMapping; |
| 29 | 27 | import org.springframework.web.bind.annotation.RequestBody; |
| 30 | 28 | import org.springframework.web.bind.annotation.RequestMapping; |
| ... | ... | @@ -81,7 +79,7 @@ public class ZLMHttpHookListener { |
| 81 | 79 | private ZLMMediaListManager zlmMediaListManager; |
| 82 | 80 | |
| 83 | 81 | @Autowired |
| 84 | - private ZLMHttpHookSubscribe subscribe; | |
| 82 | + private ZlmHttpHookSubscribe subscribe; | |
| 85 | 83 | |
| 86 | 84 | @Autowired |
| 87 | 85 | private UserSetting userSetting; |
| ... | ... | @@ -109,9 +107,9 @@ public class ZLMHttpHookListener { |
| 109 | 107 | |
| 110 | 108 | logger.info("[ ZLM HOOK ] on_server_keepalive API调用,参数:" + json.toString()); |
| 111 | 109 | String mediaServerId = json.getString("mediaServerId"); |
| 112 | - List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive); | |
| 110 | + List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive); | |
| 113 | 111 | if (subscribes != null && subscribes.size() > 0) { |
| 114 | - for (ZLMHttpHookSubscribe.Event subscribe : subscribes) { | |
| 112 | + for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { | |
| 115 | 113 | subscribe.response(null, json); |
| 116 | 114 | } |
| 117 | 115 | } |
| ... | ... | @@ -175,7 +173,7 @@ public class ZLMHttpHookListener { |
| 175 | 173 | logger.debug("[ ZLM HOOK ]on_play API调用,参数:" + JSON.toJSONString(param)); |
| 176 | 174 | } |
| 177 | 175 | String mediaServerId = param.getMediaServerId(); |
| 178 | - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_play, json); | |
| 176 | + ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_play, json); | |
| 179 | 177 | if (subscribe != null ) { |
| 180 | 178 | MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); |
| 181 | 179 | if (mediaInfo != null) { |
| ... | ... | @@ -263,7 +261,7 @@ public class ZLMHttpHookListener { |
| 263 | 261 | } |
| 264 | 262 | |
| 265 | 263 | |
| 266 | - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json); | |
| 264 | + ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json); | |
| 267 | 265 | if (subscribe != null) { |
| 268 | 266 | if (mediaInfo != null) { |
| 269 | 267 | subscribe.response(mediaInfo, json); |
| ... | ... | @@ -387,7 +385,7 @@ public class ZLMHttpHookListener { |
| 387 | 385 | logger.debug("[ ZLM HOOK ]on_shell_login API调用,参数:" + json.toString()); |
| 388 | 386 | } |
| 389 | 387 | String mediaServerId = json.getString("mediaServerId"); |
| 390 | - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_shell_login, json); | |
| 388 | + ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_shell_login, json); | |
| 391 | 389 | if (subscribe != null ) { |
| 392 | 390 | MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); |
| 393 | 391 | if (mediaInfo != null) { |
| ... | ... | @@ -413,7 +411,7 @@ public class ZLMHttpHookListener { |
| 413 | 411 | logger.info("[ ZLM HOOK ]on_stream_changed API调用,参数:" + JSONObject.toJSONString(item)); |
| 414 | 412 | String mediaServerId = item.getMediaServerId(); |
| 415 | 413 | JSONObject json = (JSONObject) JSON.toJSON(item); |
| 416 | - ZLMHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_stream_changed, json); | |
| 414 | + ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_stream_changed, json); | |
| 417 | 415 | if (subscribe != null ) { |
| 418 | 416 | MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); |
| 419 | 417 | if (mediaInfo != null) { |
| ... | ... | @@ -635,9 +633,9 @@ public class ZLMHttpHookListener { |
| 635 | 633 | } |
| 636 | 634 | String remoteAddr = request.getRemoteAddr(); |
| 637 | 635 | jsonObject.put("ip", remoteAddr); |
| 638 | - List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_started); | |
| 636 | + List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_started); | |
| 639 | 637 | if (subscribes != null && subscribes.size() > 0) { |
| 640 | - for (ZLMHttpHookSubscribe.Event subscribe : subscribes) { | |
| 638 | + for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { | |
| 641 | 639 | subscribe.response(null, jsonObject); |
| 642 | 640 | } |
| 643 | 641 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java
| 1 | 1 | package com.genersoft.iot.vmp.media.zlm; |
| 2 | 2 | |
| 3 | -import com.alibaba.fastjson.JSONObject; | |
| 4 | 3 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 5 | 4 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; |
| 6 | 5 | import com.genersoft.iot.vmp.media.zlm.dto.*; |
| 7 | 6 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 8 | 7 | import com.genersoft.iot.vmp.service.IStreamProxyService; |
| 9 | 8 | import com.genersoft.iot.vmp.service.IStreamPushService; |
| 10 | -import com.genersoft.iot.vmp.service.bean.ThirdPartyGB; | |
| 11 | 9 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 12 | 10 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 13 | 11 | import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; |
| 14 | 12 | import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; |
| 15 | 13 | import com.genersoft.iot.vmp.storager.dao.StreamPushMapper; |
| 16 | 14 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 17 | -import org.checkerframework.checker.units.qual.C; | |
| 18 | 15 | import org.slf4j.Logger; |
| 19 | 16 | import org.slf4j.LoggerFactory; |
| 20 | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 21 | 18 | import org.springframework.stereotype.Component; |
| 22 | -import org.springframework.util.StringUtils; | |
| 23 | 19 | |
| 24 | 20 | import java.util.*; |
| 25 | 21 | import java.util.concurrent.ConcurrentHashMap; |
| 26 | -import java.util.regex.Matcher; | |
| 27 | -import java.util.regex.Pattern; | |
| 28 | 22 | |
| 29 | 23 | /** |
| 30 | 24 | * @author lin |
| ... | ... | @@ -59,7 +53,7 @@ public class ZLMMediaListManager { |
| 59 | 53 | private StreamPushMapper streamPushMapper; |
| 60 | 54 | |
| 61 | 55 | @Autowired |
| 62 | - private ZLMHttpHookSubscribe subscribe; | |
| 56 | + private ZlmHttpHookSubscribe subscribe; | |
| 63 | 57 | |
| 64 | 58 | @Autowired |
| 65 | 59 | private UserSetting userSetting; | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
| ... | ... | @@ -8,7 +8,6 @@ import com.genersoft.iot.vmp.conf.MediaConfig; |
| 8 | 8 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 9 | 9 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 10 | 10 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForServerStarted; |
| 11 | -import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; | |
| 12 | 11 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 13 | 12 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 14 | 13 | import org.slf4j.Logger; |
| ... | ... | @@ -19,9 +18,7 @@ import org.springframework.core.annotation.Order; |
| 19 | 18 | import org.springframework.scheduling.annotation.Async; |
| 20 | 19 | import org.springframework.stereotype.Component; |
| 21 | 20 | |
| 22 | -import java.time.Instant; | |
| 23 | 21 | import java.util.*; |
| 24 | -import java.util.concurrent.TimeUnit; | |
| 25 | 22 | |
| 26 | 23 | @Component |
| 27 | 24 | @Order(value=1) |
| ... | ... | @@ -35,7 +32,7 @@ public class ZLMRunner implements CommandLineRunner { |
| 35 | 32 | private ZLMRESTfulUtils zlmresTfulUtils; |
| 36 | 33 | |
| 37 | 34 | @Autowired |
| 38 | - private ZLMHttpHookSubscribe hookSubscribe; | |
| 35 | + private ZlmHttpHookSubscribe hookSubscribe; | |
| 39 | 36 | |
| 40 | 37 | @Autowired |
| 41 | 38 | private EventPublisher publisher; |
| ... | ... | @@ -62,8 +59,6 @@ public class ZLMRunner implements CommandLineRunner { |
| 62 | 59 | } |
| 63 | 60 | mediaServerService.syncCatchFromDatabase(); |
| 64 | 61 | HookSubscribeForServerStarted hookSubscribeForServerStarted = HookSubscribeFactory.on_server_started(); |
| 65 | -// Instant expiresInstant = Instant.now().plusSeconds(TimeUnit.SECONDS.toSeconds(60)); | |
| 66 | -// hookSubscribeForStreamChange.setExpires(expiresInstant); | |
| 67 | 62 | // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 |
| 68 | 63 | hookSubscribe.addSubscribe(hookSubscribeForServerStarted, |
| 69 | 64 | (MediaServerItem mediaServerItem, JSONObject response)->{ | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java renamed to src/main/java/com/genersoft/iot/vmp/media/zlm/ZlmHttpHookSubscribe.java
| ... | ... | @@ -4,6 +4,9 @@ import com.alibaba.fastjson.JSONObject; |
| 4 | 4 | import com.genersoft.iot.vmp.media.zlm.dto.HookType; |
| 5 | 5 | import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe; |
| 6 | 6 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.scheduling.annotation.Scheduled; | |
| 7 | 10 | import org.springframework.stereotype.Component; |
| 8 | 11 | import org.springframework.util.CollectionUtils; |
| 9 | 12 | |
| ... | ... | @@ -13,21 +16,22 @@ import java.util.concurrent.ConcurrentHashMap; |
| 13 | 16 | import java.util.concurrent.TimeUnit; |
| 14 | 17 | |
| 15 | 18 | /** |
| 16 | - * @description:针对 ZLMediaServer的hook事件订阅 | |
| 17 | - * @author: pan | |
| 18 | - * @date: 2020年12月2日 21:17:32 | |
| 19 | + * ZLMediaServer的hook事件订阅 | |
| 20 | + * @author lin | |
| 19 | 21 | */ |
| 20 | 22 | @Component |
| 21 | -public class ZLMHttpHookSubscribe { | |
| 23 | +public class ZlmHttpHookSubscribe { | |
| 24 | + | |
| 25 | + private final static Logger logger = LoggerFactory.getLogger(ZlmHttpHookSubscribe.class); | |
| 22 | 26 | |
| 23 | 27 | @FunctionalInterface |
| 24 | 28 | public interface Event{ |
| 25 | 29 | void response(MediaServerItem mediaServerItem, JSONObject response); |
| 26 | 30 | } |
| 27 | 31 | |
| 28 | - private Map<HookType, Map<IHookSubscribe, ZLMHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>(); | |
| 32 | + private Map<HookType, Map<IHookSubscribe, ZlmHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>(); | |
| 29 | 33 | |
| 30 | - public void addSubscribe(IHookSubscribe hookSubscribe, ZLMHttpHookSubscribe.Event event) { | |
| 34 | + public void addSubscribe(IHookSubscribe hookSubscribe, ZlmHttpHookSubscribe.Event event) { | |
| 31 | 35 | if (hookSubscribe.getExpires() == null) { |
| 32 | 36 | // 默认5分钟过期 |
| 33 | 37 | Instant expiresInstant = Instant.now().plusSeconds(TimeUnit.MINUTES.toSeconds(5)); |
| ... | ... | @@ -36,8 +40,8 @@ public class ZLMHttpHookSubscribe { |
| 36 | 40 | allSubscribes.computeIfAbsent(hookSubscribe.getHookType(), k -> new ConcurrentHashMap<>()).put(hookSubscribe, event); |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | - public ZLMHttpHookSubscribe.Event sendNotify(HookType type, JSONObject hookResponse) { | |
| 40 | - ZLMHttpHookSubscribe.Event event= null; | |
| 43 | + public ZlmHttpHookSubscribe.Event sendNotify(HookType type, JSONObject hookResponse) { | |
| 44 | + ZlmHttpHookSubscribe.Event event= null; | |
| 41 | 45 | Map<IHookSubscribe, Event> eventMap = allSubscribes.get(type); |
| 42 | 46 | if (eventMap == null) { |
| 43 | 47 | return null; |
| ... | ... | @@ -69,8 +73,8 @@ public class ZLMHttpHookSubscribe { |
| 69 | 73 | |
| 70 | 74 | Set<Map.Entry<IHookSubscribe, Event>> entries = eventMap.entrySet(); |
| 71 | 75 | if (entries.size() > 0) { |
| 72 | - List<Map.Entry<IHookSubscribe, ZLMHttpHookSubscribe.Event>> entriesToRemove = new ArrayList<>(); | |
| 73 | - for (Map.Entry<IHookSubscribe, ZLMHttpHookSubscribe.Event> entry : entries) { | |
| 76 | + List<Map.Entry<IHookSubscribe, ZlmHttpHookSubscribe.Event>> entriesToRemove = new ArrayList<>(); | |
| 77 | + for (Map.Entry<IHookSubscribe, ZlmHttpHookSubscribe.Event> entry : entries) { | |
| 74 | 78 | JSONObject content = entry.getKey().getContent(); |
| 75 | 79 | if (content == null || content.size() == 0) { |
| 76 | 80 | entriesToRemove.add(entry); |
| ... | ... | @@ -87,13 +91,13 @@ public class ZLMHttpHookSubscribe { |
| 87 | 91 | result = result && content.getString(s).equals(hookSubscribe.getContent().getString(s)); |
| 88 | 92 | } |
| 89 | 93 | } |
| 90 | - if (null != result && result){ | |
| 94 | + if (result){ | |
| 91 | 95 | entriesToRemove.add(entry); |
| 92 | 96 | } |
| 93 | 97 | } |
| 94 | 98 | |
| 95 | 99 | if (!CollectionUtils.isEmpty(entriesToRemove)) { |
| 96 | - for (Map.Entry<IHookSubscribe, ZLMHttpHookSubscribe.Event> entry : entriesToRemove) { | |
| 100 | + for (Map.Entry<IHookSubscribe, ZlmHttpHookSubscribe.Event> entry : entriesToRemove) { | |
| 97 | 101 | entries.remove(entry); |
| 98 | 102 | } |
| 99 | 103 | } |
| ... | ... | @@ -106,12 +110,12 @@ public class ZLMHttpHookSubscribe { |
| 106 | 110 | * @param type |
| 107 | 111 | * @return |
| 108 | 112 | */ |
| 109 | - public List<ZLMHttpHookSubscribe.Event> getSubscribes(HookType type) { | |
| 113 | + public List<ZlmHttpHookSubscribe.Event> getSubscribes(HookType type) { | |
| 110 | 114 | Map<IHookSubscribe, Event> eventMap = allSubscribes.get(type); |
| 111 | 115 | if (eventMap == null) { |
| 112 | 116 | return null; |
| 113 | 117 | } |
| 114 | - List<ZLMHttpHookSubscribe.Event> result = new ArrayList<>(); | |
| 118 | + List<ZlmHttpHookSubscribe.Event> result = new ArrayList<>(); | |
| 115 | 119 | for (IHookSubscribe key : eventMap.keySet()) { |
| 116 | 120 | result.add(eventMap.get(key)); |
| 117 | 121 | } |
| ... | ... | @@ -127,5 +131,28 @@ public class ZLMHttpHookSubscribe { |
| 127 | 131 | return result; |
| 128 | 132 | } |
| 129 | 133 | |
| 134 | + /** | |
| 135 | + * 对订阅数据进行过期清理 | |
| 136 | + */ | |
| 137 | + @Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次 | |
| 138 | + public void execute(){ | |
| 130 | 139 | |
| 140 | + logger.info("[hook订阅] 清理"); | |
| 141 | + | |
| 142 | + Instant instant = Instant.now().minusMillis(TimeUnit.MINUTES.toMillis(5)); | |
| 143 | + int total = 0; | |
| 144 | + for (HookType hookType : allSubscribes.keySet()) { | |
| 145 | + Map<IHookSubscribe, Event> hookSubscribeEventMap = allSubscribes.get(hookType); | |
| 146 | + if (hookSubscribeEventMap.size() > 0) { | |
| 147 | + for (IHookSubscribe hookSubscribe : hookSubscribeEventMap.keySet()) { | |
| 148 | + if (hookSubscribe.getExpires().isBefore(instant)) { | |
| 149 | + // 过期的 | |
| 150 | + hookSubscribeEventMap.remove(hookSubscribe); | |
| 151 | + total ++; | |
| 152 | + } | |
| 153 | + } | |
| 154 | + } | |
| 155 | + } | |
| 156 | + logger.info("[hook订阅] 清理结束,共清理{}条过期数据", total); | |
| 157 | + } | |
| 131 | 158 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
| ... | ... | @@ -6,14 +6,13 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback; |
| 7 | 7 | import com.genersoft.iot.vmp.gb28181.bean.InviteStreamInfo; |
| 8 | 8 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| 9 | -import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | |
| 9 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 10 | 10 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 11 | 11 | import com.genersoft.iot.vmp.service.bean.InviteTimeOutCallback; |
| 12 | 12 | import com.genersoft.iot.vmp.service.bean.PlayBackCallback; |
| 13 | 13 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 14 | 14 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| 15 | 15 | import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult; |
| 16 | -import org.springframework.http.ResponseEntity; | |
| 17 | 16 | import org.springframework.web.context.request.async.DeferredResult; |
| 18 | 17 | |
| 19 | 18 | /** |
| ... | ... | @@ -24,9 +23,9 @@ public interface IPlayService { |
| 24 | 23 | void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid); |
| 25 | 24 | |
| 26 | 25 | void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, |
| 27 | - ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, | |
| 26 | + ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, | |
| 28 | 27 | InviteTimeOutCallback timeoutCallback, String uuid); |
| 29 | - PlayResult play(MediaServerItem mediaServerItem, String deviceId, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent, Runnable timeoutCallback); | |
| 28 | + PlayResult play(MediaServerItem mediaServerItem, String deviceId, String channelId, ZlmHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent, Runnable timeoutCallback); | |
| 30 | 29 | |
| 31 | 30 | MediaServerItem getNewMediaServerItem(Device device); |
| 32 | 31 | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -39,7 +39,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 39 | 39 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| 40 | 40 | import com.genersoft.iot.vmp.utils.DateUtil; |
| 41 | 41 | import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils; |
| 42 | -import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | |
| 42 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 43 | 43 | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; |
| 44 | 44 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 45 | 45 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| ... | ... | @@ -99,7 +99,7 @@ public class PlayServiceImpl implements IPlayService { |
| 99 | 99 | private DynamicTask dynamicTask; |
| 100 | 100 | |
| 101 | 101 | @Autowired |
| 102 | - private ZLMHttpHookSubscribe subscribe; | |
| 102 | + private ZlmHttpHookSubscribe subscribe; | |
| 103 | 103 | |
| 104 | 104 | |
| 105 | 105 | @Qualifier("taskExecutor") |
| ... | ... | @@ -110,7 +110,7 @@ public class PlayServiceImpl implements IPlayService { |
| 110 | 110 | |
| 111 | 111 | @Override |
| 112 | 112 | public PlayResult play(MediaServerItem mediaServerItem, String deviceId, String channelId, |
| 113 | - ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, | |
| 113 | + ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, | |
| 114 | 114 | Runnable timeoutCallback) { |
| 115 | 115 | if (mediaServerItem == null) { |
| 116 | 116 | throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的zlm"); |
| ... | ... | @@ -231,8 +231,8 @@ public class PlayServiceImpl implements IPlayService { |
| 231 | 231 | |
| 232 | 232 | @Override |
| 233 | 233 | public void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, |
| 234 | - ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, | |
| 235 | - InviteTimeOutCallback timeoutCallback, String uuid) { | |
| 234 | + ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, | |
| 235 | + InviteTimeOutCallback timeoutCallback, String uuid) { | |
| 236 | 236 | |
| 237 | 237 | String streamId = null; |
| 238 | 238 | if (mediaServerItem.isRtpEnable()) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/RedisGbPlayMsgListener.java
| ... | ... | @@ -5,12 +5,11 @@ import com.alibaba.fastjson.JSONObject; |
| 5 | 5 | import com.genersoft.iot.vmp.conf.DynamicTask; |
| 6 | 6 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 7 | 7 | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| 8 | -import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | |
| 8 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 9 | 9 | import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; |
| 10 | 10 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 11 | 11 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 12 | 12 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| 13 | -import com.genersoft.iot.vmp.media.zlm.dto.HookType; | |
| 14 | 13 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 15 | 14 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 16 | 15 | import com.genersoft.iot.vmp.service.bean.*; |
| ... | ... | @@ -24,9 +23,6 @@ import org.springframework.data.redis.connection.Message; |
| 24 | 23 | import org.springframework.data.redis.connection.MessageListener; |
| 25 | 24 | import org.springframework.stereotype.Component; |
| 26 | 25 | |
| 27 | -import javax.sip.InvalidArgumentException; | |
| 28 | -import javax.sip.SipException; | |
| 29 | -import java.text.ParseException; | |
| 30 | 26 | import java.util.HashMap; |
| 31 | 27 | import java.util.Map; |
| 32 | 28 | import java.util.UUID; |
| ... | ... | @@ -86,7 +82,7 @@ public class RedisGbPlayMsgListener implements MessageListener { |
| 86 | 82 | private ZLMMediaListManager mediaListManager; |
| 87 | 83 | |
| 88 | 84 | @Autowired |
| 89 | - private ZLMHttpHookSubscribe subscribe; | |
| 85 | + private ZlmHttpHookSubscribe subscribe; | |
| 90 | 86 | |
| 91 | 87 | |
| 92 | 88 | public interface PlayMsgCallback{ | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java
| ... | ... | @@ -8,24 +8,21 @@ import com.genersoft.iot.vmp.conf.SipConfig; |
| 8 | 8 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 9 | 9 | import com.genersoft.iot.vmp.conf.VersionInfo; |
| 10 | 10 | import com.genersoft.iot.vmp.conf.exception.ControllerException; |
| 11 | -import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | |
| 11 | +import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | |
| 12 | 12 | import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe; |
| 13 | 13 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 14 | 14 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 15 | 15 | import com.genersoft.iot.vmp.utils.SpringBeanFactory; |
| 16 | 16 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 17 | -import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | |
| 18 | 17 | import gov.nist.javax.sip.SipStackImpl; |
| 19 | 18 | |
| 20 | 19 | import io.swagger.v3.oas.annotations.Operation; |
| 21 | 20 | import io.swagger.v3.oas.annotations.Parameter; |
| 22 | 21 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 23 | -import org.ehcache.xml.model.ThreadPoolsType; | |
| 24 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| 25 | 23 | import org.springframework.beans.factory.annotation.Value; |
| 26 | 24 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 27 | 25 | import org.springframework.util.ObjectUtils; |
| 28 | -import org.springframework.util.StringUtils; | |
| 29 | 26 | import org.springframework.web.bind.annotation.*; |
| 30 | 27 | |
| 31 | 28 | import javax.sip.ListeningPoint; |
| ... | ... | @@ -42,7 +39,7 @@ import java.util.List; |
| 42 | 39 | public class ServerController { |
| 43 | 40 | |
| 44 | 41 | @Autowired |
| 45 | - private ZLMHttpHookSubscribe zlmHttpHookSubscribe; | |
| 42 | + private ZlmHttpHookSubscribe zlmHttpHookSubscribe; | |
| 46 | 43 | |
| 47 | 44 | @Autowired |
| 48 | 45 | private IMediaServerService mediaServerService; | ... | ... |