forked from j62/ctbrec
Move stalled download detection from segmentDownloadFinished() to call()
This commit is contained in:
parent
3a3d7a7b8e
commit
2f34f9a687
|
@ -23,14 +23,8 @@ import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorCompletionService;
|
import java.util.concurrent.ExecutorCompletionService;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -110,10 +104,6 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
||||||
protected abstract OutputStream getSegmentOutputStream(Segment segment) throws IOException;
|
protected abstract OutputStream getSegmentOutputStream(Segment segment) throws IOException;
|
||||||
|
|
||||||
protected void segmentDownloadFinished(SegmentDownload segmentDownload) { // NOSONAR
|
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();
|
lastSegmentDownload = Instant.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +111,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractHlsDownload call() throws Exception {
|
public AbstractHlsDownload call() throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (segmentPlaylistUrl == null) {
|
if (segmentPlaylistUrl == null) {
|
||||||
segmentPlaylistUrl = getSegmentPlaylistUrl(model);
|
segmentPlaylistUrl = getSegmentPlaylistUrl(model);
|
||||||
|
@ -146,6 +137,11 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
||||||
recordingEvents.remove(0);
|
recordingEvents.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
LOG.error("Couldn't parse HLS playlist for model {}\n{}", model, e.getInput(), e);
|
LOG.error("Couldn't parse HLS playlist for model {}\n{}", model, e.getInput(), e);
|
||||||
stop();
|
stop();
|
||||||
|
@ -235,7 +231,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
||||||
for (StreamSource streamSource : streamSources) {
|
for (StreamSource streamSource : streamSources) {
|
||||||
LOG.debug("{} src {}", model.getName(), streamSource);
|
LOG.debug("{} src {}", model.getName(), streamSource);
|
||||||
}
|
}
|
||||||
String url = null;
|
String url;
|
||||||
if (model.getStreamUrlIndex() >= 0 && model.getStreamUrlIndex() < streamSources.size()) {
|
if (model.getStreamUrlIndex() >= 0 && model.getStreamUrlIndex() < streamSources.size()) {
|
||||||
// TODO don't use the index, but the bandwidth. if the bandwidth does not match, take the closest one
|
// TODO don't use the index, but the bandwidth. if the bandwidth does not match, take the closest one
|
||||||
StreamSource source = streamSources.get(model.getStreamUrlIndex());
|
StreamSource source = streamSources.get(model.getStreamUrlIndex());
|
||||||
|
@ -275,7 +271,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
||||||
try (Response response = client.execute(request, config.getSettings().playlistRequestTimeout)) {
|
try (Response response = client.execute(request, config.getSettings().playlistRequestTimeout)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
consecutivePlaylistTimeouts = 0;
|
consecutivePlaylistTimeouts = 0;
|
||||||
String body = response.body().string();
|
String body = Objects.requireNonNull(response.body()).string();
|
||||||
if (!body.contains("#EXTINF")) {
|
if (!body.contains("#EXTINF")) {
|
||||||
// no segments, empty playlist
|
// no segments, empty playlist
|
||||||
return new SegmentPlaylist(segmentPlaylistUrl);
|
return new SegmentPlaylist(segmentPlaylistUrl);
|
||||||
|
|
Loading…
Reference in New Issue