支持点播、停止点播和云台控制
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user