From 1421b4743ca8c6f32984bfd9e213f8018035e7ae Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期五, 31 三月 2023 08:59:03 +0800 Subject: [PATCH] 修复SQL错误 #802 --- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java | 100 ++++++++++++++++++++++++++++---------------------- 1 files changed, 56 insertions(+), 44 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 9548b85..1a6358b 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,21 +1,21 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; 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.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; -import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; 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; @@ -39,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; /** @@ -157,11 +159,6 @@ StreamProxyItem proxyByAppAndStream =null; // 涓嶆槸閫氶亾鍙兘鏄洿鎾祦 if (channel != null && gbStream == null) { -// if (channel.getStatus() == 0) { -// logger.info("閫氶亾绂荤嚎锛岃繑鍥�400"); -// responseAck(request, Response.BAD_REQUEST, "channel [" + channel.getChannelId() + "] offline"); -// return; -// } // 閫氶亾瀛樺湪锛屽彂100锛孴RYING try { responseAck(request, Response.TRYING); @@ -232,7 +229,7 @@ } return; } else { - logger.info("閫氶亾涓嶅瓨鍦紝杩斿洖404"); + logger.info("閫氶亾涓嶅瓨鍦紝杩斿洖404: {}", channelId); try { // 閫氶亾涓嶅瓨鍦紝鍙�404锛岃祫婧愪笉瀛樺湪 responseAck(request, Response.NOT_FOUND); @@ -318,7 +315,7 @@ 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; @@ -345,8 +342,7 @@ return; } 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); @@ -385,7 +381,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"); @@ -405,12 +406,8 @@ }, 60 * 1000); 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) -> { @@ -419,7 +416,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"); @@ -476,10 +473,11 @@ // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶� redisCatchStorage.updateSendRTPSever(sendRtpItem); + MediaServerItem finalMediaServerItem = mediaServerItem; playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> { logger.info("[涓婄骇鐐规挱]瓒呮椂, 鐢ㄦ埛锛歿}锛� 閫氶亾锛歿}", username, channelId); redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); - }, null); + }); } else { sendRtpItem.setStreamId(playTransaction.getStream()); // 鍐欏叆redis锛� 瓒呮椂鏃跺洖澶� @@ -491,6 +489,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()) { // 鎺ㄦ祦鐘舵�� @@ -520,7 +527,7 @@ } catch (SdpParseException e) { logger.error("sdp瑙f瀽閿欒", e); } catch (SdpException e) { - e.printStackTrace(); + logger.error("鏈鐞嗙殑寮傚父 ", e); } } @@ -535,8 +542,7 @@ if (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祫婧愪笉瓒�"); @@ -575,8 +581,7 @@ if (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祫婧愪笉瓒�"); @@ -656,6 +661,7 @@ if (!platform.isStartOfflinePush()) { // 骞冲彴璁剧疆涓叧闂簡鎷夎捣绂荤嚎鐨勬帹娴佸垯鐩存帴鍥炲 try { + 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()); @@ -676,11 +682,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()); // 娣诲姞鐩戝惉 @@ -692,18 +698,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(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; } @@ -754,18 +760,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(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; } @@ -818,7 +824,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()) { @@ -835,11 +847,11 @@ try { 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; } @@ -912,7 +924,7 @@ 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); -- Gitblit v1.8.0