From 503f891c9e443551309a91b38493ac49413dbe35 Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期五, 15 一月 2021 17:21:02 +0800
Subject: [PATCH] 完成向上级联->点播--增加了sdp解析 修复修改平台主键带来的bug
---
src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SessionDescription.java | 162 +++++++++
src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatformCatch.java | 10
src/main/java/com/genersoft/iot/vmp/storager/dao/PatformChannelMapper.java | 6
src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SdpLine.java | 38 ++
src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SdpParser.java | 230 ++++++++++++
src/main/java/com/genersoft/iot/vmp/conf/SipPlatformRunner.java | 4
src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java | 8
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java | 8
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java | 2
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java | 1
src/main/java/com/genersoft/iot/vmp/gb28181/sdp/RFC4566_28181.java | 51 ++
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java | 260 +++++++++++--
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java | 22 +
src/main/java/com/genersoft/iot/vmp/gb28181/sdp/MediaDescription.java | 123 ++++++
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java | 5
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java | 3
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java | 14
src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java | 14
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/RegisterResponseProcessor.java | 17
src/main/java/com/genersoft/iot/vmp/gb28181/sdp/Codec.java | 65 +++
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java | 14
21 files changed, 976 insertions(+), 81 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
index 5e796d7..6ad8e7e 100644
--- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
+++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
@@ -28,6 +28,8 @@
public static final String PLATFORM_REGISTER_PREFIX = "VMP_platform_register_";
+ public static final String PLATFORM_REGISTER_INFO_PREFIX = "VMP_platform_register_info_";
+
public static final String Pattern_Topic = "VMP_keeplive_platform_";
public static final String EVENT_ONLINE_REGISTER = "1";
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/SipPlatformRunner.java b/src/main/java/com/genersoft/iot/vmp/conf/SipPlatformRunner.java
index eae4547..106b3cf 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/SipPlatformRunner.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/SipPlatformRunner.java
@@ -45,11 +45,11 @@
ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
- parentPlatformCatch.setId(parentPlatform.getDeviceGBId());
+ parentPlatformCatch.setId(parentPlatform.getServerGBId());
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
// 鍙戦�佸钩鍙版湭娉ㄥ唽娑堟伅
- publisher.platformNotRegisterEventPublish(parentPlatform.getDeviceGBId());
+ publisher.platformNotRegisterEventPublish(parentPlatform.getServerGBId());
}
}
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatformCatch.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatformCatch.java
index 994039a..6c429f2 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatformCatch.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatformCatch.java
@@ -10,6 +10,8 @@
// 娉ㄥ唽鏈洖澶嶆鏁�
private int registerAliveReply;
+ private String callId;
+
private ParentPlatform parentPlatform;
public String getId() {
@@ -43,4 +45,12 @@
public void setParentPlatform(ParentPlatform parentPlatform) {
this.parentPlatform = parentPlatform;
}
+
+ public String getCallId() {
+ return callId;
+ }
+
+ public void setCallId(String callId) {
+ this.callId = callId;
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/Codec.java b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/Codec.java
new file mode 100755
index 0000000..4ab6f8f
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/Codec.java
@@ -0,0 +1,65 @@
+/*
+ This file is part of Peers, a java SIP softphone.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Yohann Martineau
+*/
+
+package com.genersoft.iot.vmp.gb28181.sdp;
+
+public class Codec {
+
+ private int payloadType;
+ private String name;
+
+ public int getPayloadType() {
+ return payloadType;
+ }
+
+ public void setPayloadType(int payloadType) {
+ this.payloadType = payloadType;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof Codec)) {
+ return false;
+ }
+ Codec codec = (Codec)obj;
+ if (codec.getName() == null) {
+ return name == null;
+ }
+ return codec.getName().equalsIgnoreCase(name);
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(RFC4566_28181.TYPE_ATTRIBUTE).append(RFC4566_28181.SEPARATOR);
+ buf.append(RFC4566_28181.ATTR_RTPMAP).append(RFC4566_28181.ATTR_SEPARATOR);
+ buf.append(payloadType).append(" ").append(name).append("/");
+ buf.append(9000).append("\r\n");
+ return buf.toString();
+ }
+
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/MediaDescription.java b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/MediaDescription.java
new file mode 100755
index 0000000..50f361f
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/MediaDescription.java
@@ -0,0 +1,123 @@
+/*
+ This file is part of Peers, a java SIP softphone.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2007, 2008, 2009, 2010 Yohann Martineau
+ */
+
+package com.genersoft.iot.vmp.gb28181.sdp;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.util.Hashtable;
+import java.util.List;
+
+public class MediaDescription {
+
+ private String type;
+ private InetAddress ipAddress;
+ // attributes not codec-related
+ private Hashtable<String, String> attributes;
+ private int port;
+ private List<Codec> codecs;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Hashtable<String, String> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(Hashtable<String, String> attributes) {
+ this.attributes = attributes;
+ }
+
+ public InetAddress getIpAddress() {
+ return ipAddress;
+ }
+
+ public void setIpAddress(InetAddress ipAddress) {
+ this.ipAddress = ipAddress;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public List<Codec> getCodecs() {
+ return codecs;
+ }
+
+ public void setCodecs(List<Codec> codecs) {
+ this.codecs = codecs;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(RFC4566_28181.TYPE_MEDIA).append(RFC4566_28181.SEPARATOR);
+ buf.append(type).append(" ").append(port);
+ buf.append(" RTP/AVP");
+ if (codecs != null) {
+ for (Codec codec: codecs) {
+ buf.append(" ");
+ buf.append(codec.getPayloadType());
+ }
+ buf.append("\r\n");
+ }
+ if (ipAddress != null) {
+ int ipVersion;
+ if (ipAddress instanceof Inet4Address) {
+ ipVersion = 4;
+ } else if (ipAddress instanceof Inet6Address) {
+ ipVersion = 6;
+ } else {
+ throw new RuntimeException("unknown ip version: " + ipAddress);
+ }
+ buf.append(RFC4566_28181.TYPE_CONNECTION).append(RFC4566_28181.SEPARATOR);
+ buf.append("IN IP").append(ipVersion).append(" ");
+ buf.append(ipAddress.getHostAddress()).append("\r\n");
+ }
+ if (codecs != null) {
+ for (Codec codec: codecs) {
+ buf.append(codec.toString());
+ }
+ }
+
+ if (attributes != null) {
+ for (String attributeName: attributes.keySet()) {
+ buf.append(RFC4566_28181.TYPE_ATTRIBUTE).append(RFC4566_28181.SEPARATOR);
+ buf.append(attributeName);
+ String attributeValue = attributes.get(attributeName);
+ if (attributeValue != null && !"".equals(attributeValue.trim())) {
+ buf.append(":").append(attributeValue);
+ }
+ buf.append("\r\n");
+ }
+ }
+ return buf.toString();
+ }
+
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/RFC4566_28181.java b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/RFC4566_28181.java
new file mode 100755
index 0000000..dd6019b
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/RFC4566_28181.java
@@ -0,0 +1,51 @@
+/*
+ This file is part of Peers, a java SIP softphone.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2007, 2008, 2009, 2010 Yohann Martineau
+*/
+
+package com.genersoft.iot.vmp.gb28181.sdp;
+
+public class RFC4566_28181 {
+
+ public static final char VERSION = '0';
+
+ public static final char TYPE_VERSION = 'v';
+ public static final char TYPE_ORIGIN = 'o';
+ public static final char TYPE_SUBJECT = 's';
+ public static final char TYPE_INFO = 'i';
+ public static final char TYPE_URI = 'u';
+ public static final char TYPE_EMAIL = 'e';
+ public static final char TYPE_PHONE = 'p';
+ public static final char TYPE_CONNECTION = 'c';
+ public static final char TYPE_BANDWITH = 'b';
+ public static final char TYPE_TIME = 't';
+ public static final char TYPE_REPEAT = 'r';
+ public static final char TYPE_ZONE = 'z';
+ public static final char TYPE_KEY = 'k';
+ public static final char TYPE_ATTRIBUTE = 'a';
+ public static final char TYPE_MEDIA = 'm';
+ public static final char TYPE_SSRC = 'y';
+ public static final char TYPE_MEDIA_DES = 'f';
+
+ public static final char SEPARATOR = '=';
+ public static final char ATTR_SEPARATOR = ':';
+
+ public static final String MEDIA_AUDIO = "audio";
+
+ public static final String ATTR_RTPMAP = "rtpmap";
+ public static final String ATTR_SENDRECV = "sendrecv";
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SdpLine.java b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SdpLine.java
new file mode 100755
index 0000000..2d57338
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SdpLine.java
@@ -0,0 +1,38 @@
+/*
+ This file is part of Peers, a java SIP softphone.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2007, 2008, 2009, 2010 Yohann Martineau
+*/
+
+package com.genersoft.iot.vmp.gb28181.sdp;
+
+public class SdpLine {
+ private char type;
+ private String value;
+ public char getType() {
+ return type;
+ }
+ public void setType(char type) {
+ this.type = type;
+ }
+ public String getValue() {
+ return value;
+ }
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SdpParser.java b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SdpParser.java
new file mode 100755
index 0000000..fb8d499
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SdpParser.java
@@ -0,0 +1,230 @@
+/*
+ This file is part of Peers, a java SIP softphone.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2007, 2008, 2009, 2010 Yohann Martineau
+*/
+
+package com.genersoft.iot.vmp.gb28181.sdp;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+public class SdpParser {
+
+ public SessionDescription parse(byte[] body) throws IOException {
+ if (body == null || body.length == 0) {
+ return null;
+ }
+ ByteArrayInputStream in = new ByteArrayInputStream(body);
+ InputStreamReader inputStreamReader = new InputStreamReader(in);
+ BufferedReader reader = new BufferedReader(inputStreamReader);
+ SessionDescription sessionDescription = new SessionDescription();
+
+ //version
+
+ String line = reader.readLine();
+ if (line.length() < 3) {
+ return null;
+ }
+ if (line.charAt(0) != RFC4566_28181.TYPE_VERSION
+ || line.charAt(1) != RFC4566_28181.SEPARATOR
+ || line.charAt(2) != RFC4566_28181.VERSION) {
+ return null;
+ }
+
+ //origin
+
+ line = reader.readLine();
+ if (line.length() < 3) {
+ return null;
+ }
+ if (line.charAt(0) != RFC4566_28181.TYPE_ORIGIN
+ || line.charAt(1) != RFC4566_28181.SEPARATOR) {
+ return null;
+ }
+ line = line.substring(2);
+ String[] originArr = line.split(" ");
+ if (originArr == null || originArr.length != 6) {
+ return null;
+ }
+ sessionDescription.setUsername(originArr[0]);
+ sessionDescription.setId(Long.parseLong(originArr[1]));
+ sessionDescription.setVersion(Long.parseLong(originArr[2]));
+ sessionDescription.setIpAddress(InetAddress.getByName(originArr[5]));
+
+ //name
+
+ line = reader.readLine();
+ if (line.length() < 3) {
+ return null;
+ }
+ if (line.charAt(0) != RFC4566_28181.TYPE_SUBJECT
+ || line.charAt(1) != RFC4566_28181.SEPARATOR) {
+ return null;
+ }
+ sessionDescription.setName(line.substring(2));
+
+ //session connection and attributes
+ Hashtable<String, String> sessionAttributes = new Hashtable<String, String>();
+ sessionDescription.setAttributes(sessionAttributes);
+
+ while ((line = reader.readLine()) != null
+ && line.charAt(0) != RFC4566_28181.TYPE_MEDIA) {
+ if (line.length() > 3
+ && line.charAt(0) == RFC4566_28181.TYPE_CONNECTION
+ && line.charAt(1) == RFC4566_28181.SEPARATOR) {
+ String connection = parseConnection(line.substring(2));
+ if (connection == null) {
+ continue;
+ }
+ sessionDescription.setIpAddress(InetAddress.getByName(connection));
+ } else if (line.length() > 3
+ && line.charAt(0) == RFC4566_28181.TYPE_ATTRIBUTE
+ && line.charAt(1) == RFC4566_28181.SEPARATOR) {
+ String value = line.substring(2);
+ int pos = value.indexOf(RFC4566_28181.ATTR_SEPARATOR);
+ if (pos > -1) {
+ sessionAttributes.put(value.substring(0, pos),
+ value.substring(pos + 1));
+ } else {
+ sessionAttributes.put(value, "");
+ }
+ }
+ }
+ if (line == null) {
+ return null;
+ }
+ //we are at the first media line
+
+ ArrayList<SdpLine> mediaLines = new ArrayList<SdpLine>();
+ do {
+ if (line.length() < 2) {
+ return null;
+ }
+ if (line.charAt(1) != RFC4566_28181.SEPARATOR) {
+ return null;
+ }
+ if (line.charAt(0) == RFC4566_28181.TYPE_SSRC) {
+ sessionDescription.setSsrc(line.length() >=2 ?line.substring(2):"");
+ }else if (line.charAt(0) == RFC4566_28181.TYPE_MEDIA_DES) {
+ sessionDescription.setGbMediaDescriptions(line.length() >=2 ?line.substring(2):"");
+ }else {
+ SdpLine mediaLine = new SdpLine();
+ mediaLine.setType(line.charAt(0));
+ mediaLine.setValue(line.substring(2));
+ mediaLines.add(mediaLine);
+ }
+
+ }
+ while ((line = reader.readLine()) != null );
+
+ ArrayList<MediaDescription> mediaDescriptions = new ArrayList<MediaDescription>();
+ sessionDescription.setMediaDescriptions(mediaDescriptions);
+
+ for (SdpLine sdpLine : mediaLines) {
+ MediaDescription mediaDescription;
+ if (sdpLine.getType() == RFC4566_28181.TYPE_MEDIA) {
+ String[] mediaArr = sdpLine.getValue().split(" ");
+ if (mediaArr == null || mediaArr.length < 4) {
+ return null;
+ }
+ mediaDescription = new MediaDescription();
+ mediaDescription.setType(mediaArr[0]);
+ //TODO manage port range
+ mediaDescription.setPort(Integer.parseInt(mediaArr[1]));
+ mediaDescription.setAttributes(new Hashtable<String, String>());
+ List<Codec> codecs = new ArrayList<Codec>();
+ for (int i = 3; i < mediaArr.length; ++i) {
+ int payloadType = Integer.parseInt(mediaArr[i]);
+ Codec codec = new Codec();
+ codec.setPayloadType(payloadType);
+ codec.setName("unsupported");
+ codecs.add(codec);
+ }
+ mediaDescription.setCodecs(codecs);
+ mediaDescriptions.add(mediaDescription);
+ } else {
+ mediaDescription = mediaDescriptions.get(mediaDescriptions.size() - 1);
+ String sdpLineValue = sdpLine.getValue();
+ if (sdpLine.getType() == RFC4566_28181.TYPE_CONNECTION) {
+ String ipAddress = parseConnection(sdpLineValue);
+ mediaDescription.setIpAddress(InetAddress.getByName(ipAddress));
+ } else if (sdpLine.getType() == RFC4566_28181.TYPE_ATTRIBUTE) {
+ Hashtable<String, String> attributes = mediaDescription.getAttributes();
+ int pos = sdpLineValue.indexOf(RFC4566_28181.ATTR_SEPARATOR);
+ if (pos > -1) {
+ String name = sdpLineValue.substring(0, pos);
+ String value = sdpLineValue.substring(pos + 1);
+ pos = value.indexOf(" ");
+ if (pos > -1) {
+ int payloadType;
+ try {
+ payloadType = Integer.parseInt(value.substring(0, pos));
+ List<Codec> codecs = mediaDescription.getCodecs();
+ for (Codec codec: codecs) {
+ if (codec.getPayloadType() == payloadType) {
+ value = value.substring(pos + 1);
+ pos = value.indexOf("/");
+ if (pos > -1) {
+ value = value.substring(0, pos);
+ codec.setName(value);
+ }
+ break;
+ }
+ }
+ } catch (NumberFormatException e) {
+ attributes.put(name, value);
+ }
+ } else {
+ attributes.put(name, value);
+ }
+ } else {
+ attributes.put(sdpLineValue, "");
+ }
+ }
+ }
+ }
+ sessionDescription.setMediaDescriptions(mediaDescriptions);
+
+ for (MediaDescription description : mediaDescriptions) {
+ if (description.getIpAddress() == null) {
+ InetAddress sessionAddress = sessionDescription.getIpAddress();
+ if (sessionAddress == null) {
+ return null;
+ }
+ description.setIpAddress(sessionAddress);
+ }
+ }
+
+
+ return sessionDescription;
+ }
+
+ private String parseConnection(String line) {
+ String[] connectionArr = line.split(" ");
+ if (connectionArr == null || connectionArr.length != 3) {
+ return null;
+ }
+ return connectionArr[2];
+ }
+
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SessionDescription.java b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SessionDescription.java
new file mode 100755
index 0000000..ad68099
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/sdp/SessionDescription.java
@@ -0,0 +1,162 @@
+/*
+ This file is part of Peers, a java SIP softphone.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2007, 2008, 2009, 2010 Yohann Martineau
+*/
+
+package com.genersoft.iot.vmp.gb28181.sdp;
+
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.util.Hashtable;
+import java.util.List;
+
+public class SessionDescription {
+
+ private long id;
+ private long version;
+ private String name;
+ private String username;
+ private InetAddress ipAddress;
+ private List<MediaDescription> mediaDescriptions;
+ private Hashtable<String, String> attributes;
+ private String ssrc;
+ private String gbMediaDescriptions;
+
+ public SessionDescription() {
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public InetAddress getIpAddress() {
+ return ipAddress;
+ }
+
+ public void setIpAddress(InetAddress ipAddress) {
+ this.ipAddress = ipAddress;
+ }
+
+ public List<MediaDescription> getMediaDescriptions() {
+ return mediaDescriptions;
+ }
+
+ public void setMediaDescriptions(List<MediaDescription> mediaDescriptions) {
+ this.mediaDescriptions = mediaDescriptions;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public long getVersion() {
+ return version;
+ }
+
+ public void setVersion(long version) {
+ this.version = version;
+ }
+
+ public Hashtable<String, String> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(Hashtable<String, String> attributes) {
+ this.attributes = attributes;
+ }
+
+ public String getSsrc() {
+ return ssrc;
+ }
+
+ public void setSsrc(String ssrc) {
+ this.ssrc = ssrc;
+ }
+
+ public String getGbMediaDescriptions() {
+ return gbMediaDescriptions;
+ }
+
+ public void setGbMediaDescriptions(String gbMediaDescriptions) {
+ this.gbMediaDescriptions = gbMediaDescriptions;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("v=0\r\n");
+ buf.append("o=").append(username).append(" ").append(id);
+ buf.append(" ").append(version);
+ int ipVersion;
+ if (ipAddress instanceof Inet4Address) {
+ ipVersion = 4;
+ } else if (ipAddress instanceof Inet6Address) {
+ ipVersion = 6;
+ } else {
+ throw new RuntimeException("unknown ip version: " + ipAddress);
+ }
+ buf.append(" IN IP").append(ipVersion).append(" ");
+ String hostAddress = ipAddress.getHostAddress();
+ buf.append(hostAddress).append("\r\n");
+ buf.append("s=").append(name).append("\r\n");
+ buf.append("c=IN IP").append(ipVersion).append(" ");
+ buf.append(hostAddress).append("\r\n");
+ buf.append("t=0 0\r\n");
+ if (attributes != null){
+ for (String attributeName: attributes.keySet()) {
+ String attributeValue = attributes.get(attributeName);
+ buf.append("a=").append(attributeName);
+ if (attributeValue != null && !"".equals(attributeValue.trim())) {
+ buf.append(":");
+ buf.append(attributeValue);
+ buf.append("\r\n");
+ }
+ }
+ }
+ if (mediaDescriptions != null){
+ for (MediaDescription mediaDescription: mediaDescriptions) {
+ buf.append(mediaDescription.toString());
+ }
+ }
+
+ if (ssrc != null){
+ buf.append("y=").append(ssrc).append("\r\n");
+ }
+ if (gbMediaDescriptions != null){
+ buf.append("f=").append(gbMediaDescriptions).append("\r\n");
+ }
+ return buf.toString();
+ }
+
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
index eb81ed3..75db910 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
@@ -119,6 +119,9 @@
processor.setRequestEvent(evt);
processor.setTcpSipProvider(getTcpSipProvider());
processor.setUdpSipProvider(getUdpSipProvider());
+
+ processor.setCmderFroPlatform(cmderFroPlatform);
+ processor.setStorager(storager);
return processor;
} else if (Request.REGISTER.equals(method)) {
RegisterRequestProcessor processor = new RegisterRequestProcessor();
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
index 2ba84ac..b038ec2 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
@@ -70,7 +70,7 @@
@Override
public boolean unregister(ParentPlatform parentPlatform, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) {
parentPlatform.setExpires("0");
- ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getDeviceGBId());
+ ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId());
if (parentPlatformCatch != null) {
parentPlatformCatch.setParentPlatform(parentPlatform);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
@@ -86,11 +86,21 @@
if (www == null ) {
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, 1L, null, null);
+ // 灏� callid 鍐欏叆缂撳瓨锛� 绛夋敞鍐屾垚鍔熷彲浠ユ洿鏂扮姸鎬�
+ CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME);
+ redisCatchStorage.updatePlatformRegisterInfo(callIdHeader.getCallId(), parentPlatform.getServerGBId());
+
+ sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (event)->{
+ redisCatchStorage.delPlatformRegisterInfo(callIdHeader.getCallId());
+ if (errorEvent != null) {
+ errorEvent.response(event);
+ }
+ });
}else {
request = headerProviderPlarformProvider.createRegisterRequest(parentPlatform, null, null, callId, www);
}
- transmitRequest(parentPlatform, request, errorEvent, okEvent);
+ transmitRequest(parentPlatform, request, null, okEvent);
return true;
} catch (ParseException e) {
e.printStackTrace();
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
index ab70a5e..c15b7ca 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
@@ -1,71 +1,231 @@
package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
+import javax.sip.InvalidArgumentException;
import javax.sip.RequestEvent;
+import javax.sip.SipException;
+import javax.sip.address.SipURI;
+import javax.sip.header.ContentTypeHeader;
+import javax.sip.header.FromHeader;
+import javax.sip.header.SubjectHeader;
+import javax.sip.message.Request;
+import javax.sip.message.Response;
+import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
+import com.genersoft.iot.vmp.gb28181.sdp.Codec;
+import com.genersoft.iot.vmp.gb28181.sdp.MediaDescription;
+import com.genersoft.iot.vmp.gb28181.sdp.SdpParser;
+import com.genersoft.iot.vmp.gb28181.sdp.SessionDescription;
+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.transmit.request.SIPRequestAbstractProcessor;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import gov.nist.javax.sip.address.AddressImpl;
+import gov.nist.javax.sip.address.SipUri;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.List;
/**
* @Description:澶勭悊INVITE璇锋眰
- * @author: swwheihei
- * @date: 2020骞�5鏈�3鏃� 涓嬪崍4:43:52
+ * @author: panll
+ * @date: 2021骞�1鏈�14鏃�
*/
public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
+
+ private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class);
+
+ private SIPCommanderFroPlatform cmderFroPlatform;
+
+ private IVideoManagerStorager storager;
/**
* 澶勭悊invite璇锋眰
*
- * @param request
+ * @param evt
* 璇锋眰娑堟伅
*/
@Override
public void process(RequestEvent evt) {
- // TODO 浼樺厛绾�99 Invite Request娑堟伅瀹炵幇锛屾娑堟伅涓�鑸负绾ц仈娑堟伅锛屼笂绾х粰涓嬬骇鍙戦�佽姹傝棰戞寚浠�
-// Request request = requestEvent.getRequest();
-//
-// try {
-// // 鍙戦��100 Trying
-// ServerTransaction serverTransaction = getServerTransaction(requestEvent);
-// // 鏌ヨ鐩爣鍦板潃
-// URI reqUri = request.getRequestURI();
-// URI contactURI = currUser.get(reqUri);
-//
-// System.out.println("processInvite rqStr=" + reqUri + " contact=" + contactURI);
-//
-// // 鏍规嵁Request uri鏉ヨ矾鐢憋紝鍚庣画鐨勫搷搴旀秷鎭�氳繃VIA鏉ヨ矾鐢�
-// Request cliReq = messageFactory.createRequest(request.toString());
-// cliReq.setRequestURI(contactURI);
-//
-// HeaderFactory headerFactory = SipFactory.getInstance().createHeaderFactory();
-// Via callerVia = (Via) request.getHeader(Via.NAME);
-// Via via = (Via) headerFactory.createViaHeader(SIPMain.ip, SIPMain.port, "UDP",
-// callerVia.getBranch() + "sipphone");
-//
-// cliReq.removeHeader(Via.NAME);
-// cliReq.addHeader(via);
-//
-// // 鏇存柊contact鐨勫湴鍧�
-// ContactHeader contactHeader = headerFactory.createContactHeader();
-// Address address = SipFactory.getInstance().createAddressFactory()
-// .createAddress("sip:sipsoft@" + SIPMain.ip + ":" + SIPMain.port);
-// contactHeader.setAddress(address);
-// contactHeader.setExpires(3600);
-// cliReq.setHeader(contactHeader);
-//
-// clientTransactionId = sipProvider.getNewClientTransaction(cliReq);
-// clientTransactionId.sendRequest();
-//
-// System.out.println("processInvite clientTransactionId=" + clientTransactionId.toString());
-//
-// System.out.println("send invite to callee: " + cliReq);
-// } catch (TransactionUnavailableException e1) {
-// e1.printStackTrace();
-// } catch (SipException e) {
-// e.printStackTrace();
-// } catch (ParseException e) {
-// e.printStackTrace();
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
+ // Invite Request娑堟伅瀹炵幇锛屾娑堟伅涓�鑸负绾ц仈娑堟伅锛屼笂绾х粰涓嬬骇鍙戦�佽姹傝棰戞寚浠�
+ try {
+ Request request = evt.getRequest();
+ SipURI sipURI = (SipURI) request.getRequestURI();
+ String channelId = sipURI.getUser();
+ String platformId = null;
+// SubjectHeader subjectHeader = (SubjectHeader)request.getHeader(SubjectHeader.NAME);
+// // 鏌ヨ閫氶亾鏄惁瀛樺湪 涓嶅瓨鍦ㄥ洖澶�404
+// if (subjectHeader != null) { // 瀛樺湪鍒欎粠subjectHeader 鑾峰彇骞冲彴淇℃伅
+// String subject = subjectHeader.getSubject();
+// if (subject != null) {
+// String[] info1 = subject.split(",");
+// if (info1 != null && info1 .length == 2) {
+// String[] info2 = info1[1].split(":");
+// if (info2 != null && info2.length == 2) {
+// platformId = info2[0];
+// }
+// }
+// }
+// }
+
+ FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME);
+ AddressImpl address = (AddressImpl) fromHeader.getAddress();
+ SipUri uri = (SipUri) address.getURI();
+ platformId = uri.getUser();
+
+// if (platformId == null) { // 涓嶅瓨鍦ㄥ垯浠巉romHeader 鑾峰彇骞冲彴淇℃伅
+// FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME);
+// platformId = fromHeader.getName();
+// }
+ if (platformId == null || channelId == null) {
+ response400Ack(evt); // 鍙傛暟涓嶅叏锛� 鍙�400锛岃姹傞敊璇�
+ return;
+ }
+ // 鏌ヨ骞冲彴涓嬫槸鍚︽湁璇ラ�氶亾
+ DeviceChannel channel = storager.queryChannelInParentPlatform(platformId, channelId);
+ if (channel == null) {
+ response404Ack(evt); // 閫氶亾涓嶅瓨鍦紝鍙�404锛岃祫婧愪笉瀛樺湪
+ return;
+ }else {
+ response100Ack(evt); // 閫氶亾瀛樺湪锛屽彂100锛宼rying
+ }
+ // 瑙f瀽sdp娑堟伅
+ byte[] sdpByteArray = request.getRawContent();
+ SdpParser sdpParser = new SdpParser(); // TODO keng
+ SessionDescription sdp = sdpParser.parse(sdpByteArray);
+ // 鑾峰彇鏀寔鐨勬牸寮�
+ List<MediaDescription> mediaDescriptions = sdp.getMediaDescriptions();
+ // 鏌ョ湅鏄惁鏀寔PS 璐熻浇96
+ String ip = null;
+ int port = -1;
+ for (MediaDescription mediaDescription : mediaDescriptions) {
+
+ List<Codec> codecs = mediaDescription.getCodecs();
+ for (Codec codec : codecs) {
+ if("96".equals(codec.getPayloadType()) || "PS".equals(codec.getName()) || "ps".equals(codec.getName())) {
+ ip = mediaDescription.getIpAddress().getHostName();
+ port = mediaDescription.getPort();
+ break;
+ }
+ }
+ }
+ if (ip == null || port == -1) { // TODO 娌℃湁鍚堥�傜殑瑙嗛娴佹牸寮忥紝 鍙厤缃槸鍚︿娇鐢ㄧ涓�涓猰edia淇℃伅
+ if (mediaDescriptions.size() > 0) {
+ ip = mediaDescriptions.get(0).getIpAddress().getHostName();
+ port = mediaDescriptions.get(0).getPort();
+ }
+ }
+
+ if (ip == null || port == -1) {
+ response488Ack(evt);
+ return;
+ }
+
+
+ String ssrc = sdp.getSsrc();
+ // 閫氱煡涓嬬骇鎺ㄦ祦锛�
+ // 鏌ユ壘鍚堥�傜殑绔彛鎺ㄦ祦锛�
+ // 鍙戦�� 200ok
+ // 鏀跺埌ack鍚庤皟鐢ㄦ帹娴佹帴鍙�
+
+
+
+
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ logger.warn("sdp瑙f瀽閿欒");
+ e.printStackTrace();
+ }
+
}
+ /***
+ * 鍥炲100 trying
+ * @param evt
+ * @throws SipException
+ * @throws InvalidArgumentException
+ * @throws ParseException
+ */
+ private void response100Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
+ Response response = getMessageFactory().createResponse(Response.TRYING, evt.getRequest());
+ getServerTransaction(evt).sendResponse(response);
+ }
+
+ /***
+ * 鍥炲404
+ * @param evt
+ * @throws SipException
+ * @throws InvalidArgumentException
+ * @throws ParseException
+ */
+ private void response404Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
+ Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
+ getServerTransaction(evt).sendResponse(response);
+ }
+
+ /***
+ * 鍥炲400
+ * @param evt
+ * @throws SipException
+ * @throws InvalidArgumentException
+ * @throws ParseException
+ */
+ private void response400Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
+ Response response = getMessageFactory().createResponse(Response.BAD_REQUEST, evt.getRequest());
+ getServerTransaction(evt).sendResponse(response);
+ }
+
+ /***
+ * 鍥炲488
+ * @param evt
+ * @throws SipException
+ * @throws InvalidArgumentException
+ * @throws ParseException
+ */
+ private void response488Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
+ Response response = getMessageFactory().createResponse(Response.NOT_ACCEPTABLE_HERE, evt.getRequest());
+ getServerTransaction(evt).sendResponse(response);
+ }
+
+ /***
+ * 鍥炲200 OK
+ * @param evt
+ * @throws SipException
+ * @throws InvalidArgumentException
+ * @throws ParseException
+ */
+ private void responseAck(RequestEvent evt, String sdp) throws SipException, InvalidArgumentException, ParseException {
+ Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
+ ContentTypeHeader contentTypeHeader = getHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
+ response.setContent(sdp, contentTypeHeader);
+ getServerTransaction(evt).sendResponse(response);
+ }
+
+
+
+
+
+
+
+
+
+
+ public SIPCommanderFroPlatform getCmderFroPlatform() {
+ return cmderFroPlatform;
+ }
+
+ public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) {
+ this.cmderFroPlatform = cmderFroPlatform;
+ }
+
+ public IVideoManagerStorager getStorager() {
+ return storager;
+ }
+
+ public void setStorager(IVideoManagerStorager storager) {
+ this.storager = storager;
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
index 9ad928d..06c4d68 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
@@ -15,6 +15,8 @@
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
+import gov.nist.javax.sip.address.AddressImpl;
+import gov.nist.javax.sip.address.SipUri;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
@@ -166,10 +168,15 @@
Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText();
Element deviceListElement = rootElement.element("DeviceList");
+
+ FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
+ AddressImpl address = (AddressImpl) fromHeader.getAddress();
+ SipUri uri = (SipUri) address.getURI();
+ String platformId = uri.getUser();
// if (deviceListElement == null) { // 瀛樺湪DeviceList鍒欎负鍝嶅簲 catalog锛� 涓嶅瓨鍦―eviceList鍒欎负鏌ヨ璇锋眰
if (name == "Query") { // 鍖哄垎鏄疪esponse鈥斺�旀煡璇㈠搷搴旓紝杩樻槸Query鈥斺�旀煡璇㈣姹�
// TODO 鍚庣画灏嗕唬鐮佹媶鍒�
- ParentPlatform parentPlatform = storager.queryParentPlatById(deviceId);
+ ParentPlatform parentPlatform = storager.queryParentPlatById(platformId);
if (parentPlatform == null) {
response404Ack(evt);
return;
@@ -179,9 +186,8 @@
Element snElement = rootElement.element("SN");
String sn = snElement.getText();
- FromHeader fromHeader = (FromHeader)evt.getRequest().getHeader(FromHeader.NAME);
// 鍑嗗鍥炲閫氶亾淇℃伅
- List<ChannelReduce> channelReduces = storager.queryChannelListInParentPlatform(parentPlatform.getDeviceGBId());
+ List<ChannelReduce> channelReduces = storager.queryChannelListInParentPlatform(parentPlatform.getServerGBId());
if (channelReduces.size() >0 ) {
for (ChannelReduce channelReduce : channelReduces) {
DeviceChannel deviceChannel = storager.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId());
@@ -499,7 +505,7 @@
}
/***
- * 鍥炲200 OK
+ * 鍥炲404
* @param evt
* @throws SipException
* @throws InvalidArgumentException
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/RegisterResponseProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/RegisterResponseProcessor.java
index bfe5e3f..4716a30 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/RegisterResponseProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/response/impl/RegisterResponseProcessor.java
@@ -61,10 +61,14 @@
public void process(ResponseEvent evt, SipLayer layer, SipConfig config) {
// TODO Auto-generated method stub
Response response = evt.getResponse();
- ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
- SipUri uri = (SipUri)toHeader.getAddress().getURI();
- String platformGBId = uri.getAuthority().getUser();
+ CallIdHeader callIdHeader = (CallIdHeader) response.getHeader(CallIdHeader.NAME);
+ String callId = callIdHeader.getCallId();
+ String platformGBId = redisCatchStorage.queryPlatformRegisterInfo(callId);
+ if (platformGBId == null) {
+ logger.info(String.format("鏈壘鍒癱allId锛� %s 鐨勬敞鍐�/娉ㄩ攢骞冲彴id", callId ));
+ return;
+ }
logger.info(String.format("鏀跺埌 %s 鐨勬敞鍐�/娉ㄩ攢%S鍝嶅簲", platformGBId, response.getStatusCode() ));
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(platformGBId);
@@ -80,18 +84,13 @@
if (response.getStatusCode() == 401) {
WWWAuthenticateHeader www = (WWWAuthenticateHeader)response.getHeader(WWWAuthenticateHeader.NAME);
-
-
- CallIdHeader callIdHeader = (CallIdHeader)response.getHeader(CallIdHeader.NAME);
- String callId = callIdHeader.getCallId();
-
sipCommanderForPlatform.register(parentPlatform, callId, www, null, null);
}else if (response.getStatusCode() == 200){
// 娉ㄥ唽鎴愬姛
logger.info(String.format("%s 娉ㄥ唽鎴愬姛", platformGBId ));
+ redisCatchStorage.delPlatformRegisterInfo(callId);
parentPlatform.setStatus(true);
storager.updateParentPlatform(parentPlatform);
- //
redisCatchStorage.updatePlatformRegister(parentPlatform);
redisCatchStorage.updatePlatformKeepalive(parentPlatform);
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
index 2e55a00..49e5578 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -73,4 +73,9 @@
void delPlatformRegister(String platformGbId);
+ void updatePlatformRegisterInfo(String callId, String platformGbId);
+
+ String queryPlatformRegisterInfo(String callId);
+
+ void delPlatformRegisterInfo(String callId);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
index 970f7a4..7963109 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
@@ -233,4 +233,5 @@
int delChannelForGB(String platformId, List<ChannelReduce> channelReduces);
+ DeviceChannel queryChannelInParentPlatform(String platformId, String channelId);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java
index 6d5d83b..257ca9e 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java
@@ -24,7 +24,7 @@
@Update("UPDATE parent_platform " +
"SET enable=#{enable}, " +
"name=#{name}," +
- "serverGBId=#{serverGBId}," +
+ "deviceGBId=#{deviceGBId}," +
"serverGBDomain=#{serverGBDomain}, " +
"serverIP=#{serverIP}," +
"serverPort=#{serverPort}, " +
@@ -39,13 +39,13 @@
"PTZEnable=#{PTZEnable}, " +
"rtcp=#{rtcp}, " +
"status=#{status} " +
- "WHERE deviceGBId=#{deviceGBId}")
+ "WHERE serverGBId=#{serverGBId}")
int updateParentPlatform(ParentPlatform parentPlatform);
- @Delete("DELETE FROM parent_platform WHERE deviceGBId=#{deviceGBId}")
+ @Delete("DELETE FROM parent_platform WHERE serverGBId=#{serverGBId}")
int delParentPlatform(ParentPlatform parentPlatform);
- @Select("SELECT *,( SELECT count(0) FROM platform_gb_channel pc WHERE pc.platformId = pp.deviceGBId) as channelCount FROM parent_platform pp ")
+ @Select("SELECT *,( SELECT count(0) FROM platform_gb_channel pc WHERE pc.platformId = pp.serverGBId) as channelCount FROM parent_platform pp ")
List<ParentPlatform> getParentPlatformList();
@Select("SELECT * FROM parent_platform WHERE enable=#{enable}")
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/PatformChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/PatformChannelMapper.java
index cbc56fc..a5ee275 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/PatformChannelMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/PatformChannelMapper.java
@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.storager.dao;
+import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
@@ -39,4 +40,9 @@
"DELETE FROM platform_gb_channel WHERE platformId='${platformId}'" +
"</script>")
int cleanChannelForGB(String platformId);
+
+
+ @Select("SELECT * FROM device_channel WHERE deviceId = (SELECT deviceId FROM platform_gb_channel WHERE " +
+ "platformId='${platformId}' AND channelId='${channelId}' ) AND channelId='${channelId}'")
+ DeviceChannel queryChannelInParentPlatform(String platformId, String channelId);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
index 63abc80..960e728 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -169,13 +169,13 @@
@Override
public void updatePlatformKeepalive(ParentPlatform parentPlatform) {
- String key = VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + parentPlatform.getDeviceGBId();
+ String key = VideoManagerConstants.PLATFORM_KEEPLIVEKEY_PREFIX + parentPlatform.getServerGBId();
redis.set(key, "", Integer.parseInt(parentPlatform.getKeepTimeout()));
}
@Override
public void updatePlatformRegister(ParentPlatform parentPlatform) {
- String key = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + parentPlatform.getDeviceGBId();
+ String key = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + parentPlatform.getServerGBId();
redis.set(key, "", Integer.parseInt(parentPlatform.getExpires()));
}
@@ -198,4 +198,22 @@
public void delPlatformRegister(String platformGbId) {
redis.del(VideoManagerConstants.PLATFORM_REGISTER_PREFIX + platformGbId);
}
+
+
+ @Override
+ public void updatePlatformRegisterInfo(String callId, String platformGbId) {
+ String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId;
+ redis.set(key, platformGbId);
+ }
+
+
+ @Override
+ public String queryPlatformRegisterInfo(String callId) {
+ return (String)redis.get(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId);
+ }
+
+ @Override
+ public void delPlatformRegisterInfo(String callId) {
+ redis.del(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId);
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
index 4547d76..aa83e3d 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
@@ -254,7 +254,7 @@
public boolean deleteParentPlatform(ParentPlatform parentPlatform) {
int result = platformMapper.delParentPlatform(parentPlatform);
// 鍒犻櫎鍏宠仈鐨勯�氶亾
- patformChannelMapper.cleanChannelForGB(parentPlatform.getDeviceGBId());
+ patformChannelMapper.cleanChannelForGB(parentPlatform.getServerGBId());
return result > 0;
}
@@ -329,4 +329,10 @@
return result;
}
+
+ @Override
+ public DeviceChannel queryChannelInParentPlatform(String platformId, String channelId) {
+ DeviceChannel channel = patformChannelMapper.queryChannelInParentPlatform(platformId, channelId);
+ return channel;
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
index 031fb09..ca116d5 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
@@ -110,7 +110,7 @@
if (logger.isDebugEnabled()) {
logger.debug("鏌ヨ鎵�鏈変笂绾ц澶嘇PI璋冪敤");
}
- if (StringUtils.isEmpty(parentPlatform.getDeviceGBId())
+ if (StringUtils.isEmpty(parentPlatform.getServerGBId())
){
return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
}
@@ -118,14 +118,14 @@
// 鍙戦�佺绾挎秷鎭�,鏃犺鏄惁鎴愬姛閮藉垹闄ょ紦瀛�
commanderForPlatform.unregister(parentPlatform, (event -> {
// 娓呯┖redis缂撳瓨
- redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
- redisCatchStorage.delPlatformKeepalive(parentPlatform.getDeviceGBId());
- redisCatchStorage.delPlatformRegister(parentPlatform.getDeviceGBId());
+ redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
+ redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
+ redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
}), (event -> {
// 娓呯┖redis缂撳瓨
- redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
- redisCatchStorage.delPlatformKeepalive(parentPlatform.getDeviceGBId());
- redisCatchStorage.delPlatformRegister(parentPlatform.getDeviceGBId());
+ redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
+ redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
+ redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
}));
boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
--
Gitblit v1.8.0