2
liusuyi
2026-05-12 9b5c9db9189493fbc6db48f55a7b7311b2a3253c
ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/service/impl/MediaServerServiceImpl.java
@@ -12,6 +12,7 @@
import com.ard.gb28181.api.domain.Device;
import com.ard.qs.api.RemoteQsDeviceService;
import com.ard.qs.api.domain.QsDevice;
import com.ard.work.api.RemoteCameraService;
import com.ard.zlm.api.domain.*;
import com.ard.zlm.api.hook.OriginType;
import com.ard.zlm.common.InviteErrorCode;
@@ -33,6 +34,7 @@
import com.ard.zlm.service.*;
import com.ard.zlm.session.SSRCFactory;
import com.ard.zlm.utils.ZLMRESTfulUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -61,57 +63,57 @@
@Service
public class MediaServerServiceImpl implements IMediaServerService {
    @Autowired
    @Resource
    private MediaServerMapper mediaServerMapper;
    @Autowired
    @Resource
    private UserSetting userSetting;
    @Autowired
    @Resource
    private Map<String, IMediaNodeServerService> nodeServerServiceMap;
    @Autowired
    @Resource
    private ApplicationEventPublisher applicationEventPublisher;
    @Autowired
    @Resource
    private RedisTemplate redisTemplate;
    @Autowired
    @Resource
    private IRedisCatchStorage redisCatchStorage;
    @Autowired
    @Resource
    private MediaConfig mediaConfig;
    @Autowired
    @Resource
    private IMediaNodeServerService mediaNodeServerService;
    @Autowired
    @Resource
    private DynamicTask dynamicTask;
    @Autowired
    @Resource
    private HookSubscribe subscribe;
    @Autowired
    @Resource
    private RemoteQsDeviceService remoteQsDeviceService;
    @Autowired
    @Resource
    private ZLMRESTfulUtils zlmresTfulUtils;
    @Autowired
    @Resource
    private SSRCFactory ssrcFactory;
    @Autowired
    @Resource
    @Lazy
    private IReceiveRtpServerService receiveRtpServerService;
    @Autowired
    @Resource
    @Lazy
    private IInviteStreamService inviteStreamService;
    @Autowired
    @Resource
    private IZlmCloudRecordService zlmCloudRecordService;
    @Autowired
    @Resource
    private RemoteGb28181Service remoteGb28181Service;
@@ -624,19 +626,19 @@
            callback.run(InviteErrorCode.FAIL.getCode(), "无可用的节点", null);
            return;
        }
        R<QsDevice> devicer = remoteQsDeviceService.getQsDeviceInfo(streamPullPlay.getDeviceId(), SecurityConstants
        .INNER);
        if (devicer.getCode() != Constants.SUCCESS) {
            throw new RuntimeException("获取设备信息失败" + streamPullPlay.getDeviceId());
        }
        if (devicer.getData() == null) {
            throw new RuntimeException("设备不存在" + streamPullPlay.getDeviceId());
        }
        if ("OFFLINE".equals(devicer.getData().getDeviceStatus())) {
            throw new RuntimeException("设备不在线" + streamPullPlay.getDeviceId());
        }
//        R<QsDevice> devicer = remoteQsDeviceService.getQsDeviceInfo(streamPullPlay.getDeviceId(), SecurityConstants
//        .INNER);
//        if (devicer.getCode() != Constants.SUCCESS) {
//            throw new RuntimeException("获取设备信息失败" + streamPullPlay.getDeviceId());
//        }
//
//        if (devicer.getData() == null) {
//            throw new RuntimeException("设备不存在" + streamPullPlay.getDeviceId());
//        }
//
//        if ("OFFLINE".equals(devicer.getData().getDeviceStatus())) {
//            throw new RuntimeException("设备不在线" + streamPullPlay.getDeviceId());
//        }
        StreamInfo stream = getStreamInfoByAppAndStreamWithCheck(streamPullPlay.getApp(), streamPullPlay.getStream(),
                mediaServer.getId(), null, false);
@@ -668,13 +670,13 @@
            callback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), streamInfo);
            subscribe.removeSubscribe(rtpHook);
            QsDevice qsDevice = new QsDevice();
            qsDevice.setId(streamPullPlay.getDeviceId());
            qsDevice.setSnap(filePath);
            R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER);
            if (r.getCode() != Constants.SUCCESS) {
                throw new RuntimeException("更新设备失败");
            }
//            QsDevice qsDevice = new QsDevice();
//            qsDevice.setId(streamPullPlay.getDeviceId());
//            qsDevice.setSnap(filePath);
//            R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER);
//            if (r.getCode() != Constants.SUCCESS) {
//                throw new RuntimeException("更新设备失败");
//            }
        });
        IMediaNodeServerService mediaNodeServerService = nodeServerServiceMap.get(mediaServer.getType());
@@ -686,16 +688,16 @@
        }
        String key = mediaNodeServerService.startProxy(mediaServer, streamPullPlay);
        QsDevice qsDevice = new QsDevice();
        qsDevice.setId(streamPullPlay.getDeviceId());
        qsDevice.setStreamKey(key);
        qsDevice.setMediaServerId(mediaServer.getId());
        qsDevice.setStreamStatus("1");
        R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER);
        if (r.getCode() != Constants.SUCCESS) {
            log.error("更新设备失败");
            callback.run(InviteErrorCode.FAIL.getCode(), "更新设备失败", null);
        }
//        QsDevice qsDevice = new QsDevice();
//        qsDevice.setId(streamPullPlay.getDeviceId());
//        qsDevice.setStreamKey(key);
//        qsDevice.setMediaServerId(mediaServer.getId());
//        qsDevice.setStreamStatus("1");
//        R<Boolean> r = remoteQsDeviceService.updateQsDevice(qsDevice, SecurityConstants.INNER);
//        if (r.getCode() != Constants.SUCCESS) {
//            log.error("更新设备失败");
//            callback.run(InviteErrorCode.FAIL.getCode(), "更新设备失败", null);
//        }
    }
    /**
@@ -945,7 +947,6 @@
     * @param rtpServerParam 创建rtp端口请求参数
     * @param device         设备信息
     * @param ssrc           ssrc
     * @param record         是否录制
     * @param callback       回调
     * @return
     */