From ffb21248cb270475ce9156b5056e591e14cbc20d Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 30 五月 2023 11:20:22 +0800
Subject: [PATCH] 去除多余配置
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java | 423 ++++++++++++++++++++++++++++------------------------
1 files changed, 231 insertions(+), 192 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
index 42ae826..07a1538 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -1,25 +1,26 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
-import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.*;
-import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
-import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
+import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
-import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
+import com.genersoft.iot.vmp.gb28181.transmit.SIPSender;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
-import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
+import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.dto.*;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IPlayService;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.service.IStreamPushService;
+import com.genersoft.iot.vmp.service.bean.ErrorCallback;
+import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener;
@@ -38,12 +39,14 @@
import org.springframework.stereotype.Component;
import javax.sdp.*;
-import javax.sip.*;
+import javax.sip.InvalidArgumentException;
+import javax.sip.RequestEvent;
+import javax.sip.SipException;
import javax.sip.header.CallIdHeader;
-import javax.sip.message.Request;
import javax.sip.message.Response;
import java.text.ParseException;
import java.time.Instant;
+import java.util.Random;
import java.util.Vector;
/**
@@ -72,6 +75,9 @@
private IRedisCatchStorage redisCatchStorage;
@Autowired
+ private SSRCFactory ssrcFactory;
+
+ @Autowired
private DynamicTask dynamicTask;
@Autowired
@@ -81,7 +87,7 @@
private IPlayService playService;
@Autowired
- private ISIPCommander commander;
+ private SIPSender sipSender;
@Autowired
private ZLMRTPServerFactory zlmrtpServerFactory;
@@ -94,9 +100,6 @@
@Autowired
private SIPProcessorObserver sipProcessorObserver;
-
- @Autowired
- private VideoStreamSessionManager sessionManager;
@Autowired
private UserSetting userSetting;
@@ -124,16 +127,15 @@
public void process(RequestEvent evt) {
// Invite Request娑堟伅瀹炵幇锛屾娑堟伅涓�鑸负绾ц仈娑堟伅锛屼笂绾х粰涓嬬骇鍙戦�佽姹傝棰戞寚浠�
try {
- Request request = evt.getRequest();
+ SIPRequest request = (SIPRequest)evt.getRequest();
String channelId = SipUtils.getChannelIdFromRequest(request);
String requesterId = SipUtils.getUserIdFromFromHeader(request);
CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME);
- ServerTransaction serverTransaction = getServerTransaction(evt);
if (requesterId == null || channelId == null) {
logger.info("鏃犳硶浠嶧romHeader鐨凙ddress涓幏鍙栧埌骞冲彴id锛岃繑鍥�400");
// 鍙傛暟涓嶅叏锛� 鍙�400锛岃姹傞敊璇�
try {
- responseAck(serverTransaction, Response.BAD_REQUEST);
+ responseAck(request, Response.BAD_REQUEST);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite BAD_REQUEST: {}", e.getMessage());
}
@@ -144,7 +146,7 @@
// 鏌ヨ璇锋眰鏄惁鏉ヨ嚜涓婄骇骞冲彴\璁惧
ParentPlatform platform = storager.queryParentPlatByServerGBId(requesterId);
if (platform == null) {
- inviteFromDeviceHandle(serverTransaction, requesterId);
+ inviteFromDeviceHandle(request, requesterId);
} else {
// 鏌ヨ骞冲彴涓嬫槸鍚︽湁璇ラ�氶亾
@@ -157,14 +159,9 @@
StreamProxyItem proxyByAppAndStream =null;
// 涓嶆槸閫氶亾鍙兘鏄洿鎾祦
if (channel != null && gbStream == null) {
-// if (channel.getStatus() == 0) {
-// logger.info("閫氶亾绂荤嚎锛岃繑鍥�400");
-// responseAck(serverTransaction, Response.BAD_REQUEST, "channel [" + channel.getChannelId() + "] offline");
-// return;
-// }
// 閫氶亾瀛樺湪锛屽彂100锛孴RYING
try {
- responseAck(serverTransaction, Response.TRYING);
+ responseAck(request, Response.TRYING);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite TRYING: {}", e.getMessage());
}
@@ -176,7 +173,7 @@
if ("proxy".equals(gbStream.getStreamType())) {
logger.info("[ app={}, stream={} ]鎵句笉鍒皕lm {}锛岃繑鍥�410", gbStream.getApp(), gbStream.getStream(), mediaServerId);
try {
- responseAck(serverTransaction, Response.GONE);
+ responseAck(request, Response.GONE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite GONE: {}", e.getMessage());
}
@@ -186,7 +183,7 @@
if (streamPushItem == null || streamPushItem.getServerId().equals(userSetting.getServerId())) {
logger.info("[ app={}, stream={} ]鎵句笉鍒皕lm {}锛岃繑鍥�410", gbStream.getApp(), gbStream.getStream(), mediaServerId);
try {
- responseAck(serverTransaction, Response.GONE);
+ responseAck(request, Response.GONE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite GONE: {}", e.getMessage());
}
@@ -199,7 +196,7 @@
if (streamPushItem == null) {
logger.info("[ app={}, stream={} ]鎵句笉鍒皕lm {}锛岃繑鍥�410", gbStream.getApp(), gbStream.getStream(), mediaServerId);
try {
- responseAck(serverTransaction, Response.GONE);
+ responseAck(request, Response.GONE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite GONE: {}", e.getMessage());
}
@@ -210,7 +207,7 @@
if (proxyByAppAndStream == null) {
logger.info("[ app={}, stream={} ]鎵句笉鍒皕lm {}锛岃繑鍥�410", gbStream.getApp(), gbStream.getStream(), mediaServerId);
try {
- responseAck(serverTransaction, Response.GONE);
+ responseAck(request, Response.GONE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite GONE: {}", e.getMessage());
}
@@ -219,23 +216,23 @@
}
}
try {
- responseAck(serverTransaction, Response.CALL_IS_BEING_FORWARDED);
+ responseAck(request, Response.CALL_IS_BEING_FORWARDED);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite CALL_IS_BEING_FORWARDED: {}", e.getMessage());
}
} else if (catalog != null) {
try {
// 鐩綍涓嶆敮鎸佺偣鎾�
- responseAck(serverTransaction, Response.BAD_REQUEST, "catalog channel can not play");
+ responseAck(request, Response.BAD_REQUEST, "catalog channel can not play");
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 鐩綍涓嶆敮鎸佺偣鎾�: {}", e.getMessage());
}
return;
} else {
- logger.info("閫氶亾涓嶅瓨鍦紝杩斿洖404");
+ logger.info("閫氶亾涓嶅瓨鍦紝杩斿洖404: {}", channelId);
try {
// 閫氶亾涓嶅瓨鍦紝鍙�404锛岃祫婧愪笉瀛樺湪
- responseAck(serverTransaction, Response.NOT_FOUND);
+ responseAck(request, Response.NOT_FOUND);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 閫氶亾涓嶅瓨鍦�: {}", e.getMessage());
}
@@ -245,18 +242,15 @@
String contentString = new String(request.getRawContent());
// jainSip涓嶆敮鎸亂=瀛楁锛� 绉婚櫎浠ヨВ鏋愩��
- int ssrcIndex = contentString.indexOf("y=");
// 妫�鏌ユ槸鍚︽湁y瀛楁
- String ssrcDefault = "0000000000";
- String ssrc;
+ int ssrcIndex = contentString.indexOf("y=");
+
SessionDescription sdp;
if (ssrcIndex >= 0) {
//ssrc瑙勫畾闀垮害涓�10涓瓧鑺傦紝涓嶅彇浣欎笅闀垮害浠ラ伩鍏嶅悗缁繕鏈夆�渇=鈥濆瓧娈�
- ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
- String substring = contentString.substring(0, contentString.indexOf("y="));
+ String substring = contentString.substring(0, ssrcIndex);
sdp = SdpFactory.getInstance().createSessionDescription(substring);
} else {
- ssrc = ssrcDefault;
sdp = SdpFactory.getInstance().createSessionDescription(contentString);
}
String sessionName = sdp.getSessionName().getValue();
@@ -311,16 +305,16 @@
// 鍥炲涓嶆敮鎸佺殑鏍煎紡
try {
// 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
- responseAck(serverTransaction, Response.UNSUPPORTED_MEDIA_TYPE);
+ responseAck(request, Response.UNSUPPORTED_MEDIA_TYPE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 涓嶆敮鎸佺殑鏍煎紡: {}", e.getMessage());
}
return;
}
String username = sdp.getOrigin().getUsername();
- String addressStr = sdp.getOrigin().getAddress();
+ String addressStr = sdp.getConnection().getAddress();
- logger.info("[涓婄骇鐐规挱]鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}, 鍦板潃锛歿}:{}锛� ssrc锛歿}", username, channelId, addressStr, port, ssrc);
+
Device device = null;
// 閫氳繃 channel 鍜� gbStream 鏄惁涓簄ull 鍊煎垽鏂潵婧愭槸鐩存挱娴佸悎閫傚浗鏍�
if (channel != null) {
@@ -328,7 +322,7 @@
if (device == null) {
logger.warn("鐐规挱骞冲彴{}鐨勯�氶亾{}鏃舵湭鎵惧埌璁惧淇℃伅", requesterId, channel);
try {
- responseAck(serverTransaction, Response.SERVER_INTERNAL_ERROR);
+ responseAck(request, Response.SERVER_INTERNAL_ERROR);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈壘鍒拌澶囦俊鎭�: {}", e.getMessage());
}
@@ -338,15 +332,33 @@
if (mediaServerItem == null) {
logger.warn("鏈壘鍒板彲鐢ㄧ殑zlm");
try {
- responseAck(serverTransaction, Response.BUSY_HERE);
+ responseAck(request, Response.BUSY_HERE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite BUSY_HERE: {}", e.getMessage());
}
return;
}
+
+ String ssrc;
+ if (userSetting.getUseCustomSsrcForParentInvite() || ssrcIndex < 0) {
+ // 涓婄骇骞冲彴鐐规挱鏃朵笉浣跨敤涓婄骇骞冲彴鎸囧畾鐨剆src锛屼娇鐢ㄨ嚜瀹氫箟鐨剆src锛屽弬鑰冨浗鏍囨枃妗�-鐐规挱澶栧煙璁惧濯掍綋娴丼SRC澶勭悊鏂瑰紡
+ ssrc = "Play".equalsIgnoreCase(sessionName) ? ssrcFactory.getPlaySsrc(mediaServerItem.getId()) : ssrcFactory.getPlayBackSsrc(mediaServerItem.getId());
+ }else {
+ ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+ }
+ String streamTypeStr = null;
+ if (mediaTransmissionTCP) {
+ if (tcpActive) {
+ streamTypeStr = "TCP-ACTIVE";
+ }else {
+ streamTypeStr = "TCP-PASSIVE";
+ }
+ }else {
+ streamTypeStr = "UDP";
+ }
+ logger.info("[涓婄骇Invite] {}, 骞冲彴锛歿}锛� 閫氶亾锛歿}, 鏀舵祦鍦板潃锛歿}:{}锛屾敹娴佹柟寮忥細{}, ssrc锛歿}", sessionName, username, channelId, addressStr, port, streamTypeStr, ssrc);
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
- device.getDeviceId(), channelId,
- mediaTransmissionTCP);
+ device.getDeviceId(), channelId, mediaTransmissionTCP, platform.isRtcp());
if (tcpActive != null) {
sendRtpItem.setTcpActive(tcpActive);
@@ -354,7 +366,7 @@
if (sendRtpItem == null) {
logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
try {
- responseAck(serverTransaction, Response.BUSY_HERE);
+ responseAck(request, Response.BUSY_HERE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�: {}", e.getMessage());
}
@@ -365,10 +377,10 @@
Long finalStartTime = startTime;
Long finalStopTime = stopTime;
- ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> {
- String app = responseJSON.getString("app");
- String stream = responseJSON.getString("stream");
- logger.info("[涓婄骇鐐规挱]涓嬬骇宸茬粡寮�濮嬫帹娴併�� 鍥炲200OK(SDP)锛� {}/{}", app, stream);
+ ErrorCallback<Object> hookEvent = (code, msg, data) -> {
+ StreamInfo streamInfo = (StreamInfo)data;
+ MediaServerItem mediaServerItemInUSe = mediaServerService.getOne(streamInfo.getMediaServerId());
+ logger.info("[涓婄骇Invite]涓嬬骇宸茬粡寮�濮嬫帹娴併�� 鍥炲200OK(SDP)锛� {}/{}", streamInfo.getApp(), streamInfo.getStream());
// * 0 绛夊緟璁惧鎺ㄦ祦涓婃潵
// * 1 涓嬬骇宸茬粡鎺ㄦ祦锛岀瓑寰呬笂绾у钩鍙板洖澶峚ck
// * 2 鎺ㄦ祦涓�
@@ -385,7 +397,12 @@
} else {
content.append("t=0 0\r\n");
}
- content.append("m=video " + sendRtpItem.getLocalPort() + " RTP/AVP 96\r\n");
+ int localPort = sendRtpItem.getLocalPort();
+ if (localPort == 0) {
+ // 闈炰弗鏍兼ā寮忕鍙d笉缁熶竴, 澧炲姞鍏煎鎬э紝淇敼涓轰竴涓笉涓�0鐨勭鍙�
+ localPort = new Random().nextInt(65535) + 1;
+ }
+ content.append("m=video " + localPort + " RTP/AVP 96\r\n");
content.append("a=sendonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
content.append("y=" + sendRtpItem.getSsrc() + "\r\n");
@@ -403,129 +420,128 @@
logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍙戦�丅YE: {}", e.getMessage());
}
}, 60 * 1000);
- responseSdpAck(serverTransaction, content.toString(), platform);
+ responseSdpAck(request, content.toString(), platform);
- } catch (SipException e) {
- e.printStackTrace();
- } catch (InvalidArgumentException e) {
- e.printStackTrace();
- } catch (ParseException e) {
- e.printStackTrace();
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鍥炲SdpAck", e);
}
};
- SipSubscribe.Event errorEvent = ((event) -> {
+ ErrorCallback<Object> errorEvent = ((statusCode, msg, data) -> {
// 鏈煡閿欒銆傜洿鎺ヨ浆鍙戣澶囩偣鎾殑閿欒
- Response response = null;
try {
- response = getMessageFactory().createResponse(event.statusCode, evt.getRequest());
- serverTransaction.sendResponse(response);
- System.out.println("鏈煡閿欒銆傜洿鎺ヨ浆鍙戣澶囩偣鎾殑閿欒");
- if (serverTransaction.getDialog() != null) {
- serverTransaction.getDialog().delete();
+ if (statusCode > 0) {
+ Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
+ sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response);
}
- } catch (ParseException | SipException | InvalidArgumentException e) {
- e.printStackTrace();
+ } catch (ParseException | SipException e) {
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
});
sendRtpItem.setApp("rtp");
if ("Playback".equalsIgnoreCase(sessionName)) {
sendRtpItem.setPlayType(InviteStreamType.PLAYBACK);
- SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, true, true);
+ SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, null, device.isSsrcCheck(), true, 0, false, device.getStreamModeForParam());
sendRtpItem.setStreamId(ssrcInfo.getStream());
// 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
redisCatchStorage.updateSendRTPSever(sendRtpItem);
playService.playBack(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start),
- DateUtil.formatter.format(end), null, result -> {
- if (result.getCode() != 0) {
- logger.warn("褰曞儚鍥炴斁澶辫触");
- if (result.getEvent() != null) {
- errorEvent.response(result.getEvent());
- }
+ DateUtil.formatter.format(end),
+ (code, msg, data) -> {
+ if (code == InviteErrorCode.SUCCESS.getCode()){
+ hookEvent.run(code, msg, data);
+ }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
+ logger.info("[褰曞儚鍥炴斁]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId);
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
- try {
- responseAck(serverTransaction, Response.REQUEST_TIMEOUT);
- } catch (SipException e) {
- e.printStackTrace();
- } catch (InvalidArgumentException e) {
- e.printStackTrace();
- } catch (ParseException e) {
- e.printStackTrace();
- }
- } else {
- if (result.getMediaServerItem() != null) {
- hookEvent.response(result.getMediaServerItem(), result.getResponse());
- }
+ errorEvent.run(code, msg, data);
+ }else {
+ errorEvent.run(code, msg, data);
}
});
- } else {
- sendRtpItem.setPlayType(InviteStreamType.PLAY);
- SsrcTransaction playTransaction = sessionManager.getSsrcTransaction(device.getDeviceId(), channelId, "play", null);
- if (playTransaction != null) {
- Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, "rtp", playTransaction.getStream());
- if (!streamReady) {
- boolean hasRtpServer = mediaServerService.checkRtpServer(mediaServerItem, "rtp", playTransaction.getStream());
- if (hasRtpServer) {
- logger.info("[涓婄骇鐐规挱]宸茬粡寮�鍚痳tpServer浣嗘槸灏氭湭鏀跺埌娴侊紝寮�鍚洃鍚祦鐨勫埌鏉�");
- HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", playTransaction.getStream(), true, "rtsp", mediaServerItem.getId());
- zlmHttpHookSubscribe.addSubscribe(hookSubscribe, hookEvent);
- }else {
- playTransaction = null;
- }
- }
+ }else if ("Download".equalsIgnoreCase(sessionName)) {
+ // 鑾峰彇鎸囧畾鐨勪笅杞介�熷害
+ Vector sdpMediaDescriptions = sdp.getMediaDescriptions(true);
+ MediaDescription mediaDescription = null;
+ String downloadSpeed = "1";
+ if (sdpMediaDescriptions.size() > 0) {
+ mediaDescription = (MediaDescription)sdpMediaDescriptions.get(0);
}
- if (playTransaction == null) {
- String streamId = null;
- if (mediaServerItem.isRtpEnable()) {
- streamId = String.format("%s_%s", device.getDeviceId(), channelId);
- }
- SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false);
- logger.info(JSONObject.toJSONString(ssrcInfo));
- sendRtpItem.setStreamId(ssrcInfo.getStream());
- sendRtpItem.setSsrc(ssrc.equals(ssrcDefault) ? ssrcInfo.getSsrc() : ssrc);
+ if (mediaDescription != null) {
+ downloadSpeed = mediaDescription.getAttribute("downloadspeed");
+ }
- // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
- redisCatchStorage.updateSendRTPSever(sendRtpItem);
- playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> {
+ sendRtpItem.setPlayType(InviteStreamType.DOWNLOAD);
+ SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, null, null, device.isSsrcCheck(), true, 0, false, device.getStreamModeForParam());
+ sendRtpItem.setStreamId(ssrcInfo.getStream());
+ // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
+ redisCatchStorage.updateSendRTPSever(sendRtpItem);
+ playService.download(mediaServerItem, ssrcInfo, device.getDeviceId(), channelId, DateUtil.formatter.format(start),
+ DateUtil.formatter.format(end), Integer.parseInt(downloadSpeed),
+ (code, msg, data) -> {
+ if (code == InviteErrorCode.SUCCESS.getCode()){
+ hookEvent.run(code, msg, data);
+ }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
+ logger.info("[褰曞儚涓嬭浇]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId);
+ redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
+ errorEvent.run(code, msg, data);
+ }else {
+ errorEvent.run(code, msg, data);
+ }
+ });
+ }else {
+ sendRtpItem.setPlayType(InviteStreamType.PLAY);
+ String streamId = null;
+ if (mediaServerItem.isRtpEnable()) {
+ streamId = String.format("%s_%s", device.getDeviceId(), channelId);
+ }else {
+ streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
+ }
+ sendRtpItem.setStreamId(streamId);
+ redisCatchStorage.updateSendRTPSever(sendRtpItem);
+ playService.play(mediaServerItem, device.getDeviceId(), channelId, ((code, msg, data) -> {
+ if (code == InviteErrorCode.SUCCESS.getCode()){
+ hookEvent.run(code, msg, data);
+ }else if (code == InviteErrorCode.ERROR_FOR_SIGNALLING_TIMEOUT.getCode() || code == InviteErrorCode.ERROR_FOR_STREAM_TIMEOUT.getCode()){
logger.info("[涓婄骇鐐规挱]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId);
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null);
- }, null);
- } else {
- sendRtpItem.setStreamId(playTransaction.getStream());
- // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
- redisCatchStorage.updateSendRTPSever(sendRtpItem);
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("app", sendRtpItem.getApp());
- jsonObject.put("stream", sendRtpItem.getStreamId());
- hookEvent.response(mediaServerItem, jsonObject);
- }
+ errorEvent.run(code, msg, data);
+ }else {
+ errorEvent.run(code, msg, data);
+ }
+ }));
+
}
} else if (gbStream != null) {
+
+ String ssrc;
+ if (userSetting.getUseCustomSsrcForParentInvite() || ssrcIndex < 0) {
+ // 涓婄骇骞冲彴鐐规挱鏃朵笉浣跨敤涓婄骇骞冲彴鎸囧畾鐨剆src锛屼娇鐢ㄨ嚜瀹氫箟鐨剆src锛屽弬鑰冨浗鏍囨枃妗�-鐐规挱澶栧煙璁惧濯掍綋娴丼SRC澶勭悊鏂瑰紡
+ ssrc = "Play".equalsIgnoreCase(sessionName) ? ssrcFactory.getPlaySsrc(mediaServerItem.getId()) : ssrcFactory.getPlayBackSsrc(mediaServerItem.getId());
+ }else {
+ ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+ }
+
if("push".equals(gbStream.getStreamType())) {
if (streamPushItem != null && streamPushItem.isPushIng()) {
// 鎺ㄦ祦鐘舵��
- pushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ pushStream(evt, request, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
} else {
// 鏈帹娴� 鎷夎捣
- notifyStreamOnline(evt, serverTransaction,gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ notifyStreamOnline(evt, request,gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
}
}else if ("proxy".equals(gbStream.getStreamType())){
- if(null != proxyByAppAndStream &&proxyByAppAndStream.isStatus()){
- pushProxyStream(evt, serverTransaction, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive,
- mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
- }else{
- //寮�鍚唬鐞嗘媺娴�
- boolean start1 = streamProxyService.start(gbStream.getApp(), gbStream.getStream());
- if(start1) {
- pushProxyStream(evt, serverTransaction, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ if (null != proxyByAppAndStream) {
+ if(proxyByAppAndStream.isStatus()){
+ pushProxyStream(evt, request, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
}else{
- //澶辫触鍚庨�氱煡
- notifyStreamOnline(evt, serverTransaction,gbStream, null, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ //寮�鍚唬鐞嗘媺娴�
+ notifyStreamOnline(evt, request,gbStream, null, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
}
}
+
}
}
@@ -533,28 +549,27 @@
} catch (SdpParseException e) {
logger.error("sdp瑙f瀽閿欒", e);
} catch (SdpException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
}
/**
* 瀹夋帓鎺ㄦ祦
*/
- private void pushProxyStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, ParentPlatform platform,
+ private void pushProxyStream(RequestEvent evt, SIPRequest request, GbStream gbStream, ParentPlatform platform,
CallIdHeader callIdHeader, MediaServerItem mediaServerItem,
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
String channelId, String addressStr, String ssrc, String requesterId) {
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, gbStream.getApp(), gbStream.getStream());
- if (streamReady) {
+ if (streamReady != null && streamReady) {
// 鑷钩鍙板唴瀹�
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
- gbStream.getApp(), gbStream.getStream(), channelId,
- mediaTransmissionTCP);
+ gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp());
if (sendRtpItem == null) {
logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
try {
- responseAck(serverTransaction, Response.BUSY_HERE);
+ responseAck(request, Response.BUSY_HERE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�: {}", e.getMessage());
}
@@ -567,10 +582,9 @@
// 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶�
sendRtpItem.setStatus(1);
sendRtpItem.setCallId(callIdHeader.getCallId());
- SIPRequest request = (SIPRequest) evt.getRequest();
sendRtpItem.setFromTag(request.getFromTag());
- SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt);
+ SIPResponse response = sendStreamAck(mediaServerItem, request, sendRtpItem, platform, evt);
if (response != null) {
sendRtpItem.setToTag(response.getToTag());
}
@@ -579,23 +593,22 @@
}
}
- private void pushStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
+ private void pushStream(RequestEvent evt, SIPRequest request, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
CallIdHeader callIdHeader, MediaServerItem mediaServerItem,
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
String channelId, String addressStr, String ssrc, String requesterId) {
// 鎺ㄦ祦
if (streamPushItem.isSelf()) {
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, gbStream.getApp(), gbStream.getStream());
- if (streamReady) {
+ if (streamReady != null && streamReady) {
// 鑷钩鍙板唴瀹�
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
- gbStream.getApp(), gbStream.getStream(), channelId,
- mediaTransmissionTCP);
+ gbStream.getApp(), gbStream.getStream(), channelId, mediaTransmissionTCP, platform.isRtcp());
if (sendRtpItem == null) {
logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
try {
- responseAck(serverTransaction, Response.BUSY_HERE);
+ responseAck(request, Response.BUSY_HERE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�: {}", e.getMessage());
}
@@ -609,9 +622,8 @@
sendRtpItem.setStatus(1);
sendRtpItem.setCallId(callIdHeader.getCallId());
- SIPRequest request = (SIPRequest) evt.getRequest();
sendRtpItem.setFromTag(request.getFromTag());
- SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt);
+ SIPResponse response = sendStreamAck(mediaServerItem, request, sendRtpItem, platform, evt);
if (response != null) {
sendRtpItem.setToTag(response.getToTag());
}
@@ -620,36 +632,59 @@
} else {
// 涓嶅湪绾� 鎷夎捣
- notifyStreamOnline(evt, serverTransaction,gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ notifyStreamOnline(evt, request,gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
}
} else {
// 鍏朵粬骞冲彴鍐呭
- otherWvpPushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ otherWvpPushStream(evt, request, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
}
}
/**
* 閫氱煡娴佷笂绾�
*/
- private void notifyStreamOnline(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
+ private void notifyStreamOnline(RequestEvent evt, SIPRequest request, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
CallIdHeader callIdHeader, MediaServerItem mediaServerItem,
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
String channelId, String addressStr, String ssrc, String requesterId) {
if ("proxy".equals(gbStream.getStreamType())) {
// TODO 鎺у埗鍚敤浠ヤ娇璁惧涓婄嚎
logger.info("[ app={}, stream={} ]閫氶亾鏈帹娴侊紝鍚敤娴佸悗寮�濮嬫帹娴�", gbStream.getApp(), gbStream.getStream());
- try {
- responseAck(serverTransaction, Response.BAD_REQUEST, "channel [" + gbStream.getGbId() + "] offline");
- } catch (SipException | InvalidArgumentException | ParseException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 invite 閫氶亾鏈帹娴�: {}", e.getMessage());
+ // 鐩戝惉娴佷笂绾�
+ HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed(gbStream.getApp(), gbStream.getStream(), true, "rtsp", mediaServerItem.getId());
+ zlmHttpHookSubscribe.addSubscribe(hookSubscribe, (mediaServerItemInUSe, responseJSON) -> {
+ String app = responseJSON.getString("app");
+ String stream = responseJSON.getString("stream");
+ logger.info("[涓婄骇鐐规挱]鎷夋祦浠g悊宸茬粡灏辩华锛� {}/{}", app, stream);
+ dynamicTask.stop(callIdHeader.getCallId());
+ pushProxyStream(evt, request, gbStream, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
+ });
+ dynamicTask.startDelay(callIdHeader.getCallId(), () -> {
+ logger.info("[ app={}, stream={} ] 绛夊緟鎷夋祦浠g悊娴佽秴鏃�", gbStream.getApp(), gbStream.getStream());
+ zlmHttpHookSubscribe.removeSubscribe(hookSubscribe);
+ }, userSetting.getPlatformPlayTimeout());
+ boolean start = streamProxyService.start(gbStream.getApp(), gbStream.getStream());
+ if (!start) {
+ try {
+ responseAck(request, Response.BUSY_HERE, "channel [" + gbStream.getGbId() + "] offline");
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 invite 閫氶亾鏈帹娴�: {}", e.getMessage());
+ }
+ zlmHttpHookSubscribe.removeSubscribe(hookSubscribe);
+ dynamicTask.stop(callIdHeader.getCallId());
}
+
+
+
} else if ("push".equals(gbStream.getStreamType())) {
if (!platform.isStartOfflinePush()) {
// 骞冲彴璁剧疆涓叧闂簡鎷夎捣绂荤嚎鐨勬帹娴佸垯鐩存帴鍥炲
try {
- responseAck(serverTransaction, Response.TEMPORARILY_UNAVAILABLE, "channel stream not pushing");
+ logger.info("[涓婄骇鐐规挱] 澶辫触锛屾帹娴佽澶囨湭鎺ㄦ祦锛宑hannel: {}, app: {}, stream: {}", gbStream.getGbId(), gbStream.getApp(), gbStream.getStream());
+ responseAck(request, Response.TEMPORARILY_UNAVAILABLE, "channel stream not pushing");
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 閫氶亾鏈帹娴�: {}", e.getMessage());
}
@@ -667,13 +702,13 @@
logger.info("[ app={}, stream={} ] 绛夊緟璁惧寮�濮嬫帹娴佽秴鏃�", gbStream.getApp(), gbStream.getStream());
try {
mediaListManager.removedChannelOnlineEventLister(gbStream.getApp(), gbStream.getStream());
- responseAck(serverTransaction, Response.REQUEST_TIMEOUT); // 瓒呮椂
+ responseAck(request, Response.REQUEST_TIMEOUT); // 瓒呮椂
} catch (SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (InvalidArgumentException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (ParseException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
}, userSetting.getPlatformPlayTimeout());
// 娣诲姞鐩戝惉
@@ -685,18 +720,18 @@
dynamicTask.stop(callIdHeader.getCallId());
if (serverId.equals(userSetting.getServerId())) {
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, finalPort, ssrc, requesterId,
- app, stream, channelId, mediaTransmissionTCP);
+ app, stream, channelId, mediaTransmissionTCP, platform.isRtcp());
if (sendRtpItem == null) {
logger.warn("涓婄骇鐐规椂鍒涘缓sendRTPItem澶辫触锛屽彲鑳芥槸鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
try {
- responseAck(serverTransaction, Response.BUSY_HERE);
+ responseAck(request, Response.BUSY_HERE);
} catch (SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (InvalidArgumentException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (ParseException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
return;
}
@@ -708,16 +743,15 @@
sendRtpItem.setStatus(1);
sendRtpItem.setCallId(callIdHeader.getCallId());
- SIPRequest request = (SIPRequest) evt.getRequest();
sendRtpItem.setFromTag(request.getFromTag());
- SIPResponse response = sendStreamAck(mediaServerItem, serverTransaction, sendRtpItem, platform, evt);
+ SIPResponse response = sendStreamAck(mediaServerItem, request, sendRtpItem, platform, evt);
if (response != null) {
sendRtpItem.setToTag(response.getToTag());
}
redisCatchStorage.updateSendRTPSever(sendRtpItem);
} else {
// 鍏朵粬骞冲彴鍐呭
- otherWvpPushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ otherWvpPushStream(evt, request, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
}
});
@@ -728,7 +762,7 @@
dynamicTask.stop(callIdHeader.getCallId());
mediaListManager.removedChannelOnlineEventLister(gbStream.getApp(), gbStream.getStream());
try {
- responseAck(serverTransaction, Response.TEMPORARILY_UNAVAILABLE, response.getMsg());
+ responseAck(request, Response.TEMPORARILY_UNAVAILABLE, response.getMsg());
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鐐规挱鍥炲: {}", e.getMessage());
}
@@ -740,7 +774,7 @@
/**
* 鏉ヨ嚜鍏朵粬wvp鐨勬帹娴�
*/
- private void otherWvpPushStream(RequestEvent evt, ServerTransaction serverTransaction, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
+ private void otherWvpPushStream(RequestEvent evt, SIPRequest request, GbStream gbStream, StreamPushItem streamPushItem, ParentPlatform platform,
CallIdHeader callIdHeader, MediaServerItem mediaServerItem,
int port, Boolean tcpActive, boolean mediaTransmissionTCP,
String channelId, String addressStr, String ssrc, String requesterId) {
@@ -748,18 +782,18 @@
// 鍙戦�乺edis娑堟伅
redisGbPlayMsgListener.sendMsg(streamPushItem.getServerId(), streamPushItem.getMediaServerId(),
streamPushItem.getApp(), streamPushItem.getStream(), addressStr, port, ssrc, requesterId,
- channelId, mediaTransmissionTCP, null, responseSendItemMsg -> {
+ channelId, mediaTransmissionTCP, platform.isRtcp(),null, responseSendItemMsg -> {
SendRtpItem sendRtpItem = responseSendItemMsg.getSendRtpItem();
if (sendRtpItem == null || responseSendItemMsg.getMediaServerItem() == null) {
logger.warn("鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�");
try {
- responseAck(serverTransaction, Response.BUSY_HERE);
+ responseAck(request, Response.BUSY_HERE);
} catch (SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (InvalidArgumentException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (ParseException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
return;
}
@@ -772,9 +806,8 @@
sendRtpItem.setStatus(1);
sendRtpItem.setCallId(callIdHeader.getCallId());
- SIPRequest request = (SIPRequest) evt.getRequest();
sendRtpItem.setFromTag(request.getFromTag());
- SIPResponse response = sendStreamAck(responseSendItemMsg.getMediaServerItem(), serverTransaction,sendRtpItem, platform, evt);
+ SIPResponse response = sendStreamAck(responseSendItemMsg.getMediaServerItem(), request,sendRtpItem, platform, evt);
if (response != null) {
sendRtpItem.setToTag(response.getToTag());
}
@@ -788,24 +821,24 @@
StreamPushItem currentStreamPushItem = streamPushService.getPush(streamPushItem.getApp(), streamPushItem.getStream());
if (currentStreamPushItem.isPushIng()) {
// 鍦ㄧ嚎鐘舵��
- pushStream(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ pushStream(evt, request, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
} else {
// 涓嶅湪绾� 鎷夎捣
- notifyStreamOnline(evt, serverTransaction, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
+ notifyStreamOnline(evt, request, gbStream, streamPushItem, platform, callIdHeader, mediaServerItem, port, tcpActive,
mediaTransmissionTCP, channelId, addressStr, ssrc, requesterId);
}
}
try {
- responseAck(serverTransaction, Response.BUSY_HERE);
+ responseAck(request, Response.BUSY_HERE);
} catch (InvalidArgumentException | ParseException | SipException e) {
logger.error("[鍛戒护鍙戦�佸け璐 鍥芥爣绾ц仈 鐐规挱鍥炲 BUSY_HERE: {}", e.getMessage());
}
});
}
- public SIPResponse sendStreamAck(MediaServerItem mediaServerItem, ServerTransaction serverTransaction, SendRtpItem sendRtpItem, ParentPlatform platform, RequestEvent evt) {
+ public SIPResponse sendStreamAck(MediaServerItem mediaServerItem, SIPRequest request, SendRtpItem sendRtpItem, ParentPlatform platform, RequestEvent evt) {
StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n");
@@ -813,7 +846,13 @@
content.append("s=Play\r\n");
content.append("c=IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
content.append("t=0 0\r\n");
- content.append("m=video " + sendRtpItem.getLocalPort() + " RTP/AVP 96\r\n");
+ // 闈炰弗鏍兼ā寮忕鍙d笉缁熶竴, 澧炲姞鍏煎鎬э紝淇敼涓轰竴涓笉涓�0鐨勭鍙�
+ int localPort = sendRtpItem.getLocalPort();
+ if(localPort == 0)
+ {
+ localPort = new Random().nextInt(65535) + 1;
+ }
+ content.append("m=video " + localPort + " RTP/AVP 96\r\n");
content.append("a=sendonly\r\n");
content.append("a=rtpmap:96 PS/90000\r\n");
if (sendRtpItem.isTcp()) {
@@ -828,29 +867,29 @@
content.append("f=\r\n");
try {
- return responseSdpAck(serverTransaction, content.toString(), platform);
+ return responseSdpAck(request, content.toString(), platform);
} catch (SipException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (InvalidArgumentException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
} catch (ParseException e) {
- e.printStackTrace();
+ logger.error("鏈鐞嗙殑寮傚父 ", e);
}
return null;
}
- public void inviteFromDeviceHandle(ServerTransaction serverTransaction, String requesterId) {
+ public void inviteFromDeviceHandle(SIPRequest request, String requesterId) {
// 闈炰笂绾у钩鍙拌姹傦紝鏌ヨ鏄惁璁惧璇锋眰锛堥�氬父涓烘帴鏀惰闊冲箍鎾殑璁惧锛�
Device device = redisCatchStorage.getDevice(requesterId);
if (device != null) {
logger.info("鏀跺埌璁惧" + requesterId + "鐨勮闊冲箍鎾璉nvite璇锋眰");
try {
- responseAck(serverTransaction, Response.TRYING);
+ responseAck(request, Response.TRYING);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite BAD_REQUEST: {}", e.getMessage());
}
- String contentString = new String(serverTransaction.getRequest().getRawContent());
+ String contentString = new String(request.getRawContent());
// jainSip涓嶆敮鎸亂=瀛楁锛� 绉婚櫎绉婚櫎浠ヨВ鏋愩��
String substring = contentString;
String ssrc = "0000000404";
@@ -900,14 +939,14 @@
logger.info("涓嶆敮鎸佺殑濯掍綋鏍煎紡锛岃繑鍥�415");
// 鍥炲涓嶆敮鎸佺殑鏍煎紡
try {
- responseAck(serverTransaction, Response.UNSUPPORTED_MEDIA_TYPE); // 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
+ responseAck(request, Response.UNSUPPORTED_MEDIA_TYPE); // 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 涓嶆敮鎸佺殑濯掍綋鏍煎紡锛岃繑鍥�415锛� {}", e.getMessage());
}
return;
}
String username = sdp.getOrigin().getUsername();
- String addressStr = sdp.getOrigin().getAddress();
+ String addressStr = sdp.getConnection().getAddress();
logger.info("璁惧{}璇锋眰璇煶娴侊紝鍦板潃锛歿}:{}锛宻src锛歿}", username, addressStr, port, ssrc);
} catch (SdpException e) {
logger.error("[SDP瑙f瀽寮傚父]", e);
@@ -918,7 +957,7 @@
} else {
logger.warn("鏉ヨ嚜鏃犳晥璁惧/骞冲彴鐨勮姹�");
try {
- responseAck(serverTransaction, Response.BAD_REQUEST);; // 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
+ responseAck(request, Response.BAD_REQUEST);; // 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 鏉ヨ嚜鏃犳晥璁惧/骞冲彴鐨勮姹傦紝 {}", e.getMessage());
}
--
Gitblit v1.8.0