forked from j62/ctbrec
1
0
Fork 0

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
This commit is contained in:
0xboobface 2019-12-23 19:44:34 +01:00
parent a561ab08e4
commit a018b15384
1 changed files with 18 additions and 9 deletions

View File

@ -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;
}
}