| | |
| | | |
| | | import com.genersoft.iot.vmp.common.StreamInfo; |
| | | import com.genersoft.iot.vmp.conf.MediaServerConfig; |
| | | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult; |
| | | import com.genersoft.iot.vmp.vmanager.service.IPlayService; |
| | | import com.genersoft.iot.vmp.service.IMediaService; |
| | | import com.genersoft.iot.vmp.service.IPlayService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import java.util.UUID; |
| | | |
| | | import javax.sip.message.Response; |
| | | |
| | | @CrossOrigin |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | @RequestMapping("/api/play") |
| | | public class PlayController { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(PlayController.class); |
| | |
| | | @Autowired |
| | | private IPlayService playService; |
| | | |
| | | @GetMapping("/play/{deviceId}/{channelId}") |
| | | @Autowired |
| | | private IMediaService mediaService; |
| | | |
| | | @GetMapping("/start/{deviceId}/{channelId}") |
| | | public DeferredResult<ResponseEntity<String>> play(@PathVariable String deviceId, |
| | | @PathVariable String channelId) { |
| | | |
| | |
| | | return playResult.getResult(); |
| | | } |
| | | |
| | | @PostMapping("/play/{streamId}/stop") |
| | | @PostMapping("/stop/{streamId}") |
| | | public DeferredResult<ResponseEntity<String>> playStop(@PathVariable String streamId) { |
| | | |
| | | logger.debug(String.format("设备预览/回放停止API调用,streamId:%s", streamId)); |
| | |
| | | * @param streamId 流ID |
| | | * @return |
| | | */ |
| | | @PostMapping("/play/{streamId}/convert") |
| | | @PostMapping("/convert/{streamId}") |
| | | public ResponseEntity<String> playConvert(@PathVariable String streamId) { |
| | | StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); |
| | | if (streamInfo == null) { |
| | |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | if (data != null) { |
| | | result.put("key", data.getString("key")); |
| | | StreamInfo streamInfoResult = new StreamInfo(); |
| | | streamInfoResult.setRtmp(dstUrl); |
| | | streamInfoResult.setRtsp(String.format("rtsp://%s:%s/convert/%s", mediaInfo.getWanIp(), mediaInfo.getRtspPort(), streamId)); |
| | | streamInfoResult.setStreamId(streamId); |
| | | streamInfoResult.setFlv(String.format("http://%s:%s/convert/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId)); |
| | | streamInfoResult.setWs_flv(String.format("ws://%s:%s/convert/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId)); |
| | | streamInfoResult.setHls(String.format("http://%s:%s/convert/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId)); |
| | | streamInfoResult.setWs_hls(String.format("ws://%s:%s/convert/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId)); |
| | | streamInfoResult.setFmp4(String.format("http://%s:%s/convert/%s.live.mp4", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId)); |
| | | streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/convert/%s.live.mp4", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId)); |
| | | streamInfoResult.setTs(String.format("http://%s:%s/convert/%s.live.ts", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId)); |
| | | streamInfoResult.setWs_ts(String.format("ws://%s:%s/convert/%s.live.ts", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId)); |
| | | StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStream("convert", streamId); |
| | | result.put("data", streamInfoResult); |
| | | } |
| | | }else { |
| | |
| | | * @param key |
| | | * @return |
| | | */ |
| | | @PostMapping("/play/convert/stop/{key}") |
| | | @PostMapping("/convertStop/{key}") |
| | | public ResponseEntity<String> playConvertStop(@PathVariable String key) { |
| | | |
| | | JSONObject jsonObject = zlmresTfulUtils.delFFmpegSource(key); |
| | |
| | | } |
| | | return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK); |
| | | } |
| | | |
| | | /** |
| | | * 语音广播命令API接口 |
| | | * |
| | | * @param deviceId |
| | | */ |
| | | @GetMapping("/broadcast/{deviceId}") |
| | | @PostMapping("/broadcast/{deviceId}") |
| | | public DeferredResult<ResponseEntity<String>> broadcastApi(@PathVariable String deviceId) { |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("语音广播API调用"); |
| | | } |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | cmder.audioBroadcastCmd(device, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId); |
| | | JSONObject json = new JSONObject(); |
| | | json.put("DeviceID", deviceId); |
| | | json.put("CmdType", "Broadcast"); |
| | | json.put("Result", "Failed"); |
| | | json.put("Description", String.format("语音广播操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | msg.setData(json); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| | | result.onTimeout(() -> { |
| | | logger.warn(String.format("语音广播操作超时, 设备未返回应答指令")); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId); |
| | | JSONObject json = new JSONObject(); |
| | | json.put("DeviceID", deviceId); |
| | | json.put("CmdType", "Broadcast"); |
| | | json.put("Result", "Failed"); |
| | | json.put("Error", "Timeout. Device did not response to broadcast command."); |
| | | msg.setData(json); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | resultHolder.put(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId, result); |
| | | return result; |
| | | } |
| | | |
| | | } |
| | | |