| | |
| | | |
| | | 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.device.camera.domain.ArdCameras; |
| | | 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; |
| | | import com.ruoyi.media.service.IVtduService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: |
| | | * @Description: 流媒体业务 |
| | | * @ClassName: controller |
| | | * @Author: 刘苏义 |
| | | * @Date: 2023年07月13日9:26 |
| | |
| | | public class MediaController extends BaseController { |
| | | @Resource |
| | | private IMediaService mediaService; |
| | | @Resource |
| | | private IVtduService vtduService; |
| | | |
| | | @PostMapping() |
| | | @ApiOperation("增加转码") |
| | | @PreAuthorize("@ss.hasPermi('media:stream:add')") |
| | | @ApiOperationSupport(includeParameters = {"streamInfo.name", "streamInfo.rtspSource", "streamInfo.mode"}) |
| | | public AjaxResult addPath(@RequestBody StreamInfo streamInfo) { |
| | | String rtsp = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode()); |
| | | return AjaxResult.success(rtsp); |
| | | } |
| | | /** |
| | | * 获取转码详细信息 |
| | | * 增加通道 |
| | | */ |
| | | @ApiOperation("获取转码详细信息") |
| | | @PostMapping() |
| | | @ApiOperation("增加通道") |
| | | @PreAuthorize("@ss.hasPermi('media:stream:add')") |
| | | @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("通道名称不能为空"); |
| | | } |
| | | if (StringUtils.isEmpty(streamInfo.getRtspSource())) { |
| | | return AjaxResult.error("rtsp地址不能为空"); |
| | | } |
| | | Map<String, String> map = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(), streamInfo.getIsCode()); |
| | | map.get("rtspUrl"); |
| | | Vtdu vtdu = new Vtdu(); |
| | | vtdu.setName(streamInfo.getName()); |
| | | vtdu.setRtspSource(streamInfo.getRtspSource()); |
| | | vtdu.setIsCode(streamInfo.getIsCode()); |
| | | vtdu.setMode(streamInfo.getMode()); |
| | | vtdu.setRtspUrl(map.get("rtspUrl")); |
| | | vtdu.setRtmpUrl(map.get("rtmpUrl")); |
| | | vtdu.setWebrtcUrl(map.get("webrtcUrl")); |
| | | vtduService.insertVtdu(vtdu); |
| | | return AjaxResult.success(map); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改通道 |
| | | */ |
| | | @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) { |
| | | Map<String, String> map = mediaService.editPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(), streamInfo.getIsCode()); |
| | | Vtdu vtdu = new Vtdu(); |
| | | vtdu.setName(streamInfo.getName()); |
| | | vtdu.setRtspSource(streamInfo.getRtspSource()); |
| | | vtdu.setIsCode(streamInfo.getIsCode()); |
| | | vtdu.setMode(streamInfo.getMode()); |
| | | vtdu.setRtspUrl(map.get("rtspUrl")); |
| | | vtdu.setRtmpUrl(map.get("rtmpUrl")); |
| | | vtdu.setWebrtcUrl(map.get("webrtcUrl")); |
| | | vtduService.updateVtdu(vtdu); |
| | | return AjaxResult.success(map); |
| | | } |
| | | |
| | | /** |
| | | * 移除通道 |
| | | */ |
| | | @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("/{sessionId}") |
| | | 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()); |
| | | 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()); |
| | | } |
| | | |
| | | /** |
| | | * 按ID查询拉流详情 |
| | | */ |
| | | @GetMapping("/getRtspSessionById") |
| | | @ApiOperation("按ID查询会话") |
| | | @ApiOperation("按ID查询拉流详情") |
| | | 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) { |
| | | return AjaxResult.success(mediaService.kickRtspSession(id)); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('media:stream:list')") |
| | | @GetMapping("/pullList") |
| | | @ApiOperation("获取拉流列表") |
| | | @ApiOperationSupport(order = 7) |
| | | public TableDataInfo getPullStreamList() { |
| | | startPage(); |
| | | return getDataTable(mediaService.getPullStreamList()); |
| | | } |
| | | |
| | | /** |
| | | * 配置流媒体参数 |
| | | */ |
| | | @PostMapping("/setConfig") |
| | | @ApiOperation("配置流媒体参数") |
| | | @ApiOperationSupport(order = 8) |
| | | public AjaxResult setConfig(@RequestBody Config config) { |
| | | return AjaxResult.success(mediaService.setConfig(config)); |
| | | } |
| | | } |