| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.MediaConfig; |
| | | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| | | import com.genersoft.iot.vmp.service.IMediaServerService; |
| | | import com.genersoft.iot.vmp.service.IStreamProxyService; |
| | |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private IStreamProxyService streamProxyService; |
| | | |
| | | @Autowired |
| | | private EventPublisher publisher; |
| | | |
| | | @Autowired |
| | | private IMediaServerService mediaServerService; |
| | |
| | | |
| | | @Async |
| | | public void connectZlmServer(MediaServerItem mediaServerItem){ |
| | | ZLMServerConfig zlmServerConfig = getMediaServerConfig(mediaServerItem); |
| | | ZLMServerConfig zlmServerConfig = getMediaServerConfig(mediaServerItem, 1); |
| | | if (zlmServerConfig != null) { |
| | | zlmServerConfig.setIp(mediaServerItem.getIp()); |
| | | zlmServerConfig.setHttpPort(mediaServerItem.getHttpPort()); |
| | |
| | | } |
| | | } |
| | | |
| | | public ZLMServerConfig getMediaServerConfig(MediaServerItem mediaServerItem) { |
| | | public ZLMServerConfig getMediaServerConfig(MediaServerItem mediaServerItem, int index) { |
| | | if (startGetMedia == null) { return null;} |
| | | if (!mediaServerItem.isDefaultServer() && mediaServerService.getOne(mediaServerItem.getId()) == null) { |
| | | return null; |
| | |
| | | ZLMServerConfig.setIp(mediaServerItem.getIp()); |
| | | } |
| | | } else { |
| | | logger.error("[ {} ]-[ {}:{} ]主动连接失败失败, 2s后重试", |
| | | mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); |
| | | logger.error("[ {} ]-[ {}:{} ]第{}次主动连接失败, 2s后重试", |
| | | mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort(), index); |
| | | if (index == 1 && !StringUtils.isEmpty(mediaServerItem.getId())) { |
| | | logger.info("[ {} ]-[ {}:{} ]第{}次主动连接失败, 开始清理相关资源", |
| | | mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort(), index); |
| | | publisher.zlmOfflineEventPublish(mediaServerItem.getId()); |
| | | } |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | ZLMServerConfig = getMediaServerConfig(mediaServerItem); |
| | | ZLMServerConfig = getMediaServerConfig(mediaServerItem, index += 1); |
| | | } |
| | | return ZLMServerConfig; |
| | | |