| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | |
| | | |
| | | } |
| | | String streamId = String.format("%08x", Integer.parseInt(streamInfo.getSsrc())).toUpperCase(); |
| | | // 等待推流, TODO 默认超时15s |
| | | // 等待推流, TODO 默认超时30s |
| | | boolean lockFlag = true; |
| | | long startTime = System.currentTimeMillis(); |
| | | |
| | | while (lockFlag) { |
| | | try { |
| | | |
| | | if (System.currentTimeMillis() - startTime > 15 * 1000) { |
| | | if (System.currentTimeMillis() - startTime > 30 * 1000) { |
| | | storager.stopPlay(streamInfo); |
| | | return new ResponseEntity<String>("timeout",HttpStatus.OK); |
| | | }else { |
| | | streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
| | | JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); |
| | | Boolean exist = rtpInfo.getBoolean("exist"); |
| | | if (rtpInfo == null || !rtpInfo.getBoolean("exist") || streamInfo.getFlv() != null){ |
| | | continue; |
| | | }else { |
| | | lockFlag = false; |
| | | streamInfo = storager.queryPlay(streamInfo); |
| | | // 获取媒体信息 |
| | | JSONObject mediaList = zlmresTfulUtils.getMediaList("rtp", "rtmp"); |
| | | if (mediaList.getInteger("code") == 0) { |
| | | JSONArray data = mediaList.getJSONArray("data"); |
| | | if (data!= null) { |
| | | for (Object datum : data) { |
| | | JSONObject media = (JSONObject)datum; |
| | | if (streamId.equals(media.getString("stream"))) { |
| | | streamInfo.setTracks(media.getJSONArray("tracks")); |
| | | storager.startPlay(streamInfo); |
| | | } |
| | | } |
| | | } |
| | | if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo.getFlv() != null){ |
| | | JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); |
| | | if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { |
| | | lockFlag = false; |
| | | JSONArray tracks = mediaInfo.getJSONArray("tracks"); |
| | | streamInfo.setTracks(tracks); |
| | | storager.startPlay(streamInfo); |
| | | }else { |
| | | |
| | | } |
| | | }else { |
| | | Thread.sleep(2000); |
| | | continue; |
| | | }; |
| | | } |
| | | Thread.sleep(200); |
| | | streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |