| | |
| | | package com.ard.device.channel.service.impl; |
| | | |
| | | import com.ard.common.constant.CacheConstants; |
| | | import com.ard.common.constant.UserConstants; |
| | | import com.ard.common.core.redis.RedisCache; |
| | | import com.ard.common.utils.uuid.IdUtils; |
| | | import com.ard.device.camera.domain.ArdCamera; |
| | | import com.ard.device.camera.service.IArdCameraService; |
| | |
| | | import com.ard.vtdu.domain.ArdVtdu; |
| | | import com.ard.vtdu.service.IArdVtduService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class ArdChannelServiceImpl implements IArdChannelService { |
| | | @Resource |
| | | private IArdCameraService ardCameraService; |
| | | // @Resource |
| | | //private IArdCameraService ardCameraService; |
| | | @Resource |
| | | private ArdChannelMapper ardChannelMapper; |
| | | @Resource |
| | | private IArdVtduService ardVtduService; |
| | | @Resource |
| | | private MediamtxConfig mediamtxConfig; |
| | | @Resource |
| | | private RedisCache redisCache; |
| | | |
| | | /** |
| | | * 查询通道管理 |
| | | * |
| | |
| | | * 清空通道 |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2024/8/10 11:18 |
| | | * @date 2024/8/10 11:18 |
| | | */ |
| | | @Override |
| | | public int clearArdChannel(){ |
| | | public int clearArdChannel() { |
| | | return ardChannelMapper.clearArdChannel(); |
| | | } |
| | | |
| | | /** |
| | | * 删除通道管理信息 |
| | | * |
| | |
| | | public int deleteArdChannelByDeviceId(String deviceId) { |
| | | return ardChannelMapper.deleteArdChannelByDeviceId(deviceId); |
| | | } |
| | | |
| | | /** |
| | | * 校验相机通道是否唯一 |
| | | * |
| | |
| | | @Override |
| | | public boolean checkArdChannelUnique(ArdChannel channel) { |
| | | ArdChannel info = ardChannelMapper.checkArdChannelUnique(channel); |
| | | if (info != null && !Objects.equals(info.getId(), channel.getId())) |
| | | { |
| | | if (info != null && !Objects.equals(info.getId(), channel.getId())) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | } |
| | | |
| | | |
| | | @Scheduled(cron = "0/5 * * * * ?") |
| | | @Scheduled(fixedDelay = 5000) |
| | | public void syncVtdu() { |
| | | log.debug("定时同步Vtdu任务"); |
| | | List<ArdChannel> channels = this.selectArdChannelList(new ArdChannel()); |
| | | if (channels == null || channels.isEmpty()) { |
| | | // log.warn("没有获取到通道数据,退出同步"); |
| | | // log.warn("没有获取到通道数据,退出同步"); |
| | | return; |
| | | } |
| | | List<ArdVtdu> ardVtduList = ardVtduService.selectArdVtduList(new ArdVtdu()); |
| | |
| | | String name = channel.getDeviceId() + "_" + channel.getChanNo(); // 生成媒体表的 name |
| | | String cameraId = channel.getDeviceId(); // cameraId 就是通道的 deviceId |
| | | String rtspSourceUrl = getRtspSource(channel); |
| | | String rtspUrl = "rtsp://" + mediamtxConfig.getPlayHost() + ":8554" + "/" + name; // 拼接 webrtcUrl |
| | | String rtmpUrl = "rtmp://" + mediamtxConfig.getPlayHost() + ":1935" + "/" + name; // 拼接 webrtcUrl |
| | | String rtspUrl = |
| | | "rtsp://" + mediamtxConfig.getPlayHost() + ":" + mediamtxConfig.getRtspPort() + "/" + name; // |
| | | // 拼接 webrtcUrl |
| | | String rtmpUrl = |
| | | "rtmp://" + mediamtxConfig.getPlayHost() + ":" + mediamtxConfig.getRtmpPort() + "/" + name; // 拼接 |
| | | // webrtcUrl |
| | | String protocol = mediamtxConfig.isHttps() ? "https://" : "http://"; |
| | | String webrtcUrl = protocol + mediamtxConfig.getPlayHost() + ":8889" + "/" + name; // 拼接 webrtcUrl |
| | | String webrtcUrl = |
| | | protocol + mediamtxConfig.getPlayHost() + ":" + mediamtxConfig.getWebrtcPort() + "/" + name; |
| | | // 拼接 webrtcUrl |
| | | |
| | | // 先检查媒体表是否已有此记录 |
| | | Optional<ArdVtdu> existingMedia = ardVtduList.stream() |
| | |
| | | // 根据通道信息获取rtsp源地址 |
| | | private String getRtspSource(ArdChannel channel) { |
| | | String rtspSource = ""; |
| | | ArdCamera ardCamera =ardCameraService.selectArdCameraById(channel.getDeviceId()); |
| | | ArdCamera ardCamera = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + channel.getDeviceId()); |
| | | if (ardCamera != null) { |
| | | switch (ardCamera.getFactory()) { |
| | | case "1": |