diff --git a/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/request/InviteRequestBuilder.java b/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/request/InviteRequestBuilder.java index 4bc84dc..4687b18 100644 --- a/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/request/InviteRequestBuilder.java +++ b/gb28181-sip/src/main/java/cn/skcks/docking/gb28181/sip/method/invite/request/InviteRequestBuilder.java @@ -15,30 +15,66 @@ import org.apache.commons.lang3.StringUtils; import javax.sdp.Connection; import javax.sip.address.Address; +import javax.sip.header.SubjectHeader; import javax.sip.message.Request; +import java.util.Date; @Data @SuperBuilder @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class InviteRequestBuilder extends RequestBuilder implements InviteBuilder { - public Request createPlayInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, int receiveId){ + private SubjectHeader createSubject(String senderId, String senderStreamId, String receiveId, String receiveStreamId){ + String subject = StringUtils.joinWith(",", + // 发送者 channelId:流序号 + StringUtils.joinWith(":", senderId, senderStreamId), + // 接收者 id:流序号号 + StringUtils.joinWith(":", receiveId, receiveStreamId)); + return SipBuilder.createSubjectHeader(subject); + } + + public Request createPlayInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, String receiveId){ GB28181Description description = GB28181SDPBuilder.Receiver.play(getTargetId(), channelId, Connection.IP4,rtpIp,rtpPort,ssrc,mediaStreamMode); SIPRequest request = (SIPRequest) createRequest(METHOD, callId, cSeq, description); Address address = request.getFrom().getAddress(); - String subject = StringUtils.joinWith(",", - // 发送者 channelId:流序号 - StringUtils.joinWith(":", channelId, ssrc), - // 接收者 id:流序号号 - StringUtils.joinWith(":", getLocalId(), receiveId)); return SipBuilder.addHeaders(request, SipBuilder.createContactHeader(address), - SipBuilder.createSubjectHeader(subject)); + createSubject(channelId, ssrc, getLocalId(), receiveId)); } public Request createPlayInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode) { - return createPlayInviteRequest(callId, cSeq, channelId, rtpIp, rtpPort, ssrc, mediaStreamMode, 0); + return createPlayInviteRequest(callId, cSeq, channelId, rtpIp, rtpPort, ssrc, mediaStreamMode, String.valueOf(0)); + } + + public Request createPlaybackInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, String receiveId, Date startTime, Date endTime) { + GB28181Description description = GB28181SDPBuilder.Receiver.playback(getTargetId(), channelId, Connection.IP4, rtpIp, rtpPort, ssrc, mediaStreamMode, startTime, endTime); + + SIPRequest request = (SIPRequest) createRequest(METHOD, callId, cSeq, description); + Address address = request.getFrom().getAddress(); + + return SipBuilder.addHeaders(request, + SipBuilder.createContactHeader(address), + createSubject(channelId, ssrc, getLocalId(), receiveId)); + } + + public Request createPlaybackInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, Date startTime, Date endTime) { + return createPlaybackInviteRequest(callId, cSeq, channelId, rtpIp, rtpPort, ssrc, mediaStreamMode, String.valueOf(0), startTime, endTime); + } + + public Request createDownloadInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, String receiveId, Date startTime, Date endTime, Double downloadSpeed) { + GB28181Description description = GB28181SDPBuilder.Receiver.download(getTargetId(), channelId, Connection.IP4, rtpIp, rtpPort, ssrc, mediaStreamMode, startTime, endTime,downloadSpeed); + + SIPRequest request = (SIPRequest) createRequest(METHOD, callId, cSeq, description); + Address address = request.getFrom().getAddress(); + + return SipBuilder.addHeaders(request, + SipBuilder.createContactHeader(address), + createSubject(channelId, ssrc, getLocalId(), receiveId)); + } + + public Request createDownloadInviteRequest(String callId, long cSeq, String channelId, String rtpIp, int rtpPort, String ssrc, MediaStreamMode mediaStreamMode, Date startTime, Date endTime, Double downloadSpeed) { + return createDownloadInviteRequest(callId, cSeq, channelId, rtpIp, rtpPort, ssrc, mediaStreamMode, String.valueOf(0), startTime, endTime, downloadSpeed); } } diff --git a/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/process/RequestTest.java b/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/process/RequestTest.java index 8d0c107..c8e8d82 100644 --- a/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/process/RequestTest.java +++ b/gb28181-sip/src/test/java/cn/skcks/docking/gb28181/sip/process/RequestTest.java @@ -1,5 +1,6 @@ package cn.skcks.docking.gb28181.sip.process; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.RandomUtil; import cn.skcks.docking.gb28181.constant.CmdType; @@ -30,6 +31,7 @@ import javax.sip.header.WWWAuthenticateHeader; import javax.sip.message.Request; import javax.sip.message.Response; import java.util.Collections; +import java.util.Date; @Slf4j public class RequestTest { @@ -67,8 +69,20 @@ public class RequestTest { String playSsrc = "0" + ssrc; // 1 开头的为历史 String playBackSsrc = "1" + ssrc; + // 实时点播请求 Request playInviteRequest = inviteRequestBuilder.createPlayInviteRequest(callId, 1, localId, rtpIp, rtpPort, playSsrc, MediaStreamMode.TCP_ACTIVE); log.info("\n{}", playInviteRequest); + + Date now = DateUtil.date(); + Date startTime = DateUtil.beginOfDay(DateUtil.offsetDay(now,-1)); + Date endTime = DateUtil.endOfDay(DateUtil.offsetDay(now,-1)); + // 回放请求 + Request playbackInviteRequest = inviteRequestBuilder.createPlaybackInviteRequest(callId, 1, localId, rtpIp, rtpPort, playBackSsrc, MediaStreamMode.TCP_ACTIVE,startTime,endTime); + log.info("\n{}", playbackInviteRequest); + + // 下载请求 + Request downloadInviteRequest = inviteRequestBuilder.createDownloadInviteRequest(callId, 1, localId, rtpIp, rtpPort, playBackSsrc, MediaStreamMode.TCP_ACTIVE,startTime,endTime,4.0); + log.info("\n{}", downloadInviteRequest); }