From 2601150f036e17604ee0431144a7ab921b7f8206 Mon Sep 17 00:00:00 2001
From: 648540858 <18010473990@163.com>
Date: 星期四, 02 九月 2021 15:47:42 +0800
Subject: [PATCH] 更新readme
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 222 +++++++++++++++++++++++--------------------------------
1 files changed, 94 insertions(+), 128 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 d2318dc..cec64cc 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,6 +1,8 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
+import java.lang.reflect.Field;
import java.text.ParseException;
+import java.util.HashSet;
import javax.sip.*;
import javax.sip.address.SipURI;
@@ -8,18 +10,20 @@
import javax.sip.header.ViaHeader;
import javax.sip.message.Request;
-import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-import com.genersoft.iot.vmp.common.StreamInfo;
-import com.genersoft.iot.vmp.conf.MediaConfig;
import com.genersoft.iot.vmp.conf.UserSetup;
+import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
import com.genersoft.iot.vmp.media.zlm.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
-import com.genersoft.iot.vmp.media.zlm.dto.IMediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
+import com.genersoft.iot.vmp.service.IMediaServerService;
+import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import gov.nist.javax.sip.SipProviderImpl;
+import gov.nist.javax.sip.SipStackImpl;
import gov.nist.javax.sip.message.SIPRequest;
+import gov.nist.javax.sip.stack.SIPDialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -35,7 +39,6 @@
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
-import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import org.springframework.util.StringUtils;
/**
@@ -55,12 +58,12 @@
@Lazy
@Autowired
@Qualifier(value="tcpSipProvider")
- private SipProvider tcpSipProvider;
+ private SipProviderImpl tcpSipProvider;
@Lazy
@Autowired
@Qualifier(value="udpSipProvider")
- private SipProvider udpSipProvider;
+ private SipProviderImpl udpSipProvider;
@Autowired
private SIPRequestHeaderProvider headerProvider;
@@ -75,9 +78,6 @@
private IRedisCatchStorage redisCatchStorage;
@Autowired
- private ZLMRTPServerFactory zlmrtpServerFactory;
-
- @Autowired
private UserSetup userSetup;
@Autowired
@@ -85,6 +85,11 @@
@Autowired
private SipSubscribe sipSubscribe;
+
+ @Autowired
+ private IMediaServerService mediaServerService;
+
+ private SIPDialog dialog;
public SipConfig getSipConfig() {
return sipConfig;
@@ -100,7 +105,7 @@
*/
@Override
public boolean ptzdirectCmd(Device device, String channelId, int leftRight, int upDown) {
- return ptzCmd(device, channelId, leftRight, upDown, 0, sipConfig.getSpeed(), 0);
+ return ptzCmd(device, channelId, leftRight, upDown, 0, sipConfig.getPtzSpeed(), 0);
}
/**
@@ -126,7 +131,7 @@
*/
@Override
public boolean ptzZoomCmd(Device device, String channelId, int inOut) {
- return ptzCmd(device, channelId, 0, 0, inOut, 0, sipConfig.getSpeed());
+ return ptzCmd(device, channelId, 0, 0, inOut, 0, sipConfig.getPtzSpeed());
}
/**
@@ -334,26 +339,13 @@
* @param errorEvent sip閿欒璁㈤槄
*/
@Override
- public void playStreamCmd(IMediaServerItem mediaServerItem, Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
- String streamId = null;
+ public void playStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, ZLMHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent) {
+ String streamId = ssrcInfo.getStreamId();
try {
if (device == null) return;
String streamMode = device.getStreamMode().toUpperCase();
- String ssrc = streamSession.createPlaySsrc();
- if (mediaServerItem.isRtpEnable()) {
- streamId = String.format("gb_play_%s_%s", device.getDeviceId(), channelId);
- }else {
- streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
- }
- Integer mediaPort = null;
- // 浣跨敤鍔ㄦ�乽dp绔彛
- if (mediaServerItem.isRtpEnable()) {
- mediaPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId);
- }else {
- mediaPort = mediaServerItem.getRtpProxyPort();
- }
- logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", streamId, mediaServerItem.getId(), mediaServerItem.getIp(), mediaPort);
+ logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", streamId, mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
// 娣诲姞璁㈤槄
JSONObject subscribeKey = new JSONObject();
subscribeKey.put("app", "rtp");
@@ -361,7 +353,7 @@
subscribeKey.put("regist", true);
subscribeKey.put("mediaServerId", mediaServerItem.getId());
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
- (IMediaServerItem mediaServerItemInUse, JSONObject json)->{
+ (MediaServerItem mediaServerItemInUse, JSONObject json)->{
if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
event.response(mediaServerItemInUse, json);
subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
@@ -369,7 +361,6 @@
//
StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n");
-// content.append("o=" + sipConfig.getSipId() + " 0 0 IN IP4 "+mediaInfo.getWanIp()+"\r\n");
content.append("o="+"00000"+" 0 0 IN IP4 "+ mediaServerItem.getSdpIp() +"\r\n");
content.append("s=Play\r\n");
content.append("c=IN IP4 "+ mediaServerItem.getSdpIp() +"\r\n");
@@ -377,11 +368,11 @@
if (userSetup.isSeniorSdp()) {
if("TCP-PASSIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if("UDP".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 126 125 99 34 98 97\r\n");
}
content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
@@ -402,11 +393,11 @@
}
}else {
if("TCP-PASSIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" 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");
+ content.append("m=video "+ ssrcInfo.getPort() +" 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("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
}
content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
@@ -421,20 +412,25 @@
}
}
- content.append("y="+ssrc+"\r\n");//ssrc
+ content.append("y="+ssrcInfo.getSsrc()+"\r\n");//ssrc
String tm = Long.toString(System.currentTimeMillis());
CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
: udpSipProvider.getNewCallId();
- Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrc, callIdHeader);
+ Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrcInfo.getSsrc(), callIdHeader);
- ClientTransaction transaction = transmitRequest(device, request, (e -> {
+ String finalStreamId = streamId;
+ transmitRequest(device, request, (e -> {
streamSession.remove(device.getDeviceId(), channelId);
+ mediaServerService.releaseSsrc(mediaServerItem, ssrcInfo.getSsrc());
errorEvent.response(e);
- }));
- streamSession.put(device.getDeviceId(), channelId ,ssrc,streamId, transaction);
+ }), e ->{
+ streamSession.put(device.getDeviceId(), channelId ,ssrcInfo.getSsrc(), finalStreamId, mediaServerItem.getId(),e.getClientTransaction());
+ streamSession.put(device.getDeviceId(), channelId , e.getDialog());
+ });
+
} catch ( SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace();
@@ -450,30 +446,21 @@
* @param endTime 缁撴潫鏃堕棿,鏍煎紡瑕佹眰锛歽yyy-MM-dd HH:mm:ss
*/
@Override
- public void playbackStreamCmd(IMediaServerItem mediaServerItem,Device device, String channelId, String startTime, String endTime, ZLMHttpHookSubscribe.Event event
+ public void playbackStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, String startTime, String endTime, ZLMHttpHookSubscribe.Event event
, SipSubscribe.Event errorEvent) {
try {
- String ssrc = streamSession.createPlayBackSsrc();
- String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
- Integer mediaPort = null;
- // 浣跨敤鍔ㄦ�乽dp绔彛
- if (mediaServerItem.isRtpEnable()) {
- mediaPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId);
- }else {
- mediaPort = mediaServerItem.getRtpProxyPort();
- }
- logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", streamId, mediaServerItem.getId(), mediaServerItem.getIp(), mediaPort);
+ logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", ssrcInfo.getStreamId(), mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
// 娣诲姞璁㈤槄
JSONObject subscribeKey = new JSONObject();
subscribeKey.put("app", "rtp");
- subscribeKey.put("stream", streamId);
+ subscribeKey.put("stream", ssrcInfo.getStreamId());
subscribeKey.put("regist", true);
subscribeKey.put("mediaServerId", mediaServerItem.getId());
logger.debug("褰曞儚鍥炴斁娣诲姞璁㈤槄锛岃闃呭唴瀹癸細" + subscribeKey.toString());
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
- (IMediaServerItem mediaServerItemInUse, JSONObject json)->{
+ (MediaServerItem mediaServerItemInUse, JSONObject json)->{
if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
event.response(mediaServerItemInUse, json);
subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
@@ -481,7 +468,7 @@
StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n");
- content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
+ content.append("o="+sipConfig.getId()+" 0 0 IN IP4 "+sipConfig.getIp()+"\r\n");
content.append("s=Playback\r\n");
content.append("u="+channelId+":0\r\n");
content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
@@ -494,11 +481,11 @@
if (userSetup.isSeniorSdp()) {
if("TCP-PASSIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if("UDP".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 126 125 99 34 98 97\r\n");
}
content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
@@ -519,11 +506,11 @@
}
}else {
if("TCP-PASSIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" 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");
+ content.append("m=video "+ ssrcInfo.getPort() +" 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("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
}
content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
@@ -538,7 +525,7 @@
}
}
- content.append("y="+ssrc+"\r\n");//ssrc
+ content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
String tm = Long.toString(System.currentTimeMillis());
@@ -547,9 +534,11 @@
Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader);
- ClientTransaction transaction = transmitRequest(device, request, errorEvent);
- streamSession.put(device.getDeviceId(), channelId, ssrc, streamId, transaction);
-
+ transmitRequest(device, request, errorEvent, okEvent -> {
+ Dialog dialog = okEvent.getClientTransaction().getDialog();
+ streamSession.put(device.getDeviceId(), channelId, ssrcInfo.getSsrc(), ssrcInfo.getStreamId(), mediaServerItem.getId(), okEvent.getClientTransaction());
+ streamSession.put(device.getDeviceId(), channelId, dialog);
+ });
} catch ( SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace();
}
@@ -565,30 +554,20 @@
* @param downloadSpeed 涓嬭浇鍊嶉�熷弬鏁�
*/
@Override
- public void downloadStreamCmd(IMediaServerItem mediaServerItem,Device device, String channelId, String startTime, String endTime, String downloadSpeed, ZLMHttpHookSubscribe.Event event
+ public void downloadStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, String startTime, String endTime, String downloadSpeed, ZLMHttpHookSubscribe.Event event
, SipSubscribe.Event errorEvent) {
try {
- String ssrc = streamSession.createPlayBackSsrc();
- String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
-
- Integer mediaPort = null;
- // 浣跨敤鍔ㄦ�乽dp绔彛
- if (mediaServerItem.isRtpEnable()) {
- mediaPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId);
- }else {
- mediaPort = mediaServerItem.getRtpProxyPort();
- }
- logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", streamId, mediaServerItem.getId(), mediaServerItem.getIp(), mediaPort);
+ logger.info("{} 鍒嗛厤鐨刏LM涓�: {} [{}:{}]", ssrcInfo.getStreamId(), mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
// 娣诲姞璁㈤槄
JSONObject subscribeKey = new JSONObject();
subscribeKey.put("app", "rtp");
- subscribeKey.put("stream", streamId);
+ subscribeKey.put("stream", ssrcInfo.getStreamId());
subscribeKey.put("regist", true);
subscribeKey.put("mediaServerId", mediaServerItem.getId());
logger.debug("褰曞儚鍥炴斁娣诲姞璁㈤槄锛岃闃呭唴瀹癸細" + subscribeKey.toString());
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
- (IMediaServerItem mediaServerItemInUse, JSONObject json)->{
+ (MediaServerItem mediaServerItemInUse, JSONObject json)->{
if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
event.response(mediaServerItemInUse, json);
subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
@@ -596,7 +575,7 @@
StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n");
- content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
+ content.append("o="+sipConfig.getId()+" 0 0 IN IP4 "+sipConfig.getIp()+"\r\n");
content.append("s=Download\r\n");
content.append("u="+channelId+":0\r\n");
content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
@@ -609,11 +588,11 @@
if (userSetup.isSeniorSdp()) {
if("TCP-PASSIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if ("TCP-ACTIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
}else if("UDP".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" RTP/AVP 96 126 125 99 34 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 126 125 99 34 98 97\r\n");
}
content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
@@ -634,11 +613,11 @@
}
}else {
if("TCP-PASSIVE".equals(streamMode)) {
- content.append("m=video "+ mediaPort +" TCP/RTP/AVP 96 98 97\r\n");
+ content.append("m=video "+ ssrcInfo.getPort() +" 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");
+ content.append("m=video "+ ssrcInfo.getPort() +" 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("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
}
content.append("a=recvonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
@@ -654,7 +633,7 @@
}
content.append("a=downloadspeed:" + downloadSpeed + "\r\n");
- content.append("y="+ssrc+"\r\n");//ssrc
+ content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
String tm = Long.toString(System.currentTimeMillis());
@@ -664,7 +643,7 @@
Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader);
ClientTransaction transaction = transmitRequest(device, request, errorEvent);
- streamSession.put(device.getDeviceId(), channelId, ssrc, streamId, transaction);
+ streamSession.put(device.getDeviceId(), channelId, ssrcInfo.getSsrc(), ssrcInfo.getStreamId(), mediaServerItem.getId(), transaction);
} catch ( SipException | ParseException | InvalidArgumentException e) {
e.printStackTrace();
@@ -684,53 +663,35 @@
*/
@Override
public void streamByeCmd(String deviceId, String channelId, SipSubscribe.Event okEvent) {
- StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
try {
ClientTransaction transaction = streamSession.getTransaction(deviceId, channelId);
- // 鏈嶅姟閲嶅惎鍚�, 鏃犳硶鐩存帴鍙戦�乥ye锛� 閫氳繃鎵嬪姩鏋勫缓鍙戦��
-// if (transaction == null) {
-//
-// if (streamInfo != null) {
-// MediaServerItem mediaServerItem = redisCatchStorage.getMediaInfo(streamInfo.getMediaServerId());
-// JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaServerItem,streamInfo.getApp(), streamInfo.getStreamId());
-// if (mediaList != null) { // 浠嶅湪鎺ㄦ祦鎵嶅彂閫�
-// if (mediaList.getInteger("code") == 0) {
-// JSONArray data = mediaList.getJSONArray("data");
-// if (data != null && data.size() > 0) {
-// Device device = storager.queryVideoDevice(deviceId);
-// if (device != null) {
-// StreamInfo.TransactionInfo transactionInfo = streamInfo.getTransactionInfo();
-// try {
-// Request byteRequest = headerProvider.createByteRequest(device, channelId,
-// transactionInfo.branch,
-// transactionInfo.localTag,
-// transactionInfo.remoteTag,
-// transactionInfo.callId);
-// transmitRequest(device, byteRequest);
-// } catch (InvalidArgumentException e) {
-// e.printStackTrace();
-// }
-// }
-// }
-// }
-// }
-// redisCatchStorage.stopPlay(streamInfo);
-// }
-//
-// if (okEvent != null) {
-// okEvent.response(null);
-// }
-// return;
-// }
if (transaction == null) {
logger.warn("[ {} -> {}]鍋滄瑙嗛娴佺殑鏃跺�欏彂鐜颁簨鍔″凡涓㈠け", deviceId, channelId);
return;
}
- Dialog dialog = transaction.getDialog();
+ SIPDialog dialog = streamSession.getDialog(deviceId, channelId);
if (dialog == null) {
logger.warn("[ {} -> {}]鍋滄瑙嗛娴佺殑鏃跺�欏彂鐜板璇濆凡涓㈠け", deviceId, channelId);
return;
}
+ SipStack sipStack = udpSipProvider.getSipStack();
+ SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog);
+ if (dialog != sipDialog) {
+ dialog = sipDialog;
+ }else {
+ dialog.setSipProvider(udpSipProvider);
+ try {
+ Field sipStackField = SIPDialog.class.getDeclaredField("sipStack");
+ sipStackField.setAccessible(true);
+ sipStackField.set(dialog, sipStack);
+ Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners");
+ eventListenersField.setAccessible(true);
+ eventListenersField.set(dialog, new HashSet<>());
+ } catch (NoSuchFieldException | IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+
Request byeRequest = dialog.createRequest(Request.BYE);
SipURI byeURI = (SipURI) byeRequest.getRequestURI();
SIPRequest request = (SIPRequest)transaction.getRequest();
@@ -752,7 +713,12 @@
dialog.sendRequest(clientTransaction);
- streamSession.remove(deviceId, channelId);
+ SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(deviceId, channelId);
+ if (ssrcTransaction != null) {
+ MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId());
+ mediaServerService.releaseSsrc(mediaServerItem, ssrcTransaction.getSsrc());
+ streamSession.remove(deviceId, channelId);
+ }
} catch (SipException | ParseException e) {
e.printStackTrace();
}
@@ -783,7 +749,7 @@
broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
- broadcastXml.append("<SourceID>" + sipConfig.getSipId() + "</SourceID>\r\n");
+ broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
broadcastXml.append("</Notify>\r\n");
@@ -808,7 +774,7 @@
broadcastXml.append("<Notify>\r\n");
broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
- broadcastXml.append("<SourceID>" + sipConfig.getSipId() + "</SourceID>\r\n");
+ broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
broadcastXml.append("</Notify>\r\n");
--
Gitblit v1.8.0