| | |
| | | return ptzCmd(device, channelId, 0, 0, inOut, 0, zoomSpeed);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 云台指令码计算 |
| | | *
|
| | | * @param leftRight 镜头左移右移 0:停止 1:左移 2:右移
|
| | | * @param upDown 镜头上移下移 0:停止 1:上移 2:下移
|
| | | * @param inOut 镜头放大缩小 0:停止 1:缩小 2:放大
|
| | | * @param moveSpeed 镜头移动速度 默认 0XFF (0-255)
|
| | | * @param zoomSpeed 镜头缩放速度 默认 0X1 (0-15)
|
| | | */
|
| | | public static String cmdString(int leftRight, int upDown, int inOut, int moveSpeed, int zoomSpeed) {
|
| | | int cmdCode = 0;
|
| | | if (leftRight == 2) {
|
| | | cmdCode|=0x01; // 右移
|
| | | } else if(leftRight == 1) {
|
| | | cmdCode|=0x02; // 左移
|
| | | }
|
| | | if (upDown == 2) {
|
| | | cmdCode|=0x04; // 下移
|
| | | } else if(upDown == 1) {
|
| | | cmdCode|=0x08; // 上移
|
| | | }
|
| | | if (inOut == 2) {
|
| | | cmdCode |= 0x10; // 放大
|
| | | } else if(inOut == 1) {
|
| | | cmdCode |= 0x20; // 缩小
|
| | | }
|
| | | StringBuilder builder = new StringBuilder("A50F01");
|
| | | String strTmp;
|
| | | strTmp = String.format("%02X", cmdCode);
|
| | | builder.append(strTmp, 0, 2);
|
| | | strTmp = String.format("%02X", moveSpeed);
|
| | | builder.append(strTmp, 0, 2);
|
| | | builder.append(strTmp, 0, 2);
|
| | | // strTmp = String.format("%X", zoomSpeed);
|
| | | int zs=(zoomSpeed<<4 & 0XF0);
|
| | | strTmp = String.format("%X", zs);
|
| | | builder.append(strTmp, 0, 1).append("0");
|
| | | //计算校验码
|
| | | int checkCode = (0XA5 + 0X0F + 0X01 + cmdCode + moveSpeed + moveSpeed + zs/*(zoomSpeed << 4 & 0XF0)*/) % 0X100;
|
| | | strTmp = String.format("%02X", checkCode);
|
| | | builder.append(strTmp, 0, 2);
|
| | | return builder.toString();
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 云台控制,支持方向与缩放控制
|
| | | *
|
| | |
| | | public boolean ptzCmd(Device device, String channelId, int leftRight, int upDown, int inOut, int moveSpeed,
|
| | | int zoomSpeed) {
|
| | | try {
|
| | | String cmdStr= cmdString(leftRight, upDown, inOut, moveSpeed, zoomSpeed);
|
| | | StringBuffer ptzXml = new StringBuffer(200);
|
| | | ptzXml.append("<?xml version=\"1.0\" ?>");
|
| | | ptzXml.append("<Control>");
|
| | | ptzXml.append("<CmdType>DeviceControl</CmdType>");
|
| | | ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>");
|
| | | ptzXml.append("<DeviceID>" + channelId + "</DeviceID>");
|
| | | ptzXml.append("<PTZCmd>" + PtzCmdHelper.create(leftRight, upDown, inOut, moveSpeed, zoomSpeed) + "</PTZCmd>");
|
| | | ptzXml.append("<PTZCmd>" + cmdStr + "</PTZCmd>");
|
| | | ptzXml.append("<Info>");
|
| | | ptzXml.append("</Info>");
|
| | | ptzXml.append("</Control>");
|
| | |
| | | Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag");
|
| | |
|
| | | transmitRequest(device, request);
|
| | | |
| | | return true;
|
| | | } catch (SipException | ParseException | InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | |
| | | try {
|
| | |
|
| | | String ssrc = streamSession.createPlaySsrc();
|
| | | String transport = device.getTransport();
|
| | | //
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+channelId+" 0 0 IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
| | | content.append("o="+channelId+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
|
| | | content.append("s=Play\r\n");
|
| | | content.append("c=IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
| | | content.append("t=0 0\r\n");
|
| | | if(device.getTransport().equals("TCP")) {
|
| | | if("TCP".equals(transport)) {
|
| | | content.append("m=video "+sipConfig.getMediaPort()+" TCP/RTP/AVP 96 98 97\r\n");
|
| | | }
|
| | | if(device.getTransport().equals("UDP")) {
|
| | | if("UDP".equals(transport)) {
|
| | | content.append("m=video "+sipConfig.getMediaPort()+" RTP/AVP 96 98 97\r\n");
|
| | | }
|
| | | content.append("a=sendrecv\r\n");
|
| | | content.append("a=recvonly\r\n");
|
| | | content.append("a=rtpmap:96 PS/90000\r\n");
|
| | | content.append("a=rtpmap:98 H264/90000\r\n");
|
| | | content.append("a=rtpmap:97 MPEG4/90000\r\n");
|
| | | if(device.getTransport().equals("TCP")){
|
| | | if("TCP".equals(transport)){
|
| | | content.append("a=setup:passive\r\n");
|
| | | content.append("a=connection:new\r\n");
|
| | | }
|
| | | content.append("y="+ssrc+"\r\n");//ssrc
|
| | |
|
| | | Request request = headerProvider.createInviteRequest(device, content.toString(), null, "live", null);
|
| | | Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null);
|
| | |
|
| | | ClientTransaction transaction = transmitRequest(device, request);
|
| | | streamSession.put(ssrc, transaction);
|
| | |
| | | //
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+device.getDeviceId()+" 0 0 IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
| | | content.append("o="+sipConfig.getSipId()+" 0 0 IN IP4 "+sipConfig.getSipIp()+"\r\n");
|
| | | content.append("s=Playback\r\n");
|
| | | content.append("u="+channelId+":3\r\n");
|
| | | content.append("u="+channelId+":0\r\n");
|
| | | content.append("c=IN IP4 "+sipConfig.getMediaIp()+"\r\n");
|
| | | content.append("t="+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime)+" "+DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime) +"\r\n");
|
| | | if(device.getTransport().equals("TCP")) {
|
| | |
| | | }
|
| | | content.append("y="+ssrc+"\r\n");//ssrc
|
| | |
|
| | | Request request = headerProvider.createInviteRequest(device, content.toString(), null, "live", null);
|
| | | Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "playback", null);
|
| | |
|
| | | ClientTransaction transaction = transmitRequest(device, request);
|
| | | streamSession.put(ssrc, transaction);
|
| | |
| | | }
|
| | | Request byeRequest = dialog.createRequest(Request.BYE);
|
| | | ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
|
| | | String protocol = viaHeader.getTransport();
|
| | | String protocol = viaHeader.getTransport().toUpperCase();
|
| | | ClientTransaction clientTransaction = null;
|
| | | if("TCP".equals(protocol)) {
|
| | | clientTransaction = sipLayer.getTcpSipProvider().getNewClientTransaction(byeRequest);
|