Commit b7c16fe6ed13a3ddc3f35a8caf2736f1536bad61
Committed by
GitHub
Merge pull request #311 from szy833/wvp-28181-2.0
feat(): 增加拉框放大,缩小。接收下级设备控制Message信令后增加200返回,防止下级重复发送Message。
Showing
4 changed files
with
199 additions
and
10 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
| ... | ... | @@ -328,4 +328,13 @@ public interface ISIPCommander { |
| 328 | 328 | * @return true = 命令发送成功 |
| 329 | 329 | */ |
| 330 | 330 | boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent); |
| 331 | + | |
| 332 | + /** | |
| 333 | + * 拉框控制命令 | |
| 334 | + * | |
| 335 | + * @param device 控制设备 | |
| 336 | + * @param channelId 通道id | |
| 337 | + * @param cmdString 前端控制指令串 | |
| 338 | + */ | |
| 339 | + boolean dragZoomCmd(Device device, String channelId, String cmdString); | |
| 331 | 340 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
| ... | ... | @@ -1509,6 +1509,34 @@ public class SIPCommander implements ISIPCommander { |
| 1509 | 1509 | } |
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | + @Override | |
| 1513 | + public boolean dragZoomCmd(Device device, String channelId, String cmdString) { | |
| 1514 | + try { | |
| 1515 | + StringBuffer dragXml = new StringBuffer(200); | |
| 1516 | + dragXml.append("<?xml version=\"1.0\" ?>\r\n"); | |
| 1517 | + dragXml.append("<Control>\r\n"); | |
| 1518 | + dragXml.append("<CmdType>DeviceControl</CmdType>\r\n"); | |
| 1519 | + dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n"); | |
| 1520 | + if (StringUtils.isEmpty(channelId)) { | |
| 1521 | + dragXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n"); | |
| 1522 | + } else { | |
| 1523 | + dragXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n"); | |
| 1524 | + } | |
| 1525 | + dragXml.append(cmdString); | |
| 1526 | + dragXml.append("</Control>\r\n"); | |
| 1527 | + String tm = Long.toString(System.currentTimeMillis()); | |
| 1528 | + CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId() | |
| 1529 | + : udpSipProvider.getNewCallId(); | |
| 1530 | + Request request = headerProvider.createMessageRequest(device, dragXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader); | |
| 1531 | + logger.debug("拉框信令: " + request.toString()); | |
| 1532 | + transmitRequest(device, request); | |
| 1533 | + return true; | |
| 1534 | + } catch (SipException | ParseException | InvalidArgumentException e) { | |
| 1535 | + e.printStackTrace(); | |
| 1536 | + } | |
| 1537 | + return false; | |
| 1538 | + } | |
| 1539 | + | |
| 1512 | 1540 | |
| 1513 | 1541 | private ClientTransaction transmitRequest(Device device, Request request) throws SipException { |
| 1514 | 1542 | return transmitRequest(device, request, null, null); | ... | ... |
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; |
| 16 | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| 17 | 17 | import org.springframework.stereotype.Component; |
| 18 | 18 | |
| 19 | +import javax.sip.InvalidArgumentException; | |
| 19 | 20 | import javax.sip.RequestEvent; |
| 21 | +import javax.sip.SipException; | |
| 22 | +import javax.sip.message.Response; | |
| 23 | + | |
| 24 | +import java.text.ParseException; | |
| 20 | 25 | |
| 21 | 26 | import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; |
| 22 | 27 | |
| ... | ... | @@ -40,17 +45,26 @@ public class DeviceControlResponseMessageHandler extends SIPRequestProcessorPare |
| 40 | 45 | @Override |
| 41 | 46 | public void handForDevice(RequestEvent evt, Device device, Element element) { |
| 42 | 47 | // 此处是对本平台发出DeviceControl指令的应答 |
| 43 | - JSONObject json = new JSONObject(); | |
| 44 | - String channelId = getText(element, "DeviceID"); | |
| 45 | - XmlUtil.node2Json(element, json); | |
| 46 | - if (logger.isDebugEnabled()) { | |
| 47 | - logger.debug(json.toJSONString()); | |
| 48 | + try { | |
| 49 | + responseAck(evt, Response.OK); | |
| 50 | + JSONObject json = new JSONObject(); | |
| 51 | + String channelId = getText(element, "DeviceID"); | |
| 52 | + XmlUtil.node2Json(element, json); | |
| 53 | + if (logger.isDebugEnabled()) { | |
| 54 | + logger.debug(json.toJSONString()); | |
| 55 | + } | |
| 56 | + RequestMessage msg = new RequestMessage(); | |
| 57 | + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + device.getDeviceId() + channelId; | |
| 58 | + msg.setKey(key); | |
| 59 | + msg.setData(json); | |
| 60 | + deferredResultHolder.invokeAllResult(msg); | |
| 61 | + } catch (SipException e) { | |
| 62 | + e.printStackTrace(); | |
| 63 | + } catch (InvalidArgumentException e) { | |
| 64 | + e.printStackTrace(); | |
| 65 | + } catch (ParseException e) { | |
| 66 | + e.printStackTrace(); | |
| 48 | 67 | } |
| 49 | - RequestMessage msg = new RequestMessage(); | |
| 50 | - String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + device.getDeviceId() + channelId; | |
| 51 | - msg.setKey(key); | |
| 52 | - msg.setData(json); | |
| 53 | - deferredResultHolder.invokeAllResult(msg); | |
| 54 | 68 | } |
| 55 | 69 | |
| 56 | 70 | @Override | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/dragZoom/DragZoomControl.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.vmanager.gb28181.dragZoom; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 5 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | |
| 6 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 7 | +import io.swagger.annotations.Api; | |
| 8 | +import io.swagger.annotations.ApiImplicitParam; | |
| 9 | +import io.swagger.annotations.ApiImplicitParams; | |
| 10 | +import io.swagger.annotations.ApiOperation; | |
| 11 | +import org.slf4j.Logger; | |
| 12 | +import org.slf4j.LoggerFactory; | |
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | +import org.springframework.http.HttpStatus; | |
| 15 | +import org.springframework.http.ResponseEntity; | |
| 16 | +import org.springframework.web.bind.annotation.*; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * @author szy | |
| 20 | + * @date 21:55 2022/1/15 | |
| 21 | + */ | |
| 22 | +@Api(tags = "拉框控制") | |
| 23 | +@CrossOrigin | |
| 24 | +@RestController | |
| 25 | +@RequestMapping("/api/dragZoom") | |
| 26 | +public class DragZoomControl { | |
| 27 | + | |
| 28 | + private final static Logger logger = LoggerFactory.getLogger(DragZoomControl.class); | |
| 29 | + | |
| 30 | + @Autowired | |
| 31 | + private SIPCommander cmder; | |
| 32 | + | |
| 33 | + @Autowired | |
| 34 | + private IVideoManagerStorager storager; | |
| 35 | + | |
| 36 | + @Autowired | |
| 37 | + private DeferredResultHolder resultHolder; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 拉框放大 | |
| 41 | + * @param deviceId 设备id | |
| 42 | + * @param channelId 通道id | |
| 43 | + * @param length 播放窗口长度像素值 | |
| 44 | + * @param width 播放窗口宽度像素值 | |
| 45 | + * @param midpointx 拉框中心的横轴坐标像素值 | |
| 46 | + * @param midpointy 拉框中心的纵轴坐标像素值 | |
| 47 | + * @param lengthx 拉框长度像素值 | |
| 48 | + * @param lengthy 拉框宽度像素值 | |
| 49 | + * @return | |
| 50 | + */ | |
| 51 | + @ApiOperation("拉框放大") | |
| 52 | + @ApiImplicitParams({ | |
| 53 | + @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), | |
| 54 | + @ApiImplicitParam(name = "channelId", value = "通道ID", dataTypeClass = String.class), | |
| 55 | + @ApiImplicitParam(name = "length", value = "播放窗口长度像素值", required = true, dataTypeClass = Integer.class), | |
| 56 | + @ApiImplicitParam(name = "width", value = "播放窗口宽度像素值", required = true, dataTypeClass = Integer.class), | |
| 57 | + @ApiImplicitParam(name = "midpointx", value = "拉框中心的横轴坐标像素值", required = true, dataTypeClass = Integer.class), | |
| 58 | + @ApiImplicitParam(name = "midpointy", value = "拉框中心的纵轴坐标像素值", required = true, dataTypeClass = Integer.class), | |
| 59 | + @ApiImplicitParam(name = "lengthx", value = "拉框长度像素值", required = true, dataTypeClass = Integer.class), | |
| 60 | + @ApiImplicitParam(name = "lengthy", value = "拉框宽度像素值", required = true, dataTypeClass = Integer.class), | |
| 61 | + }) | |
| 62 | + @GetMapping("/dragzoomin") | |
| 63 | + public ResponseEntity<String> dragZoomIn(@RequestParam String deviceId, | |
| 64 | + @RequestParam(required = false) String channelId, | |
| 65 | + @RequestParam int length, | |
| 66 | + @RequestParam int width, | |
| 67 | + @RequestParam int midpointx, | |
| 68 | + @RequestParam int midpointy, | |
| 69 | + @RequestParam int lengthx, | |
| 70 | + @RequestParam int lengthy){ | |
| 71 | + if (logger.isDebugEnabled()) { | |
| 72 | + 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)); | |
| 73 | + } | |
| 74 | + Device device = storager.queryVideoDevice(deviceId); | |
| 75 | + StringBuffer cmdXml = new StringBuffer(200); | |
| 76 | + cmdXml.append("<DragZoomIn>\r\n"); | |
| 77 | + cmdXml.append("<Length>" + length+ "</Length>\r\n"); | |
| 78 | + cmdXml.append("<Width>" + width+ "</Width>\r\n"); | |
| 79 | + cmdXml.append("<MidPointX>" + midpointx+ "</MidPointX>\r\n"); | |
| 80 | + cmdXml.append("<MidPointY>" + midpointy+ "</MidPointY>\r\n"); | |
| 81 | + cmdXml.append("<LengthX>" + lengthx+ "</LengthX>\r\n"); | |
| 82 | + cmdXml.append("<LengthY>" + lengthy+ "</LengthY>\r\n"); | |
| 83 | + cmdXml.append("</DragZoomIn>\r\n"); | |
| 84 | + cmder.dragZoomCmd(device, channelId, cmdXml.toString()); | |
| 85 | + return new ResponseEntity<String>("success", HttpStatus.OK); | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * 拉框缩小 | |
| 90 | + * @param deviceId 设备id | |
| 91 | + * @param channelId 通道id | |
| 92 | + * @param length 播放窗口长度像素值 | |
| 93 | + * @param width 播放窗口宽度像素值 | |
| 94 | + * @param midpointx 拉框中心的横轴坐标像素值 | |
| 95 | + * @param midpointy 拉框中心的纵轴坐标像素值 | |
| 96 | + * @param lengthx 拉框长度像素值 | |
| 97 | + * @param lengthy 拉框宽度像素值 | |
| 98 | + * @return | |
| 99 | + */ | |
| 100 | + @ApiOperation("拉框缩小") | |
| 101 | + @ApiImplicitParams({ | |
| 102 | + @ApiImplicitParam(name = "deviceId", value = "设备ID", required = true, dataTypeClass = String.class), | |
| 103 | + @ApiImplicitParam(name = "channelId", value = "通道ID", dataTypeClass = String.class), | |
| 104 | + @ApiImplicitParam(name = "length", value = "播放窗口长度像素值", required = true, dataTypeClass = Integer.class), | |
| 105 | + @ApiImplicitParam(name = "width", value = "播放窗口宽度像素值", required = true, dataTypeClass = Integer.class), | |
| 106 | + @ApiImplicitParam(name = "midpointx", value = "拉框中心的横轴坐标像素值", required = true, dataTypeClass = Integer.class), | |
| 107 | + @ApiImplicitParam(name = "midpointy", value = "拉框中心的纵轴坐标像素值", required = true, dataTypeClass = Integer.class), | |
| 108 | + @ApiImplicitParam(name = "lengthx", value = "拉框长度像素值", required = true, dataTypeClass = Integer.class), | |
| 109 | + @ApiImplicitParam(name = "lengthy", value = "拉框宽度像素值", required = true, dataTypeClass = Integer.class), | |
| 110 | + }) | |
| 111 | + @GetMapping("/dragzoomout") | |
| 112 | + public ResponseEntity<String> dragZoomOut(@RequestParam String deviceId, | |
| 113 | + @RequestParam(required = false) String channelId, | |
| 114 | + @RequestParam int length, | |
| 115 | + @RequestParam int width, | |
| 116 | + @RequestParam int midpointx, | |
| 117 | + @RequestParam int midpointy, | |
| 118 | + @RequestParam int lengthx, | |
| 119 | + @RequestParam int lengthy){ | |
| 120 | + | |
| 121 | + if (logger.isDebugEnabled()) { | |
| 122 | + 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)); | |
| 123 | + } | |
| 124 | + Device device = storager.queryVideoDevice(deviceId); | |
| 125 | + StringBuffer cmdXml = new StringBuffer(200); | |
| 126 | + cmdXml.append("<DragZoomOut>\r\n"); | |
| 127 | + cmdXml.append("<Length>" + length+ "</Length>\r\n"); | |
| 128 | + cmdXml.append("<Width>" + width+ "</Width>\r\n"); | |
| 129 | + cmdXml.append("<MidPointX>" + midpointx+ "</MidPointX>\r\n"); | |
| 130 | + cmdXml.append("<MidPointY>" + midpointy+ "</MidPointY>\r\n"); | |
| 131 | + cmdXml.append("<LengthX>" + lengthx+ "</LengthX>\r\n"); | |
| 132 | + cmdXml.append("<LengthY>" + lengthy+ "</LengthY>\r\n"); | |
| 133 | + cmdXml.append("</DragZoomOut>\r\n"); | |
| 134 | + cmder.dragZoomCmd(device, channelId, cmdXml.toString()); | |
| 135 | + return new ResponseEntity<String>("success",HttpStatus.OK); | |
| 136 | + } | |
| 137 | + | |
| 138 | +} | ... | ... |