648540858
2021-05-06 fd296d1a6acccbe9f3a72623719bf7101725f4e9
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -1,7 +1,7 @@
package com.genersoft.iot.vmp.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.conf.MediaServerConfig;
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@@ -40,23 +40,40 @@
    @Override
    public void save(StreamProxyItem param) {
        MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
    public String save(StreamProxyItem param) {
        ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
        String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
                param.getStream() );
        param.setDst_url(dstUrl);
        StringBuffer result = new StringBuffer();
        // 更新
        if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) {
            boolean result = videoManagerStorager.updateStreamProxy(param);
            if (result && param.isEnable()) {
                addStreamProxyToZlm(param);
            if (videoManagerStorager.updateStreamProxy(param)) {
                result.append("保存成功");
                if (param.isEnable()){
                    JSONObject jsonObject = addStreamProxyToZlm(param);
                    if (jsonObject == null) {
                        result.append(", 但是启用失败,请检查流地址是否可用");
                        param.setEnable(false);
                        videoManagerStorager.updateStreamProxy(param);
                    }
                }
            }
        }else { // 新增
            boolean result = videoManagerStorager.addStreamProxy(param);
            if (result  && param.isEnable()) {
                addStreamProxyToZlm(param);
            if (videoManagerStorager.addStreamProxy(param)){
                result.append("保存成功");
                if (param.isEnable()) {
                    JSONObject jsonObject = addStreamProxyToZlm(param);
                    if (jsonObject == null) {
                        result.append(", 但是启用失败,请检查流地址是否可用");
                        param.setEnable(false);
                        videoManagerStorager.updateStreamProxy(param);
                    }
                }
            }
        }
        return result.toString();
    }
    @Override
@@ -105,6 +122,7 @@
        StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream);
        if (!streamProxy.isEnable() &&  streamProxy != null) {
            JSONObject jsonObject = addStreamProxyToZlm(streamProxy);
            if (jsonObject == null) return false;
            if (jsonObject.getInteger("code") == 0) {
                result = true;
                streamProxy.setEnable(true);
@@ -118,12 +136,11 @@
    public boolean stop(String app, String stream) {
        boolean result = false;
        StreamProxyItem streamProxyDto = videoManagerStorager.queryStreamProxy(app, stream);
        if (streamProxyDto.isEnable() &&  streamProxyDto != null) {
        if (streamProxyDto != null && streamProxyDto.isEnable()) {
            JSONObject jsonObject = removeStreamProxyFromZlm(streamProxyDto);
            if (jsonObject.getInteger("code") == 0) {
                result = true;
                streamProxyDto.setEnable(false);
                videoManagerStorager.updateStreamProxy(streamProxyDto);
                result = videoManagerStorager.updateStreamProxy(streamProxyDto);
            }
        }
        return result;