diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/Makefile.am | 12 | ||||
-rw-r--r-- | src/totem-resources.c | 122 | ||||
-rw-r--r-- | src/totem-resources.h | 33 | ||||
-rw-r--r-- | src/totem-video-indexer.c | 3 | ||||
-rw-r--r-- | src/totem-video-thumbnailer.c | 62 |
6 files changed, 181 insertions, 62 deletions
@@ -1,5 +1,16 @@ 2007-04-02 Bastien Nocera <hadess@hadess.net> + * src/Makefile.am: + * src/totem-resources.c: (set_resource_limits), (time_monitor), + (totem_resources_monitor_start), (totem_resources_monitor_stop): + * src/totem-resources.h: + * src/totem-video-indexer.c: (main): + * src/totem-video-thumbnailer.c: (main): Move the resource + monitoring, and the wall-clock checking thread to a separate file, + add resource monitoring support to the video indexer + +2007-04-02 Bastien Nocera <hadess@hadess.net> + * browser-plugin/totemBasicPlugin.cpp: * browser-plugin/totemComplexPlugin.cpp: * browser-plugin/totemGMPPlugin.cpp: diff --git a/src/Makefile.am b/src/Makefile.am index 64c618021..5dba3e6f8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -170,8 +170,10 @@ totem-marshal.h: totem-marshal.list # Totem video thumbnailer -totem_video_thumbnailer_SOURCES = \ - totem-video-thumbnailer.c +totem_video_thumbnailer_SOURCES = \ + totem-video-thumbnailer.c \ + totem-resources.c \ + totem-resources.h totem_video_thumbnailer_CPPFLAGS = \ -I$(srcdir)/plparse \ @@ -277,8 +279,10 @@ endif # HAVE_NAUTILUS # Totem Video Indexer -totem_video_indexer_SOURCES = \ - totem-video-indexer.c +totem_video_indexer_SOURCES = \ + totem-video-indexer.c \ + totem-resources.c \ + totem-resources.h totem_video_indexer_CPPFLAGS = \ -I$(srcdir)/plparse \ diff --git a/src/totem-resources.c b/src/totem-resources.c new file mode 100644 index 000000000..14b924e43 --- /dev/null +++ b/src/totem-resources.c @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2007 Bastien Nocera <hadess@hadess.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Totem project hereby grant permission for non-gpl compatible GStreamer + * plugins to be used and distributed together with GStreamer and Totem. This + * permission are above and beyond the permissions granted by the GPL license + * Totem is covered by. + * + * Monday 7th February 2005: Christian Schaller: Add exception clause. + * See license_change file for details. + * + */ + +#include "config.h" + +#include <glib.h> +#include <glib/gstdio.h> +#include <glib/gthread.h> + +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/resource.h> + +#include "totem-resources.h" + +#define MAX_HELPER_MEMORY (256 * 1024 * 1024) /* 256 MB */ +#define MAX_HELPER_SECONDS (15) /* 15 seconds */ +#define DEFAULT_SLEEP_TIME (30 * G_USEC_PER_SEC) /* 30 seconds */ + +static guint sleep_time = DEFAULT_SLEEP_TIME; +static gboolean finished = TRUE; + +static void +set_resource_limits (const char *input) +{ + struct rlimit limit; + struct stat buf; + rlim_t max; + + g_return_if_fail (input != NULL); + + max = MAX_HELPER_MEMORY; + + /* Set the maximum virtual size depending on the size + * of the file to process, as we wouldn't be able to + * mmap it otherwise */ + if (g_stat (input, &buf) == 0) { + max = MAX_HELPER_MEMORY + buf.st_size; + } else if (g_str_has_prefix (input, "file://") != FALSE) { + char *file; + file = g_filename_from_uri (input, NULL, NULL); + if (file != NULL && g_stat (file, &buf) == 0) + max = MAX_HELPER_MEMORY + buf.st_size; + g_free (file); + } + + limit.rlim_cur = max; + limit.rlim_max = max; + + setrlimit (RLIMIT_DATA, &limit); + + limit.rlim_cur = MAX_HELPER_SECONDS; + limit.rlim_max = MAX_HELPER_SECONDS; + setrlimit (RLIMIT_CPU, &limit); +} + +static gpointer +time_monitor (gpointer data) +{ + const char *app_name; + + g_usleep (sleep_time); + + if (finished != FALSE) + g_thread_exit (NULL); + + app_name = g_get_application_name (); + if (app_name == NULL) + app_name = g_get_prgname (); + g_print ("%s couln't process file: '%s'\n" + "Reason: Took too much time to process.\n", + app_name, + (const char *) data); + + exit (0); +} + +void +totem_resources_monitor_start (const char *input, guint wall_clock_time) +{ + set_resource_limits (input); + + if (wall_clock_time != 0) + sleep_time = wall_clock_time; + + finished = FALSE; + g_thread_create (time_monitor, (gpointer) input, FALSE, NULL); + +} + +void +totem_resources_monitor_stop (void) +{ + finished = TRUE; +} + diff --git a/src/totem-resources.h b/src/totem-resources.h new file mode 100644 index 000000000..d1c0848f8 --- /dev/null +++ b/src/totem-resources.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2007 Bastien Nocera <hadess@hadess.net> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Totem project hereby grant permission for non-gpl compatible GStreamer + * plugins to be used and distributed together with GStreamer and Totem. This + * permission are above and beyond the permissions granted by the GPL license + * Totem is covered by. + * + * Monday 7th February 2005: Christian Schaller: Add exception clause. + * See license_change file for details. + * + */ + +#include <glib.h> + +void totem_resources_monitor_start (const char *input, + guint wall_clock_time); +void totem_resources_monitor_stop (void); + diff --git a/src/totem-video-indexer.c b/src/totem-video-indexer.c index 7d89c7216..9cc6f37f9 100644 --- a/src/totem-video-indexer.c +++ b/src/totem-video-indexer.c @@ -45,6 +45,7 @@ #include <libgnomevfs/gnome-vfs-init.h> #include <glib/gi18n.h> +#include "totem-resources.h" #include "totem-mime-types.h" static gboolean show_mimetype = FALSE; @@ -206,6 +207,7 @@ int main (int argc, char **argv) NULL); path = filenames[0]; + totem_resources_monitor_start (path, 0); if (bacon_video_widget_open (bvw, path, &error) == FALSE) { g_print ("Can't open %s: %s\n", path, error->message); return 1; @@ -214,6 +216,7 @@ int main (int argc, char **argv) g_print ("Can't play %s: %s\n", path, error->message); return 1; } + totem_resources_monitor_stop (); gtk_main (); diff --git a/src/totem-video-thumbnailer.c b/src/totem-video-thumbnailer.c index 5aeff7a36..eb158c403 100644 --- a/src/totem-video-thumbnailer.c +++ b/src/totem-video-thumbnailer.c @@ -36,12 +36,12 @@ #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> -#include <sys/resource.h> #ifndef HAVE_GTK_ONLY #include <libgnomeui/gnome-authentication-manager.h> #endif #include <libgnomevfs/gnome-vfs-init.h> #include "bacon-video-widget.h" +#include "totem-resources.h" /* #define THUMB_DEBUG */ @@ -54,7 +54,6 @@ #define HALF_SECOND G_USEC_PER_SEC * .5 #define BORING_IMAGE_VARIANCE 256.0 /* Tweak this if necessary */ -gboolean finished = FALSE; static gboolean jpeg_output = FALSE; static gboolean output_size = 128; static gboolean time_limit = TRUE; @@ -330,57 +329,6 @@ save_pixbuf (GdkPixbuf *pixbuf, const char *path, g_object_unref (with_holes); } -#define MAX_HELPER_MEMORY (256 * 1024 * 1024) /* 256 MB */ -#define MAX_HELPER_SECONDS (15) /* 15 seconds */ - -static void -set_resource_limits (const char *input) -{ - struct rlimit limit; - struct stat buf; - rlim_t max; - - g_return_if_fail (input != NULL); - - max = MAX_HELPER_MEMORY; - - /* Set the maximum virtual size depending on the size - * of the file to process, as we wouldn't be able to - * mmap it otherwise */ - if (g_stat (input, &buf) == 0) { - max = MAX_HELPER_MEMORY + buf.st_size; - } else if (g_str_has_prefix (input, "file://") != FALSE) { - char *file; - file = g_filename_from_uri (input, NULL, NULL); - if (file != NULL && g_stat (file, &buf) == 0) - max = MAX_HELPER_MEMORY + buf.st_size; - g_free (file); - } - - limit.rlim_cur = max; - limit.rlim_max = max; - - setrlimit (RLIMIT_DATA, &limit); - - limit.rlim_cur = MAX_HELPER_SECONDS; - limit.rlim_max = MAX_HELPER_SECONDS; - setrlimit (RLIMIT_CPU, &limit); -} - -static gpointer -time_monitor (gpointer data) -{ - g_usleep (30 * G_USEC_PER_SEC); - - if (finished != FALSE) - g_thread_exit (NULL); - - g_print ("totem-video-thumbnailer couln't thumbnail file: '%s'\n" - "Reason: Took too much time to thumbnail.\n", - (const char *) data); - exit (0); -} - static const GOptionEntry entries[] = { { "jpeg", 'j', 0, G_OPTION_ARG_NONE, &jpeg_output, "Output the thumbnail as a JPEG instead of PNG", NULL }, { "size", 's', 0, G_OPTION_ARG_INT, &output_size, "Size of the thumbnail in pixels", NULL }, @@ -469,10 +417,8 @@ int main (int argc, char *argv[]) PROGRESS_DEBUG("Video widget created\n"); - if (time_limit != FALSE) { - g_thread_create (time_monitor, (gpointer) input, FALSE, NULL); - set_resource_limits (input); - } + if (time_limit != FALSE) + totem_resources_monitor_start (input, 0); PROGRESS_DEBUG("About to open video file\n"); @@ -541,7 +487,7 @@ int main (int argc, char *argv[]) /* Cleanup */ bacon_video_widget_close (bvw); - finished = TRUE; + totem_resources_monitor_stop (); gtk_widget_destroy (GTK_WIDGET (bvw)); if (pixbuf == NULL) |