From 1af77ab5f7c11a4b3d59c1989b51b9fca29679ce Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期二, 18 十月 2022 22:18:49 +0800 Subject: [PATCH] Merge pull request #645 from IKangXu/wvp-28181-2.0 --- src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java | 109 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 79 insertions(+), 30 deletions(-) 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 b4b7469..6f7132e 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 @@ -1,22 +1,28 @@ package com.genersoft.iot.vmp.vmanager.gb28181.media; import com.genersoft.iot.vmp.common.StreamInfo; -import com.genersoft.iot.vmp.service.IStreamPushService; +import com.genersoft.iot.vmp.conf.exception.ControllerException; +import com.genersoft.iot.vmp.conf.security.SecurityUtils; +import com.genersoft.iot.vmp.conf.security.dto.LoginUser; +import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo; +import com.genersoft.iot.vmp.service.IStreamProxyService; import com.genersoft.iot.vmp.service.IMediaService; -import com.genersoft.iot.vmp.storager.IVideoManagerStorager; +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 = "濯掍綋娴佺浉鍏�") + +@Tag(name = "濯掍綋娴佺浉鍏�") @Controller @CrossOrigin @RequestMapping(value = "/api/media") @@ -25,13 +31,12 @@ private final static Logger logger = LoggerFactory.getLogger(MediaController.class); @Autowired - private IVideoManagerStorager storager; - - @Autowired - private IStreamPushService streamPushService; + private IRedisCatchStorage redisCatchStorage; @Autowired private IMediaService mediaService; + @Autowired + private IStreamProxyService streamProxyService; /** @@ -40,28 +45,72 @@ * @param stream 娴乮d * @return */ - @ApiOperation("鏍规嵁搴旂敤鍚嶅拰娴乮d鑾峰彇鎾斁鍦板潃") - @ApiImplicitParams({ - @ApiImplicitParam(name = "app", value = "搴旂敤鍚�", dataTypeClass = String.class), - @ApiImplicitParam(name = "stream", value = "娴乮d", dataTypeClass = String.class), - @ApiImplicitParam(name = "mediaServerId", value = "濯掍綋鏈嶅姟鍣╥d", dataTypeClass = String.class), - }) + @Operation(summary = "鏍规嵁搴旂敤鍚嶅拰娴乮d鑾峰彇鎾斁鍦板潃") + @Parameter(name = "app", description = "搴旂敤鍚�", required = true) + @Parameter(name = "stream", description = "娴乮d", required = true) + @Parameter(name = "mediaServerId", description = "濯掍綋鏈嶅姟鍣╥d") + @Parameter(name = "callId", description = "鎺ㄦ祦鏃舵惡甯︾殑鑷畾涔夐壌鏉僆D") + @Parameter(name = "useSourceIpAsStreamIp", description = "鏄惁浣跨敤璇锋眰IP浣滀负杩斿洖鐨勫湴鍧�IP") @GetMapping(value = "/stream_info_by_app_and_stream") @ResponseBody - public WVPResult<StreamInfo> getStreamInfoByAppAndStream(@RequestParam String app, @RequestParam String stream, @RequestParam String mediaServerId){ - StreamInfo streamInfoByAppAndStreamWithCheck = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId); - WVPResult<StreamInfo> result = new WVPResult<>(); - if (streamInfoByAppAndStreamWithCheck != null){ - result.setCode(0); - result.setMsg("scccess"); - result.setData(streamInfoByAppAndStreamWithCheck); + public StreamInfo getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app, + @RequestParam String stream, + @RequestParam(required = false) String mediaServerId, + @RequestParam(required = false) String callId, + @RequestParam(required = false) Boolean useSourceIpAsStreamIp){ + boolean authority = false; + if (callId != null) { + // 鏉冮檺鏍¢獙 + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); + if (streamAuthorityInfo.getCallId().equals(callId)) { + authority = true; + }else { + throw new ControllerException(ErrorCode.ERROR400); + } }else { - result.setCode(-1); - result.setMsg("fail"); + // 鏄惁鐧婚檰鐢ㄦ埛, 鐧婚檰鐢ㄦ埛杩斿洖瀹屾暣淇℃伅 + LoginUser userInfo = SecurityUtils.getUserInfo(); + if (userInfo!= null) { + authority = true; + } } - return result; + + StreamInfo streamInfo; + + if (useSourceIpAsStreamIp != null && useSourceIpAsStreamIp) { + String host = request.getHeader("Host"); + String localAddr = host.split(":")[0]; + logger.info("浣跨敤{}浣滀负杩斿洖娴佺殑ip", localAddr); + streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, localAddr, authority); + }else { + streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority); + } + + WVPResult<StreamInfo> result = new WVPResult<>(); + if (streamInfo != null){ + return streamInfo; + }else { + //鑾峰彇娴佸け璐ワ紝閲嶅惎鎷夋祦鍚庨噸璇曚竴娆� + streamProxyService.stop(app,stream); + boolean start = streamProxyService.start(app, stream); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + logger.error("[绾跨▼浼戠湢澶辫触]锛� {}", e.getMessage()); + } + if (useSourceIpAsStreamIp != null && useSourceIpAsStreamIp) { + String host = request.getHeader("Host"); + String localAddr = host.split(":")[0]; + logger.info("浣跨敤{}浣滀负杩斿洖娴佺殑ip", localAddr); + streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, localAddr, authority); + }else { + streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority); + } + if (streamInfo != null){ + return streamInfo; + }else { + throw new ControllerException(ErrorCode.ERROR100); + } + } } - - - } -- Gitblit v1.8.0