Stop hlsdl if the recording size didn't change for 90 seconds
This commit is contained in:
parent
7678e6041e
commit
505c501428
|
@ -1,7 +1,8 @@
|
|||
3.12.2
|
||||
========================
|
||||
* Fix: Some Cam4 URLs where broken
|
||||
* Fix Cam4 search
|
||||
* Fix: Cam4 search didn't work
|
||||
* Stop hlsdl if the recording size didn't change for 90 seconds
|
||||
|
||||
3.12.1
|
||||
========================
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package ctbrec.recorder.download.hls;
|
||||
|
||||
import static ctbrec.recorder.download.StreamSource.*;
|
||||
import static java.util.concurrent.TimeUnit.*;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -41,6 +42,8 @@ public class HlsdlDownload extends AbstractDownload {
|
|||
protected transient Config config;
|
||||
protected transient Process hlsdlProcess;
|
||||
protected transient boolean running;
|
||||
protected transient Instant lastSizeChange = Instant.now();
|
||||
protected transient long lastSize = 0;
|
||||
|
||||
@Override
|
||||
public void init(Config config, Model model, Instant startTime) {
|
||||
|
@ -60,22 +63,33 @@ public class HlsdlDownload extends AbstractDownload {
|
|||
Thread.currentThread().setName(threadName);
|
||||
Files.createDirectories(targetFile.getParentFile().toPath());
|
||||
|
||||
Thread splittingMonitor = new Thread(() -> {
|
||||
Thread processMonitor = new Thread(() -> {
|
||||
try {
|
||||
while (running) {
|
||||
if (splittingStrategy.splitNecessary(HlsdlDownload.this)) {
|
||||
LOG.debug("splitting strategy {} triggered split", splittingStrategy.getClass().getSimpleName());
|
||||
stop();
|
||||
}
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
long size = getSizeInByte();
|
||||
if (size != lastSize) {
|
||||
lastSize = size;
|
||||
lastSizeChange = Instant.now();
|
||||
} else {
|
||||
int seconds = 90;
|
||||
if (Duration.between(lastSizeChange, Instant.now()).toMillis() > SECONDS.toMillis(seconds)) {
|
||||
LOG.info("Recording size didn't change for {} secs. Stopping recording for {}", seconds, model);
|
||||
stop();
|
||||
}
|
||||
}
|
||||
SECONDS.sleep(1);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
});
|
||||
splittingMonitor.setName(threadName + " splitter");
|
||||
splittingMonitor.setDaemon(true);
|
||||
splittingMonitor.start();
|
||||
processMonitor.setName(threadName + " monitor");
|
||||
processMonitor.setDaemon(true);
|
||||
processMonitor.start();
|
||||
|
||||
Hlsdl hlsdl = new Hlsdl.Builder()
|
||||
.logOutput(config.getSettings().loghlsdlOutput)
|
||||
|
|
Loading…
Reference in New Issue