Commit fb90dfdac54dfc9550604ef699e6390d433368b6

Authored by 648540858
1 parent 1458014f

临时提交

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -1031,6 +1031,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -1031,6 +1031,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
1031 logger.info("设备{}请求语音流, 收流地址:{}:{},ssrc:{}, {}, 对讲方式:{}", requesterId, addressStr, port, ssrc, 1031 logger.info("设备{}请求语音流, 收流地址:{}:{},ssrc:{}, {}, 对讲方式:{}", requesterId, addressStr, port, ssrc,
1032 mediaTransmissionTCP ? (tcpActive ? "TCP主动" : "TCP被动") : "UDP", sdp.getSessionName().getValue()); 1032 mediaTransmissionTCP ? (tcpActive ? "TCP主动" : "TCP被动") : "UDP", sdp.getSessionName().getValue());
1033 CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME); 1033 CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME);
  1034 +
1034 SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId, 1035 SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
1035 device.getDeviceId(), broadcastCatch.getChannelId(), 1036 device.getDeviceId(), broadcastCatch.getChannelId(),
1036 mediaTransmissionTCP, false, ssrcFromCallback -> { 1037 mediaTransmissionTCP, false, ssrcFromCallback -> {
@@ -1050,7 +1051,6 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @@ -1050,7 +1051,6 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
1050 } 1051 }
1051 1052
1052 1053
1053 -  
1054 sendRtpItem.setPlayType(InviteStreamType.BROADCAST); 1054 sendRtpItem.setPlayType(InviteStreamType.BROADCAST);
1055 sendRtpItem.setCallId(callIdHeader.getCallId()); 1055 sendRtpItem.setCallId(callIdHeader.getCallId());
1056 sendRtpItem.setPlatformId(requesterId); 1056 sendRtpItem.setPlatformId(requesterId);
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -174,9 +174,10 @@ public class ZLMRTPServerFactory { @@ -174,9 +174,10 @@ public class ZLMRTPServerFactory {
174 Map<String, Object> param = new HashMap<>(); 174 Map<String, Object> param = new HashMap<>();
175 param.put("stream_id", streamId); 175 param.put("stream_id", streamId);
176 JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(serverItem, param); 176 JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(serverItem, param);
  177 + logger.info("关闭RTP Server " + jsonObject);
177 if (jsonObject != null ) { 178 if (jsonObject != null ) {
178 if (jsonObject.getInteger("code") == 0) { 179 if (jsonObject.getInteger("code") == 0) {
179 - result = jsonObject.getInteger("hit") == 1; 180 + result = jsonObject.getInteger("hit") >= 1;
180 }else { 181 }else {
181 logger.error("关闭RTP Server 失败: " + jsonObject.getString("msg")); 182 logger.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
182 } 183 }
@@ -301,6 +302,7 @@ public class ZLMRTPServerFactory { @@ -301,6 +302,7 @@ public class ZLMRTPServerFactory {
301 param.put("port", localPort); 302 param.put("port", localPort);
302 param.put("enable_tcp", 1); 303 param.put("enable_tcp", 1);
303 param.put("stream_id", ssrc); 304 param.put("stream_id", ssrc);
  305 + param.put("re_use_port", 1);
304 JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param); 306 JSONObject jsonObject = zlmresTfulUtils.openRtpServer(serverItem, param);
305 if (jsonObject.getInteger("code") == 0) { 307 if (jsonObject.getInteger("code") == 0) {
306 localPort = jsonObject.getInteger("port"); 308 localPort = jsonObject.getInteger("port");
@@ -335,6 +337,11 @@ public class ZLMRTPServerFactory { @@ -335,6 +337,11 @@ public class ZLMRTPServerFactory {
335 public boolean releasePort(MediaServerItem serverItem, String ssrc) { 337 public boolean releasePort(MediaServerItem serverItem, String ssrc) {
336 logger.info("[保持端口] {}->释放监听端口", ssrc); 338 logger.info("[保持端口] {}->释放监听端口", ssrc);
337 boolean closeRTPServerResult = closeRtpServer(serverItem, ssrc); 339 boolean closeRTPServerResult = closeRtpServer(serverItem, ssrc);
  340 + try {
  341 + Thread.sleep(1000);
  342 + } catch (InterruptedException e) {
  343 + throw new RuntimeException(e);
  344 + }
338 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId()); 345 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, serverItem.getId());
339 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 346 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统
340 hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout); 347 hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -25,7 +25,6 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; @@ -25,7 +25,6 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
25 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; 25 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
26 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; 26 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
27 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; 27 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
28 -import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout;  
29 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; 28 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
30 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; 29 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
31 import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; 30 import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam;
@@ -1436,14 +1435,10 @@ public class PlayServiceImpl implements IPlayService { @@ -1436,14 +1435,10 @@ public class PlayServiceImpl implements IPlayService {
1436 1435
1437 @Override 1436 @Override
1438 public void startPushStream(SendRtpItem sendRtpItem, SIPResponse sipResponse, ParentPlatform platform, CallIdHeader callIdHeader) { 1437 public void startPushStream(SendRtpItem sendRtpItem, SIPResponse sipResponse, ParentPlatform platform, CallIdHeader callIdHeader) {
1439 -  
1440 // 开始发流 1438 // 开始发流
1441 - // 取消设置的超时任务  
1442 -// String channelId = request.getCallIdHeader().getCallId();  
1443 -  
1444 String is_Udp = sendRtpItem.isTcp() ? "0" : "1"; 1439 String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
1445 MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId()); 1440 MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
1446 - logger.info("收到ACK,rtp/{}开始推流, 目标={}:{},SSRC={}, RTCP={}", sendRtpItem.getStream(), 1441 + logger.info("[开始推流] rtp/{}, 目标={}:{},SSRC={}, RTCP={}", sendRtpItem.getStream(),
1447 sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isRtcp()); 1442 sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isRtcp());
1448 Map<String, Object> param = new HashMap<>(12); 1443 Map<String, Object> param = new HashMap<>(12);
1449 param.put("vhost", "__defaultVhost__"); 1444 param.put("vhost", "__defaultVhost__");
@@ -1469,19 +1464,16 @@ public class PlayServiceImpl implements IPlayService { @@ -1469,19 +1464,16 @@ public class PlayServiceImpl implements IPlayService {
1469 startSendRtpStreamHand(sendRtpItem, platform, json, param, callIdHeader); 1464 startSendRtpStreamHand(sendRtpItem, platform, json, param, callIdHeader);
1470 }); 1465 });
1471 } else { 1466 } else {
1472 - // 如果是严格模式,需要关闭端口占用 1467 + // 如果是严格模式,需要关闭端口占用
1473 JSONObject startSendRtpStreamResult = null; 1468 JSONObject startSendRtpStreamResult = null;
1474 if (sendRtpItem.getLocalPort() != 0) { 1469 if (sendRtpItem.getLocalPort() != 0) {
1475 - HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(sendRtpItem.getSsrc(), null, mediaInfo.getId());  
1476 - hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);  
1477 - if (zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc())) {  
1478 - if (sendRtpItem.isTcpActive()) {  
1479 - startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);  
1480 - } else {  
1481 - param.put("dst_url", sendRtpItem.getIp());  
1482 - param.put("dst_port", sendRtpItem.getPort());  
1483 - startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);  
1484 - } 1470 + zlmrtpServerFactory.releasePort(mediaInfo, sendRtpItem.getSsrc());
  1471 + if (sendRtpItem.isTcpActive()) {
  1472 + startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, param);
  1473 + } else {
  1474 + param.put("dst_url", sendRtpItem.getIp());
  1475 + param.put("dst_port", sendRtpItem.getPort());
  1476 + startSendRtpStreamResult = zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
1485 } 1477 }
1486 } else { 1478 } else {
1487 if (sendRtpItem.isTcpActive()) { 1479 if (sendRtpItem.isTcpActive()) {
@@ -1505,7 +1497,8 @@ public class PlayServiceImpl implements IPlayService { @@ -1505,7 +1497,8 @@ public class PlayServiceImpl implements IPlayService {
1505 logger.error("RTP推流失败: 请检查ZLM服务"); 1497 logger.error("RTP推流失败: 请检查ZLM服务");
1506 } else if (jsonObject.getInteger("code") == 0) { 1498 } else if (jsonObject.getInteger("code") == 0) {
1507 logger.info("调用ZLM推流接口, 结果: {}", jsonObject); 1499 logger.info("调用ZLM推流接口, 结果: {}", jsonObject);
1508 - logger.info("RTP推流成功[ {}/{} ],{}->{}:{}, ", param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port")); 1500 + logger.info("RTP推流成功[ {}/{} ],{}->{}, ", param.get("app"), param.get("stream"), jsonObject.getString("local_port"),
  1501 + sendRtpItem.isTcpActive()?"被动发流": param.get("dst_url") + ":" + param.get("dst_port"));
1509 } else { 1502 } else {
1510 logger.error("RTP推流失败: {}, 参数:{}", jsonObject.getString("msg"), JSONObject.toJSONString(param)); 1503 logger.error("RTP推流失败: {}, 参数:{}", jsonObject.getString("msg"), JSONObject.toJSONString(param));
1511 if (sendRtpItem.isOnlyAudio()) { 1504 if (sendRtpItem.isOnlyAudio()) {