Commit a01086fe1c0accccf8ee5f98e601a6b14f0cf152

Authored by 648540858
1 parent 6797f772

修复tcp主动录像回放时ssrc不一致时点播失败的问题

src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
1 package com.genersoft.iot.vmp.conf; 1 package com.genersoft.iot.vmp.conf;
2 2
  3 +import org.apache.commons.lang3.ObjectUtils;
3 import org.slf4j.Logger; 4 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
5 import org.springframework.scheduling.annotation.Scheduled; 6 import org.springframework.scheduling.annotation.Scheduled;
@@ -100,7 +101,7 @@ public class DynamicTask { @@ -100,7 +101,7 @@ public class DynamicTask {
100 101
101 public boolean stop(String key) { 102 public boolean stop(String key) {
102 boolean result = false; 103 boolean result = false;
103 - if (futureMap.get(key) != null && !futureMap.get(key).isCancelled() && !futureMap.get(key).isDone()) { 104 + if (!ObjectUtils.isEmpty(futureMap.get(key)) && !futureMap.get(key).isCancelled() && !futureMap.get(key).isDone()) {
104 result = futureMap.get(key).cancel(false); 105 result = futureMap.get(key).cancel(false);
105 futureMap.remove(key); 106 futureMap.remove(key);
106 runnableMap.remove(key); 107 runnableMap.remove(key);
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -422,11 +422,11 @@ public class PlayServiceImpl implements IPlayService { @@ -422,11 +422,11 @@ public class PlayServiceImpl implements IPlayService {
422 break; 422 break;
423 } 423 }
424 } 424 }
425 - logger.info("[点播-TCP主动连接对方] deviceId: {}, channelId: {}, 连接对方的地址:{}:{}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, sdp.getConnection().getAddress(), port, device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck()); 425 + logger.info("[TCP主动连接对方] deviceId: {}, channelId: {}, 连接对方的地址:{}:{}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, sdp.getConnection().getAddress(), port, device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
426 JSONObject jsonObject = zlmresTfulUtils.connectRtpServer(mediaServerItem, sdp.getConnection().getAddress(), port, ssrcInfo.getStream()); 426 JSONObject jsonObject = zlmresTfulUtils.connectRtpServer(mediaServerItem, sdp.getConnection().getAddress(), port, ssrcInfo.getStream());
427 - logger.info("[点播-TCP主动连接对方] 结果: {}", jsonObject); 427 + logger.info("[TCP主动连接对方] 结果: {}", jsonObject);
428 } catch (SdpException e) { 428 } catch (SdpException e) {
429 - logger.error("[点播-TCP主动连接对方] deviceId: {}, channelId: {}, 解析200OK的SDP信息失败", device.getDeviceId(), channelId, e); 429 + logger.error("[TCP主动连接对方] deviceId: {}, channelId: {}, 解析200OK的SDP信息失败", device.getDeviceId(), channelId, e);
430 dynamicTask.stop(timeOutTaskKey); 430 dynamicTask.stop(timeOutTaskKey);
431 mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream()); 431 mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
432 // 释放ssrc 432 // 释放ssrc
@@ -648,39 +648,7 @@ public class PlayServiceImpl implements IPlayService { @@ -648,39 +648,7 @@ public class PlayServiceImpl implements IPlayService {
648 // 查询到ssrc不一致且开启了ssrc校验则需要针对处理 648 // 查询到ssrc不一致且开启了ssrc校验则需要针对处理
649 if (ssrcInfo.getSsrc().equals(ssrcInResponse)) { 649 if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
650 if (device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) { 650 if (device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) {
651 - String substring = contentString.substring(0, contentString.indexOf("y="));  
652 - try {  
653 - SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);  
654 - int port = -1;  
655 - Vector mediaDescriptions = sdp.getMediaDescriptions(true);  
656 - for (Object description : mediaDescriptions) {  
657 - MediaDescription mediaDescription = (MediaDescription) description;  
658 - Media media = mediaDescription.getMedia();  
659 -  
660 - Vector mediaFormats = media.getMediaFormats(false);  
661 - if (mediaFormats.contains("96")) {  
662 - port = media.getMediaPort();  
663 - break;  
664 - }  
665 - }  
666 - logger.info("[录像回放-TCP主动连接对方] deviceId: {}, channelId: {}, 连接对方的地址:{}:{}, 收流模式:{}, SSRC: {}, SSRC校验:{}", device.getDeviceId(), channelId, sdp.getConnection().getAddress(), port, device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());  
667 - JSONObject jsonObject = zlmresTfulUtils.connectRtpServer(mediaServerItem, sdp.getConnection().getAddress(), port, ssrcInfo.getStream());  
668 - logger.info("[录像回放-TCP主动连接对方] 结果: {}", jsonObject);  
669 - } catch (SdpException e) {  
670 - logger.error("[录像回放-TCP主动连接对方] deviceId: {}, channelId: {}, 解析200OK的SDP信息失败", device.getDeviceId(), channelId, e);  
671 - dynamicTask.stop(playBackTimeOutTaskKey);  
672 - mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());  
673 - // 释放ssrc  
674 - mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());  
675 -  
676 - streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());  
677 -  
678 - callback.run(InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),  
679 - InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);  
680 - inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,  
681 - InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getCode(),  
682 - InviteErrorCode.ERROR_FOR_SDP_PARSING_EXCEPTIONS.getMsg(), null);  
683 - } 651 + tcpActiveHandler(device, channelId, contentString, mediaServerItem, playBackTimeOutTaskKey, ssrcInfo, callback);
684 } 652 }
685 return; 653 return;
686 } 654 }
@@ -734,6 +702,9 @@ public class PlayServiceImpl implements IPlayService { @@ -734,6 +702,9 @@ public class PlayServiceImpl implements IPlayService {
734 ssrcInfo.setSsrc(ssrcInResponse); 702 ssrcInfo.setSsrc(ssrcInResponse);
735 inviteInfo.setSsrcInfo(ssrcInfo); 703 inviteInfo.setSsrcInfo(ssrcInfo);
736 inviteInfo.setStream(ssrcInfo.getStream()); 704 inviteInfo.setStream(ssrcInfo.getStream());
  705 + if (device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) {
  706 + tcpActiveHandler(device, channelId, contentString, mediaServerItem, playBackTimeOutTaskKey, ssrcInfo, callback);
  707 + }
737 } 708 }
738 }else { 709 }else {
739 logger.info("[点播消息] 收到invite 200, 下级自定义了ssrc, 但是当前模式无需修正"); 710 logger.info("[点播消息] 收到invite 200, 下级自定义了ssrc, 但是当前模式无需修正");