Commit 32c73ff595c9939b342017ffbd8c86bc16877ba6
Merge branch '2.6.8' into wvp-28181-2.0
# Conflicts: # src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
Showing
3 changed files
with
58 additions
and
18 deletions
src/main/java/com/genersoft/iot/vmp/media/zlm/SendRtpPortManager.java
| 1 | 1 | package com.genersoft.iot.vmp.media.zlm; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | |
| 3 | 4 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; | |
| 4 | 6 | import com.genersoft.iot.vmp.media.zlm.dto.MediaSendRtpPortInfo; |
| 7 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | |
| 5 | 8 | import org.slf4j.Logger; |
| 6 | 9 | import org.slf4j.LoggerFactory; |
| 7 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | 11 | import org.springframework.data.redis.core.RedisTemplate; |
| 9 | 12 | import org.springframework.stereotype.Component; |
| 10 | 13 | |
| 14 | +import java.util.HashMap; | |
| 15 | +import java.util.List; | |
| 16 | +import java.util.Map; | |
| 17 | + | |
| 11 | 18 | @Component |
| 12 | 19 | public class SendRtpPortManager { |
| 13 | 20 | |
| ... | ... | @@ -29,27 +36,55 @@ public class SendRtpPortManager { |
| 29 | 36 | } |
| 30 | 37 | |
| 31 | 38 | public int getNextPort(String mediaServerId) { |
| 32 | - String key = KEY + userSetting.getServerId() + "_" + mediaServerId; | |
| 33 | - MediaSendRtpPortInfo mediaSendRtpPortInfo = (MediaSendRtpPortInfo)redisTemplate.opsForValue().get(key); | |
| 39 | + String sendIndexKey = KEY + userSetting.getServerId() + "_" + mediaServerId; | |
| 40 | + MediaSendRtpPortInfo mediaSendRtpPortInfo = (MediaSendRtpPortInfo)redisTemplate.opsForValue().get(sendIndexKey); | |
| 34 | 41 | if (mediaSendRtpPortInfo == null) { |
| 35 | 42 | logger.warn("[发送端口管理] 获取{}的发送端口时未找到端口信息", mediaServerId); |
| 36 | 43 | return 0; |
| 37 | 44 | } |
| 45 | + | |
| 46 | + String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX | |
| 47 | + + userSetting.getServerId() + "_*"; | |
| 48 | + List<Object> queryResult = RedisUtil.scan(redisTemplate, key); | |
| 49 | + Map<Integer, SendRtpItem> sendRtpItemMap = new HashMap<>(); | |
| 50 | + | |
| 51 | + for (Object o : queryResult) { | |
| 52 | + SendRtpItem sendRtpItem = (SendRtpItem) redisTemplate.opsForValue().get(o); | |
| 53 | + if (sendRtpItem != null) { | |
| 54 | + sendRtpItemMap.put(sendRtpItem.getLocalPort(), sendRtpItem); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + | |
| 58 | + int port = getPort(mediaSendRtpPortInfo.getCurrent(), | |
| 59 | + mediaSendRtpPortInfo.getStart(), | |
| 60 | + mediaSendRtpPortInfo.getEnd(), checkPort -> sendRtpItemMap.get(checkPort) == null); | |
| 61 | + | |
| 62 | + mediaSendRtpPortInfo.setCurrent(port); | |
| 63 | + redisTemplate.opsForValue().set(sendIndexKey, mediaSendRtpPortInfo); | |
| 64 | + return port; | |
| 65 | + } | |
| 66 | + | |
| 67 | + interface CheckPortCallback{ | |
| 68 | + boolean check(int port); | |
| 69 | + } | |
| 70 | + | |
| 71 | + private int getPort(int current, int start, int end, CheckPortCallback checkPortCallback) { | |
| 38 | 72 | int port; |
| 39 | - if (mediaSendRtpPortInfo.getCurrent() %2 != 0) { | |
| 40 | - port = mediaSendRtpPortInfo.getCurrent() + 1; | |
| 73 | + if (current %2 != 0) { | |
| 74 | + port = current + 1; | |
| 41 | 75 | }else { |
| 42 | - port = mediaSendRtpPortInfo.getCurrent() + 2; | |
| 76 | + port = current + 2; | |
| 43 | 77 | } |
| 44 | - if (port > mediaSendRtpPortInfo.getEnd()) { | |
| 45 | - if (mediaSendRtpPortInfo.getStart() %2 != 0) { | |
| 46 | - port = mediaSendRtpPortInfo.getStart() + 1; | |
| 78 | + if (port > end) { | |
| 79 | + if (start %2 != 0) { | |
| 80 | + port = start + 1; | |
| 47 | 81 | }else { |
| 48 | - port = mediaSendRtpPortInfo.getStart(); | |
| 82 | + port = start; | |
| 49 | 83 | } |
| 50 | 84 | } |
| 51 | - mediaSendRtpPortInfo.setCurrent(port); | |
| 52 | - redisTemplate.opsForValue().set(key, mediaSendRtpPortInfo); | |
| 85 | + if (!checkPortCallback.check(port)) { | |
| 86 | + return getPort(port, start, end, checkPortCallback); | |
| 87 | + } | |
| 53 | 88 | return port; |
| 54 | 89 | } |
| 55 | 90 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| ... | ... | @@ -225,10 +225,7 @@ public class ZLMHttpHookListener { |
| 225 | 225 | |
| 226 | 226 | |
| 227 | 227 | HookResultForOnPublish result = HookResultForOnPublish.SUCCESS(); |
| 228 | - if (!"rtp".equals(param.getApp())) { | |
| 229 | - result.setEnable_audio(true); | |
| 230 | - } | |
| 231 | - | |
| 228 | + result.setEnable_audio(true); | |
| 232 | 229 | taskExecutor.execute(() -> { |
| 233 | 230 | ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json); |
| 234 | 231 | if (subscribe != null) { |
| ... | ... | @@ -256,7 +253,6 @@ public class ZLMHttpHookListener { |
| 256 | 253 | // 如果是录像下载就设置视频间隔十秒 |
| 257 | 254 | if (ssrcTransactionForAll.get(0).getType() == InviteSessionType.DOWNLOAD) { |
| 258 | 255 | result.setMp4_max_second(10); |
| 259 | - result.setEnable_audio(true); | |
| 260 | 256 | result.setEnable_mp4(true); |
| 261 | 257 | } |
| 262 | 258 | } |
| ... | ... | @@ -278,6 +274,14 @@ public class ZLMHttpHookListener { |
| 278 | 274 | } |
| 279 | 275 | } |
| 280 | 276 | } |
| 277 | + if (param.getApp().equalsIgnoreCase("rtp")) { | |
| 278 | + String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + param.getStream(); | |
| 279 | + OtherRtpSendInfo otherRtpSendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(receiveKey); | |
| 280 | + if (otherRtpSendInfo != null) { | |
| 281 | + result.setEnable_mp4(true); | |
| 282 | + } | |
| 283 | + } | |
| 284 | + logger.info("[ZLM HOOK]推流鉴权 响应:{}->{}->>>>{}", param.getMediaServerId(), param, result); | |
| 281 | 285 | return result; |
| 282 | 286 | } |
| 283 | 287 | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/rtp/RtpController.java
| ... | ... | @@ -141,11 +141,12 @@ public class RtpController { |
| 141 | 141 | // 预创建发流信息 |
| 142 | 142 | int portForVideo = sendRtpPortManager.getNextPort(mediaServerItem.getId()); |
| 143 | 143 | int portForAudio = sendRtpPortManager.getNextPort(mediaServerItem.getId()); |
| 144 | - // 将信息写入redis中,以备后用 | |
| 145 | - redisTemplate.opsForValue().set(key, otherRtpSendInfo, 300, TimeUnit.SECONDS); | |
| 144 | + | |
| 146 | 145 | otherRtpSendInfo.setSendLocalIp(mediaServerItem.getSdpIp()); |
| 147 | 146 | otherRtpSendInfo.setSendLocalPortForVideo(portForVideo); |
| 148 | 147 | otherRtpSendInfo.setSendLocalPortForAudio(portForAudio); |
| 148 | + // 将信息写入redis中,以备后用 | |
| 149 | + redisTemplate.opsForValue().set(key, otherRtpSendInfo, 300, TimeUnit.SECONDS); | |
| 149 | 150 | logger.info("[第三方服务对接->开启收流和获取发流信息] 结果,callId->{}, {}", callId, otherRtpSendInfo); |
| 150 | 151 | } |
| 151 | 152 | // 将信息写入redis中,以备后用 | ... | ... |