|
|
@@ -1,81 +1,57 @@
|
|
|
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.apache.lucene.search.BooleanClause;
|
|
|
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.gb28181.result.WVPResult;
|
|
|
+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.core.event.EventBus;
|
|
|
-import org.jetlinks.core.event.Subscription;
|
|
|
-import org.jetlinks.core.event.TopicPayload;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
+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.EmitterProcessor;
|
|
|
-import reactor.core.publisher.Flux;
|
|
|
-import reactor.core.publisher.FluxSink;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
-
|
|
|
-import java.time.Duration;
|
|
|
-import java.util.Arrays;
|
|
|
+import reactor.util.function.Tuple2;
|
|
|
import java.util.concurrent.*;
|
|
|
-import java.util.function.Consumer;
|
|
|
-import java.util.function.Function;
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
-@RequestMapping("/device/directives")
|
|
|
+@RequestMapping("/media/play")
|
|
|
@Slf4j
|
|
|
@Authorize(ignore = true)
|
|
|
@Resource(id="gb28181-play",name = "国标设备点播")
|
|
|
@AllArgsConstructor
|
|
|
-@Tag(name = "设备下发指令")
|
|
|
+@Tag(name = "GB媒体设备操作")
|
|
|
public class PlayController {
|
|
|
- //
|
|
|
-// private final static Logger logger = LoggerFactory.getLogger(com.genersoft.iot.vmp.vmanager.gb28181.play.PlayController.class);
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private SIPCommander cmder;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private VideoStreamSessionManager streamSession;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private IVideoManagerStorager storager;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private IRedisCatchStorage redisCatchStorage;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private ZLMRESTfulUtils zlmresTfulUtils;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private DeferredResultHolder resultHolder;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private IPlayService playService;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private IMediaService mediaService;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private IMediaServerService mediaServerService;
|
|
|
-//
|
|
|
+
|
|
|
+ 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;
|
|
|
@QueryAction
|
|
|
@Operation(summary = "设备点播")
|
|
|
@GetMapping("/start/{deviceId}/{channelId}")
|
|
|
@@ -92,75 +68,77 @@ public class PlayController {
|
|
|
.flatMap(this::deferredResultHandler);
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
-// @ApiOperation("停止点播")
|
|
|
-// @ApiImplicitParams({
|
|
|
-// @ApiImplicitParam(name = "deviceId", value = "设备ID", dataTypeClass = String.class),
|
|
|
-// @ApiImplicitParam(name = "channelId", value = "通道ID", dataTypeClass = String.class),
|
|
|
-// })
|
|
|
-// @GetMapping("/stop/{deviceId}/{channelId}")
|
|
|
-// public DeferredResult<ResponseEntity<String>> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
|
|
|
-//
|
|
|
-// logger.debug(String.format("设备预览/回放停止API调用,streamId:%s_%s", deviceId, channelId ));
|
|
|
-//
|
|
|
-// String uuid = UUID.randomUUID().toString();
|
|
|
-// DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>();
|
|
|
-//
|
|
|
-// // 录像查询以channelId作为deviceId查询
|
|
|
-// String key = DeferredResultHolder.CALLBACK_CMD_STOP + deviceId + channelId;
|
|
|
-// resultHolder.put(key, uuid, result);
|
|
|
-// Device device = storager.queryVideoDevice(deviceId);
|
|
|
-// cmder.streamByeCmd(deviceId, channelId, (event) -> {
|
|
|
-// StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
|
|
|
-// if (streamInfo == null) {
|
|
|
-// RequestMessage msg = new RequestMessage();
|
|
|
-// msg.setId(uuid);
|
|
|
-// msg.setKey(key);
|
|
|
-// msg.setData("点播未找到");
|
|
|
-// resultHolder.invokeAllResult(msg);
|
|
|
-// storager.stopPlay(deviceId, channelId);
|
|
|
-// }else {
|
|
|
-// redisCatchStorage.stopPlay(streamInfo);
|
|
|
-// storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
|
|
-// RequestMessage msg = new RequestMessage();
|
|
|
-// msg.setId(uuid);
|
|
|
-// msg.setKey(key);
|
|
|
-// //Response response = event.getResponse();
|
|
|
-// msg.setData(String.format("success"));
|
|
|
-// resultHolder.invokeAllResult(msg);
|
|
|
-// }
|
|
|
-// mediaServerService.closeRTPServer(device, channelId);
|
|
|
-// });
|
|
|
-//
|
|
|
-// if (deviceId != null || channelId != null) {
|
|
|
-// JSONObject json = new JSONObject();
|
|
|
-// json.put("deviceId", deviceId);
|
|
|
-// json.put("channelId", channelId);
|
|
|
-// RequestMessage msg = new RequestMessage();
|
|
|
-// msg.setId(uuid);
|
|
|
-// msg.setKey(key);
|
|
|
-// msg.setData(json.toString());
|
|
|
-// resultHolder.invokeAllResult(msg);
|
|
|
-// } else {
|
|
|
-// logger.warn("设备预览/回放停止API调用失败!");
|
|
|
-// RequestMessage msg = new RequestMessage();
|
|
|
-// msg.setId(uuid);
|
|
|
-// msg.setKey(key);
|
|
|
-// msg.setData("streamId null");
|
|
|
-// resultHolder.invokeAllResult(msg);
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 超时处理
|
|
|
-// result.onTimeout(()->{
|
|
|
-// logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId));
|
|
|
-// RequestMessage msg = new RequestMessage();
|
|
|
-// msg.setId(uuid);
|
|
|
-// msg.setKey(key);
|
|
|
-// msg.setData("Timeout");
|
|
|
-// resultHolder.invokeAllResult(msg);
|
|
|
-// });
|
|
|
-// return result;
|
|
|
-// }
|
|
|
+
|
|
|
+ @QueryAction
|
|
|
+ @Operation(summary = "停止点播")
|
|
|
+ @GetMapping("/stop/{deviceId}/{channelId}")
|
|
|
+ public Mono<Object> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
|
|
|
+ if(log.isDebugEnabled()){
|
|
|
+ log.debug(String.format("设备预览/回放停止API调用,streamId:%s_%s", deviceId, channelId ));
|
|
|
+ }
|
|
|
+
|
|
|
+ String uuid = UUID.randomUUID().toString();
|
|
|
+ DeferredResult<ResponseEntity<String>> result = new DeferredResult<>();
|
|
|
+ // 录像查询以channelId作为deviceId查询
|
|
|
+ String key = DeferredResultHolder.CALLBACK_CMD_STOP + deviceId + channelId;
|
|
|
+ resultHolder.put(key, uuid, result);
|
|
|
+ PlayResult playResult = new PlayResult();
|
|
|
+ playResult.setResult(result);
|
|
|
+ // 超时处理
|
|
|
+ playResult.onTimeout(Mono.fromRunnable(()->{
|
|
|
+ log.warn(String.format("设备预览/回放停止响应超时,deviceId/channelId:%s_%s ", deviceId, channelId));
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ msg.setId(uuid);
|
|
|
+ msg.setKey(key);
|
|
|
+ msg.setData("设备预览/回放停止响应超时");
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ }));
|
|
|
+
|
|
|
+ return Mono.justOrEmpty(redisCacheStorage.getDevice(deviceId))
|
|
|
+ .flatMap(device->
|
|
|
+ Mono.zip(cmder.streamByeCmd(deviceId, channelId, (event) -> {
|
|
|
+ StreamInfo streamInfo = redisCacheStorage.queryPlayByDevice(deviceId, channelId);
|
|
|
+ if (streamInfo == null) {
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ msg.setId(uuid);
|
|
|
+ msg.setKey(key);
|
|
|
+ msg.setData("点播未找到");
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ deviceChannelService.stopPlay(deviceId, channelId).subscribe();
|
|
|
+ }else {
|
|
|
+ redisCacheStorage.stopPlay(streamInfo);
|
|
|
+ deviceChannelService.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()).subscribe();
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ msg.setId(uuid);
|
|
|
+ msg.setKey(key);
|
|
|
+ msg.setData("success");
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ }
|
|
|
+ mediaServerItemService.closeRTPServer(device, channelId);
|
|
|
+ })
|
|
|
+ .mergeWith(Mono.fromRunnable(()->{
|
|
|
+ if (deviceId != null || channelId != null) {
|
|
|
+ JSONObject json = new JSONObject()
|
|
|
+ .putOpt("deviceId", deviceId)
|
|
|
+ .putOpt("channelId", channelId);
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ msg.setId(uuid);
|
|
|
+ msg.setKey(key);
|
|
|
+ msg.setData(json.toString());
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ } else {
|
|
|
+ log.warn("设备预览/回放停止API调用失败!");
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ msg.setId(uuid);
|
|
|
+ msg.setKey(key);
|
|
|
+ msg.setData("streamId null");
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ .then(),Mono.just(deferredResultHandler(playResult)))
|
|
|
+ )
|
|
|
+ .flatMap(Tuple2::getT2);
|
|
|
+ }
|
|
|
//
|
|
|
// /**
|
|
|
// * 将不是h264的视频通过ffmpeg 转码为h264 + aac
|