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
|
3.12.2
|
||||||
========================
|
========================
|
||||||
* Fix: Some Cam4 URLs where broken
|
* 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
|
3.12.1
|
||||||
========================
|
========================
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package ctbrec.recorder.download.hls;
|
package ctbrec.recorder.download.hls;
|
||||||
|
|
||||||
import static ctbrec.recorder.download.StreamSource.*;
|
import static ctbrec.recorder.download.StreamSource.*;
|
||||||
|
import static java.util.concurrent.TimeUnit.*;
|
||||||
|
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -41,6 +42,8 @@ public class HlsdlDownload extends AbstractDownload {
|
||||||
protected transient Config config;
|
protected transient Config config;
|
||||||
protected transient Process hlsdlProcess;
|
protected transient Process hlsdlProcess;
|
||||||
protected transient boolean running;
|
protected transient boolean running;
|
||||||
|
protected transient Instant lastSizeChange = Instant.now();
|
||||||
|
protected transient long lastSize = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Config config, Model model, Instant startTime) {
|
public void init(Config config, Model model, Instant startTime) {
|
||||||
|
@ -60,22 +63,33 @@ public class HlsdlDownload extends AbstractDownload {
|
||||||
Thread.currentThread().setName(threadName);
|
Thread.currentThread().setName(threadName);
|
||||||
Files.createDirectories(targetFile.getParentFile().toPath());
|
Files.createDirectories(targetFile.getParentFile().toPath());
|
||||||
|
|
||||||
Thread splittingMonitor = new Thread(() -> {
|
Thread processMonitor = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
while (running) {
|
while (running) {
|
||||||
if (splittingStrategy.splitNecessary(HlsdlDownload.this)) {
|
if (splittingStrategy.splitNecessary(HlsdlDownload.this)) {
|
||||||
LOG.debug("splitting strategy {} triggered split", splittingStrategy.getClass().getSimpleName());
|
LOG.debug("splitting strategy {} triggered split", splittingStrategy.getClass().getSimpleName());
|
||||||
stop();
|
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) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
splittingMonitor.setName(threadName + " splitter");
|
processMonitor.setName(threadName + " monitor");
|
||||||
splittingMonitor.setDaemon(true);
|
processMonitor.setDaemon(true);
|
||||||
splittingMonitor.start();
|
processMonitor.start();
|
||||||
|
|
||||||
Hlsdl hlsdl = new Hlsdl.Builder()
|
Hlsdl hlsdl = new Hlsdl.Builder()
|
||||||
.logOutput(config.getSettings().loghlsdlOutput)
|
.logOutput(config.getSettings().loghlsdlOutput)
|
||||||
|
|
Loading…
Reference in New Issue