|  |  | 
 |  |  | package com.genersoft.iot.vmp.vmanager.gb28181.media; | 
 |  |  |  | 
 |  |  | import com.genersoft.iot.vmp.common.StreamInfo; | 
 |  |  | 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.IRedisCatchStorage; | 
 |  |  | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; | 
 |  |  | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | 
 |  |  | import io.swagger.v3.oas.annotations.Operation; | 
 |  |  | import io.swagger.v3.oas.annotations.Parameter; | 
 |  |  | 
 |  |  |     @Parameter(name = "useSourceIpAsStreamIp", description = "是否使用请求IP作为返回的地址IP") | 
 |  |  |     @GetMapping(value = "/stream_info_by_app_and_stream") | 
 |  |  |     @ResponseBody | 
 |  |  |     public WVPResult<StreamInfo> getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app, | 
 |  |  |     public StreamInfo getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app, | 
 |  |  |                                                              @RequestParam String stream, | 
 |  |  |                                                              @RequestParam(required = false) String mediaServerId, | 
 |  |  |                                                              @RequestParam(required = false) String callId, | 
 |  |  | 
 |  |  |             if (streamAuthorityInfo.getCallId().equals(callId)) { | 
 |  |  |                 authority = true; | 
 |  |  |             }else { | 
 |  |  |                 WVPResult<StreamInfo> result = new WVPResult<>(); | 
 |  |  |                 result.setCode(401); | 
 |  |  |                 result.setMsg("fail"); | 
 |  |  |                 return result; | 
 |  |  |                 throw new ControllerException(ErrorCode.ERROR400); | 
 |  |  |             } | 
 |  |  |         }else { | 
 |  |  |             // 是否登陆用户, 登陆用户返回完整信息 | 
 |  |  | 
 |  |  |  | 
 |  |  |         WVPResult<StreamInfo> result = new WVPResult<>(); | 
 |  |  |         if (streamInfo != null){ | 
 |  |  |             result.setCode(0); | 
 |  |  |             result.setMsg("scccess"); | 
 |  |  |             result.setData(streamInfo); | 
 |  |  |             return  streamInfo; | 
 |  |  |         }else { | 
 |  |  |             //获取流失败,重启拉流后重试一次 | 
 |  |  |             streamProxyService.stop(app,stream); | 
 |  |  | 
 |  |  |             try { | 
 |  |  |                 Thread.sleep(1000); | 
 |  |  |             } catch (InterruptedException e) { | 
 |  |  |                 e.printStackTrace(); | 
 |  |  |                 logger.error("[线程休眠失败], {}", e.getMessage()); | 
 |  |  |             } | 
 |  |  |             if (useSourceIpAsStreamIp != null && useSourceIpAsStreamIp) { | 
 |  |  |                 String host = request.getHeader("Host"); | 
 |  |  | 
 |  |  |                 streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority); | 
 |  |  |             } | 
 |  |  |             if (streamInfo != null){ | 
 |  |  |                 result.setCode(0); | 
 |  |  |                 result.setMsg("scccess"); | 
 |  |  |                 result.setData(streamInfo); | 
 |  |  |                 return  streamInfo; | 
 |  |  |             }else { | 
 |  |  |                 result.setCode(-1); | 
 |  |  |                 result.setMsg("fail"); | 
 |  |  |                 throw new ControllerException(ErrorCode.ERROR100); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  | } |