From a7b7371e7406cd8e3a40c20a5aee045218da4186 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Wed, 3 Apr 2024 18:00:48 +0800 Subject: [PATCH] =?UTF-8?q?1078-=E5=A2=9E=E5=8A=A0=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E7=82=B9=E6=92=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmp/jt1078/config/JT1078Controller.java | 35 ++++++++++++++----- .../service/impl/jt1078ServiceImpl.java | 24 ++++++++++++- .../iot/vmp/service/bean/InviteErrorCode.java | 4 ++- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/config/JT1078Controller.java b/src/main/java/com/genersoft/iot/vmp/jt1078/config/JT1078Controller.java index 9f0621ecd..4d9010149 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/config/JT1078Controller.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/config/JT1078Controller.java @@ -22,6 +22,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; @@ -51,21 +52,26 @@ public class JT1078Controller { @Autowired UserSetting userSetting; - /** - * jt1078Template 调用示例 - */ - @GetMapping("/start/live/{deviceId}/{channelId}") - public DeferredResult> startLive(HttpServletRequest request, @PathVariable String deviceId, @PathVariable String channelId) { + @Operation(summary = "1078-开始点播", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "deviceId", description = "设备国标编号", required = true) + @Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true) + @GetMapping("/live/start") + public DeferredResult> startLive(HttpServletRequest request, + @Parameter(required = true) String deviceId, + @Parameter(required = false) String channelId) { DeferredResult> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); - + if (ObjectUtils.isEmpty(channelId)) { + channelId = "1"; + } + String finalChannelId = channelId; result.onTimeout(()->{ - logger.info("[1078-点播等待超时] deviceId:{}, channelId:{}, ", deviceId, channelId); + logger.info("[1078-点播等待超时] deviceId:{}, channelId:{}, ", deviceId, finalChannelId); // 释放rtpserver WVPResult wvpResult = new WVPResult<>(); wvpResult.setCode(ErrorCode.ERROR100.getCode()); wvpResult.setMsg("点播超时"); result.setResult(wvpResult); - service.stopPlay(deviceId, channelId); + service.stopPlay(deviceId, finalChannelId); }); service.play(deviceId, channelId, (code, msg, streamInfo) -> { @@ -101,6 +107,19 @@ public class JT1078Controller { return result; } + @Operation(summary = "1078-结束点播", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "deviceId", description = "设备国标编号", required = true) + @Parameter(name = "channelId", description = "通道国标编号, 一般为从1开始的数字", required = true) + @GetMapping("/live/stop") + public void stopLive(HttpServletRequest request, + @Parameter(required = true) String deviceId, + @Parameter(required = false) String channelId) { + if (ObjectUtils.isEmpty(channelId)) { + channelId = "1"; + } + service.stopPlay(deviceId, channelId); + } + @Operation(summary = "分页查询部标设备", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "page", description = "当前页", required = true) @Parameter(name = "count", description = "每页查询数量", required = true) diff --git a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java index 45e47767c..af87e01b7 100644 --- a/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/jt1078/service/impl/jt1078ServiceImpl.java @@ -12,6 +12,7 @@ import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template; import com.genersoft.iot.vmp.jt1078.config.JT1078Controller; import com.genersoft.iot.vmp.jt1078.dao.JTDeviceMapper; import com.genersoft.iot.vmp.jt1078.proc.response.J9101; +import com.genersoft.iot.vmp.jt1078.proc.response.J9102; import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; @@ -194,6 +195,27 @@ public class jt1078ServiceImpl implements Ijt1078Service { @Override public void stopPlay(String deviceId, String channelId) { - + String playKey = VideoManagerConstants.INVITE_INFO_1078 + deviceId + ":" + channelId; + dynamicTask.stop(playKey); + StreamInfo streamInfo = (StreamInfo) redisTemplate.opsForValue().get(playKey); + // 发送停止命令 + J9102 j9102 = new J9102(); + j9102.setChannel(Integer.valueOf(channelId)); + j9102.setCommand(0); + j9102.setCloseType(0); + j9102.setStreamType(1); + jt1078Template.stopLive(deviceId, j9102, 6); + // 删除缓存数据 + if (streamInfo != null) { + // 关闭rtpServer + mediaServerService.closeRTPServer(streamInfo.getMediaServerId(), streamInfo.getStream()); + } + // 清理回调 + List> generalCallbacks = inviteErrorCallbackMap.get(playKey); + if (!generalCallbacks.isEmpty()) { + for (GeneralCallback callback : generalCallbacks) { + callback.run(InviteErrorCode.ERROR_FOR_FINISH.getCode(), InviteErrorCode.ERROR_FOR_FINISH.getMsg(), null); + } + } } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java b/src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java index d43792e79..da6117495 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java +++ b/src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java @@ -17,7 +17,9 @@ public enum InviteErrorCode { ERROR_FOR_RESET_SSRC(-9, "重新设置收流信息失败"), ERROR_FOR_SIP_SENDING_FAILED(-10, "命令发送失败"), ERROR_FOR_ASSIST_NOT_READY(-11, "没有可用的assist服务"), - ERROR_FOR_PARAMETER_ERROR(-13, "参数异常"); + ERROR_FOR_PARAMETER_ERROR(-13, "参数异常"), + ERROR_FOR_FINISH(-14, "已结束"), + ; private final int code; private final String msg;