648540858
2024-03-21 3291c4b2e67d510186ca5fbfac8ec5af1a9d4f16
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java
old mode 100644 new mode 100755
@@ -2,16 +2,18 @@
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.security.JwtUtils;
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.service.IStreamProxyService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -24,7 +26,7 @@
@Tag(name  = "媒体流相关")
@Controller
@CrossOrigin
@RequestMapping(value = "/api/media")
public class MediaController {
@@ -45,7 +47,7 @@
     * @param stream 流id
     * @return
     */
    @Operation(summary = "根据应用名和流id获取播放地址")
    @Operation(summary = "根据应用名和流id获取播放地址", security = @SecurityRequirement(name = JwtUtils.HEADER))
    @Parameter(name = "app", description = "应用名", required = true)
    @Parameter(name = "stream", description = "流id", required = true)
    @Parameter(name = "mediaServerId", description = "媒体服务器id")
@@ -53,11 +55,11 @@
    @Parameter(name = "useSourceIpAsStreamIp", description = "是否使用请求IP作为返回的地址IP")
    @GetMapping(value = "/stream_info_by_app_and_stream")
    @ResponseBody
    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){
    public StreamContent 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) {
            // 权限校验
@@ -67,7 +69,7 @@
                    && streamAuthorityInfo.getCallId().equals(callId)) {
                authority = true;
            }else {
                throw new ControllerException(ErrorCode.ERROR400);
                throw new ControllerException(ErrorCode.ERROR400.getCode(), "获取播放地址鉴权失败");
            }
        }else {
            // 是否登陆用户, 登陆用户返回完整信息
@@ -88,9 +90,8 @@
            streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
        }
        WVPResult<StreamInfo> result = new WVPResult<>();
        if (streamInfo != null){
            return  streamInfo;
            return  new StreamContent(streamInfo);
        }else {
            //获取流失败,重启拉流后重试一次
            streamProxyService.stop(app,stream);
@@ -109,7 +110,7 @@
                streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
            }
            if (streamInfo != null){
                return  streamInfo;
                return new StreamContent(streamInfo);
            }else {
                throw new ControllerException(ErrorCode.ERROR100);
            }