From 2bc284222483d0fb76b861ead4f462421274706d Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Thu, 4 May 2023 15:36:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BD=E6=A0=87=E7=82=B9?= =?UTF-8?q?=E6=92=AD=E4=B8=8B=E7=BA=A7=E5=B9=B3=E5=8F=B0=EF=BC=8Cssrc?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=9A=84=E6=97=B6=E5=9B=A0=E4=B8=BA=E6=97=A7?= =?UTF-8?q?=E7=9A=84=E7=AB=AF=E5=8F=A3=E9=87=8A=E6=94=BE=E6=85=A2=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=82=B9=E6=92=AD=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B4=E6=8E=A5=E6=9B=B4=E6=96=B0ssrc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/media/zlm/ZLMRESTfulUtils.java | 9 +++ .../vmp/media/zlm/ZLMRTPServerFactory.java | 15 ++++ .../iot/vmp/service/IMediaServerService.java | 1 + .../service/impl/MediaServerServiceImpl.java | 5 ++ .../iot/vmp/service/impl/PlayServiceImpl.java | 72 ++++++++++++------- 5 files changed, 76 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java index 13f32402..a2fd1e37 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java @@ -25,6 +25,8 @@ public class ZLMRESTfulUtils { private OkHttpClient client; + + public interface RequestCallback{ void run(JSONObject response); } @@ -354,4 +356,11 @@ public class ZLMRESTfulUtils { param.put("stream_id", stream_id); return sendPost(mediaServerItem, "connectRtpServer",param, null); } + + public JSONObject updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc) { + Map param = new HashMap<>(1); + param.put("ssrc", ssrc); + param.put("stream_id", streamId); + return sendPost(mediaServerItem, "updateRtpServerSSRC",param, null); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java index 99576c4a..f3e4d440 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java @@ -386,4 +386,19 @@ public class ZLMRTPServerFactory { public void closeAllSendRtpStream() { } + + public Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc) { + boolean result = false; + JSONObject jsonObject = zlmresTfulUtils.updateRtpServerSSRC(mediaServerItem, streamId, ssrc); + if (jsonObject == null) { + logger.error("[更新RTPServer] 失败: 请检查ZLM服务"); + } else if (jsonObject.getInteger("code") == 0) { + result= true; + logger.info("[更新RTPServer] 成功"); + } else { + logger.error("[更新RTPServer] 失败: {}, streamId:{},ssrc:{}->\r\n{}",jsonObject.getString("msg"), + streamId, ssrc, jsonObject); + } + return result; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java b/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java index 495b009e..530cd6df 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java @@ -50,6 +50,7 @@ public interface IMediaServerService { void closeRTPServer(MediaServerItem mediaServerItem, String streamId); void closeRTPServer(MediaServerItem mediaServerItem, String streamId, CommonCallback callback); + Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc); void closeRTPServer(String mediaServerId, String streamId); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index 94ed200f..c0d07650 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -180,6 +180,11 @@ public class MediaServerServiceImpl implements IMediaServerService { closeRTPServer(mediaServerItem, streamId); } + @Override + public Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc) { + return zlmrtpServerFactory.updateRtpServerSSRC(mediaServerItem, streamId, ssrc); + } + @Override public void releaseSsrc(String mediaServerItemId, String ssrc) { MediaServerItem mediaServerItem = getOne(mediaServerItemId); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 51574392..0347611c 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -143,7 +143,7 @@ public class PlayServiceImpl implements IPlayService { if (rtpInfo.getBoolean("exist")) { int localPort = rtpInfo.getInteger("local_port"); if (localPort == 0) { - logger.warn("[点播],点播时发现rtpServerC存在,但是尚未开始推流"); + logger.warn("[点播],点播时发现rtpServer存在,但是尚未开始推流"); // 此时说明rtpServer已经创建但是流还没有推上来 WVPResult wvpResult = new WVPResult(); wvpResult.setCode(ErrorCode.ERROR100.getCode()); @@ -228,7 +228,7 @@ public class PlayServiceImpl implements IPlayService { ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent, InviteTimeOutCallback timeoutCallback) { - logger.info("[点播开始] deviceId: {}, channelId: {},收流端口: {}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck()); + logger.info("[点播开始] deviceId: {}, channelId: {},收流端口:{}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck()); // 超时处理 String timeOutTaskKey = UUID.randomUUID().toString(); dynamicTask.startDelay(timeOutTaskKey, () -> { @@ -352,30 +352,50 @@ public class PlayServiceImpl implements IPlayService { hookEvent.response(mediaServerItemInUse, response); }); } - // 关闭rtp server - mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream(), result->{ - if (result) { - // 重新开启ssrc server - mediaServerService.openRTPServer(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse, device.isSsrcCheck(), false, ssrcInfo.getPort(), true, device.getStreamModeForParam()); - }else { - try { - logger.warn("[停止点播] {}/{}", device.getDeviceId(), channelId); - cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null); - } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) { - logger.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage()); - throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); - } - dynamicTask.stop(timeOutTaskKey); - // 释放ssrc - mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); - - streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); - event.msg = "下级自定义了ssrc,重新设置收流信息失败"; - event.statusCode = 500; - errorEvent.response(event); + Boolean result = mediaServerService.updateRtpServerSSRC(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse); + if (!result) { + try { + logger.warn("[停止点播] {}/{}", device.getDeviceId(), channelId); + cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null); + } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) { + logger.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage()); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); } - }); + + dynamicTask.stop(timeOutTaskKey); + // 释放ssrc + mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); + + streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); + event.msg = "下级自定义了ssrc,重新设置收流信息失败"; + event.statusCode = 500; + errorEvent.response(event); + } +// // 关闭rtp server +// mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream(), result->{ +// if (result) { +// // 重新开启ssrc server +// mediaServerService.openRTPServer(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse, device.isSsrcCheck(), false, ssrcInfo.getPort(), true, device.getStreamModeForParam()); +// }else { +// try { +// logger.warn("[停止点播] {}/{}", device.getDeviceId(), channelId); +// cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null); +// } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) { +// logger.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage()); +// throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); +// } +// +// dynamicTask.stop(timeOutTaskKey); +// // 释放ssrc +// mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); +// +// streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); +// event.msg = "下级自定义了ssrc,重新设置收流信息失败"; +// event.statusCode = 500; +// errorEvent.response(event); +// } +// }); } @@ -519,7 +539,7 @@ public class PlayServiceImpl implements IPlayService { if (device == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备: " + deviceId + "不存在"); } - logger.info("[回放消息] deviceId: {}, channelId: {},收流端口: {}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck()); + logger.info("[回放消息] deviceId: {}, channelId: {},收流端口:{}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck()); PlayBackResult playBackResult = new PlayBackResult<>(); String playBackTimeOutTaskKey = UUID.randomUUID().toString(); dynamicTask.startDelay(playBackTimeOutTaskKey, () -> { @@ -689,7 +709,7 @@ public class PlayServiceImpl implements IPlayService { throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + "不存在"); } PlayBackResult downloadResult = new PlayBackResult<>(); - logger.info("[录像下载] deviceId: {}, channelId: {},收流端口: {}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck()); + logger.info("[录像下载] deviceId: {}, channelId: {},收流端口:{}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck()); String downLoadTimeOutTaskKey = UUID.randomUUID().toString(); dynamicTask.startDelay(downLoadTimeOutTaskKey, () -> { logger.warn(String.format("录像下载请求超时,deviceId:%s ,channelId:%s", deviceId, channelId));