From: David S. <ds...@pd...> - 2004-02-21 00:52:20
|
CVS Root: /home/cvs/gstreamer Module: gst-sandbox Changes by: ds Date: Fri Feb 20 2004 16:45:51 PST Log message: new project * autogen.sh: * configure.ac: * gst/Makefile.am: * gst/watchdog/Makefile.am: * gst/watchdog/gstwatchdog.c: (gst_watchdog_get_type), (gst_watchdog_base_init), (gst_watchdog_class_init), (gst_watchdog_init), (gst_watchdog_dispose), (gst_watchdog_set_property), (gst_watchdog_get_property), (gst_watchdog_new), (gst_watchdog_add_bin), (gst_watchdog_remove_bin), (gst_watchdog_arm), (gst_watchdog_disarm), (gst_watchdog_ping), (gst_watchdog_find_link), (gst_watchdog_remove_bin_nounref), (gst_watchdog_bin_log_activity), (g_time_val_compare), (gst_watchdog_find_expired), (gst_watchdog_threadfunc): * gst/watchdog/gstwatchdog.h: * m4/as-ac-expand.m4: * testsuite/Makefile.am: * testsuite/test1.c: (dog_alarm), (main): Added files: gst-watchdog : ChangeLog autogen.sh configure.ac gst-watchdog/gst: Makefile.am gst-watchdog/gst/watchdog: Makefile.am gstwatchdog.c gstwatchdog.h gst-watchdog/m4 : as-ac-expand.m4 gst-watchdog/testsuite: Makefile.am test1.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/ChangeLog?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/autogen.sh?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/configure.ac?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/gst/Makefile.am?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/gst/watchdog/Makefile.am?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/gst/watchdog/gstwatchdog.c?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/gst/watchdog/gstwatchdog.h?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/m4/as-ac-expand.m4?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/testsuite/Makefile.am?rev=1.1&content-type=text/vnd.viewcvs-markup http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/gst-watchdog/testsuite/test1.c?rev=1.1&content-type=text/vnd.viewcvs-markup ====Begin Diffs==== --- NEW FILE: ChangeLog --- 2004-02-20 David Schleef <ds...@sc...> new project * autogen.sh: * configure.ac: * gst/Makefile.am: * gst/watchdog/Makefile.am: * gst/watchdog/gstwatchdog.c: (gst_watchdog_get_type), (gst_watchdog_base_init), (gst_watchdog_class_init), (gst_watchdog_init), (gst_watchdog_dispose), (gst_watchdog_set_property), (gst_watchdog_get_property), (gst_watchdog_new), (gst_watchdog_add_bin), (gst_watchdog_remove_bin), (gst_watchdog_arm), (gst_watchdog_disarm), (gst_watchdog_ping), (gst_watchdog_find_link), (gst_watchdog_remove_bin_nounref), (gst_watchdog_bin_log_activity), (g_time_val_compare), (gst_watchdog_find_expired), (gst_watchdog_threadfunc): * gst/watchdog/gstwatchdog.h: * m4/as-ac-expand.m4: * testsuite/Makefile.am: * testsuite/test1.c: (dog_alarm), (main): --- NEW FILE: autogen.sh --- #!/bin/sh set -x if test -f po/Makefile.in.in; then patch -p0 -R < gettext.patch; fi && \ autopoint && \ patch -p0 < gettext.patch && \ aclocal -I m4 && \ libtoolize --force && \ autoheader && \ autoconf && \ automake -a --foreign && \ ./configure $@ --- NEW FILE: configure.ac --- AC_INIT dnl Fill in your package name and version here PACKAGE=gst-watchdog MAJORMINOR=0.7 VERSION=$MAJORMINOR.1 dnl these AC_DEFINE_UNQUOTED's are necessary for make dist to work AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE") AC_DEFINE_UNQUOTED(VERSION, "$VERSION") AC_DEFINE_UNQUOTED(RELEASE, "$RELEASE", [Release]) AC_SUBST(PACKAGE) AC_SUBST(VERSION) AC_SUBST(RELEASE) AC_SUBST(MAJORMINOR) AM_CONFIG_HEADER(config.h) AM_INIT_AUTOMAKE($PACKAGE, $VERSION) AC_PROG_CC AC_PROG_LIBTOOL AC_SUBST(ACLOCAL_AMFLAGS, "-I m4") dnl the gettext stuff needed AM_GNU_GETTEXT_VERSION(0.12) AM_GNU_GETTEXT([external]) GETTEXT_PACKAGE=$PACKAGE-$MAJORMINOR dnl substitue this for po/Makefile.in AC_SUBST(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE") dnl define PACKAGE in config.h AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE], "$GETTEXT_PACKAGE", [gettext package name]) dnl define LOCALEDIR in config.h AS_AC_EXPAND(LOCALEDIR, $datadir/locale) AC_DEFINE_UNQUOTED([LOCALEDIR], "$LOCALEDIR", [gettext locale dir]) dnl Check for pkgconfig first AC_CHECK_PROG(HAVE_PKGCONFIG, pkg-config, yes, no) dnl Give error and exit if we don't have pkgconfig if test "x$HAVE_PKGCONFIG" = "xno"; then AC_MSG_ERROR(you need to have pkgconfig installed !) fi dnl Now we're ready to ask for gstreamer libs and cflags dnl And we can also ask for the right version of gstreamer GST_REQUIRED=0.7.3.1 dnl 0.7 required, 0.6 is too old GST_MAJORMINOR=0.7 PKG_CHECK_MODULES(GST, \ gstreamer-$GST_MAJORMINOR >= $GST_REQUIRED \ gstreamer-control-$GST_MAJORMINOR >= $GST_REQUIRED, HAVE_GST=yes,HAVE_GST=no) dnl Give error and exit if we don't have gstreamer if test "x$HAVE_GST" = "xno"; then AC_MSG_ERROR(you need gstreamer development packages installed !) GST_CFLAGS="$GST_CFLAGS -Wall -Werror" dnl make GST_CFLAGS and GST_LIBS available AC_SUBST(GST_CFLAGS) AC_SUBST(GST_LIBS) dnl make GST_MAJORMINOR available in Makefile.am AC_SUBST(GST_MAJORMINOR) dnl If we need them, we can also use the plugin libraries PKG_CHECK_MODULES(GST_LIBS, gstreamer-libs-$GST_MAJORMINOR >= $GST_REQUIRED, HAVE_GST_LIBS=yes, HAVE_GST_LIBS=no) dnl Give a warning if we don't have gstreamer libs if test "x$HAVE_GST_LIBS" = "xno"; then AC_MSG_NOTICE(no GStreamer plugin libs found) dnl make GST_LIBS_CFLAGS and GST_LIBS_LIBS available AC_SUBST(GST_LIBS_CFLAGS) AC_SUBST(GST_LIBS_LIBS) GSTWATCHDOG_CFLAGS="$GST_LIBS_CFLAGS -Wall -Werror" AC_SUBST(GSTWATCHDOG_CFLAGS) GST_WD_CFLAGS="$GST_CFLAGS" GST_WD_LIBS="$GST_LIBS \$(top_builddir)/gst/watchdog/libgstwatchdog-$MAJORMINOR.la" AC_SUBST(GST_WD_CFLAGS) AC_SUBST(GST_WD_LIBS) AC_OUTPUT( Makefile gst/Makefile gst/watchdog/Makefile po/Makefile.in testsuite/Makefile ) --- NEW FILE: Makefile.am --- SUBDIRS = watchdog lib_LTLIBRARIES = libgstwatchdog-@GST_MAJORMINOR@.la libgstwatchdog_@GST_MAJORMINOR@_includedir = \ $(includedir)/gstreamer-@GST_MAJORMINOR@/gst/watchdog libgstwatchdog_@GST_MAJORMINOR@_include_HEADERS = \ gstwatchdog.h libgstwatchdog_@GST_MAJORMINOR@_la_SOURCES = \ gstwatchdog.c libgstwatchdog_@GST_MAJORMINOR@_la_CFLAGS = $(GST_CFLAGS) libgstwatchdog_@GST_MAJORMINOR@_la_LIBADD = $(GST_LIBS) --- NEW FILE: gstwatchdog.c --- #include <gstwatchdog.h> #include <unistd.h> static void gst_watchdog_base_init (gpointer g_class); static void gst_watchdog_class_init (gpointer g_class, gpointer user_data); static void gst_watchdog_init (GTypeInstance *instance, gpointer g_class); static void gst_watchdog_dispose (GObject *object); static void gst_watchdog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); static void gst_watchdog_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static gpointer gst_watchdog_threadfunc (gpointer data); static void gst_watchdog_remove_bin_nounref (GstWatchdog *dog, GstBin *bin); static gboolean gst_watchdog_bin_log_activity (GstBin *bin, gpointer data); static void gst_watchdog_ping (GstWatchdog *dog); GType _gst_watchdog_type; enum { ARG_0, ARG_TIMEOUT }; WATCHDOG_ALARM, LAST_SIGNAL static guint gst_watchdog_signals[LAST_SIGNAL]; static GObjectClass *parent_class = NULL; GType gst_watchdog_get_type (void) { if (!_gst_watchdog_type) { static const GTypeInfo object_info = { sizeof (GstWatchdogClass), gst_watchdog_base_init, NULL, gst_watchdog_class_init, sizeof (GstWatchdog), 32, gst_watchdog_init, NULL }; _gst_watchdog_type = g_type_register_static (G_TYPE_OBJECT, "GstWatchdog", &object_info, 0); } return _gst_watchdog_type; } static void gst_watchdog_base_init (gpointer g_class) //GObjectClass *gobject_class = G_OBJECT_CLASS (g_class); static void gst_watchdog_class_init (gpointer g_class, gpointer class_data) GObjectClass *gobject_class = G_OBJECT_CLASS (g_class); gobject_class->dispose = gst_watchdog_dispose; parent_class = g_type_class_peek_parent (gobject_class); gst_watchdog_signals[WATCHDOG_ALARM] = g_signal_new ("alarm", G_TYPE_FROM_CLASS (g_class), G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GstWatchdogClass, alarm), NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_BIN); gobject_class->get_property = gst_watchdog_get_property; gobject_class->set_property = gst_watchdog_set_property; g_object_class_install_property (gobject_class, ARG_TIMEOUT, g_param_spec_uint64 ("timeout", "Timeout", "Time before signaling alarm (in nanoseconds)", 0, G_MAXUINT64, 5*GST_SECOND, G_PARAM_READWRITE)); static void gst_watchdog_init (GTypeInstance *instance, gpointer g_class) GstWatchdog *dog = GST_WATCHDOG (instance); GError *error = NULL; dog->mutex = g_mutex_new(); dog->cond = g_cond_new(); dog->thread = g_thread_create(gst_watchdog_threadfunc, dog, TRUE, &error); dog->timeout = 5*GST_SECOND; dog->state = GST_WATCHDOG_STATE_DISARMED; static void gst_watchdog_dispose (GObject *object) GstWatchdog *dog = GST_WATCHDOG (object); dog->state = GST_WATCHDOG_STATE_EXIT; gst_watchdog_ping (dog); g_thread_join (dog->thread); g_mutex_free (dog->mutex); g_cond_free (dog->cond); while (dog->bins) { GstWatchdogBin *dog_bin = dog->bins->data; g_object_weak_unref (G_OBJECT (dog_bin->bin), (GWeakNotify)gst_watchdog_remove_bin_nounref, dog); g_free (dog_bin); dog->bins = g_list_delete_link (dog->bins, dog->bins); static void gst_watchdog_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) switch (prop_id) { case ARG_TIMEOUT: dog->timeout = g_value_get_uint64 (value); gst_watchdog_ping (dog); break; default: gst_watchdog_get_property (GObject *object, guint prop_id, GValue *value, g_value_set_uint64 (value, dog->timeout); GstWatchdog * gst_watchdog_new (void) GST_DEBUG ("new"); return (GstWatchdog *)g_object_new (GST_TYPE_WATCHDOG, NULL); void gst_watchdog_add_bin (GstWatchdog *dog, GstBin *bin) GstWatchdogBin *dog_bin; GST_DEBUG ("adding %"GST_PTR_FORMAT, bin); dog_bin = g_new0(GstWatchdogBin, 1); g_object_weak_ref (G_OBJECT (bin), (GWeakNotify)gst_watchdog_remove_bin_nounref, dog); dog_bin->bin = bin; g_get_current_time (&dog_bin->last_activity); g_mutex_lock (dog->mutex); dog->bins = g_list_append (dog->bins, dog_bin); g_mutex_unlock (dog->mutex); g_signal_connect (G_OBJECT (bin), "iterate", (GCallback)gst_watchdog_bin_log_activity, dog); gst_watchdog_remove_bin (GstWatchdog *dog, GstBin *bin) GST_DEBUG ("removing %"GST_PTR_FORMAT, bin); gst_watchdog_remove_bin_nounref (dog, bin); g_object_weak_unref (G_OBJECT (bin), gst_watchdog_arm (GstWatchdog *dog) dog->state = GST_WATCHDOG_STATE_ARMED; gst_watchdog_disarm (GstWatchdog *dog) gst_watchdog_ping (GstWatchdog *dog) g_cond_signal (dog->cond); static GList * gst_watchdog_find_link (GstWatchdog *dog, GstBin *bin) GList *link; GstWatchdogBin *dog_bin = NULL; for (link = g_list_first (dog->bins); link; link = g_list_next(link)) { dog_bin = link->data; if (dog_bin->bin == bin) { return link; } return NULL; gst_watchdog_remove_bin_nounref (GstWatchdog *dog, GstBin *bin) link = gst_watchdog_find_link (dog, bin); if (link) { dog->bins = g_list_remove(dog->bins, link); } else { /* error */ static gboolean gst_watchdog_bin_log_activity (GstBin *bin, gpointer data) GstWatchdog *dog = GST_WATCHDOG (data); GST_DEBUG ("activity on %"GST_PTR_FORMAT, bin); g_get_current_time (&dog_bin->last_activity); return TRUE; static int g_time_val_compare (GTimeVal *a, GTimeVal *b) GST_DEBUG ("comparing %ld.%06ld to %ld.%06ld", a->tv_sec, a->tv_usec, b->tv_sec, b->tv_usec); if (a->tv_sec < b->tv_sec) return -1; if (a->tv_sec > b->tv_sec) return 1; if (a->tv_usec < b->tv_usec) return -1; if (a->tv_usec > b->tv_usec) return 1; return 0; gst_watchdog_find_expired (GstWatchdog *dog, GTimeVal *time) if (g_time_val_compare (&dog_bin->last_activity, time) < 0) { static gpointer gst_watchdog_threadfunc (gpointer data) GTimeVal time; gboolean ret; GstWatchdogState state; while (1) { g_get_current_time (&time); g_time_val_add (&time, 1 * G_USEC_PER_SEC); g_mutex_lock (dog->mutex); ret = g_cond_timed_wait (dog->cond, dog->mutex, &time); state = dog->state; g_mutex_unlock (dog->mutex); GST_DEBUG("checking bins"); if(state == GST_WATCHDOG_STATE_EXIT) { return NULL; if(state == GST_WATCHDOG_STATE_ARMED) { GList *link; g_get_current_time (&time); g_time_val_add (&time, -(dog->timeout/1000)); g_mutex_lock (dog->mutex); link = gst_watchdog_find_expired (dog, &time); if (link) { GstWatchdogBin *dog_bin = link->data; GstBin *bin = dog_bin->bin; g_object_ref(bin); g_mutex_unlock (dog->mutex); g_signal_emit (G_OBJECT (dog), gst_watchdog_signals[WATCHDOG_ALARM], 0, bin); dog->state = GST_WATCHDOG_STATE_DISARMED; g_object_unref (bin); } else { } --- NEW FILE: gstwatchdog.h --- #ifndef _GST_WATCHDOG_H_ #define _GST_WATCHDOG_H_ #include <glib-object.h> #include <gst/gst.h> #include <glib.h> G_BEGIN_DECLS typedef struct _GstWatchdog GstWatchdog; typedef struct _GstWatchdogClass GstWatchdogClass; typedef struct _GstWatchdogBin GstWatchdogBin; #define GST_TYPE_WATCHDOG (gst_watchdog_get_type()) #define GST_IS_WATCHDOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WATCHDOG)) #define GST_IS_WATCHDOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WATCHDOG)) #define GST_WATCHDOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WATCHDOG, GstWatchdog)) #define GST_WATCHDOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WATCHDOG, GstWatchdogClass)) typedef enum _GstWatchdogState { GST_WATCHDOG_STATE_EXIT, GST_WATCHDOG_STATE_DISARMED, GST_WATCHDOG_STATE_ARMED, } GstWatchdogState; struct _GstWatchdogBin { GstBin *bin; GTimeVal last_activity; struct _GstWatchdog { GObject object; GMutex *mutex; GCond *cond; GThread *thread; GList *bins; GstClockTime timeout; struct _GstWatchdogClass { GObjectClass object_class; void (*alarm) (GstWatchdog *dog, GstBin *bin); GType gst_watchdog_get_type (void); GstWatchdog * gst_watchdog_new (void); void gst_watchdog_add_bin (GstWatchdog *dog, GstBin *bin); void gst_watchdog_remove_bin (GstWatchdog *dog, GstBin *bin); void gst_watchdog_arm (GstWatchdog *dog); void gst_watchdog_disarm (GstWatchdog *dog); G_END_DECLS #endif --- NEW FILE: as-ac-expand.m4 --- dnl as-ac-expand.m4 0.2.0 dnl autostars m4 macro for expanding directories using configure's prefix dnl th...@ap... dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR) dnl example dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir) dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local AC_DEFUN([AS_AC_EXPAND], [ EXP_VAR=[$1] FROM_VAR=[$2] dnl first expand prefix and exec_prefix if necessary prefix_save=$prefix exec_prefix_save=$exec_prefix dnl if no prefix given, then use /usr/local, the default prefix if test "x$prefix" = "xNONE"; then prefix="$ac_default_prefix" fi dnl if no exec_prefix given, then use prefix if test "x$exec_prefix" = "xNONE"; then exec_prefix=$prefix full_var="$FROM_VAR" dnl loop until it doesn't change anymore while true; do new_full_var="`eval echo $full_var`" if test "x$new_full_var" = "x$full_var"; then break; fi full_var=$new_full_var done dnl clean up full_var=$new_full_var AC_SUBST([$1], "$full_var") dnl restore prefix and exec_prefix prefix=$prefix_save exec_prefix=$exec_prefix_save ]) testprogs = test1 TESTS = $(testprogs) check_PROGRAMS = $(testprogs) LIBS = $(GST_WD_LIBS) AM_CFLAGS = $(GST_WD_CFLAGS) --- NEW FILE: test1.c --- #include <gst/watchdog/gstwatchdog.h> dog_alarm (GstWatchdog *dog, GstBin *bin, gpointer data) g_print ("got alarm\n"); int main (int argc, char *argv[]) GstElement *pipeline; GstWatchdog *dog; int i; gst_init (&argc, &argv); dog = gst_watchdog_new (); pipeline = gst_parse_launch ("fakesrc ! fakesink", NULL); gst_watchdog_add_bin (dog, GST_BIN (pipeline)); g_signal_connect (dog, "alarm", (GCallback)dog_alarm, NULL); gst_watchdog_arm (dog); for(i=0;i<10;i++){ g_print("%d\n",i); g_usleep(1000000); //gst_object_unref (GST_OBJECT (pipeline)); g_object_unref (dog); |