From 2f165d595af3565bd17612ee0f5866ace8ab43f4 Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期二, 02 三月 2021 18:23:06 +0800
Subject: [PATCH] 对级联点播信令进行处理

---
 src/main/java/com/genersoft/iot/vmp/gb28181/bean/SendRtpItem.java                             |  150 ++++++++++++++++++
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java |  256 +++++++++++--------------------
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java                        |   32 ++++
 src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java                  |   11 
 src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java                          |    3 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java                 |    1 
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java    |    9 
 src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java                         |    2 
 8 files changed, 294 insertions(+), 170 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 832bce3..8e9e871 100644
--- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
+++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
@@ -30,6 +30,8 @@
 
 	public static final String PLATFORM_REGISTER_INFO_PREFIX = "VMP_platform_register_info_";
 
+	public static final String PLATFORM_SEND_RTP_INFO_PREFIX = "VMP_platform_send_rtp_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/gb28181/bean/SendRtpItem.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SendRtpItem.java
new file mode 100644
index 0000000..f3ec337
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SendRtpItem.java
@@ -0,0 +1,150 @@
+package com.genersoft.iot.vmp.gb28181.bean;
+
+public class SendRtpItem {
+
+    /**
+     * 鎺ㄦ祦ip
+     */
+    private String ip;
+
+    /**
+     * 鎺ㄦ祦绔彛
+     */
+    private int port;
+
+    /**
+     * 鎺ㄦ祦鏍囪瘑
+     */
+    private String ssrc;
+
+    /**
+     * 骞冲彴id
+     */
+    private String platformId;
+
+    /**
+     * 閫氶亾id
+     */
+    private String channelId;
+
+    /**
+     * 鎺ㄦ祦鐘舵��
+     * 0 绛夊緟璁惧鎺ㄦ祦涓婃潵
+     * 1 绛夊緟涓婄骇骞冲彴鍥炲ack
+     * 2 鎺ㄦ祦涓�
+     */
+    private int status = 0;
+
+    /**
+     * 璁惧鎺ㄦ祦鐨刟pp
+     */
+    private String app = "rtp";
+
+    /**
+     * 璁惧鎺ㄦ祦鐨剆treamId
+     */
+    private String streamId;
+
+    /**
+     * 鏄惁涓簍cp
+     */
+    private boolean tcp;
+
+    /**
+     * 鏄惁涓簍cp涓诲姩妯″紡
+     */
+    private boolean tcpActive;
+
+    /**
+     * 鑷繁鎺ㄦ祦浣跨敤鐨勭鍙�
+     */
+    private int localPort;
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public String getSsrc() {
+        return ssrc;
+    }
+
+    public void setSsrc(String ssrc) {
+        this.ssrc = ssrc;
+    }
+
+    public String getPlatformId() {
+        return platformId;
+    }
+
+    public void setPlatformId(String platformId) {
+        this.platformId = platformId;
+    }
+
+    public String getChannelId() {
+        return channelId;
+    }
+
+    public void setChannelId(String channelId) {
+        this.channelId = channelId;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public void setStatus(int status) {
+        this.status = status;
+    }
+
+    public String getApp() {
+        return app;
+    }
+
+    public void setApp(String app) {
+        this.app = app;
+    }
+
+    public String getStreamId() {
+        return streamId;
+    }
+
+    public void setStreamId(String streamId) {
+        this.streamId = streamId;
+    }
+
+    public boolean isTcp() {
+        return tcp;
+    }
+
+    public void setTcp(boolean tcp) {
+        this.tcp = tcp;
+    }
+
+    public int getLocalPort() {
+        return localPort;
+    }
+
+    public void setLocalPort(int localPort) {
+        this.localPort = localPort;
+    }
+
+    public boolean isTcpActive() {
+        return tcpActive;
+    }
+
+    public void setTcpActive(boolean tcpActive) {
+        this.tcpActive = tcpActive;
+    }
+}
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 9c8129d..829bc7f 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
@@ -136,6 +136,7 @@
 			processor.setCmderFroPlatform(cmderFroPlatform);
 			processor.setPlayService(playService);
 			processor.setStorager(storager);
+			processor.setRedisCatchStorage(redisCatchStorage);
 			processor.setZlmrtpServerFactory(zlmrtpServerFactory);
 			return processor;
 		} else if (Request.REGISTER.equals(method)) {
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
index 13d630c..b72f013 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
@@ -1,9 +1,6 @@
 package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
 
-import javax.sip.Dialog;
-import javax.sip.InvalidArgumentException;
-import javax.sip.RequestEvent;
-import javax.sip.SipException;
+import javax.sip.*;
 import javax.sip.message.Request;
 
 import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor;
@@ -26,7 +23,11 @@
 	public void process(RequestEvent evt) {
 		Request request = evt.getRequest();
 		Dialog dialog = evt.getDialog();
+		DialogState state = dialog.getState();
 		if (dialog == null) return;
+		if (request.getMethod().equals(Request.INVITE) && dialog.getState()== DialogState.CONFIRMED) {
+			// TODO 鏌ヨ骞跺紑濮嬫帹娴�
+		}
 		try {
 			Request ackRequest = null;
 			CSeq csReq = (CSeq) request.getHeader(CSeq.NAME);
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 7e9e626..ac19d6f 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
@@ -4,9 +4,12 @@
 import javax.sip.InvalidArgumentException;
 import javax.sip.RequestEvent;
 import javax.sip.SipException;
+import javax.sip.SipFactory;
+import javax.sip.address.Address;
 import javax.sip.address.SipURI;
 import javax.sip.header.ContentTypeHeader;
 import javax.sip.header.FromHeader;
+import javax.sip.header.HeaderFactory;
 import javax.sip.header.SubjectHeader;
 import javax.sip.message.Request;
 import javax.sip.message.Response;
@@ -15,6 +18,7 @@
 import com.genersoft.iot.vmp.conf.MediaServerConfig;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
 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;
@@ -100,16 +104,18 @@
 			platformId = uri.getUser();
 
 			if (platformId == null || channelId == null) {
-				response400Ack(evt); // 鍙傛暟涓嶅叏锛� 鍙�400锛岃姹傞敊璇�
+				logger.info("鏃犳硶浠嶧romHeader鐨凙ddress涓幏鍙栧埌骞冲彴id锛岃繑鍥�404");
+				responseAck(evt, Response.BAD_REQUEST); // 鍙傛暟涓嶅叏锛� 鍙�400锛岃姹傞敊璇�
 				return;
 			}
 			// 鏌ヨ骞冲彴涓嬫槸鍚︽湁璇ラ�氶亾
 			DeviceChannel channel = storager.queryChannelInParentPlatform(platformId, channelId);
 			if (channel == null) {
-				response404Ack(evt); // 閫氶亾涓嶅瓨鍦紝鍙�404锛岃祫婧愪笉瀛樺湪
+				logger.info("閫氶亾涓嶅瓨鍦紝杩斿洖404");
+				responseAck(evt, Response.NOT_FOUND); // 閫氶亾涓嶅瓨鍦紝鍙�404锛岃祫婧愪笉瀛樺湪
 				return;
 			}else {
-				response100Ack(evt); // 閫氶亾瀛樺湪锛屽彂100锛宼rying
+				responseAck(evt, Response.TRYING); // 閫氶亾瀛樺湪锛屽彂100锛宼rying
 			}
 			// 瑙f瀽sdp娑堟伅, 浣跨敤jainsip 鑷甫鐨剆dp瑙f瀽鏂瑰紡
 			String contentString = new String(request.getRawContent());
@@ -152,107 +158,79 @@
 							}
 						}
 					}
-//					Vector attributes = mediaDescription.getAttributes(false);
-//					for (Object attributeObj : attributes) {
-//						Attribute attribute = (Attribute)attributeObj;
-//						String name = attribute.getName();
-//						switch (name){
-//							case "recvonly":
-//								recvonly = true;
-//								break;
-//							case "rtpmap":
-//							case "connection":
-//								break;
-//							case "setup":
-//								mediaTransmissionTCP = true;
-//								if ("active".equals(attribute.getValue())) {  // tcp涓诲姩妯″紡
-//									tcpActive = true;
-//								}else if ("passive".equals(attribute.getValue())){ // tcp琚姩妯″紡
-//									tcpActive = false;
-//								}
-//								break;
-//
-//						}
-//						if ("recvonly".equals(name)) {
-//							recvonly = true;
-//						}
-//
-//						String value = attribute.getValue();
-//					}
 					break;
 				}
 			}
 			if (port == -1) {
+				logger.info("涓嶆敮鎸佺殑濯掍綋鏍煎紡锛岃繑鍥�415");
 				// 鍥炲涓嶆敮鎸佺殑鏍煎紡
-				response415Ack(evt); // 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
+				responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE); // 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
 				return;
 			}
 			String username = sdp.getOrigin().getUsername();
 			String addressStr = sdp.getOrigin().getAddress();
 			String sessionName = sdp.getSessionName().getValue();
 			logger.info("[涓婄骇鐐规挱]鐢ㄦ埛锛歿}锛� 鍦板潃锛歿}:{}锛� ssrc锛歿}", username, addressStr, port, ssrc);
-//
-//			Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, channelId);
-//			if (device == null) {
-//				logger.warn("鐐规挱骞冲彴{}鐨勯�氶亾{}鏃舵湭鎵惧埌璁惧淇℃伅", platformId, channel);
-//				response500Ack(evt);
-//				return;
-//			}
-//
-//			// 閫氱煡涓嬬骇鎺ㄦ祦锛�
-//			PlayResult playResult = playService.play(device.getDeviceId(), channelId, (responseJSON)->{
-//				// 鏀跺埌鎺ㄦ祦锛� 鍥炲200OK
-//				UUID uuid = UUID.randomUUID();
-//				int rtpServer = zlmrtpServerFactory.createRTPServer(uuid.toString());
-//				if (rtpServer == -1) {
-//					logger.error("涓鸿幏鍙栧埌鍙敤绔彛");
-//					return;
-//				}else {
-//					zlmrtpServerFactory.closeRTPServer(uuid.toString());
-//				}
-//				// TODO 娣诲姞瀵箃cp鐨勬敮鎸�
-//				MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
-//				StringBuffer content = new StringBuffer(200);
-//				content.append("v=0\r\n");
-//				content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
-//				content.append("s=Play\r\n");
-//				content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
-//				content.append("t=0 0\r\n");
-//				content.append("m=video "+ rtpServer+" RTP/AVP 96\r\n");
-//				content.append("a=sendonly\r\n");
-//				content.append("a=rtpmap:96 PS/90000\r\n");
-//				content.append("y="+ ssrc + "\r\n");
-//				content.append("f=\r\n");
-//
-//				try {
-//					responseAck(evt, content.toString());
-//				} catch (SipException e) {
-//					e.printStackTrace();
-//				} catch (InvalidArgumentException e) {
-//					e.printStackTrace();
-//				} catch (ParseException e) {
-//					e.printStackTrace();
-//				}
-//
-//				// 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
-////				redisCatchStorage.waiteAck()
-//			},(event -> {
-//				// 鏈煡閿欒銆傜洿鎺ヨ浆鍙戣澶囩偣鎾殑閿欒
-//				Response response = null;
-//				try {
-//					response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest());
-//					getServerTransaction(evt).sendResponse(response);
-//
-//				} catch (ParseException | SipException | InvalidArgumentException e) {
-//					e.printStackTrace();
-//				}
-//			}));
-//			playResult.getResult();
-			// 鏌ユ壘鍚堥�傜殑绔彛鎺ㄦ祦锛�
-			// 鏀跺埌ack鍚庤皟鐢ㄦ帹娴佹帴鍙�
 
+			Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, channelId);
+			if (device == null) {
+				logger.warn("鐐规挱骞冲彴{}鐨勯�氶亾{}鏃舵湭鎵惧埌璁惧淇℃伅", platformId, channel);
+				responseAck(evt, Response.SERVER_INTERNAL_ERROR);
+				return;
+			}
+			SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(ip, port, platformId, ssrc, channelId,
+					mediaTransmissionTCP);
+			if (tcpActive != null) {
+				sendRtpItem.setTcpActive(tcpActive);
+			}
+			if (sendRtpItem == null) {
+				logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
+				responseAck(evt, Response.BUSY_HERE);
+				return;
+			}
 
+			// 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
+			redisCatchStorage.updateSendRTPSever(sendRtpItem);
+			// 閫氱煡涓嬬骇鎺ㄦ祦锛�
+			PlayResult playResult = playService.play(device.getDeviceId(), channelId, (responseJSON)->{
+				// 鏀跺埌鎺ㄦ祦锛� 鍥炲200OK, 绛夊緟ack
+				sendRtpItem.setStatus(1);
+				redisCatchStorage.updateSendRTPSever(sendRtpItem);
+				// TODO 娣诲姞瀵箃cp鐨勬敮鎸�
+				MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
+				StringBuffer content = new StringBuffer(200);
+				content.append("v=0\r\n");
+				content.append("o="+"00000"+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
+				content.append("s=Play\r\n");
+				content.append("c=IN IP4 "+mediaInfo.getWanIp()+"\r\n");
+				content.append("t=0 0\r\n");
+				content.append("m=video "+ sendRtpItem.getLocalPort()+" RTP/AVP 96\r\n");
+				content.append("a=sendonly\r\n");
+				content.append("a=rtpmap:96 PS/90000\r\n");
+				content.append("y="+ ssrc + "\r\n");
+				content.append("f=\r\n");
 
+				try {
+					responseAck(evt, content.toString());
+				} catch (SipException e) {
+					e.printStackTrace();
+				} catch (InvalidArgumentException e) {
+					e.printStackTrace();
+				} catch (ParseException e) {
+					e.printStackTrace();
+				}
+			},(event -> {
+				// 鏈煡閿欒銆傜洿鎺ヨ浆鍙戣澶囩偣鎾殑閿欒
+				Response response = null;
+				try {
+					response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest());
+					getServerTransaction(evt).sendResponse(response);
+
+				} catch (ParseException | SipException | InvalidArgumentException e) {
+					e.printStackTrace();
+				}
+			}));
+			playResult.getResult();
 
 		} catch (SipException | InvalidArgumentException | ParseException e) {
 			e.printStackTrace();
@@ -263,100 +241,46 @@
 		} catch (SdpException e) {
 			e.printStackTrace();
 		}
-
 	}
 
 	/***
-	 * 鍥炲100 trying
+	 * 鍥炲鐘舵�佺爜
+	 * 100 trying
+	 * 200 OK
+	 * 400
+	 * 404
 	 * @param evt
 	 * @throws SipException
 	 * @throws InvalidArgumentException
 	 * @throws ParseException
 	 */
-	private void response100Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
+	private void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException {
 		Response response = getMessageFactory().createResponse(Response.TRYING, evt.getRequest());
 		getServerTransaction(evt).sendResponse(response);
 	}
 
-	/***
-	 * 鍥炲200 OK
+	/**
+	 * 鍥炲甯dp鐨�200
 	 * @param evt
+	 * @param sdp
 	 * @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");
+		SipFactory sipFactory = SipFactory.getInstance();
+		ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
 		response.setContent(sdp, contentTypeHeader);
+
+		SipURI sipURI = (SipURI)evt.getRequest().getRequestURI();
+
+		Address concatAddress = sipFactory.createAddressFactory().createAddress(
+				sipFactory.createAddressFactory().createSipURI(sipURI.getUser(),  sipURI.getHost()+":"+sipURI.getPort()
+				));
+		response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
 		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);
-	}
-
-	/***
-	 * 鍥炲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);
-	}
-
-	/***
-	 * 鍥炲415 涓嶆敮鎸佺殑濯掍綋绫诲瀷
-	 * @param evt
-	 * @throws SipException
-	 * @throws InvalidArgumentException
-	 * @throws ParseException
-	 */
-	private void response415Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
-		Response response = getMessageFactory().createResponse(Response.UNSUPPORTED_MEDIA_TYPE, 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);
-	}
-
-	/***
-	 * 鍥炲500
-	 * @param evt
-	 * @throws SipException
-	 * @throws InvalidArgumentException
-	 * @throws ParseException
-	 */
-	private void response500Ack(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
-		Response response = getMessageFactory().createResponse(Response.SERVER_INTERNAL_ERROR, evt.getRequest());
-		getServerTransaction(evt).sendResponse(response);
-	}
-
-
-
-
-
-
 
 
 
@@ -394,4 +318,12 @@
 	public void setPlayService(IPlayService playService) {
 		this.playService = playService;
 	}
+
+	public IRedisCatchStorage getRedisCatchStorage() {
+		return redisCatchStorage;
+	}
+
+	public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) {
+		this.redisCatchStorage = redisCatchStorage;
+	}
 }
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
index f69ff0f..a556ba7 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -1,6 +1,8 @@
 package com.genersoft.iot.vmp.media.zlm;
 
 import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
+import com.genersoft.iot.vmp.gb28181.session.SsrcUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -92,4 +94,34 @@
             return currentPort++;
         }
     }
+
+    /**
+     * 鍒涘缓涓�涓帹娴�
+     * @param ip 鎺ㄦ祦ip
+     * @param port 鎺ㄦ祦绔彛
+     * @param ssrc 鎺ㄦ祦鍞竴鏍囪瘑
+     * @param platformId 骞冲彴id
+     * @param channelId 閫氶亾id
+     * @param tcp 鏄惁涓簍cp
+     * @return SendRtpItem
+     */
+    public SendRtpItem createSendRtpItem(String ip, int port, String ssrc, String platformId, String channelId, boolean tcp){
+        String playSsrc = SsrcUtil.getPlaySsrc();
+        int localPort = createRTPServer(SsrcUtil.getPlaySsrc());
+        if (localPort != -1) {
+            closeRTPServer(playSsrc);
+        }else {
+            logger.error("娌℃湁鍙敤鐨勭鍙�");
+            return null;
+        }
+        SendRtpItem sendRtpItem = new SendRtpItem();
+        sendRtpItem.setIp(ip);
+        sendRtpItem.setPort(port);
+        sendRtpItem.setSsrc(ssrc);
+        sendRtpItem.setPlatformId(platformId);
+        sendRtpItem.setChannelId(channelId);
+        sendRtpItem.setTcp(tcp);
+        sendRtpItem.setLocalPort(localPort);
+        return sendRtpItem;
+    }
 }
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 49e5578..4ca25e2 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -5,6 +5,7 @@
 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
 import com.genersoft.iot.vmp.gb28181.bean.PlatformRegister;
+import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
 
 import java.util.Map;
 
@@ -78,4 +79,6 @@
     String queryPlatformRegisterInfo(String callId);
 
     void delPlatformRegisterInfo(String callId);
+
+    void updateSendRTPSever(SendRtpItem sendRtpItem);
 }
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 083c86c..a9abdd9 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
@@ -3,10 +3,7 @@
 import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
 import com.genersoft.iot.vmp.conf.MediaServerConfig;
-import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
-import com.genersoft.iot.vmp.gb28181.bean.PlatformRegister;
+import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
@@ -215,4 +212,10 @@
     public void delPlatformRegisterInfo(String callId) {
         redis.del(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + callId);
     }
+
+    @Override
+    public void updateSendRTPSever(SendRtpItem sendRtpItem) {
+        String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX + sendRtpItem.getPlatformId() + "_" + sendRtpItem.getChannelId();
+        redis.set(key, sendRtpItem);
+    }
 }

--
Gitblit v1.8.0