Improve server download progress calculation
This commit is contained in:
parent
b87f090ac3
commit
1bea13dc05
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -1,3 +1,14 @@
|
||||||
|
3.7.1
|
||||||
|
========================
|
||||||
|
* Server now logs in on startup, if credentials are set
|
||||||
|
* Show confirmation dialog on shutdown, if the are active downloads from the
|
||||||
|
server
|
||||||
|
* Added setting to remove recordings after post-processing
|
||||||
|
* Added max resolution setting for the player (click on the gear!)
|
||||||
|
* Added systemd service example for the server
|
||||||
|
* Server now returns the version in the HTML and HTTP headers
|
||||||
|
* Improved server download progress calculation
|
||||||
|
|
||||||
3.7.0
|
3.7.0
|
||||||
========================
|
========================
|
||||||
* Fixed the problem, that media players won't start anymore
|
* Fixed the problem, that media players won't start anymore
|
||||||
|
|
|
@ -584,7 +584,7 @@ public class RecordingsTab extends Tab implements TabSelectionListener {
|
||||||
MergedFfmpegHlsDownload download = new MergedFfmpegHlsDownload(CamrecApplication.httpClient);
|
MergedFfmpegHlsDownload download = new MergedFfmpegHlsDownload(CamrecApplication.httpClient);
|
||||||
download.init(config, recording.getModel(), Instant.now());
|
download.init(config, recording.getModel(), Instant.now());
|
||||||
LOG.info("Downloading {}", url);
|
LOG.info("Downloading {}", url);
|
||||||
download.downloadFinishedRecording(url.toString(), target, createDownloadListener(recording));
|
download.downloadFinishedRecording(url.toString(), target, createDownloadListener(recording), recording.getSizeInByte());
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
showErrorDialog(ERROR_WHILE_DOWNLOADING_RECORDING, "The target file couldn't be created", e);
|
showErrorDialog(ERROR_WHILE_DOWNLOADING_RECORDING, "The target file couldn't be created", e);
|
||||||
|
|
|
@ -470,7 +470,7 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadFinishedRecording(String segmentPlaylistUri, File target, ProgressListener progressListener) throws Exception {
|
public void downloadFinishedRecording(String segmentPlaylistUri, File target, ProgressListener progressListener, long sizeInBytes) throws Exception {
|
||||||
running = true;
|
running = true;
|
||||||
if (Config.getInstance().getSettings().requireAuthentication) {
|
if (Config.getInstance().getSettings().requireAuthentication) {
|
||||||
URL u = new URL(segmentPlaylistUri);
|
URL u = new URL(segmentPlaylistUri);
|
||||||
|
@ -489,19 +489,18 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
||||||
}
|
}
|
||||||
|
|
||||||
SegmentPlaylist segmentPlaylist = getNextSegments(segmentPlaylistUri);
|
SegmentPlaylist segmentPlaylist = getNextSegments(segmentPlaylistUri);
|
||||||
int fileCounter = 0;
|
long loadedBytes = 0;
|
||||||
for (String segmentUrl : segmentPlaylist.segments) {
|
for (String segmentUrl : segmentPlaylist.segments) {
|
||||||
downloadFile(segmentUrl);
|
loadedBytes += downloadFile(segmentUrl, loadedBytes, sizeInBytes, progressListener);
|
||||||
fileCounter++;
|
int progress = (int) (loadedBytes / (double) sizeInBytes * 100);
|
||||||
int total = segmentPlaylist.segments.size();
|
|
||||||
int progress = (int) (fileCounter / (double) total * 100);
|
|
||||||
progressListener.update(progress);
|
progressListener.update(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
internalStop();
|
internalStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadFile(String fileUri) throws IOException {
|
private long downloadFile(String fileUri, long loadedBytes, long totalBytes, ProgressListener progressListener) throws IOException {
|
||||||
|
long fileLoadedBytes = 0;
|
||||||
Request request = new Request.Builder().url(fileUri).addHeader("connection", "keep-alive").build();
|
Request request = new Request.Builder().url(fileUri).addHeader("connection", "keep-alive").build();
|
||||||
try (Response response = client.execute(request)) {
|
try (Response response = client.execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
|
@ -510,11 +509,15 @@ public class MergedFfmpegHlsDownload extends AbstractHlsDownload {
|
||||||
int length = -1;
|
int length = -1;
|
||||||
while ((length = in.read(b)) >= 0) {
|
while ((length = in.read(b)) >= 0) {
|
||||||
ffmpegStdIn.write(b, 0, length);
|
ffmpegStdIn.write(b, 0, length);
|
||||||
|
fileLoadedBytes += length;
|
||||||
|
int progress = (int) ((loadedBytes + fileLoadedBytes) / (double) totalBytes * 100);
|
||||||
|
progressListener.update(progress);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), response.message());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return fileLoadedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue