|
@@ -1,240 +0,0 @@
|
|
|
-package org.jetlinks.community.media.controller;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-import cn.hutool.core.lang.UUID;
|
|
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
|
|
-import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
-import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
-import org.hswebframework.web.authorization.annotation.Authorize;
|
|
|
|
|
-import org.hswebframework.web.authorization.annotation.QueryAction;
|
|
|
|
|
-import org.hswebframework.web.authorization.annotation.Resource;
|
|
|
|
|
-import org.hswebframework.web.exception.BusinessException;
|
|
|
|
|
-import org.jetlinks.community.media.bean.StreamInfo;
|
|
|
|
|
-import org.jetlinks.community.media.gb28181.result.PlayResult;
|
|
|
|
|
-import org.jetlinks.community.media.service.LocalMediaDeviceChannelService;
|
|
|
|
|
-import org.jetlinks.community.media.service.LocalMediaDeviceService;
|
|
|
|
|
-import org.jetlinks.community.media.service.LocalMediaServerItemService;
|
|
|
|
|
-import org.jetlinks.community.media.service.LocalPlayService;
|
|
|
|
|
-import org.jetlinks.community.media.storage.impl.RedisCacheStorageImpl;
|
|
|
|
|
-import org.jetlinks.community.media.transmit.callback.DeferredResultHolder;
|
|
|
|
|
-import org.jetlinks.community.media.transmit.callback.RequestMessage;
|
|
|
|
|
-import org.jetlinks.community.media.transmit.cmd.SipCommander;
|
|
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
-import org.springframework.web.context.request.async.DeferredResult;
|
|
|
|
|
-import reactor.core.publisher.Mono;
|
|
|
|
|
-import reactor.util.function.Tuple2;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-@RestController
|
|
|
|
|
-@RequestMapping("/media/play")
|
|
|
|
|
-@Slf4j
|
|
|
|
|
-@Authorize(ignore = true)
|
|
|
|
|
-@Resource(id="gb28181-play",name = "国标设备点播")
|
|
|
|
|
-@AllArgsConstructor
|
|
|
|
|
-@Tag(name = "GB媒体设备操作")
|
|
|
|
|
-public class PlayController{
|
|
|
|
|
-
|
|
|
|
|
- private final SipCommander cmder;
|
|
|
|
|
-
|
|
|
|
|
- private final RedisCacheStorageImpl redisCacheStorage;
|
|
|
|
|
-
|
|
|
|
|
- private final LocalMediaDeviceChannelService deviceChannelService;
|
|
|
|
|
-
|
|
|
|
|
- private final LocalMediaDeviceService mediaDeviceService;
|
|
|
|
|
-
|
|
|
|
|
- private final LocalPlayService playService;
|
|
|
|
|
-
|
|
|
|
|
- private final DeferredResultHolder resultHolder;
|
|
|
|
|
-
|
|
|
|
|
- private final LocalMediaServerItemService mediaServerItemService;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-//
|
|
|
|
|
-// /**
|
|
|
|
|
-// * 将不是h264的视频通过ffmpeg 转码为h264 + aac
|
|
|
|
|
-// * @param streamId 流ID
|
|
|
|
|
-// * @return
|
|
|
|
|
-// */
|
|
|
|
|
-// @ApiOperation("将不是h264的视频通过ffmpeg 转码为h264 + aac")
|
|
|
|
|
-// @ApiImplicitParams({
|
|
|
|
|
-// @ApiImplicitParam(name = "streamId", value = "视频流ID", dataTypeClass = String.class),
|
|
|
|
|
-// })
|
|
|
|
|
-// @PostMapping("/convert/{streamId}")
|
|
|
|
|
-// public ResponseEntity<String> playConvert(@PathVariable String streamId) {
|
|
|
|
|
-// StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
|
|
|
|
|
-// if (streamInfo == null) {
|
|
|
|
|
-// streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
|
|
|
|
|
-// }
|
|
|
|
|
-// if (streamInfo == null) {
|
|
|
|
|
-// logger.warn("视频转码API调用失败!, 视频流已经停止!");
|
|
|
|
|
-// return new ResponseEntity<String>("未找到视频流信息, 视频流可能已经停止", HttpStatus.OK);
|
|
|
|
|
-// }
|
|
|
|
|
-// MediaServerItem mediaInfo = mediaServerService.getOneByServerId(streamInfo.getMediaServerId());
|
|
|
|
|
-// JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
|
|
|
|
|
-// if (!rtpInfo.getBoolean("exist")) {
|
|
|
|
|
-// logger.warn("视频转码API调用失败!, 视频流已停止推流!");
|
|
|
|
|
-// return new ResponseEntity<String>("推流信息在流媒体中不存在, 视频流可能已停止推流", HttpStatus.OK);
|
|
|
|
|
-// } else {
|
|
|
|
|
-// String dstUrl = String.format("rtmp://%s:%s/convert/%s", "127.0.0.1", mediaInfo.getRtmpPort(),
|
|
|
|
|
-// streamId );
|
|
|
|
|
-// String srcUrl = String.format("rtsp://%s:%s/rtp/%s", "127.0.0.1", mediaInfo.getRtspPort(), streamId);
|
|
|
|
|
-// JSONObject jsonObject = zlmresTfulUtils.addFFmpegSource(mediaInfo, srcUrl, dstUrl, "1000000", true, false, null);
|
|
|
|
|
-// logger.info(jsonObject.toJSONString());
|
|
|
|
|
-// JSONObject result = new JSONObject();
|
|
|
|
|
-// if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
|
|
|
|
-// result.put("code", 0);
|
|
|
|
|
-// JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
-// if (data != null) {
|
|
|
|
|
-// result.put("key", data.getString("key"));
|
|
|
|
|
-// StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStreamWithCheck("convert", streamId, mediaInfo.getId());
|
|
|
|
|
-// result.put("data", streamInfoResult);
|
|
|
|
|
-// }
|
|
|
|
|
-// }else {
|
|
|
|
|
-// result.put("code", 1);
|
|
|
|
|
-// result.put("msg", "cover fail");
|
|
|
|
|
-// }
|
|
|
|
|
-// return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
|
|
|
|
|
-// }
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// /**
|
|
|
|
|
-// * 结束转码
|
|
|
|
|
-// * @param key
|
|
|
|
|
-// * @return
|
|
|
|
|
-// */
|
|
|
|
|
-// @ApiOperation("结束转码")
|
|
|
|
|
-// @ApiImplicitParams({
|
|
|
|
|
-// @ApiImplicitParam(name = "key", value = "视频流key", dataTypeClass = String.class),
|
|
|
|
|
-// })
|
|
|
|
|
-// @PostMapping("/convertStop/{key}")
|
|
|
|
|
-// public ResponseEntity<String> playConvertStop(@PathVariable String key, String mediaServerId) {
|
|
|
|
|
-// JSONObject result = new JSONObject();
|
|
|
|
|
-// if (mediaServerId == null) {
|
|
|
|
|
-// result.put("code", 400);
|
|
|
|
|
-// result.put("msg", "mediaServerId is null");
|
|
|
|
|
-// return new ResponseEntity<String>( result.toJSONString(), HttpStatus.BAD_REQUEST);
|
|
|
|
|
-// }
|
|
|
|
|
-// MediaServerItem mediaInfo = mediaServerService.getOneByServerId(mediaServerId);
|
|
|
|
|
-// if (mediaInfo == null) {
|
|
|
|
|
-// result.put("code", 0);
|
|
|
|
|
-// result.put("msg", "使用的流媒体已经停止运行");
|
|
|
|
|
-// return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
|
|
|
|
|
-// }else {
|
|
|
|
|
-// JSONObject jsonObject = zlmresTfulUtils.delFFmpegSource(mediaInfo, key);
|
|
|
|
|
-// logger.info(jsonObject.toJSONString());
|
|
|
|
|
-// if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
|
|
|
|
-// result.put("code", 0);
|
|
|
|
|
-// JSONObject data = jsonObject.getJSONObject("data");
|
|
|
|
|
-// if (data != null && data.getBoolean("flag")) {
|
|
|
|
|
-// result.put("code", "0");
|
|
|
|
|
-// result.put("msg", "success");
|
|
|
|
|
-// }else {
|
|
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
-// }else {
|
|
|
|
|
-// result.put("code", 1);
|
|
|
|
|
-// result.put("msg", "delFFmpegSource fail");
|
|
|
|
|
-// }
|
|
|
|
|
-// return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// @ApiOperation("语音广播命令")
|
|
|
|
|
-// @ApiImplicitParams({
|
|
|
|
|
-// @ApiImplicitParam(name = "deviceId", value = "设备Id", dataTypeClass = String.class),
|
|
|
|
|
-// })
|
|
|
|
|
-// @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);
|
|
|
|
|
-// DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
|
|
|
|
|
-// String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
|
|
|
|
|
-// if (resultHolder.exist(key, null)) {
|
|
|
|
|
-// result.setResult(new ResponseEntity<>("设备使用中", HttpStatus.OK));
|
|
|
|
|
-// return result;
|
|
|
|
|
-// }
|
|
|
|
|
-// String uuid = UUID.randomUUID().toString();
|
|
|
|
|
-// if (device == null) {
|
|
|
|
|
-//
|
|
|
|
|
-// resultHolder.put(key, key, result);
|
|
|
|
|
-// RequestMessage msg = new RequestMessage();
|
|
|
|
|
-// msg.setKey(key);
|
|
|
|
|
-// msg.setId(uuid);
|
|
|
|
|
-// JSONObject json = new JSONObject();
|
|
|
|
|
-// json.put("DeviceID", deviceId);
|
|
|
|
|
-// json.put("CmdType", "Broadcast");
|
|
|
|
|
-// json.put("Result", "Failed");
|
|
|
|
|
-// json.put("Description", "Device 不存在");
|
|
|
|
|
-// msg.setData(json);
|
|
|
|
|
-// resultHolder.invokeResult(msg);
|
|
|
|
|
-// return result;
|
|
|
|
|
-// }
|
|
|
|
|
-// cmder.audioBroadcastCmd(device, (event) -> {
|
|
|
|
|
-// RequestMessage msg = new RequestMessage();
|
|
|
|
|
-// msg.setKey(key);
|
|
|
|
|
-// msg.setId(uuid);
|
|
|
|
|
-// JSONObject json = new JSONObject();
|
|
|
|
|
-// json.put("DeviceID", deviceId);
|
|
|
|
|
-// json.put("CmdType", "Broadcast");
|
|
|
|
|
-// json.put("Result", "Failed");
|
|
|
|
|
-// json.put("Description", String.format("语音广播操作失败,错误码: %s, %s", event.statusCode, event.msg));
|
|
|
|
|
-// msg.setData(json);
|
|
|
|
|
-// resultHolder.invokeResult(msg);
|
|
|
|
|
-// });
|
|
|
|
|
-//
|
|
|
|
|
-// result.onTimeout(() -> {
|
|
|
|
|
-// logger.warn(String.format("语音广播操作超时, 设备未返回应答指令"));
|
|
|
|
|
-// RequestMessage msg = new RequestMessage();
|
|
|
|
|
-// msg.setKey(key);
|
|
|
|
|
-// msg.setId(uuid);
|
|
|
|
|
-// 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(key, uuid, result);
|
|
|
|
|
-// return result;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// @ApiOperation("获取所有的ssrc")
|
|
|
|
|
-// @GetMapping("/ssrc")
|
|
|
|
|
-// public WVPResult<JSONObject> getSSRC() {
|
|
|
|
|
-// if (logger.isDebugEnabled()) {
|
|
|
|
|
-// logger.debug("获取所有的ssrc");
|
|
|
|
|
-// }
|
|
|
|
|
-// JSONArray objects = new JSONArray();
|
|
|
|
|
-// List<SsrcTransaction> allSsrc = streamSession.getAllSsrc();
|
|
|
|
|
-// for (SsrcTransaction transaction : allSsrc) {
|
|
|
|
|
-// JSONObject jsonObject = new JSONObject();
|
|
|
|
|
-// jsonObject.put("deviceId", transaction.getDeviceId());
|
|
|
|
|
-// jsonObject.put("channelId", transaction.getChannelId());
|
|
|
|
|
-// jsonObject.put("ssrc", transaction.getSsrc());
|
|
|
|
|
-// jsonObject.put("streamId", transaction.getStreamId());
|
|
|
|
|
-// objects.add(jsonObject);
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// WVPResult<JSONObject> result = new WVPResult<>();
|
|
|
|
|
-// result.setCode(0);
|
|
|
|
|
-// result.setMsg("success");
|
|
|
|
|
-// JSONObject jsonObject = new JSONObject();
|
|
|
|
|
-// jsonObject.put("data", objects);
|
|
|
|
|
-// jsonObject.put("count", objects.size());
|
|
|
|
|
-// result.setData(jsonObject);
|
|
|
|
|
-// return result;
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|