From b4048fbe80dba8e7756ae557a15ab60b4f80a44b Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期二, 04 四月 2023 09:09:07 +0800 Subject: [PATCH] 合并开源主线 --- src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java | 63 +++++++++++++++++++++---------- 1 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index 28b5405..dc495f9 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -1,16 +1,5 @@ package com.genersoft.iot.vmp.service.impl; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.genersoft.iot.vmp.media.zlm.ZLMRunner; -import com.genersoft.iot.vmp.service.IStreamProxyService; -import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; @@ -22,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; +import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; @@ -33,13 +23,12 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.MediaServerMapper; import com.genersoft.iot.vmp.utils.DateUtil; +import com.genersoft.iot.vmp.utils.JsonUtil; import com.genersoft.iot.vmp.utils.redis.RedisUtil; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -import java.time.LocalDateTime; -import java.util.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -50,6 +39,7 @@ import org.springframework.transaction.TransactionStatus; import org.springframework.util.ObjectUtils; +import java.io.File; import java.time.LocalDateTime; import java.util.*; @@ -74,6 +64,9 @@ @Autowired private UserSetting userSetting; + + @Autowired + private AssistRESTfulUtils assistRESTfulUtils; @Autowired private ZLMRESTfulUtils zlmresTfulUtils; @@ -133,7 +126,8 @@ } @Override - public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, String presetSsrc, boolean ssrcCheck, boolean isPlayback, Integer port) { + public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, String presetSsrc, boolean ssrcCheck, + boolean isPlayback, Integer port, Boolean onlyAuto) { if (mediaServerItem == null || mediaServerItem.getId() == null) { logger.info("[openRTPServer] 澶辫触, mediaServerItem == null || mediaServerItem.getId() == null"); return null; @@ -162,7 +156,7 @@ } int rtpServerPort; if (mediaServerItem.isRtpEnable()) { - rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0, port); + rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0, port, onlyAuto); } else { rtpServerPort = mediaServerItem.getRtpProxyPort(); } @@ -173,7 +167,7 @@ @Override public SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, String ssrc, boolean ssrcCheck, boolean isPlayback) { - return openRTPServer(mediaServerItem, streamId, ssrc, ssrcCheck, isPlayback, null); + return openRTPServer(mediaServerItem, streamId, ssrc, ssrcCheck, isPlayback, null, null); } @Override @@ -241,7 +235,10 @@ String onlineKey = VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId(); for (Object mediaServerKey : mediaServerKeys) { String key = (String) mediaServerKey; - MediaServerItem mediaServerItem = (MediaServerItem) RedisUtil.get(key); + MediaServerItem mediaServerItem = JsonUtil.redisJsonToObject(key, MediaServerItem.class); + if (Objects.isNull(mediaServerItem)) { + continue; + } // 妫�鏌ョ姸鎬� Double aDouble = RedisUtil.zScore(onlineKey, mediaServerItem.getId()); if (aDouble != null) { @@ -293,7 +290,7 @@ return null; } String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerId; - return (MediaServerItem)RedisUtil.get(key); + return JsonUtil.redisJsonToObject(key, MediaServerItem.class); } @@ -410,18 +407,34 @@ SsrcConfig ssrcConfig = new SsrcConfig(zlmServerConfig.getGeneralMediaServerId(), null, sipConfig.getDomain()); serverItem.setSsrcConfig(ssrcConfig); }else { - MediaServerItem mediaServerItemInRedis = (MediaServerItem)RedisUtil.get(key); - serverItem.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig()); + MediaServerItem mediaServerItemInRedis = JsonUtil.redisJsonToObject(key, MediaServerItem.class); + if (Objects.nonNull(mediaServerItemInRedis)) { + serverItem.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig()); + } } RedisUtil.set(key, serverItem); resetOnlineServerItem(serverItem); + + if (serverItem.isAutoConfig()) { + // 鏌ョ湅assist鏈嶅姟鐨勫綍鍍忚矾寰勯厤缃� + if (serverItem.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) { + JSONObject info = assistRESTfulUtils.getInfo(serverItem, null); + if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) { + JSONObject dataJson = info.getJSONObject("data"); + if (dataJson != null) { + String recordPath = dataJson.getString("record"); + userSetting.setRecordPath(recordPath); + } + } + } setZLMConfig(serverItem, "0".equals(zlmServerConfig.getHookEnable())); } final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + serverItem.getId(); dynamicTask.stop(zlmKeepaliveKey); dynamicTask.startDelay(zlmKeepaliveKey, new KeepAliveTimeoutRunnable(serverItem), (Math.getExponent(serverItem.getHookAliveInterval()) + 5) * 1000); publisher.zlmOnlineEventPublish(serverItem.getId()); + logger.info("[ZLM] 杩炴帴鎴愬姛 {} - {}:{} ", zlmServerConfig.getGeneralMediaServerId(), zlmServerConfig.getIp(), zlmServerConfig.getHttpPort()); } @@ -555,6 +568,9 @@ Map<String, Object> param = new HashMap<>(); param.put("api.secret",mediaServerItem.getSecret()); // -profile:v Baseline + if (mediaServerItem.getRtspPort() != 0) { + param.put("ffmpeg.snap", "%s -rtsp_transport tcp -i %s -y -f mjpeg -t 0.001 %s"); + } param.put("hook.enable","1"); param.put("hook.on_flow_report",""); param.put("hook.on_play",String.format("%s/on_play", hookPrex)); @@ -589,6 +605,13 @@ param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-")); } + if (userSetting.getRecordPath() != null) { + File recordPathFile = new File(userSetting.getRecordPath()); + File mp4SavePathFile = recordPathFile.getParentFile().getAbsoluteFile(); + param.put("protocol.mp4_save_path", mp4SavePathFile.getAbsoluteFile()); + param.put("record.appName", recordPathFile.getName()); + } + JSONObject responseJSON = zlmresTfulUtils.setServerConfig(mediaServerItem, param); if (responseJSON != null && responseJSON.getInteger("code") == 0) { -- Gitblit v1.8.0