aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-10-27 15:20:30 +0200
committerdec05eba <dec05eba@protonmail.com>2021-10-27 18:22:29 +0200
commitbb80d168af2c5e36903dd61473fdbd3840846d7f (patch)
treea32bfbca3d4f47b3eb1747d6226030dafc057a7a /src
parent9aecfa8da5daae017ce3ff21fd6b496fda2a690b (diff)
Stop download of thumbnail if the thumbnail is no longer visible on the screen
Diffstat (limited to 'src')
-rw-r--r--src/AsyncImageLoader.cpp37
1 files changed, 29 insertions, 8 deletions
diff --git a/src/AsyncImageLoader.cpp b/src/AsyncImageLoader.cpp
index f926a8d..762408c 100644
--- a/src/AsyncImageLoader.cpp
+++ b/src/AsyncImageLoader.cpp
@@ -236,14 +236,7 @@ namespace QuickMedia {
} else {
fprintf(stderr, "Thumbnail download failed for %s\n", download.url.c_str());
}
-
- std::lock_guard<std::mutex> lock(download_mutex);
- close(download.read_program.read_fd);
- download.read_program.pid = -1;
- download.read_program.read_fd = -1;
- download.thumbnail_path.data.clear();
- download.url.c_str();
- download.thumbnail_data = nullptr;
+ reset_download(download);
}
}
@@ -336,6 +329,19 @@ namespace QuickMedia {
bool loaded_textures_changed = false;
for(auto it = thumbnails.begin(); it != thumbnails.end();) {
if(it->second->counter != counter) {
+ {
+ for(int i = 0; i < NUM_IMAGE_LOAD_PARALLEL; ++i) {
+ Download &download = downloads[i];
+ if(download.read_program.pid == -1)
+ continue;
+
+ if(download.url == it->first) {
+ reset_download(download);
+ break;
+ }
+ }
+ }
+
image_load_queue.erase_if([&it](ThumbnailLoadData &load_data) {
return load_data.path.data == it->first;
});
@@ -358,4 +364,19 @@ namespace QuickMedia {
}
return -1;
}
+
+ void AsyncImageLoader::reset_download(Download &download) {
+ std::lock_guard<std::mutex> lock(download_mutex);
+ if(download.read_program.pid != -1) {
+ kill(download.read_program.pid, SIGTERM);
+ download.read_program.pid = -1;
+ }
+ if(download.read_program.read_fd != -1) {
+ close(download.read_program.read_fd);
+ download.read_program.read_fd = -1;
+ }
+ download.thumbnail_path.data.clear();
+ download.url.c_str();
+ download.thumbnail_data = nullptr;
+ }
}