From 510c29eecab77493816d3f0cdb5e5c4462083cc8 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期二, 29 八月 2023 14:03:55 +0800
Subject: [PATCH] 增加流媒体数据库业务 增加电子围栏接口
---
ard-work/src/main/java/com/ruoyi/media/mapper/VtduMapper.java | 60 ++++
ard-work/src/main/java/com/ruoyi/media/controller/MediaController.java | 178 ++++++++-----
ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java | 88 ++++++
ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml | 69 +++++
ard-work/src/main/resources/templates/mediaMTX.html | 36 ++
ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java | 104 ++++++++
ard-work/src/main/java/com/ruoyi/alarmpoints/elecwall/controller/ArdWallController.java | 9
ard-work/src/main/java/com/ruoyi/media/service/IMediaService.java | 19
ard-work/src/main/java/com/ruoyi/media/service/IVtduService.java | 61 ++++
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java | 101 +++----
ard-work/src/main/java/com/ruoyi/media/domain/Vtdu.java | 45 +++
11 files changed, 627 insertions(+), 143 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/alarmpoints/elecwall/controller/ArdWallController.java b/ard-work/src/main/java/com/ruoyi/alarmpoints/elecwall/controller/ArdWallController.java
index 786865c..07d9c27 100644
--- a/ard-work/src/main/java/com/ruoyi/alarmpoints/elecwall/controller/ArdWallController.java
+++ b/ard-work/src/main/java/com/ruoyi/alarmpoints/elecwall/controller/ArdWallController.java
@@ -2,6 +2,9 @@
import java.util.List;
import javax.servlet.http.HttpServletResponse;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -27,6 +30,7 @@
* @author ard
* @date 2023-07-20
*/
+@Api(tags = "鐢靛瓙鍥存爮绠$悊")
@RestController
@RequestMapping("/alarmpoints/wall")
public class ArdWallController extends BaseController
@@ -37,6 +41,7 @@
/**
* 鏌ヨ鐢靛瓙鍥存爮绠$悊鍒楄〃
*/
+ @ApiOperation("鏌ヨ鐢靛瓙鍥存爮绠$悊鍒楄〃")
@PreAuthorize("@ss.hasPermi('alarmpoints:wall:list')")
@GetMapping("/list")
public TableDataInfo list(ArdWall ardWall)
@@ -62,6 +67,7 @@
/**
* 鑾峰彇鐢靛瓙鍥存爮绠$悊璇︾粏淇℃伅
*/
+ @ApiOperation("鑾峰彇鐢靛瓙鍥存爮绠$悊璇︾粏淇℃伅")
@PreAuthorize("@ss.hasPermi('alarmpoints:wall:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id)
@@ -72,6 +78,7 @@
/**
* 鏂板鐢靛瓙鍥存爮绠$悊
*/
+ @ApiOperation("鏂板鐢靛瓙鍥存爮绠$悊")
@PreAuthorize("@ss.hasPermi('alarmpoints:wall:add')")
@Log(title = "鐢靛瓙鍥存爮绠$悊", businessType = BusinessType.INSERT)
@PostMapping
@@ -83,6 +90,7 @@
/**
* 淇敼鐢靛瓙鍥存爮绠$悊
*/
+ @ApiOperation("淇敼鐢靛瓙鍥存爮绠$悊")
@PreAuthorize("@ss.hasPermi('alarmpoints:wall:edit')")
@Log(title = "鐢靛瓙鍥存爮绠$悊", businessType = BusinessType.UPDATE)
@PutMapping
@@ -94,6 +102,7 @@
/**
* 鍒犻櫎鐢靛瓙鍥存爮绠$悊
*/
+ @ApiOperation("鍒犻櫎鐢靛瓙鍥存爮绠$悊")
@PreAuthorize("@ss.hasPermi('alarmpoints:wall:remove')")
@Log(title = "鐢靛瓙鍥存爮绠$悊", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
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 ca50877..e91ca81 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
@@ -2,15 +2,15 @@
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.annotation.Anonymous;
-import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
-import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.device.camera.domain.ArdCameras;
+import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.media.domain.StreamInfo;
+import com.ruoyi.media.domain.Vtdu;
import com.ruoyi.media.service.IMediaService;
+import com.ruoyi.media.service.IVtduService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -19,7 +19,6 @@
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
/**
* @Description:
@@ -35,11 +34,16 @@
public class MediaController extends BaseController {
@Resource
private IMediaService mediaService;
+ @Resource
+ private IVtduService vtduService;
+ /**
+ * 澧炲姞閫氶亾
+ */
@PostMapping()
- @ApiOperation("澧炲姞杞爜")
+ @ApiOperation("澧炲姞閫氶亾")
@PreAuthorize("@ss.hasPermi('media:stream:add')")
- @ApiOperationSupport(includeParameters = {"streamInfo.name", "streamInfo.rtspSource", "streamInfo.mode"})
+ @ApiOperationSupport(includeParameters = {"streamInfo.name", "streamInfo.rtspSource", "streamInfo.mode", "streamInfo.isCode"}, order = 1)
public AjaxResult addPath(@RequestBody StreamInfo streamInfo) {
if (StringUtils.isEmpty(streamInfo.getName())) {
return AjaxResult.error("閫氶亾鍚嶇О涓嶈兘涓虹┖");
@@ -48,107 +52,135 @@
return AjaxResult.error("rtsp鍦板潃涓嶈兘涓虹┖");
}
String rtsp = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(), streamInfo.getIsCode());
+ Vtdu vtdu = new Vtdu();
+ vtdu.setName(streamInfo.getName());
+ vtdu.setRtspUrl(streamInfo.getRtspSource());
+ vtdu.setIsCode(streamInfo.getIsCode());
+ vtdu.setCodeType(streamInfo.getMode());
+ vtduService.insertVtdu(vtdu);
+ return AjaxResult.success(rtsp);
+ }
+
+
+ /**
+ * 淇敼閫氶亾
+ */
+ @ApiOperation("淇敼閫氶亾")
+ @ApiOperationSupport(includeParameters = {"streamInfo.name", "streamInfo.rtspSource", "streamInfo.mode", "streamInfo.isCode"}, order = 2)
+ @PreAuthorize("@ss.hasPermi('media:stream:edit')")
+ @PutMapping
+ public AjaxResult edit(@RequestBody StreamInfo streamInfo) {
+ mediaService.removePath(new String[]{streamInfo.getName()});
+ vtduService.deleteVtduByName(streamInfo.getName());
+ String rtsp = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(), streamInfo.getIsCode());
+ Vtdu vtdu = new Vtdu();
+ vtdu.setName(streamInfo.getName());
+ vtdu.setRtspUrl(streamInfo.getRtspSource());
+ vtdu.setIsCode(streamInfo.getIsCode());
+ vtdu.setCodeType(streamInfo.getMode());
+ vtduService.insertVtdu(vtdu);
return AjaxResult.success(rtsp);
}
/**
- * 鑾峰彇杞爜璇︾粏淇℃伅
+ * 绉婚櫎閫氶亾
*/
- @ApiOperation("鑾峰彇杞爜璇︾粏淇℃伅")
+ @DeleteMapping("/path/{names}")
+ @PreAuthorize("@ss.hasPermi('media:stream:remove')")
+ @ApiOperation("绉婚櫎閫氶亾")
+ @ApiOperationSupport(order = 3)
+ public AjaxResult removePath(@PathVariable String[] names) {
+ mediaService.removePath(names);
+ vtduService.deleteVtduByNames(names);
+ return AjaxResult.success();
+ }
+
+ /**
+ * 绉婚櫎鎷夋祦
+ */
+ @ApiOperation("绉婚櫎鎷夋祦")
+ @ApiOperationSupport(order =4 )
+ @PreAuthorize("@ss.hasPermi('media:stream:remove')")
+ @DeleteMapping("/{id}")
+ public AjaxResult removePullStreamSession(@PathVariable String sessionId) {
+ List<StreamInfo> pullStreamList = mediaService.getPullStreamList();
+ StreamInfo streamInfo = pullStreamList.stream()
+ .filter(object -> object.getId().equals(sessionId))
+ .collect(Collectors.toList()).get(0);
+ switch (streamInfo.getSessionType()) {
+ case "rtsp":
+ return AjaxResult.success(mediaService.kickRtspSession(sessionId));
+ case "webrtc":
+ return AjaxResult.success(mediaService.kickWebrtcSession(sessionId));
+ case "rtmp":
+ return AjaxResult.success(mediaService.kickRtmpSession(sessionId));
+ }
+ return AjaxResult.error();
+ }
+
+ /**
+ * 鑾峰彇閫氶亾璇︾粏淇℃伅
+ */
+ @ApiOperation("鑾峰彇閫氶亾璇︾粏淇℃伅")
+ @ApiOperationSupport(order =4 )
@GetMapping(value = "/{name}")
public AjaxResult getInfo(@PathVariable("name") String name) {
return success(mediaService.getPathInfo(name));
}
/**
- * 淇敼杞爜
+ * 鑾峰彇褰撳墠閫氶亾鍒楄〃
*/
- @ApiOperation("淇敼杞爜")
- @PreAuthorize("@ss.hasPermi('media:stream:edit')")
- @PutMapping
- public AjaxResult edit(@RequestBody StreamInfo streamInfo) {
- mediaService.removePath(new String[]{streamInfo.getName()});
- String rtsp = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(), streamInfo.getIsCode());
- return AjaxResult.success(rtsp);
- }
-
- @DeleteMapping("/path/{names}")
- @PreAuthorize("@ss.hasPermi('media:stream:remove')")
- @ApiOperation("绉婚櫎杞爜")
- public AjaxResult removePath(@PathVariable String[] names) {
- mediaService.removePath(names);
- return AjaxResult.success();
- }
-
@GetMapping("/path/list")
- @ApiOperation("鑾峰彇褰撳墠杞爜鍒楄〃")
+ @ApiOperation("鑾峰彇褰撳墠閫氶亾鍒楄〃")
+ @ApiOperationSupport(order = 5)
public TableDataInfo getPaths() {
startPage();
return getDataTable(mediaService.paths());
}
- @GetMapping("/getRtspSessions")
- @ApiOperation("鑾峰彇rtsp浼氳瘽鍒楄〃")
- public AjaxResult getRtspSessions() {
- return AjaxResult.success(mediaService.rtspsessions());
- }
-
- @GetMapping("/getRtspConns")
- @ApiOperation("鑾峰彇rtsp杩炴帴鍒楄〃")
- public AjaxResult getRtspConns() {
- return AjaxResult.success(mediaService.rtspconns());
- }
-
+ /**
+ * 鎸塈D鏌ヨ鎷夋祦璇︽儏
+ */
@GetMapping("/getRtspSessionById")
- @ApiOperation("鎸塈D鏌ヨ浼氳瘽")
+ @ApiOperation("鎸塈D鏌ヨ鎷夋祦璇︽儏")
public AjaxResult getRtspSessionById(String sessionId) {
- return AjaxResult.success(mediaService.getRtspSessionById(sessionId));
+ List<StreamInfo> pullStreamList = mediaService.getPullStreamList();
+ StreamInfo streamInfo = pullStreamList.stream()
+ .filter(object -> object.getId().equals(sessionId))
+ .collect(Collectors.toList()).get(0);
+ switch (streamInfo.getSessionType()) {
+ case "rtsp":
+ return AjaxResult.success(mediaService.getRtspSessionById(sessionId));
+ case "rtmp":
+ return AjaxResult.success(mediaService.getRtmpSessionById(sessionId));
+ case "webrtc":
+ return AjaxResult.success(mediaService.getWebrtcSessionById(sessionId));
+ }
+ return AjaxResult.error();
}
- @GetMapping("/getPushStreams")
- @ApiOperation("鑾峰彇鎺ㄦ祦淇℃伅")
- public AjaxResult getPushStreams() {
- return AjaxResult.success(mediaService.getPushStreams());
- }
-
- @GetMapping("/getPullStreams")
- @ApiOperation("鑾峰彇鎷夋祦淇℃伅")
- public AjaxResult getPullStreams() {
- return AjaxResult.success(mediaService.getPullStreams());
- }
-
+ /**
+ * 鑾峰彇鎺ㄦ祦鍒楄〃
+ */
@PreAuthorize("@ss.hasPermi('media:stream:list')")
@GetMapping("/pushList")
@ApiOperation("鑾峰彇鎺ㄦ祦鍒楄〃")
+ @ApiOperationSupport(order = 6)
public TableDataInfo getPushStreamList() {
startPage();
return getDataTable(mediaService.getPushStreamList());
}
- /**
- * 鍒犻櫎娴佸獟浣撴媺娴�
- */
- @PreAuthorize("@ss.hasPermi('media:stream:remove')")
- @DeleteMapping("/{id}")
- public AjaxResult removePullStreamSession(@PathVariable String id) {
- List<StreamInfo> pullStreamList = mediaService.getPullStreamList();
- StreamInfo streamInfo = pullStreamList.stream()
- .filter(object -> object.getId().equals(id))
- .collect(Collectors.toList()).get(0);
- switch (streamInfo.getSessionType()) {
- case "rtsp":
- return AjaxResult.success(mediaService.kickRtspSession(id));
- case "webrtc":
- return AjaxResult.success(mediaService.kickWebrtcSession(id));
- case "rtmp":
- return AjaxResult.success(mediaService.kickRtmpSession(id));
- }
- return AjaxResult.error();
- }
+
+ /**
+ * 鑾峰彇鎷夋祦鍒楄〃
+ */
@PreAuthorize("@ss.hasPermi('media:stream:list')")
@GetMapping("/pullList")
@ApiOperation("鑾峰彇鎷夋祦鍒楄〃")
+ @ApiOperationSupport(order = 7)
public TableDataInfo getPullStreamList() {
startPage();
return getDataTable(mediaService.getPullStreamList());
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
new file mode 100644
index 0000000..e6847aa
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/media/controller/VtduController.java
@@ -0,0 +1,104 @@
+package com.ruoyi.media.controller;
+
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.media.domain.Vtdu;
+import com.ruoyi.media.service.IVtduService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 娴佸獟浣撶鐞咰ontroller
+ *
+ * @author ard
+ * @date 2023-08-29
+ */
+@RestController
+@RequestMapping("/vtdu/media")
+public class VtduController extends BaseController
+{
+ @Autowired
+ private IVtduService vtduService;
+
+ /**
+ * 鏌ヨ娴佸獟浣撶鐞嗗垪琛�
+ */
+ @PreAuthorize("@ss.hasPermi('vtdu:media:list')")
+ @GetMapping("/list")
+ public TableDataInfo list(Vtdu vtdu)
+ {
+ startPage();
+ List<Vtdu> list = vtduService.selectVtduList(vtdu);
+ return getDataTable(list);
+ }
+
+ /**
+ * 瀵煎嚭娴佸獟浣撶鐞嗗垪琛�
+ */
+ @PreAuthorize("@ss.hasPermi('vtdu:media:export')")
+ @Log(title = "娴佸獟浣撶鐞�", businessType = BusinessType.EXPORT)
+ @PostMapping("/export")
+ public void export(HttpServletResponse response, Vtdu vtdu)
+ {
+ List<Vtdu> list = vtduService.selectVtduList(vtdu);
+ ExcelUtil<Vtdu> util = new ExcelUtil<Vtdu>(Vtdu.class);
+ util.exportExcel(response, list, "娴佸獟浣撶鐞嗘暟鎹�");
+ }
+
+ /**
+ * 鑾峰彇娴佸獟浣撶鐞嗚缁嗕俊鎭�
+ */
+ @PreAuthorize("@ss.hasPermi('vtdu:media:query')")
+ @GetMapping(value = "/{name}")
+ public AjaxResult getInfo(@PathVariable("name") String name)
+ {
+ return success(vtduService.selectVtduByName(name));
+ }
+
+ /**
+ * 鏂板娴佸獟浣撶鐞�
+ */
+ @PreAuthorize("@ss.hasPermi('vtdu:media:add')")
+ @Log(title = "娴佸獟浣撶鐞�", businessType = BusinessType.INSERT)
+ @PostMapping
+ public AjaxResult add(@RequestBody Vtdu vtdu)
+ {
+ return toAjax(vtduService.insertVtdu(vtdu));
+ }
+
+ /**
+ * 淇敼娴佸獟浣撶鐞�
+ */
+ @PreAuthorize("@ss.hasPermi('vtdu:media:edit')")
+ @Log(title = "娴佸獟浣撶鐞�", businessType = BusinessType.UPDATE)
+ @PutMapping
+ public AjaxResult edit(@RequestBody Vtdu vtdu)
+ {
+ return toAjax(vtduService.updateVtdu(vtdu));
+ }
+
+ /**
+ * 鍒犻櫎娴佸獟浣撶鐞�
+ */
+ @PreAuthorize("@ss.hasPermi('vtdu:media:remove')")
+ @Log(title = "娴佸獟浣撶鐞�", businessType = BusinessType.DELETE)
+ @DeleteMapping("/{names}")
+ public AjaxResult remove(@PathVariable String[] names)
+ {
+ return toAjax(vtduService.deleteVtduByNames(names));
+ }
+}
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
new file mode 100644
index 0000000..bbf9d60
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/media/domain/Vtdu.java
@@ -0,0 +1,45 @@
+package com.ruoyi.media.domain;
+
+import lombok.Data;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+
+/**
+ * 娴佸獟浣撶鐞嗗璞� vtdu
+ *
+ * @author ard
+ * @date 2023-08-29
+ */
+@Data
+public class Vtdu extends BaseEntity {
+ private static final long serialVersionUID = 1L;
+
+
+ /**
+ * 涓婚敭鍚嶇О
+ */
+ @Excel(name = "鍚嶇О")
+ private String name;
+
+ /**
+ * rtsp婧愬湴鍧�
+ */
+ @Excel(name = "rtsp婧愬湴鍧�")
+ private String rtspUrl;
+
+ /**
+ * 鏄惁杞爜
+ */
+ @Excel(name = "鏄惁杞爜")
+ private String isCode;
+
+ /**
+ * 杞爜妯″紡
+ */
+ @Excel(name = "杞爜妯″紡")
+ private String codeType;
+
+
+}
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
new file mode 100644
index 0000000..db474de
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/media/mapper/VtduMapper.java
@@ -0,0 +1,60 @@
+package com.ruoyi.media.mapper;
+
+import java.util.List;
+import com.ruoyi.media.domain.Vtdu;
+
+/**
+ * 娴佸獟浣撶鐞哅apper鎺ュ彛
+ *
+ * @author ard
+ * @date 2023-08-29
+ */
+public interface VtduMapper
+{
+ /**
+ * 鏌ヨ娴佸獟浣撶鐞�
+ *
+ * @param name 娴佸獟浣撶鐞嗕富閿�
+ * @return 娴佸獟浣撶鐞�
+ */
+ public Vtdu selectVtduByName(String name);
+
+ /**
+ * 鏌ヨ娴佸獟浣撶鐞嗗垪琛�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 娴佸獟浣撶鐞嗛泦鍚�
+ */
+ public List<Vtdu> selectVtduList(Vtdu vtdu);
+
+ /**
+ * 鏂板娴佸獟浣撶鐞�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 缁撴灉
+ */
+ public int insertVtdu(Vtdu vtdu);
+
+ /**
+ * 淇敼娴佸獟浣撶鐞�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 缁撴灉
+ */
+ public int updateVtdu(Vtdu vtdu);
+
+ /**
+ * 鍒犻櫎娴佸獟浣撶鐞�
+ *
+ * @param name 娴佸獟浣撻�氶亾鍚嶇О
+ * @return 缁撴灉
+ */
+ public int deleteVtduByName(String name);
+ /**
+ * 鎵归噺鍒犻櫎娴佸獟浣撶鐞�
+ *
+ * @param names 闇�瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎
+ * @return 缁撴灉
+ */
+ public int deleteVtduByNames(String[] names);
+}
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 bd99555..8337a5f 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
@@ -14,30 +14,27 @@
* 鍒樿嫃涔�
* 2023/8/12 13:56:52
*/
- public String addPath(String name, String rtspPath, String mode, String isCode);
+ String addPath(String name, String rtspPath, String mode, String isCode);
StreamInfo getPathInfo(String name);
- public void removePath(String[] names);
+ void removePath(String[] names);
- public List<StreamInfo> paths();
-
- public List<Items> rtspconns();
-
- public List<Items> rtspsessions();
+ List<StreamInfo> paths();
RtspSession getRtspSessionById(String sessionId);
- WebrtcSession getWebrtcSessionById(String sessionId);
- RtmpSession getRtmpSessionById(String sessionId);
- List<RtspSession> getPushStreams();
- List<RtspSession> getPullStreams();
+ WebrtcSession getWebrtcSessionById(String sessionId);
+
+ RtmpSession getRtmpSessionById(String sessionId);
List<StreamInfo> getPushStreamList();
List<StreamInfo> getPullStreamList();
Boolean kickRtspSession(String sessionId);
+
Boolean kickRtmpSession(String sessionId);
+
Boolean kickWebrtcSession(String sessionId);
}
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
new file mode 100644
index 0000000..7fb33dd
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/media/service/IVtduService.java
@@ -0,0 +1,61 @@
+package com.ruoyi.media.service;
+
+import java.util.List;
+import com.ruoyi.media.domain.Vtdu;
+
+/**
+ * 娴佸獟浣撶鐞哠ervice鎺ュ彛
+ *
+ * @author ard
+ * @date 2023-08-29
+ */
+public interface IVtduService
+{
+ /**
+ * 鏌ヨ娴佸獟浣撶鐞�
+ *
+ * @param name 娴佸獟浣撶鐞嗕富閿�
+ * @return 娴佸獟浣撶鐞�
+ */
+ public Vtdu selectVtduByName(String name);
+
+ /**
+ * 鏌ヨ娴佸獟浣撶鐞嗗垪琛�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 娴佸獟浣撶鐞嗛泦鍚�
+ */
+ public List<Vtdu> selectVtduList(Vtdu vtdu);
+
+ /**
+ * 鏂板娴佸獟浣撶鐞�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 缁撴灉
+ */
+ public int insertVtdu(Vtdu vtdu);
+
+ /**
+ * 淇敼娴佸獟浣撶鐞�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 缁撴灉
+ */
+ public int updateVtdu(Vtdu vtdu);
+
+ /**
+ * 鎵归噺鍒犻櫎娴佸獟浣撶鐞�
+ *
+ * @param names 闇�瑕佸垹闄ょ殑娴佸獟浣撶鐞嗕富閿泦鍚�
+ * @return 缁撴灉
+ */
+ public int deleteVtduByNames(String[] names);
+
+ /**
+ * 鍒犻櫎娴佸獟浣撶鐞嗕俊鎭�
+ *
+ * @param name 娴佸獟浣撶鐞嗕富閿�
+ * @return 缁撴灉
+ */
+ public int deleteVtduByName(String name);
+}
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
index 090961e..9b69946 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
@@ -2,7 +2,9 @@
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.media.domain.*;
+import com.ruoyi.media.mapper.VtduMapper;
import com.ruoyi.media.service.IMediaService;
import com.ruoyi.utils.forest.MediaClient;
import com.ruoyi.utils.tools.ArdTool;
@@ -33,13 +35,16 @@
@Service
@Slf4j(topic = "cmd")
public class MediaService implements IMediaService {
-
+ @Resource
+ VtduMapper vtduMapper;
@Resource
MediaClient mediaClient;
@Value("${mediamtx.host}")
String mediamtxHost;
@Value("${mediamtx.enabled}")
Boolean mediamtxEnabled;
+ @Value("${mediamtx.software_decoding}")
+ Boolean softwareDecoding;
String processName = "mediamtx.exe";
@@ -64,6 +69,10 @@
// CmdUtils.commandStart(command);
}
}
+ List<Vtdu> vtduList = vtduMapper.selectVtduList(new Vtdu());
+ for (Vtdu v : vtduList) {
+ addPath(v.getName(), v.getRtspUrl(), v.getCodeType(), v.getIsCode());
+ }
}
@PreDestroy
@@ -81,18 +90,25 @@
public String addPath(String name, String rtspPath, String mode, String isCode) {
String rtspUrl = "rtsp://" + mediamtxHost + ":7554/" + name;
Conf mediaInfo = new Conf();
+ String rootPath = System.getProperty("user.dir").replaceAll("\\\\", "/");
//-vcodec libx264 //鎸囧畾瑙嗛缂栫爜鍣ㄤ负 libx264锛屼娇鐢� H.264 缂栫爜鏍煎紡杩涜瑙嗛鍘嬬缉
//-preset ultrafast //--preset鐨勫弬鏁颁富瑕佽皟鑺傜紪鐮侀�熷害鍜岃川閲忕殑骞宠 锛屾湁ultrafast锛堣浆鐮侀�熷害鏈�蹇紝瑙嗛寰�寰�涔熸渶妯$硦锛夈�乻uperfast銆乿eryfast銆乫aster銆乫ast銆乵edium銆乻low銆乻lower銆乿eryslow銆乸lacebo杩�10涓�夐」锛屼粠蹇埌鎱�
//-r 25 //璁剧疆杈撳嚭瑙嗛鐨勫抚鐜囦负 25 甯�/绉�
//-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 鏍煎紡銆�
//CPU杞В鐮佺紪鐮�
- String cmd = "ffmpeg -rtsp_transport tcp -i \"" + rtspPath + "\" -vcodec libx264 -preset:v ultrafast -r 25 -threads 4 -b:v 4096k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
+ //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 = "ffmpeg -hwaccel cuvid -c:v h264_cuvid -rtsp_transport udp -i \"" + rtspPath + "\" -c:v h264_nvenc -r 25 -threads 4 -b:v 4096k -f rtsp rtsp://localhost:$RTSP_PORT/$MTX_PATH";
+ //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 = 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";
+ if (!softwareDecoding) {
+ 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 (mode.equals("1")) {
mediaInfo.setRunondemand(cmd);
mediaInfo.setRunondemandrestart(true);
@@ -188,19 +204,6 @@
return pathInfoList;
}
- @Override
- public List<Items> rtspconns() {
- String list = mediaClient.rtspconns();
- JsonsRoot jsonsRoot = JSONObject.parseObject(list, JsonsRoot.class);
- return jsonsRoot.getItems();
- }
-
- @Override
- public List<Items> rtspsessions() {
- String list = mediaClient.rtspsessions();
- JsonsRoot jsonsRoot = JSONObject.parseObject(list, JsonsRoot.class);
- return jsonsRoot.getItems();
- }
@Override
public RtspSession getRtspSessionById(String sessionId) {
@@ -223,39 +226,11 @@
return rtmpSession;
}
- @Override
- public List<RtspSession> getPushStreams() {
- List<RtspSession> rtspSessions = new ArrayList<>();
-
- String list = mediaClient.paths();
- JsonsRoot jsonsRoot = JSONObject.parseObject(list, JsonsRoot.class);
- List<Items> items = jsonsRoot.getItems();
- for (Items item : items) {
- Source source = item.getSource();
- RtspSession rtspSession = getRtspSessionById(source.getId());
- rtspSession.setName(item.getName());
- rtspSessions.add(rtspSession);
- }
- return rtspSessions;
- }
-
- @Override
- public List<RtspSession> getPullStreams() {
- List<RtspSession> rtspSessions = new ArrayList<>();
- String list = mediaClient.paths();
- JsonsRoot jsonsRoot = JSONObject.parseObject(list, JsonsRoot.class);
- List<Items> items = jsonsRoot.getItems();
- for (Items item : items) {
- List<Readers> readers = item.getReaders();
- for (Readers reader : readers) {
- RtspSession rtspSession = getRtspSessionById(reader.getId());
- rtspSession.setName(item.getName());
- rtspSessions.add(rtspSession);
- }
- }
- return rtspSessions;
- }
-
+ /**
+ * 鑾峰彇鎺ㄦ祦鍒楄〃
+ * 鍒樿嫃涔�
+ * 2023/8/29 9:37:05
+ */
@Override
public List<StreamInfo> getPushStreamList() {
List<StreamInfo> PushStreamInfoList = new ArrayList<>();
@@ -329,6 +304,11 @@
return PushStreamInfoList;
}
+ /**
+ * 鑾峰彇鎷夋祦鍒楄〃
+ * 鍒樿嫃涔�
+ * 2023/8/29 9:37:05
+ */
@Override
public List<StreamInfo> getPullStreamList() {
List<StreamInfo> PullStreamInfoList = new ArrayList<>();
@@ -380,12 +360,12 @@
//寮�濮嬫媺娴佹椂闂�
info.setBeginTime(webrtcSession.getCreated());
//涓婅娴侀噺
- bytesReceived = webrtcSession.getBytesReceived();
- formatReceivedSize = ArdTool.formatFileSize(bytesReceived);
+ bytesReceived = webrtcSession.getBytesReceived();
+ formatReceivedSize = ArdTool.formatFileSize(bytesReceived);
info.setUpTraffic(formatReceivedSize);
//涓嬭娴侀噺
- bytesSent = webrtcSession.getBytesSent();
- formatSentSize = ArdTool.formatFileSize(bytesSent);
+ bytesSent = webrtcSession.getBytesSent();
+ formatSentSize = ArdTool.formatFileSize(bytesSent);
info.setDownTraffic(formatSentSize);
//鎷夋祦鏈嶅姟鍣�
info.setRemoteAddr(webrtcSession.getRemoteAddr());
@@ -421,6 +401,11 @@
return PullStreamInfoList;
}
+ /**
+ * 韪㈠嚭rtsp浼氳瘽
+ * 鍒樿嫃涔�
+ * 2023/8/29 9:37:05
+ */
@Override
public Boolean kickRtspSession(String sessionId) {
try {
@@ -431,6 +416,11 @@
}
}
+ /**
+ * 韪㈠嚭rtmp浼氳瘽
+ * 鍒樿嫃涔�
+ * 2023/8/29 9:37:05
+ */
@Override
public Boolean kickRtmpSession(String sessionId) {
try {
@@ -441,6 +431,11 @@
}
}
+ /**
+ * 韪㈠嚭webrtc浼氳瘽
+ * 鍒樿嫃涔�
+ * 2023/8/29 9:37:05
+ */
@Override
public Boolean kickWebrtcSession(String sessionId) {
try {
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
new file mode 100644
index 0000000..ebf5978
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/VtduServiceImpl.java
@@ -0,0 +1,88 @@
+package com.ruoyi.media.service.impl;
+
+import java.util.List;
+
+import com.ruoyi.common.utils.uuid.IdUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import com.ruoyi.media.mapper.VtduMapper;
+import com.ruoyi.media.domain.Vtdu;
+import com.ruoyi.media.service.IVtduService;
+
+/**
+ * 娴佸獟浣撶鐞哠ervice涓氬姟灞傚鐞�
+ *
+ * @author ard
+ * @date 2023-08-29
+ */
+@Service
+public class VtduServiceImpl implements IVtduService {
+ @Autowired
+ private VtduMapper vtduMapper;
+
+ /**
+ * 鏌ヨ娴佸獟浣撶鐞�
+ *
+ * @param name 娴佸獟浣撶鐞嗕富閿�
+ * @return 娴佸獟浣撶鐞�
+ */
+ @Override
+ public Vtdu selectVtduByName(String name) {
+ return vtduMapper.selectVtduByName(name);
+ }
+
+ /**
+ * 鏌ヨ娴佸獟浣撶鐞嗗垪琛�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 娴佸獟浣撶鐞�
+ */
+ @Override
+ public List<Vtdu> selectVtduList(Vtdu vtdu) {
+ return vtduMapper.selectVtduList(vtdu);
+ }
+
+ /**
+ * 鏂板娴佸獟浣撶鐞�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 缁撴灉
+ */
+ @Override
+ public int insertVtdu(Vtdu vtdu) {
+ return vtduMapper.insertVtdu(vtdu);
+ }
+
+ /**
+ * 淇敼娴佸獟浣撶鐞�
+ *
+ * @param vtdu 娴佸獟浣撶鐞�
+ * @return 缁撴灉
+ */
+ @Override
+ public int updateVtdu(Vtdu vtdu) {
+ return vtduMapper.updateVtdu(vtdu);
+ }
+
+ /**
+ * 鎵归噺鍒犻櫎娴佸獟浣撶鐞�
+ *
+ * @param names 闇�瑕佸垹闄ょ殑鏁版嵁涓婚敭闆嗗悎
+ * @return 缁撴灉
+ */
+ @Override
+ public int deleteVtduByNames(String[] names) {
+ return vtduMapper.deleteVtduByNames(names);
+ }
+
+ /**
+ * 鍒犻櫎娴佸獟浣撶鐞�
+ *
+ * @param name 娴佸獟浣撻�氶亾鍚嶇О
+ * @return 缁撴灉
+ */
+ @Override
+ public int deleteVtduByName(String name) {
+ return vtduMapper.deleteVtduByName(name);
+ }
+}
diff --git a/ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml b/ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml
new file mode 100644
index 0000000..30dd0fb
--- /dev/null
+++ b/ard-work/src/main/resources/mapper/vtdu/VtduMapper.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.media.mapper.VtduMapper">
+
+ <resultMap type="Vtdu" id="VtduResult">
+ <result property="name" column="name" />
+ <result property="rtspUrl" column="rtsp_url" />
+ <result property="isCode" column="is_code" />
+ <result property="codeType" column="code_type" />
+ </resultMap>
+
+ <sql id="selectVtduVo">
+ select name, rtsp_url, is_code, code_type from vtdu
+ </sql>
+
+ <select id="selectVtduList" parameterType="Vtdu" resultMap="VtduResult">
+ <include refid="selectVtduVo"/>
+ <where>
+ <if test="name != null and name != ''"> and name like '%'||#{name}||'%'</if>
+ <if test="rtspUrl != null and rtspUrl != ''"> and rtsp_url = #{rtspUrl}</if>
+ <if test="isCode != null and isCode != ''"> and is_code = #{isCode}</if>
+ <if test="codeType != null and codeType != ''"> and code_type = #{codeType}</if>
+ </where>
+ </select>
+
+ <select id="selectVtduByName" parameterType="String" resultMap="VtduResult">
+ <include refid="selectVtduVo"/>
+ where name = #{name}
+ </select>
+
+ <insert id="insertVtdu" parameterType="Vtdu">
+ insert into vtdu
+ <trim prefix="(" suffix=")" suffixOverrides=",">
+ <if test="name != null">name,</if>
+ <if test="rtspUrl != null">rtsp_url,</if>
+ <if test="isCode != null">is_code,</if>
+ <if test="codeType != null">code_type,</if>
+ </trim>
+ <trim prefix="values (" suffix=")" suffixOverrides=",">
+ <if test="name != null">#{name},</if>
+ <if test="rtspUrl != null">#{rtspUrl},</if>
+ <if test="isCode != null">#{isCode},</if>
+ <if test="codeType != null">#{codeType},</if>
+ </trim>
+ </insert>
+
+ <update id="updateVtdu" parameterType="Vtdu">
+ update vtdu
+ <trim prefix="SET" suffixOverrides=",">
+ <if test="rtspUrl != null">rtsp_url = #{rtspUrl},</if>
+ <if test="isCode != null">is_code = #{isCode},</if>
+ <if test="codeType != null">code_type = #{codeType},</if>
+ </trim>
+ where name = #{name}
+ </update>
+
+ <delete id="deleteVtduByName" parameterType="String">
+ delete from vtdu where name = #{name}
+ </delete>
+
+ <delete id="deleteVtduByNames" parameterType="String">
+ delete from vtdu where name in
+ <foreach item="name" collection="array" open="(" separator="," close=")">
+ #{name}
+ </foreach>
+ </delete>
+</mapper>
\ No newline at end of file
diff --git a/ard-work/src/main/resources/templates/mediaMTX.html b/ard-work/src/main/resources/templates/mediaMTX.html
index 2ae58db..b3a39ee 100644
--- a/ard-work/src/main/resources/templates/mediaMTX.html
+++ b/ard-work/src/main/resources/templates/mediaMTX.html
@@ -10,7 +10,7 @@
.video-container {
display: inline-block;
vertical-align: top;
- width: 25%; /* 鍏釜瑙嗛骞冲潎鍒嗛厤涓�琛岀殑瀹藉害 */
+ width: 33%; /* 3涓棰戝钩鍧囧垎閰嶄竴琛岀殑瀹藉害 */
/*padding: 2px; !* 鍙互鏍规嵁闇�瑕佽皟鏁村唴杈硅窛 *!*/
box-sizing: border-box;
}
@@ -42,7 +42,16 @@
</div>
</div>
<script th:inline="javascript">
- const restartPause = 2000;
+ var chanMap = new Map();
+ window.onload = function () {
+
+ chanMap.set("video1", "http://127.0.0.1:8889/164/");
+ chanMap.set("video2", "http://127.0.0.1:8889/164/");
+ chanMap.set("video3", "http://127.0.0.1:8889/164/");
+ chanMap.set("video4", "http://127.0.0.1:8889/165/");
+ chanMap.set("video5", "http://127.0.0.1:8889/165/");
+ console.log(chanMap);
+ }
const linkToIceServers = (links) => (
(links !== null) ? links.split(', ').map((link) => {
const m = link.match(/^<(.+?)>; rel="ice-server"(; username="(.*?)"; credential="(.*?)"; credential-type="password")?/i);
@@ -260,22 +269,37 @@
this.eTag = '';
this.queuedCandidates = [];
}
+
+ stop() {
+ if (this.pc) {
+ try {
+ this.pc.close();
+ } catch (e) {
+ console.log("Failure close peer connection:" + e);
+ }
+ this.pc = null;
+ }
+ }
}
let videoMap = new Map();
$('video').click(function (e) {
let ID = e.target.id;//鑾峰彇褰撳墠鐐瑰嚮浜嬩欢鐨勫厓绱�
console.log(ID);
+ console.log(videoMap);
if (videoMap.get(ID) != null) {
- closeVideo(ID, videoMap.get(ID));
+ closeVideo(ID);
} else {
- let client = new WHEPClient("http://127.0.0.1:8889/165/", ID);
+ let stream = chanMap.get(ID);
+ let client = new WHEPClient(stream, ID);
videoMap.set(ID, client);
}
});
+
function closeVideo(id) {
- let elementById = document.getElementById(id);
- elementById.pause();
+ console.log("鍏抽棴" + id)
+ let client = videoMap.get(id);
+ client.stop(id);
videoMap.delete(id);
}
</script>
--
Gitblit v1.9.3