修复单端口点播

This commit is contained in:
648540858 2023-07-03 17:55:34 +08:00
parent 43ef195543
commit 733a11f265
2 changed files with 18 additions and 23 deletions

View File

@ -158,8 +158,10 @@ public class PlayServiceImpl implements IPlayService {
} }
} }
} }
String streamId = null;
String streamId = String.format("%s_%s", device.getDeviceId(), channelId); if (mediaServerItem.isRtpEnable()) {
streamId = String.format("%s_%s", device.getDeviceId(), channelId);
}
SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam()); SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam());
if (ssrcInfo == null) { if (ssrcInfo == null) {
callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null); callback.run(InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getCode(), InviteErrorCode.ERROR_FOR_RESOURCE_EXHAUSTION.getMsg(), null);

View File

@ -7,13 +7,13 @@ import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.VersionInfo; import com.genersoft.iot.vmp.conf.VersionInfo;
import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout; import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRtpServerTimeoutHookParam;
import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.service.IDeviceChannelService;
import com.genersoft.iot.vmp.service.IDeviceService; import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IMediaServerService;
@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Tag(name = "第三方服务对接") @Tag(name = "第三方服务对接")
@ -49,6 +50,9 @@ public class RtpController {
@Autowired @Autowired
private ZLMServerFactory zlmServerFactory; private ZLMServerFactory zlmServerFactory;
@Autowired
private SendRtpPortManager sendRtpPortManager;
private final static Logger logger = LoggerFactory.getLogger(RtpController.class); private final static Logger logger = LoggerFactory.getLogger(RtpController.class);
@Autowired @Autowired
@ -127,8 +131,9 @@ public class RtpController {
HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, mediaServerItem.getId()); HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, mediaServerItem.getId());
// 订阅 zlm启动事件, 新的zlm也会从这里进入系统 // 订阅 zlm启动事件, 新的zlm也会从这里进入系统
hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout, hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
(mediaServerItemInUse, response)->{ (mediaServerItemInUse, hookParam)->{
if (stream.equals(response.getString("stream_id"))) { OnRtpServerTimeoutHookParam serverTimeoutHookParam = (OnRtpServerTimeoutHookParam) hookParam;
if (stream.equals(serverTimeoutHookParam.getStream_id())) {
logger.info("[开启收流和获取发流信息] 等待收流超时 callId->{}, 发送回调", callId); logger.info("[开启收流和获取发流信息] 等待收流超时 callId->{}, 发送回调", callId);
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
OkHttpClient client = httpClientBuilder.build(); OkHttpClient client = httpClientBuilder.build();
@ -142,30 +147,20 @@ public class RtpController {
} }
}); });
} }
String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
OtherRtpSendInfo otherRtpSendInfo = new OtherRtpSendInfo(); OtherRtpSendInfo otherRtpSendInfo = new OtherRtpSendInfo();
otherRtpSendInfo.setReceiveIp(mediaServerItem.getSdpIp()); otherRtpSendInfo.setReceiveIp(mediaServerItem.getSdpIp());
otherRtpSendInfo.setReceivePort(localPort); otherRtpSendInfo.setReceivePort(localPort);
otherRtpSendInfo.setCallId(callId); otherRtpSendInfo.setCallId(callId);
otherRtpSendInfo.setStream(stream); otherRtpSendInfo.setStream(stream);
if (isSend != null && isSend) { if (isSend != null && isSend) {
String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId; int port = sendRtpPortManager.getNextPort(mediaServerItem.getId());
// 预创建发流信息
int port = zlmServerFactory.keepPort(mediaServerItem, callId, 0, ssrc1 -> {
return redisTemplate.opsForValue().get(key) != null;
});
// 将信息写入redis中以备后用
redisTemplate.opsForValue().set(key, otherRtpSendInfo);
// 设置超时任务超时未使用则自动移除并关闭端口保持, 默认五分钟
dynamicTask.startDelay(key, ()->{
logger.info("[第三方服务对接->开启收流和获取发流信息] 端口保持超时 callId->{}", callId);
redisTemplate.delete(key);
zlmServerFactory.releasePort(mediaServerItem, callId);
}, 300000);
otherRtpSendInfo.setIp(mediaServerItem.getSdpIp()); otherRtpSendInfo.setIp(mediaServerItem.getSdpIp());
otherRtpSendInfo.setPort(port); otherRtpSendInfo.setPort(port);
logger.info("[开启收流和获取发流信息] 结果callId->{} {}", callId, otherRtpSendInfo); logger.info("[开启收流和获取发流信息] 结果callId->{} {}", callId, otherRtpSendInfo);
} }
// 将信息写入redis中以备后用
redisTemplate.opsForValue().set(key, otherRtpSendInfo, 300, TimeUnit.SECONDS);
return otherRtpSendInfo; return otherRtpSendInfo;
} }
@ -197,9 +192,7 @@ public class RtpController {
MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer(); MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer();
String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId; String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId;
OtherRtpSendInfo sendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key); OtherRtpSendInfo sendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key);
if (sendInfo != null) { if (sendInfo == null) {
zlmServerFactory.releasePort(mediaServerItem, sendInfo.getCallId());
}else {
sendInfo = new OtherRtpSendInfo(); sendInfo = new OtherRtpSendInfo();
} }
sendInfo.setPushApp(app); sendInfo.setPushApp(app);