Commit 3d83775468dc9dd69a52332ba566f7e07e931325
1 parent
00e61d9a
存储部分使用sqlite代替redis
Showing
30 changed files
with
932 additions
and
955 deletions
pom.xml
| @@ -99,6 +99,13 @@ | @@ -99,6 +99,13 @@ | ||
| 99 | <version>8.0.22</version> | 99 | <version>8.0.22</version> |
| 100 | </dependency> | 100 | </dependency> |
| 101 | 101 | ||
| 102 | + <!-- 添加sqlite-jdbc数据库驱动 --> | ||
| 103 | + <dependency> | ||
| 104 | + <groupId>org.xerial</groupId> | ||
| 105 | + <artifactId>sqlite-jdbc</artifactId> | ||
| 106 | + <version>3.32.3.2</version> | ||
| 107 | + </dependency> | ||
| 108 | + | ||
| 102 | <!--Mybatis --> | 109 | <!--Mybatis --> |
| 103 | <dependency> | 110 | <dependency> |
| 104 | <groupId>org.mybatis</groupId> | 111 | <groupId>org.mybatis</groupId> |
src/main/java/com/genersoft/iot/vmp/gb28181/SipLayer.java
| @@ -138,16 +138,25 @@ public class SipLayer implements SipListener { | @@ -138,16 +138,25 @@ public class SipLayer implements SipListener { | ||
| 138 | // TODO Auto-generated catch block | 138 | // TODO Auto-generated catch block |
| 139 | e.printStackTrace(); | 139 | e.printStackTrace(); |
| 140 | } | 140 | } |
| 141 | + if (evt.getResponse() != null && sipSubscribe.getOkSubscribesSize() > 0 ) { | ||
| 142 | + CallIdHeader callIdHeader = (CallIdHeader)evt.getResponse().getHeader(CallIdHeader.NAME); | ||
| 143 | + if (callIdHeader != null) { | ||
| 144 | + SipSubscribe.Event subscribe = sipSubscribe.getOkSubscribe(callIdHeader.getCallId()); | ||
| 145 | + if (subscribe != null) { | ||
| 146 | + subscribe.response(evt); | ||
| 147 | + } | ||
| 148 | + } | ||
| 149 | + } | ||
| 141 | // } else if (status == Response.TRYING) { | 150 | // } else if (status == Response.TRYING) { |
| 142 | // trying不会回复 | 151 | // trying不会回复 |
| 143 | } else if ((status >= 100) && (status < 200)) { | 152 | } else if ((status >= 100) && (status < 200)) { |
| 144 | // 增加其它无需回复的响应,如101、180等 | 153 | // 增加其它无需回复的响应,如101、180等 |
| 145 | } else { | 154 | } else { |
| 146 | logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/); | 155 | logger.warn("接收到失败的response响应!status:" + status + ",message:" + response.getReasonPhrase()/* .getContent().toString()*/); |
| 147 | - if (evt.getResponse() != null && sipSubscribe.getSize() > 0 ) { | 156 | + if (evt.getResponse() != null && sipSubscribe.getErrorSubscribesSize() > 0 ) { |
| 148 | CallIdHeader callIdHeader = (CallIdHeader)evt.getResponse().getHeader(CallIdHeader.NAME); | 157 | CallIdHeader callIdHeader = (CallIdHeader)evt.getResponse().getHeader(CallIdHeader.NAME); |
| 149 | if (callIdHeader != null) { | 158 | if (callIdHeader != null) { |
| 150 | - SipSubscribe.Event subscribe = sipSubscribe.getSubscribe(callIdHeader.getCallId()); | 159 | + SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()); |
| 151 | if (subscribe != null) { | 160 | if (subscribe != null) { |
| 152 | subscribe.response(evt); | 161 | subscribe.response(evt); |
| 153 | } | 162 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java
| 1 | package com.genersoft.iot.vmp.gb28181.bean; | 1 | package com.genersoft.iot.vmp.gb28181.bean; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | +import java.util.Date; | ||
| 4 | import java.util.List; | 5 | import java.util.List; |
| 5 | import java.util.Map; | 6 | import java.util.Map; |
| 6 | 7 | ||
| 7 | public class Device { | 8 | public class Device { |
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| 11 | + * 数据库存储ID | ||
| 12 | + */ | ||
| 13 | + private int id; | ||
| 14 | + | ||
| 15 | + /** | ||
| 10 | * 设备Id | 16 | * 设备Id |
| 11 | */ | 17 | */ |
| 12 | private String deviceId; | 18 | private String deviceId; |
| @@ -55,14 +61,24 @@ public class Device { | @@ -55,14 +61,24 @@ public class Device { | ||
| 55 | */ | 61 | */ |
| 56 | private int online; | 62 | private int online; |
| 57 | 63 | ||
| 64 | + | ||
| 58 | /** | 65 | /** |
| 59 | - * 通道列表 | 66 | + * 注册时间 |
| 60 | */ | 67 | */ |
| 61 | -// private Map<String,DeviceChannel> channelMap; | 68 | + private Long registerTimeMillis; |
| 62 | 69 | ||
| 70 | + /** | ||
| 71 | + * 通道个数 | ||
| 72 | + */ | ||
| 63 | private int channelCount; | 73 | private int channelCount; |
| 64 | 74 | ||
| 65 | - private List<String> channelList; | 75 | + public int getId() { |
| 76 | + return id; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + public void setId(int id) { | ||
| 80 | + this.id = id; | ||
| 81 | + } | ||
| 66 | 82 | ||
| 67 | public String getDeviceId() { | 83 | public String getDeviceId() { |
| 68 | return deviceId; | 84 | return deviceId; |
| @@ -144,11 +160,11 @@ public class Device { | @@ -144,11 +160,11 @@ public class Device { | ||
| 144 | this.channelCount = channelCount; | 160 | this.channelCount = channelCount; |
| 145 | } | 161 | } |
| 146 | 162 | ||
| 147 | - public List<String> getChannelList() { | ||
| 148 | - return channelList; | 163 | + public Long getRegisterTimeMillis() { |
| 164 | + return registerTimeMillis; | ||
| 149 | } | 165 | } |
| 150 | 166 | ||
| 151 | - public void setChannelList(List<String> channelList) { | ||
| 152 | - this.channelList = channelList; | 167 | + public void setRegisterTimeMillis(Long registerTimeMillis) { |
| 168 | + this.registerTimeMillis = registerTimeMillis; | ||
| 153 | } | 169 | } |
| 154 | } | 170 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java
| @@ -2,10 +2,17 @@ package com.genersoft.iot.vmp.gb28181.bean; | @@ -2,10 +2,17 @@ package com.genersoft.iot.vmp.gb28181.bean; | ||
| 2 | 2 | ||
| 3 | public class DeviceChannel { | 3 | public class DeviceChannel { |
| 4 | 4 | ||
| 5 | + | ||
| 6 | + | ||
| 5 | /** | 7 | /** |
| 6 | * 通道id | 8 | * 通道id |
| 7 | */ | 9 | */ |
| 8 | private String channelId; | 10 | private String channelId; |
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 设备id | ||
| 14 | + */ | ||
| 15 | + private String deviceId; | ||
| 9 | 16 | ||
| 10 | /** | 17 | /** |
| 11 | * 通道名 | 18 | * 通道名 |
| @@ -146,13 +153,15 @@ public class DeviceChannel { | @@ -146,13 +153,15 @@ public class DeviceChannel { | ||
| 146 | /** | 153 | /** |
| 147 | * 是否含有音频 | 154 | * 是否含有音频 |
| 148 | */ | 155 | */ |
| 149 | - private boolean hasAudio; | 156 | + private boolean hasAudio; |
| 150 | 157 | ||
| 151 | - /** | ||
| 152 | - * 是否正在播放 | ||
| 153 | - */ | ||
| 154 | - private boolean play; | 158 | + public String getDeviceId() { |
| 159 | + return deviceId; | ||
| 160 | + } | ||
| 155 | 161 | ||
| 162 | + public void setDeviceId(String deviceId) { | ||
| 163 | + this.deviceId = deviceId; | ||
| 164 | + } | ||
| 156 | 165 | ||
| 157 | public void setPTZType(int PTZType) { | 166 | public void setPTZType(int PTZType) { |
| 158 | this.PTZType = PTZType; | 167 | this.PTZType = PTZType; |
| @@ -387,14 +396,6 @@ public class DeviceChannel { | @@ -387,14 +396,6 @@ public class DeviceChannel { | ||
| 387 | this.hasAudio = hasAudio; | 396 | this.hasAudio = hasAudio; |
| 388 | } | 397 | } |
| 389 | 398 | ||
| 390 | - public boolean isPlay() { | ||
| 391 | - return play; | ||
| 392 | - } | ||
| 393 | - | ||
| 394 | - public void setPlay(boolean play) { | ||
| 395 | - this.play = play; | ||
| 396 | - } | ||
| 397 | - | ||
| 398 | public String getStreamId() { | 399 | public String getStreamId() { |
| 399 | return streamId; | 400 | return streamId; |
| 400 | } | 401 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java
| @@ -17,21 +17,34 @@ public class SipSubscribe { | @@ -17,21 +17,34 @@ public class SipSubscribe { | ||
| 17 | 17 | ||
| 18 | private final static Logger logger = LoggerFactory.getLogger(SipSubscribe.class); | 18 | private final static Logger logger = LoggerFactory.getLogger(SipSubscribe.class); |
| 19 | 19 | ||
| 20 | - private Map<String, SipSubscribe.Event> allSubscribes = new ConcurrentHashMap<>(); | 20 | + private Map<String, SipSubscribe.Event> errorSubscribes = new ConcurrentHashMap<>(); |
| 21 | + | ||
| 22 | + private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>(); | ||
| 21 | 23 | ||
| 22 | public interface Event { | 24 | public interface Event { |
| 23 | void response(ResponseEvent event); | 25 | void response(ResponseEvent event); |
| 24 | } | 26 | } |
| 25 | 27 | ||
| 26 | - public void addSubscribe(String key, SipSubscribe.Event event) { | ||
| 27 | - allSubscribes.put(key, event); | 28 | + public void addErrorSubscribe(String key, SipSubscribe.Event event) { |
| 29 | + errorSubscribes.put(key, event); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void addOkSubscribe(String key, SipSubscribe.Event event) { | ||
| 33 | + okSubscribes.put(key, event); | ||
| 28 | } | 34 | } |
| 29 | 35 | ||
| 30 | - public SipSubscribe.Event getSubscribe(String key) { | ||
| 31 | - return allSubscribes.get(key); | 36 | + public SipSubscribe.Event getErrorSubscribe(String key) { |
| 37 | + return errorSubscribes.get(key); | ||
| 32 | } | 38 | } |
| 33 | 39 | ||
| 34 | - public int getSize(){ | ||
| 35 | - return allSubscribes.size(); | 40 | + public SipSubscribe.Event getOkSubscribe(String key) { |
| 41 | + return okSubscribes.get(key); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public int getErrorSubscribesSize(){ | ||
| 45 | + return errorSubscribes.size(); | ||
| 46 | + } | ||
| 47 | + public int getOkSubscribesSize(){ | ||
| 48 | + return okSubscribes.size(); | ||
| 36 | } | 49 | } |
| 37 | } | 50 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
| @@ -4,13 +4,10 @@ import javax.sip.RequestEvent; | @@ -4,13 +4,10 @@ import javax.sip.RequestEvent; | ||
| 4 | import javax.sip.ResponseEvent; | 4 | import javax.sip.ResponseEvent; |
| 5 | import javax.sip.SipProvider; | 5 | import javax.sip.SipProvider; |
| 6 | import javax.sip.header.CSeqHeader; | 6 | import javax.sip.header.CSeqHeader; |
| 7 | -import javax.sip.header.CallIdHeader; | ||
| 8 | -import javax.sip.header.Header; | ||
| 9 | import javax.sip.message.Request; | 7 | import javax.sip.message.Request; |
| 10 | import javax.sip.message.Response; | 8 | import javax.sip.message.Response; |
| 11 | 9 | ||
| 12 | -import com.alibaba.fastjson.JSON; | ||
| 13 | -import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; | 10 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 14 | import org.slf4j.Logger; | 11 | import org.slf4j.Logger; |
| 15 | import org.slf4j.LoggerFactory; | 12 | import org.slf4j.LoggerFactory; |
| 16 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -59,6 +56,9 @@ public class SIPProcessorFactory { | @@ -59,6 +56,9 @@ public class SIPProcessorFactory { | ||
| 59 | 56 | ||
| 60 | @Autowired | 57 | @Autowired |
| 61 | private IVideoManagerStorager storager; | 58 | private IVideoManagerStorager storager; |
| 59 | + | ||
| 60 | + @Autowired | ||
| 61 | + private IRedisCatchStorage redisCatchStorage; | ||
| 62 | 62 | ||
| 63 | @Autowired | 63 | @Autowired |
| 64 | private EventPublisher publisher; | 64 | private EventPublisher publisher; |
| @@ -143,6 +143,7 @@ public class SIPProcessorFactory { | @@ -143,6 +143,7 @@ public class SIPProcessorFactory { | ||
| 143 | processor.setOffLineDetector(offLineDetector); | 143 | processor.setOffLineDetector(offLineDetector); |
| 144 | processor.setCmder(cmder); | 144 | processor.setCmder(cmder); |
| 145 | processor.setStorager(storager); | 145 | processor.setStorager(storager); |
| 146 | + processor.setRedisCatchStorage(redisCatchStorage); | ||
| 146 | return processor; | 147 | return processor; |
| 147 | } else { | 148 | } else { |
| 148 | return new OtherRequestProcessor(); | 149 | return new OtherRequestProcessor(); |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
| @@ -25,6 +25,8 @@ public class DeferredResultHolder { | @@ -25,6 +25,8 @@ public class DeferredResultHolder { | ||
| 25 | 25 | ||
| 26 | public static final String CALLBACK_CMD_PlAY = "CALLBACK_PLAY"; | 26 | public static final String CALLBACK_CMD_PlAY = "CALLBACK_PLAY"; |
| 27 | 27 | ||
| 28 | + public static final String CALLBACK_CMD_STOP = "CALLBACK_STOP"; | ||
| 29 | + | ||
| 28 | private Map<String, DeferredResult> map = new ConcurrentHashMap<String, DeferredResult>(); | 30 | private Map<String, DeferredResult> map = new ConcurrentHashMap<String, DeferredResult>(); |
| 29 | 31 | ||
| 30 | public void put(String key, DeferredResult result) { | 32 | public void put(String key, DeferredResult result) { |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
| @@ -101,8 +101,9 @@ public interface ISIPCommander { | @@ -101,8 +101,9 @@ public interface ISIPCommander { | ||
| 101 | * | 101 | * |
| 102 | * @param ssrc ssrc | 102 | * @param ssrc ssrc |
| 103 | */ | 103 | */ |
| 104 | + void streamByeCmd(String ssrc, SipSubscribe.Event okEvent); | ||
| 104 | void streamByeCmd(String ssrc); | 105 | void streamByeCmd(String ssrc); |
| 105 | - | 106 | + |
| 106 | /** | 107 | /** |
| 107 | * 语音广播 | 108 | * 语音广播 |
| 108 | * | 109 | * |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
| 1 | package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; | 1 | package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl; |
| 2 | 2 | ||
| 3 | import java.text.ParseException; | 3 | import java.text.ParseException; |
| 4 | +import java.util.UUID; | ||
| 4 | import java.util.regex.Matcher; | 5 | import java.util.regex.Matcher; |
| 5 | import java.util.regex.Pattern; | 6 | import java.util.regex.Pattern; |
| 6 | 7 | ||
| @@ -12,11 +13,13 @@ import javax.sip.header.ViaHeader; | @@ -12,11 +13,13 @@ import javax.sip.header.ViaHeader; | ||
| 12 | import javax.sip.message.Request; | 13 | import javax.sip.message.Request; |
| 13 | 14 | ||
| 14 | import com.alibaba.fastjson.JSONObject; | 15 | import com.alibaba.fastjson.JSONObject; |
| 16 | +import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 15 | import com.genersoft.iot.vmp.conf.MediaServerConfig; | 17 | import com.genersoft.iot.vmp.conf.MediaServerConfig; |
| 16 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | 18 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 17 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; | 19 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| 18 | import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; | 20 | import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; |
| 19 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; | 21 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 22 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 20 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 23 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 21 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
| 22 | import org.slf4j.LoggerFactory; | 25 | import org.slf4j.LoggerFactory; |
| @@ -53,6 +56,9 @@ public class SIPCommander implements ISIPCommander { | @@ -53,6 +56,9 @@ public class SIPCommander implements ISIPCommander { | ||
| 53 | 56 | ||
| 54 | @Autowired | 57 | @Autowired |
| 55 | private IVideoManagerStorager storager; | 58 | private IVideoManagerStorager storager; |
| 59 | + | ||
| 60 | + @Autowired | ||
| 61 | + private IRedisCatchStorage redisCatchStorage; | ||
| 56 | 62 | ||
| 57 | @Autowired | 63 | @Autowired |
| 58 | @Qualifier(value="tcpSipProvider") | 64 | @Qualifier(value="tcpSipProvider") |
| @@ -229,7 +235,7 @@ public class SIPCommander implements ISIPCommander { | @@ -229,7 +235,7 @@ public class SIPCommander implements ISIPCommander { | ||
| 229 | 235 | ||
| 230 | Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag"); | 236 | Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag"); |
| 231 | 237 | ||
| 232 | - transmitRequest(device, request, null); | 238 | + transmitRequest(device, request); |
| 233 | return true; | 239 | return true; |
| 234 | } catch (SipException | ParseException | InvalidArgumentException e) { | 240 | } catch (SipException | ParseException | InvalidArgumentException e) { |
| 235 | e.printStackTrace(); | 241 | e.printStackTrace(); |
| @@ -264,7 +270,7 @@ public class SIPCommander implements ISIPCommander { | @@ -264,7 +270,7 @@ public class SIPCommander implements ISIPCommander { | ||
| 264 | ptzXml.append("</Control>\r\n"); | 270 | ptzXml.append("</Control>\r\n"); |
| 265 | 271 | ||
| 266 | Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag"); | 272 | Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag"); |
| 267 | - transmitRequest(device, request, null); | 273 | + transmitRequest(device, request); |
| 268 | return true; | 274 | return true; |
| 269 | } catch (SipException | ParseException | InvalidArgumentException e) { | 275 | } catch (SipException | ParseException | InvalidArgumentException e) { |
| 270 | e.printStackTrace(); | 276 | e.printStackTrace(); |
| @@ -291,7 +297,7 @@ public class SIPCommander implements ISIPCommander { | @@ -291,7 +297,7 @@ public class SIPCommander implements ISIPCommander { | ||
| 291 | streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); | 297 | streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); |
| 292 | } | 298 | } |
| 293 | String streamMode = device.getStreamMode().toUpperCase(); | 299 | String streamMode = device.getStreamMode().toUpperCase(); |
| 294 | - MediaServerConfig mediaInfo = storager.getMediaInfo(); | 300 | + MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); |
| 295 | if (mediaInfo == null) { | 301 | if (mediaInfo == null) { |
| 296 | logger.warn("点播时发现ZLM尚未连接..."); | 302 | logger.warn("点播时发现ZLM尚未连接..."); |
| 297 | return; | 303 | return; |
| @@ -344,6 +350,9 @@ public class SIPCommander implements ISIPCommander { | @@ -344,6 +350,9 @@ public class SIPCommander implements ISIPCommander { | ||
| 344 | } | 350 | } |
| 345 | content.append("y="+ssrc+"\r\n");//ssrc | 351 | content.append("y="+ssrc+"\r\n");//ssrc |
| 346 | 352 | ||
| 353 | +// String fromTag = UUID.randomUUID().toString(); | ||
| 354 | +// Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, fromTag, null, ssrc); | ||
| 355 | + | ||
| 347 | Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc); | 356 | Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc); |
| 348 | 357 | ||
| 349 | ClientTransaction transaction = transmitRequest(device, request, errorEvent); | 358 | ClientTransaction transaction = transmitRequest(device, request, errorEvent); |
| @@ -372,7 +381,7 @@ public class SIPCommander implements ISIPCommander { | @@ -372,7 +381,7 @@ public class SIPCommander implements ISIPCommander { | ||
| 372 | public void playbackStreamCmd(Device device, String channelId, String startTime, String endTime, ZLMHttpHookSubscribe.Event event | 381 | public void playbackStreamCmd(Device device, String channelId, String startTime, String endTime, ZLMHttpHookSubscribe.Event event |
| 373 | , SipSubscribe.Event errorEvent) { | 382 | , SipSubscribe.Event errorEvent) { |
| 374 | try { | 383 | try { |
| 375 | - MediaServerConfig mediaInfo = storager.getMediaInfo(); | 384 | + MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); |
| 376 | String ssrc = streamSession.createPlayBackSsrc(); | 385 | String ssrc = streamSession.createPlayBackSsrc(); |
| 377 | String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); | 386 | String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); |
| 378 | // 添加订阅 | 387 | // 添加订阅 |
| @@ -457,17 +466,28 @@ public class SIPCommander implements ISIPCommander { | @@ -457,17 +466,28 @@ public class SIPCommander implements ISIPCommander { | ||
| 457 | e.printStackTrace(); | 466 | e.printStackTrace(); |
| 458 | } | 467 | } |
| 459 | } | 468 | } |
| 460 | - | 469 | + |
| 470 | + | ||
| 471 | + | ||
| 461 | /** | 472 | /** |
| 462 | * 视频流停止 | 473 | * 视频流停止 |
| 463 | * | 474 | * |
| 464 | */ | 475 | */ |
| 465 | @Override | 476 | @Override |
| 466 | - public void streamByeCmd(String streamId) { | 477 | + public void streamByeCmd(String ssrc) { |
| 478 | + streamByeCmd(ssrc, null); | ||
| 479 | + } | ||
| 480 | + @Override | ||
| 481 | + public void streamByeCmd(String streamId, SipSubscribe.Event okEvent) { | ||
| 467 | 482 | ||
| 468 | try { | 483 | try { |
| 469 | ClientTransaction transaction = streamSession.get(streamId); | 484 | ClientTransaction transaction = streamSession.get(streamId); |
| 485 | + // 服务重启后 | ||
| 470 | if (transaction == null) { | 486 | if (transaction == null) { |
| 487 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); | ||
| 488 | + if (streamInfo != null) { | ||
| 489 | + | ||
| 490 | + } | ||
| 471 | return; | 491 | return; |
| 472 | } | 492 | } |
| 473 | 493 | ||
| @@ -475,6 +495,9 @@ public class SIPCommander implements ISIPCommander { | @@ -475,6 +495,9 @@ public class SIPCommander implements ISIPCommander { | ||
| 475 | if (dialog == null) { | 495 | if (dialog == null) { |
| 476 | return; | 496 | return; |
| 477 | } | 497 | } |
| 498 | + | ||
| 499 | + | ||
| 500 | + | ||
| 478 | Request byeRequest = dialog.createRequest(Request.BYE); | 501 | Request byeRequest = dialog.createRequest(Request.BYE); |
| 479 | SipURI byeURI = (SipURI) byeRequest.getRequestURI(); | 502 | SipURI byeURI = (SipURI) byeRequest.getRequestURI(); |
| 480 | String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString(); | 503 | String vh = transaction.getRequest().getHeader(ViaHeader.NAME).toString(); |
| @@ -491,7 +514,14 @@ public class SIPCommander implements ISIPCommander { | @@ -491,7 +514,14 @@ public class SIPCommander implements ISIPCommander { | ||
| 491 | } else if("UDP".equals(protocol)) { | 514 | } else if("UDP".equals(protocol)) { |
| 492 | clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); | 515 | clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); |
| 493 | } | 516 | } |
| 517 | + | ||
| 518 | + CallIdHeader callIdHeader = (CallIdHeader) byeRequest.getHeader(CallIdHeader.NAME); | ||
| 519 | + if (okEvent != null) { | ||
| 520 | + sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent); | ||
| 521 | + } | ||
| 522 | + | ||
| 494 | dialog.sendRequest(clientTransaction); | 523 | dialog.sendRequest(clientTransaction); |
| 524 | + | ||
| 495 | streamSession.remove(streamId); | 525 | streamSession.remove(streamId); |
| 496 | zlmrtpServerFactory.closeRTPServer(streamId); | 526 | zlmrtpServerFactory.closeRTPServer(streamId); |
| 497 | } catch (TransactionDoesNotExistException e) { | 527 | } catch (TransactionDoesNotExistException e) { |
| @@ -612,7 +642,7 @@ public class SIPCommander implements ISIPCommander { | @@ -612,7 +642,7 @@ public class SIPCommander implements ISIPCommander { | ||
| 612 | 642 | ||
| 613 | Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", "ToDeviceInfoTag"); | 643 | Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", "ToDeviceInfoTag"); |
| 614 | 644 | ||
| 615 | - transmitRequest(device, request, null); | 645 | + transmitRequest(device, request); |
| 616 | 646 | ||
| 617 | } catch (SipException | ParseException | InvalidArgumentException e) { | 647 | } catch (SipException | ParseException | InvalidArgumentException e) { |
| 618 | e.printStackTrace(); | 648 | e.printStackTrace(); |
| @@ -676,7 +706,7 @@ public class SIPCommander implements ISIPCommander { | @@ -676,7 +706,7 @@ public class SIPCommander implements ISIPCommander { | ||
| 676 | Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", null); | 706 | Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", null); |
| 677 | 707 | ||
| 678 | 708 | ||
| 679 | - transmitRequest(device, request, null); | 709 | + transmitRequest(device, request); |
| 680 | } catch (SipException | ParseException | InvalidArgumentException e) { | 710 | } catch (SipException | ParseException | InvalidArgumentException e) { |
| 681 | e.printStackTrace(); | 711 | e.printStackTrace(); |
| 682 | return false; | 712 | return false; |
| @@ -727,8 +757,16 @@ public class SIPCommander implements ISIPCommander { | @@ -727,8 +757,16 @@ public class SIPCommander implements ISIPCommander { | ||
| 727 | // TODO Auto-generated method stub | 757 | // TODO Auto-generated method stub |
| 728 | return false; | 758 | return false; |
| 729 | } | 759 | } |
| 730 | - | 760 | + |
| 761 | + private ClientTransaction transmitRequest(Device device, Request request) throws SipException { | ||
| 762 | + return transmitRequest(device, request, null, null); | ||
| 763 | + } | ||
| 764 | + | ||
| 731 | private ClientTransaction transmitRequest(Device device, Request request, SipSubscribe.Event errorEvent) throws SipException { | 765 | private ClientTransaction transmitRequest(Device device, Request request, SipSubscribe.Event errorEvent) throws SipException { |
| 766 | + return transmitRequest(device, request, errorEvent, null); | ||
| 767 | + } | ||
| 768 | + | ||
| 769 | + private ClientTransaction transmitRequest(Device device, Request request, SipSubscribe.Event errorEvent , SipSubscribe.Event okEvent) throws SipException { | ||
| 732 | ClientTransaction clientTransaction = null; | 770 | ClientTransaction clientTransaction = null; |
| 733 | if("TCP".equals(device.getTransport())) { | 771 | if("TCP".equals(device.getTransport())) { |
| 734 | clientTransaction = tcpSipProvider.getNewClientTransaction(request); | 772 | clientTransaction = tcpSipProvider.getNewClientTransaction(request); |
| @@ -736,10 +774,14 @@ public class SIPCommander implements ISIPCommander { | @@ -736,10 +774,14 @@ public class SIPCommander implements ISIPCommander { | ||
| 736 | clientTransaction = udpSipProvider.getNewClientTransaction(request); | 774 | clientTransaction = udpSipProvider.getNewClientTransaction(request); |
| 737 | } | 775 | } |
| 738 | 776 | ||
| 739 | - // 添加订阅 | 777 | + CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME); |
| 778 | + // 添加错误订阅 | ||
| 740 | if (errorEvent != null) { | 779 | if (errorEvent != null) { |
| 741 | - CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME); | ||
| 742 | - sipSubscribe.addSubscribe(callIdHeader.getCallId(), errorEvent); | 780 | + sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), errorEvent); |
| 781 | + } | ||
| 782 | + // 添加订阅 | ||
| 783 | + if (okEvent != null) { | ||
| 784 | + sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), okEvent); | ||
| 743 | } | 785 | } |
| 744 | 786 | ||
| 745 | clientTransaction.sendRequest(); | 787 | clientTransaction.sendRequest(); |
| @@ -747,6 +789,8 @@ public class SIPCommander implements ISIPCommander { | @@ -747,6 +789,8 @@ public class SIPCommander implements ISIPCommander { | ||
| 747 | } | 789 | } |
| 748 | 790 | ||
| 749 | 791 | ||
| 792 | + | ||
| 793 | + | ||
| 750 | @Override | 794 | @Override |
| 751 | public void closeRTPServer(Device device, String channelId) { | 795 | public void closeRTPServer(Device device, String channelId) { |
| 752 | if (rtpEnable) { | 796 | if (rtpEnable) { |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
| @@ -10,6 +10,7 @@ import javax.sip.SipException; | @@ -10,6 +10,7 @@ import javax.sip.SipException; | ||
| 10 | import javax.sip.message.Request; | 10 | import javax.sip.message.Request; |
| 11 | import javax.sip.message.Response; | 11 | import javax.sip.message.Response; |
| 12 | 12 | ||
| 13 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 13 | import org.dom4j.Document; | 14 | import org.dom4j.Document; |
| 14 | import org.dom4j.DocumentException; | 15 | import org.dom4j.DocumentException; |
| 15 | import org.dom4j.Element; | 16 | import org.dom4j.Element; |
| @@ -48,6 +49,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -48,6 +49,8 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 48 | 49 | ||
| 49 | private IVideoManagerStorager storager; | 50 | private IVideoManagerStorager storager; |
| 50 | 51 | ||
| 52 | + private IRedisCatchStorage redisCatchStorage; | ||
| 53 | + | ||
| 51 | private EventPublisher publisher; | 54 | private EventPublisher publisher; |
| 52 | 55 | ||
| 53 | private RedisUtil redis; | 56 | private RedisUtil redis; |
| @@ -451,9 +454,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -451,9 +454,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 451 | String NotifyType =XmlUtil.getText(rootElement, "NotifyType"); | 454 | String NotifyType =XmlUtil.getText(rootElement, "NotifyType"); |
| 452 | if (NotifyType.equals("121")){ | 455 | if (NotifyType.equals("121")){ |
| 453 | logger.info("媒体播放完毕,通知关流"); | 456 | logger.info("媒体播放完毕,通知关流"); |
| 454 | - StreamInfo streamInfo = storager.queryPlaybackByDevice(deviceId, "*"); | 457 | + StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(deviceId, "*"); |
| 455 | if (streamInfo != null) { | 458 | if (streamInfo != null) { |
| 456 | - storager.stopPlayback(streamInfo); | 459 | + redisCatchStorage.stopPlayback(streamInfo); |
| 457 | cmder.streamByeCmd(streamInfo.getStreamId()); | 460 | cmder.streamByeCmd(streamInfo.getStreamId()); |
| 458 | } | 461 | } |
| 459 | } | 462 | } |
| @@ -507,4 +510,11 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -507,4 +510,11 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 507 | this.offLineDetector = offLineDetector; | 510 | this.offLineDetector = offLineDetector; |
| 508 | } | 511 | } |
| 509 | 512 | ||
| 513 | + public IRedisCatchStorage getRedisCatchStorage() { | ||
| 514 | + return redisCatchStorage; | ||
| 515 | + } | ||
| 516 | + | ||
| 517 | + public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) { | ||
| 518 | + this.redisCatchStorage = redisCatchStorage; | ||
| 519 | + } | ||
| 510 | } | 520 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java
| @@ -141,9 +141,15 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | @@ -141,9 +141,15 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 141 | // 下发catelog查询目录 | 141 | // 下发catelog查询目录 |
| 142 | if (registerFlag == 1 && device != null) { | 142 | if (registerFlag == 1 && device != null) { |
| 143 | logger.info("注册成功! deviceId:" + device.getDeviceId()); | 143 | logger.info("注册成功! deviceId:" + device.getDeviceId()); |
| 144 | + boolean exists = storager.exists(device.getDeviceId()); | ||
| 145 | + device.setRegisterTimeMillis(System.currentTimeMillis()); | ||
| 144 | storager.updateDevice(device); | 146 | storager.updateDevice(device); |
| 145 | publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER); | 147 | publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER); |
| 146 | - handler.onRegister(device); | 148 | + |
| 149 | + // 只有第一次注册才更新通道 | ||
| 150 | + if (!exists) { | ||
| 151 | + handler.onRegister(device); | ||
| 152 | + } | ||
| 147 | } else if (registerFlag == 2) { | 153 | } else if (registerFlag == 2) { |
| 148 | logger.info("注销成功! deviceId:" + device.getDeviceId()); | 154 | logger.info("注销成功! deviceId:" + device.getDeviceId()); |
| 149 | publisher.outlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_OUTLINE_UNREGISTER); | 155 | publisher.outlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_OUTLINE_UNREGISTER); |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHTTPProxyController.java
| @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.media.zlm; | @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.media.zlm; | ||
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | import com.genersoft.iot.vmp.conf.MediaServerConfig; | 4 | import com.genersoft.iot.vmp.conf.MediaServerConfig; |
| 5 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 5 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 6 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 6 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
| 7 | import org.slf4j.LoggerFactory; | 8 | import org.slf4j.LoggerFactory; |
| @@ -29,6 +30,9 @@ public class ZLMHTTPProxyController { | @@ -29,6 +30,9 @@ public class ZLMHTTPProxyController { | ||
| 29 | @Autowired | 30 | @Autowired |
| 30 | private IVideoManagerStorager storager; | 31 | private IVideoManagerStorager storager; |
| 31 | 32 | ||
| 33 | + @Autowired | ||
| 34 | + private IRedisCatchStorage redisCatchStorage; | ||
| 35 | + | ||
| 32 | @Value("${media.port}") | 36 | @Value("${media.port}") |
| 33 | private int mediaHttpPort; | 37 | private int mediaHttpPort; |
| 34 | 38 | ||
| @@ -36,10 +40,10 @@ public class ZLMHTTPProxyController { | @@ -36,10 +40,10 @@ public class ZLMHTTPProxyController { | ||
| 36 | @RequestMapping(value = "/**/**/**", produces = "application/json;charset=UTF-8") | 40 | @RequestMapping(value = "/**/**/**", produces = "application/json;charset=UTF-8") |
| 37 | public Object proxy(HttpServletRequest request, HttpServletResponse response){ | 41 | public Object proxy(HttpServletRequest request, HttpServletResponse response){ |
| 38 | 42 | ||
| 39 | - if (storager.getMediaInfo() == null) { | 43 | + if (redisCatchStorage.getMediaInfo() == null) { |
| 40 | return "未接入流媒体"; | 44 | return "未接入流媒体"; |
| 41 | } | 45 | } |
| 42 | - MediaServerConfig mediaInfo = storager.getMediaInfo(); | 46 | + MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); |
| 43 | String requestURI = String.format("http://%s:%s%s?%s&%s", | 47 | String requestURI = String.format("http://%s:%s%s?%s&%s", |
| 44 | mediaInfo.getLocalIP(), | 48 | mediaInfo.getLocalIP(), |
| 45 | mediaHttpPort, | 49 | mediaHttpPort, |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| @@ -11,6 +11,7 @@ import com.alibaba.fastjson.JSONArray; | @@ -11,6 +11,7 @@ import com.alibaba.fastjson.JSONArray; | ||
| 11 | import com.genersoft.iot.vmp.common.StreamInfo; | 11 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 12 | import com.genersoft.iot.vmp.conf.MediaServerConfig; | 12 | import com.genersoft.iot.vmp.conf.MediaServerConfig; |
| 13 | import com.genersoft.iot.vmp.gb28181.bean.Device; | 13 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 14 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 14 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 15 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 15 | import com.genersoft.iot.vmp.utils.IpUtil; | 16 | import com.genersoft.iot.vmp.utils.IpUtil; |
| 16 | import com.genersoft.iot.vmp.vmanager.service.IPlayService; | 17 | import com.genersoft.iot.vmp.vmanager.service.IPlayService; |
| @@ -53,6 +54,9 @@ public class ZLMHttpHookListener { | @@ -53,6 +54,9 @@ public class ZLMHttpHookListener { | ||
| 53 | private IVideoManagerStorager storager; | 54 | private IVideoManagerStorager storager; |
| 54 | 55 | ||
| 55 | @Autowired | 56 | @Autowired |
| 57 | + private IRedisCatchStorage redisCatchStorage; | ||
| 58 | + | ||
| 59 | + @Autowired | ||
| 56 | private ZLMRESTfulUtils zlmresTfulUtils; | 60 | private ZLMRESTfulUtils zlmresTfulUtils; |
| 57 | 61 | ||
| 58 | @Autowired | 62 | @Autowired |
| @@ -249,13 +253,13 @@ public class ZLMHttpHookListener { | @@ -249,13 +253,13 @@ public class ZLMHttpHookListener { | ||
| 249 | String app = json.getString("app"); | 253 | String app = json.getString("app"); |
| 250 | String streamId = json.getString("stream"); | 254 | String streamId = json.getString("stream"); |
| 251 | boolean regist = json.getBoolean("regist"); | 255 | boolean regist = json.getBoolean("regist"); |
| 252 | - StreamInfo streamInfo = storager.queryPlayByStreamId(streamId); | 256 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); |
| 253 | if ("rtp".equals(app) && !regist ) { | 257 | if ("rtp".equals(app) && !regist ) { |
| 254 | if (streamInfo!=null){ | 258 | if (streamInfo!=null){ |
| 255 | - storager.stopPlay(streamInfo); | 259 | + redisCatchStorage.stopPlay(streamInfo); |
| 256 | }else{ | 260 | }else{ |
| 257 | - streamInfo = storager.queryPlaybackByStreamId(streamId); | ||
| 258 | - storager.stopPlayback(streamInfo); | 261 | + streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); |
| 262 | + redisCatchStorage.stopPlayback(streamInfo); | ||
| 259 | } | 263 | } |
| 260 | } | 264 | } |
| 261 | 265 | ||
| @@ -281,12 +285,12 @@ public class ZLMHttpHookListener { | @@ -281,12 +285,12 @@ public class ZLMHttpHookListener { | ||
| 281 | String streamId = json.getString("stream"); | 285 | String streamId = json.getString("stream"); |
| 282 | 286 | ||
| 283 | cmder.streamByeCmd(streamId); | 287 | cmder.streamByeCmd(streamId); |
| 284 | - StreamInfo streamInfo = storager.queryPlayByStreamId(streamId); | 288 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); |
| 285 | if (streamInfo!=null){ | 289 | if (streamInfo!=null){ |
| 286 | - storager.stopPlay(streamInfo); | 290 | + redisCatchStorage.stopPlay(streamInfo); |
| 287 | }else{ | 291 | }else{ |
| 288 | - streamInfo = storager.queryPlaybackByStreamId(streamId); | ||
| 289 | - storager.stopPlayback(streamInfo); | 292 | + streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId); |
| 293 | + redisCatchStorage.stopPlayback(streamInfo); | ||
| 290 | } | 294 | } |
| 291 | 295 | ||
| 292 | JSONObject ret = new JSONObject(); | 296 | JSONObject ret = new JSONObject(); |
| @@ -311,7 +315,7 @@ public class ZLMHttpHookListener { | @@ -311,7 +315,7 @@ public class ZLMHttpHookListener { | ||
| 311 | if (autoApplyPlay) { | 315 | if (autoApplyPlay) { |
| 312 | String app = json.getString("app"); | 316 | String app = json.getString("app"); |
| 313 | String streamId = json.getString("stream"); | 317 | String streamId = json.getString("stream"); |
| 314 | - StreamInfo streamInfo = storager.queryPlayByStreamId(streamId); | 318 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); |
| 315 | if ("rtp".equals(app) && streamId.indexOf("gb_play") > -1 && streamInfo == null) { | 319 | if ("rtp".equals(app) && streamId.indexOf("gb_play") > -1 && streamInfo == null) { |
| 316 | String[] s = streamId.split("_"); | 320 | String[] s = streamId.split("_"); |
| 317 | if (s.length == 4) { | 321 | if (s.length == 4) { |
| @@ -355,7 +359,7 @@ public class ZLMHttpHookListener { | @@ -355,7 +359,7 @@ public class ZLMHttpHookListener { | ||
| 355 | // MediaServerConfig mediaServerConfig = mediaServerConfigs.get(0); | 359 | // MediaServerConfig mediaServerConfig = mediaServerConfigs.get(0); |
| 356 | MediaServerConfig mediaServerConfig = JSON.toJavaObject(json, MediaServerConfig.class); | 360 | MediaServerConfig mediaServerConfig = JSON.toJavaObject(json, MediaServerConfig.class); |
| 357 | mediaServerConfig.setLocalIP(mediaIp); | 361 | mediaServerConfig.setLocalIP(mediaIp); |
| 358 | - storager.updateMediaInfo(mediaServerConfig); | 362 | + redisCatchStorage.updateMediaInfo(mediaServerConfig); |
| 359 | // TODO Auto-generated method stub | 363 | // TODO Auto-generated method stub |
| 360 | 364 | ||
| 361 | JSONObject ret = new JSONObject(); | 365 | JSONObject ret = new JSONObject(); |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
| @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; | @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; | ||
| 4 | import com.alibaba.fastjson.JSONArray; | 4 | import com.alibaba.fastjson.JSONArray; |
| 5 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
| 6 | import com.genersoft.iot.vmp.conf.MediaServerConfig; | 6 | import com.genersoft.iot.vmp.conf.MediaServerConfig; |
| 7 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 7 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 8 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 8 | import okhttp3.*; | 9 | import okhttp3.*; |
| 9 | import org.slf4j.Logger; | 10 | import org.slf4j.Logger; |
| @@ -30,6 +31,9 @@ public class ZLMRunner implements CommandLineRunner { | @@ -30,6 +31,9 @@ public class ZLMRunner implements CommandLineRunner { | ||
| 30 | @Autowired | 31 | @Autowired |
| 31 | private IVideoManagerStorager storager; | 32 | private IVideoManagerStorager storager; |
| 32 | 33 | ||
| 34 | + @Autowired | ||
| 35 | + private IRedisCatchStorage redisCatchStorage; | ||
| 36 | + | ||
| 33 | @Value("${media.ip}") | 37 | @Value("${media.ip}") |
| 34 | private String mediaIp; | 38 | private String mediaIp; |
| 35 | 39 | ||
| @@ -69,7 +73,7 @@ public class ZLMRunner implements CommandLineRunner { | @@ -69,7 +73,7 @@ public class ZLMRunner implements CommandLineRunner { | ||
| 69 | logger.info("zlm接入成功..."); | 73 | logger.info("zlm接入成功..."); |
| 70 | if (autoConfig) saveZLMConfig(); | 74 | if (autoConfig) saveZLMConfig(); |
| 71 | mediaServerConfig = getMediaServerConfig(); | 75 | mediaServerConfig = getMediaServerConfig(); |
| 72 | - storager.updateMediaInfo(mediaServerConfig); | 76 | + redisCatchStorage.updateMediaInfo(mediaServerConfig); |
| 73 | } | 77 | } |
| 74 | } | 78 | } |
| 75 | 79 |
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.storager; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 4 | +import com.genersoft.iot.vmp.conf.MediaServerConfig; | ||
| 5 | + | ||
| 6 | +import java.util.Map; | ||
| 7 | + | ||
| 8 | +public interface IRedisCatchStorage { | ||
| 9 | + | ||
| 10 | + /** | ||
| 11 | + * 开始播放时将流存入 | ||
| 12 | + * | ||
| 13 | + * @param stream 流信息 | ||
| 14 | + * @return | ||
| 15 | + */ | ||
| 16 | + boolean startPlay(StreamInfo stream); | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + /** | ||
| 20 | + * 停止播放时删除 | ||
| 21 | + * | ||
| 22 | + * @return | ||
| 23 | + */ | ||
| 24 | + boolean stopPlay(StreamInfo streamInfo); | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 查询播放列表 | ||
| 28 | + * @return | ||
| 29 | + */ | ||
| 30 | + StreamInfo queryPlay(StreamInfo streamInfo); | ||
| 31 | + | ||
| 32 | + StreamInfo queryPlayByStreamId(String steamId); | ||
| 33 | + | ||
| 34 | + StreamInfo queryPlaybackByStreamId(String steamId); | ||
| 35 | + | ||
| 36 | + StreamInfo queryPlayByDevice(String deviceId, String code); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 更新流媒体信息 | ||
| 40 | + * @param mediaServerConfig | ||
| 41 | + * @return | ||
| 42 | + */ | ||
| 43 | + boolean updateMediaInfo(MediaServerConfig mediaServerConfig); | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 获取流媒体信息 | ||
| 47 | + * @return | ||
| 48 | + */ | ||
| 49 | + MediaServerConfig getMediaInfo(); | ||
| 50 | + | ||
| 51 | + Map<String, StreamInfo> queryPlayByDeviceId(String deviceId); | ||
| 52 | + | ||
| 53 | + boolean startPlayback(StreamInfo stream); | ||
| 54 | + | ||
| 55 | + boolean stopPlayback(StreamInfo streamInfo); | ||
| 56 | + | ||
| 57 | + StreamInfo queryPlaybackByDevice(String deviceId, String code); | ||
| 58 | +} |
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
| @@ -17,19 +17,6 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | @@ -17,19 +17,6 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 17 | */ | 17 | */ |
| 18 | public interface IVideoManagerStorager { | 18 | public interface IVideoManagerStorager { |
| 19 | 19 | ||
| 20 | - /** | ||
| 21 | - * 更新流媒体信息 | ||
| 22 | - * @param mediaServerConfig | ||
| 23 | - * @return | ||
| 24 | - */ | ||
| 25 | - public boolean updateMediaInfo(MediaServerConfig mediaServerConfig); | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * 获取流媒体信息 | ||
| 29 | - * @return | ||
| 30 | - */ | ||
| 31 | - public MediaServerConfig getMediaInfo(); | ||
| 32 | - | ||
| 33 | /** | 20 | /** |
| 34 | * 根据设备ID判断设备是否存在 | 21 | * 根据设备ID判断设备是否存在 |
| 35 | * | 22 | * |
| @@ -106,10 +93,9 @@ public interface IVideoManagerStorager { | @@ -106,10 +93,9 @@ public interface IVideoManagerStorager { | ||
| 106 | /** | 93 | /** |
| 107 | * 获取多个设备 | 94 | * 获取多个设备 |
| 108 | * | 95 | * |
| 109 | - * @param deviceIds 设备ID数组 | ||
| 110 | * @return List<Device> 设备对象数组 | 96 | * @return List<Device> 设备对象数组 |
| 111 | */ | 97 | */ |
| 112 | - public List<Device> queryVideoDeviceList(String[] deviceIds); | 98 | + public List<Device> queryVideoDeviceList(); |
| 113 | 99 | ||
| 114 | /** | 100 | /** |
| 115 | * 删除设备 | 101 | * 删除设备 |
| @@ -135,27 +121,6 @@ public interface IVideoManagerStorager { | @@ -135,27 +121,6 @@ public interface IVideoManagerStorager { | ||
| 135 | */ | 121 | */ |
| 136 | public boolean outline(String deviceId); | 122 | public boolean outline(String deviceId); |
| 137 | 123 | ||
| 138 | - /** | ||
| 139 | - * 开始播放时将流存入 | ||
| 140 | - * | ||
| 141 | - * @param stream 流信息 | ||
| 142 | - * @return | ||
| 143 | - */ | ||
| 144 | - public boolean startPlay(StreamInfo stream); | ||
| 145 | - | ||
| 146 | - /** | ||
| 147 | - * 停止播放时删除 | ||
| 148 | - * | ||
| 149 | - * @return | ||
| 150 | - */ | ||
| 151 | - public boolean stopPlay(StreamInfo streamInfo); | ||
| 152 | - | ||
| 153 | - /** | ||
| 154 | - * 查找视频流 | ||
| 155 | - * | ||
| 156 | - * @return | ||
| 157 | - */ | ||
| 158 | - public StreamInfo queryPlay(StreamInfo streamInfo); | ||
| 159 | 124 | ||
| 160 | /** | 125 | /** |
| 161 | * 查询子设备 | 126 | * 查询子设备 |
| @@ -168,10 +133,6 @@ public interface IVideoManagerStorager { | @@ -168,10 +133,6 @@ public interface IVideoManagerStorager { | ||
| 168 | */ | 133 | */ |
| 169 | PageResult querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, String online, int page, int count); | 134 | PageResult querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, String online, int page, int count); |
| 170 | 135 | ||
| 171 | - /** | ||
| 172 | - * 更新缓存 | ||
| 173 | - */ | ||
| 174 | - public void updateCatch(); | ||
| 175 | 136 | ||
| 176 | /** | 137 | /** |
| 177 | * 清空通道 | 138 | * 清空通道 |
| @@ -179,17 +140,4 @@ public interface IVideoManagerStorager { | @@ -179,17 +140,4 @@ public interface IVideoManagerStorager { | ||
| 179 | */ | 140 | */ |
| 180 | void cleanChannelsForDevice(String deviceId); | 141 | void cleanChannelsForDevice(String deviceId); |
| 181 | 142 | ||
| 182 | - StreamInfo queryPlayByStreamId(String streamId); | ||
| 183 | - | ||
| 184 | - StreamInfo queryPlayByDevice(String deviceId, String code); | ||
| 185 | - | ||
| 186 | - Map<String, StreamInfo> queryPlayByDeviceId(String deviceId); | ||
| 187 | - | ||
| 188 | - boolean startPlayback(StreamInfo streamInfo); | ||
| 189 | - | ||
| 190 | - boolean stopPlayback(StreamInfo streamInfo); | ||
| 191 | - | ||
| 192 | - StreamInfo queryPlaybackByDevice(String deviceId, String channelId); | ||
| 193 | - | ||
| 194 | - StreamInfo queryPlaybackByStreamId(String streamId); | ||
| 195 | } | 143 | } |
src/main/java/com/genersoft/iot/vmp/storager/VideoManagerStoragerFactory.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.storager; | ||
| 2 | - | ||
| 3 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | -import org.springframework.context.annotation.Bean; | ||
| 5 | -import org.springframework.stereotype.Component; | ||
| 6 | - | ||
| 7 | -import com.genersoft.iot.vmp.conf.VManagerConfig; | ||
| 8 | - | ||
| 9 | -/** | ||
| 10 | - * @Description:视频设备数据存储工厂,根据存储策略,返回对应的存储器 | ||
| 11 | - * @author: swwheihei | ||
| 12 | - * @date: 2020年5月6日 下午2:15:16 | ||
| 13 | - */ | ||
| 14 | -@Component | ||
| 15 | -public class VideoManagerStoragerFactory { | ||
| 16 | - | ||
| 17 | - @Autowired | ||
| 18 | - private VManagerConfig vmConfig; | ||
| 19 | - | ||
| 20 | - @Autowired | ||
| 21 | - private IVideoManagerStorager jdbcStorager; | ||
| 22 | - | ||
| 23 | - @Autowired | ||
| 24 | - private IVideoManagerStorager redisStorager; | ||
| 25 | - | ||
| 26 | - @Bean("storager") | ||
| 27 | - public IVideoManagerStorager getStorager() { | ||
| 28 | - if ("redis".equals(vmConfig.getDatabase().toLowerCase())) { | ||
| 29 | - return redisStorager; | ||
| 30 | - } else if ("jdbc".equals(vmConfig.getDatabase().toLowerCase())) { | ||
| 31 | - return jdbcStorager; | ||
| 32 | - } | ||
| 33 | - return redisStorager; | ||
| 34 | - } | ||
| 35 | - | ||
| 36 | -} |
src/main/java/com/genersoft/iot/vmp/storager/VodeoMannagerTask.java
| @@ -8,10 +8,10 @@ import org.springframework.stereotype.Component; | @@ -8,10 +8,10 @@ import org.springframework.stereotype.Component; | ||
| 8 | public class VodeoMannagerTask implements CommandLineRunner { | 8 | public class VodeoMannagerTask implements CommandLineRunner { |
| 9 | 9 | ||
| 10 | @Autowired | 10 | @Autowired |
| 11 | - private IVideoManagerStorager storager; | 11 | + private IVideoManagerStorager redisStorager; |
| 12 | 12 | ||
| 13 | @Override | 13 | @Override |
| 14 | public void run(String... strings) throws Exception { | 14 | public void run(String... strings) throws Exception { |
| 15 | - storager.updateCatch(); | 15 | + redisStorager.updateCatch(); |
| 16 | } | 16 | } |
| 17 | } | 17 | } |
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.storager.dao; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.common.PageResult; | ||
| 4 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 5 | +import org.apache.ibatis.annotations.Mapper; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +@Mapper | ||
| 10 | +public interface DeviceChannelMapper { | ||
| 11 | + int update(DeviceChannel channel); | ||
| 12 | + | ||
| 13 | + List<DeviceChannel> queryChannelsByDeviceId(String deviceId); | ||
| 14 | + | ||
| 15 | + List<DeviceChannel> queryChannelsByDeviceId(String deviceId, String parentChannelId); | ||
| 16 | + | ||
| 17 | + DeviceChannel queryChannel(String deviceId, String channelId); | ||
| 18 | + | ||
| 19 | + int cleanChannelsByDeviceId(String deviceId); | ||
| 20 | +} |
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.storager.dao; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 4 | +import org.apache.ibatis.annotations.Insert; | ||
| 5 | +import org.apache.ibatis.annotations.Mapper; | ||
| 6 | +import org.apache.ibatis.annotations.Select; | ||
| 7 | + | ||
| 8 | +import java.util.List; | ||
| 9 | + | ||
| 10 | +@Mapper | ||
| 11 | +public interface DeviceMapper { | ||
| 12 | + | ||
| 13 | + @Select("SELECT * FROM device WHERE deviceId = #{deviceId}") | ||
| 14 | + Device getDeviceByDeviceId(String deviceId); | ||
| 15 | + | ||
| 16 | + @Insert("SELECT * FROM device WHERE deviceId = #{deviceId}") | ||
| 17 | + int add(Device device); | ||
| 18 | + | ||
| 19 | + int update(Device device); | ||
| 20 | + | ||
| 21 | + List<Device> getDevices(); | ||
| 22 | + | ||
| 23 | + int del(String deviceId); | ||
| 24 | +} |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.storager.impl; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 4 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 5 | +import com.genersoft.iot.vmp.conf.MediaServerConfig; | ||
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 7 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 8 | +import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; | ||
| 9 | +import com.genersoft.iot.vmp.storager.dao.DeviceMapper; | ||
| 10 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.stereotype.Component; | ||
| 13 | + | ||
| 14 | +import java.util.HashMap; | ||
| 15 | +import java.util.HashSet; | ||
| 16 | +import java.util.List; | ||
| 17 | +import java.util.Map; | ||
| 18 | + | ||
| 19 | +@Component | ||
| 20 | +public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 21 | + | ||
| 22 | + @Autowired | ||
| 23 | + private RedisUtil redis; | ||
| 24 | + | ||
| 25 | + @Autowired | ||
| 26 | + private DeviceMapper deviceMapper; | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + private DeviceChannelMapper deviceChannelMapper; | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 开始播放时将流存入redis | ||
| 34 | + * | ||
| 35 | + * @return | ||
| 36 | + */ | ||
| 37 | + @Override | ||
| 38 | + public boolean startPlay(StreamInfo stream) { | ||
| 39 | + return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()), | ||
| 40 | + stream); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 停止播放时从redis删除 | ||
| 45 | + * | ||
| 46 | + * @return | ||
| 47 | + */ | ||
| 48 | + @Override | ||
| 49 | + public boolean stopPlay(StreamInfo streamInfo) { | ||
| 50 | + if (streamInfo == null) return false; | ||
| 51 | + DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId()); | ||
| 52 | + if (deviceChannel != null) { | ||
| 53 | + deviceChannel.setStreamId(null); | ||
| 54 | + deviceChannel.setPlay(false); | ||
| 55 | + deviceChannel.setDeviceId(streamInfo.getDeviceID()); | ||
| 56 | + deviceChannelMapper.update(deviceChannel); | ||
| 57 | + } | ||
| 58 | + return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | ||
| 59 | + streamInfo.getStreamId(), | ||
| 60 | + streamInfo.getDeviceID(), | ||
| 61 | + streamInfo.getCahnnelId())); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * 查询播放列表 | ||
| 66 | + * @return | ||
| 67 | + */ | ||
| 68 | + @Override | ||
| 69 | + public StreamInfo queryPlay(StreamInfo streamInfo) { | ||
| 70 | + return (StreamInfo)redis.get(String.format("%S_%s_%s_%s", | ||
| 71 | + VideoManagerConstants.PLAYER_PREFIX, | ||
| 72 | + streamInfo.getStreamId(), | ||
| 73 | + streamInfo.getDeviceID(), | ||
| 74 | + streamInfo.getCahnnelId())); | ||
| 75 | + } | ||
| 76 | + @Override | ||
| 77 | + public StreamInfo queryPlayByStreamId(String steamId) { | ||
| 78 | + List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, steamId)); | ||
| 79 | + if (playLeys == null || playLeys.size() == 0) return null; | ||
| 80 | + return (StreamInfo)redis.get(playLeys.get(0).toString()); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public StreamInfo queryPlaybackByStreamId(String steamId) { | ||
| 85 | + List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, steamId)); | ||
| 86 | + if (playLeys == null || playLeys.size() == 0) return null; | ||
| 87 | + return (StreamInfo)redis.get(playLeys.get(0).toString()); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public StreamInfo queryPlayByDevice(String deviceId, String code) { | ||
| 92 | +// List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | ||
| 93 | + List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | ||
| 94 | + deviceId, | ||
| 95 | + code)); | ||
| 96 | + if (playLeys == null || playLeys.size() == 0) return null; | ||
| 97 | + return (StreamInfo)redis.get(playLeys.get(0).toString()); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 更新流媒体信息 | ||
| 102 | + * @param mediaServerConfig | ||
| 103 | + * @return | ||
| 104 | + */ | ||
| 105 | + @Override | ||
| 106 | + public boolean updateMediaInfo(MediaServerConfig mediaServerConfig) { | ||
| 107 | + return redis.set(VideoManagerConstants.MEDIA_SERVER_PREFIX,mediaServerConfig); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 获取流媒体信息 | ||
| 112 | + * @return | ||
| 113 | + */ | ||
| 114 | + @Override | ||
| 115 | + public MediaServerConfig getMediaInfo() { | ||
| 116 | + return (MediaServerConfig)redis.get(VideoManagerConstants.MEDIA_SERVER_PREFIX); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + @Override | ||
| 120 | + public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) { | ||
| 121 | + Map<String, StreamInfo> streamInfos = new HashMap<>(); | ||
| 122 | +// List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); | ||
| 123 | + List<Object> players = redis.scan(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); | ||
| 124 | + if (players.size() == 0) return streamInfos; | ||
| 125 | + for (int i = 0; i < players.size(); i++) { | ||
| 126 | + String key = (String) players.get(i); | ||
| 127 | + StreamInfo streamInfo = (StreamInfo)redis.get(key); | ||
| 128 | + streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getCahnnelId(), streamInfo); | ||
| 129 | + } | ||
| 130 | + return streamInfos; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + | ||
| 134 | + @Override | ||
| 135 | + public boolean startPlayback(StreamInfo stream) { | ||
| 136 | + return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()), | ||
| 137 | + stream); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + | ||
| 141 | + @Override | ||
| 142 | + public boolean stopPlayback(StreamInfo streamInfo) { | ||
| 143 | + if (streamInfo == null) return false; | ||
| 144 | + DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId()); | ||
| 145 | + if (deviceChannel != null) { | ||
| 146 | + deviceChannel.setStreamId(null); | ||
| 147 | + deviceChannel.setPlay(false); | ||
| 148 | + deviceChannel.setDeviceId(streamInfo.getDeviceID()); | ||
| 149 | + deviceChannelMapper.update(deviceChannel); | ||
| 150 | + } | ||
| 151 | + return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | ||
| 152 | + streamInfo.getStreamId(), | ||
| 153 | + streamInfo.getDeviceID(), | ||
| 154 | + streamInfo.getCahnnelId())); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + @Override | ||
| 158 | + public StreamInfo queryPlaybackByDevice(String deviceId, String code) { | ||
| 159 | + String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | ||
| 160 | + deviceId, | ||
| 161 | + code); | ||
| 162 | + List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | ||
| 163 | + deviceId, | ||
| 164 | + code)); | ||
| 165 | + if (playLeys == null || playLeys.size() == 0) { | ||
| 166 | + playLeys = redis.scan(String.format("%S_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | ||
| 167 | + deviceId)); | ||
| 168 | + } | ||
| 169 | + if (playLeys == null || playLeys.size() == 0) return null; | ||
| 170 | + return (StreamInfo)redis.get(playLeys.get(0).toString()); | ||
| 171 | + } | ||
| 172 | +} |
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.storager.impl; | ||
| 2 | + | ||
| 3 | +import java.util.*; | ||
| 4 | + | ||
| 5 | +import com.genersoft.iot.vmp.common.PageResult; | ||
| 6 | +import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 7 | +import com.genersoft.iot.vmp.conf.MediaServerConfig; | ||
| 8 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 9 | +import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; | ||
| 10 | +import com.genersoft.iot.vmp.storager.dao.DeviceMapper; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.stereotype.Component; | ||
| 13 | + | ||
| 14 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 15 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 16 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 17 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | ||
| 18 | +import org.springframework.util.StringUtils; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * @Description:视频设备数据存储-jdbc实现 | ||
| 22 | + * @author: swwheihei | ||
| 23 | + * @date: 2020年5月6日 下午2:31:42 | ||
| 24 | + */ | ||
| 25 | +@Component | ||
| 26 | +public class VideoManagerStoragerImpl implements IVideoManagerStorager { | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + private DeviceMapper deviceMapper; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + private DeviceChannelMapper deviceChannelMapper; | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 根据设备ID判断设备是否存在 | ||
| 37 | + * | ||
| 38 | + * @param deviceId 设备ID | ||
| 39 | + * @return true:存在 false:不存在 | ||
| 40 | + */ | ||
| 41 | + @Override | ||
| 42 | + public boolean exists(String deviceId) { | ||
| 43 | + return deviceMapper.getDeviceByDeviceId(deviceId) != null; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 视频设备创建 | ||
| 48 | + * | ||
| 49 | + * @param device 设备对象 | ||
| 50 | + * @return true:创建成功 false:创建失败 | ||
| 51 | + */ | ||
| 52 | + @Override | ||
| 53 | + public boolean create(Device device) { | ||
| 54 | + return deviceMapper.add(device) > 0; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 视频设备更新 | ||
| 61 | + * | ||
| 62 | + * @param device 设备对象 | ||
| 63 | + * @return true:更新成功 false:更新失败 | ||
| 64 | + */ | ||
| 65 | + @Override | ||
| 66 | + public boolean updateDevice(Device device) { | ||
| 67 | +// if (deviceMap.get(device.getDeviceId()) == null) { | ||
| 68 | +// deviceMap.put(device.getDeviceId(), new HashMap<String, HashSet<String>>()); | ||
| 69 | +// } | ||
| 70 | + // 更新device中的通道数量 | ||
| 71 | +// device.setChannelCount(deviceMap.get(device.getDeviceId()).size()); | ||
| 72 | + int result = deviceMapper.update(device); | ||
| 73 | + // 存储device | ||
| 74 | + return result > 0; | ||
| 75 | + | ||
| 76 | + | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public void updateChannel(String deviceId, DeviceChannel channel) { | ||
| 81 | + String channelId = channel.getChannelId(); | ||
| 82 | + channel.setDeviceId(deviceId); | ||
| 83 | + deviceChannelMapper.update(channel); | ||
| 84 | + | ||
| 85 | +// HashMap<String, HashSet<String>> channelMap = deviceMap.get(deviceId); | ||
| 86 | +// if (channelMap == null) return; | ||
| 87 | +// // 作为父设备, 确定自己的子节点数 | ||
| 88 | +// if (channelMap.get(channelId) == null) { | ||
| 89 | +// channelMap.put(channelId, new HashSet<String>()); | ||
| 90 | +// }else if (channelMap.get(channelId).size() > 0) { | ||
| 91 | +// channel.setSubCount(channelMap.get(channelId).size()); | ||
| 92 | +// } | ||
| 93 | +// | ||
| 94 | +// // 存储通道 | ||
| 95 | +// redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 96 | +// "_" + channel.getChannelId() + | ||
| 97 | +// "_" + (channel.getStatus() == 1 ? "on":"off") + | ||
| 98 | +// "_" + (channelMap.get(channelId).size() > 0)+ | ||
| 99 | +// "_" + (StringUtils.isEmpty(channel.getParentId())?null:channel.getParentId()), | ||
| 100 | +// channel); | ||
| 101 | +// // 更新device中的通道数量 | ||
| 102 | +// Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 103 | +// device.setChannelCount(deviceMap.get(deviceId).size()); | ||
| 104 | +// redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 105 | +// | ||
| 106 | +// | ||
| 107 | +// // 如果有父设备,更新父设备内子节点数 | ||
| 108 | +// String parentId = channel.getParentId(); | ||
| 109 | +// if (!StringUtils.isEmpty(parentId) && !parentId.equals(deviceId)) { | ||
| 110 | +// | ||
| 111 | +// if (channelMap.get(parentId) == null) { | ||
| 112 | +// channelMap.put(parentId, new HashSet<String>()); | ||
| 113 | +// } | ||
| 114 | +// channelMap.get(parentId).add(channelId); | ||
| 115 | +// | ||
| 116 | +// DeviceChannel deviceChannel = queryChannel(deviceId, parentId); | ||
| 117 | +// if (deviceChannel != null) { | ||
| 118 | +// deviceChannel.setSubCount(channelMap.get(parentId).size()); | ||
| 119 | +// redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 120 | +// "_" + deviceChannel.getChannelId() + | ||
| 121 | +// "_" + (deviceChannel.getStatus() == 1 ? "on":"off") + | ||
| 122 | +// "_" + (channelMap.get(deviceChannel.getChannelId()).size() > 0)+ | ||
| 123 | +// "_" + (StringUtils.isEmpty(deviceChannel.getParentId())?null:deviceChannel.getParentId()), | ||
| 124 | +// deviceChannel); | ||
| 125 | +// | ||
| 126 | +// } | ||
| 127 | +// } | ||
| 128 | + | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + /** | ||
| 132 | + * 获取设备 | ||
| 133 | + * | ||
| 134 | + * @param deviceId 设备ID | ||
| 135 | + * @return Device 设备对象 | ||
| 136 | + */ | ||
| 137 | + @Override | ||
| 138 | + public Device queryVideoDevice(String deviceId) { | ||
| 139 | + return deviceMapper.getDeviceByDeviceId(deviceId); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + @Override | ||
| 143 | + public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 144 | + // 获取到所有正在播放的流 | ||
| 145 | + List<DeviceChannel> result = new ArrayList<>(); | ||
| 146 | + PageResult pageResult = new PageResult<DeviceChannel>(); | ||
| 147 | + | ||
| 148 | + deviceChannelMapper.queryChannelsByDeviceId(deviceId); | ||
| 149 | +// String queryContent = "*"; | ||
| 150 | +// if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); | ||
| 151 | +// String queryHasSubChannel = "*"; | ||
| 152 | +// if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; | ||
| 153 | +// String queryOnline = "*"; | ||
| 154 | +// if (!StringUtils.isEmpty(online)) queryOnline = online; | ||
| 155 | +// String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 156 | +// "_" + queryContent + // 搜索编号和名称 | ||
| 157 | +// "_" + queryOnline + // 搜索是否在线 | ||
| 158 | +// "_" + queryHasSubChannel + // 搜索是否含有子节点 | ||
| 159 | +// "_" + "*"; | ||
| 160 | +// List<Object> deviceChannelList = redis.scan(queryStr); | ||
| 161 | +// //对查询结果排序,避免出现通道排列顺序乱序的情况 | ||
| 162 | +// Collections.sort(deviceChannelList,new Comparator<Object>(){ | ||
| 163 | +// @Override | ||
| 164 | +// public int compare(Object o1, Object o2) { | ||
| 165 | +// return o1.toString().compareToIgnoreCase(o2.toString()); | ||
| 166 | +// } | ||
| 167 | +// }); | ||
| 168 | +// pageResult.setPage(page); | ||
| 169 | +// pageResult.setCount(count); | ||
| 170 | +// pageResult.setTotal(deviceChannelList.size()); | ||
| 171 | +// int maxCount = (page + 1 ) * count; | ||
| 172 | +// if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 173 | +// for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | ||
| 174 | +// DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); | ||
| 175 | +// StreamInfo streamInfo = stringStreamInfoMap.get(deviceId + "_" + deviceChannel.getChannelId()); | ||
| 176 | +// deviceChannel.setPlay(streamInfo != null); | ||
| 177 | +// if (streamInfo != null) deviceChannel.setStreamId(streamInfo.getStreamId()); | ||
| 178 | +// result.add(deviceChannel); | ||
| 179 | +// } | ||
| 180 | +// pageResult.setData(result); | ||
| 181 | +// } | ||
| 182 | + | ||
| 183 | + return pageResult; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + | ||
| 187 | + | ||
| 188 | + @Override | ||
| 189 | + public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { | ||
| 190 | +// List<DeviceChannel> result = new ArrayList<>(); | ||
| 191 | +//// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 192 | +// List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 193 | +// | ||
| 194 | +// if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 195 | +// for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 196 | +// result.add((DeviceChannel)redis.get((String) deviceChannelList.get(i))); | ||
| 197 | +// } | ||
| 198 | +// } | ||
| 199 | + return deviceChannelMapper.queryChannelsByDeviceId(deviceId); | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + @Override | ||
| 203 | + public PageResult querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 204 | + | ||
| 205 | + deviceChannelMapper.queryChannelsByDeviceId(deviceId, parentChannelId); | ||
| 206 | + | ||
| 207 | +// List<DeviceChannel> allDeviceChannels = new ArrayList<>(); | ||
| 208 | +// String queryContent = "*"; | ||
| 209 | +// if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); | ||
| 210 | +// String queryHasSubChannel = "*"; | ||
| 211 | +// if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; | ||
| 212 | +// String queryOnline = "*"; | ||
| 213 | +// if (!StringUtils.isEmpty(online)) queryOnline = online; | ||
| 214 | +// String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 215 | +// "_" + queryContent + // 搜索编号和名称 | ||
| 216 | +// "_" + queryOnline + // 搜索是否在线 | ||
| 217 | +// "_" + queryHasSubChannel + // 搜索是否含有子节点 | ||
| 218 | +// "_" + parentChannelId; | ||
| 219 | +// | ||
| 220 | +//// List<Object> deviceChannelList = redis.keys(queryStr); | ||
| 221 | +// List<Object> deviceChannelList = redis.scan(queryStr); | ||
| 222 | +// | ||
| 223 | +// if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 224 | +// for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 225 | +// DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); | ||
| 226 | +// if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { | ||
| 227 | +// allDeviceChannels.add(deviceChannel); | ||
| 228 | +// } | ||
| 229 | +// } | ||
| 230 | +// } | ||
| 231 | +// int maxCount = (page + 1 ) * count; | ||
| 232 | + PageResult pageResult = new PageResult<DeviceChannel>(); | ||
| 233 | +// pageResult.setPage(page); | ||
| 234 | +// pageResult.setCount(count); | ||
| 235 | +// pageResult.setTotal(allDeviceChannels.size()); | ||
| 236 | +// | ||
| 237 | +// if (allDeviceChannels.size() > 0) { | ||
| 238 | +// pageResult.setData(allDeviceChannels.subList( | ||
| 239 | +// page * count, pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() | ||
| 240 | +// )); | ||
| 241 | +// } | ||
| 242 | + return pageResult; | ||
| 243 | + } | ||
| 244 | + | ||
| 245 | + public List<DeviceChannel> querySubChannels(String deviceId, String parentChannelId) { | ||
| 246 | + List<DeviceChannel> allDeviceChannels = new ArrayList<>(); | ||
| 247 | +// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 248 | +// List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 249 | +// | ||
| 250 | +// if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 251 | +// for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 252 | +// DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); | ||
| 253 | +// if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { | ||
| 254 | +// allDeviceChannels.add(deviceChannel); | ||
| 255 | +// } | ||
| 256 | +// } | ||
| 257 | +// } | ||
| 258 | + | ||
| 259 | + return allDeviceChannels; | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + @Override | ||
| 263 | + public DeviceChannel queryChannel(String deviceId, String channelId) { | ||
| 264 | + DeviceChannel deviceChannel = null; | ||
| 265 | + return deviceChannelMapper.queryChannel(deviceId, channelId); | ||
| 266 | +//// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 267 | +// List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 268 | +// "_" + channelId + "*"); | ||
| 269 | +// if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 270 | +// deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(0)); | ||
| 271 | +// } | ||
| 272 | +// return deviceChannel; | ||
| 273 | + } | ||
| 274 | + | ||
| 275 | + | ||
| 276 | + /** | ||
| 277 | + * 获取多个设备 | ||
| 278 | + * | ||
| 279 | + * @param deviceIds 设备ID数组 | ||
| 280 | + * @return List<Device> 设备对象数组 | ||
| 281 | + */ | ||
| 282 | + @Override | ||
| 283 | + public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) { | ||
| 284 | + List<Device> devices = new ArrayList<>(); | ||
| 285 | + PageResult pageResult = new PageResult<Device>(); | ||
| 286 | +// pageResult.setPage(page); | ||
| 287 | +// pageResult.setCount(count); | ||
| 288 | +// Device device = null; | ||
| 289 | +// | ||
| 290 | +// if (deviceIds == null || deviceIds.length == 0) { | ||
| 291 | +// | ||
| 292 | +//// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 293 | +// List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 294 | +// pageResult.setTotal(deviceIdList.size()); | ||
| 295 | +// int maxCount = (page + 1)* count; | ||
| 296 | +// for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | ||
| 297 | +// // devices.add((Device)redis.get((String)deviceIdList.get(i))); | ||
| 298 | +// device =(Device)redis.get((String)deviceIdList.get(i)); | ||
| 299 | +// if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 300 | +// // outline(device.getDeviceId()); | ||
| 301 | +// } | ||
| 302 | +// devices.add(device); | ||
| 303 | +// } | ||
| 304 | +// } else { | ||
| 305 | +// for (int i = 0; i < deviceIds.length; i++) { | ||
| 306 | +// // devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | ||
| 307 | +// device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); | ||
| 308 | +// if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 309 | +// // outline(device.getDeviceId()); | ||
| 310 | +// } | ||
| 311 | +// devices.add(device); | ||
| 312 | +// } | ||
| 313 | +// } | ||
| 314 | +// pageResult.setData(devices); | ||
| 315 | + return pageResult; | ||
| 316 | + } | ||
| 317 | + | ||
| 318 | + /** | ||
| 319 | + * 获取多个设备 | ||
| 320 | + * | ||
| 321 | + * @return List<Device> 设备对象数组 | ||
| 322 | + */ | ||
| 323 | + @Override | ||
| 324 | + public List<Device> queryVideoDeviceList() { | ||
| 325 | + | ||
| 326 | +// if (deviceIds == null || deviceIds.length == 0) { | ||
| 327 | +//// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 328 | +// List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 329 | +// for (int i = 0; i < deviceIdList.size(); i++) { | ||
| 330 | +// device =(Device)redis.get((String)deviceIdList.get(i)); | ||
| 331 | +// if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 332 | +// outline(device.getDeviceId()); | ||
| 333 | +// } | ||
| 334 | +// devices.add(device); | ||
| 335 | +// } | ||
| 336 | +// } else { | ||
| 337 | +// for (int i = 0; i < deviceIds.length; i++) { | ||
| 338 | +// device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); | ||
| 339 | +// if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 340 | +// outline(device.getDeviceId()); | ||
| 341 | +// } | ||
| 342 | +// devices.add(device); | ||
| 343 | +// } | ||
| 344 | +// } | ||
| 345 | + | ||
| 346 | + List<Device> deviceList = deviceMapper.getDevices(); | ||
| 347 | + return deviceList; | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + /** | ||
| 351 | + * 删除设备 | ||
| 352 | + * | ||
| 353 | + * @param deviceId 设备ID | ||
| 354 | + * @return true:删除成功 false:删除失败 | ||
| 355 | + */ | ||
| 356 | + @Override | ||
| 357 | + public boolean delete(String deviceId) { | ||
| 358 | + int result = deviceMapper.del(deviceId); | ||
| 359 | + | ||
| 360 | + return result > 0; | ||
| 361 | + } | ||
| 362 | + | ||
| 363 | + /** | ||
| 364 | + * 更新设备在线 | ||
| 365 | + * | ||
| 366 | + * @param deviceId 设备ID | ||
| 367 | + * @return true:更新成功 false:更新失败 | ||
| 368 | + */ | ||
| 369 | + @Override | ||
| 370 | + public boolean online(String deviceId) { | ||
| 371 | + Device device = deviceMapper.getDeviceByDeviceId(deviceId); | ||
| 372 | + device.setOnline(1); | ||
| 373 | + return deviceMapper.update(device) > 0; | ||
| 374 | + } | ||
| 375 | + | ||
| 376 | + /** | ||
| 377 | + * 更新设备离线 | ||
| 378 | + * | ||
| 379 | + * @param deviceId 设备ID | ||
| 380 | + * @return true:更新成功 false:更新失败 | ||
| 381 | + */ | ||
| 382 | + @Override | ||
| 383 | + public boolean outline(String deviceId) { | ||
| 384 | +// Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 385 | +// if (device == null) return false; | ||
| 386 | +// device.setOnline(0); | ||
| 387 | +// return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 388 | + | ||
| 389 | + Device device = deviceMapper.getDeviceByDeviceId(deviceId); | ||
| 390 | + device.setOnline(0); | ||
| 391 | + return deviceMapper.update(device) > 0; | ||
| 392 | + } | ||
| 393 | + | ||
| 394 | + | ||
| 395 | + @Override | ||
| 396 | + public void cleanChannelsForDevice(String deviceId) { | ||
| 397 | + int result = deviceChannelMapper.cleanChannelsByDeviceId(deviceId); | ||
| 398 | + } | ||
| 399 | + | ||
| 400 | + | ||
| 401 | +} |
src/main/java/com/genersoft/iot/vmp/storager/jdbc/VideoManagerJdbcStoragerImpl.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.storager.jdbc; | ||
| 2 | - | ||
| 3 | -import java.util.List; | ||
| 4 | -import java.util.Map; | ||
| 5 | - | ||
| 6 | -import com.genersoft.iot.vmp.common.PageResult; | ||
| 7 | -import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 8 | -import com.genersoft.iot.vmp.conf.MediaServerConfig; | ||
| 9 | -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 10 | -import org.springframework.stereotype.Component; | ||
| 11 | -import org.springframework.stereotype.Service; | ||
| 12 | - | ||
| 13 | -import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 14 | -import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 15 | -import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 16 | - | ||
| 17 | -/** | ||
| 18 | - * @Description:视频设备数据存储-jdbc实现 | ||
| 19 | - * @author: swwheihei | ||
| 20 | - * @date: 2020年5月6日 下午2:28:12 | ||
| 21 | - */ | ||
| 22 | -@Component("jdbcStorager") | ||
| 23 | -public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager { | ||
| 24 | - | ||
| 25 | - @Override | ||
| 26 | - public boolean updateMediaInfo(MediaServerConfig mediaServerConfig) { | ||
| 27 | - return false; | ||
| 28 | - } | ||
| 29 | - | ||
| 30 | - @Override | ||
| 31 | - public MediaServerConfig getMediaInfo() { | ||
| 32 | - return null; | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - /** | ||
| 36 | - * 根据设备ID判断设备是否存在 | ||
| 37 | - * | ||
| 38 | - * @param deviceId 设备ID | ||
| 39 | - * @return true:存在 false:不存在 | ||
| 40 | - */ | ||
| 41 | - @Override | ||
| 42 | - public boolean exists(String deviceId) { | ||
| 43 | - // TODO Auto-generated method stub | ||
| 44 | - return false; | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - /** | ||
| 48 | - * 视频设备创建 | ||
| 49 | - * | ||
| 50 | - * @param device 设备对象 | ||
| 51 | - * @return true:创建成功 false:创建失败 | ||
| 52 | - */ | ||
| 53 | - @Override | ||
| 54 | - public boolean create(Device device) { | ||
| 55 | - // TODO Auto-generated method stub | ||
| 56 | - return false; | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - @Override | ||
| 60 | - public boolean updateDevice(Device device) { | ||
| 61 | - return false; | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - @Override | ||
| 65 | - public void updateChannel(String deviceId, DeviceChannel channel) { | ||
| 66 | - | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - /** | ||
| 71 | - * 获取设备 | ||
| 72 | - * | ||
| 73 | - * @param deviceId 设备ID | ||
| 74 | - * @return Device 设备对象 | ||
| 75 | - */ | ||
| 76 | - @Override | ||
| 77 | - public Device queryVideoDevice(String deviceId) { | ||
| 78 | - // TODO Auto-generated method stub | ||
| 79 | - return null; | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - @Override | ||
| 83 | - public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 84 | - return null; | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - | ||
| 88 | - @Override | ||
| 89 | - public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { | ||
| 90 | - return null; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - @Override | ||
| 94 | - public DeviceChannel queryChannel(String deviceId, String channelId) { | ||
| 95 | - return null; | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - @Override | ||
| 99 | - public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) { | ||
| 100 | - return null; | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - /** | ||
| 104 | - * 获取多个设备 | ||
| 105 | - * | ||
| 106 | - * @param deviceIds 设备ID数组 | ||
| 107 | - * @return List<Device> 设备对象数组 | ||
| 108 | - */ | ||
| 109 | - @Override | ||
| 110 | - public List<Device> queryVideoDeviceList(String[] deviceIds) { | ||
| 111 | - // TODO Auto-generated method stub | ||
| 112 | - return null; | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - /** | ||
| 116 | - * 删除设备 | ||
| 117 | - * | ||
| 118 | - * @param deviceId 设备ID | ||
| 119 | - * @return true:删除成功 false:删除失败 | ||
| 120 | - */ | ||
| 121 | - @Override | ||
| 122 | - public boolean delete(String deviceId) { | ||
| 123 | - // TODO Auto-generated method stub | ||
| 124 | - return false; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - /** | ||
| 128 | - * 更新设备在线 | ||
| 129 | - * | ||
| 130 | - * @param deviceId 设备ID | ||
| 131 | - * @return true:更新成功 false:更新失败 | ||
| 132 | - */ | ||
| 133 | - @Override | ||
| 134 | - public boolean online(String deviceId) { | ||
| 135 | - // TODO Auto-generated method stub | ||
| 136 | - return false; | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - /** | ||
| 140 | - * 更新设备离线 | ||
| 141 | - * | ||
| 142 | - * @param deviceId 设备ID | ||
| 143 | - * @return true:更新成功 false:更新失败 | ||
| 144 | - */ | ||
| 145 | - @Override | ||
| 146 | - public boolean outline(String deviceId) { | ||
| 147 | - // TODO Auto-generated method stub | ||
| 148 | - return false; | ||
| 149 | - } | ||
| 150 | - | ||
| 151 | - @Override | ||
| 152 | - public boolean stopPlay(StreamInfo streamInfo) { | ||
| 153 | - return false; | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - @Override | ||
| 157 | - public StreamInfo queryPlay(StreamInfo streamInfo) { | ||
| 158 | - return null; | ||
| 159 | - } | ||
| 160 | - | ||
| 161 | - @Override | ||
| 162 | - public PageResult querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 163 | - return null; | ||
| 164 | - } | ||
| 165 | - | ||
| 166 | - @Override | ||
| 167 | - public void updateCatch() { | ||
| 168 | - System.out.println("##################"); | ||
| 169 | - } | ||
| 170 | - | ||
| 171 | - @Override | ||
| 172 | - public void cleanChannelsForDevice(String deviceId) { | ||
| 173 | - | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | - @Override | ||
| 177 | - public boolean startPlay(StreamInfo stream) { | ||
| 178 | - return false; | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - | ||
| 182 | - @Override | ||
| 183 | - public StreamInfo queryPlayByDevice(String deviceId, String code) { | ||
| 184 | - return null; | ||
| 185 | - } | ||
| 186 | - | ||
| 187 | - @Override | ||
| 188 | - public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) { | ||
| 189 | - | ||
| 190 | - return null; | ||
| 191 | - } | ||
| 192 | - | ||
| 193 | - @Override | ||
| 194 | - public boolean startPlayback(StreamInfo streamInfo) { | ||
| 195 | - return false; | ||
| 196 | - } | ||
| 197 | - | ||
| 198 | - @Override | ||
| 199 | - public boolean stopPlayback(StreamInfo streamInfo) { | ||
| 200 | - return false; | ||
| 201 | - } | ||
| 202 | - | ||
| 203 | - @Override | ||
| 204 | - public StreamInfo queryPlaybackByDevice(String deviceId, String channelId) { | ||
| 205 | - return null; | ||
| 206 | - } | ||
| 207 | - | ||
| 208 | - @Override | ||
| 209 | - public StreamInfo queryPlayByStreamId(String streamId) { | ||
| 210 | - return null; | ||
| 211 | - } | ||
| 212 | - | ||
| 213 | - @Override | ||
| 214 | - public StreamInfo queryPlaybackByStreamId(String streamId) { | ||
| 215 | - return null; | ||
| 216 | - } | ||
| 217 | -} |
src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.storager.redis; | ||
| 2 | - | ||
| 3 | -import java.util.*; | ||
| 4 | - | ||
| 5 | -import com.alibaba.fastjson.JSON; | ||
| 6 | -import com.alibaba.fastjson.JSONObject; | ||
| 7 | -import com.genersoft.iot.vmp.common.PageResult; | ||
| 8 | -import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 9 | -import com.genersoft.iot.vmp.conf.MediaServerConfig; | ||
| 10 | -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 11 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | -import org.springframework.stereotype.Component; | ||
| 13 | - | ||
| 14 | -import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 15 | -import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 16 | -import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 17 | -import com.genersoft.iot.vmp.utils.redis.RedisUtil; | ||
| 18 | -import org.springframework.util.StringUtils; | ||
| 19 | - | ||
| 20 | -/** | ||
| 21 | - * @Description:视频设备数据存储-redis实现 | ||
| 22 | - * @author: swwheihei | ||
| 23 | - * @date: 2020年5月6日 下午2:31:42 | ||
| 24 | - */ | ||
| 25 | -@Component("redisStorager") | ||
| 26 | -public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | ||
| 27 | - | ||
| 28 | - @Autowired | ||
| 29 | - private RedisUtil redis; | ||
| 30 | - | ||
| 31 | - private HashMap<String, HashMap<String, HashSet<String>>> deviceMap = new HashMap<>(); | ||
| 32 | - | ||
| 33 | - | ||
| 34 | - /** | ||
| 35 | - * 根据设备ID判断设备是否存在 | ||
| 36 | - * | ||
| 37 | - * @param deviceId 设备ID | ||
| 38 | - * @return true:存在 false:不存在 | ||
| 39 | - */ | ||
| 40 | - @Override | ||
| 41 | - public boolean exists(String deviceId) { | ||
| 42 | - return redis.hasKey(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - /** | ||
| 46 | - * 视频设备创建 | ||
| 47 | - * | ||
| 48 | - * @param device 设备对象 | ||
| 49 | - * @return true:创建成功 false:创建失败 | ||
| 50 | - */ | ||
| 51 | - @Override | ||
| 52 | - public boolean create(Device device) { | ||
| 53 | - return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - /** | ||
| 59 | - * 视频设备更新 | ||
| 60 | - * | ||
| 61 | - * @param device 设备对象 | ||
| 62 | - * @return true:更新成功 false:更新失败 | ||
| 63 | - */ | ||
| 64 | - @Override | ||
| 65 | - public boolean updateDevice(Device device) { | ||
| 66 | - if (deviceMap.get(device.getDeviceId()) == null) { | ||
| 67 | - deviceMap.put(device.getDeviceId(), new HashMap<String, HashSet<String>>()); | ||
| 68 | - } | ||
| 69 | - // 更新device中的通道数量 | ||
| 70 | - device.setChannelCount(deviceMap.get(device.getDeviceId()).size()); | ||
| 71 | - // 存储device | ||
| 72 | - return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 73 | - | ||
| 74 | - | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - @Override | ||
| 78 | - public void updateChannel(String deviceId, DeviceChannel channel) { | ||
| 79 | - String channelId = channel.getChannelId(); | ||
| 80 | - HashMap<String, HashSet<String>> channelMap = deviceMap.get(deviceId); | ||
| 81 | - if (channelMap == null) return; | ||
| 82 | - // 作为父设备, 确定自己的子节点数 | ||
| 83 | - if (channelMap.get(channelId) == null) { | ||
| 84 | - channelMap.put(channelId, new HashSet<String>()); | ||
| 85 | - }else if (channelMap.get(channelId).size() > 0) { | ||
| 86 | - channel.setSubCount(channelMap.get(channelId).size()); | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - // 存储通道 | ||
| 90 | - redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 91 | - "_" + channel.getChannelId() + | ||
| 92 | - "_" + (channel.getStatus() == 1 ? "on":"off") + | ||
| 93 | - "_" + (channelMap.get(channelId).size() > 0)+ | ||
| 94 | - "_" + (StringUtils.isEmpty(channel.getParentId())?null:channel.getParentId()), | ||
| 95 | - channel); | ||
| 96 | - // 更新device中的通道数量 | ||
| 97 | - Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 98 | - device.setChannelCount(deviceMap.get(deviceId).size()); | ||
| 99 | - redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 100 | - | ||
| 101 | - | ||
| 102 | - // 如果有父设备,更新父设备内子节点数 | ||
| 103 | - String parentId = channel.getParentId(); | ||
| 104 | - if (!StringUtils.isEmpty(parentId) && !parentId.equals(deviceId)) { | ||
| 105 | - | ||
| 106 | - if (channelMap.get(parentId) == null) { | ||
| 107 | - channelMap.put(parentId, new HashSet<String>()); | ||
| 108 | - } | ||
| 109 | - channelMap.get(parentId).add(channelId); | ||
| 110 | - | ||
| 111 | - DeviceChannel deviceChannel = queryChannel(deviceId, parentId); | ||
| 112 | - if (deviceChannel != null) { | ||
| 113 | - deviceChannel.setSubCount(channelMap.get(parentId).size()); | ||
| 114 | - redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 115 | - "_" + deviceChannel.getChannelId() + | ||
| 116 | - "_" + (deviceChannel.getStatus() == 1 ? "on":"off") + | ||
| 117 | - "_" + (channelMap.get(deviceChannel.getChannelId()).size() > 0)+ | ||
| 118 | - "_" + (StringUtils.isEmpty(deviceChannel.getParentId())?null:deviceChannel.getParentId()), | ||
| 119 | - deviceChannel); | ||
| 120 | - | ||
| 121 | - } | ||
| 122 | - } | ||
| 123 | - | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | - /** | ||
| 127 | - * 获取设备 | ||
| 128 | - * | ||
| 129 | - * @param deviceId 设备ID | ||
| 130 | - * @return Device 设备对象 | ||
| 131 | - */ | ||
| 132 | - @Override | ||
| 133 | - public Device queryVideoDevice(String deviceId) { | ||
| 134 | - return (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 135 | - } | ||
| 136 | - | ||
| 137 | - @Override | ||
| 138 | - public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 139 | - // 获取到所有正在播放的流 | ||
| 140 | - Map<String, StreamInfo> stringStreamInfoMap = queryPlayByDeviceId(deviceId); | ||
| 141 | - List<DeviceChannel> result = new ArrayList<>(); | ||
| 142 | - PageResult pageResult = new PageResult<DeviceChannel>(); | ||
| 143 | - String queryContent = "*"; | ||
| 144 | - if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); | ||
| 145 | - String queryHasSubChannel = "*"; | ||
| 146 | - if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; | ||
| 147 | - String queryOnline = "*"; | ||
| 148 | - if (!StringUtils.isEmpty(online)) queryOnline = online; | ||
| 149 | - String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 150 | - "_" + queryContent + // 搜索编号和名称 | ||
| 151 | - "_" + queryOnline + // 搜索是否在线 | ||
| 152 | - "_" + queryHasSubChannel + // 搜索是否含有子节点 | ||
| 153 | - "_" + "*"; | ||
| 154 | - List<Object> deviceChannelList = redis.scan(queryStr); | ||
| 155 | - //对查询结果排序,避免出现通道排列顺序乱序的情况 | ||
| 156 | - Collections.sort(deviceChannelList,new Comparator<Object>(){ | ||
| 157 | - @Override | ||
| 158 | - public int compare(Object o1, Object o2) { | ||
| 159 | - return o1.toString().compareToIgnoreCase(o2.toString()); | ||
| 160 | - } | ||
| 161 | - }); | ||
| 162 | - pageResult.setPage(page); | ||
| 163 | - pageResult.setCount(count); | ||
| 164 | - pageResult.setTotal(deviceChannelList.size()); | ||
| 165 | - int maxCount = (page + 1 ) * count; | ||
| 166 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 167 | - for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | ||
| 168 | - DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); | ||
| 169 | - StreamInfo streamInfo = stringStreamInfoMap.get(deviceId + "_" + deviceChannel.getChannelId()); | ||
| 170 | - deviceChannel.setPlay(streamInfo != null); | ||
| 171 | - if (streamInfo != null) deviceChannel.setStreamId(streamInfo.getStreamId()); | ||
| 172 | - result.add(deviceChannel); | ||
| 173 | - } | ||
| 174 | - pageResult.setData(result); | ||
| 175 | - } | ||
| 176 | - | ||
| 177 | - return pageResult; | ||
| 178 | - } | ||
| 179 | - | ||
| 180 | - | ||
| 181 | - | ||
| 182 | - @Override | ||
| 183 | - public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { | ||
| 184 | - List<DeviceChannel> result = new ArrayList<>(); | ||
| 185 | -// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 186 | - List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 187 | - | ||
| 188 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 189 | - for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 190 | - result.add((DeviceChannel)redis.get((String) deviceChannelList.get(i))); | ||
| 191 | - } | ||
| 192 | - } | ||
| 193 | - return result; | ||
| 194 | - } | ||
| 195 | - | ||
| 196 | - @Override | ||
| 197 | - public PageResult querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 198 | - List<DeviceChannel> allDeviceChannels = new ArrayList<>(); | ||
| 199 | - String queryContent = "*"; | ||
| 200 | - if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); | ||
| 201 | - String queryHasSubChannel = "*"; | ||
| 202 | - if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; | ||
| 203 | - String queryOnline = "*"; | ||
| 204 | - if (!StringUtils.isEmpty(online)) queryOnline = online; | ||
| 205 | - String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 206 | - "_" + queryContent + // 搜索编号和名称 | ||
| 207 | - "_" + queryOnline + // 搜索是否在线 | ||
| 208 | - "_" + queryHasSubChannel + // 搜索是否含有子节点 | ||
| 209 | - "_" + parentChannelId; | ||
| 210 | - | ||
| 211 | -// List<Object> deviceChannelList = redis.keys(queryStr); | ||
| 212 | - List<Object> deviceChannelList = redis.scan(queryStr); | ||
| 213 | - | ||
| 214 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 215 | - for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 216 | - DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); | ||
| 217 | - if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { | ||
| 218 | - allDeviceChannels.add(deviceChannel); | ||
| 219 | - } | ||
| 220 | - } | ||
| 221 | - } | ||
| 222 | - int maxCount = (page + 1 ) * count; | ||
| 223 | - PageResult pageResult = new PageResult<DeviceChannel>(); | ||
| 224 | - pageResult.setPage(page); | ||
| 225 | - pageResult.setCount(count); | ||
| 226 | - pageResult.setTotal(allDeviceChannels.size()); | ||
| 227 | - | ||
| 228 | - if (allDeviceChannels.size() > 0) { | ||
| 229 | - pageResult.setData(allDeviceChannels.subList( | ||
| 230 | - page * count, pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() | ||
| 231 | - )); | ||
| 232 | - } | ||
| 233 | - return pageResult; | ||
| 234 | - } | ||
| 235 | - | ||
| 236 | - public List<DeviceChannel> querySubChannels(String deviceId, String parentChannelId) { | ||
| 237 | - List<DeviceChannel> allDeviceChannels = new ArrayList<>(); | ||
| 238 | -// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 239 | - List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 240 | - | ||
| 241 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 242 | - for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 243 | - DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); | ||
| 244 | - if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { | ||
| 245 | - allDeviceChannels.add(deviceChannel); | ||
| 246 | - } | ||
| 247 | - } | ||
| 248 | - } | ||
| 249 | - | ||
| 250 | - return allDeviceChannels; | ||
| 251 | - } | ||
| 252 | - | ||
| 253 | - @Override | ||
| 254 | - public DeviceChannel queryChannel(String deviceId, String channelId) { | ||
| 255 | - DeviceChannel deviceChannel = null; | ||
| 256 | -// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 257 | - List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 258 | - "_" + channelId + "*"); | ||
| 259 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 260 | - deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(0)); | ||
| 261 | - } | ||
| 262 | - return deviceChannel; | ||
| 263 | - } | ||
| 264 | - | ||
| 265 | - | ||
| 266 | - /** | ||
| 267 | - * 获取多个设备 | ||
| 268 | - * | ||
| 269 | - * @param deviceIds 设备ID数组 | ||
| 270 | - * @return List<Device> 设备对象数组 | ||
| 271 | - */ | ||
| 272 | - @Override | ||
| 273 | - public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) { | ||
| 274 | - List<Device> devices = new ArrayList<>(); | ||
| 275 | - PageResult pageResult = new PageResult<Device>(); | ||
| 276 | - pageResult.setPage(page); | ||
| 277 | - pageResult.setCount(count); | ||
| 278 | - Device device = null; | ||
| 279 | - | ||
| 280 | - if (deviceIds == null || deviceIds.length == 0) { | ||
| 281 | - | ||
| 282 | -// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 283 | - List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 284 | - pageResult.setTotal(deviceIdList.size()); | ||
| 285 | - int maxCount = (page + 1)* count; | ||
| 286 | - for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | ||
| 287 | - // devices.add((Device)redis.get((String)deviceIdList.get(i))); | ||
| 288 | - device =(Device)redis.get((String)deviceIdList.get(i)); | ||
| 289 | - if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 290 | - // outline(device.getDeviceId()); | ||
| 291 | - } | ||
| 292 | - devices.add(device); | ||
| 293 | - } | ||
| 294 | - } else { | ||
| 295 | - for (int i = 0; i < deviceIds.length; i++) { | ||
| 296 | - // devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | ||
| 297 | - device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); | ||
| 298 | - if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 299 | - // outline(device.getDeviceId()); | ||
| 300 | - } | ||
| 301 | - devices.add(device); | ||
| 302 | - } | ||
| 303 | - } | ||
| 304 | - pageResult.setData(devices); | ||
| 305 | - return pageResult; | ||
| 306 | - } | ||
| 307 | - | ||
| 308 | - /** | ||
| 309 | - * 获取多个设备 | ||
| 310 | - * | ||
| 311 | - * @param deviceIds 设备ID数组 | ||
| 312 | - * @return List<Device> 设备对象数组 | ||
| 313 | - */ | ||
| 314 | - @Override | ||
| 315 | - public List<Device> queryVideoDeviceList(String[] deviceIds) { | ||
| 316 | - List<Device> devices = new ArrayList<>(); | ||
| 317 | - Device device = null; | ||
| 318 | - | ||
| 319 | - if (deviceIds == null || deviceIds.length == 0) { | ||
| 320 | -// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 321 | - List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 322 | - for (int i = 0; i < deviceIdList.size(); i++) { | ||
| 323 | - device =(Device)redis.get((String)deviceIdList.get(i)); | ||
| 324 | - if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 325 | - outline(device.getDeviceId()); | ||
| 326 | - } | ||
| 327 | - devices.add(device); | ||
| 328 | - } | ||
| 329 | - } else { | ||
| 330 | - for (int i = 0; i < deviceIds.length; i++) { | ||
| 331 | - device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); | ||
| 332 | - if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | ||
| 333 | - outline(device.getDeviceId()); | ||
| 334 | - } | ||
| 335 | - devices.add(device); | ||
| 336 | - } | ||
| 337 | - } | ||
| 338 | - return devices; | ||
| 339 | - } | ||
| 340 | - | ||
| 341 | - /** | ||
| 342 | - * 删除设备 | ||
| 343 | - * | ||
| 344 | - * @param deviceId 设备ID | ||
| 345 | - * @return true:删除成功 false:删除失败 | ||
| 346 | - */ | ||
| 347 | - @Override | ||
| 348 | - public boolean delete(String deviceId) { | ||
| 349 | - return redis.del(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 350 | - } | ||
| 351 | - | ||
| 352 | - /** | ||
| 353 | - * 更新设备在线 | ||
| 354 | - * | ||
| 355 | - * @param deviceId 设备ID | ||
| 356 | - * @return true:更新成功 false:更新失败 | ||
| 357 | - */ | ||
| 358 | - @Override | ||
| 359 | - public boolean online(String deviceId) { | ||
| 360 | - Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 361 | - device.setOnline(1); | ||
| 362 | - return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 363 | - } | ||
| 364 | - | ||
| 365 | - /** | ||
| 366 | - * 更新设备离线 | ||
| 367 | - * | ||
| 368 | - * @param deviceId 设备ID | ||
| 369 | - * @return true:更新成功 false:更新失败 | ||
| 370 | - */ | ||
| 371 | - @Override | ||
| 372 | - public boolean outline(String deviceId) { | ||
| 373 | - Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 374 | - if (device == null) return false; | ||
| 375 | - device.setOnline(0); | ||
| 376 | - return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 377 | - } | ||
| 378 | - | ||
| 379 | - /** | ||
| 380 | - * 开始播放时将流存入redis | ||
| 381 | - * | ||
| 382 | - * @return | ||
| 383 | - */ | ||
| 384 | - @Override | ||
| 385 | - public boolean startPlay(StreamInfo stream) { | ||
| 386 | - return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()), | ||
| 387 | - stream); | ||
| 388 | - } | ||
| 389 | - | ||
| 390 | - /** | ||
| 391 | - * 停止播放时从redis删除 | ||
| 392 | - * | ||
| 393 | - * @return | ||
| 394 | - */ | ||
| 395 | - @Override | ||
| 396 | - public boolean stopPlay(StreamInfo streamInfo) { | ||
| 397 | - if (streamInfo == null) return false; | ||
| 398 | - DeviceChannel deviceChannel = queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId()); | ||
| 399 | - if (deviceChannel != null) { | ||
| 400 | - deviceChannel.setStreamId(null); | ||
| 401 | - deviceChannel.setPlay(false); | ||
| 402 | - updateChannel(streamInfo.getDeviceID(), deviceChannel); | ||
| 403 | - } | ||
| 404 | - return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | ||
| 405 | - streamInfo.getStreamId(), | ||
| 406 | - streamInfo.getDeviceID(), | ||
| 407 | - streamInfo.getCahnnelId())); | ||
| 408 | - } | ||
| 409 | - | ||
| 410 | - /** | ||
| 411 | - * 查询播放列表 | ||
| 412 | - * @return | ||
| 413 | - */ | ||
| 414 | - @Override | ||
| 415 | - public StreamInfo queryPlay(StreamInfo streamInfo) { | ||
| 416 | - return (StreamInfo)redis.get(String.format("%S_%s_%s_%s", | ||
| 417 | - VideoManagerConstants.PLAYER_PREFIX, | ||
| 418 | - streamInfo.getStreamId(), | ||
| 419 | - streamInfo.getDeviceID(), | ||
| 420 | - streamInfo.getCahnnelId())); | ||
| 421 | - } | ||
| 422 | - @Override | ||
| 423 | - public StreamInfo queryPlayByStreamId(String steamId) { | ||
| 424 | - List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, steamId)); | ||
| 425 | - if (playLeys == null || playLeys.size() == 0) return null; | ||
| 426 | - return (StreamInfo)redis.get(playLeys.get(0).toString()); | ||
| 427 | - } | ||
| 428 | - | ||
| 429 | - @Override | ||
| 430 | - public StreamInfo queryPlaybackByStreamId(String steamId) { | ||
| 431 | - List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, steamId)); | ||
| 432 | - if (playLeys == null || playLeys.size() == 0) return null; | ||
| 433 | - return (StreamInfo)redis.get(playLeys.get(0).toString()); | ||
| 434 | - } | ||
| 435 | - | ||
| 436 | - @Override | ||
| 437 | - public StreamInfo queryPlayByDevice(String deviceId, String code) { | ||
| 438 | -// List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | ||
| 439 | - List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | ||
| 440 | - deviceId, | ||
| 441 | - code)); | ||
| 442 | - if (playLeys == null || playLeys.size() == 0) return null; | ||
| 443 | - return (StreamInfo)redis.get(playLeys.get(0).toString()); | ||
| 444 | - } | ||
| 445 | - | ||
| 446 | - /** | ||
| 447 | - * 更新流媒体信息 | ||
| 448 | - * @param mediaServerConfig | ||
| 449 | - * @return | ||
| 450 | - */ | ||
| 451 | - @Override | ||
| 452 | - public boolean updateMediaInfo(MediaServerConfig mediaServerConfig) { | ||
| 453 | - return redis.set(VideoManagerConstants.MEDIA_SERVER_PREFIX,mediaServerConfig); | ||
| 454 | - } | ||
| 455 | - | ||
| 456 | - /** | ||
| 457 | - * 获取流媒体信息 | ||
| 458 | - * @return | ||
| 459 | - */ | ||
| 460 | - @Override | ||
| 461 | - public MediaServerConfig getMediaInfo() { | ||
| 462 | - return (MediaServerConfig)redis.get(VideoManagerConstants.MEDIA_SERVER_PREFIX); | ||
| 463 | - } | ||
| 464 | - | ||
| 465 | - @Override | ||
| 466 | - public void updateCatch() { | ||
| 467 | - deviceMap = new HashMap<>(); | ||
| 468 | - // 更新设备 | ||
| 469 | - List<Device> devices = queryVideoDeviceList(null); | ||
| 470 | - if (devices == null && devices.size() == 0) return; | ||
| 471 | - for (Device device : devices) { | ||
| 472 | - // 更新设备下的通道 | ||
| 473 | - HashMap<String, HashSet<String>> channelMap = new HashMap<String, HashSet<String>>(); | ||
| 474 | - List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + | ||
| 475 | - device.getDeviceId() + "_" + "*"); | ||
| 476 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 477 | - for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 478 | - String key = (String)deviceChannelList.get(i); | ||
| 479 | - String[] s = key.split("_"); | ||
| 480 | - String channelId = s[3]; | ||
| 481 | - HashSet<String> subChannel = channelMap.get(channelId); | ||
| 482 | - if (subChannel == null) { | ||
| 483 | - subChannel = new HashSet<>(); | ||
| 484 | - } | ||
| 485 | - System.out.println(key); | ||
| 486 | - if (s.length == 6 && !"null".equals(s[5])) { | ||
| 487 | - subChannel.add(s[5]); | ||
| 488 | - } | ||
| 489 | - channelMap.put(channelId, subChannel); | ||
| 490 | - } | ||
| 491 | - } | ||
| 492 | - deviceMap.put(device.getDeviceId(),channelMap); | ||
| 493 | - } | ||
| 494 | - System.out.println(); | ||
| 495 | - } | ||
| 496 | - | ||
| 497 | - @Override | ||
| 498 | - public void cleanChannelsForDevice(String deviceId) { | ||
| 499 | - List<DeviceChannel> result = new ArrayList<>(); | ||
| 500 | -// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 501 | - List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 502 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 503 | - for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 504 | - redis.del((String)deviceChannelList.get(i)); | ||
| 505 | - } | ||
| 506 | - } | ||
| 507 | - } | ||
| 508 | - | ||
| 509 | - @Override | ||
| 510 | - public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) { | ||
| 511 | - Map<String, StreamInfo> streamInfos = new HashMap<>(); | ||
| 512 | -// List<Object> playLeys = redis.keys(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); | ||
| 513 | - List<Object> playLeys = redis.scan(String.format("%S_*_%S_*", VideoManagerConstants.PLAYER_PREFIX, deviceId)); | ||
| 514 | - if (playLeys.size() == 0) return streamInfos; | ||
| 515 | - for (int i = 0; i < playLeys.size(); i++) { | ||
| 516 | - String key = (String) playLeys.get(i); | ||
| 517 | - StreamInfo streamInfo = (StreamInfo)redis.get(key); | ||
| 518 | - streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getCahnnelId(), streamInfo); | ||
| 519 | - } | ||
| 520 | - return streamInfos; | ||
| 521 | - } | ||
| 522 | - | ||
| 523 | - | ||
| 524 | - @Override | ||
| 525 | - public boolean startPlayback(StreamInfo stream) { | ||
| 526 | - return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getStreamId(),stream.getDeviceID(), stream.getCahnnelId()), | ||
| 527 | - stream); | ||
| 528 | - } | ||
| 529 | - | ||
| 530 | - | ||
| 531 | - @Override | ||
| 532 | - public boolean stopPlayback(StreamInfo streamInfo) { | ||
| 533 | - if (streamInfo == null) return false; | ||
| 534 | - DeviceChannel deviceChannel = queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId()); | ||
| 535 | - if (deviceChannel != null) { | ||
| 536 | - deviceChannel.setStreamId(null); | ||
| 537 | - deviceChannel.setPlay(false); | ||
| 538 | - updateChannel(streamInfo.getDeviceID(), deviceChannel); | ||
| 539 | - } | ||
| 540 | - return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | ||
| 541 | - streamInfo.getStreamId(), | ||
| 542 | - streamInfo.getDeviceID(), | ||
| 543 | - streamInfo.getCahnnelId())); | ||
| 544 | - } | ||
| 545 | - | ||
| 546 | - @Override | ||
| 547 | - public StreamInfo queryPlaybackByDevice(String deviceId, String code) { | ||
| 548 | - String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | ||
| 549 | - deviceId, | ||
| 550 | - code); | ||
| 551 | - List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | ||
| 552 | - deviceId, | ||
| 553 | - code)); | ||
| 554 | - if (playLeys == null || playLeys.size() == 0) { | ||
| 555 | - playLeys = redis.scan(String.format("%S_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | ||
| 556 | - deviceId)); | ||
| 557 | - } | ||
| 558 | - if (playLeys == null || playLeys.size() == 0) return null; | ||
| 559 | - return (StreamInfo)redis.get(playLeys.get(0).toString()); | ||
| 560 | - } | ||
| 561 | -} |
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
| @@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | @@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | ||
| 8 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | 8 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 9 | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; | 9 | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; |
| 10 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; | 10 | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; |
| 11 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 11 | import com.genersoft.iot.vmp.vmanager.service.IPlayService; | 12 | import com.genersoft.iot.vmp.vmanager.service.IPlayService; |
| 12 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
| @@ -46,6 +47,9 @@ public class PlayController { | @@ -46,6 +47,9 @@ public class PlayController { | ||
| 46 | private IVideoManagerStorager storager; | 47 | private IVideoManagerStorager storager; |
| 47 | 48 | ||
| 48 | @Autowired | 49 | @Autowired |
| 50 | + private IRedisCatchStorage redisCatchStorage; | ||
| 51 | + | ||
| 52 | + @Autowired | ||
| 49 | private ZLMRESTfulUtils zlmresTfulUtils; | 53 | private ZLMRESTfulUtils zlmresTfulUtils; |
| 50 | 54 | ||
| 51 | @Autowired | 55 | @Autowired |
| @@ -60,7 +64,7 @@ public class PlayController { | @@ -60,7 +64,7 @@ public class PlayController { | ||
| 60 | 64 | ||
| 61 | 65 | ||
| 62 | Device device = storager.queryVideoDevice(deviceId); | 66 | Device device = storager.queryVideoDevice(deviceId); |
| 63 | - StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId); | 67 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); |
| 64 | 68 | ||
| 65 | UUID uuid = UUID.randomUUID(); | 69 | UUID uuid = UUID.randomUUID(); |
| 66 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(); | 70 | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(); |
| @@ -89,7 +93,7 @@ public class PlayController { | @@ -89,7 +93,7 @@ public class PlayController { | ||
| 89 | msg.setData(JSON.toJSONString(streamInfo)); | 93 | msg.setData(JSON.toJSONString(streamInfo)); |
| 90 | resultHolder.invokeResult(msg); | 94 | resultHolder.invokeResult(msg); |
| 91 | } else { | 95 | } else { |
| 92 | - storager.stopPlay(streamInfo); | 96 | + redisCatchStorage.stopPlay(streamInfo); |
| 93 | cmder.playStreamCmd(device, channelId, (JSONObject response) -> { | 97 | cmder.playStreamCmd(device, channelId, (JSONObject response) -> { |
| 94 | logger.info("收到订阅消息: " + response.toJSONString()); | 98 | logger.info("收到订阅消息: " + response.toJSONString()); |
| 95 | playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString()); | 99 | playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString()); |
| @@ -117,25 +121,59 @@ public class PlayController { | @@ -117,25 +121,59 @@ public class PlayController { | ||
| 117 | } | 121 | } |
| 118 | 122 | ||
| 119 | @PostMapping("/play/{streamId}/stop") | 123 | @PostMapping("/play/{streamId}/stop") |
| 120 | - public ResponseEntity<String> playStop(@PathVariable String streamId) { | ||
| 121 | - | ||
| 122 | - cmder.streamByeCmd(streamId); | ||
| 123 | - StreamInfo streamInfo = storager.queryPlayByStreamId(streamId); | ||
| 124 | - if (streamInfo == null) | ||
| 125 | - return new ResponseEntity<String>("streamId not found", HttpStatus.OK); | ||
| 126 | - storager.stopPlay(streamInfo); | ||
| 127 | - if (logger.isDebugEnabled()) { | ||
| 128 | - logger.debug(String.format("设备预览停止API调用,streamId:%s", streamId)); | ||
| 129 | - } | 124 | + public DeferredResult<ResponseEntity<String>> playStop(@PathVariable String streamId) { |
| 125 | + | ||
| 126 | + logger.debug(String.format("设备预览/回放停止API调用,streamId:%s", streamId)); | ||
| 127 | + | ||
| 128 | + UUID uuid = UUID.randomUUID(); | ||
| 129 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(); | ||
| 130 | + | ||
| 131 | + // 录像查询以channelId作为deviceId查询 | ||
| 132 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_STOP + uuid, result); | ||
| 133 | + | ||
| 134 | + cmder.streamByeCmd(streamId, event -> { | ||
| 135 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); | ||
| 136 | + if (streamInfo == null) { | ||
| 137 | + RequestMessage msg = new RequestMessage(); | ||
| 138 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); | ||
| 139 | + msg.setData("streamId not found"); | ||
| 140 | + resultHolder.invokeResult(msg); | ||
| 141 | + redisCatchStorage.stopPlay(streamInfo); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + RequestMessage msg = new RequestMessage(); | ||
| 145 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid); | ||
| 146 | + Response response = event.getResponse(); | ||
| 147 | + msg.setData(String.format("success")); | ||
| 148 | + resultHolder.invokeResult(msg); | ||
| 149 | + }); | ||
| 150 | + | ||
| 151 | + | ||
| 130 | 152 | ||
| 131 | if (streamId != null) { | 153 | if (streamId != null) { |
| 132 | JSONObject json = new JSONObject(); | 154 | JSONObject json = new JSONObject(); |
| 133 | json.put("streamId", streamId); | 155 | json.put("streamId", streamId); |
| 134 | - return new ResponseEntity<String>(json.toString(), HttpStatus.OK); | 156 | + RequestMessage msg = new RequestMessage(); |
| 157 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); | ||
| 158 | + msg.setData(json.toString()); | ||
| 159 | + resultHolder.invokeResult(msg); | ||
| 135 | } else { | 160 | } else { |
| 136 | - logger.warn("设备预览停止API调用失败!"); | ||
| 137 | - return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR); | 161 | + logger.warn("设备预览/回放停止API调用失败!"); |
| 162 | + RequestMessage msg = new RequestMessage(); | ||
| 163 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); | ||
| 164 | + msg.setData("streamId null"); | ||
| 165 | + resultHolder.invokeResult(msg); | ||
| 138 | } | 166 | } |
| 167 | + | ||
| 168 | + // 超时处理 | ||
| 169 | + result.onTimeout(()->{ | ||
| 170 | + logger.warn(String.format("设备预览/回放停止超时,streamId:%s ", streamId)); | ||
| 171 | + RequestMessage msg = new RequestMessage(); | ||
| 172 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid); | ||
| 173 | + msg.setData("Timeout"); | ||
| 174 | + resultHolder.invokeResult(msg); | ||
| 175 | + }); | ||
| 176 | + return result; | ||
| 139 | } | 177 | } |
| 140 | 178 | ||
| 141 | /** | 179 | /** |
| @@ -145,7 +183,7 @@ public class PlayController { | @@ -145,7 +183,7 @@ public class PlayController { | ||
| 145 | */ | 183 | */ |
| 146 | @PostMapping("/play/{streamId}/convert") | 184 | @PostMapping("/play/{streamId}/convert") |
| 147 | public ResponseEntity<String> playConvert(@PathVariable String streamId) { | 185 | public ResponseEntity<String> playConvert(@PathVariable String streamId) { |
| 148 | - StreamInfo streamInfo = storager.queryPlayByStreamId(streamId); | 186 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); |
| 149 | if (streamInfo == null) { | 187 | if (streamInfo == null) { |
| 150 | logger.warn("视频转码API调用失败!, 视频流已经停止!"); | 188 | logger.warn("视频转码API调用失败!, 视频流已经停止!"); |
| 151 | return new ResponseEntity<String>("未找到视频流信息, 视频流可能已经停止", HttpStatus.OK); | 189 | return new ResponseEntity<String>("未找到视频流信息, 视频流可能已经停止", HttpStatus.OK); |
| @@ -155,7 +193,7 @@ public class PlayController { | @@ -155,7 +193,7 @@ public class PlayController { | ||
| 155 | logger.warn("视频转码API调用失败!, 视频流已停止推流!"); | 193 | logger.warn("视频转码API调用失败!, 视频流已停止推流!"); |
| 156 | return new ResponseEntity<String>("推流信息在流媒体中不存在, 视频流可能已停止推流", HttpStatus.OK); | 194 | return new ResponseEntity<String>("推流信息在流媒体中不存在, 视频流可能已停止推流", HttpStatus.OK); |
| 157 | } else { | 195 | } else { |
| 158 | - MediaServerConfig mediaInfo = storager.getMediaInfo(); | 196 | + MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); |
| 159 | String dstUrl = String.format("rtmp://%s:%s/convert/%s", "127.0.0.1", mediaInfo.getRtmpPort(), | 197 | String dstUrl = String.format("rtmp://%s:%s/convert/%s", "127.0.0.1", mediaInfo.getRtmpPort(), |
| 160 | streamId ); | 198 | streamId ); |
| 161 | String srcUrl = String.format("rtsp://%s:%s/rtp/%s", "127.0.0.1", mediaInfo.getRtspPort(), streamId); | 199 | String srcUrl = String.format("rtsp://%s:%s/rtp/%s", "127.0.0.1", mediaInfo.getRtspPort(), streamId); |
src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java
| @@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; | @@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 6 | import com.genersoft.iot.vmp.conf.MediaServerConfig; | 6 | import com.genersoft.iot.vmp.conf.MediaServerConfig; |
| 7 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | 7 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 8 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | 8 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| 9 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 9 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 10 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 10 | import com.genersoft.iot.vmp.vmanager.play.PlayController; | 11 | import com.genersoft.iot.vmp.vmanager.play.PlayController; |
| 11 | import com.genersoft.iot.vmp.vmanager.service.IPlayService; | 12 | import com.genersoft.iot.vmp.vmanager.service.IPlayService; |
| @@ -25,6 +26,9 @@ public class PlayServiceImpl implements IPlayService { | @@ -25,6 +26,9 @@ public class PlayServiceImpl implements IPlayService { | ||
| 25 | private IVideoManagerStorager storager; | 26 | private IVideoManagerStorager storager; |
| 26 | 27 | ||
| 27 | @Autowired | 28 | @Autowired |
| 29 | + private IRedisCatchStorage redisCatchStorage; | ||
| 30 | + | ||
| 31 | + @Autowired | ||
| 28 | private DeferredResultHolder resultHolder; | 32 | private DeferredResultHolder resultHolder; |
| 29 | 33 | ||
| 30 | @Override | 34 | @Override |
| @@ -33,7 +37,7 @@ public class PlayServiceImpl implements IPlayService { | @@ -33,7 +37,7 @@ public class PlayServiceImpl implements IPlayService { | ||
| 33 | msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); | 37 | msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); |
| 34 | StreamInfo streamInfo = onPublishHandler(resonse, deviceId, channelId, uuid); | 38 | StreamInfo streamInfo = onPublishHandler(resonse, deviceId, channelId, uuid); |
| 35 | if (streamInfo != null) { | 39 | if (streamInfo != null) { |
| 36 | - storager.startPlay(streamInfo); | 40 | + redisCatchStorage.startPlay(streamInfo); |
| 37 | msg.setData(JSON.toJSONString(streamInfo)); | 41 | msg.setData(JSON.toJSONString(streamInfo)); |
| 38 | resultHolder.invokeResult(msg); | 42 | resultHolder.invokeResult(msg); |
| 39 | } else { | 43 | } else { |
| @@ -49,7 +53,7 @@ public class PlayServiceImpl implements IPlayService { | @@ -49,7 +53,7 @@ public class PlayServiceImpl implements IPlayService { | ||
| 49 | msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); | 53 | msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid); |
| 50 | StreamInfo streamInfo = onPublishHandler(resonse, deviceId, channelId, uuid); | 54 | StreamInfo streamInfo = onPublishHandler(resonse, deviceId, channelId, uuid); |
| 51 | if (streamInfo != null) { | 55 | if (streamInfo != null) { |
| 52 | - storager.startPlayback(streamInfo); | 56 | + redisCatchStorage.startPlayback(streamInfo); |
| 53 | msg.setData(JSON.toJSONString(streamInfo)); | 57 | msg.setData(JSON.toJSONString(streamInfo)); |
| 54 | resultHolder.invokeResult(msg); | 58 | resultHolder.invokeResult(msg); |
| 55 | } else { | 59 | } else { |
| @@ -65,7 +69,7 @@ public class PlayServiceImpl implements IPlayService { | @@ -65,7 +69,7 @@ public class PlayServiceImpl implements IPlayService { | ||
| 65 | streamInfo.setStreamId(streamId); | 69 | streamInfo.setStreamId(streamId); |
| 66 | streamInfo.setDeviceID(deviceId); | 70 | streamInfo.setDeviceID(deviceId); |
| 67 | streamInfo.setCahnnelId(channelId); | 71 | streamInfo.setCahnnelId(channelId); |
| 68 | - MediaServerConfig mediaServerConfig = storager.getMediaInfo(); | 72 | + MediaServerConfig mediaServerConfig = redisCatchStorage.getMediaInfo(); |
| 69 | 73 | ||
| 70 | streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); | 74 | streamInfo.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
| 71 | streamInfo.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); | 75 | streamInfo.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaServerConfig.getWanIp(), mediaServerConfig.getHttpPort(), streamId)); |
src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java
| @@ -65,7 +65,7 @@ public class ApiDeviceController { | @@ -65,7 +65,7 @@ public class ApiDeviceController { | ||
| 65 | JSONObject result = new JSONObject(); | 65 | JSONObject result = new JSONObject(); |
| 66 | List<Device> devices; | 66 | List<Device> devices; |
| 67 | if (start == null || limit ==null) { | 67 | if (start == null || limit ==null) { |
| 68 | - devices = storager.queryVideoDeviceList(null); | 68 | + devices = storager.queryVideoDeviceList(); |
| 69 | result.put("DeviceCount", devices.size()); | 69 | result.put("DeviceCount", devices.size()); |
| 70 | }else { | 70 | }else { |
| 71 | PageResult<Device> deviceList = storager.queryVideoDeviceList(null, start/limit, limit); | 71 | PageResult<Device> deviceList = storager.queryVideoDeviceList(null, start/limit, limit); |
src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java
| @@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; | @@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 8 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | 8 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 9 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | 9 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 10 | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; | 10 | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; |
| 11 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 11 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 12 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 12 | import com.genersoft.iot.vmp.vmanager.play.PlayController; | 13 | import com.genersoft.iot.vmp.vmanager.play.PlayController; |
| 13 | import org.slf4j.Logger; | 14 | import org.slf4j.Logger; |
| @@ -35,6 +36,9 @@ public class ApiStreamController { | @@ -35,6 +36,9 @@ public class ApiStreamController { | ||
| 35 | @Autowired | 36 | @Autowired |
| 36 | private IVideoManagerStorager storager; | 37 | private IVideoManagerStorager storager; |
| 37 | 38 | ||
| 39 | + @Autowired | ||
| 40 | + private IRedisCatchStorage redisCatchStorage; | ||
| 41 | + | ||
| 38 | private boolean closeWaitRTPInfo = false; | 42 | private boolean closeWaitRTPInfo = false; |
| 39 | 43 | ||
| 40 | 44 | ||
| @@ -158,14 +162,14 @@ public class ApiStreamController { | @@ -158,14 +162,14 @@ public class ApiStreamController { | ||
| 158 | 162 | ||
| 159 | ){ | 163 | ){ |
| 160 | 164 | ||
| 161 | - StreamInfo streamInfo = storager.queryPlayByDevice(serial, code); | 165 | + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(serial, code); |
| 162 | if (streamInfo == null) { | 166 | if (streamInfo == null) { |
| 163 | JSONObject result = new JSONObject(); | 167 | JSONObject result = new JSONObject(); |
| 164 | result.put("error","未找到流信息"); | 168 | result.put("error","未找到流信息"); |
| 165 | return result; | 169 | return result; |
| 166 | } | 170 | } |
| 167 | cmder.streamByeCmd(streamInfo.getStreamId()); | 171 | cmder.streamByeCmd(streamInfo.getStreamId()); |
| 168 | - storager.stopPlay(streamInfo); | 172 | + redisCatchStorage.stopPlay(streamInfo); |
| 169 | return null; | 173 | return null; |
| 170 | } | 174 | } |
| 171 | 175 |
src/main/resources/wvp.sqlite
0 → 100644
No preview for this file type
web_src/src/components/channelList.vue
| @@ -104,7 +104,7 @@ export default { | @@ -104,7 +104,7 @@ export default { | ||
| 104 | 104 | ||
| 105 | mounted() { | 105 | mounted() { |
| 106 | this.initData(); | 106 | this.initData(); |
| 107 | - this.updateLooper = setInterval(this.initData, 10000); | 107 | + this.updateLooper = setInterval(this.initData, 1000); |
| 108 | }, | 108 | }, |
| 109 | destroyed() { | 109 | destroyed() { |
| 110 | this.$destroy('videojs'); | 110 | this.$destroy('videojs'); |