Commit 6a2ff9951584cb014a8e07703678e0f4d748746d

Authored by 648540858
1 parent 6bfd4877

合并主线

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -159,12 +159,33 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -159,12 +159,33 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
159 String requesterId = SipUtils.getUserIdFromFromHeader(request); 159 String requesterId = SipUtils.getUserIdFromFromHeader(request);
160 CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME); 160 CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME);
161 ServerTransaction serverTransaction = getServerTransaction(evt); 161 ServerTransaction serverTransaction = getServerTransaction(evt);
162 - if (requesterId == null || channelId == null) {  
163 - logger.info("无法从FromHeader的Address中获取到平台id,返回400"); 162 + if (requesterId == null) {
  163 + logger.info("无法从FromHeader的Address中获取到平台/设备id,返回400");
164 // 参数不全, 发400,请求错误 164 // 参数不全, 发400,请求错误
165 responseAck(serverTransaction, Response.BAD_REQUEST); 165 responseAck(serverTransaction, Response.BAD_REQUEST);
166 return; 166 return;
167 } 167 }
  168 + String ssrc = null;
  169 + SessionDescription sdp = null;
  170 + String ssrcDefault = "0000000000";
  171 + if (channelId == null) {
  172 + // 解析sdp消息, 使用jainsip 自带的sdp解析方式
  173 + String contentString = new String(request.getRawContent());
  174 +
  175 + // jainSip不支持y=字段, 移除以解析。
  176 + int ssrcIndex = contentString.indexOf("y=");
  177 +
  178 + if (ssrcIndex >= 0) {
  179 + //ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段
  180 + ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
  181 + String substring = contentString.substring(0, contentString.indexOf("y="));
  182 + sdp = SdpFactory.getInstance().createSessionDescription(substring);
  183 + } else {
  184 + ssrc = ssrcDefault;
  185 + sdp = SdpFactory.getInstance().createSessionDescription(contentString);
  186 + }
  187 + channelId = sdp.getOrigin().getUsername();
  188 + }
168 189
169 190
170 // 查询请求是否来自上级平台\设备 191 // 查询请求是否来自上级平台\设备
@@ -232,24 +253,23 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -232,24 +253,23 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
232 responseAck(serverTransaction, Response.NOT_FOUND); // 通道不存在,发404,资源不存在 253 responseAck(serverTransaction, Response.NOT_FOUND); // 通道不存在,发404,资源不存在
233 return; 254 return;
234 } 255 }
235 - // 解析sdp消息, 使用jainsip 自带的sdp解析方式  
236 - String contentString = new String(request.getRawContent());  
237 -  
238 - // jainSip不支持y=字段, 移除以解析。  
239 - int ssrcIndex = contentString.indexOf("y=");  
240 - // 检查是否有y字段  
241 - String ssrcDefault = "0000000000";  
242 - String ssrc;  
243 - SessionDescription sdp;  
244 - if (ssrcIndex >= 0) {  
245 - //ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段  
246 - ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);  
247 - String substring = contentString.substring(0, contentString.indexOf("y="));  
248 - sdp = SdpFactory.getInstance().createSessionDescription(substring);  
249 - } else {  
250 - ssrc = ssrcDefault;  
251 - sdp = SdpFactory.getInstance().createSessionDescription(contentString); 256 + if (sdp == null || ssrc == null) {
  257 + // 解析sdp消息, 使用jainsip 自带的sdp解析方式
  258 + String contentString = new String(request.getRawContent());
  259 +
  260 + // jainSip不支持y=字段, 移除以解析。
  261 + int ssrcIndex = contentString.indexOf("y=");
  262 + if (ssrcIndex >= 0) {
  263 + //ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段
  264 + ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
  265 + String substring = contentString.substring(0, contentString.indexOf("y="));
  266 + sdp = SdpFactory.getInstance().createSessionDescription(substring);
  267 + } else {
  268 + ssrc = ssrcDefault;
  269 + sdp = SdpFactory.getInstance().createSessionDescription(contentString);
  270 + }
252 } 271 }
  272 +
253 String sessionName = sdp.getSessionName().getValue(); 273 String sessionName = sdp.getSessionName().getValue();
254 274
255 Long startTime = null; 275 Long startTime = null;
@@ -339,6 +359,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -339,6 +359,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
339 359
340 Long finalStartTime = startTime; 360 Long finalStartTime = startTime;
341 Long finalStopTime = stopTime; 361 Long finalStopTime = stopTime;
  362 + String finalChannelId = channelId;
342 ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> { 363 ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> {
343 String app = responseJSON.getString("app"); 364 String app = responseJSON.getString("app");
344 String stream = responseJSON.getString("stream"); 365 String stream = responseJSON.getString("stream");
@@ -351,7 +372,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -351,7 +372,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
351 372
352 StringBuffer content = new StringBuffer(200); 373 StringBuffer content = new StringBuffer(200);
353 content.append("v=0\r\n"); 374 content.append("v=0\r\n");
354 - content.append("o=" + channelId + " 0 0 IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n"); 375 + content.append("o=" + finalChannelId + " 0 0 IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n");
355 content.append("s=" + sessionName + "\r\n"); 376 content.append("s=" + sessionName + "\r\n");
356 content.append("c=IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n"); 377 content.append("c=IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n");
357 if ("Playback".equalsIgnoreCase(sessionName)) { 378 if ("Playback".equalsIgnoreCase(sessionName)) {
@@ -416,7 +437,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -416,7 +437,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
416 if (result.getEvent() != null) { 437 if (result.getEvent() != null) {
417 errorEvent.response(result.getEvent()); 438 errorEvent.response(result.getEvent());
418 } 439 }
419 - redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); 440 + redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), finalChannelId, callIdHeader.getCallId(), null);
420 try { 441 try {
421 responseAck(serverTransaction, Response.REQUEST_TIMEOUT); 442 responseAck(serverTransaction, Response.REQUEST_TIMEOUT);
422 } catch (SipException e) { 443 } catch (SipException e) {
@@ -461,8 +482,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -461,8 +482,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
461 // 写入redis, 超时时回复 482 // 写入redis, 超时时回复
462 redisCatchStorage.updateSendRTPSever(sendRtpItem); 483 redisCatchStorage.updateSendRTPSever(sendRtpItem);
463 playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> { 484 playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> {
464 - logger.info("[上级点播]超时, 用户:{}, 通道:{}", username, channelId);  
465 - redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); 485 + logger.info("[上级点播]超时, 用户:{}, 通道:{}", username, finalChannelId);
  486 + redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), finalChannelId, callIdHeader.getCallId(), null);
466 }, null); 487 }, null);
467 } else { 488 } else {
468 sendRtpItem.setStreamId(playTransaction.getStream()); 489 sendRtpItem.setStreamId(playTransaction.getStream());
@@ -916,7 +937,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -916,7 +937,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
916 937
917 Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream); 938 Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream);
918 if (streamReady) { 939 if (streamReady) {
919 - sendOk(device, sendRtpItem, sdp, serverTransaction, mediaServerItem, mediaTransmissionTCP, ssrc); 940 + sendOk(device, sendRtpItem, sdp, serverTransaction, mediaServerItem, mediaTransmissionTCP, ssrc);
920 }else { 941 }else {
921 logger.warn("[语音通话], 未发现待推送的流,app={},stream={}", app, stream); 942 logger.warn("[语音通话], 未发现待推送的流,app={},stream={}", app, stream);
922 playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId()); 943 playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -610,8 +610,6 @@ public class PlayServiceImpl implements IPlayService { @@ -610,8 +610,6 @@ public class PlayServiceImpl implements IPlayService {
610 if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { 610 if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) {
611 mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); 611 mediaServerItem = mediaServerService.getMediaServerForMinimumLoad();
612 } else { 612 } else {
613 - mediaServerItem = mediaServerService.getOne(mediaServerId);  
614 - } else {  
615 mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); 613 mediaServerItem = mediaServerService.getOne(device.getMediaServerId());
616 } 614 }
617 if (mediaServerItem == null) { 615 if (mediaServerItem == null) {
@@ -987,9 +985,9 @@ public class PlayServiceImpl implements IPlayService { @@ -987,9 +985,9 @@ public class PlayServiceImpl implements IPlayService {
987 return null; 985 return null;
988 } 986 }
989 MediaServerItem mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); 987 MediaServerItem mediaServerItem = mediaServerService.getMediaServerForMinimumLoad();
990 -// String app = "broadcast"; 988 + String app = "broadcast";
991 // TODO 从sip user agent中判断是什么品牌设备,大华默认使用talk模式,其他使用broadcast模式 989 // TODO 从sip user agent中判断是什么品牌设备,大华默认使用talk模式,其他使用broadcast模式
992 - String app = "talk"; 990 +// String app = "talk";
993 String stream = device.getDeviceId() + "_" + channelId; 991 String stream = device.getDeviceId() + "_" + channelId;
994 StreamInfo broadcast = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "broadcast", stream, null, null, null, false); 992 StreamInfo broadcast = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "broadcast", stream, null, null, null, false);
995 AudioBroadcastResult audioBroadcastResult = new AudioBroadcastResult(); 993 AudioBroadcastResult audioBroadcastResult = new AudioBroadcastResult();