| | |
| | | |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.media.domain.MediaInfo; |
| | | 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.StreamInfo; |
| | | import com.ruoyi.media.domain.Vtdu; |
| | | import com.ruoyi.media.service.IMediaService; |
| | | import com.ruoyi.media.service.impl.MediaService; |
| | | import com.ruoyi.media.service.IVtduService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | 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: |
| | |
| | | **/ |
| | | @RestController |
| | | @Api(tags = "流媒体接口") |
| | | @RequestMapping("/media/stream") |
| | | @Anonymous |
| | | public class MediaController { |
| | | public class MediaController extends BaseController { |
| | | @Resource |
| | | private IMediaService mediaService; |
| | | @Resource |
| | | private IVtduService vtduService; |
| | | |
| | | @PostMapping("/add") |
| | | @ApiOperation("增加转码") |
| | | public AjaxResult addPath(@RequestBody MediaInfo mediaInfo) { |
| | | String rtsp = mediaService.addPath(mediaInfo.getCameraId(), mediaInfo.getRtspPath()); |
| | | return AjaxResult.success(rtsp); |
| | | /** |
| | | * 增加通道 |
| | | */ |
| | | @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.setSourceUrl(streamInfo.getRtspSource()); |
| | | vtdu.setIsCode(streamInfo.getIsCode()); |
| | | vtdu.setCodeType(streamInfo.getMode()); |
| | | vtdu.setRtspUrl(map.get("rtspUrl")); |
| | | vtdu.setRtmpUrl(map.get("rtmpUrl")); |
| | | vtdu.setWebrtcUrl(map.get("webrtcUrl")); |
| | | vtduService.insertVtdu(vtdu); |
| | | return AjaxResult.success(map); |
| | | } |
| | | @PostMapping("/remove") |
| | | @ApiOperation("移除转码") |
| | | @ApiOperationSupport(includeParameters={"mediaInfo.cameraId"}) |
| | | public AjaxResult removePath(@RequestBody MediaInfo mediaInfo) { |
| | | mediaService.removePath(mediaInfo.getCameraId()); |
| | | |
| | | |
| | | /** |
| | | * 修改通道 |
| | | */ |
| | | @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()); |
| | | Map<String, String> map = mediaService.addPath(streamInfo.getName(), streamInfo.getRtspSource(), streamInfo.getMode(), streamInfo.getIsCode()); |
| | | Vtdu vtdu = new Vtdu(); |
| | | vtdu.setName(streamInfo.getName()); |
| | | vtdu.setSourceUrl(streamInfo.getRtspSource()); |
| | | vtdu.setIsCode(streamInfo.getIsCode()); |
| | | vtdu.setCodeType(streamInfo.getMode()); |
| | | vtdu.setRtspUrl(map.get("rtspUrl")); |
| | | vtdu.setRtmpUrl(map.get("rtmpUrl")); |
| | | vtdu.setWebrtcUrl(map.get("webrtcUrl")); |
| | | 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(); |
| | | } |
| | | @GetMapping("/getPaths") |
| | | @ApiOperation("获取当前转码列表") |
| | | public AjaxResult getPaths() { |
| | | return AjaxResult.success(mediaService.paths()); |
| | | |
| | | /** |
| | | * 移除拉流 |
| | | */ |
| | | @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(); |
| | | } |
| | | @GetMapping("/getRtspSessions") |
| | | @ApiOperation("获取rtsp会话列表") |
| | | public AjaxResult getRtspSessions() { |
| | | return AjaxResult.success(mediaService.rtspsessions()); |
| | | |
| | | /** |
| | | * 获取通道详细信息 |
| | | */ |
| | | @ApiOperation("获取通道详细信息") |
| | | @ApiOperationSupport(order =4 ) |
| | | @GetMapping(value = "/{name}") |
| | | public AjaxResult getInfo(@PathVariable("name") String name) { |
| | | return success(mediaService.getPathInfo(name)); |
| | | } |
| | | @GetMapping("/getRtspConns") |
| | | @ApiOperation("获取rtsp连接列表") |
| | | public AjaxResult getRtspConns() { |
| | | return AjaxResult.success(mediaService.rtspconns()); |
| | | |
| | | /** |
| | | * 获取当前通道列表 |
| | | */ |
| | | @GetMapping("/path/list") |
| | | @ApiOperation("获取当前通道列表") |
| | | @ApiOperationSupport(order = 5) |
| | | public TableDataInfo getPaths() { |
| | | startPage(); |
| | | return getDataTable(mediaService.paths()); |
| | | } |
| | | |
| | | /** |
| | | * 按ID查询拉流详情 |
| | | */ |
| | | @GetMapping("/getRtspSessionById") |
| | | @ApiOperation("按ID查询拉流详情") |
| | | public AjaxResult getRtspSessionById(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.getRtspSessionById(sessionId)); |
| | | case "rtmp": |
| | | return AjaxResult.success(mediaService.getRtmpSessionById(sessionId)); |
| | | case "webrtc": |
| | | return AjaxResult.success(mediaService.getWebrtcSessionById(sessionId)); |
| | | } |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | /** |
| | | * 获取推流列表 |
| | | */ |
| | | @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:list')") |
| | | @GetMapping("/pullList") |
| | | @ApiOperation("获取拉流列表") |
| | | @ApiOperationSupport(order = 7) |
| | | public TableDataInfo getPullStreamList() { |
| | | startPage(); |
| | | return getDataTable(mediaService.getPullStreamList()); |
| | | } |
| | | } |