Commit 7b24d51db9800d41fe73df4a97d02ed1429dae11
1 parent
3350b652
优化国标级联的端口保持
Showing
20 changed files
with
168 additions
and
74 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; |
| 2 | 2 | |
| 3 | -import com.alibaba.fastjson2.JSONObject; | |
| 4 | 3 | import com.genersoft.iot.vmp.common.InviteSessionType; |
| 5 | 4 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 6 | 5 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 7 | 6 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 8 | 7 | import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; |
| 9 | 8 | import com.genersoft.iot.vmp.gb28181.SipLayer; |
| 10 | -import com.genersoft.iot.vmp.gb28181.bean.*; | |
| 9 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 10 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; | |
| 11 | +import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; | |
| 11 | 12 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| 12 | 13 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| 13 | 14 | import com.genersoft.iot.vmp.gb28181.transmit.SIPSender; |
| ... | ... | @@ -19,6 +20,7 @@ import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; |
| 19 | 20 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 20 | 21 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| 21 | 22 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 23 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; | |
| 22 | 24 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 23 | 25 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 24 | 26 | import com.genersoft.iot.vmp.utils.DateUtil; |
| ... | ... | @@ -276,9 +278,9 @@ public class SIPCommander implements ISIPCommander { |
| 276 | 278 | |
| 277 | 279 | logger.info("{} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort()); |
| 278 | 280 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", stream, true, "rtsp", mediaServerItem.getId()); |
| 279 | - subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json) -> { | |
| 281 | + subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, HookParam hookParam) -> { | |
| 280 | 282 | if (event != null) { |
| 281 | - event.response(mediaServerItemInUse, json); | |
| 283 | + event.response(mediaServerItemInUse, hookParam); | |
| 282 | 284 | subscribe.removeSubscribe(hookSubscribe); |
| 283 | 285 | } |
| 284 | 286 | }); |
| ... | ... | @@ -466,9 +468,9 @@ public class SIPCommander implements ISIPCommander { |
| 466 | 468 | |
| 467 | 469 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId()); |
| 468 | 470 | // 添加订阅 |
| 469 | - subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json) -> { | |
| 471 | + subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, HookParam hookParam) -> { | |
| 470 | 472 | if (hookEvent != null) { |
| 471 | - hookEvent.response(mediaServerItemInUse, json); | |
| 473 | + hookEvent.response(mediaServerItemInUse, hookParam); | |
| 472 | 474 | } |
| 473 | 475 | subscribe.removeSubscribe(hookSubscribe); |
| 474 | 476 | }); |
| ... | ... | @@ -569,15 +571,15 @@ public class SIPCommander implements ISIPCommander { |
| 569 | 571 | // 添加订阅 |
| 570 | 572 | CallIdHeader newCallIdHeader = sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()), device.getTransport()); |
| 571 | 573 | String callId= newCallIdHeader.getCallId(); |
| 572 | - subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json) -> { | |
| 574 | + subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> { | |
| 573 | 575 | logger.debug("sipc 添加订阅===callId {}",callId); |
| 574 | - hookEvent.response(mediaServerItemInUse, json); | |
| 576 | + hookEvent.response(mediaServerItemInUse, hookParam); | |
| 575 | 577 | subscribe.removeSubscribe(hookSubscribe); |
| 576 | 578 | hookSubscribe.getContent().put("regist", false); |
| 577 | 579 | hookSubscribe.getContent().put("schema", "rtsp"); |
| 578 | 580 | // 添加流注销的订阅,注销了后向设备发送bye |
| 579 | 581 | subscribe.addSubscribe(hookSubscribe, |
| 580 | - (MediaServerItem mediaServerItemForEnd, JSONObject jsonForEnd) -> { | |
| 582 | + (mediaServerItemForEnd, hookParam1) -> { | |
| 581 | 583 | logger.info("[录像]下载结束, 发送BYE"); |
| 582 | 584 | try { |
| 583 | 585 | streamByeCmd(device, channelId, ssrcInfo.getStream(), callId); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; |
| 15 | 15 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 16 | 16 | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; |
| 17 | 17 | import com.genersoft.iot.vmp.media.zlm.dto.*; |
| 18 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; | |
| 18 | 19 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 19 | 20 | import com.genersoft.iot.vmp.service.IPlayService; |
| 20 | 21 | import com.genersoft.iot.vmp.service.IStreamProxyService; |
| ... | ... | @@ -646,10 +647,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 646 | 647 | logger.info("[ app={}, stream={} ]通道未推流,启用流后开始推流", gbStream.getApp(), gbStream.getStream()); |
| 647 | 648 | // 监听流上线 |
| 648 | 649 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed(gbStream.getApp(), gbStream.getStream(), true, "rtsp", mediaServerItem.getId()); |
| 649 | - zlmHttpHookSubscribe.addSubscribe(hookSubscribe, (mediaServerItemInUSe, responseJSON) -> { | |
| 650 | - String app = responseJSON.getString("app"); | |
| 651 | - String stream = responseJSON.getString("stream"); | |
| 652 | - logger.info("[上级点播]拉流代理已经就绪, {}/{}", app, stream); | |
| 650 | + zlmHttpHookSubscribe.addSubscribe(hookSubscribe, (mediaServerItemInUSe, hookParam) -> { | |
| 651 | + OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam)hookParam; | |
| 652 | + logger.info("[上级点播]拉流代理已经就绪, {}/{}", streamChangedHookParam.getApp(), streamChangedHookParam.getStream()); | |
| 653 | 653 | dynamicTask.stop(callIdHeader.getCallId()); |
| 654 | 654 | pushProxyStream(evt, request, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| 655 | 655 | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| ... | ... | @@ -124,14 +124,12 @@ public class ZLMHttpHookListener { |
| 124 | 124 | @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8") |
| 125 | 125 | public HookResult onServerKeepalive(@RequestBody OnServerKeepaliveHookParam param) { |
| 126 | 126 | |
| 127 | -// logger.info("[ZLM HOOK] 收到zlm心跳:" + param.getMediaServerId()); | |
| 128 | 127 | |
| 129 | 128 | taskExecutor.execute(() -> { |
| 130 | 129 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive); |
| 131 | - JSONObject json = (JSONObject) JSON.toJSON(param); | |
| 132 | 130 | if (subscribes != null && subscribes.size() > 0) { |
| 133 | 131 | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { |
| 134 | - subscribe.response(null, json); | |
| 132 | + subscribe.response(null, param); | |
| 135 | 133 | } |
| 136 | 134 | } |
| 137 | 135 | }); |
| ... | ... | @@ -158,7 +156,7 @@ public class ZLMHttpHookListener { |
| 158 | 156 | if (subscribe != null) { |
| 159 | 157 | MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); |
| 160 | 158 | if (mediaInfo != null) { |
| 161 | - subscribe.response(mediaInfo, json); | |
| 159 | + subscribe.response(mediaInfo, param); | |
| 162 | 160 | } |
| 163 | 161 | } |
| 164 | 162 | }); |
| ... | ... | @@ -234,7 +232,7 @@ public class ZLMHttpHookListener { |
| 234 | 232 | ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json); |
| 235 | 233 | if (subscribe != null) { |
| 236 | 234 | if (mediaInfo != null) { |
| 237 | - subscribe.response(mediaInfo, json); | |
| 235 | + subscribe.response(mediaInfo, param); | |
| 238 | 236 | } else { |
| 239 | 237 | new HookResultForOnPublish(1, "zlm not register"); |
| 240 | 238 | } |
| ... | ... | @@ -306,7 +304,7 @@ public class ZLMHttpHookListener { |
| 306 | 304 | return; |
| 307 | 305 | } |
| 308 | 306 | if (subscribe != null) { |
| 309 | - subscribe.response(mediaInfo, json); | |
| 307 | + subscribe.response(mediaInfo, param); | |
| 310 | 308 | } |
| 311 | 309 | |
| 312 | 310 | List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks(); |
| ... | ... | @@ -649,7 +647,7 @@ public class ZLMHttpHookListener { |
| 649 | 647 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_started); |
| 650 | 648 | if (subscribes != null && subscribes.size() > 0) { |
| 651 | 649 | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { |
| 652 | - subscribe.response(null, jsonObject); | |
| 650 | + subscribe.response(null, zlmServerConfig); | |
| 653 | 651 | } |
| 654 | 652 | } |
| 655 | 653 | mediaServerService.zlmServerOnline(zlmServerConfig); |
| ... | ... | @@ -704,7 +702,7 @@ public class ZLMHttpHookListener { |
| 704 | 702 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_rtp_server_timeout); |
| 705 | 703 | if (subscribes != null && subscribes.size() > 0) { |
| 706 | 704 | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { |
| 707 | - subscribe.response(null, json); | |
| 705 | + subscribe.response(null, param); | |
| 708 | 706 | } |
| 709 | 707 | } |
| 710 | 708 | }); | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
| ... | ... | @@ -270,6 +270,11 @@ public class ZLMRESTfulUtils { |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | public JSONObject openRtpServer(MediaServerItem mediaServerItem, Map<String, Object> param){ |
| 273 | + System.out.println("==============openRtpServer================="); | |
| 274 | + for (String s : param.keySet()) { | |
| 275 | + System.out.println(s + "-->" + param.get(s)); | |
| 276 | + } | |
| 277 | + System.out.println("==============================="); | |
| 273 | 278 | return sendPost(mediaServerItem, "openRtpServer",param, null); |
| 274 | 279 | } |
| 275 | 280 | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
| ... | ... | @@ -9,6 +9,8 @@ import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| 9 | 9 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 10 | 10 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout; |
| 11 | 11 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 12 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; | |
| 13 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRtpServerTimeoutHookParam; | |
| 12 | 14 | import org.slf4j.Logger; |
| 13 | 15 | import org.slf4j.LoggerFactory; |
| 14 | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | ... | @@ -225,7 +227,8 @@ public class ZLMRTPServerFactory { |
| 225 | 227 | int localPort = 0; |
| 226 | 228 | if (userSetting.getGbSendStreamStrict()) { |
| 227 | 229 | if (userSetting.getGbSendStreamStrict()) { |
| 228 | - localPort = keepPort(serverItem, ssrc); | |
| 230 | + System.out.println("createSendRtpItem1"); | |
| 231 | + localPort = keepPort(serverItem, ssrc, localPort); | |
| 229 | 232 | if (localPort == 0) { |
| 230 | 233 | return null; |
| 231 | 234 | } |
| ... | ... | @@ -261,7 +264,8 @@ public class ZLMRTPServerFactory { |
| 261 | 264 | // 默认为随机端口 |
| 262 | 265 | int localPort = 0; |
| 263 | 266 | if (userSetting.getGbSendStreamStrict()) { |
| 264 | - localPort = keepPort(serverItem, ssrc); | |
| 267 | + System.out.println("createSendRtpItem2"); | |
| 268 | + localPort = keepPort(serverItem, ssrc, localPort); | |
| 265 | 269 | if (localPort == 0) { |
| 266 | 270 | return null; |
| 267 | 271 | } |
| ... | ... | @@ -285,30 +289,37 @@ public class ZLMRTPServerFactory { |
| 285 | 289 | /** |
| 286 | 290 | * 保持端口,直到需要需要发流时再释放 |
| 287 | 291 | */ |
| 288 | - public int keepPort(MediaServerItem serverItem, String ssrc) { | |
| 289 | - int localPort = 0; | |
| 292 | + public int keepPort(MediaServerItem serverItem, String ssrc, Integer localPort) { | |
| 290 | 293 | Map<String, Object> param = new HashMap<>(3); |
| 291 | - param.put("port", 0); | |
| 294 | + param.put("port", localPort); | |
| 292 | 295 | param.put("enable_tcp", 1); |
| 293 | 296 | param.put("stream_id", ssrc); |
| 297 | + System.out.println("用于收流"); | |
| 294 | 298 | JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param); |
| 299 | + System.out.println(jsonObject); | |
| 295 | 300 | if (jsonObject.getInteger("code") == 0) { |
| 296 | 301 | localPort = jsonObject.getInteger("port"); |
| 297 | 302 | HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId()); |
| 303 | + Integer finalLocalPort = localPort; | |
| 298 | 304 | hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout, |
| 299 | - (MediaServerItem mediaServerItem, JSONObject response)->{ | |
| 300 | - logger.info("[上级点播] {}->监听端口到期继续保持监听", ssrc); | |
| 301 | - int port = keepPort(serverItem, ssrc); | |
| 305 | + (MediaServerItem mediaServerItem, HookParam hookParam)->{ | |
| 306 | + logger.info("[上级点播] {}->监听端口到期继续保持监听: {}", ssrc, finalLocalPort); | |
| 307 | + OnRtpServerTimeoutHookParam rtpServerTimeoutHookParam = (OnRtpServerTimeoutHookParam) hookParam; | |
| 308 | + if (!ssrc.equals(rtpServerTimeoutHookParam.getSsrc())) { | |
| 309 | + return; | |
| 310 | + } | |
| 311 | + int port = keepPort(serverItem, ssrc, finalLocalPort); | |
| 302 | 312 | if (port == 0) { |
| 303 | 313 | logger.info("[上级点播] {}->监听端口失败,移除监听", ssrc); |
| 304 | 314 | hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout); |
| 305 | 315 | } |
| 306 | 316 | }); |
| 307 | 317 | logger.info("[上级点播] {}->监听端口: {}", ssrc, localPort); |
| 318 | + return localPort; | |
| 308 | 319 | }else { |
| 309 | - logger.info("[上级点播] 监听端口失败: {}", ssrc); | |
| 320 | + logger.info("[上级点播] 监听端口失败: {}->{}", ssrc, localPort); | |
| 321 | + return 0; | |
| 310 | 322 | } |
| 311 | - return localPort; | |
| 312 | 323 | } |
| 313 | 324 | |
| 314 | 325 | /** | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
| ... | ... | @@ -65,8 +65,8 @@ public class ZLMRunner implements CommandLineRunner { |
| 65 | 65 | HookSubscribeForServerStarted hookSubscribeForServerStarted = HookSubscribeFactory.on_server_started(); |
| 66 | 66 | // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 |
| 67 | 67 | hookSubscribe.addSubscribe(hookSubscribeForServerStarted, |
| 68 | - (MediaServerItem mediaServerItem, JSONObject response)->{ | |
| 69 | - ZLMServerConfig zlmServerConfig = response.to(ZLMServerConfig.class); | |
| 68 | + (mediaServerItem, hookParam)->{ | |
| 69 | + ZLMServerConfig zlmServerConfig = (ZLMServerConfig)hookParam; | |
| 70 | 70 | if (zlmServerConfig !=null ) { |
| 71 | 71 | if (startGetMedia != null) { |
| 72 | 72 | startGetMedia.remove(zlmServerConfig.getGeneralMediaServerId()); | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerConfig.java
| 1 | 1 | package com.genersoft.iot.vmp.media.zlm; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson2.annotation.JSONField; |
| 4 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; | |
| 4 | 5 | |
| 5 | -public class ZLMServerConfig { | |
| 6 | +public class ZLMServerConfig extends HookParam { | |
| 6 | 7 | |
| 7 | 8 | @JSONField(name = "api.apiDebug") |
| 8 | 9 | private String apiDebug; | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZlmHttpHookSubscribe.java
| ... | ... | @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.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 com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; | |
| 7 | 8 | import org.slf4j.Logger; |
| 8 | 9 | import org.slf4j.LoggerFactory; |
| 9 | 10 | import org.springframework.scheduling.annotation.Scheduled; |
| ... | ... | @@ -26,7 +27,7 @@ public class ZlmHttpHookSubscribe { |
| 26 | 27 | |
| 27 | 28 | @FunctionalInterface |
| 28 | 29 | public interface Event{ |
| 29 | - void response(MediaServerItem mediaServerItem, JSONObject response); | |
| 30 | + void response(MediaServerItem mediaServerItem, HookParam hookParam); | |
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | private Map<HookType, Map<IHookSubscribe, ZlmHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookResultForOnPublish.java
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnPlayHookParam.java
| ... | ... | @@ -81,6 +81,15 @@ public class OnPlayHookParam extends HookParam{ |
| 81 | 81 | |
| 82 | 82 | @Override |
| 83 | 83 | public String toString() { |
| 84 | - return String.format("%s://%s:%s/%s/%s?%s", schema, ip, port, app, stream, params); | |
| 84 | + return "OnPlayHookParam{" + | |
| 85 | + "id='" + id + '\'' + | |
| 86 | + ", app='" + app + '\'' + | |
| 87 | + ", stream='" + stream + '\'' + | |
| 88 | + ", ip='" + ip + '\'' + | |
| 89 | + ", params='" + params + '\'' + | |
| 90 | + ", port=" + port + | |
| 91 | + ", schema='" + schema + '\'' + | |
| 92 | + ", vhost='" + vhost + '\'' + | |
| 93 | + '}'; | |
| 85 | 94 | } |
| 86 | 95 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnPublishHookParam.java
| ... | ... | @@ -81,6 +81,15 @@ public class OnPublishHookParam extends HookParam{ |
| 81 | 81 | |
| 82 | 82 | @Override |
| 83 | 83 | public String toString() { |
| 84 | - return String.format("%s://%s:%s/%s/%s?%s", schema, ip, port, app, stream, params); | |
| 84 | + return "OnPublishHookParam{" + | |
| 85 | + "id='" + id + '\'' + | |
| 86 | + ", app='" + app + '\'' + | |
| 87 | + ", stream='" + stream + '\'' + | |
| 88 | + ", ip='" + ip + '\'' + | |
| 89 | + ", params='" + params + '\'' + | |
| 90 | + ", port=" + port + | |
| 91 | + ", schema='" + schema + '\'' + | |
| 92 | + ", vhost='" + vhost + '\'' + | |
| 93 | + '}'; | |
| 85 | 94 | } |
| 86 | 95 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnRtpServerTimeoutHookParam.java
| ... | ... | @@ -50,4 +50,15 @@ public class OnRtpServerTimeoutHookParam extends HookParam{ |
| 50 | 50 | public void setSsrc(String ssrc) { |
| 51 | 51 | this.ssrc = ssrc; |
| 52 | 52 | } |
| 53 | + | |
| 54 | + @Override | |
| 55 | + public String toString() { | |
| 56 | + return "OnRtpServerTimeoutHookParam{" + | |
| 57 | + "local_port=" + local_port + | |
| 58 | + ", stream_id='" + stream_id + '\'' + | |
| 59 | + ", tcpMode=" + tcpMode + | |
| 60 | + ", re_use_port=" + re_use_port + | |
| 61 | + ", ssrc='" + ssrc + '\'' + | |
| 62 | + '}'; | |
| 63 | + } | |
| 53 | 64 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnSendRtpStoppedHookParam.java
| ... | ... | @@ -24,4 +24,12 @@ public class OnSendRtpStoppedHookParam extends HookParam{ |
| 24 | 24 | public void setStream(String stream) { |
| 25 | 25 | this.stream = stream; |
| 26 | 26 | } |
| 27 | + | |
| 28 | + @Override | |
| 29 | + public String toString() { | |
| 30 | + return "OnSendRtpStoppedHookParam{" + | |
| 31 | + "app='" + app + '\'' + | |
| 32 | + ", stream='" + stream + '\'' + | |
| 33 | + '}'; | |
| 34 | + } | |
| 27 | 35 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnServerKeepaliveHookParam.java
| ... | ... | @@ -17,4 +17,11 @@ public class OnServerKeepaliveHookParam extends HookParam{ |
| 17 | 17 | public void setData(ServerKeepaliveData data) { |
| 18 | 18 | this.data = data; |
| 19 | 19 | } |
| 20 | + | |
| 21 | + @Override | |
| 22 | + public String toString() { | |
| 23 | + return "OnServerKeepaliveHookParam{" + | |
| 24 | + "data=" + data + | |
| 25 | + '}'; | |
| 26 | + } | |
| 20 | 27 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnStreamChangedHookParam.java
| ... | ... | @@ -430,4 +430,14 @@ public class OnStreamChangedHookParam extends HookParam{ |
| 430 | 430 | public void setCallId(String callId) { |
| 431 | 431 | this.callId = callId; |
| 432 | 432 | } |
| 433 | + | |
| 434 | + @Override | |
| 435 | + public String toString() { | |
| 436 | + return "OnStreamChangedHookParam{" + | |
| 437 | + "regist=" + regist + | |
| 438 | + ", app='" + app + '\'' + | |
| 439 | + ", stream='" + stream + '\'' + | |
| 440 | + ", severId='" + severId + '\'' + | |
| 441 | + '}'; | |
| 442 | + } | |
| 433 | 443 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnStreamNoneReaderHookParam.java
| ... | ... | @@ -38,4 +38,14 @@ public class OnStreamNoneReaderHookParam extends HookParam{ |
| 38 | 38 | public void setVhost(String vhost) { |
| 39 | 39 | this.vhost = vhost; |
| 40 | 40 | } |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public String toString() { | |
| 44 | + return "OnStreamNoneReaderHookParam{" + | |
| 45 | + "schema='" + schema + '\'' + | |
| 46 | + ", app='" + app + '\'' + | |
| 47 | + ", stream='" + stream + '\'' + | |
| 48 | + ", vhost='" + vhost + '\'' + | |
| 49 | + '}'; | |
| 50 | + } | |
| 41 | 51 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnStreamNotFoundHookParam.java
| ... | ... | @@ -81,6 +81,15 @@ public class OnStreamNotFoundHookParam extends HookParam{ |
| 81 | 81 | |
| 82 | 82 | @Override |
| 83 | 83 | public String toString() { |
| 84 | - return String.format("%s://%s:%s/%s/%s?%s", schema, ip, port, app, stream, params); | |
| 84 | + return "OnStreamNotFoundHookParam{" + | |
| 85 | + "id='" + id + '\'' + | |
| 86 | + ", app='" + app + '\'' + | |
| 87 | + ", stream='" + stream + '\'' + | |
| 88 | + ", ip='" + ip + '\'' + | |
| 89 | + ", params='" + params + '\'' + | |
| 90 | + ", port=" + port + | |
| 91 | + ", schema='" + schema + '\'' + | |
| 92 | + ", vhost='" + vhost + '\'' + | |
| 93 | + '}'; | |
| 85 | 94 | } |
| 86 | 95 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| 1 | 1 | package com.genersoft.iot.vmp.service.impl; |
| 2 | 2 | |
| 3 | -import com.alibaba.fastjson2.JSONArray; | |
| 4 | 3 | import com.alibaba.fastjson2.JSONObject; |
| 5 | 4 | import com.genersoft.iot.vmp.common.InviteInfo; |
| 6 | 5 | import com.genersoft.iot.vmp.common.InviteSessionStatus; |
| ... | ... | @@ -25,6 +24,8 @@ import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; |
| 25 | 24 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 26 | 25 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| 27 | 26 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 27 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; | |
| 28 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; | |
| 28 | 29 | import com.genersoft.iot.vmp.service.*; |
| 29 | 30 | import com.genersoft.iot.vmp.service.bean.ErrorCallback; |
| 30 | 31 | import com.genersoft.iot.vmp.service.bean.InviteErrorCode; |
| ... | ... | @@ -321,11 +322,11 @@ public class PlayServiceImpl implements IPlayService { |
| 321 | 322 | }, userSetting.getPlayTimeout()); |
| 322 | 323 | |
| 323 | 324 | try { |
| 324 | - cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId,isSubStream, (MediaServerItem mediaServerItemInuse, JSONObject response) -> { | |
| 325 | - logger.info("收到订阅消息: " + response.toJSONString()); | |
| 325 | + cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId,isSubStream, (mediaServerItemInuse, hookParam ) -> { | |
| 326 | + logger.info("收到订阅消息: " + hookParam); | |
| 326 | 327 | dynamicTask.stop(timeOutTaskKey); |
| 327 | 328 | // hook响应 |
| 328 | - StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInuse, response, device.getDeviceId(), channelId,isSubStream); | |
| 329 | + StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInuse, hookParam, device.getDeviceId(), channelId,isSubStream); | |
| 329 | 330 | if (streamInfo == null){ |
| 330 | 331 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| 331 | 332 | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); |
| ... | ... | @@ -438,11 +439,11 @@ public class PlayServiceImpl implements IPlayService { |
| 438 | 439 | String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase(); |
| 439 | 440 | hookSubscribe.getContent().put("stream", stream); |
| 440 | 441 | inviteInfo.setStream(stream); |
| 441 | - subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response) -> { | |
| 442 | - logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + response.toJSONString()); | |
| 442 | + subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> { | |
| 443 | + logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam); | |
| 443 | 444 | dynamicTask.stop(timeOutTaskKey); |
| 444 | 445 | // hook响应 |
| 445 | - StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInUse, response, device.getDeviceId(), channelId,isSubStream); | |
| 446 | + StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInUse, hookParam, device.getDeviceId(), channelId,isSubStream); | |
| 446 | 447 | if (streamInfo == null){ |
| 447 | 448 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| 448 | 449 | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); |
| ... | ... | @@ -568,13 +569,14 @@ public class PlayServiceImpl implements IPlayService { |
| 568 | 569 | } |
| 569 | 570 | } |
| 570 | 571 | |
| 571 | - private StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId,boolean isSubStream) { | |
| 572 | + private StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, HookParam hookParam, String deviceId, String channelId, boolean isSubStream) { | |
| 572 | 573 | StreamInfo streamInfo = null; |
| 573 | 574 | Device device = redisCatchStorage.getDevice(deviceId); |
| 575 | + OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam)hookParam; | |
| 574 | 576 | if( device.isSwitchPrimarySubStream() ){ |
| 575 | - streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId,isSubStream); | |
| 577 | + streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId,isSubStream); | |
| 576 | 578 | }else { |
| 577 | - streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId); | |
| 579 | + streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId); | |
| 578 | 580 | } |
| 579 | 581 | if (streamInfo != null) { |
| 580 | 582 | InviteInfo inviteInfo; |
| ... | ... | @@ -603,9 +605,9 @@ public class PlayServiceImpl implements IPlayService { |
| 603 | 605 | |
| 604 | 606 | } |
| 605 | 607 | |
| 606 | - private StreamInfo onPublishHandlerForPlayback(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId, String startTime, String endTime) { | |
| 607 | - | |
| 608 | - StreamInfo streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId); | |
| 608 | + private StreamInfo onPublishHandlerForPlayback(MediaServerItem mediaServerItem, HookParam param, String deviceId, String channelId, String startTime, String endTime) { | |
| 609 | + OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam) param; | |
| 610 | + StreamInfo streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId); | |
| 609 | 611 | if (streamInfo != null) { |
| 610 | 612 | streamInfo.setStartTime(startTime); |
| 611 | 613 | streamInfo.setEndTime(endTime); |
| ... | ... | @@ -724,10 +726,10 @@ public class PlayServiceImpl implements IPlayService { |
| 724 | 726 | inviteStreamService.removeInviteInfo(inviteInfo); |
| 725 | 727 | }; |
| 726 | 728 | |
| 727 | - ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInuse, jsonObject) -> { | |
| 728 | - logger.info("收到回放订阅消息: " + jsonObject); | |
| 729 | + ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInuse, hookParam) -> { | |
| 730 | + logger.info("收到回放订阅消息: " + hookParam); | |
| 729 | 731 | dynamicTask.stop(playBackTimeOutTaskKey); |
| 730 | - StreamInfo streamInfo = onPublishHandlerForPlayback(mediaServerItemInuse, jsonObject, deviceId, channelId, startTime, endTime); | |
| 732 | + StreamInfo streamInfo = onPublishHandlerForPlayback(mediaServerItemInuse, hookParam, deviceId, channelId, startTime, endTime); | |
| 731 | 733 | if (streamInfo == null) { |
| 732 | 734 | logger.warn("设备回放API调用失败!"); |
| 733 | 735 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| ... | ... | @@ -804,11 +806,11 @@ public class PlayServiceImpl implements IPlayService { |
| 804 | 806 | String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase(); |
| 805 | 807 | hookSubscribe.getContent().put("stream", stream); |
| 806 | 808 | inviteInfo.setStream(stream); |
| 807 | - subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response) -> { | |
| 808 | - logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + response.toJSONString()); | |
| 809 | + subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> { | |
| 810 | + logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam); | |
| 809 | 811 | dynamicTask.stop(playBackTimeOutTaskKey); |
| 810 | 812 | // hook响应 |
| 811 | - hookEvent.response(mediaServerItemInUse, response); | |
| 813 | + hookEvent.response(mediaServerItemInUse, hookParam); | |
| 812 | 814 | }); |
| 813 | 815 | } |
| 814 | 816 | // 更新ssrc |
| ... | ... | @@ -920,10 +922,10 @@ public class PlayServiceImpl implements IPlayService { |
| 920 | 922 | streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); |
| 921 | 923 | inviteStreamService.removeInviteInfo(inviteInfo); |
| 922 | 924 | }; |
| 923 | - ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInuse, jsonObject) -> { | |
| 924 | - logger.info("[录像下载]收到订阅消息: " + jsonObject); | |
| 925 | + ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInuse, hookParam) -> { | |
| 926 | + logger.info("[录像下载]收到订阅消息: " + hookParam); | |
| 925 | 927 | dynamicTask.stop(downLoadTimeOutTaskKey); |
| 926 | - StreamInfo streamInfo = onPublishHandlerForDownload(mediaServerItemInuse, jsonObject, deviceId, channelId, startTime, endTime); | |
| 928 | + StreamInfo streamInfo = onPublishHandlerForDownload(mediaServerItemInuse, hookParam, deviceId, channelId, startTime, endTime); | |
| 927 | 929 | if (streamInfo == null) { |
| 928 | 930 | logger.warn("[录像下载] 获取流地址信息失败"); |
| 929 | 931 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| ... | ... | @@ -997,10 +999,10 @@ public class PlayServiceImpl implements IPlayService { |
| 997 | 999 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId()); |
| 998 | 1000 | subscribe.removeSubscribe(hookSubscribe); |
| 999 | 1001 | hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase()); |
| 1000 | - subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject response) -> { | |
| 1001 | - logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + response.toJSONString()); | |
| 1002 | + subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> { | |
| 1003 | + logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + hookParam); | |
| 1002 | 1004 | dynamicTask.stop(downLoadTimeOutTaskKey); |
| 1003 | - hookEvent.response(mediaServerItemInUse, response); | |
| 1005 | + hookEvent.response(mediaServerItemInUse, hookParam); | |
| 1004 | 1006 | }); |
| 1005 | 1007 | } |
| 1006 | 1008 | |
| ... | ... | @@ -1090,8 +1092,9 @@ public class PlayServiceImpl implements IPlayService { |
| 1090 | 1092 | return null; |
| 1091 | 1093 | } |
| 1092 | 1094 | |
| 1093 | - private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, JSONObject response, String deviceId, String channelId, String startTime, String endTime) { | |
| 1094 | - StreamInfo streamInfo = onPublishHandler(mediaServerItemInuse, response, deviceId, channelId); | |
| 1095 | + private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, HookParam hookParam, String deviceId, String channelId, String startTime, String endTime) { | |
| 1096 | + OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam) hookParam; | |
| 1097 | + StreamInfo streamInfo = onPublishHandler(mediaServerItemInuse, streamChangedHookParam, deviceId, channelId); | |
| 1095 | 1098 | if (streamInfo != null) { |
| 1096 | 1099 | streamInfo.setProgress(0); |
| 1097 | 1100 | streamInfo.setStartTime(startTime); |
| ... | ... | @@ -1108,10 +1111,8 @@ public class PlayServiceImpl implements IPlayService { |
| 1108 | 1111 | } |
| 1109 | 1112 | |
| 1110 | 1113 | |
| 1111 | - public StreamInfo onPublishHandler(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId) { | |
| 1112 | - String streamId = resonse.getString("stream"); | |
| 1113 | - JSONArray tracks = resonse.getJSONArray("tracks"); | |
| 1114 | - StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "rtp", streamId, tracks, null); | |
| 1114 | + public StreamInfo onPublishHandler(MediaServerItem mediaServerItem, OnStreamChangedHookParam hookParam, String deviceId, String channelId) { | |
| 1115 | + StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "rtp", hookParam.getStream(), hookParam.getTracks(), null); | |
| 1115 | 1116 | streamInfo.setDeviceID(deviceId); |
| 1116 | 1117 | streamInfo.setChannelId(channelId); |
| 1117 | 1118 | return streamInfo; |
| ... | ... | @@ -1307,9 +1308,9 @@ public class PlayServiceImpl implements IPlayService { |
| 1307 | 1308 | |
| 1308 | 1309 | |
| 1309 | 1310 | /*======================设备主子码流逻辑START=========================*/ |
| 1310 | - public StreamInfo onPublishHandler(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId,boolean isSubStream) { | |
| 1311 | - String streamId = resonse.getString("stream"); | |
| 1312 | - JSONArray tracks = resonse.getJSONArray("tracks"); | |
| 1311 | + public StreamInfo onPublishHandler(MediaServerItem mediaServerItem, OnStreamChangedHookParam hookParam, String deviceId, String channelId,boolean isSubStream) { | |
| 1312 | + String streamId = hookParam.getStream(); | |
| 1313 | + List<OnStreamChangedHookParam.MediaTrack> tracks = hookParam.getTracks(); | |
| 1313 | 1314 | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "rtp", streamId, tracks, null); |
| 1314 | 1315 | streamInfo.setDeviceID(deviceId); |
| 1315 | 1316 | streamInfo.setChannelId(channelId); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/redisMsg/RedisGbPlayMsgListener.java
| ... | ... | @@ -289,7 +289,7 @@ public class RedisGbPlayMsgListener implements MessageListener { |
| 289 | 289 | // 添加订阅 |
| 290 | 290 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed(content.getApp(), content.getStream(), true, "rtsp", mediaServerItem.getId()); |
| 291 | 291 | |
| 292 | - subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json)->{ | |
| 292 | + subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam)->{ | |
| 293 | 293 | dynamicTask.stop(taskKey); |
| 294 | 294 | responseSendItem(mediaServerItem, content, toId, serial); |
| 295 | 295 | }); | ... | ... |