package com.ard.device.component.sdk.service;
|
|
import com.ard.common.constant.CacheConstants;
|
import com.ard.common.core.domain.AjaxResult;
|
import com.ard.common.core.redis.RedisCache;
|
import com.ard.device.camera.domain.ArdCamera;
|
import com.ard.device.camera.domain.CameraCmd;
|
import com.ard.device.channel.domain.ArdChannel;
|
import com.ard.device.channel.domain.VideoCompressionCfg;
|
import com.ard.device.component.sdk.common.GlobalVariable;
|
import com.ard.device.component.sdk.factory.CameraSDKFactory;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Service;
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
|
/**
|
* @Description: 相机sdk业务
|
* @ClassName: CameraSdkServiceImpl
|
* @Author: 刘苏义
|
* @Date: 2023年10月16日15:21:01
|
**/
|
@Service
|
@Slf4j
|
public class CameraSDKService {
|
|
@Resource
|
private RedisCache redisService;
|
|
@Resource
|
private CameraSDKFactory cameraSDKFactory;
|
|
//异步登录
|
@Async
|
public AjaxResult login(ArdCamera ardCamera) {
|
try {
|
if (ardCamera == null) {
|
return AjaxResult.warn("设备不存在");
|
}
|
String factory = ardCamera.getFactory();
|
CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
return cameraSDK.login(ardCamera);//异步登录
|
} catch (Exception ex) {
|
log.error("登录异常:{}", ex.getMessage());
|
return AjaxResult.error("登录异常:" + ex.getMessage());
|
}
|
}
|
|
//注销
|
public boolean logout(String cameraId) {
|
boolean result = false;
|
try {
|
ArdCamera ardCamera = redisService.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId);
|
if (ardCamera != null) {
|
String factory = ardCamera.getFactory();
|
CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
result = cameraSDK.logout(cameraId);
|
if (result) {
|
GlobalVariable.loginMap.remove(cameraId);//移除相机登录id缓存
|
}
|
}
|
} catch (Exception ex) {
|
log.error("注销异常:{}", ex.getMessage());
|
return false;
|
}
|
return result;
|
}
|
|
//在线检测
|
public boolean isOnLine(CameraCmd cmd) {
|
try {
|
boolean onLine = false;
|
String cameraId = cmd.getCameraId();
|
ArdCamera ardCamera = redisService.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId);
|
if (ardCamera != null) {
|
String factory = ardCamera.getFactory();
|
CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
onLine = cameraSDK.isOnLine(cmd);
|
}
|
return onLine;
|
} catch (Exception ex) {
|
log.error("检测在线异常:{}", ex.getMessage());
|
return false;
|
}
|
}
|
|
//获取码流压缩参数
|
public VideoCompressionCfg getVideoCompressionCfg(CameraCmd cmd) {
|
try {
|
String cameraId = cmd.getCameraId();
|
ArdCamera ardCamera = redisService.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId);
|
if (ardCamera == null) {
|
return null;
|
}
|
String factory = ardCamera.getFactory();
|
CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(factory);
|
return cameraSDK.getVideoCompressionCfg(cmd);
|
} catch (Exception ex) {
|
log.error("获取码流压缩参数异常:{}", ex.getMessage());
|
return null;
|
}
|
}
|
|
//获取通道列表
|
public List<ArdChannel> getChannels(ArdCamera camera) {
|
try {
|
CameraSDK cameraSDK = cameraSDKFactory.createCameraSDK(camera.getFactory());
|
return cameraSDK.getChannels(camera);
|
} catch (Exception ex) {
|
log.error("获取相机通道异常:{}", ex.getMessage());
|
return null;
|
}
|
}
|
}
|