| | |
| | | import com.genersoft.iot.vmp.service.IPlayService; |
| | | import com.genersoft.iot.vmp.service.IStreamProxyService; |
| | | import com.genersoft.iot.vmp.service.IStreamPushService; |
| | | import com.genersoft.iot.vmp.service.bean.InviteErrorCallback; |
| | | import com.genersoft.iot.vmp.service.bean.ErrorCallback; |
| | | import com.genersoft.iot.vmp.service.bean.InviteErrorCode; |
| | | import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; |
| | | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| | |
| | | // 解析sdp消息, 使用jainsip 自带的sdp解析方式 |
| | | String contentString = new String(request.getRawContent()); |
| | | |
| | | // jainSip不支持y=字段, 移除以解析。 |
| | | // 检查是否有y字段 |
| | | int ssrcIndex = contentString.indexOf("y="); |
| | | |
| | | SessionDescription sdp; |
| | | if (ssrcIndex >= 0) { |
| | | //ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段 |
| | | String substring = contentString.substring(0, ssrcIndex); |
| | | sdp = SdpFactory.getInstance().createSessionDescription(substring); |
| | | } else { |
| | | sdp = SdpFactory.getInstance().createSessionDescription(contentString); |
| | | } |
| | | Gb28181Sdp gb28181Sdp = SipUtils.parseSDP(contentString); |
| | | SessionDescription sdp = gb28181Sdp.getBaseSdb(); |
| | | String sessionName = sdp.getSessionName().getValue(); |
| | | |
| | | Long startTime = null; |
| | |
| | | } |
| | | |
| | | String ssrc; |
| | | if (userSetting.getUseCustomSsrcForParentInvite() || ssrcIndex < 0) { |
| | | if (userSetting.getUseCustomSsrcForParentInvite() || gb28181Sdp.getSsrc() == null) { |
| | | // 上级平台点播时不使用上级平台指定的ssrc,使用自定义的ssrc,参考国标文档-点播外域设备媒体流SSRC处理方式 |
| | | ssrc = "Play".equalsIgnoreCase(sessionName) ? ssrcFactory.getPlaySsrc(mediaServerItem.getId()) : ssrcFactory.getPlayBackSsrc(mediaServerItem.getId()); |
| | | }else { |
| | | ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); |
| | | ssrc = gb28181Sdp.getSsrc(); |
| | | } |
| | | String streamTypeStr = null; |
| | | if (mediaTransmissionTCP) { |
| | |
| | | |
| | | Long finalStartTime = startTime; |
| | | Long finalStopTime = stopTime; |
| | | InviteErrorCallback<Object> hookEvent = (code, msg, data) -> { |
| | | ErrorCallback<Object> hookEvent = (code, msg, data) -> { |
| | | StreamInfo streamInfo = (StreamInfo)data; |
| | | MediaServerItem mediaServerItemInUSe = mediaServerService.getOne(streamInfo.getMediaServerId()); |
| | | logger.info("[上级Invite]下级已经开始推流。 回复200OK(SDP), {}/{}", streamInfo.getApp(), streamInfo.getStream()); |
| | |
| | | logger.error("[命令发送失败] 国标级联 回复SdpAck", e); |
| | | } |
| | | }; |
| | | InviteErrorCallback<Object> errorEvent = ((statusCode, msg, data) -> { |
| | | ErrorCallback<Object> errorEvent = ((statusCode, msg, data) -> { |
| | | // 未知错误。直接转发设备点播的错误 |
| | | try { |
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); |
| | | sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response); |
| | | if (statusCode > 0) { |
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest()); |
| | | sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response); |
| | | } |
| | | } catch (ParseException | SipException e) { |
| | | logger.error("未处理的异常 ", e); |
| | | } |
| | |
| | | errorEvent.run(code, msg, data); |
| | | } |
| | | }); |
| | | } else { |
| | | }else if ("Download".equalsIgnoreCase(sessionName)) { |
| | | // 获取指定的下载速度 |
| | | Vector sdpMediaDescriptions = sdp.getMediaDescriptions(true); |
| | | MediaDescription mediaDescription = null; |
| | | String downloadSpeed = "1"; |
| | | if (sdpMediaDescriptions.size() > 0) { |
| | | mediaDescription = (MediaDescription)sdpMediaDescriptions.get(0); |
| | | } |
| | | if (mediaDescription != null) { |
| | | downloadSpeed = mediaDescription.getAttribute("downloadspeed"); |
| | | } |
| | | |
| | | sendRtpItem.setPlayType(InviteStreamType.DOWNLOAD); |
| | | SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, null, device.isSsrcCheck(), true, 0, false, device.getStreamModeForParam()); |
| | | sendRtpItem.setStreamId(ssrcInfo.getStream()); |
| | | // 写入redis, 超时时回复 |
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| | | playService.download(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start), |
| | | DateUtil.formatter.format(end), Integer.parseInt(downloadSpeed), |
| | | (code, msg, data) -> { |
| | | if (code == InviteErrorCode.SUCCESS.getCode()){ |
| | | hookEvent.run(code, msg, data); |
| | | }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){ |
| | | logger.info("[录像下载]超时, 用户:{}, 通道:{}", username, channelId); |
| | | redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); |
| | | errorEvent.run(code, msg, data); |
| | | }else { |
| | | errorEvent.run(code, msg, data); |
| | | } |
| | | }); |
| | | }else { |
| | | sendRtpItem.setPlayType(InviteStreamType.PLAY); |
| | | String streamId = null; |
| | | if (mediaServerItem.isRtpEnable()) { |
| | |
| | | } |
| | | sendRtpItem.setStreamId(streamId); |
| | | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| | | playService.play(mediaServerItem, device.getDeviceId(), channelId, ((code, msg, data) -> { |
| | | playService.play(mediaServerItem, device.getDeviceId(), channelId,false, ((code, msg, data) -> { |
| | | if (code == InviteErrorCode.SUCCESS.getCode()){ |
| | | hookEvent.run(code, msg, data); |
| | | }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){ |
| | |
| | | } else if (gbStream != null) { |
| | | |
| | | String ssrc; |
| | | if (userSetting.getUseCustomSsrcForParentInvite() || ssrcIndex < 0) { |
| | | if (userSetting.getUseCustomSsrcForParentInvite() || gb28181Sdp.getSsrc() == null) { |
| | | // 上级平台点播时不使用上级平台指定的ssrc,使用自定义的ssrc,参考国标文档-点播外域设备媒体流SSRC处理方式 |
| | | ssrc = "Play".equalsIgnoreCase(sessionName) ? ssrcFactory.getPlaySsrc(mediaServerItem.getId()) : ssrcFactory.getPlayBackSsrc(mediaServerItem.getId()); |
| | | }else { |
| | | ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); |
| | | ssrc = gb28181Sdp.getSsrc(); |
| | | } |
| | | |
| | | if("push".equals(gbStream.getStreamType())) { |
| | |
| | | } |
| | | String contentString = new String(request.getRawContent()); |
| | | // jainSip不支持y=字段, 移除移除以解析。 |
| | | String substring = contentString; |
| | | String ssrc = "0000000404"; |
| | | int ssrcIndex = contentString.indexOf("y="); |
| | | if (ssrcIndex > 0) { |
| | | substring = contentString.substring(0, ssrcIndex); |
| | | ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); |
| | | } |
| | | ssrcIndex = substring.indexOf("f="); |
| | | if (ssrcIndex > 0) { |
| | | substring = contentString.substring(0, ssrcIndex); |
| | | } |
| | | SessionDescription sdp = null; |
| | | |
| | | try { |
| | | sdp = SdpFactory.getInstance().createSessionDescription(substring); |
| | | Gb28181Sdp gb28181Sdp = SipUtils.parseSDP(contentString); |
| | | SessionDescription sdp = gb28181Sdp.getBaseSdb(); |
| | | // 获取支持的格式 |
| | | Vector mediaDescriptions = sdp.getMediaDescriptions(true); |
| | | // 查看是否支持PS 负载96 |