From f70aabc2b2b46fafbdd5fd2778beff76cde83daa Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 30 Dec 2024 16:59:08 +0800 Subject: [PATCH] =?UTF-8?q?[RPC]=20=E6=8E=A8=E6=B5=81=E6=92=AD=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/redisMsg/IRedisRpcService.java | 3 +++ .../control/RedisRpcStreamPushController.java | 26 +++++++++++++++++++ .../redisMsg/service/RedisRpcServiceImpl.java | 7 +++++ .../controller/StreamPushController.java | 2 +- .../impl/StreamPushPlayServiceImpl.java | 5 ++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/IRedisRpcService.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/IRedisRpcService.java index a6d93926..84511b69 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/IRedisRpcService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/IRedisRpcService.java @@ -28,4 +28,7 @@ public interface IRedisRpcService { void subscribeCatalog(int id, int cycle); void subscribeMobilePosition(int id, int cycle, int interval); + + void play(Integer id, ErrorCallback callback); + } diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcStreamPushController.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcStreamPushController.java index 1cf46890..d4d0d256 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcStreamPushController.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcStreamPushController.java @@ -18,6 +18,7 @@ import com.genersoft.iot.vmp.service.ISendRtpServerService; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcController; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcMapping; import com.genersoft.iot.vmp.service.redisMsg.dto.RpcController; +import com.genersoft.iot.vmp.streamPush.service.IStreamPushPlayService; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -47,6 +48,9 @@ public class RedisRpcStreamPushController extends RpcController { @Autowired private RedisTemplate redisTemplate; + @Autowired + private IStreamPushPlayService streamPushPlayService; + private void sendResponse(RedisRpcResponse response){ log.info("[redis-rpc] >> {}", response); @@ -172,4 +176,26 @@ public class RedisRpcStreamPushController extends RpcController { return response; } + /** + * 停止监听流上线 + */ + @RedisRpcMapping("play") + public RedisRpcResponse play(RedisRpcRequest request) { + int id = Integer.parseInt(request.getParam().toString()); + RedisRpcResponse response = request.getResponse(); + if (id <= 0) { + response.setStatusCode(ErrorCode.ERROR400.getCode()); + response.setBody("param error"); + return response; + } + streamPushPlayService.start(id, (code, msg, data) -> { + if (code == ErrorCode.SUCCESS.getCode()) { + response.setStatusCode(ErrorCode.SUCCESS.getCode()); + response.setBody(data); + sendResponse(response); + } + }, null, null); + return null; + } + } diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/service/RedisRpcServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/service/RedisRpcServiceImpl.java index f11c7f0c..afa22ab1 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/service/RedisRpcServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/service/RedisRpcServiceImpl.java @@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.media.event.hook.HookSubscribe; import com.genersoft.iot.vmp.media.event.hook.HookType; import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.service.ISendRtpServerService; +import com.genersoft.iot.vmp.service.bean.ErrorCallback; import com.genersoft.iot.vmp.service.redisMsg.IRedisRpcService; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; @@ -221,4 +222,10 @@ public class RedisRpcServiceImpl implements IRedisRpcService { RedisRpcRequest request = buildRequest("device/subscribeMobilePosition", jsonObject); redisRpcConfig.request(request, 10); } + + @Override + public void play(Integer id, ErrorCallback callback) { + RedisRpcRequest request = buildRequest("streamPush/play", id); + redisRpcConfig.request(request, 10); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/streamPush/controller/StreamPushController.java b/src/main/java/com/genersoft/iot/vmp/streamPush/controller/StreamPushController.java index ecaa92ee..d6c24cb5 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamPush/controller/StreamPushController.java +++ b/src/main/java/com/genersoft/iot/vmp/streamPush/controller/StreamPushController.java @@ -245,7 +245,7 @@ public class StreamPushController { @GetMapping(value = "/start") @ResponseBody @Operation(summary = "开始播放", security = @SecurityRequirement(name = JwtUtils.HEADER)) - public DeferredResult> batchStop(Integer id){ + public DeferredResult> start(Integer id){ Assert.notNull(id, "推流ID不可为NULL"); DeferredResult> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); result.onTimeout(()->{ diff --git a/src/main/java/com/genersoft/iot/vmp/streamPush/service/impl/StreamPushPlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/streamPush/service/impl/StreamPushPlayServiceImpl.java index 30ed9155..d1fdb82a 100644 --- a/src/main/java/com/genersoft/iot/vmp/streamPush/service/impl/StreamPushPlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/streamPush/service/impl/StreamPushPlayServiceImpl.java @@ -53,6 +53,11 @@ public class StreamPushPlayServiceImpl implements IStreamPushPlayService { StreamPush streamPush = streamPushMapper.queryOne(id); Assert.notNull(streamPush, "推流信息未找到"); + if (!userSetting.getServerId().equals(streamPush.getServerId())) { + redisRpcService.play(id, callback); + return; + } + MediaServer mediaServer = mediaServerService.getOne(streamPush.getMediaServerId()); Assert.notNull(mediaServer, "节点" + streamPush.getMediaServerId() + "未找到"); MediaInfo mediaInfo = mediaServerService.getMediaInfo(mediaServer, streamPush.getApp(), streamPush.getStream());