From f452e3af3bc72448a018a9c131bc3d492c97d86c Mon Sep 17 00:00:00 2001 From: shikong <919411476@qq.com> Date: Fri, 12 Jan 2024 11:16:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E5=90=88=20=E5=9B=9E=E6=94=BE=20?= =?UTF-8?q?=E5=92=8C=20=E4=B8=8B=E8=BD=BD=20sdp=20=E6=9E=84=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/InviteRequestProcessor.java | 47 +++++-------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/processor/invite/request/InviteRequestProcessor.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/processor/invite/request/InviteRequestProcessor.java index dab73ca..39c79fc 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/processor/invite/request/InviteRequestProcessor.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/core/sip/message/processor/invite/request/InviteRequestProcessor.java @@ -13,12 +13,9 @@ import cn.skcks.docking.gb28181.mocking.service.device.DeviceProxyService; import cn.skcks.docking.gb28181.mocking.service.device.DeviceService; import cn.skcks.docking.gb28181.sdp.GB28181Description; import cn.skcks.docking.gb28181.sdp.GB28181SDPBuilder; +import cn.skcks.docking.gb28181.sdp.media.MediaStreamMode; import cn.skcks.docking.gb28181.sdp.parser.GB28181DescriptionParser; -import gov.nist.core.Separators; -import gov.nist.javax.sdp.SessionDescriptionImpl; import gov.nist.javax.sdp.TimeDescriptionImpl; -import gov.nist.javax.sdp.fields.AttributeField; -import gov.nist.javax.sdp.fields.ConnectionField; import gov.nist.javax.sdp.fields.TimeField; import gov.nist.javax.sip.message.SIPRequest; import jakarta.annotation.PostConstruct; @@ -32,7 +29,6 @@ import javax.sdp.*; import javax.sip.RequestEvent; import javax.sip.message.Request; import javax.sip.message.Response; -import java.util.Arrays; import java.util.Date; import java.util.EventObject; import java.util.Vector; @@ -99,8 +95,8 @@ public class InviteRequestProcessor implements MessageProcessor { log.info("点播/回放请求"); if (StringUtils.equalsIgnoreCase(type, "Play")) { // 暂不支持实时 - sender.sendResponse(senderIp, transport, unsupported(request)); - // play(request, device, gb28181Description, (MediaDescription) item); +// sender.sendResponse(senderIp, transport, unsupported(request)); + play(request, device, gb28181Description, (MediaDescription) item); } else { playback(request, device, gb28181Description, (MediaDescription) item); } @@ -193,33 +189,16 @@ public class InviteRequestProcessor implements MessageProcessor { return; } - SdpFactory sdpFactory = SdpFactory.getInstance(); - SessionDescriptionImpl sessionDescription = new SessionDescriptionImpl(); - GB28181Description description = new GB28181Description(sessionDescription); - description.setVersion(sdpFactory.createVersion(0)); - // 目前只配置 ipv4 - description.setOrigin(sdpFactory.createOrigin(channelId, 0, 0, ConnectionField.IN, Connection.IP4, senderIp)); - description.setSessionName(gb28181Description.getSessionName()); - description.setConnection(sdpFactory.createConnection(ConnectionField.IN, Connection.IP4, senderIp)); - TimeField respTime = new TimeField(); - respTime.setZero(); - TimeDescription timeDescription = SdpFactory.getInstance().createTimeDescription(respTime); - description.setTimeDescriptions(new Vector<>() {{ - add(timeDescription); - }}); - String[] mediaTypeCodes = new String[]{"98","96"}; - String protocol = ((MediaDescription) gb28181Description.getMediaDescriptions(true).get(0)).getMedia().getProtocol(); - MediaDescription respMediaDescription = SdpFactory.getInstance().createMediaDescription("video", port, 0, StringUtils.isBlank(protocol)?SdpConstants.RTP_AVP:protocol, mediaTypeCodes); - Arrays.stream(mediaTypeCodes).forEach((k)->{ - String v = GB28181SDPBuilder.RTPMAP.get(k); - respMediaDescription.addAttribute((AttributeField) SdpFactory.getInstance().createAttribute(SdpConstants.RTPMAP, StringUtils.joinWith(Separators.SP,k,v))); - }); - respMediaDescription.addAttribute((AttributeField) SdpFactory.getInstance().createAttribute("sendonly", null)); + GB28181SDPBuilder.Action action = isDownload ? GB28181SDPBuilder.Action.DOWNLOAD : GB28181SDPBuilder.Action.PLAY_BACK; + TimeField timeField = new TimeField(); + timeField.setZero(); + GB28181Description sdp = GB28181SDPBuilder.Sender.build(action, + device.getGbDeviceId(), + channelId, Connection.IP4, address, port, + gb28181Description.getSsrcField().getSsrc(), + MediaStreamMode.of(((MediaDescription) gb28181Description.getMediaDescriptions(true).get(0)).getMedia().getProtocol()), + SdpFactory.getInstance().createTimeDescription(timeField)); - description.setMediaDescriptions(new Vector<>(){{ - add(respMediaDescription); - }}); - description.setSsrcField(gb28181Description.getSsrcField()); String ssrc = gb28181Description.getSsrcField().getSsrc(); String callId = request.getCallId().getCallId(); String key = GenericSubscribe.Helper.getKey(Request.ACK, callId); @@ -239,7 +218,7 @@ public class InviteRequestProcessor implements MessageProcessor { scheduledExecutorService.schedule(()->{ // 发送 sdp 响应 - sender.sendResponse(senderIp, transport, (ignore, ignore2, ignore3) -> SipResponseBuilder.responseSdp(request, description)); + sender.sendResponse(senderIp, transport, (ignore, ignore2, ignore3) -> SipResponseBuilder.responseSdp(request, sdp)); }, 1,TimeUnit.SECONDS); }