From c6202b3b2754ce81234940caa108ca24448ac9ca Mon Sep 17 00:00:00 2001 From: szy833 <1037966925@qq.com> Date: Sat, 15 Jan 2022 22:29:59 +0800 Subject: [PATCH] =?UTF-8?q?feat():=20=E5=A2=9E=E5=8A=A0=E6=8B=89=E6=A1=86?= =?UTF-8?q?=E6=94=BE=E5=A4=A7=EF=BC=8C=E7=BC=A9=E5=B0=8F=E3=80=82=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E4=B8=8B=E7=BA=A7=E8=AE=BE=E5=A4=87=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E4=BF=A1=E4=BB=A4=E5=A2=9E=E5=8A=A0200=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/transmit/cmd/ISIPCommander.java | 9 ++ .../transmit/cmd/impl/SIPCommander.java | 28 ++++ .../DeviceControlResponseMessageHandler.java | 34 +++-- .../gb28181/dragZoom/DragZoomControl.java | 138 ++++++++++++++++++ 4 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/dragZoom/DragZoomControl.java diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java index 6e96dac3..8be07ca1 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java @@ -328,4 +328,13 @@ public interface ISIPCommander { * @return true = 命令发送成功 */ boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent); + + /** + * 拉框控制命令 + * + * @param device 控制设备 + * @param channelId 通道id + * @param cmdString 前端控制指令串 + */ + boolean dragZoomCmd(Device device, String channelId, String cmdString); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index 59e21925..285a8175 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -1509,6 +1509,34 @@ public class SIPCommander implements ISIPCommander { } } + @Override + public boolean dragZoomCmd(Device device, String channelId, String cmdString) { + try { + StringBuffer dragXml = new StringBuffer(200); + dragXml.append("\r\n"); + dragXml.append("\r\n"); + dragXml.append("DeviceControl\r\n"); + dragXml.append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n"); + if (StringUtils.isEmpty(channelId)) { + dragXml.append("" + device.getDeviceId() + "\r\n"); + } else { + dragXml.append("" + channelId + "\r\n"); + } + dragXml.append(cmdString); + dragXml.append("\r\n"); + String tm = Long.toString(System.currentTimeMillis()); + CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() + : udpSipProvider.getNewCallId(); + Request request = headerProvider.createMessageRequest(device, dragXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader); + logger.debug("拉框信令: " + request.toString()); + transmitRequest(device, request); + return true; + } catch (SipException | ParseException | InvalidArgumentException e) { + e.printStackTrace(); + } + return false; + } + private ClientTransaction transmitRequest(Device device, Request request) throws SipException { return transmitRequest(device, request, null, null); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlResponseMessageHandler.java index 69f664bb..0c9b8353 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlResponseMessageHandler.java @@ -16,7 +16,12 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.sip.InvalidArgumentException; import javax.sip.RequestEvent; +import javax.sip.SipException; +import javax.sip.message.Response; + +import java.text.ParseException; import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; @@ -40,17 +45,26 @@ public class DeviceControlResponseMessageHandler extends SIPRequestProcessorPare @Override public void handForDevice(RequestEvent evt, Device device, Element element) { // 此处是对本平台发出DeviceControl指令的应答 - JSONObject json = new JSONObject(); - String channelId = getText(element, "DeviceID"); - XmlUtil.node2Json(element, json); - if (logger.isDebugEnabled()) { - logger.debug(json.toJSONString()); + try { + responseAck(evt, Response.OK); + JSONObject json = new JSONObject(); + String channelId = getText(element, "DeviceID"); + XmlUtil.node2Json(element, json); + if (logger.isDebugEnabled()) { + logger.debug(json.toJSONString()); + } + RequestMessage msg = new RequestMessage(); + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + device.getDeviceId() + channelId; + msg.setKey(key); + msg.setData(json); + deferredResultHolder.invokeAllResult(msg); + } catch (SipException e) { + e.printStackTrace(); + } catch (InvalidArgumentException e) { + e.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); } - RequestMessage msg = new RequestMessage(); - String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + device.getDeviceId() + channelId; - msg.setKey(key); - msg.setData(json); - deferredResultHolder.invokeAllResult(msg); } @Override diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/dragZoom/DragZoomControl.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/dragZoom/DragZoomControl.java new file mode 100644 index 00000000..fb1970ef --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/dragZoom/DragZoomControl.java @@ -0,0 +1,138 @@ +package com.genersoft.iot.vmp.vmanager.gb28181.dragZoom; + +import com.genersoft.iot.vmp.gb28181.bean.Device; +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +/** + * @author szy + * @date 21:55 2022/1/15 + */ +@Api(tags = "拉框控制") +@CrossOrigin +@RestController +@RequestMapping("/api/dragZoom") +public class DragZoomControl { + + private final static Logger logger = LoggerFactory.getLogger(DragZoomControl.class); + + @Autowired + private SIPCommander cmder; + + @Autowired + private IVideoManagerStorager storager; + + @Autowired + private DeferredResultHolder resultHolder; + + /** + * 拉框放大 + * @param deviceId 设备id + * @param channelId 通道id + * @param length 播放窗口长度像素值 + * @param width 播放窗口宽度像素值 + * @param midpointx 拉框中心的横轴坐标像素值 + * @param midpointy 拉框中心的纵轴坐标像素值 + * @param lengthx 拉框长度像素值 + * @param lengthy 拉框宽度像素值 + * @return + */ + @ApiOperation("拉框放大") + @ApiImplicitParams({ + @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), + @ApiImplicitParam(name = "channelId", value = "通道ID", dataTypeClass = String.class), + @ApiImplicitParam(name = "length", value = "播放窗口长度像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "width", value = "播放窗口宽度像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "midpointx", value = "拉框中心的横轴坐标像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "midpointy", value = "拉框中心的纵轴坐标像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "lengthx", value = "拉框长度像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "lengthy", value = "拉框宽度像素值", required = true, dataTypeClass = Integer.class), + }) + @GetMapping("/dragzoomin") + public ResponseEntity dragZoomIn(@RequestParam String deviceId, + @RequestParam(required = false) String channelId, + @RequestParam int length, + @RequestParam int width, + @RequestParam int midpointx, + @RequestParam int midpointy, + @RequestParam int lengthx, + @RequestParam int lengthy){ + if (logger.isDebugEnabled()) { + logger.debug(String.format("设备拉框放大 API调用,deviceId:%s ,channelId:%s ,length:%d ,width:%d ,midpointx:%d ,midpointy:%d ,lengthx:%d ,lengthy:%d",deviceId, channelId, length, width, midpointx, midpointy,lengthx, lengthy)); + } + Device device = storager.queryVideoDevice(deviceId); + StringBuffer cmdXml = new StringBuffer(200); + cmdXml.append("\r\n"); + cmdXml.append("" + length+ "\r\n"); + cmdXml.append("" + width+ "\r\n"); + cmdXml.append("" + midpointx+ "\r\n"); + cmdXml.append("" + midpointy+ "\r\n"); + cmdXml.append("" + lengthx+ "\r\n"); + cmdXml.append("" + lengthy+ "\r\n"); + cmdXml.append("\r\n"); + cmder.dragZoomCmd(device, channelId, cmdXml.toString()); + return new ResponseEntity("success", HttpStatus.OK); + } + + /** + * 拉框缩小 + * @param deviceId 设备id + * @param channelId 通道id + * @param length 播放窗口长度像素值 + * @param width 播放窗口宽度像素值 + * @param midpointx 拉框中心的横轴坐标像素值 + * @param midpointy 拉框中心的纵轴坐标像素值 + * @param lengthx 拉框长度像素值 + * @param lengthy 拉框宽度像素值 + * @return + */ + @ApiOperation("拉框缩小") + @ApiImplicitParams({ + @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), + @ApiImplicitParam(name = "channelId", value = "通道ID", dataTypeClass = String.class), + @ApiImplicitParam(name = "length", value = "播放窗口长度像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "width", value = "播放窗口宽度像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "midpointx", value = "拉框中心的横轴坐标像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "midpointy", value = "拉框中心的纵轴坐标像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "lengthx", value = "拉框长度像素值", required = true, dataTypeClass = Integer.class), + @ApiImplicitParam(name = "lengthy", value = "拉框宽度像素值", required = true, dataTypeClass = Integer.class), + }) + @GetMapping("/dragzoomout") + public ResponseEntity dragZoomOut(@RequestParam String deviceId, + @RequestParam(required = false) String channelId, + @RequestParam int length, + @RequestParam int width, + @RequestParam int midpointx, + @RequestParam int midpointy, + @RequestParam int lengthx, + @RequestParam int lengthy){ + + if (logger.isDebugEnabled()) { + logger.debug(String.format("设备拉框缩小 API调用,deviceId:%s ,channelId:%s ,length:%d ,width:%d ,midpointx:%d ,midpointy:%d ,lengthx:%d ,lengthy:%d",deviceId, channelId, length, width, midpointx, midpointy,lengthx, lengthy)); + } + Device device = storager.queryVideoDevice(deviceId); + StringBuffer cmdXml = new StringBuffer(200); + cmdXml.append("\r\n"); + cmdXml.append("" + length+ "\r\n"); + cmdXml.append("" + width+ "\r\n"); + cmdXml.append("" + midpointx+ "\r\n"); + cmdXml.append("" + midpointy+ "\r\n"); + cmdXml.append("" + lengthx+ "\r\n"); + cmdXml.append("" + lengthy+ "\r\n"); + cmdXml.append("\r\n"); + cmder.dragZoomCmd(device, channelId, cmdXml.toString()); + return new ResponseEntity("success",HttpStatus.OK); + } + +}