Commit ee746e53cda8e35ede1d966b582160caeb1ca562

Authored by 648540858
2 parents 50c2a5a7 83671d8f

Merge remote-tracking branch 'gitee.com/wvp-pro-record' into wvp-28181-2.0

# Conflicts:
#	src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
Showing 34 changed files with 612 additions and 279 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java
... ... @@ -4,11 +4,6 @@ package com.genersoft.iot.vmp.gb28181.bean;
4 4 public class Device {
5 5  
6 6 /**
7   - * Id
8   - */
9   - private int id;
10   -
11   - /**
12 7 * 设备Id
13 8 */
14 9 private String deviceId;
... ... @@ -119,13 +114,7 @@ public class Device {
119 114 */
120 115 private int subscribeCycleForCatalog ;
121 116  
122   - public int getId() {
123   - return id;
124   - }
125 117  
126   - public void setId(int id) {
127   - this.id = id;
128   - }
129 118  
130 119 public String getDeviceId() {
131 120 return deviceId;
... ... @@ -294,6 +283,4 @@ public class Device {
294 283 public void setSubscribeCycleForCatalog(int subscribeCycleForCatalog) {
295 284 this.subscribeCycleForCatalog = subscribeCycleForCatalog;
296 285 }
297   -
298   -
299 286 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/bean/MobilePosition.java
... ... @@ -8,10 +8,6 @@ package com.genersoft.iot.vmp.gb28181.bean;
8 8  
9 9 public class MobilePosition {
10 10 /**
11   - * Id
12   - */
13   - private int id;
14   - /**
15 11 * 设备Id
16 12 */
17 13 private String deviceId;
... ... @@ -76,13 +72,6 @@ public class MobilePosition {
76 72 */
77 73 private String cnLat;
78 74  
79   - public int getId() {
80   - return id;
81   - }
82   -
83   - public void setId(int id) {
84   - this.id = id;
85   - }
86 75  
87 76 public String getDeviceId() {
88 77 return deviceId;
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/bean/RecordItem.java
... ... @@ -19,7 +19,9 @@ public class RecordItem implements Comparable<RecordItem>{
19 19 private String name;
20 20  
21 21 private String filePath;
22   -
  22 +
  23 + private String fileSize;
  24 +
23 25 private String address;
24 26  
25 27 private String startTime;
... ... @@ -104,6 +106,14 @@ public class RecordItem implements Comparable<RecordItem>{
104 106 this.recorderId = recorderId;
105 107 }
106 108  
  109 + public String getFileSize() {
  110 + return fileSize;
  111 + }
  112 +
  113 + public void setFileSize(String fileSize) {
  114 + this.fileSize = fileSize;
  115 + }
  116 +
107 117 @Override
108 118 public int compareTo(@NotNull RecordItem recordItem) {
109 119 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/bean/SDPInfo.java 0 → 100644
  1 +package com.genersoft.iot.vmp.gb28181.bean;
  2 +
  3 +import javax.sdp.SessionDescription;
  4 +
  5 +public class SDPInfo {
  6 + private byte[] source;
  7 + private SessionDescription sdpSource;
  8 + private String sessionName;
  9 + private Long startTime;
  10 + private Long stopTime;
  11 + private String username;
  12 + private String address;
  13 + private String ssrc;
  14 +}
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/bean/SendRtpItem.java
... ... @@ -71,6 +71,16 @@ public class SendRtpItem {
71 71 */
72 72 private String mediaServerId;
73 73  
  74 + /**
  75 + * invite的callId
  76 + */
  77 + private String CallId;
  78 +
  79 + /**
  80 + * 是否是play, false是playback
  81 + */
  82 + private boolean isPlay;
  83 +
74 84 public String getIp() {
75 85 return ip;
76 86 }
... ... @@ -174,4 +184,20 @@ public class SendRtpItem {
174 184 public void setMediaServerId(String mediaServerId) {
175 185 this.mediaServerId = mediaServerId;
176 186 }
  187 +
  188 + public String getCallId() {
  189 + return CallId;
  190 + }
  191 +
  192 + public void setCallId(String callId) {
  193 + CallId = callId;
  194 + }
  195 +
  196 + public boolean isPlay() {
  197 + return isPlay;
  198 + }
  199 +
  200 + public void setPlay(boolean play) {
  201 + isPlay = play;
  202 + }
177 203 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
1 1 package com.genersoft.iot.vmp.gb28181.event;
2 2  
3   -import com.genersoft.iot.vmp.gb28181.bean.Device;
4   -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
5   -import com.genersoft.iot.vmp.gb28181.bean.GbStream;
  3 +import com.genersoft.iot.vmp.gb28181.bean.*;
6 4 import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent;
7 5 import com.genersoft.iot.vmp.gb28181.event.platformKeepaliveExpire.PlatformKeepaliveExpireEvent;
8 6 import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformCycleRegisterEvent;
9 7 import com.genersoft.iot.vmp.gb28181.event.platformNotRegister.PlatformNotRegisterEvent;
  8 +import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEvent;
10 9 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
11 10 import com.genersoft.iot.vmp.media.zlm.event.ZLMOfflineEvent;
12 11 import com.genersoft.iot.vmp.media.zlm.event.ZLMOnlineEvent;
... ... @@ -15,7 +14,6 @@ import org.springframework.context.ApplicationEventPublisher;
15 14 import org.springframework.scheduling.annotation.Async;
16 15 import org.springframework.stereotype.Component;
17 16  
18   -import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
19 17 import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent;
20 18 import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent;
21 19  
... ... @@ -145,4 +143,11 @@ public class EventPublisher {
145 143 gbStreamList.add(gbStream);
146 144 catalogEventPublishForStream(platformId, gbStreamList, type);
147 145 }
  146 +
  147 + public void recordEndEventPush(RecordInfo recordInfo) {
  148 + RecordEndEvent outEvent = new RecordEndEvent(this);
  149 + outEvent.setRecordInfo(recordInfo);
  150 + applicationEventPublisher.publishEvent(outEvent);
  151 + }
  152 +
148 153 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
... ... @@ -76,10 +76,7 @@ public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEvent
76 76 eventResult.callId = callid;
77 77 eventResult.msg = "注册超时";
78 78 eventResult.type = "register timeout";
79   - if (sipSubscribe.getErrorSubscribe(callid) != null) {
80   - sipSubscribe.getErrorSubscribe(callid).response(eventResult);
81   - }
82   -
  79 + sipSubscribe.getErrorSubscribe(callid).response(eventResult);
83 80 }
84 81  
85 82 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/record/RecordEndEventListener.java
1 1 package com.genersoft.iot.vmp.gb28181.event.record;
2 2  
  3 +import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
3 4 import com.genersoft.iot.vmp.gb28181.bean.RecordItem;
4 5 import org.slf4j.Logger;
5 6 import org.slf4j.LoggerFactory;
... ... @@ -23,12 +24,8 @@ public class RecordEndEventListener implements ApplicationListener<RecordEndEven
23 24  
24 25 private static Map<String, SseEmitter> sseEmitters = new Hashtable<>();
25 26  
26   - public void addSseEmitters(String browserId, SseEmitter sseEmitter) {
27   - sseEmitters.put(browserId, sseEmitter);
28   - }
29   -
30 27 public interface RecordEndEventHandler{
31   - void handler(List<RecordItem> recordItems);
  28 + void handler(RecordInfo recordInfo);
32 29 }
33 30  
34 31 private Map<String, RecordEndEventHandler> handlerMap = new HashMap<>();
... ... @@ -38,6 +35,15 @@ public class RecordEndEventListener implements ApplicationListener&lt;RecordEndEven
38 35 logger.debug("录像查询完成事件触发,deviceId:{}, channelId: {}, 录像数量{}条", event.getRecordInfo().getDeviceId(),
39 36 event.getRecordInfo().getChannelId(), event.getRecordInfo().getRecordList().size() );
40 37 }
  38 + if (handlerMap.size() > 0) {
  39 + for (RecordEndEventHandler recordEndEventHandler : handlerMap.values()) {
  40 + recordEndEventHandler.handler(event.getRecordInfo());
  41 + }
  42 + }
  43 +
  44 + }
41 45  
  46 + public void addEndEventHandler(String device, String channelId, RecordEndEventHandler recordEndEventHandler) {
  47 + handlerMap.put(device + channelId, recordEndEventHandler);
42 48 }
43 49 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcConfig.java
... ... @@ -81,7 +81,6 @@ public class SsrcConfig {
81 81 isUsed.remove(sn);
82 82 notUsed.add(sn);
83 83 }catch (NullPointerException e){
84   - System.out.printf("11111");
85 84 }
86 85 }
87 86  
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/task/GPSSubscribeTask.java
... ... @@ -36,7 +36,6 @@ public class GPSSubscribeTask implements Runnable{
36 36  
37 37 SubscribeInfo subscribe = redisCatchStorage.getSubscribe(key);
38 38 if (subscribe != null) {
39   - System.out.println("发送GPS消息");
40 39 ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformId);
41 40 if (parentPlatform == null || parentPlatform.isStatus()) {
42 41 // TODO 暂时只处理视频流的回复,后续增加对国标设备的支持
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java
... ... @@ -141,7 +141,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
141 141 */
142 142 @Override
143 143 public void processTimeout(TimeoutEvent timeoutEvent) {
144   - System.out.println("processTimeout");
145 144 if(timeoutProcessor != null) {
146 145 timeoutProcessor.process(timeoutEvent);
147 146 }
... ... @@ -173,7 +172,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
173 172  
174 173 @Override
175 174 public void processDialogTerminated(DialogTerminatedEvent dialogTerminatedEvent) {
176   - System.out.println("processDialogTerminated");
177 175 CallIdHeader callId = dialogTerminatedEvent.getDialog().getCallId();
178 176 }
179 177  
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
... ... @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.cmd;
2 2  
3 3 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
4 4 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
  5 +import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
5 6 import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
6 7 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
7 8 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
... ... @@ -87,4 +88,12 @@ public interface ISIPCommanderForPlatform {
87 88 */
88 89 boolean sendNotifyForCatalogOther(String type, ParentPlatform parentPlatform, List<DeviceChannel> deviceChannels, SubscribeInfo subscribeInfo, Integer index);
89 90  
  91 + /**
  92 + * 回复recordInfo
  93 + * @param deviceChannel 通道信息
  94 + * @param parentPlatform 平台信息
  95 + * @param fromTag fromTag
  96 + * @param recordInfo 录像信息
  97 + */
  98 + boolean recordInfo(DeviceChannel deviceChannel, ParentPlatform parentPlatform, String fromTag, RecordInfo recordInfo);
90 99 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
... ... @@ -346,8 +346,11 @@ public class SIPCommander implements ISIPCommander {
346 346 subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
347 347 (MediaServerItem mediaServerItemInUse, JSONObject json)->{
348 348 if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
349   - event.response(mediaServerItemInUse, json);
350   - subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
  349 + if (event != null) {
  350 + event.response(mediaServerItemInUse, json);
  351 + }
  352 +
  353 +// subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
351 354 });
352 355 //
353 356 StringBuffer content = new StringBuffer(200);
... ... @@ -450,13 +453,16 @@ public class SIPCommander implements ISIPCommander {
450 453 subscribeKey.put("app", "rtp");
451 454 subscribeKey.put("stream", ssrcInfo.getStream());
452 455 subscribeKey.put("regist", true);
  456 + subscribeKey.put("schema", "rtmp");
453 457 subscribeKey.put("mediaServerId", mediaServerItem.getId());
454 458 logger.debug("录像回放添加订阅,订阅内容:" + subscribeKey.toString());
455 459 subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
456 460 (MediaServerItem mediaServerItemInUse, JSONObject json)->{
  461 + System.out.println(344444);
457 462 if (userSetup.isWaitTrack() && json.getJSONArray("tracks") == null) return;
458   - event.response(mediaServerItemInUse, json);
459   - subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
  463 + if (event != null) {
  464 + event.response(mediaServerItemInUse, json);
  465 + }
460 466 });
461 467  
462 468 StringBuffer content = new StringBuffer(200);
... ... @@ -713,6 +719,7 @@ public class SIPCommander implements ISIPCommander {
713 719 if (ssrcTransaction != null) {
714 720 MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId());
715 721 mediaServerService.releaseSsrc(mediaServerItem, ssrcTransaction.getSsrc());
  722 + mediaServerService.closeRTPServer(deviceId, channelId, ssrcTransaction.getStream());
716 723 streamSession.remove(deviceId, channelId, ssrcTransaction.getStream());
717 724 }
718 725 } catch (SipException | ParseException e) {
... ... @@ -1203,7 +1210,6 @@ public class SIPCommander implements ISIPCommander {
1203 1210 if (type == null) {
1204 1211 type = "all";
1205 1212 }
1206   -
1207 1213 try {
1208 1214 StringBuffer recordInfoXml = new StringBuffer(200);
1209 1215 recordInfoXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
... ... @@ -1211,11 +1217,19 @@ public class SIPCommander implements ISIPCommander {
1211 1217 recordInfoXml.append("<CmdType>RecordInfo</CmdType>\r\n");
1212 1218 recordInfoXml.append("<SN>" + sn + "</SN>\r\n");
1213 1219 recordInfoXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
1214   - recordInfoXml.append("<StartTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(startTime) + "</StartTime>\r\n");
1215   - recordInfoXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(endTime) + "</EndTime>\r\n");
1216   - recordInfoXml.append("<Secrecy> "+ secrecy + " </Secrecy>\r\n");
1217   - // 大华NVR要求必须增加一个值为all的文本元素节点Type
1218   - recordInfoXml.append("<Type>" + type+"</Type>\r\n");
  1220 + if (startTime != null) {
  1221 + recordInfoXml.append("<StartTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(startTime) + "</StartTime>\r\n");
  1222 + }
  1223 + if (endTime != null) {
  1224 + recordInfoXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(endTime) + "</EndTime>\r\n");
  1225 + }
  1226 + if (secrecy != null) {
  1227 + recordInfoXml.append("<Secrecy> "+ secrecy + " </Secrecy>\r\n");
  1228 + }
  1229 + if (type != null) {
  1230 + // 大华NVR要求必须增加一个值为all的文本元素节点Type
  1231 + recordInfoXml.append("<Type>" + type+"</Type>\r\n");
  1232 + }
1219 1233 recordInfoXml.append("</Query>\r\n");
1220 1234  
1221 1235 String tm = Long.toString(System.currentTimeMillis());
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
1 1 package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
2 2  
3   -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
4   -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
5   -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
6   -import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
  3 +import com.genersoft.iot.vmp.gb28181.bean.*;
7 4 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
8 5 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
9 6 import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderPlarformProvider;
  7 +import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
10 8 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
11 9 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
12 10 import org.slf4j.Logger;
... ... @@ -17,6 +15,7 @@ import org.springframework.context.annotation.DependsOn;
17 15 import org.springframework.context.annotation.Lazy;
18 16 import org.springframework.lang.Nullable;
19 17 import org.springframework.stereotype.Component;
  18 +import org.springframework.util.StringUtils;
20 19  
21 20 import javax.sip.*;
22 21 import javax.sip.header.CallIdHeader;
... ... @@ -91,7 +90,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
91 90  
92 91 sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (event)->{
93 92 if (event != null) {
94   - logger.info("向上级平台 [ {} ] 注册发错误: {} ",
  93 + logger.info("向上级平台 [ {} ] 注册发错误: {} ",
95 94 parentPlatform.getServerGBId(),
96 95 event.msg);
97 96 }
... ... @@ -496,5 +495,52 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
496 495 catalogXml.append("</Notify>\r\n");
497 496 return catalogXml.toString();
498 497 }
  498 + @Override
  499 + public boolean recordInfo(DeviceChannel deviceChannel, ParentPlatform parentPlatform, String fromTag, RecordInfo recordInfo) {
  500 + if ( parentPlatform ==null) {
  501 + return false;
  502 + }
  503 + try {
  504 + StringBuffer recordXml = new StringBuffer(600);
  505 + recordXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
  506 + recordXml.append("<Response>\r\n");
  507 + recordXml.append("<CmdType>RecordInfo</CmdType>\r\n");
  508 + recordXml.append("<SN>" +recordInfo.getSn() + "</SN>\r\n");
  509 + recordXml.append("<DeviceID>" + recordInfo.getDeviceId() + "</DeviceID>\r\n");
  510 + recordXml.append("<SumNum>" + recordInfo.getSumNum() + "</SumNum>\r\n");
  511 + recordXml.append("<RecordList Num=\"" + recordInfo.getRecordList().size()+"\">\r\n");
  512 + for (RecordItem recordItem : recordInfo.getRecordList()) {
  513 + recordXml.append("<Item>\r\n");
  514 + if (deviceChannel != null) {
  515 + recordXml.append("<DeviceID>" + recordItem.getDeviceId() + "</DeviceID>\r\n");
  516 + recordXml.append("<Name>" + recordItem.getName() + "</Name>\r\n");
  517 + recordXml.append("<StartTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(recordItem.getStartTime()) + "</StartTime>\r\n");
  518 + recordXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(recordItem.getEndTime()) + "</EndTime>\r\n");
  519 + recordXml.append("<Secrecy>" + recordItem.getSecrecy() + "</Secrecy>\r\n");
  520 + recordXml.append("<Type>" + recordItem.getType() + "</Type>\r\n");
  521 + if (!StringUtils.isEmpty(recordItem.getFileSize())) {
  522 + recordXml.append("<FileSize>" + recordItem.getFileSize() + "</FileSize>\r\n");
  523 + }
  524 + if (!StringUtils.isEmpty(recordItem.getFilePath())) {
  525 + recordXml.append("<FilePath>" + recordItem.getFilePath() + "</FilePath>\r\n");
  526 + }
  527 + }
  528 + recordXml.append("</Item>\r\n");
  529 + }
499 530  
  531 + recordXml.append("</RecordList>\r\n");
  532 + recordXml.append("</Response>\r\n");
  533 +
  534 + // callid
  535 + CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
  536 + : udpSipProvider.getNewCallId();
  537 + Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, recordXml.toString(), fromTag, callIdHeader);
  538 + transmitRequest(parentPlatform, request);
  539 +
  540 + } catch (SipException | ParseException | InvalidArgumentException e) {
  541 + e.printStackTrace();
  542 + return false;
  543 + }
  544 + return true;
  545 + }
500 546 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
1 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
2 2  
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
3 5 import com.genersoft.iot.vmp.common.StreamInfo;
4 6 import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
5 7 import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
6 8 import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
7 9 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
  10 +import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
8 11 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
9 12 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
10 13 import com.genersoft.iot.vmp.service.IMediaServerService;
... ... @@ -24,6 +27,8 @@ import javax.sip.header.HeaderAddress;
24 27 import javax.sip.header.ToHeader;
25 28 import java.util.HashMap;
26 29 import java.util.Map;
  30 +import java.util.Timer;
  31 +import java.util.TimerTask;
27 32  
28 33 /**
29 34 * SIP命令类型: ACK请求
... ... @@ -52,6 +57,9 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
52 57 @Autowired
53 58 private IMediaServerService mediaServerService;
54 59  
  60 + @Autowired
  61 + private ZLMHttpHookSubscribe subscribe;
  62 +
55 63  
56 64 /**
57 65 * 处理 ACK请求
... ... @@ -60,6 +68,7 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
60 68 */
61 69 @Override
62 70 public void process(RequestEvent evt) {
  71 + logger.info("ACK请求: {}", ((System.currentTimeMillis())));
63 72 Dialog dialog = evt.getDialog();
64 73 if (dialog == null) return;
65 74 if (dialog.getState()== DialogState.CONFIRMED) {
... ... @@ -69,16 +78,17 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
69 78 String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
70 79 String deviceId = sendRtpItem.getDeviceId();
71 80 StreamInfo streamInfo = null;
72   - if (deviceId == null) {
  81 + if (sendRtpItem.isPlay()) {
  82 + streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
  83 + }else {
  84 + streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, channelId);
  85 + }
  86 + System.out.println(JSON.toJSON(streamInfo));
  87 + if (streamInfo == null) {
73 88 streamInfo = new StreamInfo();
74 89 streamInfo.setApp(sendRtpItem.getApp());
75 90 streamInfo.setStream(sendRtpItem.getStreamId());
76   - }else {
77   - streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
78   - sendRtpItem.setStreamId(streamInfo.getStream());
79   - streamInfo.setApp("rtp");
80 91 }
81   -
82 92 redisCatchStorage.updateSendRTPSever(sendRtpItem);
83 93 logger.info(platformGbId);
84 94 logger.info(channelId);
... ... @@ -90,34 +100,42 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In
90 100 param.put("dst_url",sendRtpItem.getIp());
91 101 param.put("dst_port", sendRtpItem.getPort());
92 102 param.put("is_udp", is_Udp);
93   - //param.put ("src_port", sendRtpItem.getLocalPort());
94 103 // 设备推流查询,成功后才能转推
95   - boolean rtpPushed = false;
96   - long startTime = System.currentTimeMillis();
97   - while (!rtpPushed) {
98   - try {
99   - if (System.currentTimeMillis() - startTime < 30 * 1000) {
100   - MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
101   - if (zlmrtpServerFactory.isStreamReady(mediaInfo, streamInfo.getApp(), streamInfo.getStream())) {
102   - rtpPushed = true;
103   - logger.info("已获取设备推流[{}/{}],开始向上级推流[{}:{}]",
104   - streamInfo.getApp() ,streamInfo.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort());
105   - zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
106   - } else {
107   - logger.info("等待设备推流[{}/{}].......",
108   - streamInfo.getApp() ,streamInfo.getStream());
109   - Thread.sleep(1000);
110   - continue;
111   - }
112   - } else {
113   - rtpPushed = true;
114   - logger.info("设备推流[{}/{}]超时,终止向上级推流",
115   - streamInfo.getApp() ,streamInfo.getStream());
116   - }
117   - } catch (InterruptedException e) {
118   - e.printStackTrace();
119   - }
120   - }
  104 + MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
  105 + zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
  106 +// if (zlmrtpServerFactory.isStreamReady(mediaInfo, streamInfo.getApp(), streamInfo.getStreamId())) {
  107 +// logger.info("已获取设备推流[{}/{}],开始向上级推流[{}:{}]",
  108 +// streamInfo.getApp() ,streamInfo.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort());
  109 +// zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
  110 +// } else {
  111 +// // 对hook进行订阅
  112 +// logger.info("等待设备推流[{}/{}].......",
  113 +// streamInfo.getApp(), streamInfo.getStreamId());
  114 +// Timer timer = new Timer();
  115 +// timer.schedule(new TimerTask() {
  116 +// @Override
  117 +// public void run() {
  118 +// logger.info("设备推流[{}/{}]超时,终止向上级推流",
  119 +// finalStreamInfo.getApp() , finalStreamInfo.getStreamId());
  120 +//
  121 +// }
  122 +// }, 30*1000L);
  123 +// // 添加订阅
  124 +// JSONObject subscribeKey = new JSONObject();
  125 +// subscribeKey.put("app", "rtp");
  126 +// subscribeKey.put("stream", streamInfo.getStreamId());
  127 +// subscribeKey.put("mediaServerId", streamInfo.getMediaServerId());
  128 +// subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, subscribeKey,
  129 +// (MediaServerItem mediaServerItemInUse, JSONObject json) -> {
  130 +// logger.info("已获取设备推流[{}/{}],开始向上级推流[{}:{}]",
  131 +// finalStreamInfo.getApp(), finalStreamInfo.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort());
  132 +// timer.cancel();
  133 +// zlmrtpServerFactory.startSendRtpStream(mediaInfo, param);
  134 +// subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
  135 +// });
  136 +// }
  137 +
  138 +
121 139 }
122 140 }
123 141 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
... ... @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
2 2  
3 3 import com.genersoft.iot.vmp.common.StreamInfo;
4 4 import com.genersoft.iot.vmp.gb28181.bean.Device;
  5 +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
5 6 import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
6 7 import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
7 8 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
... ... @@ -87,22 +88,34 @@ public class ByeRequestProcessor extends SIPRequestProcessorParent implements In
87 88 MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
88 89 zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
89 90 redisCatchStorage.deleteSendRTPServer(platformGbId, channelId);
90   - if (zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId) == 0) {
  91 + int totalReaderCount = zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId);
  92 + if (totalReaderCount == 0) {
91 93 logger.info(streamId + "无其它观看者,通知设备停止推流");
92 94 cmder.streamByeCmd(sendRtpItem.getDeviceId(), channelId, streamId);
  95 + }else if (totalReaderCount == -1){
  96 + logger.warn(streamId + " 查找其它观看者失败");
93 97 }
94 98 }
95 99 // 可能是设备主动停止
96 100 Device device = storager.queryVideoDeviceByChannelId(platformGbId);
97   - if (device != null) {
  101 + if (device != null) {
98 102 StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(device.getDeviceId(), channelId);
  103 + if (sendRtpItem != null) {
  104 + if (sendRtpItem.isPlay()) {
  105 + if (streamInfo != null) {
  106 + redisCatchStorage.stopPlay(streamInfo);
  107 + }
  108 + }else {
  109 + if (streamInfo != null) {
  110 + redisCatchStorage.stopPlayback(streamInfo);
  111 + }
  112 + }
99 113  
100   - if (streamInfo != null) {
101   - redisCatchStorage.stopPlay(streamInfo);
  114 + storager.stopPlay(device.getDeviceId(), channelId);
  115 + mediaServerService.closeRTPServer(device.getDeviceId(), channelId, streamInfo.getStream());
102 116 }
103   - storager.stopPlay(device.getDeviceId(), channelId);
104   - mediaServerService.closeRTPServer(device, channelId, streamInfo.getStream());
105 117 }
  118 +
106 119 }
107 120 } catch (SipException e) {
108 121 e.printStackTrace();
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
1 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
2 2  
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.genersoft.iot.vmp.common.StreamInfo;
3 6 import com.genersoft.iot.vmp.gb28181.bean.*;
  7 +import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
4 8 import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
  9 +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
  10 +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
5 11 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
6 12 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
7 13 import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
8 14 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
  15 +import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
  16 +import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
9 17 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
10 18 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
11 19 import com.genersoft.iot.vmp.service.IMediaServerService;
12 20 import com.genersoft.iot.vmp.service.IPlayService;
  21 +import com.genersoft.iot.vmp.service.bean.SSRCInfo;
13 22 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
14 23 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
15 24 import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
  25 +import gov.nist.javax.sdp.TimeDescriptionImpl;
  26 +import gov.nist.javax.sdp.fields.TimeField;
16 27 import gov.nist.javax.sip.address.AddressImpl;
17 28 import gov.nist.javax.sip.address.SipUri;
18 29 import org.slf4j.Logger;
... ... @@ -27,10 +38,13 @@ import javax.sip.RequestEvent;
27 38 import javax.sip.ServerTransaction;
28 39 import javax.sip.SipException;
29 40 import javax.sip.address.SipURI;
  41 +import javax.sip.header.CallIdHeader;
30 42 import javax.sip.header.FromHeader;
31 43 import javax.sip.message.Request;
32 44 import javax.sip.message.Response;
33 45 import java.text.ParseException;
  46 +import java.text.SimpleDateFormat;
  47 +import java.util.Date;
34 48 import java.util.List;
35 49 import java.util.Vector;
36 50  
... ... @@ -61,6 +75,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
61 75 private IPlayService playService;
62 76  
63 77 @Autowired
  78 + private ISIPCommander commander;
  79 +
  80 + @Autowired
64 81 private ZLMRTPServerFactory zlmrtpServerFactory;
65 82  
66 83 @Autowired
... ... @@ -69,6 +86,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
69 86 @Autowired
70 87 private SIPProcessorObserver sipProcessorObserver;
71 88  
  89 +
72 90 @Override
73 91 public void afterPropertiesSet() throws Exception {
74 92 // 添加消息处理的订阅
... ... @@ -88,22 +106,19 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
88 106 Request request = evt.getRequest();
89 107 SipURI sipURI = (SipURI) request.getRequestURI();
90 108 String channelId = sipURI.getUser();
91   - String requesterId = null;
92   -
93   - FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME);
94   - AddressImpl address = (AddressImpl) fromHeader.getAddress();
95   - SipUri uri = (SipUri) address.getURI();
96   - requesterId = uri.getUser();
97   -
  109 + String requesterId = SipUtils.getUserIdFromFromHeader(request);
  110 + CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME);
98 111 if (requesterId == null || channelId == null) {
99 112 logger.info("无法从FromHeader的Address中获取到平台id,返回400");
100 113 responseAck(evt, Response.BAD_REQUEST); // 参数不全, 发400,请求错误
101 114 return;
102 115 }
103 116  
104   - // 查询请求方是否上级平台
  117 + // 查询请求是否来自上级平台\设备
105 118 ParentPlatform platform = storager.queryParentPlatByServerGBId(requesterId);
106   - if (platform != null) {
  119 + if (platform == null) {
  120 + inviteFromDeviceHandle(evt, requesterId);
  121 + }else {
107 122 // 查询平台下是否有该通道
108 123 DeviceChannel channel = storager.queryChannelInParentPlatform(requesterId, channelId);
109 124 GbStream gbStream = storager.queryStreamInParentPlatform(requesterId, channelId);
... ... @@ -122,7 +137,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
122 137 mediaServerItem = mediaServerService.getOne(mediaServerId);
123 138 if (mediaServerItem == null) {
124 139 logger.info("[ app={}, stream={} ]找不到zlm {},返回410",gbStream.getApp(), gbStream.getStream(), mediaServerId);
125   - responseAck(evt, Response.GONE, "media server not found");
  140 + responseAck(evt, Response.GONE);
126 141 return;
127 142 }
128 143 Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, gbStream.getApp(), gbStream.getStream());
... ... @@ -158,13 +173,26 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
158 173 ssrc = ssrcDefault;
159 174 sdp = SdpFactory.getInstance().createSessionDescription(contentString);
160 175 }
161   -
  176 + String sessionName = sdp.getSessionName().getValue();
  177 +
  178 + Long startTime = null;
  179 + Long stopTime = null;
  180 + Date start = null;
  181 + Date end = null;
  182 + if (sdp.getTimeDescriptions(false) != null && sdp.getTimeDescriptions(false).size() > 0) {
  183 + TimeDescriptionImpl timeDescription = (TimeDescriptionImpl)(sdp.getTimeDescriptions(false).get(0));
  184 + TimeField startTimeFiled = (TimeField)timeDescription.getTime();
  185 + startTime = startTimeFiled.getStartTime();
  186 + stopTime = startTimeFiled.getStopTime();
  187 +
  188 + start = new Date(startTime*1000);
  189 + end = new Date(stopTime*1000);
  190 + }
162 191 // 获取支持的格式
163 192 Vector mediaDescriptions = sdp.getMediaDescriptions(true);
164 193 // 查看是否支持PS 负载96
165 194 //String ip = null;
166 195 int port = -1;
167   - //boolean recvonly = false;
168 196 boolean mediaTransmissionTCP = false;
169 197 Boolean tcpActive = null;
170 198 for (Object description : mediaDescriptions) {
... ... @@ -200,7 +228,6 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
200 228 }
201 229 String username = sdp.getOrigin().getUsername();
202 230 String addressStr = sdp.getOrigin().getAddress();
203   - //String sessionName = sdp.getSessionName().getValue();
204 231 logger.info("[上级点播]用户:{}, 地址:{}:{}, ssrc:{}", username, addressStr, port, ssrc);
205 232 Device device = null;
206 233 // 通过 channel 和 gbStream 是否为null 值判断来源是直播流合适国标
... ... @@ -228,23 +255,33 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
228 255 responseAck(evt, Response.BUSY_HERE);
229 256 return;
230 257 }
231   -
  258 + sendRtpItem.setCallId(callIdHeader.getCallId());
  259 + sendRtpItem.setPlay("Play".equals(sessionName));
232 260 // 写入redis, 超时时回复
233 261 redisCatchStorage.updateSendRTPSever(sendRtpItem);
234   - // 通知下级推流,
235   - PlayResult playResult = playService.play(mediaServerItem,device.getDeviceId(), channelId, (mediaServerItemInUSe, responseJSON)->{
236   - // 收到推流, 回复200OK, 等待ack
237   - // if (sendRtpItem == null) return;
  262 +
  263 + Device finalDevice = device;
  264 + MediaServerItem finalMediaServerItem = mediaServerItem;
  265 + Long finalStartTime = startTime;
  266 + Long finalStopTime = stopTime;
  267 + ZLMHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON)->{
  268 + logger.info("[上级点播]下级已经开始推流。 回复200OK(SDP), {}/{}", sendRtpItem.getApp(), sendRtpItem.getStreamId());
  269 + // * 0 等待设备推流上来
  270 + // * 1 下级已经推流,等待上级平台回复ack
  271 + // * 2 推流中
238 272 sendRtpItem.setStatus(1);
239 273 redisCatchStorage.updateSendRTPSever(sendRtpItem);
240   - // TODO 添加对tcp的支持
241 274  
242 275 StringBuffer content = new StringBuffer(200);
243 276 content.append("v=0\r\n");
244 277 content.append("o="+ channelId +" 0 0 IN IP4 "+mediaServerItemInUSe.getSdpIp()+"\r\n");
245   - content.append("s=Play\r\n");
  278 + content.append("s=" + sessionName+"\r\n");
246 279 content.append("c=IN IP4 "+mediaServerItemInUSe.getSdpIp()+"\r\n");
247   - content.append("t=0 0\r\n");
  280 + if ("Playback".equals(sessionName)) {
  281 + content.append("t=" + finalStartTime + " " + finalStopTime + "\r\n");
  282 + }else {
  283 + content.append("t=0 0\r\n");
  284 + }
248 285 content.append("m=video "+ sendRtpItem.getLocalPort()+" RTP/AVP 96\r\n");
249 286 content.append("a=sendonly\r\n");
250 287 content.append("a=rtpmap:96 PS/90000\r\n");
... ... @@ -260,7 +297,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
260 297 } catch (ParseException e) {
261 298 e.printStackTrace();
262 299 }
263   - } ,((event) -> {
  300 + };
  301 + SipSubscribe.Event errorEvent = ((event) -> {
264 302 // 未知错误。直接转发设备点播的错误
265 303 Response response = null;
266 304 try {
... ... @@ -271,11 +309,46 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
271 309 } catch (ParseException | SipException | InvalidArgumentException e) {
272 310 e.printStackTrace();
273 311 }
274   - }));
275   - if (logger.isDebugEnabled()) {
276   - logger.debug(playResult.getResult().toString());
  312 + });
  313 + if ("Playback".equals(sessionName)) {
  314 + sendRtpItem.setPlay(false);
  315 + sendRtpItem.setStreamId(ssrc);
  316 + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  317 + playService.playBack(device.getDeviceId(), channelId, format.format(start), format.format(end),result -> {
  318 + if (result.getCode() != 0){
  319 + logger.warn("录像回放失败");
  320 + if (result.getEvent() != null) {
  321 + errorEvent.response(result.getEvent());
  322 + }
  323 + try {
  324 + responseAck(evt, Response.REQUEST_TIMEOUT);
  325 + } catch (SipException e) {
  326 + e.printStackTrace();
  327 + } catch (InvalidArgumentException e) {
  328 + e.printStackTrace();
  329 + } catch (ParseException e) {
  330 + e.printStackTrace();
  331 + }
  332 + }else {
  333 + if (result.getMediaServerItem() != null) {
  334 + hookEvent.response(result.getMediaServerItem(), result.getResponse());
  335 + }
  336 + }
  337 + });
  338 + }else {
  339 + sendRtpItem.setPlay(true);
  340 + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(device.getDeviceId(), channelId);
  341 + if (streamInfo == null) {
  342 + if (mediaServerItem.isRtpEnable()) {
  343 + sendRtpItem.setStreamId(String.format("%s_%s", device.getDeviceId(), channelId));
  344 + }
  345 + sendRtpItem.setPlay(false);
  346 + playService.play(mediaServerItem,device.getDeviceId(), channelId, hookEvent,errorEvent);
  347 + }else {
  348 + sendRtpItem.setStreamId(streamInfo.getStream());
  349 + hookEvent.response(mediaServerItem, null);
  350 + }
277 351 }
278   -
279 352 }else if (gbStream != null) {
280 353 SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
281 354 gbStream.getApp(), gbStream.getStream(), channelId,
... ... @@ -295,7 +368,6 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
295 368  
296 369 sendRtpItem.setStatus(1);
297 370 redisCatchStorage.updateSendRTPSever(sendRtpItem);
298   - // TODO 添加对tcp的支持
299 371 StringBuffer content = new StringBuffer(200);
300 372 content.append("v=0\r\n");
301 373 content.append("o="+ channelId +" 0 0 IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
... ... @@ -319,72 +391,6 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
319 391 }
320 392 }
321 393  
322   - } else {
323   - // 非上级平台请求,查询是否设备请求(通常为接收语音广播的设备)
324   - Device device = redisCatchStorage.getDevice(requesterId);
325   - if (device != null) {
326   - logger.info("收到设备" + requesterId + "的语音广播Invite请求");
327   - responseAck(evt, Response.TRYING);
328   -
329   - String contentString = new String(request.getRawContent());
330   - // jainSip不支持y=字段, 移除移除以解析。
331   - String substring = contentString;
332   - String ssrc = "0000000404";
333   - int ssrcIndex = contentString.indexOf("y=");
334   - if (ssrcIndex > 0) {
335   - substring = contentString.substring(0, ssrcIndex);
336   - ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
337   - }
338   - ssrcIndex = substring.indexOf("f=");
339   - if (ssrcIndex > 0) {
340   - substring = contentString.substring(0, ssrcIndex);
341   - }
342   - SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
343   -
344   - // 获取支持的格式
345   - Vector mediaDescriptions = sdp.getMediaDescriptions(true);
346   - // 查看是否支持PS 负载96
347   - int port = -1;
348   - //boolean recvonly = false;
349   - boolean mediaTransmissionTCP = false;
350   - Boolean tcpActive = null;
351   - for (int i = 0; i < mediaDescriptions.size(); i++) {
352   - MediaDescription mediaDescription = (MediaDescription)mediaDescriptions.get(i);
353   - Media media = mediaDescription.getMedia();
354   -
355   - Vector mediaFormats = media.getMediaFormats(false);
356   - if (mediaFormats.contains("8")) {
357   - port = media.getMediaPort();
358   - String protocol = media.getProtocol();
359   - // 区分TCP发流还是udp, 当前默认udp
360   - if ("TCP/RTP/AVP".equals(protocol)) {
361   - String setup = mediaDescription.getAttribute("setup");
362   - if (setup != null) {
363   - mediaTransmissionTCP = true;
364   - if ("active".equals(setup)) {
365   - tcpActive = true;
366   - } else if ("passive".equals(setup)) {
367   - tcpActive = false;
368   - }
369   - }
370   - }
371   - break;
372   - }
373   - }
374   - if (port == -1) {
375   - logger.info("不支持的媒体格式,返回415");
376   - // 回复不支持的格式
377   - responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415
378   - return;
379   - }
380   - String username = sdp.getOrigin().getUsername();
381   - String addressStr = sdp.getOrigin().getAddress();
382   - logger.info("设备{}请求语音流,地址:{}:{},ssrc:{}", username, addressStr, port, ssrc);
383   -
384   - } else {
385   - logger.warn("来自无效设备/平台的请求");
386   - responseAck(evt, Response.BAD_REQUEST);
387   - }
388 394 }
389 395  
390 396 } catch (SipException | InvalidArgumentException | ParseException e) {
... ... @@ -397,4 +403,74 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
397 403 e.printStackTrace();
398 404 }
399 405 }
  406 +
  407 + public void inviteFromDeviceHandle(RequestEvent evt, String requesterId) throws InvalidArgumentException, ParseException, SipException, SdpException {
  408 +
  409 + // 非上级平台请求,查询是否设备请求(通常为接收语音广播的设备)
  410 + Device device = redisCatchStorage.getDevice(requesterId);
  411 + Request request = evt.getRequest();
  412 + if (device != null) {
  413 + logger.info("收到设备" + requesterId + "的语音广播Invite请求");
  414 + responseAck(evt, Response.TRYING);
  415 +
  416 + String contentString = new String(request.getRawContent());
  417 + // jainSip不支持y=字段, 移除移除以解析。
  418 + String substring = contentString;
  419 + String ssrc = "0000000404";
  420 + int ssrcIndex = contentString.indexOf("y=");
  421 + if (ssrcIndex > 0) {
  422 + substring = contentString.substring(0, ssrcIndex);
  423 + ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
  424 + }
  425 + ssrcIndex = substring.indexOf("f=");
  426 + if (ssrcIndex > 0) {
  427 + substring = contentString.substring(0, ssrcIndex);
  428 + }
  429 + SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
  430 +
  431 + // 获取支持的格式
  432 + Vector mediaDescriptions = sdp.getMediaDescriptions(true);
  433 + // 查看是否支持PS 负载96
  434 + int port = -1;
  435 + //boolean recvonly = false;
  436 + boolean mediaTransmissionTCP = false;
  437 + Boolean tcpActive = null;
  438 + for (int i = 0; i < mediaDescriptions.size(); i++) {
  439 + MediaDescription mediaDescription = (MediaDescription)mediaDescriptions.get(i);
  440 + Media media = mediaDescription.getMedia();
  441 +
  442 + Vector mediaFormats = media.getMediaFormats(false);
  443 + if (mediaFormats.contains("8")) {
  444 + port = media.getMediaPort();
  445 + String protocol = media.getProtocol();
  446 + // 区分TCP发流还是udp, 当前默认udp
  447 + if ("TCP/RTP/AVP".equals(protocol)) {
  448 + String setup = mediaDescription.getAttribute("setup");
  449 + if (setup != null) {
  450 + mediaTransmissionTCP = true;
  451 + if ("active".equals(setup)) {
  452 + tcpActive = true;
  453 + } else if ("passive".equals(setup)) {
  454 + tcpActive = false;
  455 + }
  456 + }
  457 + }
  458 + break;
  459 + }
  460 + }
  461 + if (port == -1) {
  462 + logger.info("不支持的媒体格式,返回415");
  463 + // 回复不支持的格式
  464 + responseAck(evt, Response.UNSUPPORTED_MEDIA_TYPE); // 不支持的格式,发415
  465 + return;
  466 + }
  467 + String username = sdp.getOrigin().getUsername();
  468 + String addressStr = sdp.getOrigin().getAddress();
  469 + logger.info("设备{}请求语音流,地址:{}:{},ssrc:{}", username, addressStr, port, ssrc);
  470 +
  471 + } else {
  472 + logger.warn("来自无效设备/平台的请求");
  473 + responseAck(evt, Response.BAD_REQUEST);
  474 + }
  475 + }
400 476 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/RecordInfoQueryMessageHandler.java
... ... @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.
3 3 import com.genersoft.iot.vmp.conf.SipConfig;
4 4 import com.genersoft.iot.vmp.gb28181.bean.*;
5 5 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
  6 +import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEventListener;
6 7 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
7 8 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
8 9 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
... ... @@ -47,6 +48,9 @@ public class RecordInfoQueryMessageHandler extends SIPRequestProcessorParent imp
47 48 private SIPCommander commander;
48 49  
49 50 @Autowired
  51 + private RecordEndEventListener recordEndEventListener;
  52 +
  53 + @Autowired
50 54 private SipConfig config;
51 55  
52 56 @Autowired
... ... @@ -65,49 +69,89 @@ public class RecordInfoQueryMessageHandler extends SIPRequestProcessorParent imp
65 69 @Override
66 70 public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) {
67 71  
68   - String key = DeferredResultHolder.CALLBACK_CMD_CATALOG + parentPlatform.getServerGBId();
69 72 FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
70   - try {
71   - // 回复200 OK
72   - responseAck(evt, Response.OK);
73   - Element snElement = rootElement.element("SN");
74   - int sn = Integer.parseInt(snElement.getText());
75   - Element deviceIDElement = rootElement.element("DeviceID");
76   - String channelId = deviceIDElement.getText();
77   - Element startTimeElement = rootElement.element("StartTime");
78   - String startTime = startTimeElement.getText();
79   - Element endTimeElement = rootElement.element("EndTime");
80   - String endTime = endTimeElement.getText();
81   - Element secrecyElement = rootElement.element("Secrecy");
82   - int secrecy = Integer.parseInt(secrecyElement.getText());
83   - Element typeElement = rootElement.element("Type");
84   - String type = typeElement.getText();
85   - // 确认是直播还是国标, 国标直接请求下级,直播请求录像管理服务
86   - List<ChannelSourceInfo> channelSources = storager.getChannelSource(parentPlatform.getServerGBId(), channelId);
87   - if (channelSources.get(0).getCount() > 0) { // 国标
88   - // 向国标设备请求录像数据
89   - Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId);
90   - commander.recordInfoQuery(device, channelId, DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(startTime),
91   - DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(endTime), sn, secrecy, type, (eventResult -> {
92   - // 查询成功
93   -
94   - }),(eventResult -> {
95   - // 查询失败
96   -
97   - }));
98   -
99   - }else if (channelSources.get(0).getCount() > 0) { // 直播流
100   - // TODO
101   - }else { // 错误的请求
102 73  
  74 + Element snElement = rootElement.element("SN");
  75 + int sn = Integer.parseInt(snElement.getText());
  76 + Element deviceIDElement = rootElement.element("DeviceID");
  77 + String channelId = deviceIDElement.getText();
  78 + Element startTimeElement = rootElement.element("StartTime");
  79 + String startTime = null;
  80 + if (startTimeElement != null) {
  81 + startTime = startTimeElement.getText();
  82 + }
  83 + Element endTimeElement = rootElement.element("EndTime");
  84 + String endTime = null;
  85 + if (endTimeElement != null) {
  86 + endTime = endTimeElement.getText();
  87 + }
  88 + Element secrecyElement = rootElement.element("Secrecy");
  89 + int secrecy = 0;
  90 + if (secrecyElement != null) {
  91 + secrecy = Integer.parseInt(secrecyElement.getText());
  92 + }
  93 + String type = "all";
  94 + Element typeElement = rootElement.element("Type");
  95 + if (typeElement != null) {
  96 + type = typeElement.getText();
  97 + }
  98 + // 确认是直播还是国标, 国标直接请求下级,直播请求录像管理服务
  99 + List<ChannelSourceInfo> channelSources = storager.getChannelSource(parentPlatform.getServerGBId(), channelId);
  100 +
  101 + if (channelSources.get(0).getCount() > 0) { // 国标
  102 + // 向国标设备请求录像数据
  103 + Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId);
  104 + DeviceChannel deviceChannel = storager.queryChannelInParentPlatform(parentPlatform.getServerGBId(), channelId);
  105 + // 接收录像数据
  106 + recordEndEventListener.addEndEventHandler(deviceChannel.getDeviceId(), channelId, (recordInfo)->{
  107 + cmderFroPlatform.recordInfo(deviceChannel, parentPlatform, fromHeader.getTag(), recordInfo);
  108 + });
  109 + commander.recordInfoQuery(device, channelId, DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(startTime),
  110 + DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(endTime), sn, secrecy, type, (eventResult -> {
  111 + // 回复200 OK
  112 + try {
  113 + responseAck(evt, Response.OK);
  114 + } catch (SipException e) {
  115 + e.printStackTrace();
  116 + } catch (InvalidArgumentException e) {
  117 + e.printStackTrace();
  118 + } catch (ParseException e) {
  119 + e.printStackTrace();
  120 + }
  121 + }),(eventResult -> {
  122 + // 查询失败
  123 + try {
  124 + responseAck(evt, eventResult.statusCode, eventResult.msg);
  125 + } catch (SipException e) {
  126 + e.printStackTrace();
  127 + } catch (InvalidArgumentException e) {
  128 + e.printStackTrace();
  129 + } catch (ParseException e) {
  130 + e.printStackTrace();
  131 + }
  132 + }));
  133 +
  134 + }else if (channelSources.get(1).getCount() > 0) { // 直播流
  135 + // TODO
  136 + try {
  137 + responseAck(evt, Response.NOT_IMPLEMENTED); // 回复未实现
  138 + } catch (SipException e) {
  139 + e.printStackTrace();
  140 + } catch (InvalidArgumentException e) {
  141 + e.printStackTrace();
  142 + } catch (ParseException e) {
  143 + e.printStackTrace();
  144 + }
  145 + }else { // 错误的请求
  146 + try {
  147 + responseAck(evt, Response.BAD_REQUEST);
  148 + } catch (SipException e) {
  149 + e.printStackTrace();
  150 + } catch (InvalidArgumentException e) {
  151 + e.printStackTrace();
  152 + } catch (ParseException e) {
  153 + e.printStackTrace();
103 154 }
104   - } catch (SipException e) {
105   - e.printStackTrace();
106   - } catch (InvalidArgumentException e) {
107   - e.printStackTrace();
108   - } catch (ParseException e) {
109   - e.printStackTrace();
110 155 }
111   -
112 156 }
113 157 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java
... ... @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Device;
4 4 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
5 5 import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
6 6 import com.genersoft.iot.vmp.gb28181.bean.RecordItem;
  7 +import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
7 8 import com.genersoft.iot.vmp.gb28181.transmit.callback.CheckForAllRecordsThread;
8 9 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
9 10 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
... ... @@ -49,6 +50,9 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent
49 50 @Autowired
50 51 private DeferredResultHolder deferredResultHolder;
51 52  
  53 + @Autowired
  54 + private EventPublisher eventPublisher;
  55 +
52 56 @Override
53 57 public void afterPropertiesSet() throws Exception {
54 58 responseMessageHandler.addHandler(cmdType, this);
... ... @@ -77,6 +81,7 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent
77 81 Element recordListElement = rootElement.element("RecordList");
78 82 if (recordListElement == null || recordInfo.getSumNum() == 0) {
79 83 logger.info("无录像数据");
  84 + eventPublisher.recordEndEventPush(recordInfo);
80 85 RequestMessage msg = new RequestMessage();
81 86 msg.setKey(key);
82 87 msg.setData(recordInfo);
... ... @@ -99,6 +104,7 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent
99 104 record.setDeviceId(getText(itemRecord, "DeviceID"));
100 105 record.setName(getText(itemRecord, "Name"));
101 106 record.setFilePath(getText(itemRecord, "FilePath"));
  107 + record.setFileSize(getText(itemRecord, "FileSize"));
102 108 record.setAddress(getText(itemRecord, "Address"));
103 109 record.setStartTime(
104 110 DateUtil.ISO8601Toyyyy_MM_dd_HH_mm_ss(getText(itemRecord, "StartTime")));
... ... @@ -112,7 +118,7 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent
112 118 }
113 119 recordInfo.setRecordList(recordList);
114 120 }
115   -
  121 + eventPublisher.recordEndEventPush(recordInfo);
116 122 // 改用单独线程统计已获取录像文件数量,避免多包并行分别统计不完整的问题
117 123 String cacheKey = CACHE_RECORDINFO_KEY + device.getDeviceId() + sn;
118 124 redis.set(cacheKey + "_" + uuid, recordList, 90);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/response/impl/InviteResponseProcessor.java
... ... @@ -82,9 +82,6 @@ public class InviteResponseProcessor extends SIPResponseProcessorAbstract {
82 82 requestURI.setPort(event.getRemotePort());
83 83 reqAck.setRequestURI(requestURI);
84 84 logger.info("向 " + event.getRemoteIpAddress() + ":" + event.getRemotePort() + "回复ack");
85   - SipURI sipURI = (SipURI)dialog.getRemoteParty().getURI();
86   - String deviceId = requestURI.getUser();
87   - String channelId = sipURI.getUser();
88 85  
89 86 dialog.sendAck(reqAck);
90 87  
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
... ... @@ -181,7 +181,7 @@ public class ZLMHttpHookListener {
181 181 @PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8")
182 182 public ResponseEntity<String> onPublish(@RequestBody JSONObject json) {
183 183  
184   - logger.debug("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString());
  184 + logger.info("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString());
185 185 JSONObject ret = new JSONObject();
186 186 ret.put("code", 0);
187 187 ret.put("msg", "success");
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookSubscribe.java
... ... @@ -77,22 +77,23 @@ public class ZLMHttpHookSubscribe {
77 77 if (eventMap == null) {
78 78 return;
79 79 }
80   - Iterator<Map.Entry<JSONObject, Event>> iterator = eventMap.entrySet().iterator();
81   - while (iterator.hasNext()){
82   - Map.Entry<JSONObject, Event> next = iterator.next();
83   - JSONObject key = next.getKey();
84   - Boolean result = null;
85   - for (String s : key.keySet()) {
86   - if (result == null) {
87   - result = key.getString(s).equals(hookResponse.getString(s));
88   - }else {
89   - if (key.getString(s) == null) continue;
90   - result = result && key.getString(s).equals(hookResponse.getString(s));
  80 +
  81 + Set<Map.Entry<JSONObject, Event>> entries = eventMap.entrySet();
  82 + if (entries.size() > 0) {
  83 + for (Map.Entry<JSONObject, Event> entry : entries) {
  84 + JSONObject key = entry.getKey();
  85 + Boolean result = null;
  86 + for (String s : key.keySet()) {
  87 + if (result == null) {
  88 + result = key.getString(s).equals(hookResponse.getString(s));
  89 + }else {
  90 + if (key.getString(s) == null) continue;
  91 + result = result && key.getString(s).equals(hookResponse.getString(s));
  92 + }
  93 + }
  94 + if (null != result && result){
  95 + entries.remove(entry);
91 96 }
92   - }
93   - if (null != result && result){
94   - // TODO 报错未处理
95   - iterator.remove();
96 97 }
97 98 }
98 99 }
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
... ... @@ -242,9 +242,18 @@ public class ZLMRTPServerFactory {
242 242 */
243 243 public int totalReaderCount(MediaServerItem mediaServerItem, String app, String streamId) {
244 244 JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtmp", streamId);
  245 + Integer code = mediaInfo.getInteger("code");
245 246 if (mediaInfo == null) {
246 247 return 0;
247 248 }
  249 + if ( code < 0) {
  250 + logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
  251 + return -1;
  252 + }
  253 + if ( code == 0 && ! mediaInfo.getBoolean("online")) {
  254 + logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
  255 + return -1;
  256 + }
248 257 return mediaInfo.getInteger("totalReaderCount");
249 258 }
250 259  
... ...
src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java
... ... @@ -48,7 +48,7 @@ public interface IMediaServerService {
48 48  
49 49 SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, boolean isPlayback);
50 50  
51   - void closeRTPServer(Device device, String channelId, String ssrc);
  51 + void closeRTPServer(String deviceId, String channelId, String ssrc);
52 52  
53 53 void clearRTPServer(MediaServerItem mediaServerItem);
54 54  
... ...
src/main/java/com/genersoft/iot/vmp/service/bean/PlayBackCallback.java
1 1 package com.genersoft.iot.vmp.service.bean;
2 2  
3 3 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
  4 +import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
4 5  
5 6 public interface PlayBackCallback {
6 7  
7   - void call(RequestMessage msg);
  8 + void call(PlayBackResult<RequestMessage> msg);
8 9  
9 10 }
... ...
src/main/java/com/genersoft/iot/vmp/service/bean/PlayBackResult.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.bean;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
  5 +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
  6 +
  7 +import javax.sip.RequestEvent;
  8 +
  9 +public class PlayBackResult<T> {
  10 + private int code;
  11 + private T data;
  12 + private MediaServerItem mediaServerItem;
  13 + private JSONObject response;
  14 + private SipSubscribe.EventResult event;
  15 +
  16 + public int getCode() {
  17 + return code;
  18 + }
  19 +
  20 + public void setCode(int code) {
  21 + this.code = code;
  22 + }
  23 +
  24 + public T getData() {
  25 + return data;
  26 + }
  27 +
  28 + public void setData(T data) {
  29 + this.data = data;
  30 + }
  31 +
  32 + public MediaServerItem getMediaServerItem() {
  33 + return mediaServerItem;
  34 + }
  35 +
  36 + public void setMediaServerItem(MediaServerItem mediaServerItem) {
  37 + this.mediaServerItem = mediaServerItem;
  38 + }
  39 +
  40 + public JSONObject getResponse() {
  41 + return response;
  42 + }
  43 +
  44 + public void setResponse(JSONObject response) {
  45 + this.response = response;
  46 + }
  47 +
  48 + public SipSubscribe.EventResult getEvent() {
  49 + return event;
  50 + }
  51 +
  52 + public void setEvent(SipSubscribe.EventResult event) {
  53 + this.event = event;
  54 + }
  55 +}
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
... ... @@ -160,16 +160,16 @@ public class MediaServerServiceImpl implements IMediaServerService {
160 160 }
161 161  
162 162 @Override
163   - public void closeRTPServer(Device device, String channelId, String stream) {
164   - String mediaServerId = streamSession.getMediaServerId(device.getDeviceId(), channelId, stream);
165   - String ssrc = streamSession.getSSRC(device.getDeviceId(), channelId, stream);
  163 + public void closeRTPServer(String deviceId, String channelId, String stream) {
  164 + String mediaServerId = streamSession.getMediaServerId(deviceId, channelId, stream);
  165 + String ssrc = streamSession.getSSRC(deviceId, channelId, stream);
166 166 MediaServerItem mediaServerItem = this.getOne(mediaServerId);
167 167 if (mediaServerItem != null) {
168   - String streamId = String.format("%s_%s", device.getDeviceId(), channelId);
  168 + String streamId = String.format("%s_%s", deviceId, channelId);
169 169 zlmrtpServerFactory.closeRTPServer(mediaServerItem, streamId);
170 170 releaseSsrc(mediaServerItem, ssrc);
171 171 }
172   - streamSession.remove(device.getDeviceId(), channelId, stream);
  172 + streamSession.remove(deviceId, channelId, stream);
173 173 }
174 174  
175 175 @Override
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
... ... @@ -17,9 +17,11 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
17 17 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
18 18 import com.genersoft.iot.vmp.service.IMediaServerService;
19 19 import com.genersoft.iot.vmp.service.bean.PlayBackCallback;
  20 +import com.genersoft.iot.vmp.service.bean.PlayBackResult;
20 21 import com.genersoft.iot.vmp.service.bean.SSRCInfo;
21 22 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
22 23 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
  24 +import com.genersoft.iot.vmp.utils.redis.RedisUtil;
23 25 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
24 26 import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
25 27 import com.genersoft.iot.vmp.service.IMediaService;
... ... @@ -54,6 +56,9 @@ public class PlayServiceImpl implements IPlayService {
54 56 private IRedisCatchStorage redisCatchStorage;
55 57  
56 58 @Autowired
  59 + private RedisUtil redis;
  60 +
  61 + @Autowired
57 62 private DeferredResultHolder resultHolder;
58 63  
59 64 @Autowired
... ... @@ -121,7 +126,6 @@ public class PlayServiceImpl implements IPlayService {
121 126 // 点播结束时调用截图接口
122 127 try {
123 128 String classPath = ResourceUtils.getURL("classpath:").getPath();
124   - // System.out.println(classPath);
125 129 // 兼容打包为jar的class路径
126 130 if(classPath.contains("jar")) {
127 131 classPath = classPath.substring(0, classPath.lastIndexOf("."));
... ... @@ -170,7 +174,10 @@ public class PlayServiceImpl implements IPlayService {
170 174 WVPResult wvpResult = new WVPResult();
171 175 wvpResult.setCode(-1);
172 176 // 点播返回sip错误
173   - mediaServerService.closeRTPServer(playResult.getDevice(), channelId, ssrcInfo.getStream());
  177 + mediaServerService.closeRTPServer(playResult.getDevice().getDeviceId(), channelId, ssrcInfo.getStream());
  178 + // 释放ssrc
  179 + mediaServerService.releaseSsrc(mediaServerItem, ssrcInfo.getSsrc());
  180 + streamSession.remove(deviceId, channelId, ssrcInfo.getStream());
174 181 wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg));
175 182 msg.setData(wvpResult);
176 183 resultHolder.invokeAllResult(msg);
... ... @@ -219,7 +226,10 @@ public class PlayServiceImpl implements IPlayService {
219 226 logger.info("收到订阅消息: " + response.toJSONString());
220 227 onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid);
221 228 }, (event) -> {
222   - mediaServerService.closeRTPServer(playResult.getDevice(), channelId, ssrcInfo.getStream());
  229 + mediaServerService.closeRTPServer(playResult.getDevice().getDeviceId(), channelId, ssrcInfo.getStream());
  230 + // 释放ssrc
  231 + mediaServerService.releaseSsrc(mediaServerItem, ssrcInfo.getSsrc());
  232 + streamSession.remove(deviceId, channelId, ssrcInfo.getStream());
223 233 WVPResult wvpResult = new WVPResult();
224 234 wvpResult.setCode(-1);
225 235 wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg));
... ... @@ -233,11 +243,11 @@ public class PlayServiceImpl implements IPlayService {
233 243 }
234 244  
235 245 @Override
236   - public void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) {
  246 + public void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId, String uuid) {
237 247 RequestMessage msg = new RequestMessage();
238 248 msg.setId(uuid);
239 249 msg.setKey(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId);
240   - StreamInfo streamInfo = onPublishHandler(mediaServerItem, resonse, deviceId, channelId);
  250 + StreamInfo streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId);
241 251 if (streamInfo != null) {
242 252 DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
243 253 if (deviceChannel != null) {
... ... @@ -295,9 +305,12 @@ public class PlayServiceImpl implements IPlayService {
295 305 RequestMessage msg = new RequestMessage();
296 306 msg.setId(uuid);
297 307 msg.setKey(key);
  308 + PlayBackResult<RequestMessage> playBackResult = new PlayBackResult<>();
298 309 result.onTimeout(()->{
299 310 msg.setData("回放超时");
300   - callback.call(msg);
  311 + playBackResult.setCode(-1);
  312 + playBackResult.setData(msg);
  313 + callback.call(playBackResult);
301 314 });
302 315 cmder.playbackStreamCmd(newMediaServerItem, ssrcInfo, device, channelId, startTime, endTime, (MediaServerItem mediaServerItem, JSONObject response) -> {
303 316 logger.info("收到订阅消息: " + response.toJSONString());
... ... @@ -305,15 +318,25 @@ public class PlayServiceImpl implements IPlayService {
305 318 if (streamInfo == null) {
306 319 logger.warn("设备回放API调用失败!");
307 320 msg.setData("设备回放API调用失败!");
308   - callback.call(msg);
  321 + playBackResult.setCode(-1);
  322 + playBackResult.setData(msg);
  323 + callback.call(playBackResult);
309 324 return;
310 325 }
311 326 redisCatchStorage.startPlayback(streamInfo);
312 327 msg.setData(JSON.toJSONString(streamInfo));
313   - callback.call(msg);
  328 + playBackResult.setCode(0);
  329 + playBackResult.setData(msg);
  330 + playBackResult.setMediaServerItem(mediaServerItem);
  331 + playBackResult.setResponse(response);
  332 + callback.call(playBackResult);
314 333 }, event -> {
315 334 msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg));
316   - callback.call(msg);
  335 + playBackResult.setCode(-1);
  336 + playBackResult.setData(msg);
  337 + playBackResult.setEvent(event);
  338 + callback.call(playBackResult);
  339 + streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
317 340 });
318 341 return result;
319 342 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java
... ... @@ -88,8 +88,8 @@ public interface ParentPlatformMapper {
88 88 "</script>"})
89 89 int setDefaultCatalog(String platformId, String catalogId);
90 90  
91   - @Select("select 'channel' as name, count(pgc.platformId) count from platform_gb_channel pgc where pgc.platformId=#{platformId} and pgc.channelId =#{gbId} " +
  91 + @Select("select 'channel' as name, count(pgc.platformId) count from platform_gb_channel pgc left join device_channel dc on dc.id = pgc.deviceChannelId where pgc.platformId=#{platformId} and dc.channelId =#{gbId} " +
92 92 "union " +
93   - "select 'stream' as name, count(pgs.platformId) count from platform_gb_stream pgs left join gb_stream gs on pgs.gbStreamId = gs.id where pgs.platformId=#{platformId} and gs.gbId = #{gbId}")
  93 + "select 'stream' as name, count(pgs.platformId) count from platform_gb_stream pgs left join gb_stream gs on pgs.gbStreamId = gs.gbStreamId where pgs.platformId=#{platformId} and gs.gbId = #{gbId}")
94 94 List<ChannelSourceInfo> getChannelSource(String platformId, String gbId);
95 95 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java
... ... @@ -75,7 +75,7 @@ public interface PlatformChannelMapper {
75 75 int delByCatalogId(String id);
76 76  
77 77 @Delete("<script> "+
78   - "DELETE FROM platform_gb_channel WHERE catalogId=#{parentId} AND platformId=#{platformId} AND channelId=#{id}" +
  78 + "DELETE FROM platform_gb_channel WHERE catalogId=#{parentId} AND platformId=#{platformId} AND channelId=#{id}" +
79 79 "</script>")
80 80 int delByCatalogIdAndChannelIdAndPlatformId(PlatformCatalog platformCatalog);
81 81  
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
... ... @@ -141,7 +141,6 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
141 141  
142 142 @Override
143 143 public StreamInfo queryPlayByDevice(String deviceId, String channelId) {
144   -// List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
145 144 List<Object> playLeys = redis.scan(String.format("%S_%s_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX,
146 145 userSetup.getServerId(),
147 146 deviceId,
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
... ... @@ -129,7 +129,6 @@ public class PlayController {
129 129 //Response response = event.getResponse();
130 130 msg.setData(String.format("success"));
131 131 resultHolder.invokeAllResult(msg);
132   - mediaServerService.closeRTPServer(device, channelId, streamInfo.getStream());
133 132 });
134 133  
135 134 if (deviceId != null || channelId != null) {
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java
... ... @@ -77,8 +77,8 @@ public class PlaybackController {
77 77 logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId));
78 78 }
79 79  
80   - DeferredResult<ResponseEntity<String>> result = playService.playBack(deviceId, channelId, startTime, endTime, msg->{
81   - resultHolder.invokeResult(msg);
  80 + DeferredResult<ResponseEntity<String>> result = playService.playBack(deviceId, channelId, startTime, endTime, wvpResult->{
  81 + resultHolder.invokeResult(wvpResult.getData());
82 82 });
83 83  
84 84 return result;
... ...
src/test/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImplTest.java
... ... @@ -50,14 +50,7 @@ class DeviceAlarmServiceImplTest {
50 50 // System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, "1", null,
51 51 // null, null).getSize());
52 52  
53   - System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, null, null,
54   - "2021-01-01 00:00:00", null).getSize());
55 53  
56   - System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, null, null,
57   - null, "2021-04-01 09:00:00").getSize());
58   -
59   - System.out.println(deviceAlarmService.getAllAlarm(0, 10000, "11111111111111111111", null, null, null,
60   - "2021-02-01 01:00:00", "2021-04-01 04:00:00").getSize());
61 54 }
62 55  
63 56  
... ...