From 373bfdc44cf56592635eb898c677463ca0f797df Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 2 Sep 2022 15:49:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BA=A7=E8=81=94=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E6=B3=A8=E5=86=8C=E7=9A=84=E5=91=A8=E6=9C=9F=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/bean/ParentPlatform.java | 6 +- .../iot/vmp/gb28181/conf/SipLoggerPass.java | 106 ++++++++++++++++++ .../vmp/media/zlm/ZLMHttpHookListener.java | 80 +++++++------ .../vmp/service/impl/PlatformServiceImpl.java | 5 +- 4 files changed, 149 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/conf/SipLoggerPass.java diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java index ade5d0ee..00a16f99 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java @@ -90,7 +90,7 @@ public class ParentPlatform { * 心跳周期(秒) */ @Schema(description = "心跳周期(秒)") - private String keepTimeout; + private int keepTimeout; /** * 传输协议 @@ -294,11 +294,11 @@ public class ParentPlatform { this.expires = expires; } - public String getKeepTimeout() { + public int getKeepTimeout() { return keepTimeout; } - public void setKeepTimeout(String keepTimeout) { + public void setKeepTimeout(int keepTimeout) { this.keepTimeout = keepTimeout; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/conf/SipLoggerPass.java b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/SipLoggerPass.java new file mode 100644 index 00000000..f8d64853 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/conf/SipLoggerPass.java @@ -0,0 +1,106 @@ +package com.genersoft.iot.vmp.gb28181.conf; + +import gov.nist.core.StackLogger; + +import java.util.Properties; + +/** + * sip日志格式化 + */ +public class SipLoggerPass implements StackLogger { + + @Override + public void logStackTrace() { + + } + + @Override + public void logStackTrace(int traceLevel) { + + } + + @Override + public int getLineCount() { + return 0; + } + + @Override + public void logException(Throwable ex) { + + } + + @Override + public void logDebug(String message) { + + } + + @Override + public void logDebug(String message, Exception ex) { + + } + + @Override + public void logTrace(String message) { + + } + + @Override + public void logFatalError(String message) { + + } + + @Override + public void logError(String message) { + + } + + @Override + public boolean isLoggingEnabled() { + return false; + } + + @Override + public boolean isLoggingEnabled(int logLevel) { + return false; + } + + @Override + public void logError(String message, Exception ex) { + + } + + @Override + public void logWarning(String string) { + + } + + @Override + public void logInfo(String string) { + + } + + @Override + public void disableLogging() { + + } + + @Override + public void enableLogging() { + + } + + @Override + public void setBuildTimeStamp(String buildTimeStamp) { + + } + + @Override + public void setStackProperties(Properties stackProperties) { + + } + + @Override + public String getLoggerName() { + return null; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index ce463934..78b59d90 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -103,7 +103,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8") - public ResponseEntity onServerKeepalive(@RequestBody JSONObject json){ + public JSONObject onServerKeepalive(@RequestBody JSONObject json){ logger.info("[ ZLM HOOK ] on_server_keepalive API调用,参数:" + json.toString()); String mediaServerId = json.getString("mediaServerId"); @@ -118,7 +118,8 @@ public class ZLMHttpHookListener { JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + + return ret; } /** @@ -127,16 +128,15 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_flow_report", produces = "application/json;charset=UTF-8") - public ResponseEntity onFlowReport(@RequestBody JSONObject json){ + public JSONObject onFlowReport(@RequestBody JSONObject json){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_flow_report API调用,参数:" + json.toString()); } - String mediaServerId = json.getString("mediaServerId"); JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } /** @@ -145,7 +145,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_http_access", produces = "application/json;charset=UTF-8") - public ResponseEntity onHttpAccess(@RequestBody JSONObject json){ + public JSONObject onHttpAccess(@RequestBody JSONObject json){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_http_access API 调用,参数:" + json.toString()); @@ -156,7 +156,7 @@ public class ZLMHttpHookListener { ret.put("err", ""); ret.put("path", ""); ret.put("second", 600); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } /** @@ -165,7 +165,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8") - public ResponseEntity onPlay(@RequestBody OnPlayHookParam param){ + public JSONObject onPlay(@RequestBody OnPlayHookParam param){ JSONObject json = (JSONObject)JSON.toJSON(param); @@ -187,13 +187,13 @@ public class ZLMHttpHookListener { if (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId"))) { ret.put("code", 401); ret.put("msg", "Unauthorized"); - return new ResponseEntity<>(ret.toString(),HttpStatus.OK); + return ret; } } ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity<>(ret.toString(),HttpStatus.OK); + return ret; } /** @@ -202,7 +202,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8") - public ResponseEntity onPublish(@RequestBody OnPublishHookParam param) { + public JSONObject onPublish(@RequestBody OnPublishHookParam param) { JSONObject json = (JSONObject) JSON.toJSON(param); @@ -216,7 +216,7 @@ public class ZLMHttpHookListener { logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); ret.put("code", 401); ret.put("msg", "Unauthorized"); - return new ResponseEntity<>(ret.toString(), HttpStatus.OK); + return ret; } Map paramMap = urlParamToMap(param.getParams()); String sign = paramMap.get("sign"); @@ -224,7 +224,7 @@ public class ZLMHttpHookListener { logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); ret.put("code", 401); ret.put("msg", "Unauthorized"); - return new ResponseEntity<>(ret.toString(), HttpStatus.OK); + return ret; } // 推流自定义播放鉴权码 String callId = paramMap.get("callId"); @@ -234,7 +234,7 @@ public class ZLMHttpHookListener { logger.info("推流鉴权失败: sign 无权限: callId={}. sign={}", callId, sign); ret.put("code", 401); ret.put("msg", "Unauthorized"); - return new ResponseEntity<>(ret.toString(), HttpStatus.OK); + return ret; } StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param); streamAuthorityInfo.setCallId(callId); @@ -242,12 +242,11 @@ public class ZLMHttpHookListener { // 鉴权通过 redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo); // 通知assist新的callId - taskExecutor.execute(()->{ - if (mediaInfo != null && mediaInfo.getRecordAssistPort() > 0) { + if (mediaInfo != null && mediaInfo.getRecordAssistPort() > 0) { + taskExecutor.execute(()->{ assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null); - } - }); - + }); + } }else { zlmMediaListManager.sendStreamEvent(param.getApp(),param.getStream(), param.getMediaServerId()); } @@ -291,10 +290,7 @@ public class ZLMHttpHookListener { } } - - - - return new ResponseEntity(ret.toString(), HttpStatus.OK); + return ret; } @@ -305,7 +301,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_record_mp4", produces = "application/json;charset=UTF-8") - public ResponseEntity onRecordMp4(@RequestBody JSONObject json){ + public JSONObject onRecordMp4(@RequestBody JSONObject json){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_record_mp4 API调用,参数:" + json.toString()); @@ -314,7 +310,7 @@ public class ZLMHttpHookListener { JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } /** * 录制hls完成后通知事件;此事件对回复不敏感。 @@ -322,7 +318,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_record_ts", produces = "application/json;charset=UTF-8") - public ResponseEntity onRecordTs(@RequestBody JSONObject json){ + public JSONObject onRecordTs(@RequestBody JSONObject json){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_record_ts API调用,参数:" + json.toString()); @@ -331,7 +327,7 @@ public class ZLMHttpHookListener { JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } /** @@ -340,7 +336,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_rtsp_realm", produces = "application/json;charset=UTF-8") - public ResponseEntity onRtspRealm(@RequestBody JSONObject json){ + public JSONObject onRtspRealm(@RequestBody JSONObject json){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_rtsp_realm API调用,参数:" + json.toString()); @@ -349,7 +345,7 @@ public class ZLMHttpHookListener { JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("realm", ""); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } @@ -359,7 +355,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_rtsp_auth", produces = "application/json;charset=UTF-8") - public ResponseEntity onRtspAuth(@RequestBody JSONObject json){ + public JSONObject onRtspAuth(@RequestBody JSONObject json){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_rtsp_auth API调用,参数:" + json.toString()); @@ -369,7 +365,7 @@ public class ZLMHttpHookListener { ret.put("code", 0); ret.put("encrypted", false); ret.put("passwd", "test"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } /** @@ -378,7 +374,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_shell_login", produces = "application/json;charset=UTF-8") - public ResponseEntity onShellLogin(@RequestBody JSONObject json){ + public JSONObject onShellLogin(@RequestBody JSONObject json){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_shell_login API调用,参数:" + json.toString()); @@ -396,7 +392,7 @@ public class ZLMHttpHookListener { JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } /** @@ -405,7 +401,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_stream_changed", produces = "application/json;charset=UTF-8") - public ResponseEntity onStreamChanged(@RequestBody MediaItem item){ + public JSONObject onStreamChanged(@RequestBody MediaItem item){ logger.info("[ ZLM HOOK ]on_stream_changed API调用,参数:" + JSONObject.toJSONString(item)); String mediaServerId = item.getMediaServerId(); @@ -520,7 +516,7 @@ public class ZLMHttpHookListener { JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } /** @@ -529,7 +525,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_stream_none_reader", produces = "application/json;charset=UTF-8") - public ResponseEntity onStreamNoneReader(@RequestBody JSONObject json){ + public JSONObject onStreamNoneReader(@RequestBody JSONObject json){ logger.info("[ ZLM HOOK ]on_stream_none_reader API调用,参数:" + json.toString()); String mediaServerId = json.getString("mediaServerId"); @@ -574,7 +570,7 @@ public class ZLMHttpHookListener { if (mediaServerItem != null && mediaServerItem.getStreamNoneReaderDelayMS() == -1) { ret.put("close", false); } - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; }else { StreamProxyItem streamProxyItem = streamProxyService.getStreamProxyByAppAndStream(app, streamId); if (streamProxyItem != null && streamProxyItem.isEnable_remove_none_reader()) { @@ -585,7 +581,7 @@ public class ZLMHttpHookListener { }else { ret.put("close", false); } - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return ret; } } @@ -595,7 +591,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8") - public ResponseEntity onStreamNotFound(@RequestBody JSONObject json){ + public JSONObject onStreamNotFound(@RequestBody JSONObject json){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_stream_not_found API调用,参数:" + json.toString()); } @@ -620,7 +616,7 @@ public class ZLMHttpHookListener { JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity<>(ret.toString(),HttpStatus.OK); + return ret; } /** @@ -629,7 +625,7 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_server_started", produces = "application/json;charset=UTF-8") - public ResponseEntity onServerStarted(HttpServletRequest request, @RequestBody JSONObject jsonObject){ + public JSONObject onServerStarted(HttpServletRequest request, @RequestBody JSONObject jsonObject){ if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_server_started API调用,参数:" + jsonObject.toString()); @@ -650,7 +646,7 @@ public class ZLMHttpHookListener { JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity<>(ret.toString(),HttpStatus.OK); + return ret; } private Map urlParamToMap(String params) { diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java index 708d6935..6df1483b 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformServiceImpl.java @@ -125,7 +125,7 @@ public class PlatformServiceImpl implements IPlatformService { dynamicTask.startDelay(registerTaskKey, // 注册失败(注册成功时由程序直接调用了online方法) ()->commanderForPlatform.register(parentPlatform, eventResult -> offline(parentPlatform),null), - parentPlatform.getExpires()*1000); + (parentPlatform.getExpires() - 10) *1000); final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId(); if (!dynamicTask.contains(keepaliveTaskKey)) { @@ -164,7 +164,7 @@ public class PlatformServiceImpl implements IPlatformService { redisCatchStorage.updatePlatformCatchInfo(platformCatch); } }), - parentPlatform.getExpires()*1000); + (parentPlatform.getKeepTimeout() - 10)*1000); } } @@ -213,7 +213,6 @@ public class PlatformServiceImpl implements IPlatformService { param.put("stream", sendRtpItem.getStreamId()); zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param); } - } }