|
|
@@ -4,13 +4,18 @@ import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import gov.nist.javax.sip.stack.SIPDialog;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.hswebframework.web.exception.BusinessException;
|
|
|
import org.jetlinks.community.media.bean.SSRCInfo;
|
|
|
import org.jetlinks.community.media.bean.StreamInfo;
|
|
|
+import org.jetlinks.community.media.config.UserSetup;
|
|
|
import org.jetlinks.community.media.entity.MediaDevice;
|
|
|
+import org.jetlinks.community.media.entity.MediaDeviceChannel;
|
|
|
+import org.jetlinks.community.media.gb28181.event.SipSubscribe;
|
|
|
import org.jetlinks.community.media.gb28181.result.WVPResult;
|
|
|
import org.jetlinks.community.media.session.VideoStreamSessionManager;
|
|
|
import org.jetlinks.community.media.storage.impl.RedisCacheStorageImpl;
|
|
|
@@ -24,6 +29,7 @@ import org.jetlinks.community.media.zlm.entity.MediaServerItem;
|
|
|
import org.jetlinks.core.cluster.ClusterEventBus;
|
|
|
import org.jetlinks.core.event.EventBus;
|
|
|
import org.jetlinks.core.event.Subscription;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -59,179 +65,217 @@ public class LocalPlayService {
|
|
|
|
|
|
private final ClusterEventBus clusterEventBus;
|
|
|
|
|
|
- private final VideoStreamSessionManager streamSession;
|
|
|
+ private final DeferredResultHolder resultHolder;
|
|
|
+
|
|
|
+ private final VideoStreamSessionManager streamSessionManager;
|
|
|
|
|
|
private final LocalMediaDeviceChannelService deviceChannelService;
|
|
|
|
|
|
private final ZLMRESTfulUtils zlmresTfulUtils;
|
|
|
|
|
|
- public Mono<WVPResult> play(MediaServerItem mediaServerItem, String deviceId, String channelId,
|
|
|
- ZLMHttpHookSubscribe.Event hookEvent, ZLMHttpHookSubscribe.Event errorEvent) throws InterruptedException {
|
|
|
+ private final UserSetup userSetup;
|
|
|
+ public Mono<PlayResult> play(MediaServerItem mediaServerItem, String deviceId, String channelId,
|
|
|
+ ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent) {
|
|
|
//todo
|
|
|
- mediaServerItem.setRtpEnable(false);
|
|
|
- mediaServerItem.setRtpProxyPort(10000);
|
|
|
PlayResult playResult = new PlayResult();
|
|
|
- LinkedBlockingDeque<WVPResult> result = new LinkedBlockingDeque<>();
|
|
|
- String msgId=UUID.randomUUID().toString();
|
|
|
-
|
|
|
- RequestMessage msg = RequestMessage.of(deviceId,channelId,msgId,null);
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
|
|
|
+ msg.setKey(key);
|
|
|
+ String uuid = java.util.UUID.randomUUID().toString();
|
|
|
+ msg.setId(uuid);
|
|
|
+ playResult.setUuid(uuid);
|
|
|
+ DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(userSetup.getPlayTimeout());
|
|
|
+ playResult.setResult(result);
|
|
|
+ if (mediaServerItem == null) {
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ wvpResult.setCode(-1);
|
|
|
+ wvpResult.setMsg("未找到可用的zlm");
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeResult(msg);
|
|
|
+ return Mono.just(playResult);
|
|
|
+ }
|
|
|
|
|
|
+ MediaDevice device = redisCatchStorage.getDevice(deviceId);
|
|
|
+ StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
|
|
|
+ playResult.setDevice(device);
|
|
|
+ // 超时处理
|
|
|
+ result.onTimeout(()->{
|
|
|
+ log.warn(String.format("设备点播超时,deviceId:%s ,channelId:%s", deviceId, channelId));
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ wvpResult.setCode(-1);
|
|
|
+ SIPDialog dialog = streamSessionManager.getDialog(deviceId, channelId);
|
|
|
+ if (dialog != null) {
|
|
|
+ wvpResult.setMsg("收流超时,请稍候重试");
|
|
|
+ }else {
|
|
|
+ wvpResult.setMsg("点播超时,请稍候重试");
|
|
|
+ }
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ // 点播超时回复BYE
|
|
|
+ cmder.streamByeCmd(device.getId(), channelId)
|
|
|
+ .doOnNext(ignore->
|
|
|
+ // 释放rtpserver
|
|
|
+ mediaServerItemService.closeRTPServer(playResult.getDevice(), channelId))
|
|
|
+ .doOnNext(ignore->
|
|
|
+ // 回复之前所有的点播请求
|
|
|
+ resultHolder.invokeAllResult(msg))
|
|
|
+ .subscribe();
|
|
|
+ });
|
|
|
+ result.onCompletion(()->{
|
|
|
+ // 点播结束时调用截图接口
|
|
|
+ String fileName = deviceId + "_" + channelId + ".jpg";
|
|
|
+ ResponseEntity responseEntity = (ResponseEntity)result.getResult();
|
|
|
+ if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ WVPResult wvpResult = (WVPResult)responseEntity.getBody();
|
|
|
+ if (Objects.requireNonNull(wvpResult).getCode() == 0) {
|
|
|
+ StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData();
|
|
|
+ mediaServerItemService.findById(streamInfoForSuccess.getMediaServerId())
|
|
|
+ .doOnNext(mediaInfo->{
|
|
|
+ String classPath = null;
|
|
|
+ try {
|
|
|
+ classPath = ResourceUtils.getURL("classpath:").getPath();
|
|
|
+ // 兼容打包为jar的class路径
|
|
|
+ if(classPath.contains("jar")) {
|
|
|
+ classPath = classPath.substring(0, classPath.lastIndexOf("."));
|
|
|
+ classPath = classPath.substring(0, classPath.lastIndexOf("/") + 1);
|
|
|
+ }
|
|
|
+ if (classPath.startsWith("file:")) {
|
|
|
+ classPath = classPath.substring(classPath.indexOf(":") + 1);
|
|
|
+ }
|
|
|
+ String path = classPath + "static/static/snap/";
|
|
|
+ // 兼容Windows系统路径(去除前面的“/”)
|
|
|
+ if(System.getProperty("os.name").contains("indows")) {
|
|
|
+ path = path.substring(1);
|
|
|
+ }
|
|
|
+ String streamUrl = streamInfoForSuccess.getFlv();
|
|
|
+ // 请求截图
|
|
|
+ log.info("[请求截图]: " + fileName);
|
|
|
+ zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ log.error("存放截图文件路径不存在,",e);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .subscribe();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (streamInfo == null) {
|
|
|
+ SSRCInfo ssrcInfo;
|
|
|
+ String streamId = null;
|
|
|
+ if (mediaServerItem.isRtpEnable()) {
|
|
|
+ streamId = String.format("%s_%s", device.getId(), channelId);
|
|
|
+ }
|
|
|
|
|
|
- Disposable subscribe = eventBus.subscribe(
|
|
|
- Subscription.of("media_play", DeferredResultHolder.getCmdCallBackTopic(DeferredResultHolder.CALLBACK_CMD_PLAY, msg), Subscription.Feature.local))
|
|
|
- .mergeWith(Mono.justOrEmpty(redisCatchStorage.queryPlayByDevice(deviceId, channelId))
|
|
|
- .flatMap(streamInfo -> {
|
|
|
- if (StrUtil.isEmpty(streamInfo.getStreamId())) {
|
|
|
- return Mono.error(new BusinessException("点播失败, redis缓存streamId等于null"));
|
|
|
- }
|
|
|
- String mediaServerId = streamInfo.getMediaServerId();
|
|
|
- MediaServerItem mediaInfo = mediaServerItemService.getOneByServerId(mediaServerId);
|
|
|
+ ssrcInfo = mediaServerItemService.openRTPServer(mediaServerItem, streamId);
|
|
|
|
|
|
- JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamInfo.getStreamId());
|
|
|
+ // 发送点播消息
|
|
|
+ return cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInUse,JSONObject response) -> {
|
|
|
+ log.info("收到订阅消息: " + response.toString());
|
|
|
+ onPublishHandlerForPlay(mediaServerItemInUse, response, deviceId, channelId, uuid).subscribe();
|
|
|
+ if (hookEvent != null) {
|
|
|
+ hookEvent.accept(mediaServerItem, response);
|
|
|
+ }
|
|
|
+ }, (event) -> {
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ wvpResult.setCode(-1);
|
|
|
+ // 点播返回sip错误
|
|
|
+ mediaServerItemService.closeRTPServer(playResult.getDevice(), channelId);
|
|
|
+ wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg));
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ if (errorEvent != null) {
|
|
|
+ errorEvent.accept(event);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .thenReturn(playResult);
|
|
|
+ } else {
|
|
|
+ String streamId = streamInfo.getStreamId();
|
|
|
+ if (streamId == null) {
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ wvpResult.setCode(-1);
|
|
|
+ wvpResult.setMsg("点播失败, redis缓存streamId等于null");
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ return Mono.just(playResult);
|
|
|
+ }
|
|
|
+ return mediaServerItemService.findById(streamInfo.getMediaServerId())
|
|
|
+ .flatMap(mediaInfo->{
|
|
|
+ JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
|
|
|
if (rtpInfo != null && rtpInfo.getBool("exist")) {
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ wvpResult.setCode(0);
|
|
|
+ wvpResult.setMsg("success");
|
|
|
+ wvpResult.setData(streamInfo);
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
if (hookEvent != null) {
|
|
|
- //todo
|
|
|
-// hookEvent.response(mediaServerItem, com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(streamInfo)));
|
|
|
+ try {
|
|
|
+ hookEvent.accept(mediaServerItem, JSONUtil.parseObj(JSON.toJSONString(streamInfo)));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("点播回调函数失败,",e);
|
|
|
+ }
|
|
|
}
|
|
|
- clusterEventBus.publish(DeferredResultHolder.getCmdCallBackTopic(DeferredResultHolder.CALLBACK_CMD_PLAY, msg),
|
|
|
- streamInfo);
|
|
|
} else {
|
|
|
// TODO 点播前是否重置状态
|
|
|
redisCatchStorage.stopPlay(streamInfo);
|
|
|
- return deviceChannelService.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId())
|
|
|
- .flatMap(ignore -> {
|
|
|
- SSRCInfo ssrcInfo;
|
|
|
- String streamId2 = null;
|
|
|
- if (mediaServerItem.isRtpEnable()) {
|
|
|
- streamId2 = String.format("%s_%s", deviceId, channelId);
|
|
|
- }
|
|
|
- ssrcInfo = mediaServerItemService.openRTPServer(mediaServerItem, streamId2);
|
|
|
-
|
|
|
- return cmder.playStreamCmd(mediaServerItem, ssrcInfo, redisCatchStorage.getDevice(deviceId), channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> {
|
|
|
- log.info("收到订阅消息: " + response.toString());
|
|
|
- onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, msgId)
|
|
|
- .subscribe();
|
|
|
- }, (event) -> {
|
|
|
- mediaServerItemService.closeRTPServer(playResult.getDevice(), channelId);
|
|
|
- WVPResult wvpResult = WVPResult.of(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg), null);
|
|
|
- clusterEventBus.publish(DeferredResultHolder.getCmdCallBackTopic(DeferredResultHolder.CALLBACK_CMD_PLAY, msg),
|
|
|
- wvpResult);
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- return Mono.empty();
|
|
|
- })
|
|
|
- .switchIfEmpty(Mono.just(mediaServerItem)
|
|
|
- .flatMap(serverItem -> {
|
|
|
+ deviceChannelService.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
|
|
SSRCInfo ssrcInfo;
|
|
|
- String streamId = null;
|
|
|
- if (serverItem.isRtpEnable()) {
|
|
|
- streamId = String.format("%s_%s", deviceId, channelId);
|
|
|
+ String streamId2 = null;
|
|
|
+ if (mediaServerItem.isRtpEnable()) {
|
|
|
+ streamId2 = String.format("%s_%s", device.getId(), channelId);
|
|
|
}
|
|
|
+ ssrcInfo = mediaServerItemService.openRTPServer(mediaServerItem, streamId2);
|
|
|
|
|
|
- ssrcInfo = mediaServerItemService.openRTPServer(serverItem, streamId);
|
|
|
-
|
|
|
- // 发送点播消息
|
|
|
- MediaDevice device = redisCatchStorage.getDevice(deviceId);
|
|
|
- return cmder.playStreamCmd(serverItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInUse, JSONObject response) -> {
|
|
|
+ return cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> {
|
|
|
log.info("收到订阅消息: " + response.toString());
|
|
|
- onPublishHandlerForPlay(mediaServerItemInUse, response, deviceId, channelId, msgId).subscribe();
|
|
|
- if (hookEvent != null) {
|
|
|
-// hookEvent.response(mediaServerItem, response);
|
|
|
- }
|
|
|
+ onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid).subscribe();
|
|
|
}, (event) -> {
|
|
|
- WVPResult wvpResult = WVPResult.of(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg), null);
|
|
|
- // 点播返回sip错误
|
|
|
mediaServerItemService.closeRTPServer(playResult.getDevice(), channelId);
|
|
|
- clusterEventBus.publish(DeferredResultHolder.getCmdCallBackTopic(DeferredResultHolder.CALLBACK_CMD_PLAY, msg),
|
|
|
- wvpResult);
|
|
|
- if (errorEvent != null) {
|
|
|
- //todo
|
|
|
-// errorEvent.response(event);
|
|
|
- }
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ wvpResult.setCode(-1);
|
|
|
+ wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg));
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
});
|
|
|
- })).then(Mono.empty()))
|
|
|
- .map(topicPayload -> topicPayload.bodyToJson(false).toJavaObject(WVPResult.class))
|
|
|
- //返回结果
|
|
|
- .doOnNext(wvpResult -> {
|
|
|
- try {
|
|
|
- result.put(wvpResult);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- })
|
|
|
- .subscribe();
|
|
|
-
|
|
|
- return Mono.justOrEmpty(result.pollFirst(60,TimeUnit.SECONDS))
|
|
|
- .flatMap(wvpResult->{
|
|
|
- //取消订阅
|
|
|
- subscribe.dispose();
|
|
|
-
|
|
|
- if(wvpResult==null){
|
|
|
- return Mono.error(new BusinessException("服务器内部出现问题"));
|
|
|
- }
|
|
|
- if(wvpResult.getCode()!=HttpStatus.OK.value()){
|
|
|
- return Mono.error(new BusinessException(Optional.ofNullable(wvpResult.getMsg()).orElse("点播失败")));
|
|
|
- }
|
|
|
- return Mono.just(wvpResult);
|
|
|
- })
|
|
|
- // 点播结束时调用截图接口
|
|
|
- .doOnNext(wvpResult -> {
|
|
|
- try {
|
|
|
- String classPath = ResourceUtils.getURL("classpath:").getPath();
|
|
|
- // System.out.println(classPath);
|
|
|
- // 兼容打包为jar的class路径
|
|
|
- if (classPath.contains("jar")) {
|
|
|
- classPath = classPath.substring(0, classPath.lastIndexOf("."));
|
|
|
- classPath = classPath.substring(0, classPath.lastIndexOf("/") + 1);
|
|
|
- }
|
|
|
- if (classPath.startsWith("file:")) {
|
|
|
- classPath = classPath.substring(classPath.indexOf(":") + 1);
|
|
|
- }
|
|
|
- String path = classPath + "static/static/snap/";
|
|
|
- // 兼容Windows系统路径(去除前面的“/”)
|
|
|
- if (System.getProperty("os.name").contains("indows")) {
|
|
|
- path = path.substring(1);
|
|
|
}
|
|
|
- String fileName = deviceId + "_" + channelId + ".jpg";
|
|
|
- if (Objects.requireNonNull(wvpResult).getCode() == HttpStatus.OK.value()) {
|
|
|
- StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData();
|
|
|
- MediaServerItem mediaInfo = mediaServerItemService.getOneByServerId(streamInfoForSuccess.getMediaServerId());
|
|
|
- String streamUrl = streamInfoForSuccess.getFmp4();
|
|
|
- // 请求截图
|
|
|
- log.info("[请求截图]: " + fileName);
|
|
|
- zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName);
|
|
|
- }
|
|
|
-
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- throw new BusinessException("设备上传视频截图文件找不到");
|
|
|
- }
|
|
|
- })
|
|
|
- .switchIfEmpty(Mono.error(new BusinessException("点播超时")))
|
|
|
- //保证接下来的操作流仅被触发一次
|
|
|
- .doOnError(BusinessException.class, e -> cmder.streamByeCmd(deviceId, channelId).subscribe());
|
|
|
+ return Mono.empty();
|
|
|
+ })
|
|
|
+ .thenReturn(playResult);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
- private Mono<Void> onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String msgId) {
|
|
|
- RequestMessage msg = RequestMessage.of(deviceId, channelId, msgId, null);
|
|
|
- return onPublishHandler(mediaServerItem, resonse, deviceId, channelId, msgId)
|
|
|
- .switchIfEmpty(Mono.fromRunnable(()->{
|
|
|
- log.warn("设备预览API调用失败!");
|
|
|
- clusterEventBus.publish(DeferredResultHolder.getCmdCallBackTopic(DeferredResultHolder.CALLBACK_CMD_PLAY, msg),
|
|
|
- WVPResult.of(HttpStatus.INTERNAL_SERVER_ERROR.value(),"设备预览API调用失败",null));
|
|
|
- }))
|
|
|
+ private Mono<Void> onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) {
|
|
|
+ RequestMessage msg = new RequestMessage();
|
|
|
+ msg.setId(uuid);
|
|
|
+ msg.setKey(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId);
|
|
|
+ return onPublishHandler(mediaServerItem, resonse, deviceId, channelId, uuid)
|
|
|
.flatMap(streamInfo ->
|
|
|
- deviceChannelService.startPlay(deviceId, channelId, streamInfo.getStreamId())
|
|
|
- .mergeWith(Mono.fromRunnable(()->{
|
|
|
+ deviceChannelService.createQuery()
|
|
|
+ .where(MediaDeviceChannel::getChannelId,channelId)
|
|
|
+ .where(MediaDeviceChannel::getDeviceId,deviceId)
|
|
|
+ .fetchOne()
|
|
|
+ .defaultIfEmpty(new MediaDeviceChannel())
|
|
|
+ .flatMap(deviceChannel->{
|
|
|
redisCatchStorage.startPlay(streamInfo);
|
|
|
- WVPResult<StreamInfo> wvpResult = WVPResult.of(HttpStatus.OK.value(), "success", streamInfo);
|
|
|
- clusterEventBus.publish(DeferredResultHolder.getCmdCallBackTopic(DeferredResultHolder.CALLBACK_CMD_PLAY, msg),
|
|
|
- wvpResult);
|
|
|
- }))
|
|
|
- .then()
|
|
|
- );
|
|
|
-
|
|
|
+ msg.setData(JSON.toJSONString(streamInfo));
|
|
|
+ WVPResult wvpResult = new WVPResult();
|
|
|
+ wvpResult.setCode(0);
|
|
|
+ wvpResult.setMsg("success");
|
|
|
+ wvpResult.setData(streamInfo);
|
|
|
+ msg.setData(wvpResult);
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ if (StrUtil.isNotEmpty(deviceChannel.getId())) {
|
|
|
+ deviceChannel.setStreamId(streamInfo.getStreamId());
|
|
|
+ return deviceChannelService.startPlay(deviceId, channelId, streamInfo.getStreamId());
|
|
|
+ }
|
|
|
+ return Mono.empty();
|
|
|
+ })
|
|
|
+ )
|
|
|
+ .switchIfEmpty(Mono.fromRunnable(()->{
|
|
|
+ log.warn("设备预览API调用失败!");
|
|
|
+ msg.setData("设备预览API调用失败!");
|
|
|
+ resultHolder.invokeAllResult(msg);
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -250,45 +294,8 @@ public class LocalPlayService {
|
|
|
.switchIfEmpty(mediaServerItemService.getMediaServerForMinimumLoad())
|
|
|
.switchIfEmpty(Mono.fromRunnable(()-> log.warn("点播时未找到可使用的ZLM...")));
|
|
|
}
|
|
|
- ////
|
|
|
-////
|
|
|
-//// @Override
|
|
|
-//// public void onPublishHandlerForPlayBack(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) {
|
|
|
-//// RequestMessage msg = new RequestMessage();
|
|
|
-//// msg.setKey(DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId);
|
|
|
-//// msg.setId(uuid);
|
|
|
-//// StreamInfo streamInfo = onPublishHandler(mediaServerItem, resonse, deviceId, channelId, uuid);
|
|
|
-//// if (streamInfo != null) {
|
|
|
-//// redisCatchStorage.startPlayback(streamInfo);
|
|
|
-//// msg.setData(JSON.toJSONString(streamInfo));
|
|
|
-//// resultHolder.invokeResult(msg);
|
|
|
-//// } else {
|
|
|
-//// log.warn("设备回放API调用失败!");
|
|
|
-//// msg.setData("设备回放API调用失败!");
|
|
|
-//// resultHolder.invokeResult(msg);
|
|
|
-//// }
|
|
|
-//// }
|
|
|
-////
|
|
|
-////
|
|
|
-//// @Override
|
|
|
-//// public void onPublishHandlerForDownload(MediaServerItem mediaServerItem, JSONObject response, String deviceId, String channelId, String uuid) {
|
|
|
-//// RequestMessage msg = new RequestMessage();
|
|
|
-//// msg.setKey(DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId);
|
|
|
-//// msg.setId(uuid);
|
|
|
-//// StreamInfo streamInfo = onPublishHandler(mediaServerItem, response, deviceId, channelId, uuid);
|
|
|
-//// if (streamInfo != null) {
|
|
|
-//// redisCatchStorage.startDownload(streamInfo);
|
|
|
-//// msg.setData(JSON.toJSONString(streamInfo));
|
|
|
-//// resultHolder.invokeResult(msg);
|
|
|
-//// } else {
|
|
|
-//// log.warn("设备预览API调用失败!");
|
|
|
-//// msg.setData("设备预览API调用失败!");
|
|
|
-//// resultHolder.invokeResult(msg);
|
|
|
-//// }
|
|
|
-//// }
|
|
|
-////
|
|
|
-////
|
|
|
- public Mono<StreamInfo> onPublishHandler(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) {
|
|
|
+
|
|
|
+ private Mono<StreamInfo> onPublishHandler(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) {
|
|
|
String streamId = resonse.getStr("stream");
|
|
|
JSONArray tracks = resonse.getJSONArray("tracks");
|
|
|
return mediaServerItemService.getStreamInfoByAppAndStream(mediaServerItem,"rtp", streamId, tracks)
|