From c77c1a956c0c39575eb6d9a86cb8c137bb8126c8 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期一, 25 七月 2022 11:17:46 +0800 Subject: [PATCH] 修复推流推流状态提示 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java | 192 +++++++++++++++++++++-------------------------- 1 files changed, 87 insertions(+), 105 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 index a50b170..1b1fb9f 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java @@ -1,24 +1,33 @@ package com.genersoft.iot.vmp.media.zlm; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.genersoft.iot.vmp.conf.MediaServerConfig; -import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; -import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; +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.service.IStreamProxyService; import com.genersoft.iot.vmp.service.IStreamPushService; +import com.genersoft.iot.vmp.service.bean.ThirdPartyGB; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; -import com.genersoft.iot.vmp.storager.IVideoManagerStorager; +import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; +import com.genersoft.iot.vmp.storager.dao.StreamPushMapper; +import com.genersoft.iot.vmp.utils.DateUtil; +import org.checkerframework.checker.units.qual.C; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +/** + * @author lin + */ @Component public class ZLMMediaListManager { @@ -31,7 +40,7 @@ private IRedisCatchStorage redisCatchStorage; @Autowired - private IVideoManagerStorager storager; + private IVideoManagerStorage storager; @Autowired private GbStreamMapper gbStreamMapper; @@ -43,112 +52,85 @@ private IStreamPushService streamPushService; @Autowired + private IStreamProxyService streamProxyService; + + @Autowired + private StreamPushMapper streamPushMapper; + + @Autowired private ZLMHttpHookSubscribe subscribe; + @Autowired + private UserSetting userSetting; - public void updateMediaList() { - storager.clearMediaList(); + private Map<String, ChannelOnlineEvent> channelOnlineEvents = new ConcurrentHashMap<>(); - // 浣跨敤寮傛鐨勫綋鏃舵洿鏂板獟浣撴祦鍒楄〃 - zlmresTfulUtils.getMediaList((mediaList ->{ - if (mediaList == null) return; - String dataStr = mediaList.getString("data"); - - Integer code = mediaList.getInteger("code"); - Map<String, StreamPushItem> result = new HashMap<>(); - List<StreamPushItem> streamPushItems = null; - // 鑾峰彇鎵�鏈夌殑鍥芥爣鍏宠仈 - List<GbStream> gbStreams = gbStreamMapper.selectAll(); - if (code == 0 ) { - if (dataStr != null) { - streamPushItems = streamPushService.handleJSON(dataStr); - } - }else { - logger.warn("鏇存柊瑙嗛娴佸け璐ワ紝閿欒code锛� " + code); - } - - if (streamPushItems != null) { - storager.updateMediaList(streamPushItems); - for (StreamPushItem streamPushItem : streamPushItems) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("app", streamPushItem.getApp()); - jsonObject.put("stream", streamPushItem.getStream()); - subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_play,jsonObject,(response)->{ - updateMedia(response.getString("app"), response.getString("stream")); - }); - } - } - })); - - } - - public void addMedia(String app, String streamId) { - //浣跨敤寮傛鏇存柊鎺ㄦ祦 - updateMedia(app, streamId); - } - - - public void updateMedia(String app, String streamId) { - //浣跨敤寮傛鏇存柊鎺ㄦ祦 - zlmresTfulUtils.getMediaList(app, streamId, "rtmp", json->{ - - if (json == null) return; - String dataStr = json.getString("data"); - - Integer code = json.getInteger("code"); - Map<String, StreamPushItem> result = new HashMap<>(); - List<StreamPushItem> streamPushItems = null; - if (code == 0 ) { - if (dataStr != null) { - streamPushItems = streamPushService.handleJSON(dataStr); - } - }else { - logger.warn("鏇存柊瑙嗛娴佸け璐ワ紝閿欒code锛� " + code); - } - - if (streamPushItems != null && streamPushItems.size() == 1) { - storager.updateMedia(streamPushItems.get(0)); - } - }); - } - - - public void removeMedia(String app, String streamId) { - // 鏌ユ壘鏄惁鍏宠仈浜嗗浗鏍囷紝 鍏宠仈浜嗕笉鍒犻櫎锛� 缃负绂荤嚎 - StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(app, streamId); - if (streamProxyItem == null) { - storager.removeMedia(app, streamId); + public StreamPushItem addPush(MediaItem mediaItem) { + // 鏌ユ壘姝ょ洿鎾祦鏄惁瀛樺湪redis棰勮gbId + StreamPushItem transform = streamPushService.transform(mediaItem); + StreamPushItem pushInDb = streamPushService.getPush(mediaItem.getApp(), mediaItem.getStream()); + transform.setPushIng(mediaItem.isRegist()); + transform.setUpdateTime(DateUtil.getNow()); + transform.setPushTime(DateUtil.getNow()); + transform.setSelf(userSetting.getServerId().equals(mediaItem.getSeverId())); + if (pushInDb == null) { + transform.setCreateTime(DateUtil.getNow()); + streamPushMapper.add(transform); }else { - storager.mediaOutline(app, streamId); + streamPushMapper.update(transform); } + return transform; } - public void clearAllSessions() { - logger.info("娓呯┖鎵�鏈夊浗鏍囩浉鍏崇殑session"); - JSONObject allSessionJSON = zlmresTfulUtils.getAllSession(); - MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); - HashSet<String> allLocalPorts = new HashSet(); - if (allSessionJSON.getInteger("code") == 0) { - JSONArray data = allSessionJSON.getJSONArray("data"); - if (data.size() > 0) { - for (int i = 0; i < data.size(); i++) { - JSONObject sessionJOSN = data.getJSONObject(i); - Integer local_port = sessionJOSN.getInteger("local_port"); - if (!local_port.equals(Integer.valueOf(mediaInfo.getHttpPort())) && - !local_port.equals(Integer.valueOf(mediaInfo.getHttpSSLport())) && - !local_port.equals(Integer.valueOf(mediaInfo.getRtmpPort())) && - !local_port.equals(Integer.valueOf(mediaInfo.getRtspPort())) && - !local_port.equals(Integer.valueOf(mediaInfo.getRtspSSlport())) && - !local_port.equals(Integer.valueOf(mediaInfo.getHookOnFlowReport()))){ - allLocalPorts.add(sessionJOSN.getInteger("local_port") + ""); - } - } - } + public int removeMedia(String app, String streamId) { + // 鏌ユ壘鏄惁鍏宠仈浜嗗浗鏍囷紝 鍏宠仈浜嗕笉鍒犻櫎锛� 缃负绂荤嚎 + GbStream gbStream = gbStreamMapper.selectOne(app, streamId); + int result; + if (gbStream == null) { + result = storager.removeMedia(app, streamId); + }else { + // TODO 鏆備笉璁剧疆涓虹绾� + result =storager.mediaOffline(app, streamId); } - if (allLocalPorts.size() > 0) { - List<String> result = new ArrayList<>(allLocalPorts); - String localPortSStr = String.join(",", result); - zlmresTfulUtils.kickSessions(localPortSStr); - } + return result; } + + public void addChannelOnlineEventLister(String key, ChannelOnlineEvent callback) { + this.channelOnlineEvents.put(key,callback); + } + + public void removedChannelOnlineEventLister(String key) { + this.channelOnlineEvents.remove(key); + } + + + +// public void clearAllSessions() { +// logger.info("娓呯┖鎵�鏈夊浗鏍囩浉鍏崇殑session"); +// JSONObject allSessionJSON = zlmresTfulUtils.getAllSession(); +// ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo(); +// HashSet<String> allLocalPorts = new HashSet(); +// if (allSessionJSON.getInteger("code") == 0) { +// JSONArray data = allSessionJSON.getJSONArray("data"); +// if (data.size() > 0) { +// for (int i = 0; i < data.size(); i++) { +// JSONObject sessionJOSN = data.getJSONObject(i); +// Integer local_port = sessionJOSN.getInteger("local_port"); +// if (!local_port.equals(Integer.valueOf(mediaInfo.getHttpPort())) && +// !local_port.equals(Integer.valueOf(mediaInfo.getHttpSSLport())) && +// !local_port.equals(Integer.valueOf(mediaInfo.getRtmpPort())) && +// !local_port.equals(Integer.valueOf(mediaInfo.getRtspPort())) && +// !local_port.equals(Integer.valueOf(mediaInfo.getRtspSSlport())) && +// !local_port.equals(Integer.valueOf(mediaInfo.getHookOnFlowReport()))){ +// allLocalPorts.add(sessionJOSN.getInteger("local_port") + ""); +// } +// } +// } +// } +// if (allLocalPorts.size() > 0) { +// List<String> result = new ArrayList<>(allLocalPorts); +// String localPortSStr = String.join(",", result); +// zlmresTfulUtils.kickSessions(localPortSStr); +// } +// } } -- Gitblit v1.8.0