| | |
| | | import com.ard.gb28181.api.RemoteGb28181Service; |
| | | import com.ard.gb28181.api.domain.Device; |
| | | import com.ard.gb28181.api.domain.DeviceChannel; |
| | | import com.ard.gb28181.api.domain.GbChannelDTO; |
| | | import com.ard.qs.api.RemoteQsDeviceService; |
| | | import com.ard.qs.api.domain.QsDevice; |
| | | import com.ard.work.api.RemoteCameraService; |
| | |
| | | * @param id 设备id |
| | | * @return |
| | | */ |
| | | @Operation(summary = "gb28181播放") |
| | | @GetMapping("/startGb28181Play/{id}") |
| | | public DeferredResult<R<StreamContent>> startGb28181Play( |
| | | HttpServletRequest request, |
| | |
| | | return AjaxResult.success(json); |
| | | } |
| | | |
| | | /** |
| | | * gb28181 播放(基于GbDevice,不依赖QS,按国标编码播放) |
| | | * |
| | | * @param request |
| | | * @param gbDeviceId 国标设备编码 |
| | | * @param gbChannelId 国标通道编码 |
| | | * @return |
| | | */ |
| | | @Operation(summary = "gb28181播放(按国标编码)") |
| | | @GetMapping("/startGb28181PlayByGbDeviceId/{gbDeviceId}/{gbChannelId}") |
| | | public DeferredResult<R<StreamContent>> startGb28181PlayByGbDeviceId( |
| | | HttpServletRequest request, |
| | | @PathVariable String gbDeviceId, |
| | | @PathVariable String gbChannelId |
| | | ) { |
| | | log.info("[gb28181 开始点播] gbDeviceId:{}, gbChannelId:{}", gbDeviceId, gbChannelId); |
| | | Assert.hasText(gbDeviceId, "国标设备编码不可为空"); |
| | | Assert.hasText(gbChannelId, "国标通道编码不可为空"); |
| | | |
| | | // 1. 查询 GbChannel 配置 |
| | | R<GbChannelDTO> channelR = remoteGb28181Service.getGbChannel(gbDeviceId, gbChannelId, SecurityConstants.INNER); |
| | | if (channelR.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("获取GbChannel配置失败 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId |
| | | + "。设备注册后会自动创建,请确认设备已上线并完成目录同步。"); |
| | | } |
| | | Assert.notNull(channelR.getData(), "GbChannel不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId); |
| | | |
| | | GbChannelDTO gbChannelDTO = channelR.getData(); |
| | | |
| | | // 2. 查询国标设备 |
| | | R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(gbDeviceId, SecurityConstants.INNER); |
| | | if (deviceR.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("gb28181 获取设备信息失败 deviceId:" + gbDeviceId); |
| | | } |
| | | Assert.notNull(deviceR.getData(), "gb28181 国标设备不存在 deviceId:" + gbDeviceId); |
| | | |
| | | if (!deviceR.getData().isOnLine()) { |
| | | throw new RuntimeException("gb28181 国标设备不在线 deviceId:" + gbDeviceId); |
| | | } |
| | | |
| | | // 3. 查询国标通道 |
| | | R<DeviceChannel> deviceChannelR = remoteGb28181Service.getDeviceChannelByChannelId(gbDeviceId, gbChannelId, SecurityConstants.INNER); |
| | | if (deviceChannelR.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("gb28181 获取设备通道失败 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId); |
| | | } |
| | | Assert.notNull(deviceChannelR.getData(), "gb28181 国标设备通道不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId); |
| | | |
| | | if (!"ON".equals(deviceChannelR.getData().getStatus())) { |
| | | throw new RuntimeException("gb28181 国标设备通道不在线 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId); |
| | | } |
| | | |
| | | DeferredResult<R<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); |
| | | |
| | | result.onTimeout(() -> { |
| | | log.info("[点播等待超时] gbDeviceId:{}, gbChannelId:{}", gbDeviceId, gbChannelId); |
| | | R<StreamContent> fail = R.fail(); |
| | | fail.setMsg("点播超时"); |
| | | result.setResult(fail); |
| | | |
| | | inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, gbChannelDTO.getId()); |
| | | mediaServerService.stopGb28181PlayByGbChannel(InviteSessionType.PLAY, gbChannelDTO, deviceR.getData(), gbChannelDTO.getDeviceCode()); |
| | | }); |
| | | |
| | | ErrorCallback<StreamInfo> callback = (code, msg, streamInfo) -> { |
| | | if (code == InviteErrorCode.SUCCESS.getCode()) { |
| | | R<StreamContent> r = R.ok(); |
| | | if (streamInfo != null) { |
| | | if (userSetting.getUseSourceIpAsStreamIp()) { |
| | | streamInfo = streamInfo.clone(); |
| | | String host; |
| | | try { |
| | | URL url = new URL(request.getRequestURL().toString()); |
| | | host = url.getHost(); |
| | | } catch (MalformedURLException e) { |
| | | host = request.getLocalAddr(); |
| | | } |
| | | streamInfo.changeStreamIp(host); |
| | | } |
| | | if (!ObjectUtils.isEmpty(streamInfo.getMediaServer().getTranscodeSuffix()) |
| | | && !"null".equalsIgnoreCase(streamInfo.getMediaServer().getTranscodeSuffix())) { |
| | | streamInfo.setStream(streamInfo.getStream() + "_" + streamInfo.getMediaServer().getTranscodeSuffix()); |
| | | } |
| | | r.setData(new StreamContent(streamInfo)); |
| | | } else { |
| | | r.setCode(code); |
| | | r.setMsg(msg); |
| | | } |
| | | result.setResult(r); |
| | | } else { |
| | | result.setResult(R.fail(code, msg)); |
| | | } |
| | | }; |
| | | |
| | | mediaServerService.startGb28181PlayByGbChannel(gbChannelDTO, deviceR.getData(), callback); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * gb28181 停止点播(基于GbDevice,不依赖QS,按国标编码停止) |
| | | * |
| | | * @param gbDeviceId 国标设备编码 |
| | | * @param gbChannelId 国标通道编码 |
| | | * @return |
| | | */ |
| | | @Operation(summary = "gb28181停止点播(按国标编码)") |
| | | @GetMapping("/stopGb28181PlayByGbDeviceId/{gbDeviceId}/{gbChannelId}") |
| | | public AjaxResult stopGb28181PlayByGbDeviceId( |
| | | @PathVariable String gbDeviceId, |
| | | @PathVariable String gbChannelId |
| | | ) { |
| | | log.info("[gb28181 停止点播] gbDeviceId:{}, gbChannelId:{}", gbDeviceId, gbChannelId); |
| | | Assert.hasText(gbDeviceId, "国标设备编码不可为空"); |
| | | Assert.hasText(gbChannelId, "国标通道编码不可为空"); |
| | | |
| | | // 1. 查询 GbChannel 配置 |
| | | R<GbChannelDTO> channelR = remoteGb28181Service.getGbChannel(gbDeviceId, gbChannelId, SecurityConstants.INNER); |
| | | if (channelR.getCode() != Constants.SUCCESS || channelR.getData() == null) { |
| | | throw new RuntimeException("GbChannel不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId); |
| | | } |
| | | |
| | | GbChannelDTO gbChannelDTO = channelR.getData(); |
| | | |
| | | // 2. 查询国标设备 |
| | | R<Device> deviceR = remoteGb28181Service.getDeviceByDeviceId(gbDeviceId, SecurityConstants.INNER); |
| | | if (deviceR.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("gb28181 获取设备信息失败 deviceId:" + gbDeviceId); |
| | | } |
| | | Assert.notNull(deviceR.getData(), "gb28181 国标设备不存在 deviceId:" + gbDeviceId); |
| | | |
| | | // 3. 查询国标通道 |
| | | R<DeviceChannel> deviceChannelR = remoteGb28181Service.getDeviceChannelByChannelId(gbDeviceId, gbChannelId, SecurityConstants.INNER); |
| | | if (deviceChannelR.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("gb28181 获取设备通道失败 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId); |
| | | } |
| | | Assert.notNull(deviceChannelR.getData(), "gb28181 国标设备通道不存在 gbDeviceId:" + gbDeviceId + " gbChannelId:" + gbChannelId); |
| | | |
| | | mediaServerService.stopGb28181PlayByGbChannel(InviteSessionType.PLAY, gbChannelDTO, |
| | | deviceR.getData(), gbChannelDTO.getDeviceCode()); |
| | | |
| | | JSONObject json = new JSONObject(); |
| | | json.put("gbDeviceId", gbDeviceId); |
| | | json.put("gbChannelId", gbChannelId); |
| | | return AjaxResult.success(json); |
| | | } |
| | | |
| | | } |