StreamProxyController.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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())) param.setMediaServerId("auto");
  62. if (StringUtils.isEmpty(param.getType())) param.setType("default");
  63. if (StringUtils.isEmpty(param.getGbId())) param.setGbId(null);
  64. WVPResult<StreamInfo> result = streamProxyService.save(param);
  65. return result;
  66. }
  67. @ApiOperation("修改代理")
  68. @ApiImplicitParams({
  69. @ApiImplicitParam(name = "param", value = "代理参数", dataTypeClass = StreamProxyItem.class),
  70. })
  71. @PostMapping(value = "/update")
  72. @ResponseBody
  73. public WVPResult update(@RequestBody StreamProxyItem param){
  74. logger.info("修改代理: " + JSONObject.toJSONString(param));
  75. WVPResult<StreamInfo> result = new WVPResult<>();
  76. if(StringUtils.isEmpty(param.getApp())||StringUtils.isEmpty(param.getStream())){
  77. result.setCode(400);
  78. result.setMsg("app不能为null且stream不能为null,请检查具体参数!");
  79. return result;
  80. }
  81. streamProxyService.del(param.getApp(), param.getStream());
  82. if (StringUtils.isEmpty(param.getMediaServerId())) param.setMediaServerId("auto");
  83. if (StringUtils.isEmpty(param.getType())) param.setType("default");
  84. if (StringUtils.isEmpty(param.getGbId())) param.setGbId(null);
  85. param.setEnable(false);
  86. result = streamProxyService.save(param);
  87. return result;
  88. }
  89. @ApiOperation("获取ffmpeg.cmd模板")
  90. @GetMapping(value = "/ffmpeg_cmd/list")
  91. @ApiImplicitParams({
  92. @ApiImplicitParam(name = "mediaServerId", value = "流媒体ID", dataTypeClass = String.class),
  93. })
  94. @ResponseBody
  95. public WVPResult getFFmpegCMDs(@RequestParam String mediaServerId){
  96. logger.debug("获取节点[ {} ]ffmpeg.cmd模板", mediaServerId );
  97. MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
  98. JSONObject data = streamProxyService.getFFmpegCMDs(mediaServerItem);
  99. WVPResult<JSONObject> result = new WVPResult<>();
  100. result.setCode(0);
  101. result.setMsg("success");
  102. result.setData(data);
  103. return result;
  104. }
  105. @ApiOperation("移除代理")
  106. @ApiImplicitParams({
  107. @ApiImplicitParam(name = "app", value = "应用名", required = true, dataTypeClass = String.class),
  108. @ApiImplicitParam(name = "stream", value = "流ID", required = true, dataTypeClass = String.class),
  109. })
  110. @DeleteMapping(value = "/del")
  111. @ResponseBody
  112. public WVPResult del(@RequestParam String app, @RequestParam String stream){
  113. logger.info("移除代理: " + app + "/" + stream);
  114. WVPResult<Object> result = new WVPResult<>();
  115. if (app == null || stream == null) {
  116. result.setCode(400);
  117. result.setMsg(app == null ?"app不能为null":"stream不能为null");
  118. }else {
  119. streamProxyService.del(app, stream);
  120. result.setCode(0);
  121. result.setMsg("success");
  122. }
  123. return result;
  124. }
  125. @ApiOperation("启用代理")
  126. @ApiImplicitParams({
  127. @ApiImplicitParam(name = "app", value = "应用名", dataTypeClass = String.class),
  128. @ApiImplicitParam(name = "stream", value = "流ID", dataTypeClass = String.class),
  129. })
  130. @GetMapping(value = "/start")
  131. @ResponseBody
  132. public Object start(String app, String stream){
  133. logger.info("启用代理: " + app + "/" + stream);
  134. boolean result = streamProxyService.start(app, stream);
  135. return result?"success":"fail";
  136. }
  137. @ApiOperation("停用代理")
  138. @ApiImplicitParams({
  139. @ApiImplicitParam(name = "app", value = "应用名", dataTypeClass = String.class),
  140. @ApiImplicitParam(name = "stream", value = "流ID", dataTypeClass = String.class),
  141. })
  142. @GetMapping(value = "/stop")
  143. @ResponseBody
  144. public Object stop(String app, String stream){
  145. logger.info("停用代理: " + app + "/" + stream);
  146. boolean result = streamProxyService.stop(app, stream);
  147. return result?"success":"fail";
  148. }
  149. }