From 5cd2e2c41b6460ea628b158e9f22b6788e99eee1 Mon Sep 17 00:00:00 2001
From: lishuyuan <lishuyuan@inspur.com>
Date: 星期三, 01 十一月 2023 15:17:28 +0800
Subject: [PATCH] bugfix:设备地址变化会引起目录订阅任务失效,需要重新添加

---
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java |   40 +++++++++++++++++++++++++---------------
 1 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java
old mode 100644
new mode 100755
index 50a1fa5..cbc5fde
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java
@@ -3,6 +3,7 @@
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
 import com.genersoft.iot.vmp.media.zlm.dto.*;
+import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
 import com.genersoft.iot.vmp.service.IMediaServerService;
 import com.genersoft.iot.vmp.service.IStreamProxyService;
 import com.genersoft.iot.vmp.service.IStreamPushService;
@@ -17,6 +18,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.text.ParseException;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -59,33 +61,35 @@
     private UserSetting userSetting;
 
     @Autowired
-    private ZLMRTPServerFactory zlmrtpServerFactory;
+    private ZLMServerFactory zlmServerFactory;
 
     @Autowired
     private IMediaServerService mediaServerService;
 
     private Map<String, ChannelOnlineEvent> channelOnPublishEvents = new ConcurrentHashMap<>();
 
-    public StreamPushItem addPush(MediaItem mediaItem) {
-        // 鏌ユ壘姝ょ洿鎾祦鏄惁瀛樺湪redis棰勮gbId
-        StreamPushItem transform = streamPushService.transform(mediaItem);
-        StreamPushItem pushInDb = streamPushService.getPush(mediaItem.getApp(), mediaItem.getStream());
-        transform.setPushIng(mediaItem.isRegist());
+    public StreamPushItem addPush(OnStreamChangedHookParam onStreamChangedHookParam) {
+        StreamPushItem transform = streamPushService.transform(onStreamChangedHookParam);
+        StreamPushItem pushInDb = streamPushService.getPush(onStreamChangedHookParam.getApp(), onStreamChangedHookParam.getStream());
+        transform.setPushIng(onStreamChangedHookParam.isRegist());
         transform.setUpdateTime(DateUtil.getNow());
         transform.setPushTime(DateUtil.getNow());
-        transform.setSelf(userSetting.getServerId().equals(mediaItem.getSeverId()));
+        transform.setSelf(userSetting.getServerId().equals(onStreamChangedHookParam.getSeverId()));
         if (pushInDb == null) {
             transform.setCreateTime(DateUtil.getNow());
             streamPushMapper.add(transform);
         }else {
             streamPushMapper.update(transform);
-            gbStreamMapper.updateMediaServer(mediaItem.getApp(), mediaItem.getStream(), mediaItem.getMediaServerId());
+            gbStreamMapper.updateMediaServer(onStreamChangedHookParam.getApp(), onStreamChangedHookParam.getStream(), onStreamChangedHookParam.getMediaServerId());
         }
-        if (transform != null) {
-            if (getChannelOnlineEventLister(transform.getApp(), transform.getStream()) != null)  {
-                getChannelOnlineEventLister(transform.getApp(), transform.getStream()).run(transform.getApp(), transform.getStream(), transform.getServerId());
-                removedChannelOnlineEventLister(transform.getApp(), transform.getStream());
+        ChannelOnlineEvent channelOnlineEventLister = getChannelOnlineEventLister(transform.getApp(), transform.getStream());
+        if ( channelOnlineEventLister != null)  {
+            try {
+                channelOnlineEventLister.run(transform.getApp(), transform.getStream(), transform.getServerId());;
+            } catch (ParseException e) {
+                logger.error("addPush: ", e);
             }
+            removedChannelOnlineEventLister(transform.getApp(), transform.getStream());
         }
         return transform;
     }
@@ -93,9 +97,15 @@
     public void sendStreamEvent(String app, String stream, String mediaServerId) {
         MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
         // 鏌ョ湅鎺ㄦ祦鐘舵��
-        if (zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream)) {
-            if (getChannelOnlineEventLister(app, stream) != null)  {
-                getChannelOnlineEventLister(app, stream).run(app, stream, mediaServerId);
+        Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerItem, app, stream);
+        if (streamReady != null && streamReady) {
+            ChannelOnlineEvent channelOnlineEventLister = getChannelOnlineEventLister(app, stream);
+            if (channelOnlineEventLister != null)  {
+                try {
+                    channelOnlineEventLister.run(app, stream, mediaServerId);
+                } catch (ParseException e) {
+                    logger.error("sendStreamEvent: ", e);
+                }
                 removedChannelOnlineEventLister(app, stream);
             }
         }

--
Gitblit v1.8.0