Commit f7e39141db04ae209f436f359e781cea6a978051

Authored by 648540858
1 parent c9f091d5

修复重启服务后拉流代理回复失败的问题

src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
... ... @@ -175,3 +175,4 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
175 175 }
176 176 }
177 177 }
  178 +
178 179 \ No newline at end of file
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
1 1 package com.genersoft.iot.vmp.service.impl;
2 2  
  3 +import com.alibaba.fastjson.JSONArray;
3 4 import com.alibaba.fastjson.JSONObject;
4 5 import com.genersoft.iot.vmp.common.StreamInfo;
5 6 import com.genersoft.iot.vmp.conf.SipConfig;
... ... @@ -285,9 +286,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
285 286 }
286 287 streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId);
287 288  
  289 + // 移除拉流代理生成的流信息
  290 +// syncPullStream(mediaServerId);
  291 +
288 292 // 恢复流代理, 只查找这个这个流媒体
289 293 List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnableInMediaServer(
290   - mediaServerId, true, false);
  294 + mediaServerId, true);
291 295 for (StreamProxyItem streamProxyDto : streamProxyListForEnable) {
292 296 logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
293 297 JSONObject jsonObject = addStreamProxyToZlm(streamProxyDto);
... ... @@ -339,4 +343,45 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
339 343 public int updateStatus(boolean status, String app, String stream) {
340 344 return streamProxyMapper.updateStatus(status, app, stream);
341 345 }
  346 +
  347 + private void syncPullStream(String mediaServerId){
  348 + MediaServerItem mediaServer = mediaServerService.getOne(mediaServerId);
  349 + if (mediaServer != null) {
  350 + List<MediaItem> allPullStream = redisCatchStorage.getStreams(mediaServerId, "PULL");
  351 + if (allPullStream.size() > 0) {
  352 + zlmresTfulUtils.getMediaList(mediaServer, jsonObject->{
  353 + Map<String, StreamInfo> stringStreamInfoMap = new HashMap<>();
  354 + if (jsonObject.getInteger("code") == 0) {
  355 + JSONArray data = jsonObject.getJSONArray("data");
  356 + if(data != null && data.size() > 0) {
  357 + for (int i = 0; i < data.size(); i++) {
  358 + JSONObject streamJSONObj = data.getJSONObject(i);
  359 + if ("rtmp".equals(streamJSONObj.getString("schema"))) {
  360 + StreamInfo streamInfo = new StreamInfo();
  361 + String app = streamJSONObj.getString("app");
  362 + String stream = streamJSONObj.getString("stream");
  363 + streamInfo.setApp(app);
  364 + streamInfo.setStream(stream);
  365 + stringStreamInfoMap.put(app+stream, streamInfo);
  366 + }
  367 + }
  368 + }
  369 + }
  370 + if (stringStreamInfoMap.size() == 0) {
  371 + redisCatchStorage.removeStream(mediaServerId, "PULL");
  372 + }else {
  373 + for (String key : stringStreamInfoMap.keySet()) {
  374 + StreamInfo streamInfo = stringStreamInfoMap.get(key);
  375 + if (stringStreamInfoMap.get(streamInfo.getApp() + streamInfo.getStream()) == null) {
  376 + redisCatchStorage.removeStream(mediaServerId, "PULL", streamInfo.getApp(),
  377 + streamInfo.getStream());
  378 + }
  379 + }
  380 + }
  381 + });
  382 + }
  383 +
  384 + }
  385 +
  386 + }
342 387 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
... ... @@ -401,10 +401,9 @@ public interface IVideoManagerStorage {
401 401 * 根据媒体ID获取启用/不启用的代理列表
402 402 * @param id 媒体ID
403 403 * @param enable 启用/不启用
404   - * @param status 状态
405 404 * @return
406 405 */
407   - List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean enable, boolean status);
  406 + List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean enable);
408 407  
409 408 /**
410 409 * 根据通道ID获取其所在设备
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java
... ... @@ -51,8 +51,8 @@ public interface StreamProxyMapper {
51 51  
52 52 @Select("SELECT st.*, pgs.gbId, pgs.name, pgs.longitude, pgs.latitude FROM stream_proxy st " +
53 53 "LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream " +
54   - "WHERE st.enable=${enable} and st.status=${status} and st.mediaServerId = '${id}' order by st.createTime desc")
55   - List<StreamProxyItem> selectForEnableInMediaServer(String id, boolean enable, boolean status);
  54 + "WHERE st.enable=${enable} and st.mediaServerId = #{id} order by st.createTime desc")
  55 + List<StreamProxyItem> selectForEnableInMediaServer(String id, boolean enable);
56 56  
57 57 @Select("SELECT st.*, pgs.gbId, pgs.name, pgs.longitude, pgs.latitude FROM stream_proxy st " +
58 58 "LEFT JOIN gb_stream pgs on st.app = pgs.app AND st.stream = pgs.stream " +
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
... ... @@ -911,8 +911,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
911 911 }
912 912  
913 913 @Override
914   - public List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean enable, boolean status) {
915   - return streamProxyMapper.selectForEnableInMediaServer(id, enable, status);
  914 + public List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean enable) {
  915 + return streamProxyMapper.selectForEnableInMediaServer(id, enable);
916 916 }
917 917  
918 918  
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java
... ... @@ -65,7 +65,4 @@ public class MediaController {
65 65 }
66 66 return result;
67 67 }
68   -
69   -
70   -
71 68 }
... ...