使用Slf4j注解打印日志
This commit is contained in:
@@ -4,8 +4,7 @@ import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerChangeEvent;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
@@ -17,12 +16,11 @@ import java.util.List;
|
||||
/**
|
||||
* 启动是从配置文件加载节点信息,以及发送个节点状态管理去控制节点状态
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Order(value=12)
|
||||
public class MediaServerConfig implements CommandLineRunner {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(MediaServerConfig.class);
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@@ -56,7 +54,7 @@ public class MediaServerConfig implements CommandLineRunner {
|
||||
mediaServerService.syncCatchFromDatabase();
|
||||
// 获取所有的zlm, 并开启主动连接
|
||||
List<MediaServer> all = mediaServerService.getAllFromDatabase();
|
||||
logger.info("[媒体节点] 加载节点列表, 共{}个节点", all.size());
|
||||
log.info("[媒体节点] 加载节点列表, 共{}个节点", all.size());
|
||||
MediaServerChangeEvent event = new MediaServerChangeEvent(this);
|
||||
event.setMediaServerItemList(all);
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.genersoft.iot.vmp.media.event.mediaServer;
|
||||
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -16,18 +15,17 @@ import org.springframework.stereotype.Component;
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月6日 下午1:51:23
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MediaServerStatusEventListener {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(MediaServerStatusEventListener.class);
|
||||
|
||||
@Autowired
|
||||
private IPlayService playService;
|
||||
|
||||
@Async("taskExecutor")
|
||||
@EventListener
|
||||
public void onApplicationEvent(MediaServerOnlineEvent event) {
|
||||
logger.info("[媒体节点] 上线 ID:" + event.getMediaServerId());
|
||||
log.info("[媒体节点] 上线 ID:" + event.getMediaServerId());
|
||||
playService.zlmServerOnline(event.getMediaServerId());
|
||||
}
|
||||
|
||||
@@ -35,7 +33,7 @@ public class MediaServerStatusEventListener {
|
||||
@EventListener
|
||||
public void onApplicationEvent(MediaServerOfflineEvent event) {
|
||||
|
||||
logger.info("[媒体节点] 离线,ID:" + event.getMediaServerId());
|
||||
log.info("[媒体节点] 离线,ID:" + event.getMediaServerId());
|
||||
// 处理ZLM离线
|
||||
playService.zlmServerOffline(event.getMediaServerId());
|
||||
}
|
||||
|
||||
@@ -31,11 +31,10 @@ import com.genersoft.iot.vmp.utils.JsonUtil;
|
||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -50,12 +49,11 @@ import java.util.*;
|
||||
/**
|
||||
* 媒体服务器节点管理
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@DS("master")
|
||||
public class MediaServerServiceImpl implements IMediaServerService {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(MediaServerServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private SSRCFactory ssrcFactory;
|
||||
|
||||
@@ -95,7 +93,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
@org.springframework.context.event.EventListener
|
||||
public void onApplicationEvent(MediaArrivalEvent event) {
|
||||
if ("rtsp".equals(event.getSchema())) {
|
||||
logger.info("流变化:注册 app->{}, stream->{}", event.getApp(), event.getStream());
|
||||
log.info("流变化:注册 app->{}, stream->{}", event.getApp(), event.getStream());
|
||||
addCount(event.getMediaServer().getId());
|
||||
String type = OriginType.values()[event.getMediaInfo().getOriginType()].getType();
|
||||
redisCatchStorage.addStream(event.getMediaServer(), type, event.getApp(), event.getStream(), event.getMediaInfo());
|
||||
@@ -109,7 +107,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
@EventListener
|
||||
public void onApplicationEvent(MediaDepartureEvent event) {
|
||||
if ("rtsp".equals(event.getSchema())) {
|
||||
logger.info("流变化:注销, app->{}, stream->{}", event.getApp(), event.getStream());
|
||||
log.info("流变化:注销, app->{}, stream->{}", event.getApp(), event.getStream());
|
||||
removeCount(event.getMediaServer().getId());
|
||||
MediaInfo mediaInfo = redisCatchStorage.getStreamInfo(
|
||||
event.getApp(), event.getStream(), event.getMediaServer().getId());
|
||||
@@ -128,7 +126,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
*/
|
||||
@Override
|
||||
public void updateVmServer(List<MediaServer> mediaServerList) {
|
||||
logger.info("[媒体服务节点] 缓存初始化 ");
|
||||
log.info("[媒体服务节点] 缓存初始化 ");
|
||||
for (MediaServer mediaServer : mediaServerList) {
|
||||
if (ObjectUtils.isEmpty(mediaServer.getId())) {
|
||||
continue;
|
||||
@@ -151,7 +149,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public SSRCInfo openRTPServer(MediaServer mediaServer, String streamId, String presetSsrc, boolean ssrcCheck,
|
||||
boolean isPlayback, Integer port, Boolean onlyAuto, Boolean disableAudio, Boolean reUsePort, Integer tcpMode) {
|
||||
if (mediaServer == null || mediaServer.getId() == null) {
|
||||
logger.info("[openRTPServer] 失败, mediaServer == null || mediaServer.getId() == null");
|
||||
log.info("[openRTPServer] 失败, mediaServer == null || mediaServer.getId() == null");
|
||||
return null;
|
||||
}
|
||||
// 获取mediaServer可用的ssrc
|
||||
@@ -171,13 +169,13 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
if (ssrcCheck && tcpMode > 0) {
|
||||
// 目前zlm不支持 tcp模式更新ssrc,暂时关闭ssrc校验
|
||||
logger.warn("[openRTPServer] 平台对接时下级可能自定义ssrc,但是tcp模式zlm收流目前无法更新ssrc,可能收流超时,此时请使用udp收流或者关闭ssrc校验");
|
||||
log.warn("[openRTPServer] 平台对接时下级可能自定义ssrc,但是tcp模式zlm收流目前无法更新ssrc,可能收流超时,此时请使用udp收流或者关闭ssrc校验");
|
||||
}
|
||||
int rtpServerPort;
|
||||
if (mediaServer.isRtpEnable()) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[openRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[openRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return null;
|
||||
}
|
||||
rtpServerPort = mediaNodeServerService.createRTPServer(mediaServer, streamId, ssrcCheck ? Long.parseLong(ssrc) : 0, port, onlyAuto, disableAudio, reUsePort, tcpMode);
|
||||
@@ -194,7 +192,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[closeRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[closeRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return;
|
||||
}
|
||||
mediaNodeServerService.closeRtpServer(mediaServer, streamId);
|
||||
@@ -208,7 +206,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[closeRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[closeRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return;
|
||||
}
|
||||
mediaNodeServerService.closeRtpServer(mediaServer, streamId, callback);
|
||||
@@ -225,7 +223,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[closeRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[closeRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return;
|
||||
}
|
||||
mediaNodeServerService.closeStreams(mediaServer, "rtp", streamId);
|
||||
@@ -238,7 +236,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[updateRtpServerSSRC] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[updateRtpServerSSRC] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.updateRtpServerSSRC(mediaServer, streamId, ssrc);
|
||||
@@ -388,16 +386,16 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
mediaServer.setHookAliveInterval(10F);
|
||||
}
|
||||
if (mediaServer.getType() == null) {
|
||||
logger.info("[添加媒体节点] 失败, mediaServer的类型:为空");
|
||||
log.info("[添加媒体节点] 失败, mediaServer的类型:为空");
|
||||
return;
|
||||
}
|
||||
if (mediaServerMapper.queryOne(mediaServer.getId()) != null) {
|
||||
logger.info("[添加媒体节点] 失败, 媒体服务ID已存在,请修改媒体服务器配置, {}", mediaServer.getId());
|
||||
log.info("[添加媒体节点] 失败, 媒体服务ID已存在,请修改媒体服务器配置, {}", mediaServer.getId());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"保存失败,媒体服务ID [ " + mediaServer.getId() + " ] 已存在,请修改媒体服务器配置");
|
||||
}
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[添加媒体节点] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[添加媒体节点] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -458,7 +456,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
String key = VideoManagerConstants.ONLINE_MEDIA_SERVERS_PREFIX + userSetting.getServerId();
|
||||
Long size = redisTemplate.opsForZSet().zCard(key);
|
||||
if (size == null || size == 0) {
|
||||
logger.info("获取负载最低的节点时无在线节点");
|
||||
log.info("获取负载最低的节点时无在线节点");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -500,7 +498,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(type);
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[closeRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", type);
|
||||
log.info("[closeRTPServer] 失败, mediaServer的类型: {},未找到对应的实现类", type);
|
||||
return null;
|
||||
}
|
||||
MediaServer mediaServer = mediaNodeServerService.checkMediaServer(ip, port, secret);
|
||||
@@ -587,7 +585,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public boolean stopSendRtp(MediaServer mediaInfo, String app, String stream, String ssrc) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaInfo.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[stopSendRtp] 失败, mediaServer的类型: {},未找到对应的实现类", mediaInfo.getType());
|
||||
log.info("[stopSendRtp] 失败, mediaServer的类型: {},未找到对应的实现类", mediaInfo.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.stopSendRtp(mediaInfo, app, stream, ssrc);
|
||||
@@ -597,7 +595,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public boolean initStopSendRtp(MediaServer mediaInfo, String app, String stream, String ssrc) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaInfo.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[stopSendRtp] 失败, mediaServer的类型: {},未找到对应的实现类", mediaInfo.getType());
|
||||
log.info("[stopSendRtp] 失败, mediaServer的类型: {},未找到对应的实现类", mediaInfo.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.initStopSendRtp(mediaInfo, app, stream, ssrc);
|
||||
@@ -607,7 +605,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public boolean deleteRecordDirectory(MediaServer mediaServer, String app, String stream, String date, String fileName) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[stopSendRtp] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[stopSendRtp] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.deleteRecordDirectory(mediaServer, app, stream, date, fileName);
|
||||
@@ -617,7 +615,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public List<StreamInfo> getMediaList(MediaServer mediaServer, String app, String stream, String callId) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[getMediaList] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[getMediaList] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return mediaNodeServerService.getMediaList(mediaServer, app, stream, callId);
|
||||
@@ -627,7 +625,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public Boolean connectRtpServer(MediaServer mediaServer, String address, int port, String stream) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[connectRtpServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[connectRtpServer] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.connectRtpServer(mediaServer, address, port, stream);
|
||||
@@ -637,7 +635,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public void getSnap(MediaServer mediaServer, String streamUrl, int timeoutSec, int expireSec, String path, String fileName) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[getSnap] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[getSnap] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return;
|
||||
}
|
||||
mediaNodeServerService.getSnap(mediaServer, streamUrl, timeoutSec, expireSec, path, fileName);
|
||||
@@ -647,7 +645,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public MediaInfo getMediaInfo(MediaServer mediaServer, String app, String stream) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[getMediaInfo] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[getMediaInfo] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return null;
|
||||
}
|
||||
return mediaNodeServerService.getMediaInfo(mediaServer, app, stream);
|
||||
@@ -657,7 +655,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public Boolean pauseRtpCheck(MediaServer mediaServer, String streamKey) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[pauseRtpCheck] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[pauseRtpCheck] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.pauseRtpCheck(mediaServer, streamKey);
|
||||
@@ -667,7 +665,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public boolean resumeRtpCheck(MediaServer mediaServer, String streamKey) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[pauseRtpCheck] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[pauseRtpCheck] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.resumeRtpCheck(mediaServer, streamKey);
|
||||
@@ -677,7 +675,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public String getFfmpegCmd(MediaServer mediaServer, String cmdKey) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[getFfmpegCmd] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[getFfmpegCmd] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return null;
|
||||
}
|
||||
return mediaNodeServerService.getFfmpegCmd(mediaServer, cmdKey);
|
||||
@@ -687,7 +685,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public void closeStreams(MediaServer mediaServer, String app, String stream) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[closeStreams] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[closeStreams] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return;
|
||||
}
|
||||
mediaNodeServerService.closeStreams(mediaServer, app, stream);
|
||||
@@ -697,7 +695,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public WVPResult<String> addFFmpegSource(MediaServer mediaServer, String srcUrl, String dstUrl, int timeoutMs, boolean enableAudio, boolean enableMp4, String ffmpegCmdKey) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[addFFmpegSource] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[addFFmpegSource] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return WVPResult.fail(ErrorCode.ERROR400);
|
||||
}
|
||||
return mediaNodeServerService.addFFmpegSource(mediaServer, srcUrl, dstUrl, timeoutMs, enableAudio, enableMp4, ffmpegCmdKey);
|
||||
@@ -708,7 +706,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
boolean enableAudio, boolean enableMp4, String rtpType, Integer timeout) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[addStreamProxy] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[addStreamProxy] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return WVPResult.fail(ErrorCode.ERROR400);
|
||||
}
|
||||
return mediaNodeServerService.addStreamProxy(mediaServer, app, stream, url, enableAudio, enableMp4, rtpType, timeout);
|
||||
@@ -718,7 +716,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public Boolean delFFmpegSource(MediaServer mediaServer, String streamKey) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[delFFmpegSource] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[delFFmpegSource] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.delFFmpegSource(mediaServer, streamKey);
|
||||
@@ -728,7 +726,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public Boolean delStreamProxy(MediaServer mediaServerItem, String streamKey) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServerItem.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[delStreamProxy] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServerItem.getType());
|
||||
log.info("[delStreamProxy] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServerItem.getType());
|
||||
return false;
|
||||
}
|
||||
return mediaNodeServerService.delStreamProxy(mediaServerItem, streamKey);
|
||||
@@ -738,7 +736,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public Map<String, String> getFFmpegCMDs(MediaServer mediaServer) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[getFFmpegCMDs] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[getFFmpegCMDs] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return new HashMap<>();
|
||||
}
|
||||
return mediaNodeServerService.getFFmpegCMDs(mediaServer);
|
||||
@@ -825,7 +823,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public Boolean isStreamReady(MediaServer mediaServer, String app, String streamId) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[isStreamReady] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[isStreamReady] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
return false;
|
||||
}
|
||||
MediaInfo mediaInfo = mediaNodeServerService.getMediaInfo(mediaServer, app, streamId);
|
||||
@@ -836,7 +834,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public void startSendRtpPassive(MediaServer mediaServer, SendRtpItem sendRtpItem, Integer timeout) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[startSendRtpPassive] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[startSendRtpPassive] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到mediaServer对应的实现类");
|
||||
}
|
||||
mediaNodeServerService.startSendRtpPassive(mediaServer, sendRtpItem, timeout);
|
||||
@@ -846,10 +844,10 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public void startSendRtp(MediaServer mediaServer, SendRtpItem sendRtpItem) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[startSendRtpStream] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[startSendRtpStream] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到mediaServer对应的实现类");
|
||||
}
|
||||
logger.info("[开始推流] rtp/{}, 目标={}:{},SSRC={}, RTCP={}", sendRtpItem.getStream(),
|
||||
log.info("[开始推流] rtp/{}, 目标={}:{},SSRC={}, RTCP={}", sendRtpItem.getStream(),
|
||||
sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc(), sendRtpItem.isRtcp());
|
||||
mediaNodeServerService.startSendRtpStream(mediaServer, sendRtpItem);
|
||||
}
|
||||
@@ -916,7 +914,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public Long updateDownloadProcess(MediaServer mediaServer, String app, String stream) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[updateDownloadProcess] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[updateDownloadProcess] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到mediaServer对应的实现类");
|
||||
}
|
||||
return mediaNodeServerService.updateDownloadProcess(mediaServer, app, stream);
|
||||
@@ -926,7 +924,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public StreamInfo startProxy(MediaServer mediaServer, StreamProxy streamProxy) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[startProxy] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[startProxy] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到mediaServer对应的实现类");
|
||||
}
|
||||
return mediaNodeServerService.startProxy(mediaServer, streamProxy);
|
||||
@@ -936,7 +934,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public void stopProxy(MediaServer mediaServer, String streamKey) {
|
||||
IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
|
||||
if (mediaNodeServerService == null) {
|
||||
logger.info("[stopProxy] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
log.info("[stopProxy] 失败, mediaServer的类型: {},未找到对应的实现类", mediaServer.getType());
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到mediaServer对应的实现类");
|
||||
}
|
||||
mediaNodeServerService.stopProxy(mediaServer, streamKey);
|
||||
|
||||
@@ -4,11 +4,10 @@ import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.utils.SSLSocketClientUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -22,12 +21,10 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AssistRESTfulUtils {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(AssistRESTfulUtils.class);
|
||||
|
||||
|
||||
private OkHttpClient client;
|
||||
|
||||
|
||||
@@ -51,9 +48,9 @@ public class AssistRESTfulUtils {
|
||||
httpClientBuilder.readTimeout(readTimeOut,TimeUnit.SECONDS);
|
||||
// 设置连接池
|
||||
httpClientBuilder.connectionPool(new ConnectionPool(16, 5, TimeUnit.MINUTES));
|
||||
if (logger.isDebugEnabled()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
|
||||
logger.debug("http请求参数:" + message);
|
||||
log.debug("http请求参数:" + message);
|
||||
});
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
||||
// OkHttp進行添加攔截器loggingInterceptor
|
||||
@@ -77,7 +74,7 @@ public class AssistRESTfulUtils {
|
||||
return null;
|
||||
}
|
||||
if (mediaServerItem.getRecordAssistPort() <= 0) {
|
||||
logger.warn("未启用Assist服务");
|
||||
log.warn("未启用Assist服务");
|
||||
return null;
|
||||
}
|
||||
StringBuilder stringBuffer = new StringBuilder();
|
||||
@@ -99,7 +96,7 @@ public class AssistRESTfulUtils {
|
||||
}
|
||||
|
||||
String url = stringBuffer.toString();
|
||||
logger.info("[访问assist]: {}", url);
|
||||
log.info("[访问assist]: {}", url);
|
||||
Request request = new Request.Builder()
|
||||
.get()
|
||||
.url(url)
|
||||
@@ -118,10 +115,10 @@ public class AssistRESTfulUtils {
|
||||
Objects.requireNonNull(response.body()).close();
|
||||
}
|
||||
} catch (ConnectException e) {
|
||||
logger.error(String.format("连接Assist失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
logger.info("请检查media配置并确认Assist已启动...");
|
||||
log.error(String.format("连接Assist失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
log.info("请检查media配置并确认Assist已启动...");
|
||||
}catch (IOException e) {
|
||||
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
}
|
||||
}else {
|
||||
client.newCall(request).enqueue(new Callback(){
|
||||
@@ -133,7 +130,7 @@ public class AssistRESTfulUtils {
|
||||
String responseStr = Objects.requireNonNull(response.body()).string();
|
||||
callback.run(JSON.parseObject(responseStr));
|
||||
} catch (IOException e) {
|
||||
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
}
|
||||
|
||||
}else {
|
||||
@@ -144,8 +141,8 @@ public class AssistRESTfulUtils {
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
logger.error(String.format("连接Assist失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
logger.info("请检查media配置并确认Assist已启动...");
|
||||
log.error(String.format("连接Assist失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
log.info("请检查media配置并确认Assist已启动...");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -163,7 +160,7 @@ public class AssistRESTfulUtils {
|
||||
if (mediaServerItem == null) {
|
||||
return null;
|
||||
}
|
||||
logger.info("[访问assist]: {}, 参数: {}", url, param);
|
||||
log.info("[访问assist]: {}, 参数: {}", url, param);
|
||||
JSONObject responseJSON = new JSONObject();
|
||||
//-2自定义流媒体 调用错误码
|
||||
responseJSON.put("code",-2);
|
||||
@@ -190,19 +187,19 @@ public class AssistRESTfulUtils {
|
||||
Objects.requireNonNull(response.body()).close();
|
||||
}
|
||||
}catch (IOException e) {
|
||||
logger.error(String.format("[ %s ]ASSIST请求失败: %s", url, e.getMessage()));
|
||||
log.error(String.format("[ %s ]ASSIST请求失败: %s", url, e.getMessage()));
|
||||
|
||||
if(e instanceof SocketTimeoutException){
|
||||
//读取超时超时异常
|
||||
logger.error(String.format("读取ASSIST数据失败: %s, %s", url, e.getMessage()));
|
||||
log.error(String.format("读取ASSIST数据失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
if(e instanceof ConnectException){
|
||||
//判断连接异常,我这里是报Failed to connect to 10.7.5.144
|
||||
logger.error(String.format("连接ASSIST失败: %s, %s", url, e.getMessage()));
|
||||
log.error(String.format("连接ASSIST失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
logger.error(String.format("访问ASSIST失败: %s, %s", url, e.getMessage()));
|
||||
log.error(String.format("访问ASSIST失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
}else {
|
||||
client.newCall(request).enqueue(new Callback(){
|
||||
@@ -214,7 +211,7 @@ public class AssistRESTfulUtils {
|
||||
String responseStr = Objects.requireNonNull(response.body()).string();
|
||||
callback.run(JSON.parseObject(responseStr));
|
||||
} catch (IOException e) {
|
||||
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
}
|
||||
|
||||
}else {
|
||||
@@ -225,15 +222,15 @@ public class AssistRESTfulUtils {
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
logger.error(String.format("连接ZLM失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
log.error(String.format("连接ZLM失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
|
||||
if(e instanceof SocketTimeoutException){
|
||||
//读取超时超时异常
|
||||
logger.error(String.format("读取ZLM数据失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
log.error(String.format("读取ZLM数据失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
}
|
||||
if(e instanceof ConnectException){
|
||||
//判断连接异常,我这里是报Failed to connect to 10.7.5.144
|
||||
logger.error(String.format("连接ZLM失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
log.error(String.format("连接ZLM失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,16 +3,8 @@ package com.genersoft.iot.vmp.media.zlm;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
|
||||
import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.bean.ResultForOnPublish;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.event.media.*;
|
||||
import com.genersoft.iot.vmp.media.event.mediaServer.MediaSendRtpStoppedEvent;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
@@ -20,20 +12,11 @@ import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.*;
|
||||
import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerKeepaliveEvent;
|
||||
import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerStartEvent;
|
||||
import com.genersoft.iot.vmp.service.*;
|
||||
import com.genersoft.iot.vmp.service.redisMsg.IRedisRpcService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.streamProxy.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.streamPush.service.IStreamPushService;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import com.genersoft.iot.vmp.utils.MediaServerUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -45,85 +28,23 @@ import java.util.Map;
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月8日 上午10:46:48
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/index/hook")
|
||||
public class ZLMHttpHookListener {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ZLMHttpHookListener.class);
|
||||
|
||||
@Autowired
|
||||
private SIPCommander cmder;
|
||||
|
||||
@Autowired
|
||||
private ISIPCommanderForPlatform commanderFroPlatform;
|
||||
|
||||
@Autowired
|
||||
private AudioBroadcastManager audioBroadcastManager;
|
||||
|
||||
@Autowired
|
||||
private IPlayService playService;
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorage storager;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
|
||||
@Autowired
|
||||
private IRedisRpcService redisRpcService;
|
||||
|
||||
@Autowired
|
||||
private IInviteStreamService inviteStreamService;
|
||||
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private IStreamProxyService streamProxyService;
|
||||
|
||||
@Autowired
|
||||
private DeferredResultHolder resultHolder;
|
||||
|
||||
@Autowired
|
||||
private IMediaService mediaService;
|
||||
|
||||
@Autowired
|
||||
private EventPublisher eventPublisher;
|
||||
|
||||
@Autowired
|
||||
private HookSubscribe subscribe;
|
||||
|
||||
@Autowired
|
||||
private UserSetting userSetting;
|
||||
|
||||
@Autowired
|
||||
private IUserService userService;
|
||||
|
||||
@Autowired
|
||||
private ICloudRecordService cloudRecordService;
|
||||
|
||||
@Autowired
|
||||
private VideoStreamSessionManager sessionManager;
|
||||
|
||||
@Autowired
|
||||
private SSRCFactory ssrcFactory;
|
||||
|
||||
@Qualifier("taskExecutor")
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor taskExecutor;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@Autowired
|
||||
private IStreamPushService streamPushService;
|
||||
|
||||
/**
|
||||
* 服务器定时上报时间,上报间隔可配置,默认10s上报一次
|
||||
@@ -139,7 +60,7 @@ public class ZLMHttpHookListener {
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.info("[ZLM-HOOK-心跳] 发送通知失败 ", e);
|
||||
log.info("[ZLM-HOOK-心跳] 发送通知失败 ", e);
|
||||
}
|
||||
return HookResult.SUCCESS();
|
||||
}
|
||||
@@ -155,10 +76,10 @@ public class ZLMHttpHookListener {
|
||||
// 对于播放流进行鉴权
|
||||
boolean authenticateResult = mediaService.authenticatePlay(param.getApp(), param.getStream(), paramMap.get("callId"));
|
||||
if (!authenticateResult) {
|
||||
logger.info("[ZLM HOOK] 播放鉴权 失败:{}->{}", param.getMediaServerId(), param);
|
||||
log.info("[ZLM HOOK] 播放鉴权 失败:{}->{}", param.getMediaServerId(), param);
|
||||
return new HookResult(401, "Unauthorized");
|
||||
}
|
||||
logger.info("[ZLM HOOK] 播放鉴权成功:{}->{}", param.getMediaServerId(), param);
|
||||
log.info("[ZLM HOOK] 播放鉴权成功:{}->{}", param.getMediaServerId(), param);
|
||||
return HookResult.SUCCESS();
|
||||
}
|
||||
|
||||
@@ -171,7 +92,7 @@ public class ZLMHttpHookListener {
|
||||
|
||||
JSONObject json = (JSONObject) JSON.toJSON(param);
|
||||
|
||||
logger.info("[ZLM HOOK]推流鉴权:{}->{}", param.getMediaServerId(), param);
|
||||
log.info("[ZLM HOOK]推流鉴权:{}->{}", param.getMediaServerId(), param);
|
||||
// TODO 加快处理速度
|
||||
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
@@ -183,11 +104,11 @@ public class ZLMHttpHookListener {
|
||||
ResultForOnPublish resultForOnPublish = mediaService.authenticatePublish(mediaServer, param.getApp(), param.getStream(), param.getParams());
|
||||
if (resultForOnPublish != null) {
|
||||
HookResultForOnPublish successResult = HookResultForOnPublish.getInstance(resultForOnPublish);
|
||||
logger.info("[ZLM HOOK]推流鉴权 响应:{}->{}->>>>{}", param.getMediaServerId(), param, successResult);
|
||||
log.info("[ZLM HOOK]推流鉴权 响应:{}->{}->>>>{}", param.getMediaServerId(), param, successResult);
|
||||
return successResult;
|
||||
}else {
|
||||
HookResultForOnPublish fail = HookResultForOnPublish.Fail();
|
||||
logger.info("[ZLM HOOK]推流鉴权 响应:{}->{}->>>>{}", param.getMediaServerId(), param, fail);
|
||||
log.info("[ZLM HOOK]推流鉴权 响应:{}->{}->>>>{}", param.getMediaServerId(), param, fail);
|
||||
return fail;
|
||||
}
|
||||
}
|
||||
@@ -219,11 +140,11 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
if (param.getSchema().equalsIgnoreCase("rtsp")) {
|
||||
if (param.isRegist()) {
|
||||
logger.info("[ZLM HOOK] 流注册, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
||||
log.info("[ZLM HOOK] 流注册, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
||||
MediaArrivalEvent mediaArrivalEvent = MediaArrivalEvent.getInstance(this, param, mediaServer);
|
||||
applicationEventPublisher.publishEvent(mediaArrivalEvent);
|
||||
} else {
|
||||
logger.info("[ZLM HOOK] 流注销, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
||||
log.info("[ZLM HOOK] 流注销, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
||||
MediaDepartureEvent mediaDepartureEvent = MediaDepartureEvent.getInstance(this, param, mediaServer);
|
||||
applicationEventPublisher.publishEvent(mediaDepartureEvent);
|
||||
}
|
||||
@@ -239,7 +160,7 @@ public class ZLMHttpHookListener {
|
||||
@PostMapping(value = "/on_stream_none_reader", produces = "application/json;charset=UTF-8")
|
||||
public JSONObject onStreamNoneReader(@RequestBody OnStreamNoneReaderHookParam param) {
|
||||
|
||||
logger.info("[ZLM HOOK]流无人观看:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(),
|
||||
log.info("[ZLM HOOK]流无人观看:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(),
|
||||
param.getApp(), param.getStream());
|
||||
|
||||
MediaServer mediaInfo = mediaServerService.getOne(param.getMediaServerId());
|
||||
@@ -267,7 +188,7 @@ public class ZLMHttpHookListener {
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8")
|
||||
public HookResult onStreamNotFound(@RequestBody OnStreamNotFoundHookParam param) {
|
||||
logger.info("[ZLM HOOK] 流未找到:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
||||
log.info("[ZLM HOOK] 流未找到:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
||||
|
||||
|
||||
MediaServer mediaServer = mediaServerService.getOne(param.getMediaServerId());
|
||||
@@ -289,7 +210,7 @@ public class ZLMHttpHookListener {
|
||||
jsonObject.put("ip", request.getRemoteAddr());
|
||||
ZLMServerConfig zlmServerConfig = JSON.to(ZLMServerConfig.class, jsonObject);
|
||||
zlmServerConfig.setIp(request.getRemoteAddr());
|
||||
logger.info("[ZLM HOOK] zlm 启动 " + zlmServerConfig.getGeneralMediaServerId());
|
||||
log.info("[ZLM HOOK] zlm 启动 " + zlmServerConfig.getGeneralMediaServerId());
|
||||
try {
|
||||
HookZlmServerStartEvent event = new HookZlmServerStartEvent(this);
|
||||
MediaServer mediaServerItem = mediaServerService.getOne(zlmServerConfig.getMediaServerId());
|
||||
@@ -298,7 +219,7 @@ public class ZLMHttpHookListener {
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.info("[ZLM-HOOK-ZLM启动] 发送通知失败 ", e);
|
||||
log.info("[ZLM-HOOK-ZLM启动] 发送通知失败 ", e);
|
||||
}
|
||||
|
||||
return HookResult.SUCCESS();
|
||||
@@ -311,7 +232,7 @@ public class ZLMHttpHookListener {
|
||||
@PostMapping(value = "/on_send_rtp_stopped", produces = "application/json;charset=UTF-8")
|
||||
public HookResult onSendRtpStopped(HttpServletRequest request, @RequestBody OnSendRtpStoppedHookParam param) {
|
||||
|
||||
logger.info("[ZLM HOOK] rtp发送关闭:{}->{}/{}", param.getMediaServerId(), param.getApp(), param.getStream());
|
||||
log.info("[ZLM HOOK] rtp发送关闭:{}->{}/{}", param.getMediaServerId(), param.getApp(), param.getStream());
|
||||
|
||||
// 查找对应的上级推流,发送停止
|
||||
if (!"rtp".equals(param.getApp())) {
|
||||
@@ -325,7 +246,7 @@ public class ZLMHttpHookListener {
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.info("[ZLM-HOOK-rtp发送关闭] 发送通知失败 ", e);
|
||||
log.info("[ZLM-HOOK-rtp发送关闭] 发送通知失败 ", e);
|
||||
}
|
||||
|
||||
return HookResult.SUCCESS();
|
||||
@@ -338,7 +259,7 @@ public class ZLMHttpHookListener {
|
||||
@PostMapping(value = "/on_rtp_server_timeout", produces = "application/json;charset=UTF-8")
|
||||
public HookResult onRtpServerTimeout(@RequestBody OnRtpServerTimeoutHookParam
|
||||
param) {
|
||||
logger.info("[ZLM HOOK] rtpServer收流超时:{}->{}({})", param.getMediaServerId(), param.getStream_id(), param.getSsrc());
|
||||
log.info("[ZLM HOOK] rtpServer收流超时:{}->{}({})", param.getMediaServerId(), param.getStream_id(), param.getSsrc());
|
||||
|
||||
try {
|
||||
MediaRtpServerTimeoutEvent event = new MediaRtpServerTimeoutEvent(this);
|
||||
@@ -349,7 +270,7 @@ public class ZLMHttpHookListener {
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.info("[ZLM-HOOK-rtpServer收流超时] 发送通知失败 ", e);
|
||||
log.info("[ZLM-HOOK-rtpServer收流超时] 发送通知失败 ", e);
|
||||
}
|
||||
|
||||
return HookResult.SUCCESS();
|
||||
@@ -361,7 +282,7 @@ public class ZLMHttpHookListener {
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_record_mp4", produces = "application/json;charset=UTF-8")
|
||||
public HookResult onRecordMp4(HttpServletRequest request, @RequestBody OnRecordMp4HookParam param) {
|
||||
logger.info("[ZLM HOOK] 录像完成事件:{}->{}", param.getMediaServerId(), param.getFile_path());
|
||||
log.info("[ZLM HOOK] 录像完成事件:{}->{}", param.getMediaServerId(), param.getFile_path());
|
||||
|
||||
try {
|
||||
MediaServer mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
|
||||
@@ -371,7 +292,7 @@ public class ZLMHttpHookListener {
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.info("[ZLM-HOOK-rtpServer收流超时] 发送通知失败 ", e);
|
||||
log.info("[ZLM-HOOK-rtpServer收流超时] 发送通知失败 ", e);
|
||||
}
|
||||
|
||||
return HookResult.SUCCESS();
|
||||
|
||||
@@ -5,15 +5,14 @@ import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerChangeEvent;
|
||||
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerDeleteEvent;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerKeepaliveEvent;
|
||||
import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerStartEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -31,11 +30,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
/**
|
||||
* 管理zlm流媒体节点的状态
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ZLMMediaServerStatusManger {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ZLMMediaServerStatusManger.class);
|
||||
|
||||
private final Map<Object, MediaServer> offlineZlmPrimaryMap = new ConcurrentHashMap<>();
|
||||
private final Map<Object, MediaServer> offlineZlmsecondaryMap = new ConcurrentHashMap<>();
|
||||
private final Map<Object, Long> offlineZlmTimeMap = new ConcurrentHashMap<>();
|
||||
@@ -74,7 +72,7 @@ public class ZLMMediaServerStatusManger {
|
||||
if (!type.equals(mediaServerItem.getType())) {
|
||||
continue;
|
||||
}
|
||||
logger.info("[ZLM-添加待上线节点] ID:" + mediaServerItem.getId());
|
||||
log.info("[ZLM-添加待上线节点] ID:" + mediaServerItem.getId());
|
||||
offlineZlmPrimaryMap.put(mediaServerItem.getId(), mediaServerItem);
|
||||
offlineZlmTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis());
|
||||
execute();
|
||||
@@ -93,7 +91,7 @@ public class ZLMMediaServerStatusManger {
|
||||
if (serverItem == null) {
|
||||
return;
|
||||
}
|
||||
logger.info("[ZLM-HOOK事件-服务启动] ID:" + event.getMediaServerItem().getId());
|
||||
log.info("[ZLM-HOOK事件-服务启动] ID:" + event.getMediaServerItem().getId());
|
||||
online(serverItem, null);
|
||||
}
|
||||
|
||||
@@ -107,7 +105,7 @@ public class ZLMMediaServerStatusManger {
|
||||
if (serverItem == null) {
|
||||
return;
|
||||
}
|
||||
logger.info("[ZLM-HOOK事件-心跳] ID:" + event.getMediaServerItem().getId());
|
||||
log.info("[ZLM-HOOK事件-心跳] ID:" + event.getMediaServerItem().getId());
|
||||
online(serverItem, null);
|
||||
}
|
||||
|
||||
@@ -117,7 +115,7 @@ public class ZLMMediaServerStatusManger {
|
||||
if (event.getMediaServerId() == null) {
|
||||
return;
|
||||
}
|
||||
logger.info("[ZLM-节点被移除] ID:" + event.getMediaServerId());
|
||||
log.info("[ZLM-节点被移除] ID:" + event.getMediaServerId());
|
||||
offlineZlmPrimaryMap.remove(event.getMediaServerId());
|
||||
offlineZlmsecondaryMap.remove(event.getMediaServerId());
|
||||
offlineZlmTimeMap.remove(event.getMediaServerId());
|
||||
@@ -136,16 +134,16 @@ public class ZLMMediaServerStatusManger {
|
||||
offlineZlmPrimaryMap.remove(mediaServerItem.getId());
|
||||
continue;
|
||||
}
|
||||
logger.info("[ZLM-尝试连接] ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
log.info("[ZLM-尝试连接] ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
JSONObject responseJson = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMServerConfig zlmServerConfig = null;
|
||||
if (responseJson == null) {
|
||||
logger.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
log.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
continue;
|
||||
}
|
||||
JSONArray data = responseJson.getJSONArray("data");
|
||||
if (data == null || data.isEmpty()) {
|
||||
logger.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
log.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
}else {
|
||||
zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
initPort(mediaServerItem, zlmServerConfig);
|
||||
@@ -158,17 +156,17 @@ public class ZLMMediaServerStatusManger {
|
||||
if (offlineZlmTimeMap.get(mediaServerItem.getId()) < System.currentTimeMillis() - 30*60*1000) {
|
||||
continue;
|
||||
}
|
||||
logger.info("[ZLM-尝试连接] ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
log.info("[ZLM-尝试连接] ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
JSONObject responseJson = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMServerConfig zlmServerConfig = null;
|
||||
if (responseJson == null) {
|
||||
logger.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
log.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
offlineZlmTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis());
|
||||
continue;
|
||||
}
|
||||
JSONArray data = responseJson.getJSONArray("data");
|
||||
if (data == null || data.isEmpty()) {
|
||||
logger.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
log.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
offlineZlmTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis());
|
||||
}else {
|
||||
zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
@@ -184,7 +182,7 @@ public class ZLMMediaServerStatusManger {
|
||||
offlineZlmsecondaryMap.remove(mediaServerItem.getId());
|
||||
offlineZlmTimeMap.remove(mediaServerItem.getId());
|
||||
if (!mediaServerItem.isStatus()) {
|
||||
logger.info("[ZLM-连接成功] ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
log.info("[ZLM-连接成功] ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
mediaServerItem.setStatus(true);
|
||||
mediaServerItem.setHookAliveInterval(10F);
|
||||
mediaServerService.update(mediaServerItem);
|
||||
@@ -207,7 +205,7 @@ public class ZLMMediaServerStatusManger {
|
||||
// 设置两次心跳未收到则认为zlm离线
|
||||
String key = "zlm-keepalive-" + mediaServerItem.getId();
|
||||
dynamicTask.startDelay(key, ()->{
|
||||
logger.warn("[ZLM-心跳超时] ID:{}", mediaServerItem.getId());
|
||||
log.warn("[ZLM-心跳超时] ID:{}", mediaServerItem.getId());
|
||||
mediaServerItem.setStatus(false);
|
||||
offlineZlmPrimaryMap.put(mediaServerItem.getId(), mediaServerItem);
|
||||
offlineZlmTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis());
|
||||
@@ -239,7 +237,7 @@ public class ZLMMediaServerStatusManger {
|
||||
}
|
||||
|
||||
public void setZLMConfig(MediaServer mediaServerItem, boolean restart) {
|
||||
logger.info("[媒体服务节点] 正在设置 :{} -> {}:{}",
|
||||
log.info("[媒体服务节点] 正在设置 :{} -> {}:{}",
|
||||
mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
String protocol = sslEnabled ? "https" : "http";
|
||||
String hookPrefix = String.format("%s://%s:%s%s/index/hook", protocol, mediaServerItem.getHookIp(), serverPort, (serverServletContextPath == null || "/".equals(serverServletContextPath)) ? "" : serverServletContextPath);
|
||||
@@ -290,15 +288,15 @@ public class ZLMMediaServerStatusManger {
|
||||
|
||||
if (responseJSON != null && responseJSON.getInteger("code") == 0) {
|
||||
if (restart) {
|
||||
logger.info("[媒体服务节点] 设置成功,开始重启以保证配置生效 {} -> {}:{}",
|
||||
log.info("[媒体服务节点] 设置成功,开始重启以保证配置生效 {} -> {}:{}",
|
||||
mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
zlmresTfulUtils.restartServer(mediaServerItem);
|
||||
}else {
|
||||
logger.info("[媒体服务节点] 设置成功 {} -> {}:{}",
|
||||
log.info("[媒体服务节点] 设置成功 {} -> {}:{}",
|
||||
mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
}
|
||||
}else {
|
||||
logger.info("[媒体服务节点] 设置媒体服务节点失败 {} -> {}:{}",
|
||||
log.info("[媒体服务节点] 设置媒体服务节点失败 {} -> {}:{}",
|
||||
mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@ package com.genersoft.iot.vmp.media.zlm;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.HashMap;
|
||||
@@ -18,11 +19,10 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ZLMRESTfulUtils {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ZLMRESTfulUtils.class);
|
||||
|
||||
private OkHttpClient client;
|
||||
|
||||
public interface RequestCallback{
|
||||
@@ -46,9 +46,9 @@ public class ZLMRESTfulUtils {
|
||||
httpClientBuilder.readTimeout(readTimeOut,TimeUnit.SECONDS);
|
||||
// 设置连接池
|
||||
httpClientBuilder.connectionPool(new ConnectionPool(16, 5, TimeUnit.MINUTES));
|
||||
if (logger.isDebugEnabled()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
|
||||
logger.debug("http请求参数:" + message);
|
||||
log.debug("http请求参数:" + message);
|
||||
});
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
|
||||
// OkHttp進行添加攔截器loggingInterceptor
|
||||
@@ -107,19 +107,19 @@ public class ZLMRESTfulUtils {
|
||||
Objects.requireNonNull(response.body()).close();
|
||||
}
|
||||
}catch (IOException e) {
|
||||
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
|
||||
if(e instanceof SocketTimeoutException){
|
||||
//读取超时超时异常
|
||||
logger.error(String.format("读取ZLM数据超时失败: %s, %s", url, e.getMessage()));
|
||||
log.error(String.format("读取ZLM数据超时失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
if(e instanceof ConnectException){
|
||||
//判断连接异常,我这里是报Failed to connect to 10.7.5.144
|
||||
logger.error(String.format("连接ZLM连接失败: %s, %s", url, e.getMessage()));
|
||||
log.error(String.format("连接ZLM连接失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
logger.error(String.format("访问ZLM失败: %s, %s", url, e.getMessage()));
|
||||
log.error(String.format("访问ZLM失败: %s, %s", url, e.getMessage()));
|
||||
}
|
||||
}else {
|
||||
client.newCall(request).enqueue(new Callback(){
|
||||
@@ -131,7 +131,7 @@ public class ZLMRESTfulUtils {
|
||||
String responseStr = Objects.requireNonNull(response.body()).string();
|
||||
callback.run(JSON.parseObject(responseStr));
|
||||
} catch (IOException e) {
|
||||
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
}
|
||||
|
||||
}else {
|
||||
@@ -142,15 +142,15 @@ public class ZLMRESTfulUtils {
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
logger.error(String.format("连接ZLM失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
log.error(String.format("连接ZLM失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
|
||||
if(e instanceof SocketTimeoutException){
|
||||
//读取超时超时异常
|
||||
logger.error(String.format("读取ZLM数据失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
log.error(String.format("读取ZLM数据失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
}
|
||||
if(e instanceof ConnectException){
|
||||
//判断连接异常,我这里是报Failed to connect to 10.7.5.144
|
||||
logger.error(String.format("连接ZLM失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
log.error(String.format("连接ZLM失败: %s, %s", call.request().toString(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -179,7 +179,7 @@ public class ZLMRESTfulUtils {
|
||||
Request request = new Request.Builder()
|
||||
.url(httpBuilder.build())
|
||||
.build();
|
||||
logger.info(request.toString());
|
||||
log.info(request.toString());
|
||||
try {
|
||||
OkHttpClient client = getClient();
|
||||
Response response = client.newCall(request).execute();
|
||||
@@ -188,7 +188,7 @@ public class ZLMRESTfulUtils {
|
||||
File snapFolder = new File(targetPath);
|
||||
if (!snapFolder.exists()) {
|
||||
if (!snapFolder.mkdirs()) {
|
||||
logger.warn("{}路径创建失败", snapFolder.getAbsolutePath());
|
||||
log.warn("{}路径创建失败", snapFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -199,17 +199,17 @@ public class ZLMRESTfulUtils {
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
} else {
|
||||
logger.error(String.format("[ %s ]请求失败: %s %s", url, response.code(), response.message()));
|
||||
log.error(String.format("[ %s ]请求失败: %s %s", url, response.code(), response.message()));
|
||||
}
|
||||
} else {
|
||||
logger.error(String.format("[ %s ]请求失败: %s %s", url, response.code(), response.message()));
|
||||
log.error(String.format("[ %s ]请求失败: %s %s", url, response.code(), response.message()));
|
||||
}
|
||||
Objects.requireNonNull(response.body()).close();
|
||||
} catch (ConnectException e) {
|
||||
logger.error(String.format("连接ZLM失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
logger.info("请检查media配置并确认ZLM已启动...");
|
||||
log.error(String.format("连接ZLM失败: %s, %s", e.getCause().getMessage(), e.getMessage()));
|
||||
log.info("请检查media配置并确认ZLM已启动...");
|
||||
} catch (IOException e) {
|
||||
logger.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,8 +268,8 @@ public class ZLMRESTfulUtils {
|
||||
|
||||
public JSONObject addFFmpegSource(MediaServer mediaServerItem, String src_url, String dst_url, Integer timeout_ms,
|
||||
boolean enable_audio, boolean enable_mp4, String ffmpeg_cmd_key){
|
||||
logger.info(src_url);
|
||||
logger.info(dst_url);
|
||||
log.info(src_url);
|
||||
log.info(dst_url);
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("src_url", src_url);
|
||||
param.put("dst_url", dst_url);
|
||||
|
||||
@@ -6,19 +6,16 @@ import com.genersoft.iot.vmp.common.CommonCallback;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ZLMServerFactory {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger("ZLMServerFactory");
|
||||
|
||||
@Autowired
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
|
||||
@@ -43,7 +40,7 @@ public class ZLMServerFactory {
|
||||
int result = -1;
|
||||
// 查询此rtp server 是否已经存在
|
||||
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, streamId);
|
||||
logger.info(JSONObject.toJSONString(rtpInfo));
|
||||
log.info(JSONObject.toJSONString(rtpInfo));
|
||||
if(rtpInfo.getInteger("code") == 0){
|
||||
if (rtpInfo.getBoolean("exist")) {
|
||||
result = rtpInfo.getInteger("local_port");
|
||||
@@ -57,7 +54,7 @@ public class ZLMServerFactory {
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
return createRTPServer(mediaServerItem, streamId, ssrc, port,onlyAuto, reUsePort, tcpMode);
|
||||
}else {
|
||||
logger.warn("[开启rtpServer], 重启RtpServer错误");
|
||||
log.warn("[开启rtpServer], 重启RtpServer错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,16 +88,16 @@ public class ZLMServerFactory {
|
||||
}
|
||||
|
||||
JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
|
||||
logger.info(JSONObject.toJSONString(openRtpServerResultJson));
|
||||
log.info(JSONObject.toJSONString(openRtpServerResultJson));
|
||||
if (openRtpServerResultJson != null) {
|
||||
if (openRtpServerResultJson.getInteger("code") == 0) {
|
||||
result= openRtpServerResultJson.getInteger("port");
|
||||
}else {
|
||||
logger.error("创建RTP Server 失败 {}: ", openRtpServerResultJson.getString("msg"));
|
||||
log.error("创建RTP Server 失败 {}: ", openRtpServerResultJson.getString("msg"));
|
||||
}
|
||||
}else {
|
||||
// 检查ZLM状态
|
||||
logger.error("创建RTP Server 失败 {}: 请检查ZLM服务", param.get("port"));
|
||||
log.error("创建RTP Server 失败 {}: 请检查ZLM服务", param.get("port"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -111,16 +108,16 @@ public class ZLMServerFactory {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("stream_id", streamId);
|
||||
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(serverItem, param);
|
||||
logger.info("关闭RTP Server " + jsonObject);
|
||||
log.info("关闭RTP Server " + jsonObject);
|
||||
if (jsonObject != null ) {
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
result = jsonObject.getInteger("hit") >= 1;
|
||||
}else {
|
||||
logger.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
|
||||
log.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
|
||||
}
|
||||
}else {
|
||||
// 检查ZLM状态
|
||||
logger.error("关闭RTP Server 失败: 请检查ZLM服务");
|
||||
log.error("关闭RTP Server 失败: 请检查ZLM服务");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -139,11 +136,11 @@ public class ZLMServerFactory {
|
||||
callback.run(jsonObject.getInteger("hit") == 1);
|
||||
return;
|
||||
}else {
|
||||
logger.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
|
||||
log.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
|
||||
}
|
||||
}else {
|
||||
// 检查ZLM状态
|
||||
logger.error("关闭RTP Server 失败: 请检查ZLM服务");
|
||||
log.error("关闭RTP Server 失败: 请检查ZLM服务");
|
||||
}
|
||||
callback.run(false);
|
||||
});
|
||||
@@ -195,11 +192,11 @@ public class ZLMServerFactory {
|
||||
}
|
||||
Integer code = mediaInfo.getInteger("code");
|
||||
if (code < 0) {
|
||||
logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
|
||||
log.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
|
||||
return -1;
|
||||
}
|
||||
if ( code == 0 && mediaInfo.getBoolean("online") != null && ! mediaInfo.getBoolean("online")) {
|
||||
logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
|
||||
log.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
|
||||
return -1;
|
||||
}
|
||||
return mediaInfo.getInteger("totalReaderCount");
|
||||
@@ -207,7 +204,7 @@ public class ZLMServerFactory {
|
||||
|
||||
public JSONObject startSendRtp(MediaServer mediaInfo, SendRtpItem sendRtpItem) {
|
||||
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
|
||||
logger.info("rtp/{}开始推流, 目标={}:{},SSRC={}", sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
|
||||
log.info("rtp/{}开始推流, 目标={}:{},SSRC={}", sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
|
||||
Map<String, Object> param = new HashMap<>(12);
|
||||
param.put("vhost","__defaultVhost__");
|
||||
param.put("app",sendRtpItem.getApp());
|
||||
@@ -254,12 +251,12 @@ public class ZLMServerFactory {
|
||||
boolean result = false;
|
||||
JSONObject jsonObject = zlmresTfulUtils.updateRtpServerSSRC(mediaServerItem, streamId, ssrc);
|
||||
if (jsonObject == null) {
|
||||
logger.error("[更新RTPServer] 失败: 请检查ZLM服务");
|
||||
log.error("[更新RTPServer] 失败: 请检查ZLM服务");
|
||||
} else if (jsonObject.getInteger("code") == 0) {
|
||||
result= true;
|
||||
logger.info("[更新RTPServer] 成功");
|
||||
log.info("[更新RTPServer] 成功");
|
||||
} else {
|
||||
logger.error("[更新RTPServer] 失败: {}, streamId:{},ssrc:{}->\r\n{}",jsonObject.getString("msg"),
|
||||
log.error("[更新RTPServer] 失败: {}, streamId:{},ssrc:{}->\r\n{}",jsonObject.getString("msg"),
|
||||
streamId, ssrc, jsonObject);
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user