|
|
@@ -1,6 +1,5 @@
|
|
|
package com.genersoft.iot.vmp.service.redisMsg.control;
|
|
|
|
|
|
-import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.genersoft.iot.vmp.conf.UserSetting;
|
|
|
import com.genersoft.iot.vmp.conf.redis.RedisRpcConfig;
|
|
|
@@ -21,6 +20,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam;
|
|
|
import com.genersoft.iot.vmp.service.IMediaServerService;
|
|
|
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
|
|
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
|
|
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
@@ -78,7 +78,14 @@ public class RedisRpcController {
|
|
|
* 获取发流的信息
|
|
|
*/
|
|
|
public RedisRpcResponse getSendRtpItem(RedisRpcRequest request) {
|
|
|
- SendRtpItem sendRtpItem = JSON.parseObject(request.getParam().toString(), SendRtpItem.class);
|
|
|
+ String sendRtpItemKey = request.getParam().toString();
|
|
|
+ SendRtpItem sendRtpItem = (SendRtpItem) redisTemplate.opsForValue().get(sendRtpItemKey);
|
|
|
+ if (sendRtpItem == null) {
|
|
|
+ logger.info("[redis-rpc] 获取发流的信息, 未找到redis中的发流信息, key:{}", sendRtpItemKey);
|
|
|
+ RedisRpcResponse response = request.getResponse();
|
|
|
+ response.setStatusCode(200);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
logger.info("[redis-rpc] 获取发流的信息: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort());
|
|
|
// 查询本级是否有这个流
|
|
|
MediaServerItem mediaServerItem = mediaServerService.getMediaServerByAppAndStream(sendRtpItem.getApp(), sendRtpItem.getStream());
|
|
|
@@ -103,9 +110,10 @@ public class RedisRpcController {
|
|
|
sendRtpItem.setSsrc(ssrc);
|
|
|
}
|
|
|
redisCatchStorage.updateSendRTPSever(sendRtpItem);
|
|
|
+ redisTemplate.opsForValue().set(sendRtpItemKey, sendRtpItem);
|
|
|
RedisRpcResponse response = request.getResponse();
|
|
|
response.setStatusCode(200);
|
|
|
- response.setBody(sendRtpItem);
|
|
|
+ response.setBody(sendRtpItemKey);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
@@ -113,14 +121,25 @@ public class RedisRpcController {
|
|
|
* 监听流上线
|
|
|
*/
|
|
|
public RedisRpcResponse waitePushStreamOnline(RedisRpcRequest request) {
|
|
|
- SendRtpItem sendRtpItem = JSON.parseObject(request.getParam().toString(), SendRtpItem.class);
|
|
|
+ SendRtpItem sendRtpItem = JSONObject.parseObject(request.getParam().toString(), SendRtpItem.class);
|
|
|
logger.info("[redis-rpc] 监听流上线: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort());
|
|
|
// 查询本级是否有这个流
|
|
|
MediaServerItem mediaServerItem = mediaServerService.getMediaServerByAppAndStream(sendRtpItem.getApp(), sendRtpItem.getStream());
|
|
|
if (mediaServerItem != null) {
|
|
|
logger.info("[redis-rpc] 监听流上线时发现流已存在直接返回: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() );
|
|
|
+ // 读取redis中的上级点播信息,生成sendRtpItm发送出去
|
|
|
+ if (sendRtpItem.getSsrc() == null) {
|
|
|
+ // 上级平台点播时不使用上级平台指定的ssrc,使用自定义的ssrc,参考国标文档-点播外域设备媒体流SSRC处理方式
|
|
|
+ String ssrc = "Play".equalsIgnoreCase(sendRtpItem.getSessionName()) ? ssrcFactory.getPlaySsrc(mediaServerItem.getId()) : ssrcFactory.getPlayBackSsrc(mediaServerItem.getId());
|
|
|
+ sendRtpItem.setSsrc(ssrc);
|
|
|
+ }
|
|
|
+ sendRtpItem.setMediaServerId(mediaServerItem.getId());
|
|
|
+ sendRtpItem.setLocalIp(mediaServerItem.getSdpIp());
|
|
|
+ sendRtpItem.setServerId(userSetting.getServerId());
|
|
|
+
|
|
|
+ redisTemplate.opsForValue().set(sendRtpItem.getRedisKey(), sendRtpItem);
|
|
|
RedisRpcResponse response = request.getResponse();
|
|
|
- response.setBody(sendRtpItem);
|
|
|
+ response.setBody(sendRtpItem.getRedisKey());
|
|
|
response.setStatusCode(200);
|
|
|
}
|
|
|
// 监听流上线。 流上线直接发送sendRtpItem消息给实际的信令处理者
|
|
|
@@ -139,8 +158,9 @@ public class RedisRpcController {
|
|
|
sendRtpItem.setLocalIp(mediaServerItemInUse.getSdpIp());
|
|
|
sendRtpItem.setServerId(userSetting.getServerId());
|
|
|
|
|
|
+ redisTemplate.opsForValue().set(sendRtpItem.getRedisKey(), sendRtpItem);
|
|
|
RedisRpcResponse response = request.getResponse();
|
|
|
- response.setBody(sendRtpItem);
|
|
|
+ response.setBody(sendRtpItem.getRedisKey());
|
|
|
response.setStatusCode(200);
|
|
|
// 手动发送结果
|
|
|
sendResponse(response);
|
|
|
@@ -153,7 +173,14 @@ public class RedisRpcController {
|
|
|
* 停止监听流上线
|
|
|
*/
|
|
|
public RedisRpcResponse stopWaitePushStreamOnline(RedisRpcRequest request) {
|
|
|
- SendRtpItem sendRtpItem = JSON.parseObject(request.getParam().toString(), SendRtpItem.class);
|
|
|
+ String sendRtpItemKey = request.getParam().toString();
|
|
|
+ SendRtpItem sendRtpItem = (SendRtpItem) redisTemplate.opsForValue().get(sendRtpItemKey);
|
|
|
+ if (sendRtpItem == null) {
|
|
|
+ logger.info("[redis-rpc] 停止监听流上线, 未找到redis中的发流信息, key:{}", sendRtpItemKey);
|
|
|
+ RedisRpcResponse response = request.getResponse();
|
|
|
+ response.setStatusCode(200);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
logger.info("[redis-rpc] 停止监听流上线: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() );
|
|
|
|
|
|
// 监听流上线。 流上线直接发送sendRtpItem消息给实际的信令处理者
|
|
|
@@ -168,24 +195,33 @@ public class RedisRpcController {
|
|
|
* 开始发流
|
|
|
*/
|
|
|
public RedisRpcResponse startSendRtp(RedisRpcRequest request) {
|
|
|
- SendRtpItem sendRtpItem = JSON.parseObject(request.getParam().toString(), SendRtpItem.class);
|
|
|
+ String sendRtpItemKey = request.getParam().toString();
|
|
|
+ SendRtpItem sendRtpItem = (SendRtpItem) redisTemplate.opsForValue().get(sendRtpItemKey);
|
|
|
+ RedisRpcResponse response = request.getResponse();
|
|
|
+ response.setStatusCode(200);
|
|
|
+ if (sendRtpItem == null) {
|
|
|
+ logger.info("[redis-rpc] 开始发流, 未找到redis中的发流信息, key:{}", sendRtpItemKey);
|
|
|
+ WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "未找到redis中的发流信息");
|
|
|
+ response.setBody(wvpResult);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
logger.info("[redis-rpc] 开始发流: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort());
|
|
|
MediaServerItem mediaServerItem = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
|
|
if (mediaServerItem == null) {
|
|
|
logger.info("[redis-rpc] startSendRtp->未找到MediaServer: {}", sendRtpItem.getMediaServerId() );
|
|
|
- RedisRpcResponse response = request.getResponse();
|
|
|
- response.setStatusCode(200);
|
|
|
+ WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "未找到MediaServer");
|
|
|
+ response.setBody(wvpResult);
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerItem, sendRtpItem.getApp(), sendRtpItem.getStream());
|
|
|
if (!streamReady) {
|
|
|
logger.info("[redis-rpc] startSendRtp->流不在线: {}/{}", sendRtpItem.getApp(), sendRtpItem.getStream() );
|
|
|
- RedisRpcResponse response = request.getResponse();
|
|
|
- response.setStatusCode(200);
|
|
|
+ WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "流不在线");
|
|
|
+ response.setBody(wvpResult);
|
|
|
+ return response;
|
|
|
}
|
|
|
JSONObject jsonObject = zlmServerFactory.startSendRtp(mediaServerItem, sendRtpItem);
|
|
|
- RedisRpcResponse response = request.getResponse();
|
|
|
- response.setStatusCode(200);
|
|
|
if (jsonObject.getInteger("code") == 0) {
|
|
|
logger.info("[redis-rpc] 发流成功: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort());
|
|
|
WVPResult wvpResult = WVPResult.success();
|
|
|
@@ -202,43 +238,51 @@ public class RedisRpcController {
|
|
|
* 停止发流
|
|
|
*/
|
|
|
public RedisRpcResponse stopSendRtp(RedisRpcRequest request) {
|
|
|
- SendRtpItem sendRtpItem = JSON.parseObject(request.getParam().toString(), SendRtpItem.class);
|
|
|
+ String sendRtpItemKey = request.getParam().toString();
|
|
|
+ SendRtpItem sendRtpItem = (SendRtpItem) redisTemplate.opsForValue().get(sendRtpItemKey);
|
|
|
+ RedisRpcResponse response = request.getResponse();
|
|
|
+ response.setStatusCode(200);
|
|
|
+ if (sendRtpItem == null) {
|
|
|
+ logger.info("[redis-rpc] 停止推流, 未找到redis中的发流信息, key:{}", sendRtpItemKey);
|
|
|
+ WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "未找到redis中的发流信息");
|
|
|
+ response.setBody(wvpResult);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
logger.info("[redis-rpc] 停止推流: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() );
|
|
|
MediaServerItem mediaServerItem = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
|
|
if (mediaServerItem == null) {
|
|
|
logger.info("[redis-rpc] stopSendRtp->未找到MediaServer: {}", sendRtpItem.getMediaServerId() );
|
|
|
- RedisRpcResponse response = request.getResponse();
|
|
|
- response.setStatusCode(200);
|
|
|
+ WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "未找到MediaServer");
|
|
|
+ response.setBody(wvpResult);
|
|
|
+ return response;
|
|
|
}
|
|
|
JSONObject jsonObject = zlmServerFactory.stopSendRtpStream(mediaServerItem, sendRtpItem);
|
|
|
- RedisRpcResponse response = request.getResponse();
|
|
|
- response.setStatusCode(200);
|
|
|
if (jsonObject.getInteger("code") == 0) {
|
|
|
logger.info("[redis-rpc] 停止推流成功: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() );
|
|
|
- WVPResult wvpResult = WVPResult.success();
|
|
|
- response.setBody(wvpResult);
|
|
|
+ response.setBody(WVPResult.success());
|
|
|
+ return response;
|
|
|
}else {
|
|
|
int code = jsonObject.getInteger("code");
|
|
|
String msg = jsonObject.getString("msg");
|
|
|
logger.info("[redis-rpc] 停止推流失败: {}/{}, 目标地址: {}:{}, code: {}, msg: {}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), code, msg );
|
|
|
- WVPResult wvpResult = WVPResult.fail(code, msg);
|
|
|
- response.setBody(wvpResult);
|
|
|
+ response.setBody(WVPResult.fail(code, msg));
|
|
|
+ return response;
|
|
|
}
|
|
|
- return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 其他wvp通知推流已经停止了
|
|
|
*/
|
|
|
public RedisRpcResponse rtpSendStopped(RedisRpcRequest request) {
|
|
|
- SendRtpItem sendRtpItem = JSON.parseObject(request.getParam().toString(), SendRtpItem.class);
|
|
|
- logger.info("[redis-rpc] 推流已经停止: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() );
|
|
|
- SendRtpItem sendRtpItemInCatch = redisCatchStorage.querySendRTPServer(sendRtpItem.getPlatformId(), sendRtpItem.getChannelId(), sendRtpItem.getStream(), sendRtpItem.getCallId());
|
|
|
+ String sendRtpItemKey = request.getParam().toString();
|
|
|
+ SendRtpItem sendRtpItem = (SendRtpItem) redisTemplate.opsForValue().get(sendRtpItemKey);
|
|
|
RedisRpcResponse response = request.getResponse();
|
|
|
response.setStatusCode(200);
|
|
|
- if (sendRtpItemInCatch == null) {
|
|
|
+ if (sendRtpItem == null) {
|
|
|
+ logger.info("[redis-rpc] 推流已经停止, 未找到redis中的发流信息, key:{}", sendRtpItemKey);
|
|
|
return response;
|
|
|
}
|
|
|
+ logger.info("[redis-rpc] 推流已经停止: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() );
|
|
|
String platformId = sendRtpItem.getPlatformId();
|
|
|
ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
|
|
|
if (platform == null) {
|