PlaybackController.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package com.genersoft.iot.vmp.vmanager.playback;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.http.HttpStatus;
  6. import org.springframework.http.ResponseEntity;
  7. import org.springframework.util.StringUtils;
  8. import org.springframework.web.bind.annotation.CrossOrigin;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import com.alibaba.fastjson.JSONObject;
  15. import com.genersoft.iot.vmp.gb28181.bean.Device;
  16. import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
  17. import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
  18. @CrossOrigin
  19. @RestController
  20. @RequestMapping("/api")
  21. public class PlaybackController {
  22. private final static Logger logger = LoggerFactory.getLogger(PlaybackController.class);
  23. @Autowired
  24. private SIPCommander cmder;
  25. @Autowired
  26. private IVideoManagerStorager storager;
  27. @GetMapping("/playback/{deviceId}/{channelId}")
  28. public ResponseEntity<String> play(@PathVariable String deviceId,@PathVariable String channelId, String startTime, String endTime){
  29. if (logger.isDebugEnabled()) {
  30. logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s",deviceId, channelId));
  31. }
  32. if (StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(channelId)) {
  33. String log = String.format("设备回放 API调用失败,deviceId:%s ,channelId:%s",deviceId, channelId);
  34. logger.warn(log);
  35. return new ResponseEntity<String>(log,HttpStatus.BAD_REQUEST);
  36. }
  37. Device device = storager.queryVideoDevice(deviceId);
  38. String ssrc = cmder.playbackStreamCmd(device, channelId, startTime, endTime);
  39. if (logger.isDebugEnabled()) {
  40. logger.debug("设备回放 API调用,ssrc:"+ssrc+",ZLMedia streamId:"+Integer.toHexString(Integer.parseInt(ssrc)));
  41. }
  42. if(ssrc!=null) {
  43. JSONObject json = new JSONObject();
  44. json.put("ssrc", ssrc);
  45. return new ResponseEntity<String>(json.toString(),HttpStatus.OK);
  46. } else {
  47. logger.warn("设备回放API调用失败!");
  48. return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
  49. }
  50. }
  51. @PostMapping("/playback/{ssrc}/stop")
  52. public ResponseEntity<String> playStop(@PathVariable String ssrc){
  53. cmder.streamByeCmd(ssrc);
  54. if (logger.isDebugEnabled()) {
  55. logger.debug(String.format("设备录像回放停止 API调用,ssrc:%s", ssrc));
  56. }
  57. if(ssrc!=null) {
  58. JSONObject json = new JSONObject();
  59. json.put("ssrc", ssrc);
  60. return new ResponseEntity<String>(json.toString(),HttpStatus.OK);
  61. } else {
  62. logger.warn("设备录像回放停止API调用失败!");
  63. return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
  64. }
  65. }
  66. }