| | |
| | | import com.ard.common.core.utils.file.FileMultipartFile; |
| | | import com.ard.gb28181.api.RemoteGb28181Service; |
| | | import com.ard.gb28181.api.domain.Device; |
| | | import com.ard.gb28181.api.domain.GbChannelDTO; |
| | | import com.ard.qs.api.RemoteQsDeviceService; |
| | | import com.ard.qs.api.domain.QsDevice; |
| | | import com.ard.zlm.domain.StreamChannel; |
| | | import com.ard.zlm.service.ZlmStreamService; |
| | | import com.ard.zlm.domain.StreamChannel; |
| | | import com.ard.system.api.RemoteFileService; |
| | | import com.ard.system.api.domain.SysFile; |
| | | import com.ard.work.api.RemoteCameraService; |
| | |
| | | private HookSubscribe subscribe; |
| | | |
| | | @Resource |
| | | private RemoteQsDeviceService remoteQsDeviceService; |
| | | private ZlmStreamService zlmStreamService; |
| | | |
| | | @Resource |
| | | private RemoteChannelService remoteChannelService; |
| | |
| | | } |
| | | redisCatchStorage.updateStreamAuthorityInfo(event.getApp(), event.getStream(), streamAuthorityInfo); |
| | | |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceStream("pull_" + event.getApp() + "_" + event.getStream(), |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceStream("pull_" + event.getApp() + "_" + event.getStream(), |
| | | SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.error("获取设备信息失败,stream:{}", event.getStream()); |
| | |
| | | } |
| | | |
| | | if (r.getData() == null) { |
| | | r = remoteQsDeviceService.getQsDeviceStream(event.getStream(), SecurityConstants.INNER); |
| | | r = zlmStreamService.getQsDeviceStream(event.getStream(), SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.error("获取设备信息失败,stream:{}", event.getStream()); |
| | | return; |
| | |
| | | } |
| | | |
| | | if (r.getData() == null) { |
| | | QsDevice device = new QsDevice(); |
| | | device.setDeviceStatus("ON"); |
| | | StreamChannel device = new StreamChannel(); |
| | | device.setMediaServerId(mediaInfo.getMediaServer().getId()); |
| | | device.setDeviceName("推流设备_" + event.getApp() + "_" + event.getStream()); |
| | | device.setChannelName("推流设备_" + event.getApp() + "_" + event.getStream()); |
| | | device.setType(LiveStreamType.PUSH.getCode()); |
| | | device.setStatus("ENABLE"); |
| | | device.setStreamStatus("1"); |
| | |
| | | String filePath = snapOnPlay(mediaInfo.getMediaServer(), event.getApp(), event.getStream()); |
| | | device.setSnap(filePath); |
| | | |
| | | R<Boolean> addR = remoteQsDeviceService.addQsDevice(device, SecurityConstants.INNER); |
| | | R<Boolean> addR = zlmStreamService.addQsDevice(device, SecurityConstants.INNER); |
| | | if (addR.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("添加推流设备设备失败" + event.getApp() + "_" + event.getStream()); |
| | | } |
| | |
| | | throw new RuntimeException("添加推流设备设备失败" + event.getApp() + "_" + event.getStream()); |
| | | } |
| | | } else { |
| | | QsDevice device = new QsDevice(); |
| | | device.setDeviceStatus("ON"); |
| | | StreamChannel device = new StreamChannel(); |
| | | device.setMediaServerId(mediaInfo.getMediaServer().getId()); |
| | | device.setStreamKey(r.getData().getDeviceCode()); |
| | | device.setStreamStatus("1"); |
| | | device.setId(r.getData().getId()); |
| | | String filePath = snapOnPlay(mediaInfo.getMediaServer(), event.getApp(), event.getStream()); |
| | | device.setSnap(filePath); |
| | | R<Boolean> updateR = remoteQsDeviceService.updateQsDevice(device, SecurityConstants.INNER); |
| | | R<Boolean> updateR = zlmStreamService.updateQsDevice(device, SecurityConstants.INNER); |
| | | if (updateR.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("修改推流设备设备失败" + event.getApp() + "_" + event.getStream()); |
| | | } |
| | |
| | | if (inviteInfo != null && (inviteInfo.getType() == InviteSessionType.PLAY || inviteInfo.getType() == InviteSessionType.PLAYBACK)) { |
| | | inviteStreamService.removeInviteInfo(inviteInfo); |
| | | |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceInfo(Long.valueOf(inviteInfo.getDeviceId()), |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceInfo(Long.valueOf(inviteInfo.getDeviceId()), |
| | | SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | return; |
| | |
| | | } |
| | | |
| | | if ("video_file".equals(event.getApp())) { |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceStream(event.getStream(), SecurityConstants.INNER); |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceStream(event.getStream(), SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | return; |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | QsDevice qsDevice = new QsDevice(); |
| | | qsDevice.setId(r.getData().getId()); |
| | | qsDevice.setStreamKey(""); |
| | | qsDevice.setMediaServerId(""); |
| | | qsDevice.setStreamStatus("0"); |
| | | R<Boolean> qsDevicer = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER); |
| | | StreamChannel streamChannel = new StreamChannel(); |
| | | streamChannel.setId(r.getData().getId()); |
| | | streamChannel.setStreamKey(""); |
| | | streamChannel.setMediaServerId(""); |
| | | streamChannel.setStreamStatus("0"); |
| | | R<Boolean> qsDevicer = zlmStreamService.updateQsDevice(streamChannel, SecurityConstants.INNER); |
| | | if (qsDevicer.getCode() != Constants.SUCCESS) { |
| | | log.error("更新设备失败"); |
| | | } |
| | |
| | | redisCatchStorage.removePushListItem(event.getApp(), event.getStream(), event.getMediaServer().getId()); |
| | | } |
| | | |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceStream("pull_" + event.getApp() + "_" + event.getStream(), |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceStream("pull_" + event.getApp() + "_" + event.getStream(), |
| | | SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.error("获取设备信息失败,stream:{}", event.getStream()); |
| | |
| | | } |
| | | |
| | | if (r.getData() == null) { |
| | | r = remoteQsDeviceService.getQsDeviceStream(event.getStream(), SecurityConstants.INNER); |
| | | r = zlmStreamService.getQsDeviceStream(event.getStream(), SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.error("获取设备信息失败,stream:{}", event.getStream()); |
| | | return; |
| | |
| | | if (r.getData() == null) { |
| | | return; |
| | | } |
| | | QsDevice device = new QsDevice(); |
| | | device.setDeviceStatus("OFFLINE"); |
| | | StreamChannel device = new StreamChannel(); |
| | | device.setMediaServerId(""); |
| | | device.setStreamKey(""); |
| | | device.setStreamStatus("0"); |
| | | device.setId(r.getData().getId()); |
| | | R<Boolean> updateR = remoteQsDeviceService.updateQsDevice(device, SecurityConstants.INNER); |
| | | R<Boolean> updateR = zlmStreamService.updateQsDevice(device, SecurityConstants.INNER); |
| | | if (updateR.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("修改推流设备设备失败" + event.getApp() + "_" + event.getStream()); |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceInfo(rtpServerParam.getId(), SecurityConstants.INNER); |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceInfo(rtpServerParam.getId(), SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | callback.run(InviteErrorCode.FAIL.getCode(), "获取设备信息失败" + rtpServerParam.getId(), null); |
| | | return; |
| | |
| | | return; |
| | | } |
| | | |
| | | if ("OFFLINE".equals(r.getData().getDeviceStatus())) { |
| | | if (!Boolean.TRUE.equals(Boolean.TRUE.equals(r.getData().getDeviceOnLine()))) { |
| | | callback.run(InviteErrorCode.FAIL.getCode(), "设备不在线" + rtpServerParam.getId(), null); |
| | | return; |
| | | } |
| | |
| | | * @param callback 回调 |
| | | * @return |
| | | */ |
| | | private SSRCInfo play(ZlmMediaServer mediaServer, RTPServerParam rtpServerParam, QsDevice device, String ssrc, |
| | | private SSRCInfo play(ZlmMediaServer mediaServer, RTPServerParam rtpServerParam, StreamChannel device, String ssrc, |
| | | ErrorCallback<StreamInfo> callback) { |
| | | // 获取点播的状态信息 |
| | | InviteInfo inviteInfoInCatch = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, |
| | |
| | | |
| | | String filePath = snapOnPlay(streamInfo.getMediaServer(), streamInfo.getApp(), |
| | | streamInfo.getStream()); |
| | | QsDevice qsDevice = new QsDevice(); |
| | | qsDevice.setId(rtpServerParam.getId()); |
| | | qsDevice.setStreamKey(rtpServerParam.getStreamId()); |
| | | qsDevice.setMediaServerId(mediaServer.getId()); |
| | | qsDevice.setStreamStatus("1"); |
| | | qsDevice.setSnap(filePath); |
| | | R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER); |
| | | StreamChannel streamChannel = new StreamChannel(); |
| | | streamChannel.setId(rtpServerParam.getId()); |
| | | streamChannel.setStreamKey(rtpServerParam.getStreamId()); |
| | | streamChannel.setMediaServerId(mediaServer.getId()); |
| | | streamChannel.setStreamStatus("1"); |
| | | streamChannel.setSnap(filePath); |
| | | R<Boolean> r = zlmStreamService.updateQsDevice(streamChannel, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("更新设备失败"); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public void stopRtpPlay(RTPServerParam rtpServerParam) { |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceInfo(rtpServerParam.getId(), SecurityConstants.INNER); |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceInfo(rtpServerParam.getId(), SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("获取设备信息失败"); |
| | | } |
| | | if (r.getData() == null) { |
| | | throw new RuntimeException("设备不存在"); |
| | | } |
| | | QsDevice device = r.getData(); |
| | | StreamChannel device = r.getData(); |
| | | |
| | | String mediaServerId = device.getMediaServerId(); |
| | | ZlmMediaServer mediaServer = getOne(mediaServerId); |
| | |
| | | } |
| | | } |
| | | |
| | | QsDevice qsDevice = new QsDevice(); |
| | | qsDevice.setId(rtpServerParam.getId()); |
| | | qsDevice.setStreamKey(""); |
| | | qsDevice.setMediaServerId(""); |
| | | qsDevice.setStreamStatus("0"); |
| | | R<Boolean> devicer = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER); |
| | | StreamChannel streamChannel = new StreamChannel(); |
| | | streamChannel.setId(rtpServerParam.getId()); |
| | | streamChannel.setStreamKey(""); |
| | | streamChannel.setMediaServerId(""); |
| | | streamChannel.setStreamStatus("0"); |
| | | R<Boolean> devicer = zlmStreamService.updateQsDevice(streamChannel, SecurityConstants.INNER); |
| | | if (devicer.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("更新设备失败"); |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceInfo(id, SecurityConstants.INNER); |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceInfo(id, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | callback.run(InviteErrorCode.FAIL.getCode(), "获取设备信息失败" + id, null); |
| | | return; |
| | |
| | | return; |
| | | } |
| | | |
| | | if ("OFFLINE".equals(r.getData().getDeviceStatus())) { |
| | | if (!Boolean.TRUE.equals(Boolean.TRUE.equals(r.getData().getDeviceOnLine()))) { |
| | | throw new RuntimeException("设备不在线" + id); |
| | | } |
| | | |
| | | QsDevice device = r.getData(); |
| | | StreamChannel device = r.getData(); |
| | | String videoPath = convertUrlToPath(device.getLiveAddress(), this.fileDomain, this.filePrefix, this.filePath); |
| | | |
| | | loadMP4File(mediaServer, "video_file", device.getDeviceCode(), id, videoPath, ((code, msg, streamInfo) -> { |
| | |
| | | */ |
| | | @Override |
| | | public void closeStreams(Long id) { |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceInfo(id, SecurityConstants.INNER); |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceInfo(id, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("获取设备信息失败"); |
| | | } |
| | |
| | | throw new RuntimeException("设备不存在"); |
| | | } |
| | | |
| | | QsDevice device = r.getData(); |
| | | StreamChannel device = r.getData(); |
| | | ZlmMediaServer mediaServer = getOne(device.getMediaServerId()); |
| | | |
| | | if (mediaServer == null) { |
| | |
| | | */ |
| | | @Override |
| | | public Map<String, Object> getStreamPushAddress(Long id, String callId) { |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceInfo(id, SecurityConstants.INNER); |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceInfo(id, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("获取设备信息失败"); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public void streamPullPush(Long id, ErrorCallback<StreamInfo> callback) { |
| | | R<QsDevice> r = remoteQsDeviceService.getQsDeviceInfo(id, SecurityConstants.INNER); |
| | | R<StreamChannel> r = zlmStreamService.getQsDeviceInfo(id, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.info("获取设备信息失败 id:{}", id); |
| | | callback.run(InviteErrorCode.FAIL.getCode(), "获取设备信息失败", null); |
| | |
| | | callback.run(InviteErrorCode.FAIL.getCode(), "设备不存在", null); |
| | | return; |
| | | } |
| | | QsDevice device = r.getData(); |
| | | StreamChannel device = r.getData(); |
| | | |
| | | if (!LiveStreamType.PUSH.getCode().equals(device.getType())) { |
| | | log.info("直播流接入类型不对,应当是PUSH id:{}", id); |
| | |
| | | callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), |
| | | getStreamInfoByAppAndStream(mediaServer, "push", device.getDeviceCode(), mediaInfo)); |
| | | if ("0".equals(device.getStreamStatus())) { |
| | | QsDevice qsDevice = new QsDevice(); |
| | | qsDevice.setId(id); |
| | | qsDevice.setStreamStatus("1"); |
| | | R<Boolean> updateR = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER); |
| | | StreamChannel streamChannel = new StreamChannel(); |
| | | streamChannel.setId(id); |
| | | streamChannel.setStreamStatus("1"); |
| | | R<Boolean> updateR = zlmStreamService.updateQsDevice(streamChannel, SecurityConstants.INNER); |
| | | if (updateR.getCode() != Constants.SUCCESS) { |
| | | log.info("修改推流设备设备失败 id:{}", id); |
| | | throw new RuntimeException("修改推流设备设备失败"); |
| | |
| | | /** |
| | | * gb28181 播放 |
| | | * |
| | | * @param qsDevice |
| | | * @param streamChannel |
| | | * @param gbDevice |
| | | * @param callback |
| | | */ |
| | | @Override |
| | | public void startGb28181Play(QsDevice qsDevice, Device gbDevice, ErrorCallback<StreamInfo> callback) { |
| | | public void startGb28181Play(StreamChannel streamChannel, Device gbDevice, ErrorCallback<StreamInfo> callback) { |
| | | ZlmMediaServer mediaServer = getMediaServerForMinimumLoad(null); |
| | | |
| | | if (mediaServer == null) { |
| | |
| | | return; |
| | | } |
| | | |
| | | int tcpMode = qsDevice.getStreamMode().equals("TCP-ACTIVE") ? 2 : (qsDevice.getStreamMode().equals("TCP" + |
| | | int tcpMode = streamChannel.getStreamMode().equals("TCP-ACTIVE") ? 2 : (streamChannel.getStreamMode().equals("TCP" + |
| | | "-PASSIVE") ? 1 : 0); |
| | | |
| | | RTPServerParam rtpServerParam = new RTPServerParam(); |
| | | rtpServerParam.setApp("gb28181"); |
| | | rtpServerParam.setMediaServer(mediaServer); |
| | | rtpServerParam.setType(LiveStreamType.GB28181.getCode()); |
| | | rtpServerParam.setStreamId(qsDevice.getDeviceCode()); |
| | | rtpServerParam.setStreamId(streamChannel.getDeviceCode()); |
| | | rtpServerParam.setTcpMode(tcpMode); |
| | | rtpServerParam.setId(qsDevice.getId()); |
| | | rtpServerParam.setId(streamChannel.getId()); |
| | | |
| | | startGb28181PlayFun(mediaServer, qsDevice, gbDevice, rtpServerParam, null, callback); |
| | | startGb28181PlayFun(mediaServer, streamChannel, gbDevice, rtpServerParam, null, callback); |
| | | } |
| | | |
| | | /** |
| | |
| | | * gb28181 停止点播 |
| | | * |
| | | * @param type |
| | | * @param qsDevice |
| | | * @param streamChannel |
| | | * @param device |
| | | * @param stream |
| | | */ |
| | | @Override |
| | | public void stopGb28181Play(InviteSessionType type, QsDevice qsDevice, Device device, String stream) { |
| | | InviteInfo inviteInfo = inviteStreamService.getInviteInfo(type, qsDevice.getId(), stream); |
| | | public void stopGb28181Play(InviteSessionType type, StreamChannel streamChannel, Device device, String stream) { |
| | | InviteInfo inviteInfo = inviteStreamService.getInviteInfo(type, streamChannel.getId(), stream); |
| | | if (inviteInfo == null) { |
| | | if (type == InviteSessionType.PLAY) { |
| | | QsDevice qsDeviceUpdate = new QsDevice(); |
| | | qsDeviceUpdate.setId(qsDevice.getId()); |
| | | StreamChannel qsDeviceUpdate = new StreamChannel(); |
| | | qsDeviceUpdate.setId(streamChannel.getId()); |
| | | qsDeviceUpdate.setStreamKey(""); |
| | | qsDeviceUpdate.setMediaServerId(""); |
| | | qsDeviceUpdate.setStreamStatus("0"); |
| | | R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDeviceUpdate, SecurityConstants.INNER); |
| | | R<Boolean> r = zlmStreamService.updateQsDevice(qsDeviceUpdate, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("更新设备失败"); |
| | | } |
| | |
| | | inviteStreamService.removeInviteInfo(inviteInfo); |
| | | if (InviteSessionStatus.ok == inviteInfo.getStatus()) { |
| | | try { |
| | | log.info("[停止点播/回放/下载] {}/{}", qsDevice.getGbDeviceId(), qsDevice.getGbChannelId()); |
| | | log.info("[停止点播/回放/下载] {}/{}", streamChannel.getGbDeviceId(), streamChannel.getGbChannelId()); |
| | | |
| | | RtpServerParam rtpServer = new RtpServerParam(); |
| | | rtpServer.setApp("gb28181"); |
| | | rtpServer.setStream(qsDevice.getDeviceCode()); |
| | | rtpServer.setGbDeviceId(qsDevice.getGbDeviceId()); |
| | | rtpServer.setGbChannelId(qsDevice.getGbChannelId()); |
| | | rtpServer.setStream(streamChannel.getDeviceCode()); |
| | | rtpServer.setGbDeviceId(streamChannel.getGbDeviceId()); |
| | | rtpServer.setGbChannelId(streamChannel.getGbChannelId()); |
| | | |
| | | R<Void> r = remoteGb28181Service.streamByeCmd(rtpServer, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.error("[命令发送失败] 停止点播/回放/下载, deviceId:{}", qsDevice.getGbDeviceId()); |
| | | throw new RuntimeException("[命令发送失败] 停止点播/回放/下载, deviceId:" + qsDevice.getGbDeviceId()); |
| | | log.error("[命令发送失败] 停止点播/回放/下载, deviceId:{}", streamChannel.getGbDeviceId()); |
| | | throw new RuntimeException("[命令发送失败] 停止点播/回放/下载, deviceId:" + streamChannel.getGbDeviceId()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("[命令发送失败] 停止点播/回放/下载, 发送BYE: {}", e.getMessage()); |
| | |
| | | } |
| | | |
| | | if (inviteInfo.getType() == InviteSessionType.PLAY) { |
| | | QsDevice qsDeviceUpdate = new QsDevice(); |
| | | qsDeviceUpdate.setId(qsDevice.getId()); |
| | | StreamChannel qsDeviceUpdate = new StreamChannel(); |
| | | qsDeviceUpdate.setId(streamChannel.getId()); |
| | | qsDeviceUpdate.setStreamKey(""); |
| | | qsDeviceUpdate.setMediaServerId(""); |
| | | qsDeviceUpdate.setStreamStatus("0"); |
| | | R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDeviceUpdate, SecurityConstants.INNER); |
| | | R<Boolean> r = zlmStreamService.updateQsDevice(qsDeviceUpdate, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("更新设备失败"); |
| | | } |
| | |
| | | * gb28181 播放(基于GbDevice,不依赖QS) |
| | | */ |
| | | @Override |
| | | public void startGb28181PlayByGbChannel(GbChannelDTO gbChannelDTO, Device gbDevice, ErrorCallback<StreamInfo> callback) { |
| | | public void startGb28181PlayByGbChannel(StreamChannel streamChannel, Device gbDevice, ErrorCallback<StreamInfo> callback) { |
| | | ZlmMediaServer mediaServer = getMediaServerForMinimumLoad(null); |
| | | |
| | | if (mediaServer == null) { |
| | |
| | | return; |
| | | } |
| | | |
| | | String streamMode = gbChannelDTO.getStreamMode() != null |
| | | ? gbChannelDTO.getStreamMode() : gbDevice.getStreamMode(); |
| | | String streamMode = streamChannel.getStreamMode() != null |
| | | ? streamChannel.getStreamMode() : gbDevice.getStreamMode(); |
| | | int tcpMode = streamMode.equals("TCP-ACTIVE") ? 2 |
| | | : (streamMode.equals("TCP-PASSIVE") ? 1 : 0); |
| | | |
| | |
| | | rtpServerParam.setApp("gb28181"); |
| | | rtpServerParam.setMediaServer(mediaServer); |
| | | rtpServerParam.setType(LiveStreamType.GB28181.getCode()); |
| | | rtpServerParam.setStreamId(gbChannelDTO.getDeviceCode()); |
| | | rtpServerParam.setStreamId(streamChannel.getDeviceCode()); |
| | | rtpServerParam.setTcpMode(tcpMode); |
| | | rtpServerParam.setId(gbChannelDTO.getId()); |
| | | rtpServerParam.setId(streamChannel.getId()); |
| | | |
| | | startGb28181PlayFunByGbChannel(mediaServer, gbChannelDTO, gbDevice, rtpServerParam, null, callback); |
| | | startGb28181PlayFunByGbChannel(mediaServer, streamChannel, gbDevice, rtpServerParam, null, callback); |
| | | } |
| | | |
| | | /** |
| | | * gb28181 停止点播(基于GbDevice,不依赖QS) |
| | | */ |
| | | @Override |
| | | public void stopGb28181PlayByGbChannel(InviteSessionType type, GbChannelDTO gbChannelDTO, Device device, String stream) { |
| | | InviteInfo inviteInfo = inviteStreamService.getInviteInfo(type, gbChannelDTO.getId(), stream); |
| | | public void stopGb28181PlayByGbChannel(InviteSessionType type, StreamChannel streamChannel, Device device, String stream) { |
| | | InviteInfo inviteInfo = inviteStreamService.getInviteInfo(type, streamChannel.getId(), stream); |
| | | if (inviteInfo == null) { |
| | | if (type == InviteSessionType.PLAY) { |
| | | GbChannelDTO update = new GbChannelDTO(); |
| | | update.setId(gbChannelDTO.getId()); |
| | | StreamChannel update = new StreamChannel(); |
| | | update.setId(streamChannel.getId()); |
| | | update.setStreamKey(""); |
| | | update.setMediaServerId(""); |
| | | update.setStreamStatus("0"); |
| | | R<Boolean> r = remoteGb28181Service.updateGbChannelStream(update, SecurityConstants.INNER); |
| | | R<Boolean> r = zlmStreamService.updateQsDevice(update, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("更新GbDevice失败"); |
| | | } |
| | |
| | | inviteStreamService.removeInviteInfo(inviteInfo); |
| | | if (InviteSessionStatus.ok == inviteInfo.getStatus()) { |
| | | try { |
| | | log.info("[停止点播/回放/下载] {}/{}", gbChannelDTO.getGbDeviceId(), gbChannelDTO.getGbChannelId()); |
| | | log.info("[停止点播/回放/下载] {}/{}", streamChannel.getGbDeviceId(), streamChannel.getGbChannelId()); |
| | | |
| | | RtpServerParam rtpServer = new RtpServerParam(); |
| | | rtpServer.setApp("gb28181"); |
| | | rtpServer.setStream(gbChannelDTO.getDeviceCode()); |
| | | rtpServer.setGbDeviceId(gbChannelDTO.getGbDeviceId()); |
| | | rtpServer.setGbChannelId(gbChannelDTO.getGbChannelId()); |
| | | rtpServer.setStream(streamChannel.getDeviceCode()); |
| | | rtpServer.setGbDeviceId(streamChannel.getGbDeviceId()); |
| | | rtpServer.setGbChannelId(streamChannel.getGbChannelId()); |
| | | |
| | | R<Void> r = remoteGb28181Service.streamByeCmd(rtpServer, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.error("[命令发送失败] 停止点播/回放/下载, deviceId:{}", gbChannelDTO.getGbDeviceId()); |
| | | throw new RuntimeException("[命令发送失败] 停止点播/回放/下载, deviceId:" + gbChannelDTO.getGbDeviceId()); |
| | | log.error("[命令发送失败] 停止点播/回放/下载, deviceId:{}", streamChannel.getGbDeviceId()); |
| | | throw new RuntimeException("[命令发送失败] 停止点播/回放/下载, deviceId:" + streamChannel.getGbDeviceId()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("[命令发送失败] 停止点播/回放/下载, 发送BYE: {}", e.getMessage()); |
| | |
| | | } |
| | | |
| | | if (inviteInfo.getType() == InviteSessionType.PLAY) { |
| | | GbChannelDTO update = new GbChannelDTO(); |
| | | update.setId(gbChannelDTO.getId()); |
| | | StreamChannel update = new StreamChannel(); |
| | | update.setId(streamChannel.getId()); |
| | | update.setStreamKey(""); |
| | | update.setMediaServerId(""); |
| | | update.setStreamStatus("0"); |
| | | R<Boolean> r = remoteGb28181Service.updateGbChannelStream(update, SecurityConstants.INNER); |
| | | R<Boolean> r = zlmStreamService.updateQsDevice(update, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("更新GbDevice失败"); |
| | | } |
| | |
| | | * @param ssrc |
| | | * @param callback |
| | | */ |
| | | private SSRCInfo startGb28181PlayFun(ZlmMediaServer mediaServer, QsDevice device, Device gbDevice, |
| | | private SSRCInfo startGb28181PlayFun(ZlmMediaServer mediaServer, StreamChannel device, Device gbDevice, |
| | | RTPServerParam rtpServerParam, String ssrc, |
| | | ErrorCallback<StreamInfo> callback) { |
| | | // 获取点播的状态信息 |
| | |
| | | |
| | | String filePath = snapOnPlay(streamInfo.getMediaServer(), streamInfo.getApp(), |
| | | streamInfo.getStream()); |
| | | QsDevice qsDevice = new QsDevice(); |
| | | qsDevice.setId(rtpServerParam.getId()); |
| | | qsDevice.setStreamKey(rtpServerParam.getStreamId()); |
| | | qsDevice.setMediaServerId(mediaServer.getId()); |
| | | qsDevice.setStreamStatus("1"); |
| | | qsDevice.setSnap(filePath); |
| | | R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER); |
| | | StreamChannel streamChannel = new StreamChannel(); |
| | | streamChannel.setId(rtpServerParam.getId()); |
| | | streamChannel.setStreamKey(rtpServerParam.getStreamId()); |
| | | streamChannel.setMediaServerId(mediaServer.getId()); |
| | | streamChannel.setStreamStatus("1"); |
| | | streamChannel.setSnap(filePath); |
| | | R<Boolean> r = zlmStreamService.updateQsDevice(streamChannel, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("更新设备失败"); |
| | | } |
| | |
| | | /** |
| | | * 开启国标28181播放(基于GbDevice,不依赖QS) |
| | | */ |
| | | private SSRCInfo startGb28181PlayFunByGbChannel(ZlmMediaServer mediaServer, GbChannelDTO gbChannelDTO, |
| | | private SSRCInfo startGb28181PlayFunByGbChannel(ZlmMediaServer mediaServer, StreamChannel streamChannel, |
| | | Device gbDevice, RTPServerParam rtpServerParam, |
| | | String ssrc, ErrorCallback<StreamInfo> callback) { |
| | | // 获取点播的状态信息 |
| | | InviteInfo inviteInfoInCatch = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, |
| | | gbChannelDTO.getId()); |
| | | streamChannel.getId()); |
| | | if (inviteInfoInCatch != null) { |
| | | if (inviteInfoInCatch.getStreamInfo() == null) { |
| | | ssrcFactory.releaseSsrc(mediaServer.getId(), null); |
| | | inviteStreamService.once(InviteSessionType.PLAY, gbChannelDTO.getId(), null, callback); |
| | | log.info("[点播开始] 已经请求中,等待结果, deviceId: {}, channel: {}", gbChannelDTO.getId(), gbChannelDTO.getId()); |
| | | inviteStreamService.once(InviteSessionType.PLAY, streamChannel.getId(), null, callback); |
| | | log.info("[点播开始] 已经请求中,等待结果, deviceId: {}, channel: {}", streamChannel.getId(), streamChannel.getId()); |
| | | return inviteInfoInCatch.getSsrcInfo(); |
| | | } else { |
| | | StreamInfo streamInfo = inviteInfoInCatch.getStreamInfo(); |
| | | String streamId = streamInfo.getStream(); |
| | | if (streamId == null) { |
| | | callback.run(InviteErrorCode.ERROR_FOR_CATCH_DATA.getCode(), "点播失败, redis缓存streamId等于null", null); |
| | | inviteStreamService.call(InviteSessionType.PLAY, gbChannelDTO.getId(), null, |
| | | inviteStreamService.call(InviteSessionType.PLAY, streamChannel.getId(), null, |
| | | InviteErrorCode.ERROR_FOR_CATCH_DATA.getCode(), "点播失败, redis缓存streamId等于null", null); |
| | | return inviteInfoInCatch.getSsrcInfo(); |
| | | } |
| | |
| | | if (callback != null) { |
| | | callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | } |
| | | inviteStreamService.call(InviteSessionType.PLAY, gbChannelDTO.getId(), null, |
| | | inviteStreamService.call(InviteSessionType.PLAY, streamChannel.getId(), null, |
| | | InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | log.info("[点播已存在] 直接返回, 设备编号: {}", gbChannelDTO.getId()); |
| | | log.info("[点播已存在] 直接返回, 设备编号: {}", streamChannel.getId()); |
| | | return inviteInfoInCatch.getSsrcInfo(); |
| | | } else { |
| | | inviteStreamService.once(InviteSessionType.PLAY, gbChannelDTO.getId(), null, callback); |
| | | inviteStreamService.once(InviteSessionType.PLAY, streamChannel.getId(), null, callback); |
| | | RTPServerParam stopRtp = new RTPServerParam(); |
| | | stopRtp.setId(gbChannelDTO.getId()); |
| | | stopRtp.setId(streamChannel.getId()); |
| | | stopRtp.setType(rtpServerParam.getType()); |
| | | stopRtp.setStreamId(rtpServerParam.getStreamId()); |
| | | stopRtpPlay(stopRtp); |
| | | inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, gbChannelDTO.getId()); |
| | | inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, streamChannel.getId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | callback.run(InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| | | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); |
| | | } |
| | | inviteStreamService.call(InviteSessionType.PLAY, gbChannelDTO.getId(), null, |
| | | inviteStreamService.call(InviteSessionType.PLAY, streamChannel.getId(), null, |
| | | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getCode(), |
| | | InviteErrorCode.ERROR_FOR_STREAM_PARSING_EXCEPTIONS.getMsg(), null); |
| | | if (result != null && result.getSsrcInfo() != null) { |
| | |
| | | } |
| | | if (callback != null) { |
| | | callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | inviteStreamService.call(InviteSessionType.PLAY, gbChannelDTO.getId(), null, |
| | | inviteStreamService.call(InviteSessionType.PLAY, streamChannel.getId(), null, |
| | | InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | |
| | | InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel( |
| | | InviteSessionType.PLAY, gbChannelDTO.getId()); |
| | | InviteSessionType.PLAY, streamChannel.getId()); |
| | | if (inviteInfo != null) { |
| | | inviteInfo.setStatus(InviteSessionStatus.ok); |
| | | inviteInfo.setStreamInfo(streamInfo); |
| | |
| | | streamInfo.getStream()); |
| | | |
| | | // 更新GbDevice流状态 |
| | | GbChannelDTO update = new GbChannelDTO(); |
| | | StreamChannel update = new StreamChannel(); |
| | | update.setId(rtpServerParam.getId()); |
| | | update.setStreamKey(rtpServerParam.getStreamId()); |
| | | update.setMediaServerId(mediaServer.getId()); |
| | | update.setStreamStatus("1"); |
| | | update.setSnap(filePath); |
| | | R<Boolean> r = remoteGb28181Service.updateGbChannelStream(update, SecurityConstants.INNER); |
| | | R<Boolean> r = zlmStreamService.updateQsDevice(update, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | throw new RuntimeException("更新GbDevice失败"); |
| | | } |
| | |
| | | if (callback != null) { |
| | | callback.run(code, msg, null); |
| | | } |
| | | inviteStreamService.call(InviteSessionType.PLAY, gbChannelDTO.getId(), null, code, msg, null); |
| | | inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, gbChannelDTO.getId()); |
| | | inviteStreamService.call(InviteSessionType.PLAY, streamChannel.getId(), null, code, msg, null); |
| | | inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, streamChannel.getId()); |
| | | if (result != null && result.getSsrcInfo() != null) { |
| | | closeRTPServer(mediaServer, result.getSsrcInfo().getStream()); |
| | | ssrcFactory.releaseSsrc(mediaServer.getId(), result.getSsrcInfo().getSsrc()); |
| | |
| | | }); |
| | | |
| | | if (ssrcInfo == null || ssrcInfo.getPort() <= 0) { |
| | | log.info("[点播端口/SSRC]获取失败,设备编号:{}, 通道编号:{}, ssrcInfo: {}", gbChannelDTO.getId(), gbChannelDTO.getId(), ssrcInfo); |
| | | log.info("[点播端口/SSRC]获取失败,设备编号:{}, 通道编号:{}, ssrcInfo: {}", streamChannel.getId(), streamChannel.getId(), ssrcInfo); |
| | | if (rtpServerParam.getPresetSsrc() == null) { |
| | | ssrcFactory.releaseSsrc(mediaServer.getId(), ssrc); |
| | | } |
| | | callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), "获取端口或者ssrc失败", null); |
| | | inviteStreamService.call(InviteSessionType.PLAY, gbChannelDTO.getId(), null, |
| | | inviteStreamService.call(InviteSessionType.PLAY, streamChannel.getId(), null, |
| | | InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), |
| | | InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null); |
| | | return null; |
| | |
| | | rtpServer.setId(rtpServerParam.getId()); |
| | | rtpServer.setSsrc(rtpServerParam.getSsrc()); |
| | | rtpServer.setGbDeviceId(gbDevice.getDeviceId()); |
| | | rtpServer.setGbChannelId(gbChannelDTO.getGbChannelId()); |
| | | rtpServer.setGbChannelId(streamChannel.getGbChannelId()); |
| | | rtpServer.setStreamMode(gbDevice.getStreamMode()); |
| | | rtpServer.setMediaServerId(mediaServer.getId()); |
| | | rtpServer.setApp(rtpServerParam.getApp()); |
| | | rtpServer.setStream(rtpServerParam.getStreamId()); |
| | | |
| | | log.info("[国标28181点播开始(基于GbDevice)] ==============================="); |
| | | log.info("[国标28181] GbDeviceId: {}, 设备国标ID: {}, 通道国标ID: {}", gbChannelDTO.getId(), |
| | | gbDevice.getDeviceId(), gbChannelDTO.getGbChannelId()); |
| | | log.info("[国标28181] GbDeviceId: {}, 设备国标ID: {}, 通道国标ID: {}", streamChannel.getId(), |
| | | gbDevice.getDeviceId(), streamChannel.getGbChannelId()); |
| | | log.info("[国标28181] 流模式: {}, ZLM tcpMode: {}, ssrcCheck: {}", gbDevice.getStreamMode(), |
| | | rtpServerParam.getTcpMode(), rtpServerParam.isSsrcCheck()); |
| | | log.info("[国标28181] ZLM媒体服务器IP: {}, 收流端口: {}, 流ID: {}, SSRC: {}", ip, port, ssrcInfo.getStream(), |
| | | ssrcInfo.getSsrc()); |
| | | log.info("[国标28181] ======================================="); |
| | | |
| | | InviteInfo inviteInfo = InviteInfo.getInviteInfo(gbChannelDTO.getId().toString(), gbChannelDTO.getId(), |
| | | InviteInfo inviteInfo = InviteInfo.getInviteInfo(streamChannel.getId().toString(), streamChannel.getId(), |
| | | ssrcInfo.getStream(), ssrcInfo, mediaServer.getId(), mediaServer.getSdpIp(), ssrcInfo.getPort(), |
| | | gbDevice.getStreamMode(), InviteSessionType.PLAY, InviteSessionStatus.ready, |
| | | userSetting.getRecordSip()); |
| | | |
| | | if ("1".equals(gbChannelDTO.getEnableMp4())) { |
| | | if ("1".equals(streamChannel.getEnableMp4())) { |
| | | inviteInfo.setRecord(true); |
| | | } |
| | | |
| | |
| | | |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.info("[点播失败]{}:{} deviceId: {}, channelId:{}", r.getCode(), r.getMsg(), |
| | | gbChannelDTO.getGbDeviceId(), gbChannelDTO.getGbChannelId()); |
| | | inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.PLAY, gbChannelDTO.getId(), |
| | | streamChannel.getGbDeviceId(), streamChannel.getGbChannelId()); |
| | | inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.PLAY, streamChannel.getId(), |
| | | rtpServerParam.getStreamId()); |
| | | if (inviteInfo != null) { |
| | | inviteStreamService.removeInviteInfo(inviteInfo); |
| | |
| | | if (callback != null) { |
| | | callback.run(r.getCode(), r.getMsg(), null); |
| | | } |
| | | inviteStreamService.call(InviteSessionType.PLAY, gbChannelDTO.getId(), null, |
| | | inviteStreamService.call(InviteSessionType.PLAY, streamChannel.getId(), null, |
| | | r.getCode(), r.getMsg(), null); |
| | | inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, gbChannelDTO.getId()); |
| | | inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, streamChannel.getId()); |
| | | return ssrcInfo; |
| | | } |
| | | return ssrcInfo; |
| | |
| | | if (callback != null) { |
| | | callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | |
| | | QsDevice qsDevice = new QsDevice(); |
| | | qsDevice.setId(id); |
| | | qsDevice.setStreamKey(stream); |
| | | qsDevice.setMediaServerId(mediaServer.getId()); |
| | | qsDevice.setStreamStatus("1"); |
| | | R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER); |
| | | StreamChannel streamChannel = new StreamChannel(); |
| | | streamChannel.setId(id); |
| | | streamChannel.setStreamKey(stream); |
| | | streamChannel.setMediaServerId(mediaServer.getId()); |
| | | streamChannel.setStreamStatus("1"); |
| | | R<Boolean> r = zlmStreamService.updateQsDevice(streamChannel, SecurityConstants.INNER); |
| | | if (r.getCode() != Constants.SUCCESS) { |
| | | log.error("更新设备失败"); |
| | | callback.run(InviteErrorCode.FAIL.getCode(), "更新设备失败", null); |