فهرست منبع

Merge remote-tracking branch 'origin/wvp-28181-2.0' into wvp-28181-2.0

648540858 3 سال پیش
والد
کامیت
963a74d280

+ 1 - 1
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java

@@ -10,7 +10,7 @@ public class VideoManagerConstants {
 	
 	public static final String WVP_SERVER_PREFIX = "VMP_SIGNALLING_SERVER_INFO_";
 
-	public static final String WVP_SERVER_STREAM_PUSH_PREFIX = "VMP_SIGNALLING_STREAM_PUSH_";
+	public static final String WVP_SERVER_STREAM_PUSH_PREFIX = "VMP_SIGNALLING_STREAM_";
 
 	public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_";
 

+ 12 - 12
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java

@@ -11,6 +11,7 @@ import com.genersoft.iot.vmp.conf.UserSetup;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
+import com.genersoft.iot.vmp.media.zlm.dto.OriginType;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
 import com.genersoft.iot.vmp.service.IMediaServerService;
 import com.genersoft.iot.vmp.service.IMediaService;
@@ -315,24 +316,23 @@ public class ZLMHttpHookListener {
 			}else {
 				if (!"rtp".equals(app)){
 
-					boolean pushChange = false;
-
 					MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
 					if (regist) {
-						if ((item.getOriginType() == 1 || item.getOriginType() == 2 || item.getOriginType() == 8)) {
-							pushChange = true;
+						StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks);
+						redisCatchStorage.addStream(mediaServerItem, OriginType.values()[item.getOriginType()].getType(), app, streamId, streamInfo);
+						if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
+								|| item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
+								|| item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) {
 							zlmMediaListManager.addMedia(item);
-							StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks);
-							redisCatchStorage.addPushStream(mediaServerItem, app, streamId, streamInfo);
 						}
 					}else {
-						int result = zlmMediaListManager.removeMedia( app, streamId);
-						redisCatchStorage.removePushStream(mediaServerItem, app, streamId);
-						if (result > 0) {
-							pushChange = true;
-						}
+						zlmMediaListManager.removeMedia( app, streamId);
+						redisCatchStorage.removeStream(mediaServerItem, OriginType.values()[item.getOriginType()].getType(), app, streamId);
+
 					}
-					if(pushChange) {
+					if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
+							|| item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
+							|| item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) {
 						// 发送流变化redis消息
 						JSONObject jsonObject = new JSONObject();
 						jsonObject.put("serverId", userSetup.getServerId());

+ 22 - 0
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OriginType.java

@@ -0,0 +1,22 @@
+package com.genersoft.iot.vmp.media.zlm.dto;
+
+public enum OriginType {
+    UNKNOWN("UNKNOWN"),
+    RTMP_PUSH("PUSH"),
+    RTSP_PUSH("PUSH"),
+    RTP_PUSH("RTP"),
+    RTC_PUSH("PUSH"),
+    PULL("PULL"),
+    FFMPEG_PULL("PULL"),
+    MP4_VOD("MP4_VOD"),
+    DEVICE_CHN("DEVICE_CHN");
+
+    private final String type;
+    OriginType(String type) {
+        this.type = type;
+    }
+
+    public String getType() {
+        return type;
+    }
+}

+ 2 - 2
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java

@@ -135,7 +135,7 @@ public interface IRedisCatchStorage {
      * @param app
      * @param streamId
      */
-    void addPushStream(MediaServerItem mediaServerItem, String app, String streamId, StreamInfo streamInfo);
+    void addStream(MediaServerItem mediaServerItem, String type, String app, String streamId, StreamInfo streamInfo);
 
     /**
      * 移除流信息从redis
@@ -143,7 +143,7 @@ public interface IRedisCatchStorage {
      * @param app
      * @param streamId
      */
-    void removePushStream(MediaServerItem mediaServerItem, String app, String streamId);
+    void removeStream(MediaServerItem mediaServerItem, String type, String app, String streamId);
 
     /**
      * 开始下载录像时存入

+ 12 - 5
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java

@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.storager.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.common.VideoManagerConstants;
+import com.genersoft.iot.vmp.conf.UserSetup;
 import com.genersoft.iot.vmp.gb28181.bean.*;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@@ -24,6 +25,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
     @Autowired
     private DeviceChannelMapper deviceChannelMapper;
 
+    @Autowired
+    private UserSetup userSetup;
+
     private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     /**
@@ -313,15 +317,18 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
     }
 
     @Override
-    public void addPushStream(MediaServerItem mediaServerItem, String app, String streamId, StreamInfo streamInfo) {
-        String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + app + "_" + streamId + "_" + mediaServerItem.getId();
+    public void addStream(MediaServerItem mediaServerItem, String type, String app, String streamId, StreamInfo streamInfo) {
+        String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX  + userSetup.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerItem.getId();
         redis.set(key, streamInfo);
     }
 
     @Override
-    public void removePushStream(MediaServerItem mediaServerItem, String app, String streamId) {
-        String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + app + "_" + streamId + "_" + mediaServerItem.getId();
-        redis.del(key);
+    public void removeStream(MediaServerItem mediaServerItem, String type, String app, String streamId) {
+        String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + userSetup.getServerId() + "_*_"  + app + "_" + streamId + "_" + mediaServerItem.getId();
+        List<Object> streams = redis.scan(key);
+        for (Object stream : streams) {
+            redis.del((String) stream);
+        }
     }
 
     @Override