From 8456b0bbb9d1536ebb0b2dc476be736bdd5fb82c Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期五, 13 十月 2023 15:58:20 +0800
Subject: [PATCH] 1. 流媒体增加通过接口配置软硬件解码 2. 流媒体自动同步相机设备。
---
ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java | 26 +
ard-work/src/main/java/com/ruoyi/media/controller/MediaController.java | 21
ard-work/src/main/java/com/ruoyi/media/domain/StreamInfo.java | 2
ard-work/src/main/java/com/ruoyi/media/service/IMediaService.java | 19 +
ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/SyncTask.java | 59 ++
ruoyi-admin/src/main/resources/application.yml | 2
ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java | 14
ard-work/src/main/java/com/ruoyi/media/domain/Vtdu.java | 12
ard-work/src/main/resources/templates/preview.html | 2
ard-work/pom.xml | 2
ard-work/src/main/java/com/ruoyi/media/mapper/VtduMapper.java | 11
ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java | 46 +
ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java | 53 +++
ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml | 35 +
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java | 216 ++++++-------
ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java | 309 ++++++++++++++----
ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java | 11
ard-work/src/main/java/com/ruoyi/media/domain/Config.java | 18 +
ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java | 7
ard-work/src/main/java/com/ruoyi/media/service/IVtduService.java | 8
ard-work/src/main/java/com/ruoyi/device/hiksdk/sdk/LoginResultCallBack.java | 29 +
21 files changed, 633 insertions(+), 269 deletions(-)
diff --git a/ard-work/pom.xml b/ard-work/pom.xml
index 2b163b3..6a534ec 100644
--- a/ard-work/pom.xml
+++ b/ard-work/pom.xml
@@ -93,7 +93,7 @@
<dependency>
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-spring-boot-starter</artifactId>
- <version>1.5.28</version>
+ <version>1.5.33</version>
</dependency>
<!--lombok渚濊禆-->
<dependency>
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java b/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
index b3c6f7e..ccd6313 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
@@ -7,12 +7,15 @@
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.service.IArdCamerasService;
+import com.ruoyi.device.hiksdk.service.IHikClientService;
import com.ruoyi.device.hiksdk.service.impl.HikClientServiceImpl;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.inspect.service.IArdVideoInspectTaskService;
+import com.ruoyi.media.service.IVtduService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -41,7 +44,7 @@
@Api(tags = "鐩告満绠$悊鎺ュ彛")
public class ArdCamerasController extends BaseController {
@Resource
- private HikClientServiceImpl sdk;
+ private IHikClientService sdk;
@Resource
private IArdCamerasService ardCamerasService;
@Resource
@@ -90,11 +93,14 @@
@Log(title = "鐩告満璁惧", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ArdCameras camera) {
- //娉ㄩ攢
- sdk.loginOut(camera.getId());
- //鐧诲綍
- sdk.login(camera);
- return toAjax(ardCamerasService.insertArdCameras(camera));
+ int i = ardCamerasService.insertArdCameras(camera);
+ if(i>0) {
+ //娉ㄩ攢
+ sdk.loginOut(camera.getId());
+ //寮傛鐧诲綍
+ sdk.asyncLogin(camera);
+ }
+ return toAjax(i);
}
/**
@@ -106,10 +112,11 @@
@PutMapping
public AjaxResult edit(@RequestBody ArdCameras camera) {
int i = ardCamerasService.updateArdCameras(camera);
- if (i > 0) {
+ if(i>0)
+ {
ArdCameras cameras = ardCamerasService.selectArdCamerasById(camera.getId());
sdk.loginOut(cameras.getId());
- sdk.login(cameras);
+ sdk.asyncLogin(cameras);
}
return toAjax(i);
}
@@ -122,7 +129,8 @@
@Log(title = "鐩告満璁惧", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable String[] ids) {
- for (String id : ids) {
+ for(String id :ids)
+ {
sdk.loginOut(id);
}
return toAjax(ardCamerasService.deleteArdCamerasByIds(ids));
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
index af164ea..e44f979 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
@@ -12,6 +12,8 @@
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.channel.domain.ArdChannel;
import com.ruoyi.device.channel.mapper.ArdChannelMapper;
+import com.ruoyi.device.hiksdk.service.IHikClientService;
+import com.ruoyi.media.service.IVtduService;
import com.ruoyi.scheduling.domian.SchedulingParam;
import com.ruoyi.utils.gis.GisUtil;
import com.ruoyi.utils.tools.ArdTool;
@@ -45,7 +47,8 @@
@Resource
private ArdChannelMapper ardChannelMapper;
-
+ @Resource
+ private IVtduService vtduService;
@PostConstruct
public void loadCameras() {
@@ -160,6 +163,8 @@
if (res > 0) {
for (String id : ids) {
redisCache.deleteObject(getCacheKey(id));
+ //鍒犻櫎娴佸獟浣�
+ vtduService.deleteVtduByCameraId(id);
//鍒犻櫎褰撳墠鐩告満鐨勬墍鏈夐�氶亾
ardChannelMapper.deleteArdChannelByDeviceId(id);
}
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/sdk/LoginResultCallBack.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/sdk/LoginResultCallBack.java
index a665815..3b8c8d9 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/sdk/LoginResultCallBack.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/sdk/LoginResultCallBack.java
@@ -10,9 +10,13 @@
import com.ruoyi.device.channel.service.IArdChannelService;
import com.ruoyi.device.hiksdk.common.GlobalVariable;
import com.ruoyi.device.hiksdk.service.IHikClientService;
+import com.ruoyi.media.domain.Vtdu;
+import com.ruoyi.media.service.IVtduService;
+import com.ruoyi.utils.forest.MediaClient;
import com.sun.jna.Pointer;
import lombok.extern.slf4j.Slf4j;
+import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.PriorityBlockingQueue;
@@ -35,6 +39,8 @@
@Override
public int invoke(int lUserID, int dwResult, HCNetSDK.NET_DVR_DEVICEINFO_V30 lpDeviceinfo, Pointer pUser) {
+ MediaClient mediaClient=SpringUtils.getBean(MediaClient.class);
+ IVtduService vtduService = SpringUtils.getBean(IVtduService.class);
IArdChannelService ardChannelService = SpringUtils.getBean(IArdChannelService.class);
IHikClientService hikClientService = SpringUtils.getBean(IHikClientService.class);
IArdCamerasService ardCamerasService = SpringUtils.getBean(IArdCamerasService.class);
@@ -53,10 +59,33 @@
//鑾峰彇鏈�鏂伴�氶亾
List<ArdChannel> cameraChannelList = hikClientService.getCameraChannelList(camera);
if (cameraChannelList.size() > 0) {
+ //娣诲姞閫氶亾
for (ArdChannel channel : cameraChannelList) {
channel.setId(IdUtils.simpleUUID());
ardChannelService.insertArdChannel(channel);
}
+ //閰嶇疆鍒版祦濯掍綋
+ for (ArdChannel channel : cameraChannelList) {
+ String name = camera.getId() + "_" + channel.getChanNo();
+ String rtspSource = "rtsp://" + camera.getUsername() + ":" + camera.getPassword() + "@" + camera.getIp() + ":" + camera.getRtspPort() + "/h264/ch" + channel.getChanNo() + "/main/av_stream";
+ Vtdu vtdu = vtduService.selectVtduByName(name);
+ if (vtdu == null) {
+ //娣诲姞鍒版祦濯掍綋
+ vtdu = new Vtdu();
+ vtdu.setRtspSource(rtspSource);
+ vtdu.setName(camera.getId() + "_" + channel.getChanNo());
+ vtdu.setIsCode("0");//榛樿涓嶈浆鐮�
+ vtdu.setMode("1");//榛樿CPU杞В鐮�
+ vtdu.setCameraId(camera.getId());
+ vtduService.insertVtdu(vtdu);
+ } else {
+ if (!rtspSource.equals(vtdu.getRtspSource())) {
+ //鏇存柊rtsp鍦板潃
+ vtdu.setRtspSource(rtspSource);
+ vtduService.updateVtdu(vtdu);
+ }
+ }
+ }
}
//鍒涘缓寮曞闃熷垪
if (!GuidePriorityQueue.cameraQueueMap.containsKey(camera.getId())) {
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
index eceef2f..586c9f6 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/IHikClientService.java
@@ -17,8 +17,11 @@
public interface IHikClientService {
void loadHCNetSDKLib();
- //鐧诲綍
- void login(ArdCameras cameras);
+ //鍚屾鐧诲綍
+ void syncLogin(ArdCameras cameras);
+
+ //寮傛鐧诲綍
+ void asyncLogin(ArdCameras cameras);
//鐧诲綍鎵�鏈夌浉鏈�
void loginAll();
@@ -36,7 +39,7 @@
boolean setFocusPos(CameraCmd cmd);
//鑾峰彇鑱氱劍鍊�
- Map<String,Object> getFocusPos(CameraCmd cmd);
+ Map<String, Object> getFocusPos(CameraCmd cmd);
//璁剧疆棰勭疆浣�
boolean setPreset(CameraCmd cmd);
@@ -45,7 +48,7 @@
boolean gotoPreset(CameraCmd cmd);
//鑾峰彇鐮佹祦鍘嬬缉鍙傛暟
- Map<String,String> getVideoCompressionCfg(CameraCmd cmd);
+ Map<String, String> getVideoCompressionCfg(CameraCmd cmd);
//閫忛浘
boolean controlDefogcfg(CameraCmd cmd);
@@ -109,6 +112,7 @@
//鑾峰彇鐩告満閫氶亾淇℃伅
public List<ArdChannel> getCameraChannelList(ArdCameras camera);
+
//鑾峰彇GIS淇℃伅鏁版嵁
- public Map<String,Object> getGisInfo(CameraCmd cmd);
+ public Map<String, Object> getGisInfo(CameraCmd cmd);
}
diff --git a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
index 3485345..e803ca0 100644
--- a/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/hiksdk/service/impl/HikClientServiceImpl.java
@@ -1,14 +1,20 @@
package com.ruoyi.device.hiksdk.service.impl;
+import com.ruoyi.alarm.global.domain.GuidePriorityQueue;
+import com.ruoyi.alarm.global.domain.GuideTask;
import com.ruoyi.common.annotation.SdkOperate;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.common.utils.file.MimeTypeUtils;
+import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.service.IArdCamerasService;
import com.ruoyi.device.channel.domain.ArdChannel;
+import com.ruoyi.device.channel.service.IArdChannelService;
import com.ruoyi.device.hiksdk.common.GlobalVariable;
import com.ruoyi.device.camera.domain.ArdCameras;
+import com.ruoyi.media.domain.Vtdu;
+import com.ruoyi.media.service.IVtduService;
import com.ruoyi.utils.gis.GisUtil;
import com.ruoyi.device.hiksdk.sdk.HCNetSDK;
import com.ruoyi.device.hiksdk.service.IHikClientService;
@@ -30,6 +36,7 @@
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.util.*;
+import java.util.concurrent.PriorityBlockingQueue;
import static com.ruoyi.device.hiksdk.sdk.HCNetSDK.*;
@@ -44,10 +51,12 @@
@Service
public class HikClientServiceImpl implements IHikClientService {
- @Value("${minio.endpoint}")
- private static String endpoint;
@Resource
private IArdCamerasService ardCamerasService;
+ @Resource
+ private IArdChannelService ardChannelService;
+ @Resource
+ private IVtduService vtduService;
private static HCNetSDK hCNetSDK;
@@ -92,6 +101,7 @@
}
}
+ @Override
/**
* @鎻忚堪 娉ㄥ唽鐧诲綍 鍙敮鎸佸悓姝ョ櫥闄嗭紝涓斿畼鏂逛笉寤鸿鐩存帴鍦ㄦ鎺ュ彛涓嬪啓鑰楁椂鎿嶄綔
* @鍙傛暟 [dvrLogin]
@@ -100,14 +110,13 @@
* @鍒涘缓鏃堕棿 2023/1/17 16:12
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
- public ArdCameras login1(ArdCameras camera) {
+ public void syncLogin(ArdCameras camera) {
// 鍒濆鍖�
if (!hCNetSDK.NET_DVR_Init()) {
log.error("SDK鍒濆鍖栧け璐�");
}
//鎵撳嵃娴峰悍sdk鏃ュ織
if (Platform.isWindows()) {
-
String WIN_PATH = System.getProperty("user.dir") + File.separator + "ardLog" + File.separator + "logs" + File.separator;
hCNetSDK.NET_DVR_SetLogToFile(3, WIN_PATH, true);
} else {
@@ -121,18 +130,84 @@
hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
hCNetSDK.NET_DVR_SetReconnect(100000, true);
//璁惧淇℃伅, 杈撳嚭鍙傛暟
- NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new NET_DVR_DEVICEINFO_V30();
- int lUserID = hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP, m_sPort, m_sUsername, m_sPassword, m_strDeviceInfo);
+ HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();
+ HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();
+
+ // 娉ㄥ唽璁惧-鐧诲綍鍙傛暟锛屽寘鎷澶囧湴鍧�銆佺櫥褰曠敤鎴枫�佸瘑鐮佺瓑
+ m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
+ System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
+ m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
+ System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
+ m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
+ System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
+ m_strLoginInfo.wPort = m_sPort;
+ m_strLoginInfo.byVerifyMode = 0;
+ m_strLoginInfo.byLoginMode = 0;
+ //鏄惁寮傛鐧诲綍锛�0- 鍚︼紝1- 鏄� windowsSDK閲屾槸true鍜宖alse
+ m_strLoginInfo.bUseAsynLogin = false;
+ m_strLoginInfo.write();
+ //鍚屾鐧诲綍
+ int lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
if (lUserID < 0) {
- //閲婃斁SDK璧勬簮
- hCNetSDK.NET_DVR_Cleanup();
+ int errorCode = hCNetSDK.NET_DVR_GetLastError();
+ log.error("鐧诲綍寮傚父锛�" + errorCode);
+
+ log.debug(camera.getIp() + ":" + camera.getPort() + "鐧诲綍澶辫触");
+ camera.setChanNum(0);
camera.setLoginId(-1);
+ camera.setState("0");
+ } else {
+
+ if (GlobalVariable.loginMap.containsKey(camera.getId())) {
+ GlobalVariable.loginMap.remove(camera.getId());
+ }
+ //鍒犻櫎绠$悊閫氶亾
+ ardChannelService.deleteArdChannelByDeviceId(camera.getId());
+ GlobalVariable.loginMap.put(camera.getId(), lUserID);
+ log.debug(camera.getIp() + ":" + camera.getPort() + "鐧诲綍鎴愬姛");
+
+ camera.setLoginId(lUserID);
+ camera.setState("1");
+ camera.setChanNum((int) m_strDeviceInfo.struDeviceV30.byChanNum);
+ camera.setStartDChan((int) m_strDeviceInfo.struDeviceV30.byStartDChan);
+ //鑾峰彇鏈�鏂伴�氶亾
+ List<ArdChannel> cameraChannelList = getCameraChannelList(camera);
+ if (cameraChannelList.size() > 0) {
+ for (ArdChannel channel : cameraChannelList) {
+ channel.setId(IdUtils.simpleUUID());
+ ardChannelService.insertArdChannel(channel);
+ }
+ //娣诲姞鍒版祦濯掍綋
+ for (ArdChannel channel : cameraChannelList) {
+ String name = camera.getId() + "_" + channel.getChanNo();
+ String rtspSource = "rtsp://" + camera.getUsername() + ":" + camera.getPassword() + "@" + camera.getIp() + ":" + camera.getRtspPort() + "/h264/ch" + channel.getChanNo() + "/main/av_stream";
+ Vtdu vtdu = vtduService.selectVtduByName(name);
+ if (vtdu == null) {
+ //娣诲姞鍒版祦濯掍綋
+ vtdu = new Vtdu();
+ vtdu.setRtspSource(rtspSource);
+ vtdu.setName(camera.getId() + "_" + channel.getChanNo());
+ vtdu.setIsCode("0");//榛樿涓嶈浆鐮�
+ vtdu.setMode("1");//榛樿CPU杞В鐮�
+ vtdu.setCameraId(camera.getId());
+ vtduService.insertVtdu(vtdu);
+ } else {
+ if (!rtspSource.equals(vtdu.getRtspSource())) {
+ //鏇存柊rtsp鍦板潃
+ vtdu.setRtspSource(rtspSource);
+ vtduService.updateVtdu(vtdu);
+ }
+ }
+ }
+ }
+ //鍒涘缓寮曞闃熷垪
+ if (!GuidePriorityQueue.cameraQueueMap.containsKey(camera.getId())) {
+ Comparator<GuideTask> comparator = GuidePriorityQueue.getComparator();
+ PriorityBlockingQueue<GuideTask> priorityQueue = new PriorityBlockingQueue<>(1000, comparator);
+ GuidePriorityQueue.cameraQueueMap.put(camera.getId(), priorityQueue);
+ }
+ ardCamerasService.updateArdCameras(camera);
}
- GlobalVariable.loginMap.remove(camera.getId());
- GlobalVariable.loginMap.put(camera.getId(), lUserID);
- camera.setLoginId(lUserID);
- camera.setStartDChan((int) m_strDeviceInfo.byStartChan);
- return camera;
}
/**
@@ -144,7 +219,7 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- public void login(ArdCameras camera) {
+ public void asyncLogin(ArdCameras camera) {
// 鍒濆鍖�
if (!hCNetSDK.NET_DVR_Init()) {
log.error("SDK鍒濆鍖栧け璐�");
@@ -187,6 +262,7 @@
int errorCode = hCNetSDK.NET_DVR_GetLastError();
log.error("鐧诲綍寮傚父锛�" + errorCode);
}
+
}
/**
@@ -204,7 +280,8 @@
List<ArdCameras> ardCameras = ardCamerasService.selectArdCamerasListNoDataScope(new ArdCameras());
for (ArdCameras camera : ardCameras) {
Thread.sleep(500);
- login(camera);
+ //寮傛鐧诲綍
+ asyncLogin(camera);
}
} catch (Exception ex) {
log.error("鍒濆鍖栫櫥褰曠浉鏈哄紓甯革細" + ex.getMessage());
@@ -239,12 +316,17 @@
*/
@Override
public boolean isOnLine(CameraCmd cmd) {
- String cameraId = cmd.getCameraId();
- if (!GlobalVariable.loginMap.containsKey(cameraId)) {
+ try {
+ String cameraId = cmd.getCameraId();
+ if (!GlobalVariable.loginMap.containsKey(cameraId)) {
+ return false;
+ }
+ Integer userId = GlobalVariable.loginMap.get(cameraId);
+ return hCNetSDK.NET_DVR_RemoteControl(userId, NET_DVR_CHECK_USER_STATUS, null, 0);
+ } catch (Exception ex) {
+ log.error("妫�娴嬪湪绾垮紓甯革細" + ex.getMessage());
return false;
}
- Integer userId = GlobalVariable.loginMap.get(cameraId);
- return hCNetSDK.NET_DVR_RemoteControl(userId, HCNetSDK.NET_DVR_CHECK_USER_STATUS, null, 0);
}
/**
@@ -466,7 +548,7 @@
* @淇敼浜哄拰鍏跺畠淇℃伅
*/
@Override
- public Map<String,String> getVideoCompressionCfg(CameraCmd cmd) {
+ public Map<String, String> getVideoCompressionCfg(CameraCmd cmd) {
String cameraId = cmd.getCameraId();
Integer chanNo = cmd.getChanNo();
if (!GlobalVariable.loginMap.containsKey(cameraId)) {
@@ -474,7 +556,7 @@
}
Integer userId = GlobalVariable.loginMap.get(cameraId);
- Map<String,String> map=new HashMap<>();
+ Map<String, String> map = new HashMap<>();
NET_DVR_COMPRESSIONCFG_V30 compressioncfg = new NET_DVR_COMPRESSIONCFG_V30();
compressioncfg.write();
Pointer pioint = compressioncfg.getPointer();
@@ -484,62 +566,139 @@
if (bool) {
compressioncfg.read();
//鐮佹祦绫诲瀷锛�0-瑙嗛娴侊紝1-澶嶅悎娴侊紝0xfe- 鑷姩锛堝拰婧愪竴鑷达級
- String streamType="";
- switch(compressioncfg.struNormHighRecordPara.byStreamType)
- {
- case 0: streamType="瑙嗛娴�";break;
- case 1: streamType="澶嶅悎娴�";break;
- default:streamType="鏈煡";break;
+ String streamType = "";
+ switch (compressioncfg.struNormHighRecordPara.byStreamType) {
+ case 0:
+ streamType = "瑙嗛娴�";
+ break;
+ case 1:
+ streamType = "澶嶅悎娴�";
+ break;
+ default:
+ streamType = "鏈煡";
+ break;
}
//瑙嗛缂栫爜绫诲瀷锛�0-绉佹湁264锛�1-鏍囧噯h264锛�2-鏍囧噯mpeg4锛�7-M-JPEG锛�8-MPEG2锛�9-SVAC锛�10-鏍囧噯h265锛�0xfe- 鑷姩锛堝拰婧愪竴鑷达級锛�0xff-鏃犳晥
- String videoEncType="";
- switch (compressioncfg.struNormHighRecordPara.byVideoEncType)
- {
- case 0:videoEncType="绉佹湁264";break;
- case 1:videoEncType="鏍囧噯h264";break;
- case 2:videoEncType="鏍囧噯mpeg4";break;
- case 7:videoEncType="M-JPEG";break;
- case 8:videoEncType="MPEG2";break;
- case 9:videoEncType="SVAC";break;
- case 10:videoEncType="鏍囧噯h265";break;
- default: videoEncType="鏈煡";break;
+ String videoEncType = "";
+ switch (compressioncfg.struNormHighRecordPara.byVideoEncType) {
+ case 0:
+ videoEncType = "绉佹湁264";
+ break;
+ case 1:
+ videoEncType = "鏍囧噯h264";
+ break;
+ case 2:
+ videoEncType = "鏍囧噯mpeg4";
+ break;
+ case 7:
+ videoEncType = "M-JPEG";
+ break;
+ case 8:
+ videoEncType = "MPEG2";
+ break;
+ case 9:
+ videoEncType = "SVAC";
+ break;
+ case 10:
+ videoEncType = "鏍囧噯h265";
+ break;
+ default:
+ videoEncType = "鏈煡";
+ break;
}
//瑙嗛鐮佺巼
- String videoBitrate="";
- switch (compressioncfg.struNormHighRecordPara.dwVideoBitrate)
- {
- case 0:videoBitrate="淇濈暀";break;
- case 1:videoBitrate="16K(淇濈暀)";break;
- case 2:videoBitrate="32K";break;
- case 3:videoBitrate="48k";break;
- case 4:videoBitrate="64k";break;
- case 5:videoBitrate="80k";break;
- case 6:videoBitrate="96k";break;
- case 7:videoBitrate="128k";break;
- case 8:videoBitrate="160k";break;
- case 9:videoBitrate="192k";break;
- case 10:videoBitrate="224k";break;
- case 11:videoBitrate="256K";break;
- case 12:videoBitrate="320K";break;
- case 13:videoBitrate="384K";break;
- case 14:videoBitrate="448K";break;
- case 15:videoBitrate="512K";break;
- case 16:videoBitrate="640K";break;
- case 17:videoBitrate="768K";break;
- case 18:videoBitrate="896K";break;
- case 19:videoBitrate="1024K";break;
- case 20:videoBitrate="1280K";break;
- case 21:videoBitrate="1536K";break;
- case 22:videoBitrate="1792K";break;
- case 23:videoBitrate="2048K";break;
- case 24:videoBitrate="3072K";break;
- case 25:videoBitrate="4096K";break;
- case 26:videoBitrate="8192K";break;
- case 27:videoBitrate="16384K";break;
- default:videoBitrate="鍏朵粬";break;
+ String videoBitrate = "";
+ switch (compressioncfg.struNormHighRecordPara.dwVideoBitrate) {
+ case 0:
+ videoBitrate = "淇濈暀";
+ break;
+ case 1:
+ videoBitrate = "16K(淇濈暀)";
+ break;
+ case 2:
+ videoBitrate = "32K";
+ break;
+ case 3:
+ videoBitrate = "48k";
+ break;
+ case 4:
+ videoBitrate = "64k";
+ break;
+ case 5:
+ videoBitrate = "80k";
+ break;
+ case 6:
+ videoBitrate = "96k";
+ break;
+ case 7:
+ videoBitrate = "128k";
+ break;
+ case 8:
+ videoBitrate = "160k";
+ break;
+ case 9:
+ videoBitrate = "192k";
+ break;
+ case 10:
+ videoBitrate = "224k";
+ break;
+ case 11:
+ videoBitrate = "256K";
+ break;
+ case 12:
+ videoBitrate = "320K";
+ break;
+ case 13:
+ videoBitrate = "384K";
+ break;
+ case 14:
+ videoBitrate = "448K";
+ break;
+ case 15:
+ videoBitrate = "512K";
+ break;
+ case 16:
+ videoBitrate = "640K";
+ break;
+ case 17:
+ videoBitrate = "768K";
+ break;
+ case 18:
+ videoBitrate = "896K";
+ break;
+ case 19:
+ videoBitrate = "1024K";
+ break;
+ case 20:
+ videoBitrate = "1280K";
+ break;
+ case 21:
+ videoBitrate = "1536K";
+ break;
+ case 22:
+ videoBitrate = "1792K";
+ break;
+ case 23:
+ videoBitrate = "2048K";
+ break;
+ case 24:
+ videoBitrate = "3072K";
+ break;
+ case 25:
+ videoBitrate = "4096K";
+ break;
+ case 26:
+ videoBitrate = "8192K";
+ break;
+ case 27:
+ videoBitrate = "16384K";
+ break;
+ default:
+ videoBitrate = "鍏朵粬";
+ break;
}
//瑙嗛杈撳嚭鍙e垎杈ㄧ巼锛�0- 1024x768锛�1- 1280x720锛�2-1280x1024锛�3- 1680x1050锛�4- 1920x1080锛�5- 3840*2160
- String resolution="";
+ String resolution = "";
switch (compressioncfg.struNormHighRecordPara.byResolution) {
case 0:
resolution = "DCIF(528*384/528*320)";
@@ -605,10 +764,10 @@
resolution = "涓嶅湪褰撳墠鍒嗚鲸鐜囩储寮曪紝璇疯仈绯荤鐞嗗憳娣诲姞";
break;
}
- map.put("resolution",resolution);
- map.put("videoBitrate",videoBitrate);
- map.put("videoEncType",videoEncType);
- map.put("streamType",streamType);
+ map.put("resolution", resolution);
+ map.put("videoBitrate", videoBitrate);
+ map.put("videoEncType", videoEncType);
+ map.put("streamType", streamType);
} else {
int code = hCNetSDK.NET_DVR_GetLastError();
diff --git a/ard-work/src/main/java/com/ruoyi/media/controller/MediaController.java b/ard-work/src/main/java/com/ruoyi/media/controller/MediaController.java
index 48490b4..e24e4e6 100644
--- a/ard-work/src/main/java/com/ruoyi/media/controller/MediaController.java
+++ b/ard-work/src/main/java/com/ruoyi/media/controller/MediaController.java
@@ -7,6 +7,7 @@
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.media.domain.Config;
import com.ruoyi.media.domain.StreamInfo;
import com.ruoyi.media.domain.Vtdu;
import com.ruoyi.media.service.IMediaService;
@@ -56,9 +57,9 @@
map.get("rtspUrl");
Vtdu vtdu = new Vtdu();
vtdu.setName(streamInfo.getName());
- vtdu.setSourceUrl(streamInfo.getRtspSource());
+ vtdu.setRtspSource(streamInfo.getRtspSource());
vtdu.setIsCode(streamInfo.getIsCode());
- vtdu.setCodeType(streamInfo.getMode());
+ vtdu.setMode(streamInfo.getMode());
vtdu.setRtspUrl(map.get("rtspUrl"));
vtdu.setRtmpUrl(map.get("rtmpUrl"));
vtdu.setWebrtcUrl(map.get("webrtcUrl"));
@@ -78,9 +79,9 @@
Map<String, String> map = mediaService.editPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(), streamInfo.getIsCode());
Vtdu vtdu = new Vtdu();
vtdu.setName(streamInfo.getName());
- vtdu.setSourceUrl(streamInfo.getRtspSource());
+ vtdu.setRtspSource(streamInfo.getRtspSource());
vtdu.setIsCode(streamInfo.getIsCode());
- vtdu.setCodeType(streamInfo.getMode());
+ vtdu.setMode(streamInfo.getMode());
vtdu.setRtspUrl(map.get("rtspUrl"));
vtdu.setRtmpUrl(map.get("rtmpUrl"));
vtdu.setWebrtcUrl(map.get("webrtcUrl"));
@@ -178,8 +179,6 @@
return getDataTable(mediaService.getPushStreamList());
}
-
-
/**
* 鑾峰彇鎷夋祦鍒楄〃
*/
@@ -191,4 +190,14 @@
startPage();
return getDataTable(mediaService.getPullStreamList());
}
+
+ /**
+ * 閰嶇疆娴佸獟浣撳弬鏁�
+ */
+ @PostMapping("/setConfig")
+ @ApiOperation("閰嶇疆娴佸獟浣撳弬鏁�")
+ @ApiOperationSupport(order = 8)
+ public AjaxResult setConfig(@RequestBody Config config) {
+ return AjaxResult.success(mediaService.setConfig(config));
+ }
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java b/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java
index e6847aa..5ea0a2d 100644
--- a/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java
+++ b/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java
@@ -1,7 +1,12 @@
package com.ruoyi.media.controller;
import java.util.List;
+import java.util.Map;
+import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.media.service.IMediaService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -77,6 +82,12 @@
@PostMapping
public AjaxResult add(@RequestBody Vtdu vtdu)
{
+ if (StringUtils.isEmpty(vtdu.getName())) {
+ return AjaxResult.error("閫氶亾鍚嶇О涓嶈兘涓虹┖");
+ }
+ if (StringUtils.isEmpty(vtdu.getRtspSource())) {
+ return AjaxResult.error("rtsp鍦板潃涓嶈兘涓虹┖");
+ }
return toAjax(vtduService.insertVtdu(vtdu));
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/domain/Config.java b/ard-work/src/main/java/com/ruoyi/media/domain/Config.java
new file mode 100644
index 0000000..c8389ca
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/media/domain/Config.java
@@ -0,0 +1,18 @@
+package com.ruoyi.media.domain;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @Description:
+ * @ClassName: Config
+ * @Author: 鍒樿嫃涔�
+ * @Date: 2023骞�10鏈�13鏃�15:13:40
+ **/
+@Data
+public class Config {
+ private boolean webrtc;
+ private List<String> webrtcICEHostNAT1To1IPs;
+ private String webrtcICETCPMuxAddress;
+}
diff --git a/ard-work/src/main/java/com/ruoyi/media/domain/StreamInfo.java b/ard-work/src/main/java/com/ruoyi/media/domain/StreamInfo.java
index c605658..88ea870 100644
--- a/ard-work/src/main/java/com/ruoyi/media/domain/StreamInfo.java
+++ b/ard-work/src/main/java/com/ruoyi/media/domain/StreamInfo.java
@@ -67,7 +67,7 @@
String remoteAddr;
/**
- * 妯″紡
+ * 瑙g爜妯″紡
*/
String mode;
diff --git a/ard-work/src/main/java/com/ruoyi/media/domain/Vtdu.java b/ard-work/src/main/java/com/ruoyi/media/domain/Vtdu.java
index a2c5e14..7ddf8bb 100644
--- a/ard-work/src/main/java/com/ruoyi/media/domain/Vtdu.java
+++ b/ard-work/src/main/java/com/ruoyi/media/domain/Vtdu.java
@@ -27,7 +27,7 @@
* rtsp婧愬湴鍧�
*/
@Excel(name = "rtsp婧愬湴鍧�")
- private String sourceUrl;
+ private String rtspSource;
/**
* 鏄惁杞爜
@@ -36,10 +36,10 @@
private String isCode;
/**
- * 杞爜妯″紡
+ * 缂栬В鐮佹ā寮�
*/
- @Excel(name = "杞爜妯″紡")
- private String codeType;
+ @Excel(name = "缂栬В鐮佹ā寮�")
+ private String mode;
/**
* rtsp鎾斁鍦板潃
@@ -53,4 +53,8 @@
* webrtc鎾斁鍦板潃
*/
String webrtcUrl;
+ /**
+ * 鐩告満ID
+ */
+ String cameraId;
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/mapper/VtduMapper.java b/ard-work/src/main/java/com/ruoyi/media/mapper/VtduMapper.java
index db474de..f491d55 100644
--- a/ard-work/src/main/java/com/ruoyi/media/mapper/VtduMapper.java
+++ b/ard-work/src/main/java/com/ruoyi/media/mapper/VtduMapper.java
@@ -33,7 +33,7 @@
* @param vtdu 娴佸獟浣撶鐞�
* @return 缁撴灉
*/
- public int insertVtdu(Vtdu vtdu);
+ public Integer insertVtdu(Vtdu vtdu);
/**
* 淇敼娴佸獟浣撶鐞�
@@ -41,7 +41,7 @@
* @param vtdu 娴佸獟浣撶鐞�
* @return 缁撴灉
*/
- public int updateVtdu(Vtdu vtdu);
+ public Integer updateVtdu(Vtdu vtdu);
/**
* 鍒犻櫎娴佸獟浣撶鐞�
@@ -57,4 +57,11 @@
* @return 缁撴灉
*/
public int deleteVtduByNames(String[] names);
+ /**
+ * 鍒犻櫎娴佸獟浣撶鐞嗕俊鎭�
+ *
+ * @param cameraId 鐩告満ID
+ * @return 缁撴灉
+ */
+ public int deleteVtduByCameraId(String cameraId);
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/IMediaService.java b/ard-work/src/main/java/com/ruoyi/media/service/IMediaService.java
index 436fe72..5d04ef0 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/IMediaService.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/IMediaService.java
@@ -1,5 +1,6 @@
package com.ruoyi.media.service;
+import com.dtflys.forest.annotation.Var;
import com.ruoyi.media.domain.*;
import java.lang.reflect.MalformedParameterizedTypeException;
@@ -11,12 +12,13 @@
* 澧炲姞璺緞
* name 鍚嶇О
* rtspPath rtsp鍦板潃
- * mode 妯″紡锛氬疄鏃�/鎸夐渶
+ * mode 妯″紡锛歡pu纭В鐮�/cpu杞В鐮�
* isCode 鏄惁杞爜
* 鍒樿嫃涔�
* 2023/8/12 13:56:52
*/
- Map<String,String> addPath(String name, String sourceUrl, String mode, String isCode);
+ Map<String, String> addPath(String name, String sourceUrl, String mode, String isCode);
+
/**
* 淇敼璺緞
* name 鍚嶇О
@@ -26,13 +28,17 @@
* 鍒樿嫃涔�
* 2023/8/12 13:56:52
*/
- Map<String,String> editPath(String name, String sourceUrl, String mode, String isCode);
+ Map<String, String> editPath(String name, String sourceUrl, String mode, String isCode);
StreamInfo getPathInfo(String name);
void removePath(String[] names);
+ void removePath(String name);
+
List<StreamInfo> paths();
+
+ List<String> getNameList();
RtspSession getRtspSessionById(String sessionId);
@@ -49,4 +55,11 @@
Boolean kickRtmpSession(String sessionId);
Boolean kickWebrtcSession(String sessionId);
+
+ /**
+ * 閰嶇疆娴佸獟浣撳弬鏁�
+ * 鍒樿嫃涔�
+ * 2023/10/13 15:17:57
+ */
+ public String setConfig(Config config);
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/IVtduService.java b/ard-work/src/main/java/com/ruoyi/media/service/IVtduService.java
index 7fb33dd..e5d0246 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/IVtduService.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/IVtduService.java
@@ -58,4 +58,12 @@
* @return 缁撴灉
*/
public int deleteVtduByName(String name);
+
+ /**
+ * 鍒犻櫎娴佸獟浣撶鐞嗕俊鎭�
+ *
+ * @param cameraId 鐩告満ID
+ * @return 缁撴灉
+ */
+ public int deleteVtduByCameraId(String cameraId);
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
index af45f2b..5d84867 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
@@ -1,6 +1,9 @@
package com.ruoyi.media.service.impl;
import com.alibaba.fastjson2.JSONObject;
+import com.dtflys.forest.Forest;
+import com.dtflys.forest.exceptions.ForestNetworkException;
+import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
@@ -16,6 +19,7 @@
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@@ -36,147 +40,102 @@
@Service
@Slf4j(topic = "cmd")
@Order(2)
-public class MediaServiceImpl implements IMediaService, ApplicationRunner {
- @Resource
- VtduMapper vtduMapper;
+public class MediaServiceImpl implements IMediaService {
+
@Resource
MediaClient mediaClient;
@Value("${mediamtx.host}")
String mediamtxHost;
- @Value("${mediamtx.software_decoding}")
- Boolean softwareDecoding;
+ /**
+ * 娣诲姞娴佸獟浣�
+ * name 鐩告満ID
+ * sourceUrl rtsp鍦板潃
+ * isCode 0-涓嶈浆鐮� 1-杞爜
+ * mode 0-gpu纭В鐮� 1-cpu杞В鐮�
+ * <p>
+ * 鍒樿嫃涔�
+ * 2023/10/12 9:03:41
+ */
@Override
- public void run(ApplicationArguments args) {
- try {
- log.debug("寮�濮嬪姞杞芥祦濯掍綋鍒楄〃");
- List<StreamInfo> paths = paths();
- for (StreamInfo path : paths) {
- mediaClient.removePath(path.getName());
- }
- List<Vtdu> vtduList = vtduMapper.selectVtduList(new Vtdu());
- for (Vtdu vtdu : vtduList) {
- Map<String, String> map = addPath(vtdu.getName(), vtdu.getSourceUrl(), vtdu.getCodeType(), vtdu.getIsCode());
- vtdu.setRtspUrl(map.get("rtspUrl"));
- vtdu.setRtmpUrl(map.get("rtmpUrl"));
- vtdu.setWebrtcUrl(map.get("webrtcUrl"));
- vtdu.setUpdateTime(DateUtils.getNowDate());
- vtduMapper.updateVtdu(vtdu);
- }
- } catch (Exception ex) {
- log.error("鍔犺浇娴佸獟浣撳垪琛ㄥ紓甯�:" + ex.getMessage());
- }
- }
+ public Map<String, String> addPath(String name, String sourceUrl, String mode, String isCode) {
- @Override
- public Map<String,String> addPath(String name, String sourceUrl, String mode, String isCode) {
String rtspUrl = "rtsp://" + mediamtxHost + ":8554/" + name;
String rtmpUrl = "rtmp://" + mediamtxHost + ":1935/" + name;
String webrtcUrl = "http://" + mediamtxHost + ":8889/" + name;
Conf mediaInfo = new Conf();
String rootPath = System.getProperty("user.dir").replaceAll("\\\\", "/") + "/lib/mediamtx/";
- //-vcodec libx264 //鎸囧畾瑙嗛缂栫爜鍣ㄤ负 libx264锛屼娇鐢� H.264 缂栫爜鏍煎紡杩涜瑙嗛鍘嬬缉
- //-preset ultrafast //--preset鐨勫弬鏁颁富瑕佽皟鑺傜紪鐮侀�熷害鍜岃川閲忕殑骞宠 锛屾湁ultrafast锛堣浆鐮侀�熷害鏈�蹇紝瑙嗛寰�寰�涔熸渶妯$硦锛夈�乻uperfast銆乿eryfast銆乫aster銆乫ast銆乵edium銆乻low銆乻lower銆乿eryslow銆乸lacebo杩�10涓�夐」锛屼粠蹇埌鎱�
- //-r 25 //璁剧疆杈撳嚭瑙嗛鐨勫抚鐜囦负 25 甯�/绉�
- //-g 20 //鍏抽敭甯ч棿闅�20
- //-sc_threshold 0 //灏嗗叾璁剧疆涓�0锛�-sc_threshold 0锛夌鐢ㄥ満鏅彉鍖栨娴�
- //-rtsp_transport tcp //杩欎釜閫夐」鍛婅瘔 FFmpeg 浣跨敤 TCP 浣滀负 RTSP 鐨勪紶杈撳崗璁�
- //-threads 4: 鎸囧畾瑕佷娇鐢ㄧ殑绾跨▼鏁颁负 4銆�//杩欏厑璁� FFmpeg 鍦ㄥ鏍稿鐞嗗櫒涓婁娇鐢ㄥ涓嚎绋嬫潵杩涜瑙嗛缂栫爜锛屼互鍔犲揩閫熷害銆�
- // -i //鐢ㄤ簬鎸囧畾杈撳叆濯掍綋鏂囦欢鎴栬緭鍏ユ祦鐨勫湴鍧�
- // -bf 0 绂佺敤B甯э紝鍥犱负webrtc鍦ㄧ綉椤佃皟鐢ㄦ椂鎺у埗鍙颁竴鐩磋緭鍑� WebRTC doesn鈥檛 support H264 streams with B-frames
- //-f rtsp //杩欎釜閫夐」鍛婅瘔 FFmpeg 杈撳嚭涓� RTSP 鏍煎紡銆�
- //-acodec opus //闊抽杞爜opus
- //-acodec pcm_alaw //闊抽杞爜PCMA(G711A)
- //-strict 閫夐」鐢ㄤ簬璁剧疆闊抽缂栬В鐮佺殑涓ユ牸绾у埆锛岃�� -2 鏄叾鍙傛暟涔嬩竴銆傚湪鏃╂湡鐗堟湰鐨� FFmpeg 涓紝-strict 閫夐」鐢ㄤ簬璁剧疆闊抽缂栬В鐮佸櫒鐨勮涓猴紝鍏朵腑 -2 琛ㄧず浣跨敤闈炲父涓ユ牸鐨勬ā寮忋��
- //CPU杞В鐮佺紪鐮�
- //String cmd = rootPath + "/lib/mediamtx/" +"ffmpeg -rtsp_transport tcp -i " + rtspPath + " -vcodec libx264 -preset:v ultrafast -r 25 -threads 4 -b:v 2048k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
- //GPU纭В鐮佺紪鐮� -hwaccel cuvid -c:v h264_cuvid 浣跨敤cuda瑙g爜 -c:v h264_nvenc 浣跨敤cuda缂栫爜
- //String cmd = rootPath + "/lib/mediamtx/" + "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport udp -i " + rtspPath + " -c:v h264_nvenc -r 25 -threads 4 -b:v 2048k -bf 0 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
if (isCode.equals("1")) {
- String cmd = "ffmpeg -rtsp_transport tcp -i " + sourceUrl + " -vcodec libx264 -preset:v ultrafast -r 25 -keyint_min 25 -g 25 -sc_threshold 0 -threads 6 -b:v 2048k -acodec opus -strict -2 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
- if (!softwareDecoding) {
- cmd = "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport tcp -i " + sourceUrl + " -c:v h264_nvenc -r 25 -g 60 -threads 6 -b:v 2048k -bf 0 -acodec opus -strict -2 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
+ mediaInfo.setSource("publisher");
+ //榛樿杞В鐮�
+ String cmd = "ffmpeg -rtsp_transport tcp -i " + sourceUrl + " -vcodec libx264 -preset:v ultrafast -r 25 -keyint_min 25 -g 60 -sc_threshold 0 -threads 6 -b:v 2048k -acodec opus -strict -2 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
+ if (mode.equals("0")) {//纭В鐮�
+ cmd = "ffmpeg -hwaccel cuvid -c:v hevc_cuvid -rtsp_transport tcp -i " + sourceUrl + " -c:v h264_nvenc -r 25 -g 60 -sc_threshold 0 -threads 6 -b:v 2048k -bf 0 -acodec opus -strict -2 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
}
- if (mode.equals("0")) {
- mediaInfo.setRunondemand(cmd);
- mediaInfo.setRunondemandrestart(true);
- mediaInfo.setRunondemandcloseafter("5s");
- } else {
- mediaInfo.setRunoninit(cmd);
- mediaInfo.setRunoninitrestart(true);
- }
+ mediaInfo.setRunondemand(cmd);
+ mediaInfo.setRunondemandrestart(true);
+ mediaInfo.setRunondemandcloseafter("5s");
} else {
mediaInfo.setSource(sourceUrl);
mediaInfo.setSourceondemand(true);
}
mediaInfo.setMaxReaders(100);
mediaInfo.setSourceprotocol("tcp");
- mediaClient.addPath(name, mediaInfo);
- Map<String,String> map=new HashMap<>();
- map.put("rtspUrl",rtspUrl);
- map.put("rtmpUrl",rtmpUrl);
- map.put("webrtcUrl",webrtcUrl);
+
+ List<String> nameList=new ArrayList<>();
+ String paths = mediaClient.paths();
+ JsonsRoot jsonsRoot = JSONObject.parseObject(paths, JsonsRoot.class);
+ List<Items> items = jsonsRoot.getItems();
+ for (Items item : items) {
+ nameList.add(item.getName());
+ }
+ if(!nameList.contains(name)) {
+ mediaClient.addPath(name, mediaInfo);
+ }
+ Map<String, String> map = new HashMap<>();
+ map.put("rtspUrl", rtspUrl);
+ map.put("rtmpUrl", rtmpUrl);
+ map.put("webrtcUrl", webrtcUrl);
return map;
}
@Override
public Map<String, String> editPath(String name, String sourceUrl, String mode, String isCode) {
- String rtspUrl = "rtsp://" + mediamtxHost + ":8554/" + name;
- String rtmpUrl = "rtmp://" + mediamtxHost + ":1935/" + name;
- String webrtcUrl = "http://" + mediamtxHost + ":8889/" + name;
+ Map<String, String> map = new HashMap<>();
+ try {
+ String rtspUrl = "rtsp://" + mediamtxHost + ":8554/" + name;
+ String rtmpUrl = "rtmp://" + mediamtxHost + ":1935/" + name;
+ String webrtcUrl = "http://" + mediamtxHost + ":8889/" + name;
- Conf mediaInfo = new Conf();
- String rootPath = System.getProperty("user.dir").replaceAll("\\\\", "/") + "/lib/mediamtx/";
- //-vcodec libx264 //鎸囧畾瑙嗛缂栫爜鍣ㄤ负 libx264锛屼娇鐢� H.264 缂栫爜鏍煎紡杩涜瑙嗛鍘嬬缉
- //-preset ultrafast //--preset鐨勫弬鏁颁富瑕佽皟鑺傜紪鐮侀�熷害鍜岃川閲忕殑骞宠 锛屾湁ultrafast锛堣浆鐮侀�熷害鏈�蹇紝瑙嗛寰�寰�涔熸渶妯$硦锛夈�乻uperfast銆乿eryfast銆乫aster銆乫ast銆乵edium銆乻low銆乻lower銆乿eryslow銆乸lacebo杩�10涓�夐」锛屼粠蹇埌鎱�
- //-r 25 //璁剧疆杈撳嚭瑙嗛鐨勫抚鐜囦负 25 甯�/绉�
- //-g 20 //鍏抽敭甯ч棿闅�20
- //-sc_threshold 0 //灏嗗叾璁剧疆涓�0锛�-sc_threshold 0锛夌鐢ㄥ満鏅彉鍖栨娴�
- //-rtsp_transport tcp //杩欎釜閫夐」鍛婅瘔 FFmpeg 浣跨敤 TCP 浣滀负 RTSP 鐨勪紶杈撳崗璁�
- //-threads 4: 鎸囧畾瑕佷娇鐢ㄧ殑绾跨▼鏁颁负 4銆�//杩欏厑璁� FFmpeg 鍦ㄥ鏍稿鐞嗗櫒涓婁娇鐢ㄥ涓嚎绋嬫潵杩涜瑙嗛缂栫爜锛屼互鍔犲揩閫熷害銆�
- // -i //鐢ㄤ簬鎸囧畾杈撳叆濯掍綋鏂囦欢鎴栬緭鍏ユ祦鐨勫湴鍧�
- // -bf 0 绂佺敤B甯э紝鍥犱负webrtc鍦ㄧ綉椤佃皟鐢ㄦ椂鎺у埗鍙颁竴鐩磋緭鍑� WebRTC doesn鈥檛 support H264 streams with B-frames
- //-f rtsp //杩欎釜閫夐」鍛婅瘔 FFmpeg 杈撳嚭涓� RTSP 鏍煎紡銆�
- //-acodec opus //闊抽杞爜opus
- //CPU杞В鐮佺紪鐮�
- //String cmd = rootPath + "/lib/mediamtx/" +"ffmpeg -rtsp_transport tcp -i " + rtspPath + " -vcodec libx264 -preset:v ultrafast -r 25 -threads 4 -b:v 2048k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
- //GPU纭В鐮佺紪鐮� -hwaccel cuvid -c:v h264_cuvid 浣跨敤cuda瑙g爜 -c:v h264_nvenc 浣跨敤cuda缂栫爜
- //String cmd = rootPath + "/lib/mediamtx/" + "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport udp -i " + rtspPath + " -c:v h264_nvenc -r 25 -threads 4 -b:v 2048k -bf 0 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
- if (isCode.equals("1")) {
- mediaInfo.setSource("publisher");
- String cmd = "ffmpeg -rtsp_transport tcp -i " + sourceUrl + " -vcodec libx264 -preset:v ultrafast -r 25 -keyint_min 25 -g 25 -sc_threshold 0 -threads 6 -b:v 2048k -acodec opus -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
- if (!softwareDecoding) {
- cmd = "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport tcp -i " + sourceUrl + " -c:v h264_nvenc -r 25 -g 60 -threads 6 -b:v 2048k -bf 0 -acodec opus -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
- }
- if (mode.equals("0")) {
+ Conf mediaInfo = new Conf();
+ String rootPath = System.getProperty("user.dir").replaceAll("\\\\", "/") + "/lib/mediamtx/";
+ if (isCode.equals("1")) {
+ mediaInfo.setSource("publisher");
+ //榛樿杞В鐮�
+ String cmd = "ffmpeg -rtsp_transport tcp -i " + sourceUrl + " -vcodec libx264 -preset:v ultrafast -r 25 -keyint_min 25 -g 60 -sc_threshold 0 -threads 6 -b:v 2048k -acodec opus -strict -2 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
+ if (mode.equals("0")) {//纭В鐮�
+ cmd = "ffmpeg -hwaccel cuvid -c:v hevc_cuvid -rtsp_transport tcp -i " + sourceUrl + " -c:v h264_nvenc -r 25 -g 60 -sc_threshold 0 -threads 6 -b:v 2048k -bf 0 -acodec opus -strict -2 -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
+ }
mediaInfo.setRunondemand(cmd);
- mediaInfo.setRunondemandcloseafter("5s");
mediaInfo.setRunondemandrestart(true);
- mediaInfo.setRunoninit("");
- mediaInfo.setRunoninitrestart(false);
+ mediaInfo.setRunondemandcloseafter("5s");
} else {
- mediaInfo.setRunoninit(cmd);
- mediaInfo.setRunoninitrestart(true);
- mediaInfo.setRunondemand("");
- mediaInfo.setRunondemandrestart(false);
+ mediaInfo.setSource(sourceUrl);
}
- } else {
- mediaInfo.setSource(sourceUrl);
- mediaInfo.setSourceondemand(true);
- mediaInfo.setRunondemand("");
- mediaInfo.setRunondemandrestart(false);
- mediaInfo.setRunoninit("");
- mediaInfo.setRunoninitrestart(false);
+ mediaInfo.setMaxReaders(100);
+ mediaInfo.setSourceprotocol("tcp");
+
+ mediaClient.editPath(name, mediaInfo);
+
+ // Map<String,String> map=new HashMap<>();
+ map.put("rtspUrl", rtspUrl);
+ map.put("rtmpUrl", rtmpUrl);
+ map.put("webrtcUrl", webrtcUrl);
+ } catch (ForestNetworkException ex) {
+ log.error(ex.getMessage());
}
- mediaInfo.setMaxReaders(100);
- mediaInfo.setSourceprotocol("tcp");
- mediaClient.editPath(name, mediaInfo);
- Map<String,String> map=new HashMap<>();
- map.put("rtspUrl",rtspUrl);
- map.put("rtmpUrl",rtmpUrl);
- map.put("webrtcUrl",webrtcUrl);
return map;
}
@@ -215,6 +174,11 @@
}
@Override
+ public void removePath(String name) {
+ mediaClient.removePath(name);
+ }
+
+ @Override
public List<StreamInfo> paths() {
String list = mediaClient.paths();
JsonsRoot jsonsRoot = JSONObject.parseObject(list, JsonsRoot.class);
@@ -225,14 +189,9 @@
//ID
String name = item.getName();
info.setName(name);
- String runOn;
+ String runOn = "";
if (StringUtils.isNotEmpty(item.getConf().getRunondemand())) {
runOn = item.getConf().getRunondemand();
- info.setMode("0");
- } else {
- runOn = item.getConf().getRunoninit();
- //runOn = item.getConf().getRunonready();
- info.setMode("1");
}
//RTSP婧愬湴鍧�
Matcher matcher = Pattern.compile("rtsp://[^\\s\"]+").matcher(runOn);
@@ -327,12 +286,9 @@
info.setRemoteAddr(rtspSession.getRemoteAddr());
}
//RTSP婧愬湴鍧�
- String runOn;
+ String runOn = "";
if (StringUtils.isNotEmpty(item.getConf().getRunondemand())) {
runOn = item.getConf().getRunondemand();
- } else {
- runOn = item.getConf().getRunoninit();
- //runOn = item.getConf().getRunonready();
}
Matcher matcher = Pattern.compile("rtsp://[^\\s\"]+").matcher(runOn);
if (matcher.find()) {
@@ -492,5 +448,27 @@
return false;
}
}
-
+ /**
+ * 鑾峰彇娴佸獟浣搉ame鍒楄〃
+ * 鍒樿嫃涔�
+ * 2023/10/13 14:19:07
+ */
+ @Override
+ public List<String> getNameList() {
+ List<String> nameList=new ArrayList<>();
+ String paths = mediaClient.paths();
+ JsonsRoot jsonsRoot = JSONObject.parseObject(paths, JsonsRoot.class);
+ List<Items> items = jsonsRoot.getItems();
+ for (Items item : items) {
+ nameList.add(item.getName());
+ }
+ return nameList;
+ }
+ /**
+ * 閰嶇疆娴佸獟浣撳弬鏁�
+ */
+ @Override
+ public String setConfig(Config config) {
+ return mediaClient.setConfig(config);
+ }
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java
index 456fad4..05cc175 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java
@@ -1,11 +1,19 @@
package com.ruoyi.media.service.impl;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.media.service.IMediaService;
+import com.ruoyi.utils.forest.MediaClient;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.ruoyi.media.mapper.VtduMapper;
import com.ruoyi.media.domain.Vtdu;
@@ -20,9 +28,12 @@
* @date 2023-08-29
*/
@Service
+@Slf4j
public class VtduServiceImpl implements IVtduService {
@Resource
private VtduMapper vtduMapper;
+ @Resource
+ private IMediaService mediaService;
/**
* 鏌ヨ娴佸獟浣撶鐞�
@@ -54,7 +65,16 @@
*/
@Override
public int insertVtdu(Vtdu vtdu) {
- vtdu.setCreateBy(SecurityUtils.getUserId());
+ log.info("娴佸獟浣撱��" + vtdu.getName() + "銆戦�氶亾娣诲姞");
+ Map<String, String> map = mediaService.addPath(vtdu.getName(), vtdu.getRtspSource(), vtdu.getMode(), vtdu.getIsCode());
+ vtdu.setRtspUrl(map.get("rtspUrl"));
+ vtdu.setRtmpUrl(map.get("rtmpUrl"));
+ vtdu.setWebrtcUrl(map.get("webrtcUrl"));
+
+ vtdu.setName(vtdu.getName());
+ vtdu.setRtspSource(vtdu.getRtspSource());
+ vtdu.setIsCode(vtdu.getIsCode());
+ vtdu.setMode(vtdu.getMode());
vtdu.setCreateTime(DateUtils.getNowDate());
return vtduMapper.insertVtdu(vtdu);
}
@@ -67,7 +87,16 @@
*/
@Override
public int updateVtdu(Vtdu vtdu) {
- vtdu.setUpdateBy(SecurityUtils.getUserId());
+
+ log.info("娴佸獟浣撱��" + vtdu.getName() + "銆戦�氶亾鏇存柊");
+ Map<String, String> map = mediaService.editPath(vtdu.getName(), vtdu.getRtspSource(), vtdu.getMode(), vtdu.getIsCode());
+ vtdu.setName(vtdu.getName());
+ vtdu.setRtspSource(vtdu.getRtspSource());
+ vtdu.setIsCode(vtdu.getIsCode());
+ vtdu.setMode(vtdu.getMode());
+ vtdu.setRtspUrl(map.get("rtspUrl"));
+ vtdu.setRtmpUrl(map.get("rtmpUrl"));
+ vtdu.setWebrtcUrl(map.get("webrtcUrl"));
vtdu.setUpdateTime(DateUtils.getNowDate());
return vtduMapper.updateVtdu(vtdu);
}
@@ -80,6 +109,7 @@
*/
@Override
public int deleteVtduByNames(String[] names) {
+ mediaService.removePath(names);
return vtduMapper.deleteVtduByNames(names);
}
@@ -93,4 +123,23 @@
public int deleteVtduByName(String name) {
return vtduMapper.deleteVtduByName(name);
}
+
+ /**
+ * 鍒犻櫎娴佸獟浣撶鐞嗕俊鎭�
+ *
+ * @param cameraId 鐩告満ID
+ * @return 缁撴灉
+ */
+ @Override
+ public int deleteVtduByCameraId(String cameraId) {
+ Vtdu vtdu = new Vtdu();
+ vtdu.setCameraId(cameraId);
+ List<Vtdu> vtdus = vtduMapper.selectVtduList(vtdu);
+ if (vtdus.size() > 0) {
+ for (Vtdu v : vtdus) {
+ mediaService.removePath(v.getName());
+ }
+ }
+ return vtduMapper.deleteVtduByCameraId(cameraId);
+ }
}
diff --git a/ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java b/ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java
index 0e39f82..70fa4da 100644
--- a/ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java
+++ b/ard-work/src/main/java/com/ruoyi/utils/forest/MediaClient.java
@@ -1,7 +1,9 @@
package com.ruoyi.utils.forest;
import com.dtflys.forest.annotation.*;
+import com.dtflys.forest.callback.OnError;
import com.ruoyi.media.domain.Conf;
+import com.ruoyi.media.domain.Config;
import com.ruoyi.media.domain.Items;
/**
@@ -16,70 +18,84 @@
/**
* 澧炲姞璺緞
*/
- @Post("/config/paths/add/{name}")
- String addPath( @Var("name") String name, @JSONBody Conf body);
+ @Post(url = "/config/paths/add/{name}")
+ public String addPath(@Var("name") String name, @JSONBody Conf body);
+
/**
* 淇敼璺緞
*/
- @Post("/config/paths/edit/{name}")
- String editPath( @Var("name") String name, @JSONBody Conf body);
+ @Post(url = "/config/paths/edit/{name}", async = true)
+ public String editPath(@Var("name") String name, @JSONBody Conf body);
+
/**
* 绉婚櫎璺緞
*/
@Post("/config/paths/remove/{name}")
- String removePath(@Var("name") String name);
+ public String removePath(@Var("name") String name);
/**
* 鑾峰彇璺緞璇︽儏
*/
@Get("/paths/get/{name}")
- Items getPathInfo(@Var("name") String name);
+ public Items getPathInfo(@Var("name") String name);
+
/**
* 鏌ヨ鎵�鏈夎矾寰�
*/
@Get("/paths/list")
- String paths();
+ public String paths();
/**
* 鏌ヨ鎵�鏈塺tsp浼氳瘽
*/
@Get("/rtspsessions/list")
- String rtspsessions();
+ public String rtspsessions();
/**
* 鏌ヨ鎵�鏈塺tsp杩炴帴
*/
@Get("/rtspconns/list")
- String rtspconns();
+ public String rtspconns();
/**
* 鎸塻essionId鏌ヨrtsp浼氳瘽
*/
@Get("/rtspsessions/get/{sessionId}")
- String getRtspsessionById(@Var("sessionId") String sessionId);
+ public String getRtspsessionById(@Var("sessionId") String sessionId);
+
/**
* 鎸塻essionId鏌ヨwebrtc浼氳瘽
*/
@Get("/webrtcsessions/get/{sessionId}")
- String getWebrtcsessionById(@Var("sessionId") String sessionId);
+ public String getWebrtcsessionById(@Var("sessionId") String sessionId);
+
/**
* 鎸塻essionId鏌ヨrtmp浼氳瘽
*/
@Get("/rtmpconns/get/{sessionId}")
- String getRtmpsessionById(@Var("sessionId") String sessionId);
+ public String getRtmpsessionById(@Var("sessionId") String sessionId);
+
/**
* 鎸塻essionId鍒犻櫎rtsp浼氳瘽
*/
@Post("/rtspsessions/kick/{sessionId}")
- String kickRtspSessions(@Var("sessionId") String sessionId);
+ public String kickRtspSessions(@Var("sessionId") String sessionId);
+
/**
* 鎸塻essionId鍒犻櫎rtmp杩炴帴
*/
@Post("/rtmpconns/kick/{sessionId}")
- String kickRtmpSessions(@Var("sessionId") String sessionId);
+ public String kickRtmpSessions(@Var("sessionId") String sessionId);
+
/**
* 鎸塻essionId鍒犻櫎webrtc浼氳瘽
*/
@Post("/webrtcsessions/kick/{sessionId}")
- String kickWebrtcSessions(@Var("sessionId") String sessionId);
+ public String kickWebrtcSessions(@Var("sessionId") String sessionId);
+
+ /**
+ * 閰嶇疆娴佸獟浣撳弬鏁�
+ */
+ @Post("/config/set")
+ public String setConfig(@JSONBody Config config);
}
diff --git a/ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml b/ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml
index cfb9e36..41de89d 100644
--- a/ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml
+++ b/ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml
@@ -6,12 +6,13 @@
<resultMap type="Vtdu" id="VtduResult">
<result property="name" column="name"/>
- <result property="sourceUrl" column="source_url"/>
+ <result property="rtspSource" column="rtsp_source"/>
<result property="isCode" column="is_code"/>
- <result property="codeType" column="code_type"/>
+ <result property="mode" column="mode"/>
<result property="rtspUrl" column="rtsp_url"/>
<result property="rtmpUrl" column="rtmp_url"/>
<result property="webrtcUrl" column="webrtc_url"/>
+ <result property="cameraId" column="camera_id"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
@@ -20,12 +21,13 @@
<sql id="selectVtduVo">
select name,
- source_url,
+ rtsp_source,
is_code,
- code_type,
+ mode,
rtsp_url,
rtmp_url,
webrtc_url,
+ camera_id,
create_by,
create_time,
update_by,
@@ -37,9 +39,10 @@
<include refid="selectVtduVo"/>
<where>
<if test="name != null and name != ''">and name like '%'||#{name}||'%'</if>
- <if test="sourceUrl != null and sourceUrl != ''">and source_url = #{sourceUrl}</if>
+ <if test="rtspSource != null and rtspSource != ''">and rtsp_source = #{rtspSource}</if>
<if test="isCode != null and isCode != ''">and is_code = #{isCode}</if>
- <if test="codeType != null and codeType != ''">and code_type = #{codeType}</if>
+ <if test="mode != null and mode != ''">and mode = #{mode}</if>
+ <if test="cameraId != null and cameraId != ''">and camera_id = #{cameraId}</if>
</where>
</select>
@@ -52,12 +55,13 @@
insert into vtdu
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">name,</if>
- <if test="sourceUrl != null">source_url,</if>
+ <if test="rtspSource != null">rtsp_source,</if>
<if test="isCode != null">is_code,</if>
- <if test="codeType != null">code_type,</if>
+ <if test="mode != null">mode,</if>
<if test="rtspUrl != null">rtsp_url,</if>
<if test="rtmpUrl != null">rtmp_url,</if>
<if test="webrtcUrl != null">webrtc_url,</if>
+ <if test="cameraId != null">camera_id,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
@@ -65,12 +69,13 @@
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
- <if test="sourceUrl != null">#{sourceUrl},</if>
+ <if test="rtspSource != null">#{rtspSource},</if>
<if test="isCode != null">#{isCode},</if>
- <if test="codeType != null">#{codeType},</if>
+ <if test="mode != null">#{mode},</if>
<if test="rtspUrl != null">#{rtspUrl},</if>
<if test="rtmpUrl != null">#{rtmpUrl},</if>
<if test="webrtcUrl != null">#{webrtcUrl},</if>
+ <if test="cameraId != null">#{cameraId},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
@@ -81,12 +86,13 @@
<update id="updateVtdu" parameterType="Vtdu">
update vtdu
<trim prefix="SET" suffixOverrides=",">
- <if test="sourceUrl != null">source_url = #{sourceUrl},</if>
+ <if test="rtspSource != null">rtsp_source = #{rtspSource},</if>
<if test="isCode != null">is_code = #{isCode},</if>
- <if test="codeType != null">code_type = #{codeType},</if>
+ <if test="mode != null">mode = #{mode},</if>
<if test="rtspUrl != null">rtsp_url = #{rtspUrl},</if>
<if test="rtmpUrl != null">rtmp_url = #{rtmpUrl},</if>
<if test="webrtcUrl != null">webrtc_url = #{webrtcUrl},</if>
+ <if test="cameraId != null">camera_id = #{cameraId},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
@@ -107,4 +113,9 @@
#{name}
</foreach>
</delete>
+ <delete id="deleteVtduByCameraId" parameterType="String">
+ delete
+ from vtdu
+ where camera_id = #{cameraId}
+ </delete>
</mapper>
\ No newline at end of file
diff --git a/ard-work/src/main/resources/templates/preview.html b/ard-work/src/main/resources/templates/preview.html
index ee775ac..609e256 100644
--- a/ard-work/src/main/resources/templates/preview.html
+++ b/ard-work/src/main/resources/templates/preview.html
@@ -107,6 +107,8 @@
</div>
<script>
+ console.log(RTCRtpReceiver.getCapabilities('video').codecs)
+ console.log(RTCRtpReceiver.getCapabilities('audio').codecs)
//whep鎿嶄綔鏂规硶
const linkToIceServers = (links) => (
(links !== null) ? links.split(', ').map((link) => {
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index d97225f..45fd4b6 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -44,7 +44,7 @@
global-config:
banner: off # 鍏抽棴mybatisplus鍚姩鍥炬爣
db-config: #涓婚敭涓嶇敤MyBatis plus鐨勯洩鑺辩畻娉�,鐢ㄦ暟鎹簱鐨勪富閿嚜澧�
- id-type: auto
+ id-type: uuid
# configuration:
# # 鏄惁寮�鍚嚜鍔ㄩ┘宄板懡鍚嶈鍒欐槧灏�:浠庢暟鎹簱鍒楀悕鍒癑ava灞炴�ч┘宄板懡鍚嶇殑绫讳技鏄犲皠
# map-underscore-to-camel-case: true
diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/SyncTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/SyncTask.java
index 5ecb0ea..2ce32ca 100644
--- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/SyncTask.java
+++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/SyncTask.java
@@ -1,15 +1,24 @@
package com.ruoyi.quartz.task;
+import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.camera.service.IArdCamerasService;
+import com.ruoyi.device.channel.domain.ArdChannel;
import com.ruoyi.device.hiksdk.service.IHikClientService;
+import com.ruoyi.media.domain.Items;
+import com.ruoyi.media.domain.JsonsRoot;
+import com.ruoyi.media.domain.Vtdu;
+import com.ruoyi.media.service.IMediaService;
+import com.ruoyi.media.service.IVtduService;
import com.ruoyi.rongcloud.service.RongCloudService;
import com.ruoyi.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
+
import javax.annotation.Resource;
+import java.util.ArrayList;
import java.util.List;
/**
@@ -29,6 +38,10 @@
IArdCamerasService iArdCamerasService;
@Resource
IHikClientService iHikClientService;
+ @Resource
+ IVtduService vtduService;
+ @Resource
+ IMediaService mediaService;
/**
* 鍚屾鐩告満鍦ㄧ嚎鐘舵��
@@ -36,21 +49,26 @@
* 2023/10/8 14:54:41
*/
public void cameraState() {
- List<ArdCameras> ardCameras = iArdCamerasService.selectArdCamerasListNoDataScope(new ArdCameras());
- for (ArdCameras camera : ardCameras) {
- CameraCmd cmd = new CameraCmd();
- cmd.setCameraId(camera.getId());
- boolean onLineNew = iHikClientService.isOnLine(cmd);//鐩告満瀹炴椂鐘舵��
- boolean onLineOld = "1".equals(camera.getState());//鐩告満鍘嗗彶鐘舵��
- //褰撶姸鎬佸彂鐢熷彉鍖栨椂锛屾洿鏂板疄鏃剁姸鎬�
- if (onLineNew != onLineOld) {
- if (onLineNew) {
- camera.setState("1");
- } else {
- camera.setState("0");
+ try {
+ List<ArdCameras> ardCameras = iArdCamerasService.selectArdCamerasListNoDataScope(new ArdCameras());
+ for (ArdCameras camera : ardCameras) {
+ CameraCmd cmd = new CameraCmd();
+ cmd.setCameraId(camera.getId());
+ boolean onLineNew = iHikClientService.isOnLine(cmd);//鐩告満瀹炴椂鐘舵��
+ boolean onLineOld = "1".equals(camera.getState());//鐩告満鍘嗗彶鐘舵��
+ //褰撶姸鎬佸彂鐢熷彉鍖栨椂锛屾洿鏂板疄鏃剁姸鎬�
+ if (onLineNew != onLineOld) {
+ if (onLineNew) {
+ camera.setState("1");
+ } else {
+ camera.setState("0");
+ }
+ iArdCamerasService.updateArdCameras(camera);
}
- iArdCamerasService.updateArdCameras(camera);
+
}
+ } catch (Exception ex) {
+ log.error("鍚屾鐩告満鍦ㄧ嚎鐘舵�佸紓甯�:" + ex.getMessage());
}
}
@@ -80,4 +98,19 @@
log.error("铻嶄簯鍦ㄧ嚎鎺ュ彛寮傚父锛�" + ex.getMessage());
}
}
+
+ /**
+ * 鍚屾娴佸獟浣�
+ * 鍒樿嫃涔�
+ * 2023/10/13 14:13:53
+ */
+ public void vtdu() {
+ List<String> nameList = mediaService.getNameList();
+ List<Vtdu> vtdus = vtduService.selectVtduList(new Vtdu());
+ for (Vtdu vtdu : vtdus) {
+ if (!nameList.contains(vtdu.getName())) {
+ mediaService.addPath(vtdu.getName(),vtdu.getRtspSource(),vtdu.getMode(),vtdu.getIsCode());
+ }
+ }
+ }
}
--
Gitblit v1.9.3