From 33b51c40ddd9750a19b2c6a6618fb22386f87cd7 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期五, 13 十一月 2020 18:12:21 +0800 Subject: [PATCH] 增加强制不查询编码信息配置 --- src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java | 80 ++++++++++++++++++++++++---------------- 1 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java index 00f268c..c9b2d34 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java @@ -38,9 +38,15 @@ @Autowired private ZLMRESTfulUtils zlmresTfulUtils; - @GetMapping("/play/{deviceId}/{channelId}") - public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId) { + @Value("${media.closeWaitRTPInfo}") + private boolean closeWaitRTPInfo; + @GetMapping("/play/{deviceId}/{channelId}") + public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId, + Integer getEncoding) { + + if (getEncoding == null) getEncoding = 0; + getEncoding = closeWaitRTPInfo ? 0: getEncoding; Device device = storager.queryVideoDevice(deviceId); StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId); @@ -64,40 +70,49 @@ long startTime = System.currentTimeMillis(); JSONObject rtpInfo = null; - while (lockFlag) { - try { - if (System.currentTimeMillis() - startTime > 60 * 1000) { - storager.stopPlay(streamInfo); - logger.info("鎾斁绛夊緟瓒呮椂"); - return new ResponseEntity<String>("timeout", HttpStatus.OK); - } else { - streamInfo = storager.queryPlayByDevice(deviceId, channelId); - if (!rtpPushed) { - logger.info("鏌ヨRTP鎺ㄦ祦淇℃伅..."); - rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); - } - if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null && streamInfo.getFlv() != null) { - logger.info("鏌ヨ娴佺紪鐮佷俊鎭細" + streamInfo.getFlv()); - rtpPushed = true; - Thread.sleep(2000); - JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); - if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { - lockFlag = false; - logger.info("娴佺紪鐮佷俊鎭凡鑾峰彇"); - JSONArray tracks = mediaInfo.getJSONArray("tracks"); - streamInfo.setTracks(tracks); - storager.startPlay(streamInfo); - } else { - logger.info("娴佺紪鐮佷俊鎭湭鑾峰彇锛�2绉掑悗閲嶈瘯..."); - } + if (getEncoding == 1) { + while (lockFlag) { + try { + if (System.currentTimeMillis() - startTime > 60 * 1000) { + storager.stopPlay(streamInfo); + logger.info("鎾斁绛夊緟瓒呮椂"); + return new ResponseEntity<String>("timeout", HttpStatus.OK); } else { - Thread.sleep(2000); - continue; + streamInfo = storager.queryPlayByDevice(deviceId, channelId); + if (!rtpPushed) { + logger.info("鏌ヨRTP鎺ㄦ祦淇℃伅..."); + rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); + } + if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null + && streamInfo.getFlv() != null) { + logger.info("鏌ヨ娴佺紪鐮佷俊鎭細" + streamInfo.getFlv()); + rtpPushed = true; + Thread.sleep(2000); + JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); + if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { + lockFlag = false; + logger.info("娴佺紪鐮佷俊鎭凡鑾峰彇"); + JSONArray tracks = mediaInfo.getJSONArray("tracks"); + streamInfo.setTracks(tracks); + storager.startPlay(streamInfo); + } else { + logger.info("娴佺紪鐮佷俊鎭湭鑾峰彇锛�2绉掑悗閲嶈瘯..."); + } + } else { + Thread.sleep(2000); + continue; + } } + } catch (InterruptedException e) { + e.printStackTrace(); } - } catch (InterruptedException e) { - e.printStackTrace(); } + } else { + String flv = storager.getMediaInfo().getWanIp() + ":" + storager.getMediaInfo().getHttpPort() + "/rtp/" + + streamId + ".flv"; + streamInfo.setFlv("http://" + flv); + streamInfo.setWs_flv("ws://" + flv); + storager.startPlay(streamInfo); } if (logger.isDebugEnabled()) { @@ -136,3 +151,4 @@ } } } + -- Gitblit v1.8.0