|
@ -39,7 +39,8 @@ public class PlayController { |
|
|
private ZLMRESTfulUtils zlmresTfulUtils; |
|
|
private ZLMRESTfulUtils zlmresTfulUtils; |
|
|
|
|
|
|
|
|
@GetMapping("/play/{deviceId}/{channelId}") |
|
|
@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); |
|
|
Device device = storager.queryVideoDevice(deviceId); |
|
|
StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
|
|
StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
|
@ -64,40 +65,49 @@ public class PlayController { |
|
|
long startTime = System.currentTimeMillis(); |
|
|
long startTime = System.currentTimeMillis(); |
|
|
JSONObject rtpInfo = null; |
|
|
JSONObject rtpInfo = null; |
|
|
|
|
|
|
|
|
while (lockFlag) { |
|
|
if (getEncoding == 1) { |
|
|
try { |
|
|
while (lockFlag) { |
|
|
if (System.currentTimeMillis() - startTime > 60 * 1000) { |
|
|
try { |
|
|
storager.stopPlay(streamInfo); |
|
|
if (System.currentTimeMillis() - startTime > 60 * 1000) { |
|
|
logger.info("播放等待超时"); |
|
|
storager.stopPlay(streamInfo); |
|
|
return new ResponseEntity<String>("timeout", HttpStatus.OK); |
|
|
logger.info("播放等待超时"); |
|
|
} else { |
|
|
return new ResponseEntity<String>("timeout", HttpStatus.OK); |
|
|
streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
|
|
} else { |
|
|
if (!rtpPushed) { |
|
|
streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
|
|
logger.info("查询RTP推流信息..."); |
|
|
if (!rtpPushed) { |
|
|
rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); |
|
|
logger.info("查询RTP推流信息..."); |
|
|
} |
|
|
rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); |
|
|
if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null && streamInfo.getFlv() != null) { |
|
|
} |
|
|
logger.info("查询流编码信息:" + streamInfo.getFlv()); |
|
|
if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null |
|
|
rtpPushed = true; |
|
|
&& streamInfo.getFlv() != null) { |
|
|
Thread.sleep(2000); |
|
|
logger.info("查询流编码信息:" + streamInfo.getFlv()); |
|
|
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); |
|
|
rtpPushed = true; |
|
|
if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { |
|
|
Thread.sleep(2000); |
|
|
lockFlag = false; |
|
|
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); |
|
|
logger.info("流编码信息已获取"); |
|
|
if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { |
|
|
JSONArray tracks = mediaInfo.getJSONArray("tracks"); |
|
|
lockFlag = false; |
|
|
streamInfo.setTracks(tracks); |
|
|
logger.info("流编码信息已获取"); |
|
|
storager.startPlay(streamInfo); |
|
|
JSONArray tracks = mediaInfo.getJSONArray("tracks"); |
|
|
|
|
|
streamInfo.setTracks(tracks); |
|
|
|
|
|
storager.startPlay(streamInfo); |
|
|
|
|
|
} else { |
|
|
|
|
|
logger.info("流编码信息未获取,2秒后重试..."); |
|
|
|
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
logger.info("流编码信息未获取,2秒后重试..."); |
|
|
Thread.sleep(2000); |
|
|
|
|
|
continue; |
|
|
} |
|
|
} |
|
|
} 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()) { |
|
|
if (logger.isDebugEnabled()) { |
|
|