StreamProxyController.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package com.genersoft.iot.vmp.vmanager.streamProxy;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.genersoft.iot.vmp.common.StreamInfo;
  4. import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
  5. import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
  6. import com.genersoft.iot.vmp.service.IMediaServerService;
  7. import com.genersoft.iot.vmp.service.IMediaService;
  8. import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  9. import com.genersoft.iot.vmp.service.IStreamProxyService;
  10. import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
  11. import com.github.pagehelper.PageInfo;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiImplicitParam;
  14. import io.swagger.annotations.ApiImplicitParams;
  15. import io.swagger.annotations.ApiOperation;
  16. import org.slf4j.Logger;
  17. import org.slf4j.LoggerFactory;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Controller;
  20. import org.springframework.util.StringUtils;
  21. import org.springframework.web.bind.annotation.*;
  22. @SuppressWarnings("rawtypes")
  23. /**
  24. * 拉流代理接口
  25. */
  26. @Api(tags = "拉流代理")
  27. @Controller
  28. @CrossOrigin
  29. @RequestMapping(value = "/api/proxy")
  30. public class StreamProxyController {
  31. private final static Logger logger = LoggerFactory.getLogger(StreamProxyController.class);
  32. @Autowired
  33. private IRedisCatchStorage redisCatchStorage;
  34. @Autowired
  35. private IMediaServerService mediaServerService;
  36. @Autowired
  37. private IStreamProxyService streamProxyService;
  38. @ApiOperation("分页查询流代理")
  39. @ApiImplicitParams({
  40. @ApiImplicitParam(name="page", value = "当前页", required = true, dataTypeClass = Integer.class),
  41. @ApiImplicitParam(name="count", value = "每页查询数量", required = true, dataTypeClass = Integer.class),
  42. @ApiImplicitParam(name="query", value = "查询内容", dataTypeClass = String.class),
  43. @ApiImplicitParam(name="online", value = "是否在线", dataTypeClass = Boolean.class),
  44. })
  45. @GetMapping(value = "/list")
  46. @ResponseBody
  47. public PageInfo<StreamProxyItem> list(@RequestParam(required = false)Integer page,
  48. @RequestParam(required = false)Integer count,
  49. @RequestParam(required = false)String query,
  50. @RequestParam(required = false)Boolean online ){
  51. return streamProxyService.getAll(page, count);
  52. }
  53. @ApiOperation("保存代理")
  54. @ApiImplicitParams({
  55. @ApiImplicitParam(name = "param", value = "代理参数", dataTypeClass = StreamProxyItem.class),
  56. })
  57. @PostMapping(value = "/save")
  58. @ResponseBody
  59. public WVPResult save(@RequestBody StreamProxyItem param){
  60. logger.info("添加代理: " + JSONObject.toJSONString(param));
  61. if (StringUtils.isEmpty(param.getMediaServerId())) {
  62. param.setMediaServerId("auto");
  63. }
  64. if (StringUtils.isEmpty(param.getType())) {
  65. param.setType("default");
  66. }
  67. if (StringUtils.isEmpty(param.getGbId())) {
  68. param.setGbId(null);
  69. }
  70. WVPResult<StreamInfo> result = streamProxyService.save(param);
  71. return result;
  72. }
  73. @ApiOperation("获取ffmpeg.cmd模板")
  74. @GetMapping(value = "/ffmpeg_cmd/list")
  75. @ApiImplicitParams({
  76. @ApiImplicitParam(name = "mediaServerId", value = "流媒体ID", dataTypeClass = String.class),
  77. })
  78. @ResponseBody
  79. public WVPResult getFFmpegCMDs(@RequestParam String mediaServerId){
  80. logger.debug("获取节点[ {} ]ffmpeg.cmd模板", mediaServerId );
  81. MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
  82. JSONObject data = streamProxyService.getFFmpegCMDs(mediaServerItem);
  83. WVPResult<JSONObject> result = new WVPResult<>();
  84. result.setCode(0);
  85. result.setMsg("success");
  86. result.setData(data);
  87. return result;
  88. }
  89. @ApiOperation("移除代理")
  90. @ApiImplicitParams({
  91. @ApiImplicitParam(name = "app", value = "应用名", required = true, dataTypeClass = String.class),
  92. @ApiImplicitParam(name = "stream", value = "流ID", required = true, dataTypeClass = String.class),
  93. })
  94. @DeleteMapping(value = "/del")
  95. @ResponseBody
  96. public WVPResult del(@RequestParam String app, @RequestParam String stream){
  97. logger.info("移除代理: " + app + "/" + stream);
  98. WVPResult<Object> result = new WVPResult<>();
  99. if (app == null || stream == null) {
  100. result.setCode(400);
  101. result.setMsg(app == null ?"app不能为null":"stream不能为null");
  102. }else {
  103. streamProxyService.del(app, stream);
  104. result.setCode(0);
  105. result.setMsg("success");
  106. }
  107. return result;
  108. }
  109. @ApiOperation("启用代理")
  110. @ApiImplicitParams({
  111. @ApiImplicitParam(name = "app", value = "应用名", dataTypeClass = String.class),
  112. @ApiImplicitParam(name = "stream", value = "流ID", dataTypeClass = String.class),
  113. })
  114. @GetMapping(value = "/start")
  115. @ResponseBody
  116. public Object start(String app, String stream){
  117. logger.info("启用代理: " + app + "/" + stream);
  118. boolean result = streamProxyService.start(app, stream);
  119. if (!result) {
  120. logger.info("启用代理失败: " + app + "/" + stream);
  121. }
  122. return result?"success":"fail";
  123. }
  124. @ApiOperation("停用代理")
  125. @ApiImplicitParams({
  126. @ApiImplicitParam(name = "app", value = "应用名", dataTypeClass = String.class),
  127. @ApiImplicitParam(name = "stream", value = "流ID", dataTypeClass = String.class),
  128. })
  129. @GetMapping(value = "/stop")
  130. @ResponseBody
  131. public Object stop(String app, String stream){
  132. logger.info("停用代理: " + app + "/" + stream);
  133. boolean result = streamProxyService.stop(app, stream);
  134. return result?"success":"fail";
  135. }
  136. }