ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/controller/ZlmController.java
@@ -921,4 +921,71 @@ return AjaxResult.success(json); } /** * 拉流代理(通过通道ID,简化传参) * * @param request HttpServletRequest * @param channelId 通道ID * @return */ @Operation(summary = "拉流代理(通过通道ID,简化传参)") @PostMapping("/streamPullPlayByChannelId/{channelId}") public DeferredResult<R<StreamContent>> streamPullPlayByChannelId( HttpServletRequest request, @PathVariable String channelId ) { log.info("[拉流代理-通道ID] channelId:{}", channelId); Assert.hasText(channelId, "通道ID不可为空"); DeferredResult<R<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); ErrorCallback<StreamInfo> callback = (code, msg, streamInfo) -> { if (code == InviteErrorCode.SUCCESS.getCode()) { R<StreamContent> r = R.ok(); if (streamInfo != null) { if (userSetting.getUseSourceIpAsStreamIp()) { streamInfo = streamInfo.clone(); String host; try { URL url = new URL(request.getRequestURL().toString()); host = url.getHost(); } catch (MalformedURLException e) { host = request.getLocalAddr(); } streamInfo.changeStreamIp(host); } if (!ObjectUtils.isEmpty(streamInfo.getMediaServer().getTranscodeSuffix()) && !"null".equalsIgnoreCase(streamInfo.getMediaServer().getTranscodeSuffix())) { streamInfo.setStream(streamInfo.getStream() + "_" + streamInfo.getMediaServer().getTranscodeSuffix()); } r.setData(new StreamContent(streamInfo)); } else { r.setCode(code); r.setMsg(msg); } result.setResult(r); } else { result.setResult(R.fail(code, msg)); } }; mediaServerService.streamPullPlayByChannelId(channelId, callback); return result; } /** * 停止拉流代理(通过通道ID) * * @param channelId 通道ID * @return */ @Operation(summary = "停止拉流代理(通过通道ID)") @PostMapping("/stopStreamPullPlayByChannelId/{channelId}") public AjaxResult stopStreamPullPlayByChannelId(@PathVariable String channelId) { log.info("[停止拉流代理-通道ID] channelId:{}", channelId); Assert.hasText(channelId, "通道ID不可为空"); mediaServerService.stopStreamPullPlayByChannelId(channelId); return AjaxResult.success(); } } ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/service/IMediaServerService.java
@@ -372,4 +372,19 @@ * gb28181 停止点播(基于GbChannel,不依赖QS) */ void stopGb28181PlayByGbChannel(InviteSessionType type, StreamChannel streamChannel, Device device, String stream); /** * 通过通道ID拉流代理(简化传参,自动根据通道类型确定app/url等参数) * * @param channelId 通道ID * @param callback 回调 */ void streamPullPlayByChannelId(String channelId, ErrorCallback<StreamInfo> callback); /** * 通过通道ID停止拉流代理 * * @param channelId 通道ID */ void stopStreamPullPlayByChannelId(String channelId); } ard-modules/ard-modules-zlm/src/main/java/com/ard/zlm/service/impl/MediaServerServiceImpl.java
@@ -1904,6 +1904,65 @@ } } /** * 通过通道ID拉流代理(简化传参,自动根据通道类型确定app/url等参数) * * @param channelId 通道ID * @param callback 回调 */ @Override public void streamPullPlayByChannelId(String channelId, ErrorCallback<StreamInfo> callback) { R<ArdChannel> channelR = remoteChannelService.getInfo(channelId, SecurityConstants.INNER); if (channelR.getCode() != Constants.SUCCESS) { callback.run(InviteErrorCode.FAIL.getCode(), "获取通道信息失败 channelId:" + channelId, null); return; } if (channelR.getData() == null) { callback.run(InviteErrorCode.FAIL.getCode(), "通道不存在 channelId:" + channelId, null); return; } ArdChannel ardChannel = channelR.getData(); StreamPullPlay streamPullPlay = buildStreamPullPlay(ardChannel); streamPullPlay(streamPullPlay, callback); } /** * 通过通道ID停止拉流代理 * * @param channelId 通道ID */ @Override public void stopStreamPullPlayByChannelId(String channelId) { R<ArdChannel> channelR = remoteChannelService.getInfo(channelId, SecurityConstants.INNER); if (channelR.getCode() != Constants.SUCCESS) { throw new RuntimeException("获取通道信息失败 channelId:" + channelId); } if (channelR.getData() == null) { throw new RuntimeException("通道不存在 channelId:" + channelId); } ArdChannel ardChannel = channelR.getData(); StreamPullPlay streamPullPlay = new StreamPullPlay(); streamPullPlay.setChannelId(channelId); streamPullPlay.setMediaServerId(ardChannel.getMediaServerId()); streamPullPlay.setStreamKey(ardChannel.getStreamKey()); stopStreamPullPlay(streamPullPlay); } private StreamPullPlay buildStreamPullPlay(ArdChannel ardChannel) { StreamPullPlay streamPullPlay = new StreamPullPlay(); streamPullPlay.setChannelId(ardChannel.getId()); streamPullPlay.setStream(ardChannel.getId()); streamPullPlay.setUrl(ardChannel.getLiveAddress()); streamPullPlay.setApp("ard"); streamPullPlay.setEnable_mp4(false); streamPullPlay.setEnable_audio(true); streamPullPlay.setRtp_type("1"); streamPullPlay.setTimeOut(10); return streamPullPlay; } /** * 开启国标28181播放