| | |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.UserSetting; |
| | | import com.genersoft.iot.vmp.conf.exception.ControllerException; |
| | | import com.genersoft.iot.vmp.conf.redis.RedisRpcConfig; |
| | | import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcMessage; |
| | | import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcRequest; |
| | |
| | | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| | | import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; |
| | | import com.genersoft.iot.vmp.media.bean.MediaInfo; |
| | | import com.genersoft.iot.vmp.media.bean.MediaServer; |
| | | import com.genersoft.iot.vmp.media.event.hook.Hook; |
| | | 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.media.zlm.SendRtpPortManager; |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; |
| | | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| | | 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; |
| | |
| | | private UserSetting userSetting; |
| | | |
| | | @Autowired |
| | | private ZlmHttpHookSubscribe hookSubscribe; |
| | | |
| | | @Autowired |
| | | private ZLMServerFactory zlmServerFactory; |
| | | |
| | | private HookSubscribe hookSubscribe; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<Object, Object> redisTemplate; |
| | |
| | | } |
| | | logger.info("[redis-rpc] 获取发流的信息: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort()); |
| | | // 查询本级是否有这个流 |
| | | MediaServerItem mediaServerItem = mediaServerService.getMediaServerByAppAndStream(sendRtpItem.getApp(), sendRtpItem.getStream()); |
| | | MediaServer mediaServerItem = mediaServerService.getMediaServerByAppAndStream(sendRtpItem.getApp(), sendRtpItem.getStream()); |
| | | if (mediaServerItem == null) { |
| | | RedisRpcResponse response = request.getResponse(); |
| | | response.setStatusCode(200); |
| | |
| | | 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) { |
| | | MediaServer mediaServer = mediaServerService.getMediaServerByAppAndStream(sendRtpItem.getApp(), sendRtpItem.getStream()); |
| | | if (mediaServer != 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()); |
| | | String ssrc = "Play".equalsIgnoreCase(sendRtpItem.getSessionName()) ? ssrcFactory.getPlaySsrc(mediaServer.getId()) : ssrcFactory.getPlayBackSsrc(mediaServer.getId()); |
| | | sendRtpItem.setSsrc(ssrc); |
| | | } |
| | | sendRtpItem.setMediaServerId(mediaServerItem.getId()); |
| | | sendRtpItem.setLocalIp(mediaServerItem.getSdpIp()); |
| | | sendRtpItem.setMediaServerId(mediaServer.getId()); |
| | | sendRtpItem.setLocalIp(mediaServer.getSdpIp()); |
| | | sendRtpItem.setServerId(userSetting.getServerId()); |
| | | |
| | | redisTemplate.opsForValue().set(sendRtpItem.getRedisKey(), sendRtpItem); |
| | |
| | | response.setStatusCode(200); |
| | | } |
| | | // 监听流上线。 流上线直接发送sendRtpItem消息给实际的信令处理者 |
| | | HookSubscribeForStreamChange hook = HookSubscribeFactory.on_stream_changed( |
| | | sendRtpItem.getApp(), sendRtpItem.getStream(), true, "rtsp", null); |
| | | |
| | | hookSubscribe.addSubscribe(hook, (MediaServerItem mediaServerItemInUse, HookParam hookParam) -> { |
| | | Hook hook = Hook.getInstance(HookType.on_media_arrival, sendRtpItem.getApp(), sendRtpItem.getStream(), null); |
| | | hookSubscribe.addSubscribe(hook, (hookData) -> { |
| | | 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(mediaServerItemInUse.getId()) : ssrcFactory.getPlayBackSsrc(mediaServerItemInUse.getId()); |
| | | String ssrc = "Play".equalsIgnoreCase(sendRtpItem.getSessionName()) ? ssrcFactory.getPlaySsrc(hookData.getMediaServer().getId()) : ssrcFactory.getPlayBackSsrc(hookData.getMediaServer().getId()); |
| | | sendRtpItem.setSsrc(ssrc); |
| | | } |
| | | sendRtpItem.setMediaServerId(mediaServerItemInUse.getId()); |
| | | sendRtpItem.setLocalIp(mediaServerItemInUse.getSdpIp()); |
| | | sendRtpItem.setMediaServerId(hookData.getMediaServer().getId()); |
| | | sendRtpItem.setLocalIp(hookData.getMediaServer().getSdpIp()); |
| | | sendRtpItem.setServerId(userSetting.getServerId()); |
| | | |
| | | redisTemplate.opsForValue().set(sendRtpItem.getRedisKey(), sendRtpItem); |
| | |
| | | */ |
| | | public RedisRpcResponse stopWaitePushStreamOnline(RedisRpcRequest request) { |
| | | SendRtpItem sendRtpItem = JSONObject.parseObject(request.getParam().toString(), SendRtpItem.class); |
| | | // 监听流上线。 流上线直接发送sendRtpItem消息给实际的信令处理者 |
| | | HookSubscribeForStreamChange hook = HookSubscribeFactory.on_stream_changed( |
| | | sendRtpItem.getApp(), sendRtpItem.getStream(), true, "rtsp", null); |
| | | hookSubscribe.removeSubscribe(hook); |
| | | logger.info("[redis-rpc] 停止监听流上线: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() ); |
| | | // 监听流上线。 流上线直接发送sendRtpItem消息给实际的信令处理者 |
| | | Hook hook = Hook.getInstance(HookType.on_media_arrival, sendRtpItem.getApp(), sendRtpItem.getStream(), null); |
| | | hookSubscribe.removeSubscribe(hook); |
| | | RedisRpcResponse response = request.getResponse(); |
| | | response.setStatusCode(200); |
| | | return response; |
| | |
| | | return response; |
| | | } |
| | | logger.info("[redis-rpc] 开始发流: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort()); |
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(sendRtpItem.getMediaServerId()); |
| | | if (mediaServerItem == null) { |
| | | MediaServer mediaServer = mediaServerService.getOne(sendRtpItem.getMediaServerId()); |
| | | if (mediaServer == null) { |
| | | logger.info("[redis-rpc] startSendRtp->未找到MediaServer: {}", sendRtpItem.getMediaServerId() ); |
| | | WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "未找到MediaServer"); |
| | | response.setBody(wvpResult); |
| | | return response; |
| | | } |
| | | |
| | | Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerItem, sendRtpItem.getApp(), sendRtpItem.getStream()); |
| | | if (!streamReady) { |
| | | MediaInfo mediaInfo = mediaServerService.getMediaInfo(mediaServer, sendRtpItem.getApp(), sendRtpItem.getStream()); |
| | | if (mediaInfo != null) { |
| | | logger.info("[redis-rpc] startSendRtp->流不在线: {}/{}", sendRtpItem.getApp(), sendRtpItem.getStream() ); |
| | | WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "流不在线"); |
| | | response.setBody(wvpResult); |
| | | return response; |
| | | } |
| | | JSONObject jsonObject = zlmServerFactory.startSendRtp(mediaServerItem, sendRtpItem); |
| | | if (jsonObject.getInteger("code") == 0) { |
| | | logger.info("[redis-rpc] 发流成功: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort()); |
| | | WVPResult wvpResult = WVPResult.success(); |
| | | try { |
| | | mediaServerService.startSendRtp(mediaServer, sendRtpItem); |
| | | }catch (ControllerException exception) { |
| | | logger.info("[redis-rpc] 发流失败: {}/{}, 目标地址: {}:{}, {}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), exception.getMsg()); |
| | | WVPResult wvpResult = WVPResult.fail(exception.getCode(), exception.getMsg()); |
| | | response.setBody(wvpResult); |
| | | }else { |
| | | logger.info("[redis-rpc] 发流失败: {}/{}, 目标地址: {}:{}, {}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), jsonObject); |
| | | WVPResult wvpResult = WVPResult.fail(jsonObject.getInteger("code"), jsonObject.getString("msg")); |
| | | response.setBody(wvpResult); |
| | | return response; |
| | | } |
| | | logger.info("[redis-rpc] 发流成功: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort()); |
| | | WVPResult wvpResult = WVPResult.success(); |
| | | response.setBody(wvpResult); |
| | | return response; |
| | | } |
| | | |
| | |
| | | return response; |
| | | } |
| | | logger.info("[redis-rpc] 停止推流: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() ); |
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(sendRtpItem.getMediaServerId()); |
| | | if (mediaServerItem == null) { |
| | | MediaServer mediaServer = mediaServerService.getOne(sendRtpItem.getMediaServerId()); |
| | | if (mediaServer == null) { |
| | | logger.info("[redis-rpc] stopSendRtp->未找到MediaServer: {}", sendRtpItem.getMediaServerId() ); |
| | | WVPResult wvpResult = WVPResult.fail(ErrorCode.ERROR100.getCode(), "未找到MediaServer"); |
| | | response.setBody(wvpResult); |
| | | return response; |
| | | } |
| | | JSONObject jsonObject = zlmServerFactory.stopSendRtpStream(mediaServerItem, sendRtpItem); |
| | | if (jsonObject.getInteger("code") == 0) { |
| | | logger.info("[redis-rpc] 停止推流成功: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() ); |
| | | 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 ); |
| | | response.setBody(WVPResult.fail(code, msg)); |
| | | try { |
| | | mediaServerService.stopSendRtp(mediaServer, sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getSsrc()); |
| | | }catch (ControllerException exception) { |
| | | logger.info("[redis-rpc] 停止推流失败: {}/{}, 目标地址: {}:{}, code: {}, msg: {}", sendRtpItem.getApp(), |
| | | sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), exception.getCode(), exception.getMsg() ); |
| | | response.setBody(WVPResult.fail(exception.getCode(), exception.getMsg())); |
| | | return response; |
| | | } |
| | | logger.info("[redis-rpc] 停止推流成功: {}/{}, 目标地址: {}:{}", sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort() ); |
| | | response.setBody(WVPResult.success()); |
| | | return response; |
| | | } |
| | | |
| | | /** |