panlinlin
2021-04-27 bf8fb0c51f4e7894a62636dede6c69a2a85d8458
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
@@ -61,6 +61,9 @@
    @Value("${media.autoConfig}")
    private boolean autoConfig;
    @Value("${server.ssl.enabled}")
    private boolean sslEnabled;
    @Autowired
    private ZLMRESTfulUtils zlmresTfulUtils;
@@ -116,14 +119,14 @@
        if (StringUtils.isEmpty(mediaHookIp)) {
            mediaHookIp = sipIP;
        }
        String hookPrex = String.format("http://%s:%s/index/hook", mediaHookIp, serverPort);
        String protocol = sslEnabled ? "https" : "http";
        String hookPrex = String.format("%s://%s:%s/index/hook", protocol, mediaHookIp, serverPort);
        Map<String, Object> param = new HashMap<>();
        param.put("api.secret",mediaSecret); // -profile:v Baseline
        param.put("ffmpeg.cmd","%s -fflags nobuffer -rtsp_transport tcp -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264  -f flv %s");
        param.put("hook.enable","1");
        param.put("hook.on_flow_report","");
        param.put("hook.on_play","");
        param.put("hook.on_play",String.format("%s/on_play", hookPrex));
        param.put("hook.on_http_access","");
        param.put("hook.on_publish",String.format("%s/on_publish", hookPrex));
        param.put("hook.on_record_mp4","");
@@ -151,23 +154,32 @@
     * zlm 连接成功或者zlm重启后
     */
    private void zLmRunning(MediaServerConfig mediaServerConfig){
        logger.info("zlm接入成功...");
        logger.info( "[ id: " + mediaServerConfig.getGeneralMediaServerId() + "] zlm接入成功...");
        if (autoConfig) saveZLMConfig();
        MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
        if (mediaInfo != null && System.currentTimeMillis() - mediaInfo.getUpdateTime() < 50){
            logger.info("zlm刚刚更新,忽略这次更新");
            logger.info("[ id: " + mediaServerConfig.getGeneralMediaServerId() + "]zlm刚刚更新,忽略这次更新");
            return;
        }
        mediaServerConfig.setLocalIP(mediaIp);
        mediaServerConfig.setWanIp(StringUtils.isEmpty(mediaWanIp)? mediaIp: mediaWanIp);
        redisCatchStorage.updateMediaInfo(mediaServerConfig);
        // 清空所有session
//        zlmMediaListManager.clearAllSessions();
        // 更新流列表
        zlmMediaListManager.updateMediaList();
        // 恢复流代理
        List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnable(true);
        for (StreamProxyItem streamProxyDto : streamProxyListForEnable) {
            logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
            streamProxyService.addStreamProxyToZlm(streamProxyDto);
            JSONObject jsonObject = streamProxyService.addStreamProxyToZlm(streamProxyDto);
            if (jsonObject == null) {
                // 设置为未启用
                logger.info("恢复流代理失败,请检查流地址后重新启用" + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
                streamProxyService.stop(streamProxyDto.getApp(), streamProxyDto.getStream());
            }
        }
    }
}