Commit 733a11f265778f9f9fa64210cceae7ae8e6fdfd4
1 parent
43ef1955
修复单端口点播
Showing
2 changed files
with
18 additions
and
23 deletions
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -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 | 165 | SSRCInfo ssrcInfo = mediaServerService.openRTPServer(mediaServerItem, streamId, null, device.isSsrcCheck(), false, 0, false, device.getStreamModeForParam()); |
| 164 | 166 | if (ssrcInfo == null) { |
| 165 | 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 | 7 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 8 | 8 | import com.genersoft.iot.vmp.conf.VersionInfo; |
| 9 | 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 | 11 | import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; |
| 12 | -import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; | |
| 13 | 12 | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; |
| 14 | 13 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 15 | 14 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForRtpServerTimeout; |
| 16 | 15 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 16 | +import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRtpServerTimeoutHookParam; | |
| 17 | 17 | import com.genersoft.iot.vmp.service.IDeviceChannelService; |
| 18 | 18 | import com.genersoft.iot.vmp.service.IDeviceService; |
| 19 | 19 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| ... | ... | @@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RestController; |
| 38 | 38 | import java.io.IOException; |
| 39 | 39 | import java.util.HashMap; |
| 40 | 40 | import java.util.Map; |
| 41 | +import java.util.concurrent.TimeUnit; | |
| 41 | 42 | |
| 42 | 43 | @SuppressWarnings("rawtypes") |
| 43 | 44 | @Tag(name = "第三方服务对接") |
| ... | ... | @@ -49,6 +50,9 @@ public class RtpController { |
| 49 | 50 | @Autowired |
| 50 | 51 | private ZLMServerFactory zlmServerFactory; |
| 51 | 52 | |
| 53 | + @Autowired | |
| 54 | + private SendRtpPortManager sendRtpPortManager; | |
| 55 | + | |
| 52 | 56 | private final static Logger logger = LoggerFactory.getLogger(RtpController.class); |
| 53 | 57 | |
| 54 | 58 | @Autowired |
| ... | ... | @@ -127,8 +131,9 @@ public class RtpController { |
| 127 | 131 | HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(ssrc, null, mediaServerItem.getId()); |
| 128 | 132 | // 订阅 zlm启动事件, 新的zlm也会从这里进入系统 |
| 129 | 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 | 137 | logger.info("[开启收流和获取发流信息] 等待收流超时 callId->{}, 发送回调", callId); |
| 133 | 138 | OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); |
| 134 | 139 | OkHttpClient client = httpClientBuilder.build(); |
| ... | ... | @@ -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 | 151 | OtherRtpSendInfo otherRtpSendInfo = new OtherRtpSendInfo(); |
| 146 | 152 | otherRtpSendInfo.setReceiveIp(mediaServerItem.getSdpIp()); |
| 147 | 153 | otherRtpSendInfo.setReceivePort(localPort); |
| 148 | 154 | otherRtpSendInfo.setCallId(callId); |
| 149 | 155 | otherRtpSendInfo.setStream(stream); |
| 150 | 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 | 158 | otherRtpSendInfo.setIp(mediaServerItem.getSdpIp()); |
| 166 | 159 | otherRtpSendInfo.setPort(port); |
| 167 | 160 | logger.info("[开启收流和获取发流信息] 结果,callId->{}, {}", callId, otherRtpSendInfo); |
| 168 | 161 | } |
| 162 | + // 将信息写入redis中,以备后用 | |
| 163 | + redisTemplate.opsForValue().set(key, otherRtpSendInfo, 300, TimeUnit.SECONDS); | |
| 169 | 164 | return otherRtpSendInfo; |
| 170 | 165 | } |
| 171 | 166 | |
| ... | ... | @@ -197,9 +192,7 @@ public class RtpController { |
| 197 | 192 | MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer(); |
| 198 | 193 | String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + callId; |
| 199 | 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 | 196 | sendInfo = new OtherRtpSendInfo(); |
| 204 | 197 | } |
| 205 | 198 | sendInfo.setPushApp(app); | ... | ... |