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 | package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; | 1 | package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson2.JSONObject; | ||
| 4 | import com.genersoft.iot.vmp.common.InviteSessionType; | 3 | import com.genersoft.iot.vmp.common.InviteSessionType; |
| 5 | import com.genersoft.iot.vmp.common.StreamInfo; | 4 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 6 | import com.genersoft.iot.vmp.conf.SipConfig; | 5 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 7 | import com.genersoft.iot.vmp.conf.UserSetting; | 6 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 8 | import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; | 7 | import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; |
| 9 | import com.genersoft.iot.vmp.gb28181.SipLayer; | 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 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; | 12 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| 12 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; | 13 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| 13 | import com.genersoft.iot.vmp.gb28181.transmit.SIPSender; | 14 | import com.genersoft.iot.vmp.gb28181.transmit.SIPSender; |
| @@ -19,6 +20,7 @@ import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | @@ -19,6 +20,7 @@ import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | ||
| 19 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; | 20 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 20 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; | 21 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| 21 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 22 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 23 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; | ||
| 22 | import com.genersoft.iot.vmp.service.IMediaServerService; | 24 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 23 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; | 25 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 24 | import com.genersoft.iot.vmp.utils.DateUtil; | 26 | import com.genersoft.iot.vmp.utils.DateUtil; |
| @@ -276,9 +278,9 @@ public class SIPCommander implements ISIPCommander { | @@ -276,9 +278,9 @@ public class SIPCommander implements ISIPCommander { | ||
| 276 | 278 | ||
| 277 | logger.info("{} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort()); | 279 | logger.info("{} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort()); |
| 278 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", stream, true, "rtsp", mediaServerItem.getId()); | 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 | if (event != null) { | 282 | if (event != null) { |
| 281 | - event.response(mediaServerItemInUse, json); | 283 | + event.response(mediaServerItemInUse, hookParam); |
| 282 | subscribe.removeSubscribe(hookSubscribe); | 284 | subscribe.removeSubscribe(hookSubscribe); |
| 283 | } | 285 | } |
| 284 | }); | 286 | }); |
| @@ -466,9 +468,9 @@ public class SIPCommander implements ISIPCommander { | @@ -466,9 +468,9 @@ public class SIPCommander implements ISIPCommander { | ||
| 466 | 468 | ||
| 467 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId()); | 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 | if (hookEvent != null) { | 472 | if (hookEvent != null) { |
| 471 | - hookEvent.response(mediaServerItemInUse, json); | 473 | + hookEvent.response(mediaServerItemInUse, hookParam); |
| 472 | } | 474 | } |
| 473 | subscribe.removeSubscribe(hookSubscribe); | 475 | subscribe.removeSubscribe(hookSubscribe); |
| 474 | }); | 476 | }); |
| @@ -569,15 +571,15 @@ public class SIPCommander implements ISIPCommander { | @@ -569,15 +571,15 @@ public class SIPCommander implements ISIPCommander { | ||
| 569 | // 添加订阅 | 571 | // 添加订阅 |
| 570 | CallIdHeader newCallIdHeader = sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()), device.getTransport()); | 572 | CallIdHeader newCallIdHeader = sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()), device.getTransport()); |
| 571 | String callId= newCallIdHeader.getCallId(); | 573 | String callId= newCallIdHeader.getCallId(); |
| 572 | - subscribe.addSubscribe(hookSubscribe, (MediaServerItem mediaServerItemInUse, JSONObject json) -> { | 574 | + subscribe.addSubscribe(hookSubscribe, (mediaServerItemInUse, hookParam) -> { |
| 573 | logger.debug("sipc 添加订阅===callId {}",callId); | 575 | logger.debug("sipc 添加订阅===callId {}",callId); |
| 574 | - hookEvent.response(mediaServerItemInUse, json); | 576 | + hookEvent.response(mediaServerItemInUse, hookParam); |
| 575 | subscribe.removeSubscribe(hookSubscribe); | 577 | subscribe.removeSubscribe(hookSubscribe); |
| 576 | hookSubscribe.getContent().put("regist", false); | 578 | hookSubscribe.getContent().put("regist", false); |
| 577 | hookSubscribe.getContent().put("schema", "rtsp"); | 579 | hookSubscribe.getContent().put("schema", "rtsp"); |
| 578 | // 添加流注销的订阅,注销了后向设备发送bye | 580 | // 添加流注销的订阅,注销了后向设备发送bye |
| 579 | subscribe.addSubscribe(hookSubscribe, | 581 | subscribe.addSubscribe(hookSubscribe, |
| 580 | - (MediaServerItem mediaServerItemForEnd, JSONObject jsonForEnd) -> { | 582 | + (mediaServerItemForEnd, hookParam1) -> { |
| 581 | logger.info("[录像]下载结束, 发送BYE"); | 583 | logger.info("[录像]下载结束, 发送BYE"); |
| 582 | try { | 584 | try { |
| 583 | streamByeCmd(device, channelId, ssrcInfo.getStream(), callId); | 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,6 +15,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; | ||
| 15 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; | 15 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 16 | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | 16 | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; |
| 17 | import com.genersoft.iot.vmp.media.zlm.dto.*; | 17 | import com.genersoft.iot.vmp.media.zlm.dto.*; |
| 18 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; | ||
| 18 | import com.genersoft.iot.vmp.service.IMediaServerService; | 19 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 19 | import com.genersoft.iot.vmp.service.IPlayService; | 20 | import com.genersoft.iot.vmp.service.IPlayService; |
| 20 | import com.genersoft.iot.vmp.service.IStreamProxyService; | 21 | import com.genersoft.iot.vmp.service.IStreamProxyService; |
| @@ -646,10 +647,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements | @@ -646,10 +647,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements | ||
| 646 | logger.info("[ app={}, stream={} ]通道未推流,启用流后开始推流", gbStream.getApp(), gbStream.getStream()); | 647 | logger.info("[ app={}, stream={} ]通道未推流,启用流后开始推流", gbStream.getApp(), gbStream.getStream()); |
| 647 | // 监听流上线 | 648 | // 监听流上线 |
| 648 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed(gbStream.getApp(), gbStream.getStream(), true, "rtsp", mediaServerItem.getId()); | 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 | dynamicTask.stop(callIdHeader.getCallId()); | 653 | dynamicTask.stop(callIdHeader.getCallId()); |
| 654 | pushProxyStream(evt, request, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive, | 654 | pushProxyStream(evt, request, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive, |
| 655 | mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId); | 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,14 +124,12 @@ public class ZLMHttpHookListener { | ||
| 124 | @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8") | 124 | @PostMapping(value = "/on_server_keepalive", produces = "application/json;charset=UTF-8") |
| 125 | public HookResult onServerKeepalive(@RequestBody OnServerKeepaliveHookParam param) { | 125 | public HookResult onServerKeepalive(@RequestBody OnServerKeepaliveHookParam param) { |
| 126 | 126 | ||
| 127 | -// logger.info("[ZLM HOOK] 收到zlm心跳:" + param.getMediaServerId()); | ||
| 128 | 127 | ||
| 129 | taskExecutor.execute(() -> { | 128 | taskExecutor.execute(() -> { |
| 130 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive); | 129 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_keepalive); |
| 131 | - JSONObject json = (JSONObject) JSON.toJSON(param); | ||
| 132 | if (subscribes != null && subscribes.size() > 0) { | 130 | if (subscribes != null && subscribes.size() > 0) { |
| 133 | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { | 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,7 +156,7 @@ public class ZLMHttpHookListener { | ||
| 158 | if (subscribe != null) { | 156 | if (subscribe != null) { |
| 159 | MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); | 157 | MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); |
| 160 | if (mediaInfo != null) { | 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,7 +232,7 @@ public class ZLMHttpHookListener { | ||
| 234 | ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json); | 232 | ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json); |
| 235 | if (subscribe != null) { | 233 | if (subscribe != null) { |
| 236 | if (mediaInfo != null) { | 234 | if (mediaInfo != null) { |
| 237 | - subscribe.response(mediaInfo, json); | 235 | + subscribe.response(mediaInfo, param); |
| 238 | } else { | 236 | } else { |
| 239 | new HookResultForOnPublish(1, "zlm not register"); | 237 | new HookResultForOnPublish(1, "zlm not register"); |
| 240 | } | 238 | } |
| @@ -306,7 +304,7 @@ public class ZLMHttpHookListener { | @@ -306,7 +304,7 @@ public class ZLMHttpHookListener { | ||
| 306 | return; | 304 | return; |
| 307 | } | 305 | } |
| 308 | if (subscribe != null) { | 306 | if (subscribe != null) { |
| 309 | - subscribe.response(mediaInfo, json); | 307 | + subscribe.response(mediaInfo, param); |
| 310 | } | 308 | } |
| 311 | 309 | ||
| 312 | List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks(); | 310 | List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks(); |
| @@ -649,7 +647,7 @@ public class ZLMHttpHookListener { | @@ -649,7 +647,7 @@ public class ZLMHttpHookListener { | ||
| 649 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_started); | 647 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_server_started); |
| 650 | if (subscribes != null && subscribes.size() > 0) { | 648 | if (subscribes != null && subscribes.size() > 0) { |
| 651 | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { | 649 | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { |
| 652 | - subscribe.response(null, jsonObject); | 650 | + subscribe.response(null, zlmServerConfig); |
| 653 | } | 651 | } |
| 654 | } | 652 | } |
| 655 | mediaServerService.zlmServerOnline(zlmServerConfig); | 653 | mediaServerService.zlmServerOnline(zlmServerConfig); |
| @@ -704,7 +702,7 @@ public class ZLMHttpHookListener { | @@ -704,7 +702,7 @@ public class ZLMHttpHookListener { | ||
| 704 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_rtp_server_timeout); | 702 | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_rtp_server_timeout); |
| 705 | if (subscribes != null && subscribes.size() > 0) { | 703 | if (subscribes != null && subscribes.size() > 0) { |
| 706 | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) { | 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,6 +270,11 @@ public class ZLMRESTfulUtils { | ||
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | public JSONObject openRtpServer(MediaServerItem mediaServerItem, Map<String, Object> param){ | 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 | return sendPost(mediaServerItem, "openRtpServer",param, null); | 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,6 +9,8 @@ import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; | ||
| 9 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; | 9 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 10 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout; | 10 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout; |
| 11 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 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 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; | 15 | import org.slf4j.LoggerFactory; |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -225,7 +227,8 @@ public class ZLMRTPServerFactory { | @@ -225,7 +227,8 @@ public class ZLMRTPServerFactory { | ||
| 225 | int localPort = 0; | 227 | int localPort = 0; |
| 226 | if (userSetting.getGbSendStreamStrict()) { | 228 | if (userSetting.getGbSendStreamStrict()) { |
| 227 | if (userSetting.getGbSendStreamStrict()) { | 229 | if (userSetting.getGbSendStreamStrict()) { |
| 228 | - localPort = keepPort(serverItem, ssrc); | 230 | + System.out.println("createSendRtpItem1"); |
| 231 | + localPort = keepPort(serverItem, ssrc, localPort); | ||
| 229 | if (localPort == 0) { | 232 | if (localPort == 0) { |
| 230 | return null; | 233 | return null; |
| 231 | } | 234 | } |
| @@ -261,7 +264,8 @@ public class ZLMRTPServerFactory { | @@ -261,7 +264,8 @@ public class ZLMRTPServerFactory { | ||
| 261 | // 默认为随机端口 | 264 | // 默认为随机端口 |
| 262 | int localPort = 0; | 265 | int localPort = 0; |
| 263 | if (userSetting.getGbSendStreamStrict()) { | 266 | if (userSetting.getGbSendStreamStrict()) { |
| 264 | - localPort = keepPort(serverItem, ssrc); | 267 | + System.out.println("createSendRtpItem2"); |
| 268 | + localPort = keepPort(serverItem, ssrc, localPort); | ||
| 265 | if (localPort == 0) { | 269 | if (localPort == 0) { |
| 266 | return null; | 270 | return null; |
| 267 | } | 271 | } |
| @@ -285,30 +289,37 @@ public class ZLMRTPServerFactory { | @@ -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 | Map<String, Object> param = new HashMap<>(3); | 293 | Map<String, Object> param = new HashMap<>(3); |
| 291 | - param.put("port", 0); | 294 | + param.put("port", localPort); |
| 292 | param.put("enable_tcp", 1); | 295 | param.put("enable_tcp", 1); |
| 293 | param.put("stream_id", ssrc); | 296 | param.put("stream_id", ssrc); |
| 297 | + System.out.println("用于收流"); | ||
| 294 | JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param); | 298 | JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param); |
| 299 | + System.out.println(jsonObject); | ||
| 295 | if (jsonObject.getInteger("code") == 0) { | 300 | if (jsonObject.getInteger("code") == 0) { |
| 296 | localPort = jsonObject.getInteger("port"); | 301 | localPort = jsonObject.getInteger("port"); |
| 297 | HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId()); | 302 | HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId()); |
| 303 | + Integer finalLocalPort = localPort; | ||
| 298 | hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout, | 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 | if (port == 0) { | 312 | if (port == 0) { |
| 303 | logger.info("[上级点播] {}->监听端口失败,移除监听", ssrc); | 313 | logger.info("[上级点播] {}->监听端口失败,移除监听", ssrc); |
| 304 | hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout); | 314 | hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout); |
| 305 | } | 315 | } |
| 306 | }); | 316 | }); |
| 307 | logger.info("[上级点播] {}->监听端口: {}", ssrc, localPort); | 317 | logger.info("[上级点播] {}->监听端口: {}", ssrc, localPort); |
| 318 | + return localPort; | ||
| 308 | }else { | 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,8 +65,8 @@ public class ZLMRunner implements CommandLineRunner { | ||
| 65 | HookSubscribeForServerStarted hookSubscribeForServerStarted = HookSubscribeFactory.on_server_started(); | 65 | HookSubscribeForServerStarted hookSubscribeForServerStarted = HookSubscribeFactory.on_server_started(); |
| 66 | // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 | 66 | // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 |
| 67 | hookSubscribe.addSubscribe(hookSubscribeForServerStarted, | 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 | if (zlmServerConfig !=null ) { | 70 | if (zlmServerConfig !=null ) { |
| 71 | if (startGetMedia != null) { | 71 | if (startGetMedia != null) { |
| 72 | startGetMedia.remove(zlmServerConfig.getGeneralMediaServerId()); | 72 | startGetMedia.remove(zlmServerConfig.getGeneralMediaServerId()); |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMServerConfig.java
| 1 | package com.genersoft.iot.vmp.media.zlm; | 1 | package com.genersoft.iot.vmp.media.zlm; |
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson2.annotation.JSONField; | 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 | @JSONField(name = "api.apiDebug") | 8 | @JSONField(name = "api.apiDebug") |
| 8 | private String apiDebug; | 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,6 +4,7 @@ import com.alibaba.fastjson2.JSONObject; | ||
| 4 | import com.genersoft.iot.vmp.media.zlm.dto.HookType; | 4 | import com.genersoft.iot.vmp.media.zlm.dto.HookType; |
| 5 | import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe; | 5 | import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe; |
| 6 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 6 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 7 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; | ||
| 7 | import org.slf4j.Logger; | 8 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; | 9 | import org.slf4j.LoggerFactory; |
| 9 | import org.springframework.scheduling.annotation.Scheduled; | 10 | import org.springframework.scheduling.annotation.Scheduled; |
| @@ -26,7 +27,7 @@ public class ZlmHttpHookSubscribe { | @@ -26,7 +27,7 @@ public class ZlmHttpHookSubscribe { | ||
| 26 | 27 | ||
| 27 | @FunctionalInterface | 28 | @FunctionalInterface |
| 28 | public interface Event{ | 29 | public interface Event{ |
| 29 | - void response(MediaServerItem mediaServerItem, JSONObject response); | 30 | + void response(MediaServerItem mediaServerItem, HookParam hookParam); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | private Map<HookType, Map<IHookSubscribe, ZlmHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>(); | 33 | private Map<HookType, Map<IHookSubscribe, ZlmHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>(); |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/HookResultForOnPublish.java
| @@ -50,4 +50,6 @@ public class HookResultForOnPublish extends HookResult{ | @@ -50,4 +50,6 @@ public class HookResultForOnPublish extends HookResult{ | ||
| 50 | public void setMp4_save_path(String mp4_save_path) { | 50 | public void setMp4_save_path(String mp4_save_path) { |
| 51 | this.mp4_save_path = mp4_save_path; | 51 | this.mp4_save_path = mp4_save_path; |
| 52 | } | 52 | } |
| 53 | + | ||
| 54 | + | ||
| 53 | } | 55 | } |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/hook/OnPlayHookParam.java
| @@ -81,6 +81,15 @@ public class OnPlayHookParam extends HookParam{ | @@ -81,6 +81,15 @@ public class OnPlayHookParam extends HookParam{ | ||
| 81 | 81 | ||
| 82 | @Override | 82 | @Override |
| 83 | public String toString() { | 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,6 +81,15 @@ public class OnPublishHookParam extends HookParam{ | ||
| 81 | 81 | ||
| 82 | @Override | 82 | @Override |
| 83 | public String toString() { | 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,4 +50,15 @@ public class OnRtpServerTimeoutHookParam extends HookParam{ | ||
| 50 | public void setSsrc(String ssrc) { | 50 | public void setSsrc(String ssrc) { |
| 51 | this.ssrc = ssrc; | 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,4 +24,12 @@ public class OnSendRtpStoppedHookParam extends HookParam{ | ||
| 24 | public void setStream(String stream) { | 24 | public void setStream(String stream) { |
| 25 | this.stream = stream; | 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,4 +17,11 @@ public class OnServerKeepaliveHookParam extends HookParam{ | ||
| 17 | public void setData(ServerKeepaliveData data) { | 17 | public void setData(ServerKeepaliveData data) { |
| 18 | this.data = data; | 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,4 +430,14 @@ public class OnStreamChangedHookParam extends HookParam{ | ||
| 430 | public void setCallId(String callId) { | 430 | public void setCallId(String callId) { |
| 431 | this.callId = callId; | 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,4 +38,14 @@ public class OnStreamNoneReaderHookParam extends HookParam{ | ||
| 38 | public void setVhost(String vhost) { | 38 | public void setVhost(String vhost) { |
| 39 | this.vhost = vhost; | 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,6 +81,15 @@ public class OnStreamNotFoundHookParam extends HookParam{ | ||
| 81 | 81 | ||
| 82 | @Override | 82 | @Override |
| 83 | public String toString() { | 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 | package com.genersoft.iot.vmp.service.impl; | 1 | package com.genersoft.iot.vmp.service.impl; |
| 2 | 2 | ||
| 3 | -import com.alibaba.fastjson2.JSONArray; | ||
| 4 | import com.alibaba.fastjson2.JSONObject; | 3 | import com.alibaba.fastjson2.JSONObject; |
| 5 | import com.genersoft.iot.vmp.common.InviteInfo; | 4 | import com.genersoft.iot.vmp.common.InviteInfo; |
| 6 | import com.genersoft.iot.vmp.common.InviteSessionStatus; | 5 | import com.genersoft.iot.vmp.common.InviteSessionStatus; |
| @@ -25,6 +24,8 @@ import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | @@ -25,6 +24,8 @@ import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; | ||
| 25 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; | 24 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 26 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; | 25 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| 27 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 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 | import com.genersoft.iot.vmp.service.*; | 29 | import com.genersoft.iot.vmp.service.*; |
| 29 | import com.genersoft.iot.vmp.service.bean.ErrorCallback; | 30 | import com.genersoft.iot.vmp.service.bean.ErrorCallback; |
| 30 | import com.genersoft.iot.vmp.service.bean.InviteErrorCode; | 31 | import com.genersoft.iot.vmp.service.bean.InviteErrorCode; |
| @@ -321,11 +322,11 @@ public class PlayServiceImpl implements IPlayService { | @@ -321,11 +322,11 @@ public class PlayServiceImpl implements IPlayService { | ||
| 321 | }, userSetting.getPlayTimeout()); | 322 | }, userSetting.getPlayTimeout()); |
| 322 | 323 | ||
| 323 | try { | 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 | dynamicTask.stop(timeOutTaskKey); | 327 | dynamicTask.stop(timeOutTaskKey); |
| 327 | // hook响应 | 328 | // hook响应 |
| 328 | - StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInuse, response, device.getDeviceId(), channelId,isSubStream); | 329 | + StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInuse, hookParam, device.getDeviceId(), channelId,isSubStream); |
| 329 | if (streamInfo == null){ | 330 | if (streamInfo == null){ |
| 330 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), | 331 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| 331 | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); | 332 | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); |
| @@ -438,11 +439,11 @@ public class PlayServiceImpl implements IPlayService { | @@ -438,11 +439,11 @@ public class PlayServiceImpl implements IPlayService { | ||
| 438 | String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase(); | 439 | String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase(); |
| 439 | hookSubscribe.getContent().put("stream", stream); | 440 | hookSubscribe.getContent().put("stream", stream); |
| 440 | inviteInfo.setStream(stream); | 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 | dynamicTask.stop(timeOutTaskKey); | 444 | dynamicTask.stop(timeOutTaskKey); |
| 444 | // hook响应 | 445 | // hook响应 |
| 445 | - StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInUse, response, device.getDeviceId(), channelId,isSubStream); | 446 | + StreamInfo streamInfo = onPublishHandlerForPlay(mediaServerItemInUse, hookParam, device.getDeviceId(), channelId,isSubStream); |
| 446 | if (streamInfo == null){ | 447 | if (streamInfo == null){ |
| 447 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), | 448 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| 448 | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); | 449 | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); |
| @@ -568,13 +569,14 @@ public class PlayServiceImpl implements IPlayService { | @@ -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 | StreamInfo streamInfo = null; | 573 | StreamInfo streamInfo = null; |
| 573 | Device device = redisCatchStorage.getDevice(deviceId); | 574 | Device device = redisCatchStorage.getDevice(deviceId); |
| 575 | + OnStreamChangedHookParam streamChangedHookParam = (OnStreamChangedHookParam)hookParam; | ||
| 574 | if( device.isSwitchPrimarySubStream() ){ | 576 | if( device.isSwitchPrimarySubStream() ){ |
| 575 | - streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId,isSubStream); | 577 | + streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId,isSubStream); |
| 576 | }else { | 578 | }else { |
| 577 | - streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId); | 579 | + streamInfo = onPublishHandler(mediaServerItem, streamChangedHookParam, deviceId, channelId); |
| 578 | } | 580 | } |
| 579 | if (streamInfo != null) { | 581 | if (streamInfo != null) { |
| 580 | InviteInfo inviteInfo; | 582 | InviteInfo inviteInfo; |
| @@ -603,9 +605,9 @@ public class PlayServiceImpl implements IPlayService { | @@ -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 | if (streamInfo != null) { | 611 | if (streamInfo != null) { |
| 610 | streamInfo.setStartTime(startTime); | 612 | streamInfo.setStartTime(startTime); |
| 611 | streamInfo.setEndTime(endTime); | 613 | streamInfo.setEndTime(endTime); |
| @@ -724,10 +726,10 @@ public class PlayServiceImpl implements IPlayService { | @@ -724,10 +726,10 @@ public class PlayServiceImpl implements IPlayService { | ||
| 724 | inviteStreamService.removeInviteInfo(inviteInfo); | 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 | dynamicTask.stop(playBackTimeOutTaskKey); | 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 | if (streamInfo == null) { | 733 | if (streamInfo == null) { |
| 732 | logger.warn("设备回放API调用失败!"); | 734 | logger.warn("设备回放API调用失败!"); |
| 733 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), | 735 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| @@ -804,11 +806,11 @@ public class PlayServiceImpl implements IPlayService { | @@ -804,11 +806,11 @@ public class PlayServiceImpl implements IPlayService { | ||
| 804 | String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase(); | 806 | String stream = String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase(); |
| 805 | hookSubscribe.getContent().put("stream", stream); | 807 | hookSubscribe.getContent().put("stream", stream); |
| 806 | inviteInfo.setStream(stream); | 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 | dynamicTask.stop(playBackTimeOutTaskKey); | 811 | dynamicTask.stop(playBackTimeOutTaskKey); |
| 810 | // hook响应 | 812 | // hook响应 |
| 811 | - hookEvent.response(mediaServerItemInUse, response); | 813 | + hookEvent.response(mediaServerItemInUse, hookParam); |
| 812 | }); | 814 | }); |
| 813 | } | 815 | } |
| 814 | // 更新ssrc | 816 | // 更新ssrc |
| @@ -920,10 +922,10 @@ public class PlayServiceImpl implements IPlayService { | @@ -920,10 +922,10 @@ public class PlayServiceImpl implements IPlayService { | ||
| 920 | streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); | 922 | streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); |
| 921 | inviteStreamService.removeInviteInfo(inviteInfo); | 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 | dynamicTask.stop(downLoadTimeOutTaskKey); | 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 | if (streamInfo == null) { | 929 | if (streamInfo == null) { |
| 928 | logger.warn("[录像下载] 获取流地址信息失败"); | 930 | logger.warn("[录像下载] 获取流地址信息失败"); |
| 929 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), | 931 | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| @@ -997,10 +999,10 @@ public class PlayServiceImpl implements IPlayService { | @@ -997,10 +999,10 @@ public class PlayServiceImpl implements IPlayService { | ||
| 997 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId()); | 999 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId()); |
| 998 | subscribe.removeSubscribe(hookSubscribe); | 1000 | subscribe.removeSubscribe(hookSubscribe); |
| 999 | hookSubscribe.getContent().put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase()); | 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 | dynamicTask.stop(downLoadTimeOutTaskKey); | 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,8 +1092,9 @@ public class PlayServiceImpl implements IPlayService { | ||
| 1090 | return null; | 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 | if (streamInfo != null) { | 1098 | if (streamInfo != null) { |
| 1096 | streamInfo.setProgress(0); | 1099 | streamInfo.setProgress(0); |
| 1097 | streamInfo.setStartTime(startTime); | 1100 | streamInfo.setStartTime(startTime); |
| @@ -1108,10 +1111,8 @@ public class PlayServiceImpl implements IPlayService { | @@ -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 | streamInfo.setDeviceID(deviceId); | 1116 | streamInfo.setDeviceID(deviceId); |
| 1116 | streamInfo.setChannelId(channelId); | 1117 | streamInfo.setChannelId(channelId); |
| 1117 | return streamInfo; | 1118 | return streamInfo; |
| @@ -1307,9 +1308,9 @@ public class PlayServiceImpl implements IPlayService { | @@ -1307,9 +1308,9 @@ public class PlayServiceImpl implements IPlayService { | ||
| 1307 | 1308 | ||
| 1308 | 1309 | ||
| 1309 | /*======================设备主子码流逻辑START=========================*/ | 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 | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "rtp", streamId, tracks, null); | 1314 | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "rtp", streamId, tracks, null); |
| 1314 | streamInfo.setDeviceID(deviceId); | 1315 | streamInfo.setDeviceID(deviceId); |
| 1315 | streamInfo.setChannelId(channelId); | 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,7 +289,7 @@ public class RedisGbPlayMsgListener implements MessageListener { | ||
| 289 | // 添加订阅 | 289 | // 添加订阅 |
| 290 | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed(content.getApp(), content.getStream(), true, "rtsp", mediaServerItem.getId()); | 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 | dynamicTask.stop(taskKey); | 293 | dynamicTask.stop(taskKey); |
| 294 | responseSendItem(mediaServerItem, content, toId, serial); | 294 | responseSendItem(mediaServerItem, content, toId, serial); |
| 295 | }); | 295 | }); |
src/main/resources/application.yml