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");