支持点播、停止点播和云台控制

This commit is contained in:
648540858
2025-10-07 10:56:18 +08:00
parent 61c64589b2
commit d4da1dc91c
13 changed files with 214 additions and 43 deletions

View File

@@ -612,4 +612,5 @@ public interface CommonGBChannelMapper {
CommonGBChannel queryByDataIdAndDeviceID(Integer deviceDbId, String deviceId);
}

View File

@@ -21,7 +21,7 @@ public interface IGbChannelPlayService {
void download(CommonGBChannel channel, Long startTime, Long stopTime, Integer downloadSpeed,
ErrorCallback<StreamInfo> callback);
void stopPlay(CommonGBChannel channel, String stream);
void stopPlay(CommonGBChannel channel);
void play(CommonGBChannel channel, Platform platform, Boolean record, ErrorCallback<StreamInfo> callback);

View File

@@ -72,6 +72,8 @@ public interface IPlayService {
void play(CommonGBChannel channel, Boolean record, ErrorCallback<StreamInfo> callback);
void stopPlay(InviteSessionType inviteSessionType, CommonGBChannel channel);
void stop(InviteSessionType inviteSessionType, CommonGBChannel channel, String stream);
void playBack(CommonGBChannel channel, Long startTime, Long stopTime, ErrorCallback<StreamInfo> callback);

View File

@@ -12,6 +12,6 @@ public interface ISourcePlayService {
void play(CommonGBChannel channel, Platform platform, Boolean record, ErrorCallback<StreamInfo> callback);
void stopPlay(CommonGBChannel channel, String stream);
void stopPlay(CommonGBChannel channel);
}

View File

@@ -70,7 +70,7 @@ public class GbChannelPlayServiceImpl implements IGbChannelPlayService {
public void stopInvite(InviteSessionType type, CommonGBChannel channel, String stream) {
switch (type) {
case PLAY:
stopPlay(channel, stream);
stopPlay(channel);
break;
case PLAYBACK:
stopPlayback(channel, stream);
@@ -135,7 +135,7 @@ public class GbChannelPlayServiceImpl implements IGbChannelPlayService {
}
@Override
public void stopPlay(CommonGBChannel channel, String stream) {
public void stopPlay(CommonGBChannel channel) {
Integer dataType = channel.getDataType();
ISourcePlayService sourceChannelPlayService = sourcePlayServiceMap.get(ChannelDataType.PLAY_SERVICE + dataType);
if (sourceChannelPlayService == null) {
@@ -143,7 +143,7 @@ public class GbChannelPlayServiceImpl implements IGbChannelPlayService {
log.error("[点播通用通道] 类型编号: {} 不支持停止实时流", dataType);
throw new PlayException(Response.BUSY_HERE, "channel not support");
}
sourceChannelPlayService.stopPlay(channel, stream);
sourceChannelPlayService.stopPlay(channel);
}
@Override

View File

@@ -1741,6 +1741,18 @@ public class PlayServiceImpl implements IPlayService {
}
@Override
public void stopPlay(InviteSessionType inviteSessionType, CommonGBChannel channel) {
Device device = deviceService.getDevice(channel.getDataDeviceId());
if (device == null) {
log.warn("[停止播放] 未找到通道{}的设备信息", channel);
throw new PlayException(Response.SERVER_INTERNAL_ERROR, "server internal error");
}
DeviceChannel deviceChannel = deviceChannelService.getOneForSourceById(channel.getGbId());
String stream = String.format("%s_%s", device.getDeviceId(), deviceChannel.getDeviceId());
stop(inviteSessionType, device, deviceChannel, stream);
}
@Override
public void stop(InviteSessionType inviteSessionType, CommonGBChannel channel, String stream) {
Device device = deviceService.getDevice(channel.getDataDeviceId());

View File

@@ -40,10 +40,10 @@ public class SourcePlayServiceForGbImpl implements ISourcePlayService {
}
@Override
public void stopPlay(CommonGBChannel channel, String stream) {
public void stopPlay(CommonGBChannel channel) {
// 国标通道
try {
deviceChannelPlayService.stop(InviteSessionType.PLAY, channel, stream);
deviceChannelPlayService.stopPlay(InviteSessionType.PLAY, channel);
} catch (Exception e) {
log.error("[停止点播失败] {}({})", channel.getGbName(), channel.getGbDeviceId(), e);
}

View File

@@ -36,7 +36,7 @@ public class SourcePlayServiceForJTImpl implements ISourcePlayService {
}
@Override
public void stopPlay(CommonGBChannel channel, String stream) {
public void stopPlay(CommonGBChannel channel) {
// 推流
try {
playService.stop(channel.getDataDeviceId());

View File

@@ -31,7 +31,7 @@ public class SourcePlayServiceForStreamProxyImpl implements ISourcePlayService {
}
@Override
public void stopPlay(CommonGBChannel channel, String stream) {
public void stopPlay(CommonGBChannel channel) {
// 拉流代理通道
try {
playService.stop(channel.getDataDeviceId());

View File

@@ -42,7 +42,7 @@ public class SourcePlayServiceForStreamPushImpl implements ISourcePlayService {
}
@Override
public void stopPlay(CommonGBChannel channel, String stream) {
public void stopPlay(CommonGBChannel channel) {
// 推流
try {
playService.stop(channel.getDataDeviceId());

View File

@@ -2,7 +2,11 @@ package com.genersoft.iot.vmp.vmanager.bean;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
@Schema(description = "统一返回结果")
public class WVPResult<T> implements Cloneable{
@@ -28,7 +32,7 @@ public class WVPResult<T> implements Cloneable{
return new WVPResult<>(ErrorCode.SUCCESS.getCode(), msg, t);
}
public static WVPResult success() {
public static <T> WVPResult<T> success() {
return new WVPResult<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), null);
}
@@ -44,30 +48,6 @@ public class WVPResult<T> implements Cloneable{
return fail(errorCode.getCode(), errorCode.getMsg());
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();

View File

@@ -1,6 +1,16 @@
package com.genersoft.iot.vmp.web.custom;
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.conf.security.JwtUtils;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.FrontEndControlCodeForPTZ;
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.genersoft.iot.vmp.web.custom.bean.CameraChannel;
import com.genersoft.iot.vmp.web.custom.bean.CameraStreamContent;
import com.genersoft.iot.vmp.web.custom.bean.IdsQueryParam;
@@ -11,11 +21,16 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.DeferredResult;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
@Tag(name = "第三方接口")
@@ -27,6 +42,9 @@ public class CameraChannelController {
@Autowired
private CameraChannelService channelService;
@Autowired
private UserSetting userSetting;
@GetMapping(value = "/camera/list/group")
@ResponseBody
@@ -191,8 +209,42 @@ public class CameraChannelController {
@Operation(summary = "播放摄像头", security = @SecurityRequirement(name = JwtUtils.HEADER))
@Parameter(name = "deviceId", description = "通道编号")
@Parameter(name = "deviceCode", description = "摄像头设备国标编号, 对于非国标摄像头可以不设置此参数")
public CameraStreamContent play(String deviceId, @RequestParam(required = false) String deviceCode) {
return null;
public DeferredResult<WVPResult<CameraStreamContent>> play(HttpServletRequest request, String deviceId, @RequestParam(required = false) String deviceCode) {
log.info("[SY-播放摄像头] API调用deviceId{} deviceCode{} ",deviceId, deviceCode);
DeferredResult<WVPResult<CameraStreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
ErrorCallback<StreamInfo> callback = (code, msg, streamInfo) -> {
if (code == InviteErrorCode.SUCCESS.getCode()) {
WVPResult<CameraStreamContent> wvpResult = WVPResult.success();
if (streamInfo != null) {
if (userSetting.getUseSourceIpAsStreamIp()) {
streamInfo=streamInfo.clone();//深拷贝
String host;
try {
URL url=new URL(request.getRequestURL().toString());
host=url.getHost();
} catch (MalformedURLException e) {
host=request.getLocalAddr();
}
streamInfo.changeStreamIp(host);
}
if (!ObjectUtils.isEmpty(streamInfo.getMediaServer().getTranscodeSuffix())
&& !"null".equalsIgnoreCase(streamInfo.getMediaServer().getTranscodeSuffix())) {
streamInfo.setStream(streamInfo.getStream() + "_" + streamInfo.getMediaServer().getTranscodeSuffix());
}
wvpResult.setData(new CameraStreamContent(streamInfo));
}else {
wvpResult.setCode(code);
wvpResult.setMsg(msg);
}
result.setResult(wvpResult);
}else {
result.setResult(WVPResult.fail(code, msg));
}
};
channelService.play(deviceId, deviceCode, callback);
return result;
}
@GetMapping(value = "/camera/control/stop")
@@ -201,6 +253,8 @@ public class CameraChannelController {
@Parameter(name = "deviceId", description = "通道编号")
@Parameter(name = "deviceCode", description = "摄像头设备国标编号, 对于非国标摄像头可以不设置此参数")
public void stopPlay(String deviceId, @RequestParam(required = false) String deviceCode) {
log.info("[SY-停止播放摄像头] API调用deviceId{} deviceCode{} ",deviceId, deviceCode);
channelService.stopPlay(deviceId, deviceCode);
}
@Operation(summary = "云台控制", security = @SecurityRequirement(name = JwtUtils.HEADER))
@@ -209,8 +263,25 @@ public class CameraChannelController {
@Parameter(name = "command", description = "控制指令,允许值: left, right, up, down, upleft, upright, downleft, downright, zoomin, zoomout, stop", required = true)
@Parameter(name = "speed", description = "速度(0-100)", required = true)
@GetMapping("/camera/control/ptz")
public void ptz(String deviceId, @RequestParam(required = false) String deviceCode, String command, Integer speed){
public DeferredResult<WVPResult<String>> ptz(String deviceId, @RequestParam(required = false) String deviceCode, String command, Integer speed){
log.info("[SY-云台控制] API调用deviceId{} deviceCode{} command{} speed{} ",deviceId, deviceCode, command, speed);
DeferredResult<WVPResult<String>> result = new DeferredResult<>();
result.onTimeout(()->{
WVPResult<String> wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "请求超时");
result.setResult(wvpResult);
});
channelService.ptz(deviceId, deviceCode, command, speed, (code, msg, data) -> {
WVPResult<String> wvpResult = new WVPResult<>();
wvpResult.setCode(code);
wvpResult.setMsg(msg);
wvpResult.setData(data);
result.setResult(wvpResult);
});
return result;
}

View File

@@ -1,14 +1,23 @@
package com.genersoft.iot.vmp.web.custom.service;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.common.enums.ChannelDataType;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.FrontEndControlCodeForPTZ;
import com.genersoft.iot.vmp.gb28181.bean.Group;
import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper;
import com.genersoft.iot.vmp.gb28181.dao.DeviceChannelMapper;
import com.genersoft.iot.vmp.gb28181.dao.DeviceMapper;
import com.genersoft.iot.vmp.gb28181.dao.GroupMapper;
import com.genersoft.iot.vmp.gb28181.service.IGbChannelControlService;
import com.genersoft.iot.vmp.gb28181.service.IGbChannelPlayService;
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
import com.genersoft.iot.vmp.utils.Coordtransform;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.genersoft.iot.vmp.web.custom.bean.CameraChannel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -18,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;
import java.util.List;
@@ -37,6 +47,15 @@ public class CameraChannelService implements CommandLineRunner {
@Autowired
private RedisTemplate<Object, Object> redisTemplate;
@Autowired
private IGbChannelPlayService channelPlayService;
@Autowired
private IGbChannelControlService channelControlService;
@Autowired
private UserSetting userSetting;
@Override
public void run(String... args) throws Exception {
// 启动时获取全局token
@@ -72,7 +91,7 @@ public class CameraChannelService implements CommandLineRunner {
return channels;
}
public CameraChannel queryOne(String deviceId, String deviceCode, String geoCoordSys) {
private CommonGBChannel queryChannelByDeviceIdAndDeviceCode(String deviceId, String deviceCode) {
CommonGBChannel channel = null;
if (deviceCode != null) {
Device device = deviceMapper.getDeviceByDeviceId(deviceId);
@@ -82,10 +101,13 @@ public class CameraChannelService implements CommandLineRunner {
}else {
channel = channelMapper.queryByDeviceId(deviceId);
}
return channel;
}
public CameraChannel queryOne(String deviceId, String deviceCode, String geoCoordSys) {
CommonGBChannel channel = queryChannelByDeviceIdAndDeviceCode(deviceId, deviceCode);
Assert.notNull(channel, "通道不存在");
if (deviceDbId != null) {
channel.setDeviceCode(deviceCode);
}
if (geoCoordSys != null && channel.getGbLongitude() != null && channel.getGbLatitude() != null
&& channel.getGbLongitude() > 0 && channel.getGbLatitude() > 0) {
if (geoCoordSys.equalsIgnoreCase("GCJ02")) {
@@ -99,6 +121,89 @@ public class CameraChannelService implements CommandLineRunner {
channel.setGbLatitude(position[1]);
}
}
return channel;
CameraChannel resultChannel = (CameraChannel)channel;
if (deviceCode != null) {
resultChannel.setDeviceCode(deviceCode);
}
return resultChannel;
}
/**
* 播放通道
* @param deviceId 通道编号
* @param deviceCode 通道对应的国标设备的编号
* @param callback 点播结果的回放
*/
public void play(String deviceId, String deviceCode, ErrorCallback<StreamInfo> callback) {
CommonGBChannel channel = queryChannelByDeviceIdAndDeviceCode(deviceId, deviceCode);
Assert.notNull(channel, "通道不存在");
channelPlayService.play(channel, null, userSetting.getRecordSip(), callback);
}
/**
* 停止播放通道
* @param deviceId 通道编号
* @param deviceCode 通道对应的国标设备的编号
*/
public void stopPlay(String deviceId, String deviceCode) {
CommonGBChannel channel = queryChannelByDeviceIdAndDeviceCode(deviceId, deviceCode);
Assert.notNull(channel, "通道不存在");
channelPlayService.stopPlay(channel);
}
public void ptz(String deviceId, String deviceCode, String command, Integer speed, ErrorCallback<String> callback) {
CommonGBChannel channel = queryChannelByDeviceIdAndDeviceCode(deviceId, deviceCode);
Assert.notNull(channel, "通道不存在");
if (speed == null) {
speed = 50;
}else if (speed < 0 || speed > 100) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "panSpeed 为 0-100的数字");
}
FrontEndControlCodeForPTZ controlCode = new FrontEndControlCodeForPTZ();
controlCode.setPanSpeed(speed);
controlCode.setTiltSpeed(speed);
controlCode.setZoomSpeed(speed);
switch (command){
case "left":
controlCode.setPan(0);
break;
case "right":
controlCode.setPan(1);
break;
case "up":
controlCode.setTilt(0);
break;
case "down":
controlCode.setTilt(1);
break;
case "upleft":
controlCode.setPan(0);
controlCode.setTilt(0);
break;
case "upright":
controlCode.setTilt(0);
controlCode.setPan(1);
break;
case "downleft":
controlCode.setPan(0);
controlCode.setTilt(1);
break;
case "downright":
controlCode.setTilt(1);
controlCode.setPan(1);
break;
case "zoomin":
controlCode.setZoom(1);
break;
case "zoomout":
controlCode.setZoom(0);
break;
default:
break;
}
channelControlService.ptz(channel, controlCode, callback);
}
}