|  |  |  | 
|---|
|  |  |  | 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.tags.Tag; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Tag(name  = "媒体流相关") | 
|---|
|  |  |  | @Controller | 
|---|
|  |  |  | @CrossOrigin | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/api/media") | 
|---|
|  |  |  | public class MediaController { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @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) { | 
|---|
|  |  |  | // 权限校验 | 
|---|
|  |  |  | StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); | 
|---|
|  |  |  | if (streamAuthorityInfo.getCallId().equals(callId)) { | 
|---|
|  |  |  | if (streamAuthorityInfo != null | 
|---|
|  |  |  | && streamAuthorityInfo.getCallId() != null | 
|---|
|  |  |  | && streamAuthorityInfo.getCallId().equals(callId)) { | 
|---|
|  |  |  | authority = true; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | throw new ControllerException(ErrorCode.ERROR400); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  | return  streamInfo; | 
|---|
|  |  |  | return new StreamContent(streamInfo); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | throw new ControllerException(ErrorCode.ERROR100); | 
|---|
|  |  |  | } | 
|---|