优化拉流代理表单以及逻辑

This commit is contained in:
648540858
2022-11-22 17:17:35 +08:00
parent 1469971102
commit 8ea6e192d9
10 changed files with 108 additions and 141 deletions

View File

@@ -1,12 +1,12 @@
package com.genersoft.iot.vmp.conf;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEventListener;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
@@ -40,8 +40,8 @@ public class GlobalExceptionHandler {
*/
@ExceptionHandler(ControllerException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public WVPResult<String> exceptionHandler(ControllerException e) {
return WVPResult.fail(e.getCode(), e.getMsg());
public ResponseEntity<WVPResult<String>> exceptionHandler(ControllerException e) {
return new ResponseEntity<>(WVPResult.fail(e.getCode(), e.getMsg()), HttpStatus.OK);
}
/**
@@ -51,7 +51,7 @@ public class GlobalExceptionHandler {
*/
@ExceptionHandler(BadCredentialsException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public WVPResult<String> exceptionHandler(BadCredentialsException e) {
return WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMessage());
public ResponseEntity<WVPResult<String>> exceptionHandler(BadCredentialsException e) {
return new ResponseEntity<>(WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMessage()), HttpStatus.OK);
}
}

View File

@@ -505,6 +505,7 @@ public class ZLMHttpHookListener {
// 修改数据
streamProxyService.stop(param.getApp(), param.getStream());
}else {
// 无人观看不做处理
ret.put("close", false);
}
return ret;

View File

@@ -236,14 +236,13 @@ public class ZLMRESTfulUtils {
}
public JSONObject addFFmpegSource(MediaServerItem mediaServerItem, String src_url, String dst_url, String timeout_ms,
boolean enable_hls, boolean enable_mp4, String ffmpeg_cmd_key){
boolean enable_audio, boolean enable_mp4, String ffmpeg_cmd_key){
logger.info(src_url);
logger.info(dst_url);
Map<String, Object> param = new HashMap<>();
param.put("src_url", src_url);
param.put("dst_url", dst_url);
param.put("timeout_ms", timeout_ms);
param.put("enable_hls", enable_hls);
param.put("enable_mp4", enable_mp4);
param.put("ffmpeg_cmd_key", ffmpeg_cmd_key);
return sendPost(mediaServerItem, "addFFmpegSource",param, null);
@@ -287,19 +286,14 @@ public class ZLMRESTfulUtils {
return sendPost(mediaServerItem, "restartServer",null, null);
}
public JSONObject addStreamProxy(MediaServerItem mediaServerItem, String app, String stream, String url, boolean enable_hls, boolean enable_mp4, String rtp_type) {
public JSONObject addStreamProxy(MediaServerItem mediaServerItem, String app, String stream, String url, boolean enable_audio, boolean enable_mp4, String rtp_type) {
Map<String, Object> param = new HashMap<>();
param.put("vhost", "__defaultVhost__");
param.put("app", app);
param.put("stream", stream);
param.put("url", url);
param.put("enable_hls", enable_hls?1:0);
param.put("enable_mp4", enable_mp4?1:0);
param.put("enable_rtmp", 1);
param.put("enable_fmp4", 1);
param.put("enable_audio", 1);
param.put("enable_rtsp", 1);
param.put("add_mute_audio", 1);
param.put("enable_audio", enable_audio?1:0);
param.put("rtp_type", rtp_type);
return sendPost(mediaServerItem, "addStreamProxy",param, null);
}

View File

@@ -31,8 +31,8 @@ public class StreamProxyItem extends GbStream {
private String rtp_type;
@Schema(description = "是否启用")
private boolean enable;
@Schema(description = "是否启用HLS")
private boolean enable_hls;
@Schema(description = "是否启用音频")
private boolean enable_audio;
@Schema(description = "是否启用MP4")
private boolean enable_mp4;
@Schema(description = "是否 无人观看时删除")
@@ -40,8 +40,6 @@ public class StreamProxyItem extends GbStream {
@Schema(description = "是否 无人观看时自动停用")
private boolean enable_disable_none_reader;
@Schema(description = "上级平台国标ID")
private String platformGbId;
@Schema(description = "创建时间")
private String createTime;
@@ -139,14 +137,6 @@ public class StreamProxyItem extends GbStream {
this.enable = enable;
}
public boolean isEnable_hls() {
return enable_hls;
}
public void setEnable_hls(boolean enable_hls) {
this.enable_hls = enable_hls;
}
public boolean isEnable_mp4() {
return enable_mp4;
}
@@ -155,19 +145,12 @@ public class StreamProxyItem extends GbStream {
this.enable_mp4 = enable_mp4;
}
public String getPlatformGbId() {
return platformGbId;
}
public void setPlatformGbId(String platformGbId) {
this.platformGbId = platformGbId;
}
@Override
public String getCreateTime() {
return createTime;
}
@Override
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
@@ -187,4 +170,12 @@ public class StreamProxyItem extends GbStream {
public void setEnable_disable_none_reader(boolean enable_disable_none_reader) {
this.enable_disable_none_reader = enable_disable_none_reader;
}
public boolean isEnable_audio() {
return enable_audio;
}
public void setEnable_audio(boolean enable_audio) {
this.enable_audio = enable_audio;
}
}

View File

@@ -5,23 +5,22 @@ import com.alibaba.fastjson2.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.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
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.hook.OnStreamChangedHookParam;
import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IMediaService;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
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.ResourceBaceInfo;
@@ -35,7 +34,9 @@ import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 视频代理业务
@@ -107,7 +108,6 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
param.getStream() );
param.setDst_url(dstUrl);
StringBuffer resultMsg = new StringBuffer();
boolean streamLive = false;
param.setMediaServerId(mediaInfo.getId());
boolean saveResult;
// 更新
@@ -124,7 +124,6 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
if (param.isEnable()) {
JSONObject jsonObject = addStreamProxyToZlm(param);
if (jsonObject == null || jsonObject.getInteger("code") != 0) {
streamLive = false;
resultMsg.append(", 但是启用失败,请检查流地址是否可用");
param.setEnable(false);
// 直接移除
@@ -134,28 +133,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
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())){
return resultForStreamInfo;
}else {
resultMsg.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败");
throw new ControllerException(ErrorCode.ERROR100.getCode(), resultMsg.toString());
}
}else {
if (!streamLive) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), resultMsg.toString());
}
}
return resultForStreamInfo;
}
@@ -245,10 +228,10 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
}
if ("default".equals(param.getType())){
result = zlmresTfulUtils.addStreamProxy(mediaServerItem, param.getApp(), param.getStream(), param.getUrl(),
param.isEnable_hls(), param.isEnable_mp4(), param.getRtp_type());
param.isEnable_audio(), param.isEnable_mp4(), param.getRtp_type());
}else if ("ffmpeg".equals(param.getType())) {
result = zlmresTfulUtils.addFFmpegSource(mediaServerItem, param.getSrc_url(), param.getDst_url(),
param.getTimeout_ms() + "", param.isEnable_hls(), param.isEnable_mp4(),
param.getTimeout_ms() + "", param.isEnable_audio(), param.isEnable_mp4(),
param.getFfmpeg_cmd_key());
}
return result;

View File

@@ -12,9 +12,9 @@ import java.util.List;
public interface StreamProxyMapper {
@Insert("INSERT INTO stream_proxy (type, name, app, stream,mediaServerId, url, src_url, dst_url, " +
"timeout_ms, ffmpeg_cmd_key, rtp_type, enable_hls, enable_mp4, enable, status, enable_remove_none_reader, enable_disable_none_reader, createTime) VALUES" +
"timeout_ms, ffmpeg_cmd_key, rtp_type, enable_audio, enable_mp4, enable, status, enable_remove_none_reader, enable_disable_none_reader, createTime) VALUES" +
"('${type}','${name}', '${app}', '${stream}', '${mediaServerId}','${url}', '${src_url}', '${dst_url}', " +
"'${timeout_ms}', '${ffmpeg_cmd_key}', '${rtp_type}', ${enable_hls}, ${enable_mp4}, ${enable}, ${status}, " +
"'${timeout_ms}', '${ffmpeg_cmd_key}', '${rtp_type}', ${enable_audio}, ${enable_mp4}, ${enable}, ${status}, " +
"${enable_remove_none_reader}, ${enable_disable_none_reader}, '${createTime}' )")
int add(StreamProxyItem streamProxyDto);
@@ -30,7 +30,7 @@ public interface StreamProxyMapper {
"timeout_ms=#{timeout_ms}, " +
"ffmpeg_cmd_key=#{ffmpeg_cmd_key}, " +
"rtp_type=#{rtp_type}, " +
"enable_hls=#{enable_hls}, " +
"enable_audio=#{enable_audio}, " +
"enable=#{enable}, " +
"status=#{status}, " +
"enable_remove_none_reader=#{enable_remove_none_reader}, " +