From 80f6897976703e5442a5917bb0e9628f0f9f358d Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Wed, 29 Jun 2022 22:01:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=BA=94=E7=94=A8=E5=90=8D?= =?UTF-8?q?=E5=92=8C=E6=B5=81id=E8=8E=B7=E5=8F=96=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=20=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=9A=E4=BD=BF=E7=94=A8=E8=AF=B7=E6=B1=82?= =?UTF-8?q?ip=E4=BD=9C=E4=B8=BA=E8=BF=94=E5=9B=9E=E7=9A=84=E6=B5=81IP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../genersoft/iot/vmp/common/StreamInfo.java | 10 +++ .../vmp/service/impl/MediaServiceImpl.java | 1 + .../gb28181/media/MediaController.java | 84 ++++++++++++++++++- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java b/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java index 4e4ba15e4..11791216a 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java @@ -6,6 +6,8 @@ public class StreamInfo { private String app; private String stream; + + private String ip; private String deviceID; private String channelId; private String flv; @@ -52,6 +54,14 @@ public class StreamInfo { this.app = app; } + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + public String getDeviceID() { return deviceID; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java index 9253b517c..727196e27 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -78,6 +78,7 @@ public class MediaServiceImpl implements IMediaService { if (addr == null) { addr = mediaInfo.getStreamIp(); } + streamInfoResult.setIp(addr); streamInfoResult.setMediaServerId(mediaInfo.getId()); streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s", addr, mediaInfo.getRtmpPort(), app, stream)); if (mediaInfo.getRtmpSSlPort() != 0) { diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java index d4995a01d..26ab904b4 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java @@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; + @Api(tags = "媒体流相关") @Controller @@ -49,16 +51,90 @@ public class MediaController { @ApiImplicitParam(name = "app", value = "应用名", dataTypeClass = String.class), @ApiImplicitParam(name = "stream", value = "流id", dataTypeClass = String.class), @ApiImplicitParam(name = "mediaServerId", value = "媒体服务器id", dataTypeClass = String.class, required = false), + @ApiImplicitParam(name = "useSourceIpAsStreamIp", value = "使用请求ip作为返回的流IP", dataTypeClass = Boolean.class, required = false), }) @GetMapping(value = "/stream_info_by_app_and_stream") @ResponseBody - public WVPResult getStreamInfoByAppAndStream(@RequestParam String app, @RequestParam String stream, @RequestParam(required = false) String mediaServerId){ - StreamInfo streamInfoByAppAndStreamWithCheck = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId); + public WVPResult getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app, + @RequestParam String stream, + @RequestParam(required = false) String mediaServerId, + @RequestParam(required = false) Boolean useSourceIpAsStreamIp){ + + StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId); + WVPResult result = new WVPResult<>(); - if (streamInfoByAppAndStreamWithCheck != null){ + if (streamInfo != null){ + if (useSourceIpAsStreamIp != null && useSourceIpAsStreamIp) { + String localAddr = request.getLocalAddr(); + streamInfo.setIp(localAddr); + if (streamInfo.getRtsp() != null) { + streamInfo.setRtsp(streamInfo.getRtsp().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getRtsps() != null) { + streamInfo.setRtsps(streamInfo.getRtsps().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getRtmp() != null) { + streamInfo.setRtmp(streamInfo.getRtmp().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getRtmps() != null) { + streamInfo.setRtmps(streamInfo.getRtmps().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getFlv() != null) { + streamInfo.setFlv(streamInfo.getFlv().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getHttps_flv() != null) { + streamInfo.setHttps_flv(streamInfo.getHttps_flv().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getWs_flv() != null) { + streamInfo.setWs_flv(streamInfo.getWs_flv().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getWss_flv() != null) { + streamInfo.setWss_flv(streamInfo.getWss_flv().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getFmp4() != null) { + streamInfo.setFmp4(streamInfo.getFmp4().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getHttps_fmp4() != null) { + streamInfo.setHttps_fmp4(streamInfo.getHttps_fmp4().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getWs_fmp4() != null) { + streamInfo.setWs_fmp4(streamInfo.getWs_fmp4().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getWss_fmp4() != null) { + streamInfo.setWss_fmp4(streamInfo.getWss_fmp4().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getTs() != null) { + streamInfo.setTs(streamInfo.getTs().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getHttps_ts() != null) { + streamInfo.setHttps_ts(streamInfo.getHttps_ts().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getWs_ts() != null) { + streamInfo.setWs_ts(streamInfo.getWs_ts().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getWss_ts() != null) { + streamInfo.setWss_ts(streamInfo.getWss_ts().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getHls() != null) { + streamInfo.setHls(streamInfo.getHls().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getHttps_hls() != null) { + streamInfo.setHttps_hls(streamInfo.getHttps_hls().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getWs_hls() != null) { + streamInfo.setWs_hls(streamInfo.getWs_hls().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getWss_hls() != null) { + streamInfo.setWss_hls(streamInfo.getWss_hls().replace(streamInfo.getIp(), localAddr)); + } + if (streamInfo.getRtc() != null) { + streamInfo.setRtc(streamInfo.getRtc().replace(streamInfo.getIp(), localAddr)); + } + } + result.setCode(0); result.setMsg("scccess"); - result.setData(streamInfoByAppAndStreamWithCheck); + result.setData(streamInfo); }else { result.setCode(-1); result.setMsg("fail");