| | |
| | | package com.genersoft.iot.vmp.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.genersoft.iot.vmp.common.InviteInfo; |
| | |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| | | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; |
| | | import com.genersoft.iot.vmp.gb28181.utils.SipUtils; |
| | | import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils; |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; |
| | | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; |
| | |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper; |
| | | import com.genersoft.iot.vmp.utils.CloudRecordUtils; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| | | import gov.nist.javax.sip.message.SIPResponse; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.ParseException; |
| | | import java.time.Instant; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import java.util.Vector; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | @SuppressWarnings(value = {"rawtypes", "unchecked"}) |
| | | @Service |
| | |
| | | HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId()); |
| | | subscribe.removeSubscribe(hookSubscribe); |
| | | } |
| | | }else { |
| | | logger.info("[点播超时] 收流超时 deviceId: {}, channelId: {},码流类型:{},端口:{}, SSRC: {}", |
| | | device.getDeviceId(), channelId, device.isSwitchPrimarySubStream() ? "辅码流" : "主码流", |
| | | ssrcInfo.getPort(), ssrcInfo.getSsrc()); |
| | | |
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); |
| | | |
| | | mediaServerService.closeRTPServer(mediaServerItem.getId(), ssrcInfo.getStream()); |
| | | streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); |
| | | } |
| | | }, userSetting.getPlayTimeout()); |
| | | |
| | |
| | | InviteOKHandler(eventResult, ssrcInfo, mediaServerItem, device, channelId, |
| | | timeOutTaskKey, callback, inviteInfo, InviteSessionType.PLAY); |
| | | }, (event) -> { |
| | | logger.info("[点播失败] deviceId: {}, channelId:{}, {}: {}", device.getDeviceId(), channelId, event.statusCode, event.msg); |
| | | dynamicTask.stop(timeOutTaskKey); |
| | | mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream()); |
| | | // 释放ssrc |
| | |
| | | if (!device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) { |
| | | return; |
| | | } |
| | | String substring = contentString.substring(0, contentString.indexOf("y=")); |
| | | |
| | | String substring; |
| | | if (contentString.indexOf("y=") > 0) { |
| | | substring = contentString.substring(0, contentString.indexOf("y=")); |
| | | }else { |
| | | substring = contentString; |
| | | } |
| | | try { |
| | | SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring); |
| | | int port = -1; |
| | |
| | | deviceChannel.setStreamId(streamInfo.getStream()); |
| | | storager.startPlay(deviceId, channelId, streamInfo.getStream()); |
| | | } |
| | | InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAYBACK, deviceId, channelId); |
| | | InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, ((OnStreamChangedHookParam) param).getStream()); |
| | | if (inviteInfo != null) { |
| | | inviteInfo.setStatus(InviteSessionStatus.ok); |
| | | |
| | |
| | | } |
| | | if (mediaServerItem == null) { |
| | | logger.warn("点播时未找到可使用的ZLM..."); |
| | | } |
| | | return mediaServerItem; |
| | | } |
| | | |
| | | @Override |
| | | public MediaServerItem getNewMediaServerItemHasAssist(Device device) { |
| | | if (device == null) { |
| | | return null; |
| | | } |
| | | MediaServerItem mediaServerItem; |
| | | if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { |
| | | mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(true); |
| | | } else { |
| | | mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); |
| | | } |
| | | if (mediaServerItem == null) { |
| | | logger.warn("[获取可用的ZLM节点]未找到可使用的ZLM..."); |
| | | } |
| | | return mediaServerItem; |
| | | } |
| | |
| | | // 处理收到200ok后的TCP主动连接以及SSRC不一致的问题 |
| | | InviteOKHandler(eventResult, ssrcInfo, mediaServerItem, device, channelId, |
| | | playBackTimeOutTaskKey, callback, inviteInfo, InviteSessionType.PLAYBACK); |
| | | |
| | | }, errorEvent); |
| | | } catch (InvalidArgumentException | SipException | ParseException e) { |
| | | logger.error("[命令发送失败] 录像回放: {}", e.getMessage()); |
| | |
| | | ResponseEvent responseEvent = (ResponseEvent) eventResult.event; |
| | | String contentString = new String(responseEvent.getResponse().getRawContent()); |
| | | String ssrcInResponse = SipUtils.getSsrcFromSdp(contentString); |
| | | // 兼容回复的消息中缺少ssrc(y字段)的情况 |
| | | if (ssrcInResponse == null) { |
| | | ssrcInResponse = ssrcInfo.getSsrc(); |
| | | } |
| | | if (ssrcInfo.getSsrc().equals(ssrcInResponse)) { |
| | | // ssrc 一致 |
| | | if (mediaServerItem.isRtpEnable()) { |
| | |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, ErrorCallback<Object> callback) { |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | if (device == null) { |
| | | return; |
| | | } |
| | | MediaServerItem newMediaServerItem = getNewMediaServerItemHasAssist(device); |
| | | MediaServerItem newMediaServerItem = this.getNewMediaServerItem(device); |
| | | if (newMediaServerItem == null) { |
| | | callback.run(InviteErrorCode.ERROR_FOR_ASSIST_NOT_READY.getCode(), |
| | | InviteErrorCode.ERROR_FOR_ASSIST_NOT_READY.getMsg(), |
| | |
| | | logger.info("[录像下载] 收到录像写入磁盘消息内容: " + hookParam); |
| | | OnRecordMp4HookParam recordMp4HookParam = (OnRecordMp4HookParam)hookParam; |
| | | String filePath = recordMp4HookParam.getFile_path(); |
| | | DownloadFileInfo downloadFileInfo = getDownloadFilePath(mediaServerItem, filePath); |
| | | DownloadFileInfo downloadFileInfo = CloudRecordUtils.getDownloadFilePath(mediaServerItem, filePath); |
| | | InviteInfo inviteInfoForNew = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId() |
| | | , inviteInfo.getChannelId(), inviteInfo.getStream()); |
| | | inviteInfoForNew.getStreamInfo().setDownLoadFilePath(downloadFileInfo); |
| | |
| | | } |
| | | inviteStreamService.updateInviteInfo(inviteInfo); |
| | | return inviteInfo.getStreamInfo(); |
| | | } |
| | | |
| | | private DownloadFileInfo getDownloadFilePath(MediaServerItem mediaServerItem, String filePath) { |
| | | DownloadFileInfo downloadFileInfo = new DownloadFileInfo(); |
| | | |
| | | String pathTemplate = "%s://%s:%s/index/api/downloadFile?file_path=" + filePath; |
| | | |
| | | downloadFileInfo.setHttpPath(String.format(pathTemplate, "http", mediaServerItem.getStreamIp(), |
| | | mediaServerItem.getHttpPort())); |
| | | |
| | | if (mediaServerItem.getHttpSSlPort() > 0) { |
| | | downloadFileInfo.setHttpsPath(String.format(pathTemplate, "https", mediaServerItem.getStreamIp(), |
| | | mediaServerItem.getHttpSSlPort())); |
| | | } |
| | | return downloadFileInfo; |
| | | } |
| | | |
| | | private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, HookParam hookParam, String deviceId, String channelId, String startTime, String endTime) { |