From 730a64be077b51add311b9d880bb23f5162253ec Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期二, 05 一月 2021 14:35:43 +0800
Subject: [PATCH] 优化录像查询,优化注释

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java |  324 +++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 226 insertions(+), 98 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
index 42657a6..e1d474f 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -1,17 +1,14 @@
 package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
 
 import java.text.ParseException;
+import java.util.UUID;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import javax.sip.ClientTransaction;
-import javax.sip.Dialog;
-import javax.sip.InvalidArgumentException;
-import javax.sip.SipException;
-import javax.sip.SipFactory;
-import javax.sip.SipProvider;
-import javax.sip.TransactionDoesNotExistException;
+import javax.sip.*;
 import javax.sip.address.SipURI;
+import javax.sip.header.CallIdHeader;
+import javax.sip.header.Header;
 import javax.sip.header.ViaHeader;
 import javax.sip.message.Request;
 
@@ -19,8 +16,13 @@
 import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.conf.MediaServerConfig;
 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
-import com.genersoft.iot.vmp.media.zlm.ZLMUtils;
+import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
+import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
+import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
@@ -40,6 +42,8 @@
  */
 @Component
 public class SIPCommander implements ISIPCommander {
+
+	private final Logger logger = LoggerFactory.getLogger(SIPCommander.class);
 	
 	@Autowired
 	private SipConfig sipConfig;
@@ -52,6 +56,9 @@
 
 	@Autowired
 	private IVideoManagerStorager storager;
+
+	@Autowired
+	private IRedisCatchStorage redisCatchStorage;
 	
 	@Autowired
 	@Qualifier(value="tcpSipProvider")
@@ -62,10 +69,19 @@
 	private SipProvider udpSipProvider;
 
 	@Autowired
-	private ZLMUtils zlmUtils;
+	private ZLMRTPServerFactory zlmrtpServerFactory;
 
 	@Value("${media.rtp.enable}")
 	private boolean rtpEnable;
+
+	@Value("${media.seniorSdp}")
+	private boolean seniorSdp;
+
+	@Autowired
+	private ZLMHttpHookSubscribe subscribe;
+
+	@Autowired
+	private SipSubscribe sipSubscribe;
 
 
 
@@ -172,19 +188,29 @@
     * @param moveSpeed  闀滃ご绉诲姩閫熷害 榛樿 0XFF (0-255)
     * @param zoomSpeed  闀滃ご缂╂斁閫熷害 榛樿 0X1 (0-255)
     */
-    public static String frontEndCmdString(int cmdCode, int parameter1, int parameter2, int combineCode2) {
+
+	/**
+	 * 浜戝彴鎸囦护鐮佽绠�
+	 *
+	 * @param cmdCode 鎸囦护鐮�
+	 * @param horizonSpeed	姘村钩绉诲姩閫熷害
+	 * @param verticalSpeed	鍨傜洿绉诲姩閫熷害
+	 * @param zoomSpeed	    缂╂斁閫熷害
+	 * @return
+	 */
+    public static String frontEndCmdString(int cmdCode, int horizonSpeed, int verticalSpeed, int zoomSpeed) {
 		StringBuilder builder = new StringBuilder("A50F01");
 		String strTmp;
 		strTmp = String.format("%02X", cmdCode);
 		builder.append(strTmp, 0, 2);
-		strTmp = String.format("%02X", parameter1);
+		strTmp = String.format("%02X", horizonSpeed);
 		builder.append(strTmp, 0, 2);
-		strTmp = String.format("%02X", parameter2);
+		strTmp = String.format("%02X", verticalSpeed);
 		builder.append(strTmp, 0, 2);
-		strTmp = String.format("%X", combineCode2);
+		strTmp = String.format("%X", zoomSpeed);
 		builder.append(strTmp, 0, 1).append("0");
 		//璁$畻鏍¢獙鐮�
-		int checkCode = (0XA5 + 0X0F + 0X01 + cmdCode + parameter1 + parameter2 + (combineCode2 & 0XF0)) % 0X100;
+		int checkCode = (0XA5 + 0X0F + 0X01 + cmdCode + horizonSpeed + verticalSpeed + (zoomSpeed & 0XF0)) % 0X100;
 		strTmp = String.format("%02X", checkCode);
 		builder.append(strTmp, 0, 2);
 		return builder.toString();
@@ -233,14 +259,14 @@
 	 * @param device  		鎺у埗璁惧
 	 * @param channelId		棰勮閫氶亾
 	 * @param cmdCode		鎸囦护鐮�
-     * @param parameter1	鏁版嵁1
-     * @param parameter2	鏁版嵁2
-     * @param combineCode2	缁勫悎鐮�2
+     * @param horizonSpeed	姘村钩绉诲姩閫熷害
+     * @param verticalSpeed	鍨傜洿绉诲姩閫熷害
+     * @param zoomSpeed	    缂╂斁閫熷害
 	 */
 	@Override
-	public boolean frontEndCmd(Device device, String channelId, int cmdCode, int parameter1, int parameter2, int combineCode2) {
+	public boolean frontEndCmd(Device device, String channelId, int cmdCode, int horizonSpeed, int verticalSpeed, int zoomSpeed) {
 		try {
-			String cmdStr= frontEndCmdString(cmdCode, parameter1, parameter2, combineCode2);
+			String cmdStr= frontEndCmdString(cmdCode, horizonSpeed, verticalSpeed, zoomSpeed);
 			System.out.println("鎺у埗瀛楃涓诧細" + cmdStr);
 			StringBuffer ptzXml = new StringBuffer(200);
 			ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
@@ -254,7 +280,6 @@
 			ptzXml.append("</Control>\r\n");
 			
 			Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag");
-			
 			transmitRequest(device, request);
 			return true;
 		} catch (SipException | ParseException | InvalidArgumentException e) {
@@ -262,73 +287,92 @@
 		} 
 		return false;
 	}
+
 	/**
-	 * 璇锋眰棰勮瑙嗛娴�
-	 * 
+	 * 	璇锋眰棰勮瑙嗛娴�
 	 * @param device  瑙嗛璁惧
 	 * @param channelId  棰勮閫氶亾
-	 */  
+	 * @param event hook璁㈤槄
+	 * @param errorEvent sip閿欒璁㈤槄
+	 */
 	@Override
-	public StreamInfo playStreamCmd(Device device, String channelId) {
+	public void playStreamCmd(Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
 		try {
 
 			String ssrc = streamSession.createPlaySsrc();
+			String streamId = null;
+			if (rtpEnable) {
+				streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
+			}else {
+				streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
+			}
 			String streamMode = device.getStreamMode().toUpperCase();
-			MediaServerConfig mediaInfo = storager.getMediaInfo();
+			MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
+			if (mediaInfo == null) {
+				logger.warn("鐐规挱鏃跺彂鐜癦LM灏氭湭杩炴帴...");
+				return;
+			}
 			String mediaPort = null;
 			// 浣跨敤鍔ㄦ�乽dp绔彛
 			if (rtpEnable) {
-				mediaPort = zlmUtils.getNewRTPPort(ssrc) + "";
+				mediaPort = zlmrtpServerFactory.createRTPServer(streamId) + "";
 			}else {
 				mediaPort = mediaInfo.getRtpProxyPort();
 			}
+
+			// 娣诲姞璁㈤槄
+			JSONObject subscribeKey = new JSONObject();
+			subscribeKey.put("app", "rtp");
+			subscribeKey.put("id", streamId);
+
+			subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey, event);
 			//
 			StringBuffer content = new StringBuffer(200);
-	        content.append("v=0\r\n");
-	        content.append("o="+channelId+" 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");
-	        if("TCP-PASSIVE".equals(streamMode)) {
-	        	content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+			content.append("v=0\r\n");
+//			content.append("o="+channelId+" 0 0 IN IP4 "+mediaInfo.getWanIp()+"\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");
+			if("TCP-PASSIVE".equals(streamMode)) {
+				content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
 			}else if ("TCP-ACTIVE".equals(streamMode)) {
-				content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+				content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
 			}else if("UDP".equals(streamMode)) {
-	        	content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
+				content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n");
 			}
-	        content.append("a=recvonly\r\n");
-	        content.append("a=rtpmap:96 PS/90000\r\n");
-	        content.append("a=rtpmap:98 H264/90000\r\n");
-	        content.append("a=rtpmap:97 MPEG4/90000\r\n");
-	        if("TCP-PASSIVE".equals(streamMode)){ // tcp琚姩妯″紡
-	        	content.append("a=setup:passive\r\n");
+			content.append("a=recvonly\r\n");
+			content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
+			content.append("a=rtpmap:126 H264/90000\r\n");
+			content.append("a=rtpmap:125 H264S/90000\r\n");
+			content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
+			content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
+			content.append("a=fmtp:99 profile-level-id=3\r\n");
+			content.append("a=rtpmap:98 H264/90000\r\n");
+			content.append("a=rtpmap:97 MPEG4/90000\r\n");
+			content.append("a=rtpmap:96 PS/90000\r\n");
+			if("TCP-PASSIVE".equals(streamMode)){ // tcp琚姩妯″紡
+				content.append("a=setup:passive\r\n");
 				content.append("a=connection:new\r\n");
-	        }else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
+			}else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
 				content.append("a=setup:active\r\n");
 				content.append("a=connection:new\r\n");
 			}
-	        content.append("y="+ssrc+"\r\n");//ssrc
-	        
-	        Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc);
-	
-	        ClientTransaction transaction = transmitRequest(device, request);
-	        streamSession.put(ssrc, transaction);
-			DeviceChannel deviceChannel = storager.queryChannel(device.getDeviceId(), channelId);
-			if (deviceChannel != null) {
-				deviceChannel.setSsrc(ssrc);
-				storager.updateChannel(device.getDeviceId(), deviceChannel);
-			}
+			content.append("y="+ssrc+"\r\n");//ssrc
 
-			StreamInfo streamInfo = new StreamInfo();
-			streamInfo.setSsrc(ssrc);
-			streamInfo.setCahnnelId(channelId);
-			streamInfo.setDeviceID(device.getDeviceId());
-			storager.startPlay(streamInfo);
-			return streamInfo;
+//			String fromTag = UUID.randomUUID().toString();
+//			Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, fromTag, null, ssrc);
+
+			Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc);
+
+			ClientTransaction transaction = transmitRequest(device, request, errorEvent);
+			streamSession.put(streamId, transaction);
+
+
+
 		} catch ( SipException | ParseException | InvalidArgumentException e) {
 			e.printStackTrace();
-			return null;
-		} 
+		}
 	}
 	
 	/**
@@ -340,10 +384,19 @@
 	 * @param endTime 缁撴潫鏃堕棿,鏍煎紡瑕佹眰锛歽yyy-MM-dd HH:mm:ss
 	 */ 
 	@Override
-	public StreamInfo playbackStreamCmd(Device device, String channelId, String startTime, String endTime) {
+	public void playbackStreamCmd(Device device, String channelId, String startTime, String endTime, ZLMHttpHookSubscribe.Event event
+			, SipSubscribe.Event errorEvent) {
 		try {
-			MediaServerConfig mediaInfo = storager.getMediaInfo();
+			MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
 			String ssrc = streamSession.createPlayBackSsrc();
+			String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
+			// 娣诲姞璁㈤槄
+			JSONObject subscribeKey = new JSONObject();
+			subscribeKey.put("app", "rtp");
+			subscribeKey.put("id", streamId);
+
+			subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey, event);
+
 			//
 			StringBuffer content = new StringBuffer(200);
 	        content.append("v=0\r\n");
@@ -356,59 +409,91 @@
 			String mediaPort = null;
 			// 浣跨敤鍔ㄦ�乽dp绔彛
 			if (rtpEnable) {
-				mediaPort = zlmUtils.getNewRTPPort(ssrc) + "";
+				mediaPort = zlmrtpServerFactory.createRTPServer(streamId) + "";
 			}else {
 				mediaPort = mediaInfo.getRtpProxyPort();
 			}
 			String streamMode = device.getStreamMode().toUpperCase();
-			if("TCP-PASSIVE".equals(streamMode)) {
-				content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
-			}else if ("TCP-ACTIVE".equals(streamMode)) {
-				content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
-			}else if("UDP".equals(streamMode)) {
-				content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
+
+			if (seniorSdp) {
+				if("TCP-PASSIVE".equals(streamMode)) {
+					content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
+				}else if ("TCP-ACTIVE".equals(streamMode)) {
+					content.append("m=video "+ mediaPort +" TCP/RTP/AVP 126 125 99 34 98 97 96\r\n");
+				}else if("UDP".equals(streamMode)) {
+					content.append("m=video "+ mediaPort +" RTP/AVP 126 125 99 34 98 97 96\r\n");
+				}
+				content.append("a=recvonly\r\n");
+				content.append("a=fmtp:126 profile-level-id=42e01e\r\n");
+				content.append("a=rtpmap:126 H264/90000\r\n");
+				content.append("a=rtpmap:125 H264S/90000\r\n");
+				content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
+				content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
+				content.append("a=fmtp:99 profile-level-id=3\r\n");
+				content.append("a=rtpmap:98 H264/90000\r\n");
+				content.append("a=rtpmap:97 MPEG4/90000\r\n");
+				content.append("a=rtpmap:96 PS/90000\r\n");
+				if("TCP-PASSIVE".equals(streamMode)){ // tcp琚姩妯″紡
+					content.append("a=setup:passive\r\n");
+					content.append("a=connection:new\r\n");
+				}else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
+					content.append("a=setup:active\r\n");
+					content.append("a=connection:new\r\n");
+				}
+			}else {
+				if("TCP-PASSIVE".equals(streamMode)) {
+					content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+				}else if ("TCP-ACTIVE".equals(streamMode)) {
+					content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+				}else if("UDP".equals(streamMode)) {
+					content.append("m=video "+ mediaPort +" RTP/AVP 96 98 97\r\n");
+				}
+				content.append("a=recvonly\r\n");
+				content.append("a=rtpmap:96 PS/90000\r\n");
+				content.append("a=rtpmap:98 H264/90000\r\n");
+				content.append("a=rtpmap:97 MPEG4/90000\r\n");
+				if("TCP-PASSIVE".equals(streamMode)){ // tcp琚姩妯″紡
+					content.append("a=setup:passive\r\n");
+					content.append("a=connection:new\r\n");
+				}else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
+					content.append("a=setup:active\r\n");
+					content.append("a=connection:new\r\n");
+				}
 			}
-	        content.append("a=recvonly\r\n");
-	        content.append("a=rtpmap:96 PS/90000\r\n");
-	        content.append("a=rtpmap:98 H264/90000\r\n");
-	        content.append("a=rtpmap:97 MPEG4/90000\r\n");
-			if("TCP-PASSIVE".equals(streamMode)){ // tcp琚姩妯″紡
-				content.append("a=setup:passive\r\n");
-				content.append("a=connection:new\r\n");
-			}else if ("TCP-ACTIVE".equals(streamMode)) { // tcp涓诲姩妯″紡
-				content.append("a=setup:active\r\n");
-				content.append("a=connection:new\r\n");
-			}
+
 	        content.append("y="+ssrc+"\r\n");//ssrc
 	        
 	        Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "playback", null);
-	
-	        ClientTransaction transaction = transmitRequest(device, request);
-	        streamSession.put(ssrc, transaction);
 
-			StreamInfo streamInfo = new StreamInfo();
-			streamInfo.setSsrc(ssrc);
-			streamInfo.setCahnnelId(channelId);
-			streamInfo.setDeviceID(device.getDeviceId());
-			boolean b = storager.startPlayback(streamInfo);
-			return streamInfo;
+	        ClientTransaction transaction = transmitRequest(device, request, errorEvent);
+	        streamSession.put(streamId, transaction);
 
 		} catch ( SipException | ParseException | InvalidArgumentException e) {
 			e.printStackTrace();
-			return null;
 		}
 	}
-	
+
+
+
 	/**
 	 * 瑙嗛娴佸仠姝�
 	 * 
 	 */
 	@Override
 	public void streamByeCmd(String ssrc) {
+		streamByeCmd(ssrc, null);
+	}
+	@Override
+	public void streamByeCmd(String streamId, SipSubscribe.Event okEvent) {
 		
 		try {
-			ClientTransaction transaction = streamSession.get(ssrc);
+			ClientTransaction transaction = streamSession.get(streamId);
+			// 鏈嶅姟閲嶅惎鍚�
 			if (transaction == null) {
+				StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
+				if (streamInfo != null) {
+
+				}
 				return;
 			}
 			
@@ -416,6 +501,9 @@
 			if (dialog == null) {
 				return;
 			}
+
+
+
 			Request byeRequest = dialog.createRequest(Request.BYE);
 			SipURI byeURI = (SipURI) byeRequest.getRequestURI();
 			String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString();
@@ -432,7 +520,16 @@
 			} else if("UDP".equals(protocol)) {
 				clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest);
 			}
+
+			CallIdHeader callIdHeader = (CallIdHeader) byeRequest.getHeader(CallIdHeader.NAME);
+			if (okEvent != null) {
+				sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent);
+			}
+
 			dialog.sendRequest(clientTransaction);
+
+			streamSession.remove(streamId);
+			zlmrtpServerFactory.closeRTPServer(streamId);
 		} catch (TransactionDoesNotExistException e) {
 			e.printStackTrace();
 		} catch (SipException e) {
@@ -550,6 +647,7 @@
 			catalogXml.append("</Query>\r\n");
 			
 			Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", "ToDeviceInfoTag");
+
 			transmitRequest(device, request);
 			
 		} catch (SipException | ParseException | InvalidArgumentException e) {
@@ -565,7 +663,7 @@
 	 * @param device 瑙嗛璁惧
 	 */ 
 	@Override
-	public boolean catalogQuery(Device device) {
+	public boolean catalogQuery(Device device, SipSubscribe.Event errorEvent) {
 		// 娓呯┖閫氶亾
 		storager.cleanChannelsForDevice(device.getDeviceId());
 		try {
@@ -577,8 +675,9 @@
 			catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
 			catalogXml.append("</Query>\r\n");
 			
-			Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCatalogTag", "ToCatalogTag");
-			transmitRequest(device, request);
+			Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCatalogTag", null);
+
+			transmitRequest(device, request, errorEvent);
 		} catch (SipException | ParseException | InvalidArgumentException e) {
 			e.printStackTrace();
 			return false;
@@ -610,7 +709,8 @@
 			recordInfoXml.append("<Type>all</Type>\r\n");
 			recordInfoXml.append("</Query>\r\n");
 			
-			Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", "ToRecordInfoTag");
+			Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", null);
+
 			transmitRequest(device, request);
 		} catch (SipException | ParseException | InvalidArgumentException e) {
 			e.printStackTrace();
@@ -662,17 +762,45 @@
 		// TODO Auto-generated method stub
 		return false;
 	}
-	
+
 	private ClientTransaction transmitRequest(Device device, Request request) throws SipException {
+		return transmitRequest(device, request, null, null);
+	}
+
+	private ClientTransaction transmitRequest(Device device, Request request, SipSubscribe.Event errorEvent) throws SipException {
+		return transmitRequest(device, request, errorEvent, null);
+	}
+
+	private ClientTransaction transmitRequest(Device device, Request request, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws SipException {
 		ClientTransaction clientTransaction = null;
 		if("TCP".equals(device.getTransport())) {
 			clientTransaction = tcpSipProvider.getNewClientTransaction(request);
 		} else if("UDP".equals(device.getTransport())) {
 			clientTransaction = udpSipProvider.getNewClientTransaction(request);
 		}
+
+		CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME);
+		// 娣诲姞閿欒璁㈤槄
+		if (errorEvent != null) {
+			sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), errorEvent);
+		}
+		// 娣诲姞璁㈤槄
+		if (okEvent != null) {
+			sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent);
+		}
+
 		clientTransaction.sendRequest();
 		return clientTransaction;
 	}
 
 
+
+
+	@Override
+	public void closeRTPServer(Device device, String channelId) {
+		if (rtpEnable) {
+			String streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
+			zlmrtpServerFactory.closeRTPServer(streamId);
+		}
+	}
 }

--
Gitblit v1.8.0