From a018b153842478cec948669835b32c43caf8d3ee Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Mon, 23 Dec 2019 19:44:34 +0100 Subject: [PATCH] Improve DashDownload handling of init segments After an init segment has been downloaded, check, if exists and is not empty before setting the booleans to true, which determine, that the files have been loaded --- .../recorder/download/dash/DashDownload.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java b/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java index 54f0c770..46c14cbd 100644 --- a/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java +++ b/common/src/main/java/ctbrec/recorder/download/dash/DashDownload.java @@ -137,21 +137,29 @@ public class DashDownload implements Download { String initialization = segmentTemplate.getInitializationAttribute(); initialization = initialization.replaceAll("\\$RepresentationID\\$", representation.getId()); URL initUrl = new URL(new URL(mpd.getLocation().get(0)), initialization); - download(downloadDir.toFile().getCanonicalPath(), initUrl, isVideo); - if (isVideo) { - LOG.debug("Video init chunk loaded"); - videoInitLoaded = true; - } else { - LOG.debug("Audio init chunk loaded"); - audioInitLoaded = true; - } + File file = download(downloadDir.toFile().getCanonicalPath(), initUrl, isVideo); + setInitState(isVideo, file); return 1; } else { return 0; } } - private void download(String dir, URL url, boolean isVideo) throws IOException { + private void setInitState(boolean isVideo, File file) { + if (isVideo) { + if (file.exists() && file.length() > 0) { + LOG.debug("Video init chunk loaded"); + videoInitLoaded = true; + } + } else { + if (file.exists() && file.length() > 0) { + LOG.debug("Audio init chunk loaded"); + audioInitLoaded = true; + } + } + } + + private File download(String dir, URL url, boolean isVideo) throws IOException { // @formatter:off Request request = new Request.Builder() .url(url) @@ -189,6 +197,7 @@ public class DashDownload implements Download { } tries++; } + return segmentFile; } }