合并主线

结构优化
648540858 2022-10-17 12:47:02 +08:00
parent 6bfd48776d
commit 6a2ff99515
2 changed files with 46 additions and 27 deletions

View File

@ -159,12 +159,33 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
String requesterId = SipUtils.getUserIdFromFromHeader(request); String requesterId = SipUtils.getUserIdFromFromHeader(request);
CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME); CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME);
ServerTransaction serverTransaction = getServerTransaction(evt); ServerTransaction serverTransaction = getServerTransaction(evt);
if (requesterId == null || channelId == null) { if (requesterId == null) {
logger.info("无法从FromHeader的Address中获取到平台id返回400"); logger.info("无法从FromHeader的Address中获取到平台/设备id返回400");
// 参数不全, 发400请求错误 // 参数不全, 发400请求错误
responseAck(serverTransaction, Response.BAD_REQUEST); responseAck(serverTransaction, Response.BAD_REQUEST);
return; return;
} }
String ssrc = null;
SessionDescription sdp = null;
String ssrcDefault = "0000000000";
if (channelId == null) {
// 解析sdp消息, 使用jainsip 自带的sdp解析方式
String contentString = new String(request.getRawContent());
// jainSip不支持y=字段, 移除以解析。
int ssrcIndex = contentString.indexOf("y=");
if (ssrcIndex >= 0) {
//ssrc规定长度为10个字节不取余下长度以避免后续还有“f=”字段
ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
String substring = contentString.substring(0, contentString.indexOf("y="));
sdp = SdpFactory.getInstance().createSessionDescription(substring);
} else {
ssrc = ssrcDefault;
sdp = SdpFactory.getInstance().createSessionDescription(contentString);
}
channelId = sdp.getOrigin().getUsername();
}
// 查询请求是否来自上级平台\设备 // 查询请求是否来自上级平台\设备
@ -232,24 +253,23 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
responseAck(serverTransaction, Response.NOT_FOUND); // 通道不存在发404资源不存在 responseAck(serverTransaction, Response.NOT_FOUND); // 通道不存在发404资源不存在
return; return;
} }
// 解析sdp消息, 使用jainsip 自带的sdp解析方式 if (sdp == null || ssrc == null) {
String contentString = new String(request.getRawContent()); // 解析sdp消息, 使用jainsip 自带的sdp解析方式
String contentString = new String(request.getRawContent());
// jainSip不支持y=字段, 移除以解析。 // jainSip不支持y=字段, 移除以解析。
int ssrcIndex = contentString.indexOf("y="); int ssrcIndex = contentString.indexOf("y=");
// 检查是否有y字段 if (ssrcIndex >= 0) {
String ssrcDefault = "0000000000"; //ssrc规定长度为10个字节不取余下长度以避免后续还有“f=”字段
String ssrc; ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
SessionDescription sdp; String substring = contentString.substring(0, contentString.indexOf("y="));
if (ssrcIndex >= 0) { sdp = SdpFactory.getInstance().createSessionDescription(substring);
//ssrc规定长度为10个字节不取余下长度以避免后续还有“f=”字段 } else {
ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); ssrc = ssrcDefault;
String substring = contentString.substring(0, contentString.indexOf("y=")); sdp = SdpFactory.getInstance().createSessionDescription(contentString);
sdp = SdpFactory.getInstance().createSessionDescription(substring); }
} else {
ssrc = ssrcDefault;
sdp = SdpFactory.getInstance().createSessionDescription(contentString);
} }
String sessionName = sdp.getSessionName().getValue(); String sessionName = sdp.getSessionName().getValue();
Long startTime = null; Long startTime = null;
@ -339,6 +359,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
Long finalStartTime = startTime; Long finalStartTime = startTime;
Long finalStopTime = stopTime; Long finalStopTime = stopTime;
String finalChannelId = channelId;
ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> { ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> {
String app = responseJSON.getString("app"); String app = responseJSON.getString("app");
String stream = responseJSON.getString("stream"); String stream = responseJSON.getString("stream");
@ -351,7 +372,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
StringBuffer content = new StringBuffer(200); StringBuffer content = new StringBuffer(200);
content.append("v=0\r\n"); content.append("v=0\r\n");
content.append("o=" + channelId + " 0 0 IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n"); content.append("o=" + finalChannelId + " 0 0 IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n");
content.append("s=" + sessionName + "\r\n"); content.append("s=" + sessionName + "\r\n");
content.append("c=IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n"); content.append("c=IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n");
if ("Playback".equalsIgnoreCase(sessionName)) { if ("Playback".equalsIgnoreCase(sessionName)) {
@ -416,7 +437,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
if (result.getEvent() != null) { if (result.getEvent() != null) {
errorEvent.response(result.getEvent()); errorEvent.response(result.getEvent());
} }
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), finalChannelId, callIdHeader.getCallId(), null);
try { try {
responseAck(serverTransaction, Response.REQUEST_TIMEOUT); responseAck(serverTransaction, Response.REQUEST_TIMEOUT);
} catch (SipException e) { } catch (SipException e) {
@ -461,8 +482,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
// 写入redis 超时时回复 // 写入redis 超时时回复
redisCatchStorage.updateSendRTPSever(sendRtpItem); redisCatchStorage.updateSendRTPSever(sendRtpItem);
playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> { playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> {
logger.info("[上级点播]超时, 用户:{} 通道:{}", username, channelId); logger.info("[上级点播]超时, 用户:{} 通道:{}", username, finalChannelId);
redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), finalChannelId, callIdHeader.getCallId(), null);
}, null); }, null);
} else { } else {
sendRtpItem.setStreamId(playTransaction.getStream()); sendRtpItem.setStreamId(playTransaction.getStream());
@ -916,7 +937,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream); Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream);
if (streamReady) { if (streamReady) {
sendOk(device, sendRtpItem, sdp, serverTransaction, mediaServerItem, mediaTransmissionTCP, ssrc); sendOk(device, sendRtpItem, sdp, serverTransaction, mediaServerItem, mediaTransmissionTCP, ssrc);
}else { }else {
logger.warn("[语音通话] 未发现待推送的流,app={},stream={}", app, stream); logger.warn("[语音通话] 未发现待推送的流,app={},stream={}", app, stream);
playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId()); playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());

View File

@ -609,8 +609,6 @@ public class PlayServiceImpl implements IPlayService {
MediaServerItem mediaServerItem; MediaServerItem mediaServerItem;
if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) {
mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); mediaServerItem = mediaServerService.getMediaServerForMinimumLoad();
} else {
mediaServerItem = mediaServerService.getOne(mediaServerId);
} else { } else {
mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); mediaServerItem = mediaServerService.getOne(device.getMediaServerId());
} }
@ -987,9 +985,9 @@ public class PlayServiceImpl implements IPlayService {
return null; return null;
} }
MediaServerItem mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); MediaServerItem mediaServerItem = mediaServerService.getMediaServerForMinimumLoad();
// String app = "broadcast"; String app = "broadcast";
// TODO 从sip user agent中判断是什么品牌设备大华默认使用talk模式其他使用broadcast模式 // TODO 从sip user agent中判断是什么品牌设备大华默认使用talk模式其他使用broadcast模式
String app = "talk"; // String app = "talk";
String stream = device.getDeviceId() + "_" + channelId; String stream = device.getDeviceId() + "_" + channelId;
StreamInfo broadcast = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "broadcast", stream, null, null, null, false); StreamInfo broadcast = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "broadcast", stream, null, null, null, false);
AudioBroadcastResult audioBroadcastResult = new AudioBroadcastResult(); AudioBroadcastResult audioBroadcastResult = new AudioBroadcastResult();