| | |
| | | import org.springframework.beans.factory.annotation.Qualifier;
|
| | | import org.springframework.context.annotation.DependsOn;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.util.ObjectUtils;
|
| | | import org.springframework.util.StringUtils;
|
| | |
|
| | | import javax.sip.*;
|
| | |
| | | * 语音广播
|
| | | *
|
| | | * @param device 视频设备
|
| | | * @param channelId 预览通道
|
| | | */
|
| | | @Override
|
| | | public boolean audioBroadcastCmd(Device device, String channelId) {
|
| | | // 改为新的实现
|
| | | return false;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 语音广播
|
| | | * |
| | | * @param device 视频设备
|
| | | */
|
| | | @Override
|
| | | public boolean audioBroadcastCmd(Device device) {
|
| | | public boolean audioBroadcastCmd(Device device,String channelId, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer broadcastXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | |
| | | broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
|
| | | broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
|
| | | broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
|
| | | broadcastXml.append("<TargetID>" + channelId + "</TargetID>\r\n");
|
| | | broadcastXml.append("</Notify>\r\n");
|
| | |
|
| | | String tm = Long.toString(System.currentTimeMillis());
|
| | |
| | | : udpSipProvider.getNewCallId();
|
| | |
|
| | | Request request = headerProvider.createMessageRequest(device, broadcastXml.toString(), "z9hG4bK-ViaBcst-" + tm, "FromBcst" + tm, null, callIdHeader);
|
| | | transmitRequest(device, request);
|
| | | transmitRequest(device, request, errorEvent, okEvent);
|
| | | return true;
|
| | | } catch (SipException | ParseException | InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return false;
|
| | | }
|
| | | @Override
|
| | | public void audioBroadcastCmd(Device device, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer broadcastXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | | broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | broadcastXml.append("<Notify>\r\n");
|
| | | broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
|
| | | broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | broadcastXml.append("<SourceID>" + sipConfig.getId() + "</SourceID>\r\n");
|
| | | broadcastXml.append("<TargetID>" + device.getDeviceId() + "</TargetID>\r\n");
|
| | | broadcastXml.append("</Notify>\r\n");
|
| | | |
| | | String tm = Long.toString(System.currentTimeMillis());
|
| | |
|
| | | CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | | : udpSipProvider.getNewCallId();
|
| | | |
| | | Request request = headerProvider.createMessageRequest(device, broadcastXml.toString(), "z9hG4bK-ViaBcst-" + tm, "FromBcst" + tm, null, callIdHeader);
|
| | | transmitRequest(device, request, errorEvent);
|
| | | } catch (SipException | ParseException | InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | | } |
| | | } |
| | | |
| | | |
| | | /**
|
| | | * 音视频录像控制
|
| | | *
|
| | |
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | if (StringUtils.isEmpty(channelId)) {
|
| | | if (ObjectUtils.isEmpty(channelId)) {
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | } else {
|
| | | cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | |
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | cmdXml.append("<AlarmCmd>ResetAlarm</AlarmCmd>\r\n");
|
| | | if (!StringUtils.isEmpty(alarmMethod) || !StringUtils.isEmpty(alarmType)) {
|
| | | if (!ObjectUtils.isEmpty(alarmMethod) || !ObjectUtils.isEmpty(alarmType)) {
|
| | | cmdXml.append("<Info>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(alarmMethod)) {
|
| | | if (!ObjectUtils.isEmpty(alarmMethod)) {
|
| | | cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(alarmType)) {
|
| | | if (!ObjectUtils.isEmpty(alarmType)) {
|
| | | cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(alarmMethod) || !StringUtils.isEmpty(alarmType)) {
|
| | | if (!ObjectUtils.isEmpty(alarmMethod) || !ObjectUtils.isEmpty(alarmType)) {
|
| | | cmdXml.append("</Info>\r\n");
|
| | | }
|
| | | cmdXml.append("</Control>\r\n");
|
| | |
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | if (StringUtils.isEmpty(channelId)) {
|
| | | if (ObjectUtils.isEmpty(channelId)) {
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | } else {
|
| | | cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | |
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | if (StringUtils.isEmpty(channelId)) {
|
| | | if (ObjectUtils.isEmpty(channelId)) {
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | } else {
|
| | | cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | |
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | if (StringUtils.isEmpty(channelId)) {
|
| | | if (ObjectUtils.isEmpty(channelId)) {
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | } else {
|
| | | cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | | }
|
| | | cmdXml.append("<BasicParam>\r\n");
|
| | | if (!StringUtils.isEmpty(name)) {
|
| | | if (!ObjectUtils.isEmpty(name)) {
|
| | | cmdXml.append("<Name>" + name + "</Name>\r\n");
|
| | | }
|
| | | if (NumericUtil.isInteger(expiration)) {
|
| | |
| | | cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | if (!StringUtils.isEmpty(startPriority)) {
|
| | | if (!ObjectUtils.isEmpty(startPriority)) {
|
| | | cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(endPriority)) {
|
| | | if (!ObjectUtils.isEmpty(endPriority)) {
|
| | | cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(alarmMethod)) {
|
| | | if (!ObjectUtils.isEmpty(alarmMethod)) {
|
| | | cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(alarmType)) {
|
| | | if (!ObjectUtils.isEmpty(alarmType)) {
|
| | | cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(startTime)) {
|
| | | if (!ObjectUtils.isEmpty(startTime)) {
|
| | | cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(endTime)) {
|
| | | if (!ObjectUtils.isEmpty(endTime)) {
|
| | | cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
|
| | | }
|
| | | cmdXml.append("</Query>\r\n");
|
| | |
| | | cmdXml.append("<Query>\r\n");
|
| | | cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | if (StringUtils.isEmpty(channelId)) {
|
| | | if (ObjectUtils.isEmpty(channelId)) {
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | } else {
|
| | | cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | |
| | | cmdXml.append("<Query>\r\n");
|
| | | cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | if (StringUtils.isEmpty(channelId)) {
|
| | | if (ObjectUtils.isEmpty(channelId)) {
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | } else {
|
| | | cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | |
| | | cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | if (!StringUtils.isEmpty(startPriority)) {
|
| | | if (!ObjectUtils.isEmpty(startPriority)) {
|
| | | cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(endPriority)) {
|
| | | if (!ObjectUtils.isEmpty(endPriority)) {
|
| | | cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(alarmMethod)) {
|
| | | if (!ObjectUtils.isEmpty(alarmMethod)) {
|
| | | cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(alarmType)) {
|
| | | if (!ObjectUtils.isEmpty(alarmType)) {
|
| | | cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(startTime)) {
|
| | | if (!ObjectUtils.isEmpty(startTime)) {
|
| | | cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
|
| | | }
|
| | | if (!StringUtils.isEmpty(endTime)) {
|
| | | if (!ObjectUtils.isEmpty(endTime)) {
|
| | | cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
|
| | | }
|
| | | cmdXml.append("</Query>\r\n");
|
| | |
| | | dragXml.append("<Control>\r\n");
|
| | | dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
|
| | | if (StringUtils.isEmpty(channelId)) {
|
| | | if (ObjectUtils.isEmpty(channelId)) {
|
| | | dragXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | } else {
|
| | | dragXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | |
| | | private int getInfoCseq() {
|
| | | return (int) ((Math.random() * 9 + 1) * Math.pow(10, 8));
|
| | | }
|
| | | |
| | |
|
| | | @Override
|
| | | public void playbackControlCmd(Device device, StreamInfo streamInfo, String content,SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) {
|
| | | try {
|