diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SsrcTransaction.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SsrcTransaction.java index 9f436abe..893db116 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SsrcTransaction.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SsrcTransaction.java @@ -7,16 +7,49 @@ import lombok.Data; @Data public class SsrcTransaction { + /** + * 设备编号 + */ private String deviceId; + + /** + * 上级平台的编号 + */ private String platformId; + + /** + * 通道的数据库ID + */ private Integer channelId; + + /** + * 会话的CALL ID + */ private String callId; + + /** + * 关联的流ID + */ private String stream; + + /** + * 使用的流媒体 + */ private String mediaServerId; + + /** + * 使用的SSRC + */ private String ssrc; + /** + * 事务信息 + */ private SipTransactionInfo sipTransactionInfo; + /** + * 类型 + */ private InviteSessionType type; public static SsrcTransaction buildForDevice(String deviceId, Integer channelId, String callId, String stream, diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GBRecordController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GBRecordController.java index 25440487..c68af889 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GBRecordController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/GBRecordController.java @@ -6,12 +6,13 @@ import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.gb28181.bean.Device; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.RecordInfo; +import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.gb28181.service.IDeviceService; -import com.genersoft.iot.vmp.gb28181.service.IInviteStreamService; import com.genersoft.iot.vmp.gb28181.service.IPlayService; import com.genersoft.iot.vmp.service.bean.InviteErrorCode; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; @@ -56,7 +57,7 @@ public class GBRecordController { private IPlayService playService; @Autowired - private IInviteStreamService inviteStreamService; + private IDeviceChannelService channelService; @Autowired private IDeviceService deviceService; @@ -140,8 +141,18 @@ public class GBRecordController { requestMessage.setId(uuid); requestMessage.setKey(key); + Device device = deviceService.getDeviceByDeviceId(deviceId); + if (device == null) { + log.warn("[开始历史媒体下载] 未找到设备 deviceId: {},channelId:{}", deviceId, channelId); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId); + } - playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), + DeviceChannel channel = channelService.getOne(deviceId, channelId); + if (channel == null) { + log.warn("[开始历史媒体下载] 未找到通道 deviceId: {},channelId:{}", deviceId, channelId); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到通道:" + channelId); + } + playService.download(device, channel, startTime, endTime, Integer.parseInt(downloadSpeed), (code, msg, data)->{ WVPResult wvpResult = new WVPResult<>(); @@ -201,7 +212,18 @@ public class GBRecordController { @Parameter(name = "stream", description = "流ID", required = true) @GetMapping("/download/progress/{deviceId}/{channelId}/{stream}") public StreamContent getProgress(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) { - StreamInfo downLoadInfo = playService.getDownLoadInfo(deviceId, channelId, stream); + Device device = deviceService.getDeviceByDeviceId(deviceId); + if (device == null) { + log.warn("[获取历史媒体下载进度] 未找到设备 deviceId: {},channelId:{}", deviceId, channelId); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId); + } + + DeviceChannel channel = channelService.getOne(deviceId, channelId); + if (channel == null) { + log.warn("[获取历史媒体下载进度] 未找到通道 deviceId: {},channelId:{}", deviceId, channelId); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到通道:" + channelId); + } + StreamInfo downLoadInfo = playService.getDownLoadInfo(device, channel, stream); if (downLoadInfo == null) { throw new ControllerException(ErrorCode.ERROR404); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java index cd3196ac..90222893 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java @@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.gb28181.bean.Device; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction; import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService; import com.genersoft.iot.vmp.gb28181.service.IDeviceService; @@ -87,6 +88,9 @@ public class PlayController { Assert.notNull(channelId, "通道国标编号不可为NULL"); // 获取可用的zlm Device device = deviceService.getDeviceByDeviceId(deviceId); + Assert.notNull(deviceId, "设备不存在"); + DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId); + Assert.notNull(channel, "通道不存在"); MediaServer newMediaServerItem = playService.getNewMediaServerItem(device); RequestMessage requestMessage = new RequestMessage(); @@ -104,8 +108,8 @@ public class PlayController { wvpResult.setMsg("点播超时"); requestMessage.setData(wvpResult); resultHolder.invokeAllResult(requestMessage); - inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId); - deviceChannelService.stopPlay(deviceId, channelId); + inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, channel.getId()); + deviceChannelService.stopPlay(channel.getId()); }); // 录像查询以channelId作为deviceId查询 @@ -161,11 +165,11 @@ public class PlayController { } Device device = deviceService.getDeviceByDeviceId(deviceId); - if (device == null) { - throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备[" + deviceId + "]不存在"); - } + DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId); + Assert.notNull(device, "设备不存在"); + Assert.notNull(channel, "通道不存在"); - playService.stopPlay(device, channelId); + playService.stopPlay(device, channel); JSONObject json = new JSONObject(); json.put("deviceId", deviceId); json.put("channelId", channelId); @@ -259,9 +263,8 @@ public class PlayController { @Operation(summary = "获取截图", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "deviceId", description = "设备国标编号", required = true) @Parameter(name = "channelId", description = "通道国标编号", required = true) - @Parameter(name = "isSubStream", description = "是否子码流(true-子码流,false-主码流),默认为false", required = true) @GetMapping("/snap") - public DeferredResult getSnap(String deviceId, String channelId,boolean isSubStream) { + public DeferredResult getSnap(String deviceId, String channelId) { if (log.isDebugEnabled()) { log.debug("获取截图: {}/{}", deviceId, channelId); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlaybackController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlaybackController.java index 756d9632..3485026c 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlaybackController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlaybackController.java @@ -9,6 +9,8 @@ import com.genersoft.iot.vmp.conf.exception.ServiceException; import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.gb28181.bean.Device; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.gb28181.service.IDeviceChannelService; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; @@ -71,6 +73,9 @@ public class PlaybackController { @Autowired private IDeviceService deviceService; + @Autowired + private IDeviceChannelService channelService; + @Operation(summary = "开始视频回放", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "deviceId", description = "设备国标编号", required = true) @Parameter(name = "channelId", description = "通道国标编号", required = true) @@ -92,8 +97,18 @@ public class PlaybackController { RequestMessage requestMessage = new RequestMessage(); requestMessage.setKey(key); requestMessage.setId(uuid); + Device device = deviceService.getDeviceByDeviceId(deviceId); + if (device == null) { + log.warn("[录像回放] 未找到设备 deviceId: {},channelId:{}", deviceId, channelId); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId); + } - playService.playBack(deviceId, channelId, startTime, endTime, + DeviceChannel channel = channelService.getOne(deviceId, channelId); + if (channel == null) { + log.warn("[录像回放] 未找到通道 deviceId: {},channelId:{}", deviceId, channelId); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到通道:" + channelId); + } + playService.playBack(device, channel, startTime, endTime, (code, msg, data)->{ WVPResult wvpResult = new WVPResult<>(); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java index 230a3c39..9c641d1c 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceChannelMapper.java @@ -316,8 +316,8 @@ public interface DeviceChannelMapper { @Update(value = {"UPDATE wvp_device_channel SET stream_id=null WHERE device_db_id=#{deviceId} AND device_id=#{channelId}"}) void stopPlay(@Param("deviceId") int deviceId, @Param("channelId") String channelId); - @Update(value = {"UPDATE wvp_device_channel SET stream_id=#{streamId} WHERE device_db_id=#{deviceId} AND device_id=#{channelId}"}) - void startPlay(@Param("deviceId") int deviceId, @Param("channelId") String channelId, @Param("streamId") String streamId); + @Update(value = {"UPDATE wvp_device_channel SET stream_id=#{streamId} WHERE id=#{channelId}"}) + void startPlay(@Param("channelId") Integer channelId, @Param("streamId") String streamId); @Select(value = {"