From 4e8659e156767b7f471725840b331a5ec9be9894 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期六, 07 十一月 2020 22:15:53 +0800
Subject: [PATCH] Merge pull request #10 from lawrencehj/master

---
 src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java |   72 ++++++++++++++++++++---------------
 1 files changed, 41 insertions(+), 31 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..780e950 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
@@ -39,7 +39,8 @@
 	private ZLMRESTfulUtils zlmresTfulUtils;
 
 	@GetMapping("/play/{deviceId}/{channelId}")
-	public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId) {
+	public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId,
+	Integer getEncoding) {
 
 		Device device = storager.queryVideoDevice(deviceId);
 		StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId);
@@ -64,40 +65,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().getLocalIP() + ":" + storager.getMediaInfo().getHttpPort() + "/rtp/"
+					+ streamId + ".flv";
+			streamInfo.setFlv("http://" + flv);
+			streamInfo.setWs_flv("ws://" + flv);
+			storager.startPlay(streamInfo);
 		}
 
 		if (logger.isDebugEnabled()) {

--
Gitblit v1.8.0