Add stalled download detection
If no segments have been transfered for 30 seconds, the download will be stopped.
This commit is contained in:
parent
b8971c7190
commit
b13c4f1622
|
@ -72,6 +72,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
|||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(AbstractHlsDownload.class);
|
||||
private static final int A_FEW_SECONDS = 10_000;
|
||||
private static final int MAX_SECONDS_WITHOUT_TRANSFER = 30;
|
||||
|
||||
private transient NumberFormat nf = new DecimalFormat("000000");
|
||||
private transient int playlistEmptyCount = 0;
|
||||
|
@ -87,6 +88,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
|||
private transient Instant beforeLastPlaylistRequest= Instant.EPOCH;
|
||||
private transient int consecutivePlaylistTimeouts = 0;
|
||||
private transient int consecutivePlaylistErrors = 0;
|
||||
private transient Instant lastSegmentDownload = Instant.MAX;
|
||||
|
||||
private transient List<RecordingEvent> recordingEvents = new LinkedList<>();
|
||||
|
||||
|
@ -95,7 +97,15 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
|||
}
|
||||
|
||||
protected abstract OutputStream getSegmentOutputStream(String prefix, String fileName) throws IOException;
|
||||
protected void segmentDownloadFinished(SegmentDownload segmentDownload) {}
|
||||
|
||||
protected void segmentDownloadFinished(SegmentDownload segmentDownload) { // NOSONAR
|
||||
if (Duration.between(lastSegmentDownload, Instant.now()).getSeconds() > MAX_SECONDS_WITHOUT_TRANSFER) {
|
||||
LOG.info("No video data received for {} seconds. Stopping recording for model {}", MAX_SECONDS_WITHOUT_TRANSFER, model);
|
||||
stop();
|
||||
}
|
||||
lastSegmentDownload = Instant.now();
|
||||
}
|
||||
|
||||
protected abstract void internalStop();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -138,6 +138,7 @@ public class HlsDownload extends AbstractHlsDownload {
|
|||
|
||||
@Override
|
||||
protected void segmentDownloadFinished(SegmentDownload segmentDownload) {
|
||||
super.segmentDownloadFinished(segmentDownload);
|
||||
IoUtils.close(segmentDownload.getOutputStream(), "Couldn't close segment file");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue