Fix OutOfMemoryErrors

1. Catch exceptions thrown by ContinuityFixer and skip to the next
packet.
2. Restrict the queue size to 10 segments. Otherwise, if the download
is faster than the stream is written to hard disk, the queue builds
up with segments until the heap exceeds its maximum size
This commit is contained in:
0xboobface 2018-09-10 17:52:11 +02:00
parent dd316070a5
commit dba4aa0a02
1 changed files with 7 additions and 2 deletions

View File

@ -28,7 +28,7 @@ public class BlockingMultiMTSSource extends AbstractMTSSource implements AutoClo
if (fixContinuity) {
continuityFixer = new ContinuityFixer();
}
this.sources = new LinkedBlockingQueue<>();
this.sources = new LinkedBlockingQueue<>(10);
}
public void addSource(MTSSource source) throws InterruptedException {
@ -45,7 +45,12 @@ public class BlockingMultiMTSSource extends AbstractMTSSource implements AutoClo
packet = switchSourceIfNeeded(packet);
if (fixContinuity) {
continuityFixer.fixContinuity(packet);
try {
continuityFixer.fixContinuity(packet);
} catch(Exception e) {
LOG.error("Failed to fix continuity. MTSPacket probably invalid", e);
return nextPacketInternal();
}
}
return packet;
}