From 4e9c6b2f91210a714d8cdc2468bbe1e311a05a03 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期二, 17 十一月 2020 17:41:19 +0800 Subject: [PATCH] 配置丢失了一个空格 --- src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java | 83 ++++++++++++++++++++++++----------------- 1 files changed, 49 insertions(+), 34 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..a01748e 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); @@ -55,7 +61,6 @@ storager.stopPlay(streamInfo); streamInfo = cmder.playStreamCmd(device, channelId); } - } String streamId = String.format("%08x", Integer.parseInt(streamInfo.getSsrc())).toUpperCase(); // 绛夊緟鎺ㄦ祦, TODO 榛樿瓒呮椂30s @@ -64,40 +69,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()) { @@ -120,7 +134,7 @@ cmder.streamByeCmd(ssrc); StreamInfo streamInfo = storager.queryPlayBySSRC(ssrc); if (streamInfo == null) - return new ResponseEntity<String>(HttpStatus.PAYMENT_REQUIRED); + return new ResponseEntity<String>("ssrc not found", HttpStatus.OK); storager.stopPlay(streamInfo); if (logger.isDebugEnabled()) { logger.debug(String.format("璁惧棰勮鍋滄API璋冪敤锛宻src锛�%s", ssrc)); @@ -136,3 +150,4 @@ } } } + -- Gitblit v1.8.0