Commit 733a11f265778f9f9fa64210cceae7ae8e6fdfd4

Authored by 648540858
1 parent 43ef1955

修复单端口点播

src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -158,8 +158,10 @@ public class PlayServiceImpl implements IPlayService { @@ -158,8 +158,10 @@ public class PlayServiceImpl implements IPlayService {
158 } 158 }
159 } 159 }
160 } 160 }
161 -  
162 - String streamId = String.format("%s_%s", device.getDeviceId(), channelId); 161 + String streamId = null;
  162 + if (mediaServerItem.isRtpEnable()) {
  163 + streamId = String.format("%s_%s", device.getDeviceId(), channelId);
  164 + }
163 SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam()); 165 SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam());
164 if (ssrcInfo == null) { 166 if (ssrcInfo == null) {
165 callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null); 167 callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null);
src/main/java/com/genersoft/iot/vmp/vmanager/rtp/RtpController.java
@@ -7,13 +7,13 @@ import com.genersoft.iot.vmp.conf.SipConfig; @@ -7,13 +7,13 @@ import com.genersoft.iot.vmp.conf.SipConfig;
7 import com.genersoft.iot.vmp.conf.UserSetting; 7 import com.genersoft.iot.vmp.conf.UserSetting;
8 import com.genersoft.iot.vmp.conf.VersionInfo; 8 import com.genersoft.iot.vmp.conf.VersionInfo;
9 import com.genersoft.iot.vmp.conf.exception.ControllerException; 9 import com.genersoft.iot.vmp.conf.exception.ControllerException;
10 -import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; 10 +import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
11 import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; 11 import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
12 -import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;  
13 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; 12 import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
14 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; 13 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
15 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout; 14 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout;
16 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; 15 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
  16 +import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRtpServerTimeoutHookParam;
17 import com.genersoft.iot.vmp.service.IDeviceChannelService; 17 import com.genersoft.iot.vmp.service.IDeviceChannelService;
18 import com.genersoft.iot.vmp.service.IDeviceService; 18 import com.genersoft.iot.vmp.service.IDeviceService;
19 import com.genersoft.iot.vmp.service.IMediaServerService; 19 import com.genersoft.iot.vmp.service.IMediaServerService;
@@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RestController; @@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RestController;
38 import java.io.IOException; 38 import java.io.IOException;
39 import java.util.HashMap; 39 import java.util.HashMap;
40 import java.util.Map; 40 import java.util.Map;
  41 +import java.util.concurrent.TimeUnit;
41 42
42 @SuppressWarnings("rawtypes") 43 @SuppressWarnings("rawtypes")
43 @Tag(name = "第三方服务对接") 44 @Tag(name = "第三方服务对接")
@@ -49,6 +50,9 @@ public class RtpController { @@ -49,6 +50,9 @@ public class RtpController {
49 @Autowired 50 @Autowired
50 private ZLMServerFactory zlmServerFactory; 51 private ZLMServerFactory zlmServerFactory;
51 52
  53 + @Autowired
  54 + private SendRtpPortManager sendRtpPortManager;
  55 +
52 private final static Logger logger = LoggerFactory.getLogger(RtpController.class); 56 private final static Logger logger = LoggerFactory.getLogger(RtpController.class);
53 57
54 @Autowired 58 @Autowired
@@ -127,8 +131,9 @@ public class RtpController { @@ -127,8 +131,9 @@ public class RtpController {
127 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, mediaServerItem.getId()); 131 HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, mediaServerItem.getId());
128 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 132 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统
129 hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout, 133 hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
130 - (mediaServerItemInUse, response)->{  
131 - if (stream.equals(response.getString("stream_id"))) { 134 + (mediaServerItemInUse, hookParam)->{
  135 + OnRtpServerTimeoutHookParam serverTimeoutHookParam = (OnRtpServerTimeoutHookParam) hookParam;
  136 + if (stream.equals(serverTimeoutHookParam.getStream_id())) {
132 logger.info("[开启收流和获取发流信息] 等待收流超时 callId->{}, 发送回调", callId); 137 logger.info("[开启收流和获取发流信息] 等待收流超时 callId->{}, 发送回调", callId);
133 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); 138 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
134 OkHttpClient client = httpClientBuilder.build(); 139 OkHttpClient client = httpClientBuilder.build();
@@ -142,30 +147,20 @@ public class RtpController { @@ -142,30 +147,20 @@ public class RtpController {
142 } 147 }
143 }); 148 });
144 } 149 }
  150 + String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
145 OtherRtpSendInfo otherRtpSendInfo = new OtherRtpSendInfo(); 151 OtherRtpSendInfo otherRtpSendInfo = new OtherRtpSendInfo();
146 otherRtpSendInfo.setReceiveIp(mediaServerItem.getSdpIp()); 152 otherRtpSendInfo.setReceiveIp(mediaServerItem.getSdpIp());
147 otherRtpSendInfo.setReceivePort(localPort); 153 otherRtpSendInfo.setReceivePort(localPort);
148 otherRtpSendInfo.setCallId(callId); 154 otherRtpSendInfo.setCallId(callId);
149 otherRtpSendInfo.setStream(stream); 155 otherRtpSendInfo.setStream(stream);
150 if (isSend != null && isSend) { 156 if (isSend != null && isSend) {
151 - String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;  
152 - // 预创建发流信息  
153 - int port = zlmServerFactory.keepPort(mediaServerItem, callId, 0, ssrc1 -> {  
154 - return redisTemplate.opsForValue().get(key) != null;  
155 - });  
156 -  
157 - // 将信息写入redis中,以备后用  
158 - redisTemplate.opsForValue().set(key, otherRtpSendInfo);  
159 - // 设置超时任务,超时未使用,则自动移除,并关闭端口保持, 默认五分钟  
160 - dynamicTask.startDelay(key, ()->{  
161 - logger.info("[第三方服务对接->开启收流和获取发流信息] 端口保持超时 callId->{}", callId);  
162 - redisTemplate.delete(key);  
163 - zlmServerFactory.releasePort(mediaServerItem, callId);  
164 - }, 300000); 157 + int port = sendRtpPortManager.getNextPort(mediaServerItem.getId());
165 otherRtpSendInfo.setIp(mediaServerItem.getSdpIp()); 158 otherRtpSendInfo.setIp(mediaServerItem.getSdpIp());
166 otherRtpSendInfo.setPort(port); 159 otherRtpSendInfo.setPort(port);
167 logger.info("[开启收流和获取发流信息] 结果,callId->{}, {}", callId, otherRtpSendInfo); 160 logger.info("[开启收流和获取发流信息] 结果,callId->{}, {}", callId, otherRtpSendInfo);
168 } 161 }
  162 + // 将信息写入redis中,以备后用
  163 + redisTemplate.opsForValue().set(key, otherRtpSendInfo, 300, TimeUnit.SECONDS);
169 return otherRtpSendInfo; 164 return otherRtpSendInfo;
170 } 165 }
171 166
@@ -197,9 +192,7 @@ public class RtpController { @@ -197,9 +192,7 @@ public class RtpController {
197 MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer(); 192 MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer();
198 String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId; 193 String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
199 OtherRtpSendInfo sendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key); 194 OtherRtpSendInfo sendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key);
200 - if (sendInfo != null) {  
201 - zlmServerFactory.releasePort(mediaServerItem, sendInfo.getCallId());  
202 - }else { 195 + if (sendInfo == null) {
203 sendInfo = new OtherRtpSendInfo(); 196 sendInfo = new OtherRtpSendInfo();
204 } 197 }
205 sendInfo.setPushApp(app); 198 sendInfo.setPushApp(app);