From da29dad8676b38b3e29396db1442d0ede6f6385d Mon Sep 17 00:00:00 2001 From: Ali Abdallah Date: Sun, 21 Oct 2018 11:14:16 +0200 Subject: [PATCH] Check for sparse video files only on plugin side. Move the sparse video files check to ffmpeg and gstreamer plugins. --- .../ffmpeg-thumbnailer/ffmpeg-thumbnailer.c | 8 +++++ plugins/gst-thumbnailer/gst-thumbnailer.c | 8 +++++ tumbler/tumbler-util.c | 35 +++++++++++++++++++ tumbler/tumbler-util.h | 4 +++ tumblerd/tumbler-registry.c | 30 ---------------- 5 files changed, 55 insertions(+), 30 deletions(-) diff --git a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c index 81f2922..6bc9de3 100644 --- a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c +++ b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c @@ -183,6 +183,14 @@ ffmpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, if (g_cancellable_is_cancelled (cancellable)) return; + /* Check if is a sparse video file */ + if (tumbler_util_guess_is_sparse (info)) + { + g_debug ("Video file '%s' is probably sparse, skipping\n", + tumbler_file_info_get_uri (info)); + return; + } + /* fetch required info */ thumbnail = tumbler_file_info_get_thumbnail (info); g_assert (thumbnail != NULL); diff --git a/plugins/gst-thumbnailer/gst-thumbnailer.c b/plugins/gst-thumbnailer/gst-thumbnailer.c index 284a0b9..73f884b 100644 --- a/plugins/gst-thumbnailer/gst-thumbnailer.c +++ b/plugins/gst-thumbnailer/gst-thumbnailer.c @@ -570,6 +570,14 @@ gst_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, if (g_cancellable_is_cancelled (cancellable)) return; + /* Check if is a sparse video file */ + if (tumbler_util_guess_is_sparse (info)) + { + g_debug ("Video file '%s' is probably sparse, skipping\n", + tumbler_file_info_get_uri (info)); + return; + } + /* get size of dest thumb */ thumbnail = tumbler_file_info_get_thumbnail (info); flavor = tumbler_thumbnail_get_flavor (thumbnail); diff --git a/tumbler/tumbler-util.c b/tumbler/tumbler-util.c index 9d656d5..a414e26 100644 --- a/tumbler/tumbler-util.c +++ b/tumbler/tumbler-util.c @@ -29,8 +29,12 @@ #include #include +#include + #include +/* Float block size used in the stat struct */ +#define TUMBLER_STAT_BLKSIZE 512. gchar ** @@ -130,3 +134,34 @@ tumbler_util_get_settings (void) return settings; } + + +gboolean tumbler_util_guess_is_sparse (TumblerFileInfo *info) +{ + gchar *filename; + struct stat sb; + gboolean ret_val = FALSE; + + g_return_val_if_fail (TUMBLER_IS_FILE_INFO (info), FALSE); + + filename = g_filename_from_uri (tumbler_file_info_get_uri (info), NULL, NULL); + + if (G_LIKELY(filename)) + { + stat (filename, &sb); + + g_free (filename); + + /* Test sparse files on regular ones */ + if (S_ISREG (sb.st_mode)) + { + if (((TUMBLER_STAT_BLKSIZE * sb.st_blocks) / sb.st_size) < 0.8) + { + ret_val = TRUE; + } + } + } + + return ret_val; +} + diff --git a/tumbler/tumbler-util.h b/tumbler/tumbler-util.h index b68db0a..809332e 100644 --- a/tumbler/tumbler-util.h +++ b/tumbler/tumbler-util.h @@ -23,12 +23,16 @@ #include +#include + G_BEGIN_DECLS gchar **tumbler_util_get_supported_uri_schemes (void) G_GNUC_MALLOC; GKeyFile *tumbler_util_get_settings (void) G_GNUC_MALLOC; +gboolean tumbler_util_guess_is_sparse (TumblerFileInfo *info); + G_END_DECLS #endif /* !__TUMBLER_UTIL_H__ */ diff --git a/tumblerd/tumbler-registry.c b/tumblerd/tumbler-registry.c index b87e2c1..317c853 100644 --- a/tumblerd/tumbler-registry.c +++ b/tumblerd/tumbler-registry.c @@ -26,7 +26,6 @@ #include #include -#include #include @@ -34,8 +33,6 @@ #include #include -/* Float block size used in the stat struct */ -#define TUMBLER_STAT_BLKSIZE 512. static void tumbler_registry_finalize (GObject *object); static void tumbler_registry_remove_thumbnailer (const gchar *key, @@ -465,38 +462,11 @@ tumbler_registry_get_thumbnailer_array (TumblerRegistry *registry, /* iterate over all URIs */ for (n = 0; n < length; ++n) { - gchar *filename; - struct stat sb; - g_assert (TUMBLER_IS_FILE_INFO (infos[n])); /* reset */ file_size = 0; - filename = g_filename_from_uri (tumbler_file_info_get_uri (infos[n]), NULL, NULL); - - if (G_LIKELY(filename)) - { - stat (filename, &sb); - - g_free (filename); - - /* Test sparse files on regular ones */ - if (S_ISREG (sb.st_mode)) - { - if (((TUMBLER_STAT_BLKSIZE * sb.st_blocks) / sb.st_size) < 0.8) - { - g_debug ("'%s' is probably a sparse file, skipping\n", tumbler_file_info_get_uri (infos[n])); - continue; - } - } - } - else - { - g_warning ("Failed to get filename from uri for '%s', skipping\n", tumbler_file_info_get_uri (infos[n])); - continue; - } - /* determine the URI scheme and generate a hash key */ gfile = g_file_new_for_uri (tumbler_file_info_get_uri (infos[n])); scheme = g_file_get_uri_scheme (gfile); -- 2.19.1