From b4048fbe80dba8e7756ae557a15ab60b4f80a44b Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期二, 04 四月 2023 09:09:07 +0800 Subject: [PATCH] 合并开源主线 --- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java | 96 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 66 insertions(+), 30 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 817ce3b..30ac381 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 @@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager; +import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; import com.genersoft.iot.vmp.gb28181.transmit.SIPSender; @@ -202,7 +203,7 @@ MediaServerItem mediaServerItem = null; StreamPushItem streamPushItem = null; - StreamProxyItem proxyByAppAndStream =null; + StreamProxyItem proxyByAppAndStream = null; // 涓嶆槸閫氶亾鍙兘鏄洿鎾祦 if (channel != null && gbStream == null) { // 閫氶亾瀛樺湪锛屽彂100锛孴RYING @@ -457,12 +458,8 @@ if (!userSetting.getPushStreamAfterAck()) { playService.startPushStream(sendRtpItem, sipResponse, platform, request.getCallIdHeader()); } - } 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) -> { @@ -471,7 +468,7 @@ Response response = getMessageFactory().createResponse(event.statusCode, evt.getRequest()); sipSender.transmitRequest(request.getLocalAddress().getHostAddress(), response); } catch (ParseException | SipException e) { - e.printStackTrace(); + logger.error("鏈鐞嗙殑寮傚父 ", e); } }); sendRtpItem.setApp("rtp"); @@ -543,6 +540,15 @@ } } } else if (gbStream != null) { + if(ssrc.equals(ssrcDefault)) + { + SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); + if(ssrcConfig != null) + { + ssrc = ssrcConfig.getPlaySsrc(); + ssrcConfig.releaseSsrc(ssrc); + } + } if("push".equals(gbStream.getStreamType())) { if (streamPushItem != null && streamPushItem.isPushIng()) { // 鎺ㄦ祦鐘舵�� @@ -572,7 +578,7 @@ } catch (SdpParseException e) { logger.error("sdp瑙f瀽閿欒", e); } catch (SdpException e) { - e.printStackTrace(); + logger.error("鏈鐞嗙殑寮傚父 ", e); } } @@ -727,11 +733,11 @@ mediaListManager.removedChannelOnlineEventLister(gbStream.getApp(), gbStream.getStream()); 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()); // 娣诲姞鐩戝惉 @@ -750,11 +756,11 @@ try { 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; } @@ -812,11 +818,11 @@ try { 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; } @@ -869,7 +875,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()) { @@ -890,20 +902,46 @@ } return sipResponse; } 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(SIPRequest request, String requesterId, String channelId) { + String realChannelId = null; + // 闈炰笂绾у钩鍙拌姹傦紝鏌ヨ鏄惁璁惧璇锋眰锛堥�氬父涓烘帴鏀惰闊冲箍鎾殑璁惧锛� Device device = redisCatchStorage.getDevice(requesterId); - AudioBroadcastCatch broadcastCatch = audioBroadcastManager.get(requesterId, channelId); + // 鍒ゆ柇requesterId鏄澶囪繕鏄�氶亾 + if (device == null) { + device = storager.queryVideoDeviceByChannelId(requesterId); + realChannelId = requesterId; + } + if (device == null) { + // 妫�鏌hannelID鏄惁鍙敤 + device = redisCatchStorage.getDevice(channelId); + if (device == null) { + device = storager.queryVideoDeviceByChannelId(channelId); + realChannelId = channelId; + } + } + + if (device == null) { + logger.warn("鏉ヨ嚜璁惧鐨処nvite璇锋眰锛屾棤娉曚粠璇锋眰淇℃伅涓‘瀹氭墍灞炶澶囷紝宸插拷鐣ワ紝requesterId锛� {}/{}", requesterId, channelId); + try { + responseAck(request, Response.FORBIDDEN); + } catch (SipException | InvalidArgumentException | ParseException e) { + logger.error("[鍛戒护鍙戦�佸け璐 鏉ヨ嚜璁惧鐨処nvite璇锋眰锛屾棤娉曚粠璇锋眰淇℃伅涓‘瀹氭墍灞炶澶� FORBIDDEN: {}", e.getMessage()); + } + return; + } + + AudioBroadcastCatch broadcastCatch = audioBroadcastManager.get(device.getDeviceId(), realChannelId); if (broadcastCatch == null) { logger.warn("鏉ヨ嚜璁惧鐨処nvite璇锋眰闈炶闊冲箍鎾紝宸插拷鐣ワ紝requesterId锛� {}/{}", requesterId, channelId); try { @@ -986,22 +1024,20 @@ logger.info("璁惧{}璇锋眰璇煶娴侊紝鍦板潃锛歿}:{}锛宻src锛歿}, {}", requesterId, addressStr, port, ssrc, mediaTransmissionTCP ? (tcpActive? "TCP涓诲姩":"TCP琚姩") : "UDP"); - MediaServerItem mediaServerItem = audioBroadcastCatch.getMediaServerItem(); + MediaServerItem mediaServerItem = broadcastCatch.getMediaServerItem(); if (mediaServerItem == null) { logger.warn("鏈壘鍒拌闊冲枈璇濅娇鐢ㄧ殑zlm"); try { responseAck(request, Response.BUSY_HERE); } catch (SipException | InvalidArgumentException | ParseException e) { logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈壘鍒板彲鐢ㄧ殑zlm: {}", e.getMessage()); - playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId()); + playService.stopAudioBroadcast(device.getDeviceId(), broadcastCatch.getChannelId()); } return; } - String addressStr = sdp.getConnection().getAddress(); logger.info("璁惧{}璇锋眰璇煶娴侊紝 鏀舵祦鍦板潃锛歿}:{}锛宻src锛歿}, {}, 瀵硅鏂瑰紡锛歿}", requesterId, addressStr, port, ssrc, mediaTransmissionTCP ? (tcpActive? "TCP涓诲姩":"TCP琚姩") : "UDP", sdp.getSessionName().getValue()); - MediaServerItem mediaServerItem = broadcastCatch.getMediaServerItem(); SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId, device.getDeviceId(), broadcastCatch.getChannelId(), mediaTransmissionTCP, false); @@ -1020,12 +1056,12 @@ CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME); - sendRtpItem.setPlayType(InviteStreamType.TALK); + sendRtpItem.setPlayType(InviteStreamType.BROADCAST); sendRtpItem.setCallId(callIdHeader.getCallId()); sendRtpItem.setPlatformId(requesterId); sendRtpItem.setStatus(1); sendRtpItem.setApp(broadcastCatch.getApp()); - sendRtpItem.setStreamId(broadcastCatch.getStream()); + sendRtpItem.setStream(broadcastCatch.getStream()); sendRtpItem.setPt(8); sendRtpItem.setUsePs(false); sendRtpItem.setRtcp(false); @@ -1115,7 +1151,7 @@ } } catch (SipException | InvalidArgumentException | ParseException | SdpParseException e) { - logger.error("[鍛戒护鍙戦�佸け璐 璇煶瀵硅 鍥炲200OK锛圫DP锛�: {}", e.getMessage()); + logger.error("[鍛戒护鍙戦�佸け璐 璇煶鍠婅瘽 鍥炲200OK锛圫DP锛�: {}", e.getMessage()); } return sipResponse; } -- Gitblit v1.8.0