forked from j62/ctbrec
1
0
Fork 0

Fix race condition

The streaming thread might end before the merge thread. In that
case the download would terminate before all data has been written.
This commit is contained in:
0xboobface 2018-10-23 17:17:23 +02:00
parent 5b39bf2a3e
commit 51f0883b64
1 changed files with 4 additions and 2 deletions

View File

@ -1,7 +1,6 @@
package ctbrec.recorder.download;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.WRITE;
import static java.nio.file.StandardOpenOption.*;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
@ -66,10 +65,13 @@ public class MergedHlsDownload extends AbstractHlsDownload {
mergeThread = createMergeThread(targetFile, progressListener, false);
mergeThread.start();
downloadSegments(segmentPlaylistUri, false);
mergeThread.join();
} catch(ParseException e) {
throw new IOException("Couldn't parse stream information", e);
} catch(PlaylistException e) {
throw new IOException("Couldn't parse HLS playlist", e);
} catch (InterruptedException e) {
throw new IOException("Couldn't wait for write thread to finish. Recording might be cut off", e);
} finally {
alive = false;
streamer.stop();