支持全局异常和统一返回结果,未完待续
This commit is contained in:
@@ -64,7 +64,7 @@ public interface IMediaServerService {
|
||||
|
||||
void clearMediaServerForOnline();
|
||||
|
||||
WVPResult<String> add(MediaServerItem mediaSerItem);
|
||||
void add(MediaServerItem mediaSerItem);
|
||||
|
||||
int addToDatabase(MediaServerItem mediaSerItem);
|
||||
|
||||
@@ -72,7 +72,7 @@ public interface IMediaServerService {
|
||||
|
||||
void resetOnlineServerItem(MediaServerItem serverItem);
|
||||
|
||||
WVPResult<MediaServerItem> checkMediaServer(String ip, int port, String secret);
|
||||
MediaServerItem checkMediaServer(String ip, int port, String secret);
|
||||
|
||||
boolean checkMediaRecordServer(String ip, int port);
|
||||
|
||||
|
||||
@@ -31,13 +31,13 @@ public interface IPlayService {
|
||||
|
||||
void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String toString);
|
||||
|
||||
DeferredResult<ResponseEntity<String>> playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
DeferredResult<ResponseEntity<String>> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
DeferredResult<String> playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
DeferredResult<String> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
|
||||
void zlmServerOffline(String mediaServerId);
|
||||
|
||||
DeferredResult<ResponseEntity<String>> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
DeferredResult<ResponseEntity<String>> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
DeferredResult<String> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
DeferredResult<String> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
|
||||
|
||||
StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream);
|
||||
|
||||
|
||||
@@ -2,12 +2,8 @@ package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
public interface IStreamProxyService {
|
||||
@@ -16,7 +12,7 @@ public interface IStreamProxyService {
|
||||
* 保存视频代理
|
||||
* @param param
|
||||
*/
|
||||
WVPResult<StreamInfo> save(StreamProxyItem param);
|
||||
StreamInfo save(StreamProxyItem param);
|
||||
|
||||
/**
|
||||
* 添加视频代理到zlm
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.support.incrementer.AbstractIdentityColumnMaxValueIncrementer;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.Instant;
|
||||
@@ -282,13 +283,13 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
logger.warn("更新设备时未找到设备信息");
|
||||
return;
|
||||
}
|
||||
if (!StringUtils.isEmpty(device.getName())) {
|
||||
if (!ObjectUtils.isEmpty(device.getName())) {
|
||||
deviceInStore.setName(device.getName());
|
||||
}
|
||||
if (!StringUtils.isEmpty(device.getCharset())) {
|
||||
if (!ObjectUtils.isEmpty(device.getCharset())) {
|
||||
deviceInStore.setCharset(device.getCharset());
|
||||
}
|
||||
if (!StringUtils.isEmpty(device.getMediaServerId())) {
|
||||
if (!ObjectUtils.isEmpty(device.getMediaServerId())) {
|
||||
deviceInStore.setMediaServerId(device.getMediaServerId());
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -168,7 +169,7 @@ public class GbStreamServiceImpl implements IGbStreamService {
|
||||
public void sendCatalogMsgs(List<GbStream> gbStreams, String type) {
|
||||
if (gbStreams.size() > 0) {
|
||||
for (GbStream gs : gbStreams) {
|
||||
if (StringUtils.isEmpty(gs.getGbId())){
|
||||
if (ObjectUtils.isEmpty(gs.getGbId())){
|
||||
continue;
|
||||
}
|
||||
List<ParentPlatform> parentPlatforms = platformGbStreamMapper.selectByAppAndStream(gs.getApp(), gs.getStream());
|
||||
|
||||
@@ -8,6 +8,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -16,6 +18,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -91,7 +94,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
public void updateVmServer(List<MediaServerItem> mediaServerItemList) {
|
||||
logger.info("[zlm] 缓存初始化 ");
|
||||
for (MediaServerItem mediaServerItem : mediaServerItemList) {
|
||||
if (StringUtils.isEmpty(mediaServerItem.getId())) {
|
||||
if (ObjectUtils.isEmpty(mediaServerItem.getId())) {
|
||||
continue;
|
||||
}
|
||||
// 更新
|
||||
@@ -287,8 +290,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public WVPResult<String> add(MediaServerItem mediaServerItem) {
|
||||
WVPResult<String> result = new WVPResult<>();
|
||||
public void add(MediaServerItem mediaServerItem) {
|
||||
mediaServerItem.setCreateTime(DateUtil.getNow());
|
||||
mediaServerItem.setUpdateTime(DateUtil.getNow());
|
||||
mediaServerItem.setHookAliveInterval(120);
|
||||
@@ -298,26 +300,19 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
if (data != null && data.size() > 0) {
|
||||
ZLMServerConfig zlmServerConfig= JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
if (mediaServerMapper.queryOne(zlmServerConfig.getGeneralMediaServerId()) != null) {
|
||||
result.setCode(-1);
|
||||
result.setMsg("保存失败,媒体服务ID [ " + zlmServerConfig.getGeneralMediaServerId() + " ] 已存在,请修改媒体服务器配置");
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"保存失败,媒体服务ID [ " + zlmServerConfig.getGeneralMediaServerId() + " ] 已存在,请修改媒体服务器配置");
|
||||
}
|
||||
mediaServerItem.setId(zlmServerConfig.getGeneralMediaServerId());
|
||||
zlmServerConfig.setIp(mediaServerItem.getIp());
|
||||
mediaServerMapper.add(mediaServerItem);
|
||||
zlmServerOnline(zlmServerConfig);
|
||||
result.setCode(0);
|
||||
result.setMsg("success");
|
||||
}else {
|
||||
result.setCode(-1);
|
||||
result.setMsg("连接失败");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"连接失败");
|
||||
}
|
||||
|
||||
}else {
|
||||
result.setCode(-1);
|
||||
result.setMsg("连接失败");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"连接失败");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -385,7 +380,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
serverItem.setStatus(true);
|
||||
|
||||
if (StringUtils.isEmpty(serverItem.getId())) {
|
||||
if (ObjectUtils.isEmpty(serverItem.getId())) {
|
||||
logger.warn("[未注册的zlm] serverItem缺少ID, 无法接入:{}:{}", zlmServerConfig.getIp(),zlmServerConfig.getHttpPort() );
|
||||
return;
|
||||
}
|
||||
@@ -520,7 +515,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
// 最多等待未初始化的Track时间,单位毫秒,超时之后会忽略未初始化的Track, 设置此选项优化那些音频错误的不规范流,
|
||||
// 等zlm支持给每个rtpServer设置关闭音频的时候可以不设置此选项
|
||||
param.put("general.wait_track_ready_ms", "3000" );
|
||||
if (mediaServerItem.isRtpEnable() && !StringUtils.isEmpty(mediaServerItem.getRtpPortRange())) {
|
||||
if (mediaServerItem.isRtpEnable() && !ObjectUtils.isEmpty(mediaServerItem.getRtpPortRange())) {
|
||||
param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-"));
|
||||
}
|
||||
|
||||
@@ -547,12 +542,9 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
|
||||
|
||||
@Override
|
||||
public WVPResult<MediaServerItem> checkMediaServer(String ip, int port, String secret) {
|
||||
WVPResult<MediaServerItem> result = new WVPResult<>();
|
||||
public MediaServerItem checkMediaServer(String ip, int port, String secret) {
|
||||
if (mediaServerMapper.queryOneByHostAndPort(ip, port) != null) {
|
||||
result.setCode(-1);
|
||||
result.setMsg("此连接已存在");
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "此连接已存在");
|
||||
}
|
||||
MediaServerItem mediaServerItem = new MediaServerItem();
|
||||
mediaServerItem.setIp(ip);
|
||||
@@ -560,21 +552,15 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
mediaServerItem.setSecret(secret);
|
||||
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
if (responseJSON == null) {
|
||||
result.setCode(-1);
|
||||
result.setMsg("连接失败");
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接失败");
|
||||
}
|
||||
JSONArray data = responseJSON.getJSONArray("data");
|
||||
ZLMServerConfig zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
if (zlmServerConfig == null) {
|
||||
result.setCode(-1);
|
||||
result.setMsg("读取配置失败");
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "读取配置失败");
|
||||
}
|
||||
if (mediaServerMapper.queryOne(zlmServerConfig.getGeneralMediaServerId()) != null) {
|
||||
result.setCode(-1);
|
||||
result.setMsg("媒体服务ID [" + zlmServerConfig.getGeneralMediaServerId() + " ] 已存在,请修改媒体服务器配置");
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "媒体服务ID [" + zlmServerConfig.getGeneralMediaServerId() + " ] 已存在,请修改媒体服务器配置");
|
||||
}
|
||||
mediaServerItem.setHttpSSlPort(zlmServerConfig.getHttpPort());
|
||||
mediaServerItem.setRtmpPort(zlmServerConfig.getRtmpPort());
|
||||
@@ -586,10 +572,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
mediaServerItem.setHookIp(sipConfig.getIp());
|
||||
mediaServerItem.setSdpIp(ip);
|
||||
mediaServerItem.setStreamNoneReaderDelayMS(zlmServerConfig.getGeneralStreamNoneReaderDelayMS());
|
||||
result.setCode(0);
|
||||
result.setMsg("成功");
|
||||
result.setData(mediaServerItem);
|
||||
return result;
|
||||
return mediaServerItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.service.IMediaService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Service
|
||||
@@ -94,7 +95,7 @@ public class MediaServiceImpl implements IMediaService {
|
||||
}
|
||||
streamInfoResult.setIp(addr);
|
||||
streamInfoResult.setMediaServerId(mediaInfo.getId());
|
||||
String callIdParam = StringUtils.isEmpty(callId)?"":"?callId=" + callId;
|
||||
String callIdParam = ObjectUtils.isEmpty(callId)?"":"?callId=" + callId;
|
||||
streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s%s", addr, mediaInfo.getRtmpPort(), app, stream, callIdParam));
|
||||
if (mediaInfo.getRtmpSSlPort() != 0) {
|
||||
streamInfoResult.setRtmps(String.format("rtmps://%s:%s/%s/%s%s", addr, mediaInfo.getRtmpSSlPort(), app, stream, callIdParam));
|
||||
@@ -121,7 +122,7 @@ public class MediaServiceImpl implements IMediaService {
|
||||
streamInfoResult.setHttps_ts(String.format("https://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
|
||||
streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
|
||||
streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
|
||||
streamInfoResult.setRtc(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play%s", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream, StringUtils.isEmpty(callId)?"":"&callId=" + callId));
|
||||
streamInfoResult.setRtc(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play%s", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream, ObjectUtils.isEmpty(callId)?"":"&callId=" + callId));
|
||||
}
|
||||
|
||||
streamInfoResult.setTracks(tracks);
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.util.*;
|
||||
|
||||
import javax.sip.ResponseEvent;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -37,7 +39,6 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.HookType;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
@@ -52,7 +53,6 @@ import com.genersoft.iot.vmp.service.bean.PlayBackResult;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
|
||||
|
||||
@@ -114,6 +114,9 @@ public class PlayServiceImpl implements IPlayService {
|
||||
public PlayResult play(MediaServerItem mediaServerItem, String deviceId, String channelId,
|
||||
ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent,
|
||||
Runnable timeoutCallback) {
|
||||
if (mediaServerItem == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的zlm");
|
||||
}
|
||||
PlayResult playResult = new PlayResult();
|
||||
RequestMessage msg = new RequestMessage();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
|
||||
@@ -121,18 +124,11 @@ public class PlayServiceImpl implements IPlayService {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
msg.setId(uuid);
|
||||
playResult.setUuid(uuid);
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
|
||||
DeferredResult<WVPResult<String>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
|
||||
playResult.setResult(result);
|
||||
// 录像查询以channelId作为deviceId查询
|
||||
resultHolder.put(key, uuid, result);
|
||||
if (mediaServerItem == null) {
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setMsg("未找到可用的zlm");
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeResult(msg);
|
||||
return playResult;
|
||||
}
|
||||
|
||||
Device device = redisCatchStorage.getDevice(deviceId);
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
|
||||
playResult.setDevice(device);
|
||||
@@ -143,17 +139,14 @@ public class PlayServiceImpl implements IPlayService {
|
||||
// TODO 应该在上流时调用更好,结束也可能是错误结束
|
||||
String path = "snap";
|
||||
String fileName = deviceId + "_" + channelId + ".jpg";
|
||||
ResponseEntity responseEntity = (ResponseEntity)result.getResult();
|
||||
if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {
|
||||
WVPResult wvpResult = (WVPResult)responseEntity.getBody();
|
||||
if (Objects.requireNonNull(wvpResult).getCode() == 0) {
|
||||
StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData();
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId());
|
||||
String streamUrl = streamInfoForSuccess.getFmp4();
|
||||
// 请求截图
|
||||
logger.info("[请求截图]: " + fileName);
|
||||
zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName);
|
||||
}
|
||||
WVPResult wvpResult = (WVPResult)result.getResult();
|
||||
if (Objects.requireNonNull(wvpResult).getCode() == 0) {
|
||||
StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData();
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId());
|
||||
String streamUrl = streamInfoForSuccess.getFmp4();
|
||||
// 请求截图
|
||||
logger.info("[请求截图]: " + fileName);
|
||||
zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -161,7 +154,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
String streamId = streamInfo.getStream();
|
||||
if (streamId == null) {
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg("点播失败, redis缓存streamId等于null");
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeAllResult(msg);
|
||||
@@ -175,8 +168,8 @@ public class PlayServiceImpl implements IPlayService {
|
||||
if (rtpInfo.getBoolean("exist")) {
|
||||
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
wvpResult.setData(streamInfo);
|
||||
msg.setData(wvpResult);
|
||||
|
||||
@@ -211,7 +204,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}, event -> {
|
||||
// sip error错误
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg));
|
||||
msg.setData(wvpResult);
|
||||
resultHolder.invokeAllResult(msg);
|
||||
@@ -221,7 +214,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}, (code, msgStr)->{
|
||||
// invite点播超时
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
if (code == 0) {
|
||||
wvpResult.setMsg("点播超时,请稍候重试");
|
||||
}else if (code == 1) {
|
||||
@@ -361,8 +354,8 @@ public class PlayServiceImpl implements IPlayService {
|
||||
redisCatchStorage.startPlay(streamInfo);
|
||||
|
||||
WVPResult wvpResult = new WVPResult();
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
wvpResult.setData(streamInfo);
|
||||
msg.setData(wvpResult);
|
||||
|
||||
@@ -393,7 +386,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<ResponseEntity<String>> playBack(String deviceId, String channelId, String startTime,
|
||||
public DeferredResult<String> playBack(String deviceId, String channelId, String startTime,
|
||||
String endTime,InviteStreamCallback inviteStreamCallback,
|
||||
PlayBackCallback callback) {
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
@@ -407,7 +400,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<ResponseEntity<String>> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,
|
||||
public DeferredResult<String> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,
|
||||
String deviceId, String channelId, String startTime,
|
||||
String endTime, InviteStreamCallback infoCallBack,
|
||||
PlayBackCallback playBackCallback) {
|
||||
@@ -416,13 +409,11 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId;
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(30000L);
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device == null) {
|
||||
result.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备: " + deviceId + "不存在");
|
||||
}
|
||||
|
||||
DeferredResult<String> result = new DeferredResult<>(30000L);
|
||||
resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId, uuid, result);
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setId(uuid);
|
||||
@@ -482,7 +473,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<ResponseEntity<String>> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
|
||||
public DeferredResult<String> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device == null) {
|
||||
return null;
|
||||
@@ -494,17 +485,16 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeferredResult<ResponseEntity<String>> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
|
||||
public DeferredResult<String> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
|
||||
if (mediaServerItem == null || ssrcInfo == null) {
|
||||
return null;
|
||||
}
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId;
|
||||
DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(30000L);
|
||||
DeferredResult<String> result = new DeferredResult<>(30000L);
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device == null) {
|
||||
result.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
|
||||
return result;
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + "不存在");
|
||||
}
|
||||
|
||||
resultHolder.put(key, uuid, result);
|
||||
@@ -519,7 +509,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
String downLoadTimeOutTaskKey = UUID.randomUUID().toString();
|
||||
dynamicTask.startDelay(downLoadTimeOutTaskKey, ()->{
|
||||
logger.warn(String.format("录像下载请求超时,deviceId:%s ,channelId:%s", deviceId, channelId));
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg("录像下载请求超时");
|
||||
downloadResult.setCode(-1);
|
||||
hookCallBack.call(downloadResult);
|
||||
@@ -545,8 +535,8 @@ public class PlayServiceImpl implements IPlayService {
|
||||
streamInfo.setStartTime(startTime);
|
||||
streamInfo.setEndTime(endTime);
|
||||
redisCatchStorage.startDownload(streamInfo, inviteStreamInfo.getCallId());
|
||||
wvpResult.setCode(0);
|
||||
wvpResult.setMsg("success");
|
||||
wvpResult.setCode(ErrorCode.SUCCESS.getCode());
|
||||
wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
|
||||
wvpResult.setData(streamInfo);
|
||||
downloadResult.setCode(0);
|
||||
downloadResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
|
||||
@@ -555,7 +545,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||
}, event -> {
|
||||
dynamicTask.stop(downLoadTimeOutTaskKey);
|
||||
downloadResult.setCode(-1);
|
||||
wvpResult.setCode(-1);
|
||||
wvpResult.setCode(ErrorCode.ERROR100.getCode());
|
||||
wvpResult.setMsg(String.format("录像下载失败, 错误码: %s, %s", event.statusCode, event.msg));
|
||||
downloadResult.setEvent(event);
|
||||
hookCallBack.call(downloadResult);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.TreeType;
|
||||
@@ -24,6 +25,7 @@ import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
@@ -33,6 +35,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@@ -93,10 +96,8 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
|
||||
|
||||
@Override
|
||||
public WVPResult<StreamInfo> save(StreamProxyItem param) {
|
||||
public StreamInfo save(StreamProxyItem param) {
|
||||
MediaServerItem mediaInfo;
|
||||
WVPResult<StreamInfo> wvpResult = new WVPResult<>();
|
||||
wvpResult.setCode(0);
|
||||
if (param.getMediaServerId() == null || "auto".equals(param.getMediaServerId())){
|
||||
mediaInfo = mediaServerService.getMediaServerForMinimumLoad();
|
||||
}else {
|
||||
@@ -104,14 +105,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
}
|
||||
if (mediaInfo == null) {
|
||||
logger.warn("保存代理未找到在线的ZLM...");
|
||||
wvpResult.setMsg("保存失败");
|
||||
return wvpResult;
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "保存代理未找到在线的ZLM");
|
||||
}
|
||||
|
||||
String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
|
||||
param.getStream() );
|
||||
param.setDst_url(dstUrl);
|
||||
StringBuffer result = new StringBuffer();
|
||||
StringBuffer resultMsg = new StringBuffer();
|
||||
boolean streamLive = false;
|
||||
param.setMediaServerId(mediaInfo.getId());
|
||||
boolean saveResult;
|
||||
@@ -121,43 +120,47 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
}else { // 新增
|
||||
saveResult = addStreamProxy(param);
|
||||
}
|
||||
if (saveResult) {
|
||||
result.append("保存成功");
|
||||
if (param.isEnable()) {
|
||||
JSONObject jsonObject = addStreamProxyToZlm(param);
|
||||
if (jsonObject == null || jsonObject.getInteger("code") != 0) {
|
||||
streamLive = false;
|
||||
result.append(", 但是启用失败,请检查流地址是否可用");
|
||||
param.setEnable(false);
|
||||
// 直接移除
|
||||
if (param.isEnable_remove_none_reader()) {
|
||||
del(param.getApp(), param.getStream());
|
||||
}else {
|
||||
updateStreamProxy(param);
|
||||
}
|
||||
|
||||
}else {
|
||||
streamLive = true;
|
||||
StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
|
||||
mediaInfo, param.getApp(), param.getStream(), null, null);
|
||||
wvpResult.setData(streamInfo);
|
||||
|
||||
}
|
||||
}
|
||||
}else {
|
||||
result.append("保存失败");
|
||||
if (!saveResult) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"保存失败");
|
||||
}
|
||||
if ( !StringUtils.isEmpty(param.getPlatformGbId()) && streamLive) {
|
||||
StreamInfo resultForStreamInfo = null;
|
||||
resultMsg.append("保存成功");
|
||||
if (param.isEnable()) {
|
||||
JSONObject jsonObject = addStreamProxyToZlm(param);
|
||||
if (jsonObject == null || jsonObject.getInteger("code") != 0) {
|
||||
streamLive = false;
|
||||
resultMsg.append(", 但是启用失败,请检查流地址是否可用");
|
||||
param.setEnable(false);
|
||||
// 直接移除
|
||||
if (param.isEnable_remove_none_reader()) {
|
||||
del(param.getApp(), param.getStream());
|
||||
}else {
|
||||
updateStreamProxy(param);
|
||||
}
|
||||
|
||||
|
||||
}else {
|
||||
streamLive = true;
|
||||
resultForStreamInfo = mediaService.getStreamInfoByAppAndStream(
|
||||
mediaInfo, param.getApp(), param.getStream(), null, null);
|
||||
|
||||
}
|
||||
}
|
||||
if ( !ObjectUtils.isEmpty(param.getPlatformGbId()) && streamLive) {
|
||||
List<GbStream> gbStreams = new ArrayList<>();
|
||||
gbStreams.add(param);
|
||||
if (gbStreamService.addPlatformInfo(gbStreams, param.getPlatformGbId(), param.getCatalogId())){
|
||||
result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]成功");
|
||||
return resultForStreamInfo;
|
||||
}else {
|
||||
result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败");
|
||||
resultMsg.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), resultMsg.toString());
|
||||
}
|
||||
}else {
|
||||
if (!streamLive) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), resultMsg.toString());
|
||||
}
|
||||
}
|
||||
wvpResult.setMsg(result.toString());
|
||||
return wvpResult;
|
||||
return resultForStreamInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +177,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
streamProxyItem.setCreateTime(now);
|
||||
try {
|
||||
if (streamProxyMapper.add(streamProxyItem) > 0) {
|
||||
if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
|
||||
if (!ObjectUtils.isEmpty(streamProxyItem.getGbId())) {
|
||||
if (gbStreamMapper.add(streamProxyItem) < 0) {
|
||||
//事务回滚
|
||||
dataSourceTransactionManager.rollback(transactionStatus);
|
||||
@@ -209,7 +212,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
streamProxyItem.setStreamType("proxy");
|
||||
try {
|
||||
if (streamProxyMapper.update(streamProxyItem) > 0) {
|
||||
if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
|
||||
if (!ObjectUtils.isEmpty(streamProxyItem.getGbId())) {
|
||||
if (gbStreamMapper.updateByAppAndStream(streamProxyItem) == 0) {
|
||||
//事务回滚
|
||||
dataSourceTransactionManager.rollback(transactionStatus);
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -208,7 +209,7 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
Map<String, MediaItem> streamInfoPushItemMap = new HashMap<>();
|
||||
if (pushList.size() > 0) {
|
||||
for (StreamPushItem streamPushItem : pushList) {
|
||||
if (StringUtils.isEmpty(streamPushItem.getGbId())) {
|
||||
if (ObjectUtils.isEmpty(streamPushItem.getGbId())) {
|
||||
pushItemMap.put(streamPushItem.getApp() + streamPushItem.getStream(), streamPushItem);
|
||||
}
|
||||
}
|
||||
@@ -492,7 +493,7 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
try {
|
||||
int addStreamResult = streamPushMapper.add(stream);
|
||||
if (!StringUtils.isEmpty(stream.getGbId())) {
|
||||
if (!ObjectUtils.isEmpty(stream.getGbId())) {
|
||||
stream.setStreamType("push");
|
||||
gbStreamMapper.add(stream);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
@@ -82,9 +83,9 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPus
|
||||
|
||||
@Override
|
||||
public void invoke(StreamPushExcelDto streamPushExcelDto, AnalysisContext analysisContext) {
|
||||
if (StringUtils.isEmpty(streamPushExcelDto.getApp())
|
||||
|| StringUtils.isEmpty(streamPushExcelDto.getStream())
|
||||
|| StringUtils.isEmpty(streamPushExcelDto.getGbId())) {
|
||||
if (ObjectUtils.isEmpty(streamPushExcelDto.getApp())
|
||||
|| ObjectUtils.isEmpty(streamPushExcelDto.getStream())
|
||||
|| ObjectUtils.isEmpty(streamPushExcelDto.getGbId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,7 +131,7 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPus
|
||||
streamPushItems.add(streamPushItem);
|
||||
streamPushItemForSave.put(streamPushItem.getApp() + streamPushItem.getStream(), streamPushItem);
|
||||
|
||||
if (!StringUtils.isEmpty(streamPushExcelDto.getPlatformId())) {
|
||||
if (!ObjectUtils.isEmpty(streamPushExcelDto.getPlatformId())) {
|
||||
List<String[]> platformList = streamPushItemsForPlatform.get(streamPushItem.getApp() + streamPushItem.getStream());
|
||||
if (platformList == null) {
|
||||
platformList = new ArrayList<>();
|
||||
@@ -138,7 +139,7 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPus
|
||||
}
|
||||
String platformId = streamPushExcelDto.getPlatformId();
|
||||
String catalogId = streamPushExcelDto.getCatalogId();
|
||||
if (StringUtils.isEmpty(streamPushExcelDto.getCatalogId())) {
|
||||
if (ObjectUtils.isEmpty(streamPushExcelDto.getCatalogId())) {
|
||||
catalogId = null;
|
||||
}
|
||||
String[] platFormInfoArray = new String[]{platformId, catalogId};
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
@@ -60,7 +61,7 @@ public class UserServiceImpl implements IUserService {
|
||||
|
||||
@Override
|
||||
public boolean checkPushAuthority(String callId, String sign) {
|
||||
if (StringUtils.isEmpty(callId)) {
|
||||
if (ObjectUtils.isEmpty(callId)) {
|
||||
return userMapper.checkPushAuthorityByCallId(sign).size() > 0;
|
||||
}else {
|
||||
return userMapper.checkPushAuthorityByCallIdAndSign(callId, sign).size() > 0;
|
||||
|
||||
Reference in New Issue
Block a user