--- /dev/null
+SUBDIRS = src data gst
+
+EXTRA_DIST = \
+ autogen.sh \
+ debian/*
+
+deb: dist
+ -mkdir $(top_builddir)/debian-build
+ cd $(top_builddir)/debian-build && tar zxf ../$(top_builddir)/$(PACKAGE)-$(VERSION).tar.gz
+ cd $(top_builddir)/debian-build/$(PACKAGE)-$(VERSION) && dpkg-buildpackage -rfakeroot
+ -rm -rf $(top_builddir)/debian-build/$(PACKAGE)-$(VERSION)
+
+DISTCLEANFILES = *~
--- /dev/null
+ * Make nicer application manager icon
+ * Add process listing and killing again (use hildon button to launch it! not GTK buton)
+ * Prolly need to launch the process listing in own thread or process - else it blocks the main one and comes stacked wrong
+ * Add watermarking to the ximagewsrc, also fast scaling by factor of 2
+
--- /dev/null
+AC_INIT(Makefile.am)
+AM_INIT_AUTOMAKE(maemo5-load-applet, 0.5)
+AM_CONFIG_HEADER(config.h)
+
+AC_CANONICAL_HOST
+
+AC_PROG_CC
+AC_PROG_CPP
+AC_PROG_INSTALL
+AC_PROG_RANLIB
+AC_PROG_LIBTOOL
+
+AC_HEADER_STDC
+
+CFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wmissing-declarations"
+
+AC_SUBST(CFLAGS)
+
+PKG_CHECK_MODULES([MAEMO5_LOADAPPLET], [
+ gtk+-2.0 >= 2.4.0
+ glib-2.0 >= 2.2.0
+ hildon-1 >= 1.0.9
+ osso-af-settings >= 0.8.1
+ libhildondesktop-1 >= 2.1.0
+])
+
+AC_SUBST(MAEMO5_LOADAPPLET)
+AC_SUBST(MAEMO5_LOADAPPLET_CFLAGS)
+
+hildondesktoplibdir="${libdir}/hildon-desktop"
+AC_SUBST(hildondesktoplibdir)
+
+hildondesktoplibdir="${libdir}/hildon-desktop"
+AC_SUBST(hildondesktoplibdir)
+
+
+
+AC_CHECK_HEADER(X11/Xlib.h, HAVE_X="yes", HAVE_X="no")
+if test "x$HAVE_X" = "xno"
+ then
+ AC_MSG_NOTICE([cannot find X11 development files])
+ else
+ dnl this is much more than we want
+ X_LIBS="$X_LIBS $X_PRE_LIBS $X_EXTRA_LIBS"
+ dnl AC_PATH_XTRA only defines the path needed to find the X libs,
+ dnl it does not add the libs; therefore we add them here
+ X_LIBS="$X_LIBS -lX11"
+ AC_SUBST(X_CFLAGS)
+ AC_SUBST(X_LIBS)
+
+ dnl check for Xfixes
+ PKG_CHECK_MODULES(XFIXES, xfixes, HAVE_XFIXES="yes", HAVE_XFIXES="no")
+ if test "x$HAVE_XFIXES" = "xyes"
+ then
+ XFIXES_CFLAGS="-DHAVE_XFIXES $XFIXES_CFLAGS"
+ fi
+ AC_SUBST(XFIXES_LIBS)
+ AC_SUBST(XFIXES_CFLAGS)
+
+ dnl check for Xdamage
+ PKG_CHECK_MODULES(XDAMAGE, xdamage, HAVE_XDAMAGE="yes", HAVE_XDAMAGE="no")
+ if test "x$HAVE_XDAMAGE" = "xyes"
+ then
+ XDAMAGE_CFLAGS="-DHAVE_XDAMAGE $XDAMAGE_CFLAGS"
+ fi
+ AC_SUBST(XDAMAGE_LIBS)
+ AC_SUBST(XDAMAGE_CFLAGS)
+ fi
+
+dnl check for GST BASE flags
+PKG_CHECK_MODULES(GSTREAMERBASE, gstreamer-base-0.10, HAVE_GSTREAMERBASE="yes", HAVE_GSTREAMERBASE="no")
+AC_SUBST(GSTREAMERBASE_LIBS)
+AC_SUBST(GSTREAMERBASE_CFLAGS)
+
+dnl check for GST flags
+PKG_CHECK_MODULES(GSTREAMER, gstreamer-0.10, HAVE_GSTREAMER="yes", HAVE_GSTREAMER="no")
+AC_SUBST(GSTREAMER_LIBS)
+AC_SUBST(GSTREAMER_CFLAGS)
+
+GST_LICENSE="LGPL"
+AC_DEFINE_UNQUOTED(GST_LICENSE, "$GST_LICENSE", [GStreamer license])
+AC_SUBST(GST_LICENSE)
+
+
+
+GST_PLUGIN_LDFLAGS="-module -avoid-version -export-symbols-regex '^[_]*gst_plugin_desc\$\$' -no-undefined"
+AC_SUBST(GST_PLUGIN_LDFLAGS)
+
+
+AC_CONFIG_FILES([
+ Makefile
+ src/Makefile
+ data/Makefile
+ gst/Makefile
+])
+AC_OUTPUT
--- /dev/null
+install-data-local:
+ $(INSTALL_DATA) -D $(srcdir)/status_area_load_applet.desktop $(DESTDIR)/usr/share/applications/hildon-status-menu/status_area_load_applet.desktop
+ $(INSTALL_DATA) -D $(srcdir)/status_menu_load_applet.desktop $(DESTDIR)/usr/share/applications/hildon-status-menu/status_menu_load_applet.desktop
+ $(INSTALL_DATA) -D $(srcdir)/la_picture.png $(DESTDIR)/usr/share/pixmaps/la_picture.png
+ $(INSTALL_DATA) -D $(srcdir)/la_video.png $(DESTDIR)/usr/share/pixmaps/la_video.png
+ $(INSTALL_DATA) -D $(srcdir)/la_process.png $(DESTDIR)/usr/share/pixmaps/la_process.png
+
+
+
--- /dev/null
+[Desktop Entry]
+Name=Load Applet Maemo5 edition - status area plugin
+Type=default
+X-Path=status_area_load_applet.so
--- /dev/null
+[Desktop Entry]
+Name=Load Applet Maemo5 edition - status menu plugin
+Type=default
+X-Path=status_menu_load_applet.so
--- /dev/null
+load-applet (0.4.6-1) unstable; urgency=low
+
+ * Fixed applet name
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sat, 31 Oct 2009 12:07:08 +0200
+
+load-applet (0.4.5-2) unstable; urgency=low
+
+ * GStreamer got updated on latest images, not in SDK. Rebuild!
+
+ -- Jakub Pavelek <jpavelek@welho.com> Tue, 6 Oct 2009 21:16:50 +0300
+
+load-applet (0.4.5-1) unstable; urgency=low
+
+ * Comment that process info out for now
+ * Added copy of ximagesrc. Will modify it to have more functionality later
+
+ -- Jakub Pavelek <jpavelek@welho.com> Wed, 30 Sep 2009 18:57:44 +0300
+
+load-applet (0.4.4-3) unstable; urgency=low
+
+ * Added missing dependency on gstreamer0.10-plugins-good-extra
+
+ -- Jakub Pavelek <jpavelek@welho.com> Thu, 24 Sep 2009 23:24:26 +0300
+
+load-applet (0.4.4-2) unstable; urgency=low
+
+ * Added missing dependency on gst-tools
+
+ -- Jakub Pavelek <jpavelek@welho.com> Thu, 24 Sep 2009 20:54:40 +0300
+
+load-applet (0.4.4-1) unstable; urgency=low
+
+ * Show grayed box on no CPU/Mem usage
+
+ -- Jakub Pavelek <jpavelek@welho.com> Wed, 23 Sep 2009 21:38:52 +0300
+
+load-applet (0.4.3-1) unstable; urgency=low
+
+ * Process listing - trying out a dialog launching
+ * Bit better icon for video recording
+
+ -- Jakub Pavelek <jpavelek@welho.com> Wed, 9 Sep 2009 22:37:24 +0300
+
+load-applet (0.4.2-1) unstable; urgency=low
+
+ * More efficient and consistent blinking for max cpu load
+
+ -- Jakub Pavelek <jpavelek@welho.com> Wed, 9 Sep 2009 21:18:41 +0300
+
+load-applet (0.4.1-1) unstable; urgency=low
+
+ * Pulsating high CPU load - simple version
+
+ -- Jakub Pavelek <jpavelek@welho.com> Tue, 8 Sep 2009 23:38:58 +0300
+
+load-applet (0.4.0-2) unstable; urgency=low
+
+ * New bigger icon to test the appearance in application manager
+
+ -- Jakub Pavelek <jpavelek@welho.com> Tue, 8 Sep 2009 23:14:35 +0300
+
+load-applet (0.4.0-1) unstable; urgency=low
+
+ * Do not toggle the camera app when taking screenshot
+ * Show banner with instructions for the screenshot
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sun, 6 Sep 2009 17:53:52 +0300
+
+load-applet (0.3.3-1) unstable; urgency=low
+
+ * Do not toggle the camera app when taking screenshot
+ * Show banner with instructions for the screenshot
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sun, 6 Sep 2009 17:53:52 +0300
+
+load-applet (0.3.2-1) unstable; urgency=low
+
+ * Tuning the memory and CPU bars
+ * Stop monitoring when screen is off (should do same for fullscreen video,
+ maps or browser too, but too much trouble without system states)
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sun, 6 Sep 2009 16:19:51 +0300
+
+load-applet (0.3.1-1) unstable; urgency=low
+
+ * Moving monitoring from menu to area
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sun, 6 Sep 2009 10:22:23 +0300
+
+load-applet (0.3.0-1) unstable; urgency=low
+
+ * Repackaging and renaming files - split between status area and status menu items
+ * Adding dummy status area applet
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sat, 5 Sep 2009 12:06:07 +0300
+
+maemo5-load-applet (0.2.9-1) unstable; urgency=low
+
+ * Lets have audio for the screencast. Voice-over baby!
+ * Changed the encoder settings for better image quality.
+
+ -- Jakub Pavelek <jpavelek@welho.com> Thu, 3 Sep 2009 23:29:18 +0300
+
+maemo5-load-applet (0.2.8-1) unstable; urgency=low
+
+ * Close the menu? Toggle the screenshot? Still not done ...
+
+ -- Jakub Pavelek <jpavelek@welho.com> Mon, 3 Aug 2009 21:17:26 +0300
+
+maemo5-load-applet (0.2.7-1) unstable; urgency=low
+
+ * Listening to camera key now.
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sat, 1 Aug 2009 09:09:35 +0300
+
+maemo5-load-applet (0.2.6-1) unstable; urgency=low
+
+ * Added button for status under the icon - to open the list with apps in future
+
+ -- Jakub Pavelek <jpavelek@welho.com> Thu, 9 Jul 2009 22:12:41 +0300
+
+maemo5-load-applet (0.2.5-1) unstable; urgency=low
+
+ * Recording works. Bad framerate, no package dependencies.
+
+ -- Jakub Pavelek <jpavelek@welho.com> Thu, 9 Jul 2009 00:51:15 +0300
+
+maemo5-load-applet (0.2.4-2) unstable; urgency=low
+
+ * Moving to different category/section
+
+ -- Jakub Pavelek <jpavelek@welho.com> Tue, 21 Apr 2009 14:18:07 +0300
+
+maemo5-load-applet (0.2.4-1) unstable; urgency=low
+
+ * Record UI kinda works
+
+ -- Jakub Pavelek <jpavelek@welho.com> Thu, 9 Jul 2009 00:10:34 +0300
+
+maemo5-load-applet (0.2.3-1) unstable; urgency=low
+
+ * Added beeps to time the screenshot
+ * New UI - small bars, buttons for screenshot and screencast (non-functional)
+ * Reusing existing sound for shutter
+
+ -- Jakub Pavelek <jpavelek@welho.com> Tue, 7 Jul 2009 23:22:13 +0300
+
+maemo5-load-applet (0.2.1-1) unstable; urgency=low
+
+ * Updated the icons for transparency, should look alright with theme change now.
+
+ -- Jakub Pavelek <jpavelek@welho.com> Mon, 2 Mar 2009 11:39:54 +0200
+
+maemo5-load-applet (0.2.0-1) unstable; urgency=low
+
+ * Adding graphics for load indication
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sun, 1 Mar 2009 19:27:27 +0200
+
+maemo5-load-applet (0.1.1-1) unstable; urgency=low
+
+ * Small build script updates and looks of the button change.
+ * Removed beeping, kept shutter sound
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sat, 28 Feb 2009 18:11:10 +0200
+
+maemo5-load-applet (0.1-3) unstable; urgency=low
+
+ * Another section fix me hopes
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sat, 28 Feb 2009 04:45:31 +0200
+
+maemo5-load-applet (0.1-2) unstable; urgency=low
+
+ * Moving to proper category and giving the old icon for app manager
+
+ -- Jakub Pavelek <jpavelek@welho.com> Sat, 28 Feb 2009 04:39:37 +0200
+
+maemo5-load-applet (0.1) unstable; urgency=low
+
+ * Initial release
+
+ -- Jakub Pavelek <jpavelek@welho.com> Fri, 27 Feb 2009 18:08:43 +0200
--- /dev/null
+Source: load-applet
+Section: user/utilities
+Priority: optional
+Maintainer: Jakub Pavelek <jpavelek@welho.com>
+Build-Depends: debhelper (>= 4.1.0), libhildon1-dev (>=2.1.29), libosso-dev (>=2.0), osso-af-settings, libhildondesktop1-dev (>=2.1.0), libgstreamer0.10-dev
+Standards-Version: 3.8.0
+
+Package: load-applet-ximagewsrc
+Section: devel
+Architecture: any
+Depends: ${shlibs:Depends}
+Description: GStreamer XImage source, modified
+ XImage source modified to scale and include simple watermark
+
+
+Package: load-applet
+Section: user/utilities
+Architecture: any
+Conflicts: maemo5-load-applet
+Replaces: maemo5-load-applet
+Provides: maemo5-load-applet
+Depends: ${shlibs:Depends}, libhildon1 (>=2.1.29), libosso1 (>=2.0), libhildondesktop1 (>=2.1.0), gstreamer-tools, load-applet-ximagewsrc
+XB-Maemo-Icon-26:
+ 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
+ RU5ErkJggg==
+ ===
+Description: Show CPU and memory usage, take screenshots, record screencasts.
+ This is a small Status-bar applet that monitors the CPU load and
+ the memory consumption. It has menu for screenshot and
+ screencast taking.
--- /dev/null
+Copyright: (c) 2005-2009 Jakub Pavelek <jpavelek@welho.com>
+
+Released under the terms of BSD License.
--- /dev/null
+usr/lib/gstreamer-0.10/*.so
--- /dev/null
+usr/lib/hildon-desktop/*.so
+usr/share/applications/hildon-status-menu/*
+usr/share/sounds/*
+usr/share/pixmaps/*
--- /dev/null
+#!/usr/bin/make -f
+# -*- makefile -*-
+
+#export DH_VERBOSE=1
+
+DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+ CFLAGS += -O0
+else
+ CFLAGS += -O2
+endif
+ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
+ INSTALL_PROGRAM += -s
+endif
+
+config.status: configure
+ dh_testdir
+ CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --exec-prefix=/usr
+
+configure: configure-stamp
+
+configure-stamp:
+ libtoolize --automake
+ aclocal-1.7 || aclocal
+ autoconf
+ autoheader
+ automake-1.7 --add-missing --foreign || automake --add-missing> --foreign
+ touch configure-stamp
+
+
+build: build-stamp
+
+build-stamp: config.status
+ dh_testdir
+ $(MAKE)
+ touch build-stamp
+
+clean:
+ dh_testdir
+ dh_testroot
+ rm -f build-stamp
+ [ ! -f Makefile ] || $(MAKE) distclean
+ifneq "$(wildcard /usr/share/misc/config.sub)" ""
+ cp -f /usr/share/misc/config.sub config.sub
+endif
+ifneq "$(wildcard /usr/share/misc/config.guess)" ""
+ cp -f /usr/share/misc/config.guess config.guess
+endif
+ rm -f configure COPYING INSTALL Makefile.in aclocal.m4 configure-stamp build-stamp config.guess config.sub depcomp install-sh ltmain.sh missing mkinstalldirs config.h.in
+ dh_clean
+
+install: build
+ dh_testdir
+ dh_testroot
+ dh_clean -k
+ dh_installdirs
+ $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp
+ dh_movefiles
+
+binary-indep: build install
+
+binary-arch: build install
+ dh_testdir
+ dh_testroot
+ dh_installchangelogs
+ dh_installdocs
+ dh_install -v --sourcedir=debian/tmp
+ dh_link
+ dh_strip --dbg-package=load-applet
+ dh_compress
+ dh_fixperms
+ dh_makeshlibs -V
+ dh_installdeb
+ dh_shlibdeps
+ dh_gencontrol
+ dh_md5sums
+ dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
--- /dev/null
+plugindir = $(libdir)/gstreamer-0.10
+
+
+plugin_LTLIBRARIES = libgstximagewsrc.la
+
+libgstximagewsrc_la_SOURCES = gstximagesrc.c ximageutil.c
+libgstximagewsrc_la_CFLAGS = \
+ $(GST_PLUGINS_BASE_CFLAGS) \
+ $(GSTREAMERBASE_CFLAGS) \
+ $(GSTREAMER_CFLAGS) \
+ $(X_CFLAGS) $(XFIXES_CFLAGS) $(XDAMAGE_CFLAGS)
+libgstximagewsrc_la_LIBADD = \
+ $(GSTREAMERBASE_LIBS) \
+ $(GSTREAMER_LIBS) \
+ $(X_LIBS) $(XSHM_LIBS) $(XFIXES_LIBS) $(XDAMAGE_LIBS)
+libgstximagewsrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstximagewsrc_la_LIBTOOLFLAGS = --tag=disable-static
+
+noinst_HEADERS = gstximagesrc.h ximageutil.h
--- /dev/null
+/* GStreamer
+ *
+ * Copyright (C) 2006 Zaheer Merali <zaheerabbas at merali dot org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:element-ximagesrc
+ *
+ * This element captures your X Display and creates raw RGB video. It uses
+ * the XDamage extension if available to only capture areas of the screen that
+ * have changed since the last frame. It uses the XFixes extension if
+ * available to also capture your mouse pointer. By default it will fixate to
+ * 25 frames per second.
+ *
+ * <refsect2>
+ * <title>Example pipelines</title>
+ * |[
+ * gst-launch ximagesrc ! video/x-raw-rgb,framerate=5/1 ! ffmpegcolorspace ! theoraenc ! oggmux ! filesink location=desktop.ogg
+ * ]| Encodes your X display to an Ogg theora video at 5 frames per second.
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "gstximagesrc.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include <gst/gst.h>
+
+GST_DEBUG_CATEGORY_STATIC (gst_debug_ximage_src);
+#define GST_CAT_DEFAULT gst_debug_ximage_src
+
+/* elementfactory information */
+static const GstElementDetails ximagesrc_details =
+GST_ELEMENT_DETAILS ("Ximage video source",
+ "Source/Video",
+ "Creates a screenshot video stream",
+ "Lutz Mueller <lutz@users.sourceforge.net>, "
+ "Jan Schmidt <thaytan@mad.scientist.com>, "
+ "Zaheer Merali <zaheerabbas at merali dot org>");
+
+static GstStaticPadTemplate t =
+GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+ GST_STATIC_CAPS ("video/x-raw-rgb, "
+ "framerate = (fraction) [ 0, MAX ], "
+ "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ], "
+ "pixel-aspect-ratio = (fraction) [ 0, MAX ]"));
+
+enum
+{
+ PROP_0,
+ PROP_DISPLAY_NAME,
+ PROP_SCREEN_NUM,
+ PROP_SHOW_POINTER,
+ PROP_USE_DAMAGE,
+ PROP_STARTX,
+ PROP_STARTY,
+ PROP_ENDX,
+ PROP_ENDY
+};
+
+GST_BOILERPLATE (GstXImageSrc, gst_ximage_src, GstPushSrc, GST_TYPE_PUSH_SRC);
+
+static void gst_ximage_src_fixate (GstPad * pad, GstCaps * caps);
+static void gst_ximage_src_clear_bufpool (GstXImageSrc * ximagesrc);
+
+/* Called when a buffer is returned from the pipeline */
+static void
+gst_ximage_src_return_buf (GstXImageSrc * ximagesrc,
+ GstXImageSrcBuffer * ximage)
+{
+ /* If our geometry changed we can't reuse that image. */
+ if ((ximage->width != ximagesrc->width) ||
+ (ximage->height != ximagesrc->height)) {
+ GST_DEBUG_OBJECT (ximagesrc,
+ "destroy image %p as its size changed %dx%d vs current %dx%d",
+ ximage, ximage->width, ximage->height,
+ ximagesrc->width, ximagesrc->height);
+ g_mutex_lock (ximagesrc->x_lock);
+ gst_ximageutil_ximage_destroy (ximagesrc->xcontext, ximage);
+ g_mutex_unlock (ximagesrc->x_lock);
+ } else {
+ /* In that case we can reuse the image and add it to our image pool. */
+ GST_LOG_OBJECT (ximagesrc, "recycling image %p in pool", ximage);
+ /* need to increment the refcount again to recycle */
+ gst_buffer_ref (GST_BUFFER (ximage));
+ g_mutex_lock (ximagesrc->pool_lock);
+ ximagesrc->buffer_pool = g_slist_prepend (ximagesrc->buffer_pool, ximage);
+ g_mutex_unlock (ximagesrc->pool_lock);
+ }
+}
+
+static gboolean
+gst_ximage_src_open_display (GstXImageSrc * s, const gchar * name)
+{
+ g_return_val_if_fail (GST_IS_XIMAGE_SRC (s), FALSE);
+
+ if (s->xcontext != NULL)
+ return TRUE;
+
+ g_mutex_lock (s->x_lock);
+ s->xcontext = ximageutil_xcontext_get (GST_ELEMENT (s), name);
+ if (s->xcontext == NULL) {
+ g_mutex_unlock (s->x_lock);
+ GST_ELEMENT_ERROR (s, RESOURCE, OPEN_READ,
+ ("Could not open X display for reading"),
+ ("NULL returned from getting xcontext"));
+ return FALSE;
+ }
+ s->width = s->xcontext->width;
+ s->height = s->xcontext->height;
+
+ /* Always capture root window, for now */
+ s->xwindow = s->xcontext->root;
+
+#ifdef HAVE_XFIXES
+ /* check if xfixes supported */
+ {
+ int error_base;
+
+ if (XFixesQueryExtension (s->xcontext->disp, &s->fixes_event_base,
+ &error_base)) {
+ s->have_xfixes = TRUE;
+ GST_DEBUG_OBJECT (s, "X Server supports XFixes");
+ } else {
+
+ GST_DEBUG_OBJECT (s, "X Server does not support XFixes");
+ }
+ }
+
+#ifdef HAVE_XDAMAGE
+ /* check if xdamage is supported */
+ {
+ int error_base;
+ long evmask = NoEventMask;
+
+ s->have_xdamage = FALSE;
+ s->damage = None;
+ s->damage_copy_gc = None;
+ s->damage_region = None;
+
+ if (XDamageQueryExtension (s->xcontext->disp, &s->damage_event_base,
+ &error_base)) {
+ s->damage =
+ XDamageCreate (s->xcontext->disp, s->xwindow, XDamageReportNonEmpty);
+ if (s->damage != None) {
+ s->damage_region = XFixesCreateRegion (s->xcontext->disp, NULL, 0);
+ if (s->damage_region != None) {
+ XGCValues values;
+
+ GST_DEBUG_OBJECT (s, "Using XDamage extension");
+ values.subwindow_mode = IncludeInferiors;
+ s->damage_copy_gc = XCreateGC (s->xcontext->disp,
+ s->xwindow, GCSubwindowMode, &values);
+ XSelectInput (s->xcontext->disp, s->xwindow, evmask);
+
+ s->have_xdamage = TRUE;
+ } else {
+ XDamageDestroy (s->xcontext->disp, s->damage);
+ s->damage = None;
+ }
+ } else
+ GST_DEBUG_OBJECT (s, "Could not attach to XDamage");
+ } else {
+ GST_DEBUG_OBJECT (s, "X Server does not have XDamage extension");
+ }
+ }
+#endif
+#endif
+
+ g_mutex_unlock (s->x_lock);
+
+ if (s->xcontext == NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
+gst_ximage_src_start (GstBaseSrc * basesrc)
+{
+ GstXImageSrc *s = GST_XIMAGE_SRC (basesrc);
+
+ s->last_frame_no = -1;
+#ifdef HAVE_XDAMAGE
+ if (s->last_ximage)
+ gst_buffer_unref (GST_BUFFER_CAST (s->last_ximage));
+ s->last_ximage = NULL;
+#endif
+ return gst_ximage_src_open_display (s, s->display_name);
+}
+
+static gboolean
+gst_ximage_src_stop (GstBaseSrc * basesrc)
+{
+ GstXImageSrc *src = GST_XIMAGE_SRC (basesrc);
+
+#ifdef HAVE_XDAMAGE
+ if (src->last_ximage)
+ gst_buffer_unref (GST_BUFFER_CAST (src->last_ximage));
+ src->last_ximage = NULL;
+#endif
+
+ gst_ximage_src_clear_bufpool (src);
+
+#ifdef HAVE_XFIXES
+ if (src->cursor_image)
+ XFree (src->cursor_image);
+ src->cursor_image = NULL;
+#endif
+
+ if (src->xcontext) {
+ g_mutex_lock (src->x_lock);
+
+#ifdef HAVE_XDAMAGE
+ if (src->damage_copy_gc != None) {
+ XFreeGC (src->xcontext->disp, src->damage_copy_gc);
+ src->damage_copy_gc = None;
+ }
+ if (src->damage_region != None) {
+ XFixesDestroyRegion (src->xcontext->disp, src->damage_region);
+ src->damage_region = None;
+ }
+ if (src->damage != None) {
+ XDamageDestroy (src->xcontext->disp, src->damage);
+ src->damage = None;
+ }
+#endif
+
+ ximageutil_xcontext_clear (src->xcontext);
+ src->xcontext = NULL;
+ g_mutex_unlock (src->x_lock);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+gst_ximage_src_unlock (GstBaseSrc * basesrc)
+{
+ GstXImageSrc *src = GST_XIMAGE_SRC (basesrc);
+
+ /* Awaken the create() func if it's waiting on the clock */
+ GST_OBJECT_LOCK (src);
+ if (src->clock_id) {
+ GST_DEBUG_OBJECT (src, "Waking up waiting clock");
+ gst_clock_id_unschedule (src->clock_id);
+ }
+ GST_OBJECT_UNLOCK (src);
+
+ return TRUE;
+}
+
+static gboolean
+gst_ximage_src_recalc (GstXImageSrc * src)
+{
+ if (!src->xcontext)
+ return FALSE;
+
+ /* Maybe later we can check the display hasn't changed size */
+ /* We could use XQueryPointer to get only the current window. */
+ return TRUE;
+}
+
+#ifdef HAVE_XFIXES
+static void
+composite_pixel (GstXContext * xcontext, guchar * dest, guchar * src)
+{
+ guint8 r = src[2];
+ guint8 g = src[1];
+ guint8 b = src[0];
+ guint8 a = src[3];
+ guint8 dr, dg, db;
+ guint32 color;
+ gint r_shift, r_max, r_shift_out;
+ gint g_shift, g_max, g_shift_out;
+ gint b_shift, b_max, b_shift_out;
+
+ switch (xcontext->bpp) {
+ case 8:
+ color = *dest;
+ break;
+ case 16:
+ color = GUINT16_FROM_LE (*(guint16 *) (dest));
+ break;
+ case 32:
+ color = GUINT32_FROM_LE (*(guint32 *) (dest));
+ break;
+ default:
+ /* Should not reach here */
+ g_return_if_reached ();
+ }
+
+ /* possible optimisation:
+ * move the code that finds shift and max in the _link function */
+ for (r_shift = 0; !(xcontext->visual->red_mask & (1 << r_shift)); r_shift++);
+ for (g_shift = 0; !(xcontext->visual->green_mask & (1 << g_shift));
+ g_shift++);
+ for (b_shift = 0; !(xcontext->visual->blue_mask & (1 << b_shift)); b_shift++);
+
+ for (r_shift_out = 0; !(xcontext->visual->red_mask & (1 << r_shift_out));
+ r_shift_out++);
+ for (g_shift_out = 0; !(xcontext->visual->green_mask & (1 << g_shift_out));
+ g_shift_out++);
+ for (b_shift_out = 0; !(xcontext->visual->blue_mask & (1 << b_shift_out));
+ b_shift_out++);
+
+
+ r_max = (xcontext->visual->red_mask >> r_shift);
+ b_max = (xcontext->visual->blue_mask >> b_shift);
+ g_max = (xcontext->visual->green_mask >> g_shift);
+
+#define RGBXXX_R(x) (((x)>>r_shift) & (r_max))
+#define RGBXXX_G(x) (((x)>>g_shift) & (g_max))
+#define RGBXXX_B(x) (((x)>>b_shift) & (b_max))
+
+ dr = (RGBXXX_R (color) * 255) / r_max;
+ dg = (RGBXXX_G (color) * 255) / g_max;
+ db = (RGBXXX_B (color) * 255) / b_max;
+
+ dr = (r * a + (0xff - a) * dr) / 0xff;
+ dg = (g * a + (0xff - a) * dg) / 0xff;
+ db = (b * a + (0xff - a) * db) / 0xff;
+
+ color = (((dr * r_max) / 255) << r_shift_out) +
+ (((dg * g_max) / 255) << g_shift_out) +
+ (((db * b_max) / 255) << b_shift_out);
+
+ switch (xcontext->bpp) {
+ case 8:
+ *dest = color;
+ break;
+ case 16:
+ *(guint16 *) (dest) = color;
+ break;
+ case 32:
+ *(guint32 *) (dest) = color;
+ break;
+ default:
+ g_warning ("bpp %d not supported\n", xcontext->bpp);
+ }
+}
+#endif
+
+/* Retrieve an XImageSrcBuffer, preferably from our
+ * pool of existing images and populate it from the window */
+static GstXImageSrcBuffer *
+gst_ximage_src_ximage_get (GstXImageSrc * ximagesrc)
+{
+ GstXImageSrcBuffer *ximage = NULL;
+
+ g_mutex_lock (ximagesrc->pool_lock);
+ while (ximagesrc->buffer_pool != NULL) {
+ ximage = ximagesrc->buffer_pool->data;
+
+ if ((ximage->width != ximagesrc->width) ||
+ (ximage->height != ximagesrc->height)) {
+ gst_ximage_buffer_free (ximage);
+ }
+
+ ximagesrc->buffer_pool = g_slist_delete_link (ximagesrc->buffer_pool,
+ ximagesrc->buffer_pool);
+ }
+ g_mutex_unlock (ximagesrc->pool_lock);
+
+ if (ximage == NULL) {
+ GstXContext *xcontext;
+ GstCaps *caps = NULL;
+
+ GST_DEBUG_OBJECT (ximagesrc, "creating image (%dx%d)",
+ ximagesrc->width, ximagesrc->height);
+
+ g_mutex_lock (ximagesrc->x_lock);
+ ximage = gst_ximageutil_ximage_new (ximagesrc->xcontext,
+ GST_ELEMENT (ximagesrc), ximagesrc->width, ximagesrc->height,
+ (BufferReturnFunc) (gst_ximage_src_return_buf));
+ if (ximage == NULL) {
+ GST_ELEMENT_ERROR (ximagesrc, RESOURCE, WRITE, (NULL),
+ ("could not create a %dx%d ximage", ximage->width, ximage->height));
+ g_mutex_unlock (ximagesrc->x_lock);
+ return NULL;
+ }
+
+ xcontext = ximagesrc->xcontext;
+
+
+ caps = gst_caps_new_simple ("video/x-raw-rgb",
+ "bpp", G_TYPE_INT, xcontext->bpp,
+ "depth", G_TYPE_INT, xcontext->depth,
+ "endianness", G_TYPE_INT, xcontext->endianness,
+ "red_mask", G_TYPE_INT, xcontext->r_mask_output,
+ "green_mask", G_TYPE_INT, xcontext->g_mask_output,
+ "blue_mask", G_TYPE_INT, xcontext->b_mask_output,
+ "width", G_TYPE_INT, ximagesrc->width,
+ "height", G_TYPE_INT, ximagesrc->height,
+ "framerate", GST_TYPE_FRACTION, ximagesrc->fps_n, ximagesrc->fps_d,
+ "pixel-aspect-ratio", GST_TYPE_FRACTION,
+ gst_value_get_fraction_numerator (xcontext->par),
+ gst_value_get_fraction_denominator (xcontext->par), NULL);
+
+ gst_buffer_set_caps (GST_BUFFER (ximage), caps);
+ g_mutex_unlock (ximagesrc->x_lock);
+
+ gst_caps_unref (caps);
+ }
+
+ g_return_val_if_fail (GST_IS_XIMAGE_SRC (ximagesrc), NULL);
+#ifdef HAVE_XDAMAGE
+ if (ximagesrc->have_xdamage && ximagesrc->use_damage &&
+ ximagesrc->last_ximage != NULL) {
+ XEvent ev;
+
+ /* have_frame is TRUE when either the entire screen has been
+ * grabbed or when the last image has been copied */
+ gboolean have_frame = FALSE;
+
+ GST_DEBUG_OBJECT (ximagesrc, "Retrieving screen using XDamage");
+
+ do {
+ XNextEvent (ximagesrc->xcontext->disp, &ev);
+
+ if (ev.type == ximagesrc->damage_event_base + XDamageNotify) {
+ XserverRegion parts;
+ XRectangle *rects;
+ int nrects;
+
+ parts = XFixesCreateRegion (ximagesrc->xcontext->disp, 0, 0);
+ XDamageSubtract (ximagesrc->xcontext->disp, ximagesrc->damage, None,
+ parts);
+ /* Now copy out all of the damaged rectangles. */
+ rects = XFixesFetchRegion (ximagesrc->xcontext->disp, parts, &nrects);
+ if (rects != NULL) {
+ int i;
+
+ if (!have_frame) {
+ GST_LOG_OBJECT (ximagesrc,
+ "Copying from last frame ximage->size: %d",
+ GST_BUFFER_SIZE (GST_BUFFER (ximage)));
+ memcpy (GST_BUFFER_DATA (GST_BUFFER (ximage)),
+ GST_BUFFER_DATA (GST_BUFFER (ximagesrc->last_ximage)),
+ GST_BUFFER_SIZE (GST_BUFFER (ximage)));
+ have_frame = TRUE;
+ }
+ for (i = 0; i < nrects; i++) {
+ GST_LOG_OBJECT (ximagesrc,
+ "Damaged sub-region @ %d,%d size %dx%d reported",
+ rects[i].x, rects[i].y, rects[i].width, rects[i].height);
+
+ /* if we only want a small area, clip this damage region to
+ * area we want */
+ if (ximagesrc->endx > ximagesrc->startx &&
+ ximagesrc->endy > ximagesrc->starty) {
+ /* see if damage area intersects */
+ if (rects[i].x + rects[i].width < ximagesrc->startx ||
+ rects[i].x > ximagesrc->endx) {
+ /* trivial reject */
+ } else if (rects[i].y + rects[i].height < ximagesrc->starty ||
+ rects[i].y > ximagesrc->endy) {
+ /* trivial reject */
+ } else {
+ /* find intersect region */
+ int startx, starty, width, height;
+
+ startx = (rects[i].x < ximagesrc->startx) ? ximagesrc->startx :
+ rects[i].x;
+ starty = (rects[i].y < ximagesrc->starty) ? ximagesrc->starty :
+ rects[i].y;
+ width = (rects[i].x + rects[i].width < ximagesrc->endx) ?
+ rects[i].x + rects[i].width - startx :
+ ximagesrc->endx - startx;
+ height = (rects[i].y + rects[i].height < ximagesrc->endy) ?
+ rects[i].y + rects[i].height - starty : ximagesrc->endy -
+ starty;
+
+ GST_LOG_OBJECT (ximagesrc,
+ "Retrieving damaged sub-region @ %d,%d size %dx%d as intersect region",
+ startx, starty, width, height);
+ XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
+ startx, starty, width, height, AllPlanes, ZPixmap,
+ ximage->ximage, startx - ximagesrc->startx,
+ starty - ximagesrc->starty);
+ }
+ } else {
+
+ GST_LOG_OBJECT (ximagesrc,
+ "Retrieving damaged sub-region @ %d,%d size %dx%d",
+ rects[i].x, rects[i].y, rects[i].width, rects[i].height);
+
+ XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
+ rects[i].x, rects[i].y,
+ rects[i].width, rects[i].height,
+ AllPlanes, ZPixmap, ximage->ximage, rects[i].x, rects[i].y);
+ }
+ }
+ free (rects);
+ }
+ }
+ } while (XPending (ximagesrc->xcontext->disp));
+ if (!have_frame) {
+ GST_LOG_OBJECT (ximagesrc,
+ "Copying from last frame ximage->size: %d",
+ GST_BUFFER_SIZE (GST_BUFFER (ximage)));
+ memcpy (GST_BUFFER_DATA (GST_BUFFER (ximage)),
+ GST_BUFFER_DATA (GST_BUFFER (ximagesrc->last_ximage)),
+ GST_BUFFER_SIZE (GST_BUFFER (ximage)));
+ have_frame = TRUE;
+ }
+#ifdef HAVE_XFIXES
+ /* re-get area where last mouse pointer was but only if in our clipping
+ * bounds */
+ if (ximagesrc->cursor_image) {
+ gint x, y, width, height;
+
+ x = ximagesrc->cursor_image->x - ximagesrc->cursor_image->xhot;
+ y = ximagesrc->cursor_image->y - ximagesrc->cursor_image->yhot;
+ width = ximagesrc->cursor_image->width;
+ height = ximagesrc->cursor_image->height;
+
+ /* bounds checking */
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+ if (x + width > ximagesrc->xcontext->width)
+ width = ximagesrc->xcontext->width - x;
+ if (y + height > ximagesrc->xcontext->height)
+ height = ximagesrc->xcontext->height - y;
+ g_assert (x >= 0);
+ g_assert (y >= 0);
+ GST_DEBUG_OBJECT (ximagesrc,
+ "Cursor was at (%d,%d) width: %d, height: %d and our range is: (%d,%d) - (%d,%d)",
+ x, y, width, height, ximagesrc->startx, ximagesrc->starty,
+ ximagesrc->endx, ximagesrc->endy);
+ /* only get where cursor last was, if it is in our range */
+ if (ximagesrc->endx > ximagesrc->startx &&
+ ximagesrc->endy > ximagesrc->starty) {
+ /* check bounds */
+ if (x + width < ximagesrc->startx || x > ximagesrc->endx) {
+ /* trivial reject */
+ } else if (y + height < ximagesrc->starty || y > ximagesrc->endy) {
+ /* trivial reject */
+ } else {
+ /* find intersect region */
+ int startx, starty, iwidth, iheight;
+
+ startx = (x < ximagesrc->startx) ? ximagesrc->startx : x;
+ starty = (y < ximagesrc->starty) ? ximagesrc->starty : y;
+ iwidth = (x + width < ximagesrc->endx) ?
+ x + width - startx : ximagesrc->endx - startx;
+ iheight = (y + height < ximagesrc->endy) ?
+ y + height - starty : ximagesrc->endy - starty;
+ GST_DEBUG_OBJECT (ximagesrc, "Removing cursor from %d,%d", x, y);
+ XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
+ startx, starty, iwidth, iheight, AllPlanes, ZPixmap,
+ ximage->ximage, startx - ximagesrc->startx,
+ starty - ximagesrc->starty);
+ }
+ } else {
+
+ GST_DEBUG_OBJECT (ximagesrc, "Removing cursor from %d,%d", x, y);
+ XGetSubImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
+ x, y, width, height, AllPlanes, ZPixmap, ximage->ximage, x, y);
+ }
+ }
+#endif
+
+
+ } else {
+#endif
+
+#ifdef HAVE_XSHM
+ if (ximagesrc->xcontext->use_xshm) {
+ GST_DEBUG_OBJECT (ximagesrc, "Retrieving screen using XShm");
+ XShmGetImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
+ ximage->ximage, ximagesrc->startx, ximagesrc->starty, AllPlanes);
+
+ } else
+#endif /* HAVE_XSHM */
+ {
+ GST_DEBUG_OBJECT (ximagesrc, "Retrieving screen using XGetImage");
+ ximage->ximage = XGetImage (ximagesrc->xcontext->disp, ximagesrc->xwindow,
+ ximagesrc->startx, ximagesrc->starty, ximagesrc->width,
+ ximagesrc->height, AllPlanes, ZPixmap);
+ }
+#ifdef HAVE_XDAMAGE
+ }
+#endif
+
+#ifdef HAVE_XFIXES
+ if (ximagesrc->show_pointer && ximagesrc->have_xfixes) {
+
+ GST_DEBUG_OBJECT (ximagesrc, "Using XFixes to draw cursor");
+ /* get cursor */
+ if (ximagesrc->cursor_image)
+ XFree (ximagesrc->cursor_image);
+ ximagesrc->cursor_image = XFixesGetCursorImage (ximagesrc->xcontext->disp);
+ if (ximagesrc->cursor_image != NULL) {
+ int cx, cy, i, j, count;
+ int startx, starty, iwidth, iheight;
+ gboolean clipped = FALSE;
+ gboolean cursor_in_image = TRUE;
+
+ cx = ximagesrc->cursor_image->x - ximagesrc->cursor_image->xhot;
+ if (cx < 0)
+ cx = 0;
+ cy = ximagesrc->cursor_image->y - ximagesrc->cursor_image->yhot;
+ if (cy < 0)
+ cy = 0;
+ count = ximagesrc->cursor_image->width * ximagesrc->cursor_image->height;
+
+ /* only get where cursor last was, if it is in our range */
+ if (ximagesrc->endx > ximagesrc->startx &&
+ ximagesrc->endy > ximagesrc->starty) {
+ /* check bounds */
+ if (cx + ximagesrc->cursor_image->width < ximagesrc->startx ||
+ cx > ximagesrc->endx) {
+ /* trivial reject */
+ cursor_in_image = FALSE;
+ } else if (cy + ximagesrc->cursor_image->height < ximagesrc->starty ||
+ cy > ximagesrc->endy) {
+ /* trivial reject */
+ cursor_in_image = FALSE;
+ } else {
+ /* find intersect region */
+
+ startx = (cx < ximagesrc->startx) ? ximagesrc->startx : cx;
+ starty = (cy < ximagesrc->starty) ? ximagesrc->starty : cy;
+ iwidth = (cx + ximagesrc->cursor_image->width < ximagesrc->endx) ?
+ cx + ximagesrc->cursor_image->width - startx :
+ ximagesrc->endx - startx;
+ iheight = (cy + ximagesrc->cursor_image->height < ximagesrc->endy) ?
+ cy + ximagesrc->cursor_image->height - starty :
+ ximagesrc->endy - starty;
+ clipped = TRUE;
+ }
+ } else {
+ startx = cx;
+ starty = cy;
+ iwidth = ximagesrc->cursor_image->width;
+ iheight = ximagesrc->cursor_image->height;
+ }
+
+ if (cursor_in_image) {
+ GST_DEBUG_OBJECT (ximagesrc, "Cursor is in image so trying to draw it");
+ for (i = 0; i < count; i++)
+ ximagesrc->cursor_image->pixels[i] =
+ GUINT_TO_LE (ximagesrc->cursor_image->pixels[i]);
+ /* copy those pixels across */
+ for (j = starty;
+ j < starty + iheight && j < ximagesrc->starty + ximagesrc->height;
+ j++) {
+ for (i = startx;
+ i < startx + iwidth && i < ximagesrc->startx + ximagesrc->width;
+ i++) {
+ guint8 *src, *dest;
+
+ src =
+ (guint8 *) & (ximagesrc->cursor_image->pixels[((j -
+ cy) * ximagesrc->cursor_image->width + (i - cx))]);
+ dest =
+ (guint8 *) & (ximage->ximage->data[((j -
+ ximagesrc->starty) * ximagesrc->width + (i -
+ ximagesrc->startx)) * (ximagesrc->xcontext->bpp /
+ 8)]);
+
+ composite_pixel (ximagesrc->xcontext, (guint8 *) dest,
+ (guint8 *) src);
+ }
+ }
+ }
+ }
+ }
+#endif
+#ifdef HAVE_XDAMAGE
+ if (ximagesrc->have_xdamage && ximagesrc->use_damage) {
+ /* need to ref ximage to put in last_ximage */
+ gst_buffer_ref (GST_BUFFER (ximage));
+ if (ximagesrc->last_ximage) {
+ gst_buffer_unref (GST_BUFFER (ximagesrc->last_ximage));
+ }
+ ximagesrc->last_ximage = ximage;
+ GST_LOG_OBJECT (ximagesrc, "reffing current buffer for last_ximage");
+ }
+#endif
+ return ximage;
+}
+
+static GstFlowReturn
+gst_ximage_src_create (GstPushSrc * bs, GstBuffer ** buf)
+{
+ GstXImageSrc *s = GST_XIMAGE_SRC (bs);
+ GstXImageSrcBuffer *image;
+ GstClockTime base_time;
+ GstClockTime next_capture_ts;
+ GstClockTime dur;
+ gint64 next_frame_no;
+
+ if (!gst_ximage_src_recalc (s)) {
+ GST_ELEMENT_ERROR (s, RESOURCE, FAILED,
+ ("Changing resolution at runtime is not yet supported."), (NULL));
+ return GST_FLOW_ERROR;
+ }
+
+ if (s->fps_n <= 0 || s->fps_d <= 0)
+ return GST_FLOW_NOT_NEGOTIATED; /* FPS must be > 0 */
+
+ /* Now, we might need to wait for the next multiple of the fps
+ * before capturing */
+
+ GST_OBJECT_LOCK (s);
+ if (GST_ELEMENT_CLOCK (s) == NULL) {
+ GST_OBJECT_UNLOCK (s);
+ GST_ELEMENT_ERROR (s, RESOURCE, FAILED,
+ ("Cannot operate without a clock"), (NULL));
+ return GST_FLOW_ERROR;
+ }
+
+ base_time = GST_ELEMENT_CAST (s)->base_time;
+ next_capture_ts = gst_clock_get_time (GST_ELEMENT_CLOCK (s));
+ next_capture_ts -= base_time;
+
+ /* Figure out which 'frame number' position we're at, based on the cur time
+ * and frame rate */
+ next_frame_no = gst_util_uint64_scale (next_capture_ts,
+ s->fps_n, GST_SECOND * s->fps_d);
+ if (next_frame_no == s->last_frame_no) {
+ GstClockID id;
+ GstClockReturn ret;
+
+ /* Need to wait for the next frame */
+ next_frame_no += 1;
+
+ /* Figure out what the next frame time is */
+ next_capture_ts = gst_util_uint64_scale (next_frame_no,
+ s->fps_d * GST_SECOND, s->fps_n);
+
+ id = gst_clock_new_single_shot_id (GST_ELEMENT_CLOCK (s),
+ next_capture_ts + base_time);
+ s->clock_id = id;
+
+ /* release the object lock while waiting */
+ GST_OBJECT_UNLOCK (s);
+
+ GST_DEBUG_OBJECT (s, "Waiting for next frame time %" G_GUINT64_FORMAT,
+ next_capture_ts);
+ ret = gst_clock_id_wait (id, NULL);
+ GST_OBJECT_LOCK (s);
+
+ gst_clock_id_unref (id);
+ s->clock_id = NULL;
+ if (ret == GST_CLOCK_UNSCHEDULED) {
+ /* Got woken up by the unlock function */
+ GST_OBJECT_UNLOCK (s);
+ return GST_FLOW_WRONG_STATE;
+ }
+ /* Duration is a complete 1/fps frame duration */
+ dur = gst_util_uint64_scale_int (GST_SECOND, s->fps_d, s->fps_n);
+ } else {
+ GstClockTime next_frame_ts;
+
+ GST_DEBUG_OBJECT (s, "No need to wait for next frame time %"
+ G_GUINT64_FORMAT " next frame = %" G_GINT64_FORMAT " prev = %"
+ G_GINT64_FORMAT, next_capture_ts, next_frame_no, s->last_frame_no);
+ next_frame_ts = gst_util_uint64_scale (next_frame_no + 1,
+ s->fps_d * GST_SECOND, s->fps_n);
+ /* Frame duration is from now until the next expected capture time */
+ dur = next_frame_ts - next_capture_ts;
+ }
+ s->last_frame_no = next_frame_no;
+ GST_OBJECT_UNLOCK (s);
+
+ image = gst_ximage_src_ximage_get (s);
+ if (!image)
+ return GST_FLOW_ERROR;
+
+ *buf = GST_BUFFER (image);
+ GST_BUFFER_TIMESTAMP (*buf) = next_capture_ts;
+ GST_BUFFER_DURATION (*buf) = dur;
+
+ return GST_FLOW_OK;
+}
+
+static void
+gst_ximage_src_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstXImageSrc *src = GST_XIMAGE_SRC (object);
+
+ switch (prop_id) {
+ case PROP_DISPLAY_NAME:
+
+ g_free (src->display_name);
+ src->display_name = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_SCREEN_NUM:
+ src->screen_num = g_value_get_uint (value);
+ break;
+ case PROP_SHOW_POINTER:
+ src->show_pointer = g_value_get_boolean (value);
+ break;
+ case PROP_USE_DAMAGE:
+ src->use_damage = g_value_get_boolean (value);
+ break;
+ case PROP_STARTX:
+ src->startx = g_value_get_uint (value);
+ break;
+ case PROP_STARTY:
+ src->starty = g_value_get_uint (value);
+ break;
+ case PROP_ENDX:
+ src->endx = g_value_get_uint (value);
+ break;
+ case PROP_ENDY:
+ src->endy = g_value_get_uint (value);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
+gst_ximage_src_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
+{
+ GstXImageSrc *src = GST_XIMAGE_SRC (object);
+
+ switch (prop_id) {
+ case PROP_DISPLAY_NAME:
+ if (src->xcontext)
+ g_value_set_string (value, DisplayString (src->xcontext->disp));
+ else
+ g_value_set_string (value, src->display_name);
+
+ break;
+ case PROP_SCREEN_NUM:
+ g_value_set_uint (value, src->screen_num);
+ break;
+ case PROP_SHOW_POINTER:
+ g_value_set_boolean (value, src->show_pointer);
+ break;
+ case PROP_USE_DAMAGE:
+ g_value_set_boolean (value, src->use_damage);
+ break;
+ case PROP_STARTX:
+ g_value_set_uint (value, src->startx);
+ break;
+ case PROP_STARTY:
+ g_value_set_uint (value, src->starty);
+ break;
+ case PROP_ENDX:
+ g_value_set_uint (value, src->endx);
+ break;
+ case PROP_ENDY:
+ g_value_set_uint (value, src->endy);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_ximage_src_clear_bufpool (GstXImageSrc * ximagesrc)
+{
+ g_mutex_lock (ximagesrc->pool_lock);
+ while (ximagesrc->buffer_pool != NULL) {
+ GstXImageSrcBuffer *ximage = ximagesrc->buffer_pool->data;
+
+ gst_ximage_buffer_free (ximage);
+
+ ximagesrc->buffer_pool = g_slist_delete_link (ximagesrc->buffer_pool,
+ ximagesrc->buffer_pool);
+ }
+ g_mutex_unlock (ximagesrc->pool_lock);
+}
+
+static void
+gst_ximage_src_base_init (gpointer g_class)
+{
+ GstElementClass *ec = GST_ELEMENT_CLASS (g_class);
+
+ gst_element_class_set_details (ec, &ximagesrc_details);
+ gst_element_class_add_pad_template (ec, gst_static_pad_template_get (&t));
+}
+
+static void
+gst_ximage_src_dispose (GObject * object)
+{
+ /* Drop references in the buffer_pool */
+ gst_ximage_src_clear_bufpool (GST_XIMAGE_SRC (object));
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+gst_ximage_src_finalize (GObject * object)
+{
+ GstXImageSrc *src = GST_XIMAGE_SRC (object);
+
+ if (src->xcontext)
+ ximageutil_xcontext_clear (src->xcontext);
+
+ g_mutex_free (src->pool_lock);
+ g_mutex_free (src->x_lock);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static GstCaps *
+gst_ximage_src_get_caps (GstBaseSrc * bs)
+{
+ GstXImageSrc *s = GST_XIMAGE_SRC (bs);
+ GstXContext *xcontext;
+ gint x, y, width, height;
+
+ if ((!s->xcontext) && (!gst_ximage_src_open_display (s, s->display_name)))
+ return
+ gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC
+ (s)->srcpad));
+
+ if (!gst_ximage_src_recalc (s))
+ return
+ gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC
+ (s)->srcpad));
+
+ xcontext = s->xcontext;
+
+ x = y = 0;
+ width = xcontext->width;
+ height = xcontext->height;
+ if (s->endx > s->startx && s->endy > s->starty) {
+ /* this means user has put in values */
+ if (s->startx < xcontext->width && s->endx < xcontext->width &&
+ s->starty < xcontext->height && s->endy < xcontext->height) {
+ /* values are fine */
+ x = s->startx;
+ y = s->starty;
+ s->width = width = s->endx - s->startx;
+ s->height = height = s->endy - s->starty;
+ } else {
+ GST_WARNING
+ ("User put in co-ordinates overshooting the X resolution, setting to full screen");
+ s->startx = 0;
+ s->starty = 0;
+ s->endx = 0;
+ s->endy = 0;
+ }
+ } else {
+ GST_WARNING ("User put in bogus co-ordinates, setting to full screen");
+ s->startx = 0;
+ s->starty = 0;
+ s->endx = 0;
+ s->endy = 0;
+ }
+ GST_DEBUG ("width = %d, height=%d", width, height);
+ return gst_caps_new_simple ("video/x-raw-rgb",
+ "bpp", G_TYPE_INT, xcontext->bpp,
+ "depth", G_TYPE_INT, xcontext->depth,
+ "endianness", G_TYPE_INT, xcontext->endianness,
+ "red_mask", G_TYPE_INT, xcontext->r_mask_output,
+ "green_mask", G_TYPE_INT, xcontext->g_mask_output,
+ "blue_mask", G_TYPE_INT, xcontext->b_mask_output,
+ "width", G_TYPE_INT, width,
+ "height", G_TYPE_INT, height,
+ "framerate", GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1,
+ "pixel-aspect-ratio", GST_TYPE_FRACTION_RANGE, 1, G_MAXINT, G_MAXINT, 1,
+ NULL);
+}
+
+static gboolean
+gst_ximage_src_set_caps (GstBaseSrc * bs, GstCaps * caps)
+{
+ GstXImageSrc *s = GST_XIMAGE_SRC (bs);
+ GstStructure *structure;
+ const GValue *new_fps;
+
+ /* If not yet opened, disallow setcaps until later */
+ if (!s->xcontext)
+ return FALSE;
+
+ /* The only thing that can change is the framerate downstream wants */
+ structure = gst_caps_get_structure (caps, 0);
+ new_fps = gst_structure_get_value (structure, "framerate");
+ if (!new_fps)
+ return FALSE;
+
+ /* Store this FPS for use when generating buffers */
+ s->fps_n = gst_value_get_fraction_numerator (new_fps);
+ s->fps_d = gst_value_get_fraction_denominator (new_fps);
+
+ GST_DEBUG_OBJECT (s, "peer wants %d/%d fps", s->fps_n, s->fps_d);
+
+ return TRUE;
+}
+
+static void
+gst_ximage_src_fixate (GstPad * pad, GstCaps * caps)
+{
+ gint i;
+ GstStructure *structure;
+
+ for (i = 0; i < gst_caps_get_size (caps); ++i) {
+ structure = gst_caps_get_structure (caps, i);
+
+ gst_structure_fixate_field_nearest_fraction (structure, "framerate", 25, 1);
+ }
+}
+
+static void
+gst_ximage_src_class_init (GstXImageSrcClass * klass)
+{
+ GObjectClass *gc = G_OBJECT_CLASS (klass);
+ GstBaseSrcClass *bc = GST_BASE_SRC_CLASS (klass);
+ GstPushSrcClass *push_class = GST_PUSH_SRC_CLASS (klass);
+
+ gc->set_property = gst_ximage_src_set_property;
+ gc->get_property = gst_ximage_src_get_property;
+ gc->dispose = gst_ximage_src_dispose;
+ gc->finalize = gst_ximage_src_finalize;
+
+ g_object_class_install_property (gc, PROP_DISPLAY_NAME,
+ g_param_spec_string ("display-name", "Display", "X Display Name", NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gc, PROP_SCREEN_NUM,
+ g_param_spec_uint ("screen-num", "Screen number", "X Screen Number",
+ 0, G_MAXINT, 0, G_PARAM_READWRITE));
+ g_object_class_install_property (gc, PROP_SHOW_POINTER,
+ g_param_spec_boolean ("show-pointer", "Show Mouse Pointer",
+ "Show mouse pointer (if XFixes extension enabled)", TRUE,
+ G_PARAM_READWRITE));
+ /**
+ * GstXImageSrc:use-damage
+ *
+ * Use XDamage (if the XDamage extension is enabled)
+ *
+ * Since: 0.10.4
+ **/
+ g_object_class_install_property (gc, PROP_USE_DAMAGE,
+ g_param_spec_boolean ("use-damage", "Use XDamage",
+ "Use XDamage (if XDamage extension enabled)", TRUE,
+ G_PARAM_READWRITE));
+ /**
+ * GstXImageSrc:startx
+ *
+ * X coordinate of top left corner of area to be recorded
+ * (0 for top left of screen)
+ *
+ * Since: 0.10.4
+ **/
+ g_object_class_install_property (gc, PROP_STARTX,
+ g_param_spec_uint ("startx", "Start X co-ordinate",
+ "X coordinate of top left corner of area to be recorded (0 for top left of screen)",
+ 0, G_MAXINT, 0, G_PARAM_READWRITE));
+ /**
+ * GstXImageSrc:starty
+ *
+ * Y coordinate of top left corner of area to be recorded
+ * (0 for top left of screen)
+ *
+ * Since: 0.10.4
+ **/
+ g_object_class_install_property (gc, PROP_STARTY,
+ g_param_spec_uint ("starty", "Start Y co-ordinate",
+ "Y coordinate of top left corner of area to be recorded (0 for top left of screen)",
+ 0, G_MAXINT, 0, G_PARAM_READWRITE));
+ /**
+ * GstXImageSrc:endx
+ *
+ * X coordinate of bottom right corner of area to be recorded
+ * (0 for bottom right of screen)
+ *
+ * Since: 0.10.4
+ **/
+ g_object_class_install_property (gc, PROP_ENDX,
+ g_param_spec_uint ("endx", "End X",
+ "X coordinate of bottom right corner of area to be recorded (0 for bottom right of screen)",
+ 0, G_MAXINT, 0, G_PARAM_READWRITE));
+ /**
+ * GstXImageSrc:endy
+ *
+ * Y coordinate of bottom right corner of area to be recorded
+ * (0 for bottom right of screen)
+ *
+ * Since: 0.10.4
+ **/
+ g_object_class_install_property (gc, PROP_ENDY,
+ g_param_spec_uint ("endy", "End Y",
+ "Y coordinate of bottom right corner of area to be recorded (0 for bottom right of screen)",
+ 0, G_MAXINT, 0, G_PARAM_READWRITE));
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ push_class->create = gst_ximage_src_create;
+ bc->get_caps = gst_ximage_src_get_caps;
+ bc->set_caps = gst_ximage_src_set_caps;
+ bc->start = gst_ximage_src_start;
+ bc->stop = gst_ximage_src_stop;
+ bc->unlock = gst_ximage_src_unlock;
+}
+
+static void
+gst_ximage_src_init (GstXImageSrc * ximagesrc, GstXImageSrcClass * klass)
+{
+ gst_base_src_set_live (GST_BASE_SRC (ximagesrc), TRUE);
+ gst_pad_set_fixatecaps_function (GST_BASE_SRC_PAD (ximagesrc),
+ gst_ximage_src_fixate);
+
+ ximagesrc->pool_lock = g_mutex_new ();
+ ximagesrc->x_lock = g_mutex_new ();
+ ximagesrc->show_pointer = TRUE;
+ ximagesrc->use_damage = TRUE;
+ ximagesrc->startx = 0;
+ ximagesrc->starty = 0;
+ ximagesrc->endx = 0;
+ ximagesrc->endy = 0;
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+ gboolean ret;
+
+ GST_DEBUG_CATEGORY_INIT (gst_debug_ximage_src, "ximagewsrc", 0,
+ "ximagesrc element debug");
+
+ ret = gst_element_register (plugin, "ximagewsrc", GST_RANK_NONE,
+ GST_TYPE_XIMAGE_SRC);
+
+ return ret;
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "ximagewsrc",
+ "X11 video input plugin using standard Xlib calls, with added watermark and scaling",
+ plugin_init, VERSION, GST_LICENSE, "GStreamer private plugins", "By JP");
--- /dev/null
+/* screenshotsrc: Screenshot plugin for GStreamer
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_XIMAGE_SRC_H__
+#define __GST_XIMAGE_SRC_H__
+
+#include <gst/gst.h>
+#include <gst/base/gstpushsrc.h>
+#include "ximageutil.h"
+
+#ifdef HAVE_XFIXES
+#include <X11/extensions/Xfixes.h>
+#endif
+#ifdef HAVE_XDAMAGE
+#include <X11/extensions/Xdamage.h>
+#endif
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_XIMAGE_SRC (gst_ximage_src_get_type())
+#define GST_XIMAGE_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_XIMAGE_SRC,GstXImageSrc))
+#define GST_XIMAGE_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_XIMAGE_SRC,GstXImageSrc))
+#define GST_IS_XIMAGE_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_XIMAGE_SRC))
+#define GST_IS_XIMAGE_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_XIMAGE_SRC))
+
+typedef struct _GstXImageSrc GstXImageSrc;
+typedef struct _GstXImageSrcClass GstXImageSrcClass;
+
+GType gst_ximage_src_get_type (void) G_GNUC_CONST;
+
+struct _GstXImageSrc
+{
+ GstPushSrc parent;
+
+ /* Information on display */
+ GstXContext *xcontext;
+ gint width;
+ gint height;
+
+ Window xwindow;
+ gchar *display_name;
+ guint screen_num;
+
+ /* Desired output framerate */
+ gint fps_n;
+ gint fps_d;
+
+ /* for framerate sync */
+ GstClockID clock_id;
+ gint64 last_frame_no;
+
+ /* Protect X Windows calls */
+ GMutex *x_lock;
+
+ /* Gathered pool of emitted buffers */
+ GMutex *pool_lock;
+ GSList *buffer_pool;
+
+ /* XFixes and XDamage support */
+ gboolean have_xfixes;
+ gboolean have_xdamage;
+ gboolean show_pointer;
+ gboolean use_damage;
+
+ /* co-ordinates for start and end */
+ guint startx;
+ guint starty;
+ guint endx;
+ guint endy;
+
+#ifdef HAVE_XFIXES
+ int fixes_event_base;
+ XFixesCursorImage *cursor_image;
+#endif
+#ifdef HAVE_XDAMAGE
+ Damage damage;
+ int damage_event_base;
+ XserverRegion damage_region;
+ GC damage_copy_gc;
+ GstXImageSrcBuffer *last_ximage;
+#endif
+};
+
+struct _GstXImageSrcClass
+{
+ GstPushSrcClass parent_class;
+};
+
+G_END_DECLS
+
+#endif /* __GST_XIMAGE_SRC_H__ */
--- /dev/null
+/* GStreamer
+ * Copyright (C) <2005> Luca Ognibene <luogni@tin.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "ximageutil.h"
+
+#ifdef HAVE_XSHM
+static gboolean error_caught = FALSE;
+
+static int
+ximageutil_handle_xerror (Display * display, XErrorEvent * xevent)
+{
+ char error_msg[1024];
+
+ XGetErrorText (display, xevent->error_code, error_msg, 1024);
+ GST_DEBUG ("ximageutil failed to use XShm calls. error: %s", error_msg);
+ error_caught = TRUE;
+ return 0;
+}
+
+/* This function checks that it is actually really possible to create an image
+ using XShm */
+gboolean
+ximageutil_check_xshm_calls (GstXContext * xcontext)
+{
+ XImage *ximage;
+ XShmSegmentInfo SHMInfo;
+ size_t size;
+ int (*handler) (Display *, XErrorEvent *);
+ gboolean result = FALSE;
+ gboolean did_attach = FALSE;
+
+ g_return_val_if_fail (xcontext != NULL, FALSE);
+
+ /* Sync to ensure any older errors are already processed */
+ XSync (xcontext->disp, FALSE);
+
+ /* Set defaults so we don't free these later unnecessarily */
+ SHMInfo.shmaddr = ((void *) -1);
+ SHMInfo.shmid = -1;
+
+ /* Setting an error handler to catch failure */
+ error_caught = FALSE;
+ handler = XSetErrorHandler (ximageutil_handle_xerror);
+
+ /* Trying to create a 1x1 ximage */
+ GST_DEBUG ("XShmCreateImage of 1x1");
+
+ ximage = XShmCreateImage (xcontext->disp, xcontext->visual,
+ xcontext->depth, ZPixmap, NULL, &SHMInfo, 1, 1);
+
+ /* Might cause an error, sync to ensure it is noticed */
+ XSync (xcontext->disp, FALSE);
+ if (!ximage || error_caught) {
+ GST_WARNING ("could not XShmCreateImage a 1x1 image");
+ goto beach;
+ }
+ size = ximage->height * ximage->bytes_per_line;
+
+ SHMInfo.shmid = shmget (IPC_PRIVATE, size, IPC_CREAT | 0777);
+ if (SHMInfo.shmid == -1) {
+ GST_WARNING ("could not get shared memory of %" G_GSIZE_FORMAT " bytes",
+ size);
+ goto beach;
+ }
+
+ SHMInfo.shmaddr = shmat (SHMInfo.shmid, 0, 0);
+ if (SHMInfo.shmaddr == ((void *) -1)) {
+ GST_WARNING ("Failed to shmat: %s", g_strerror (errno));
+ goto beach;
+ }
+
+ /* Delete the SHM segment. It will actually go away automatically
+ * when we detach now */
+ shmctl (SHMInfo.shmid, IPC_RMID, 0);
+
+ ximage->data = SHMInfo.shmaddr;
+ SHMInfo.readOnly = FALSE;
+
+ if (XShmAttach (xcontext->disp, &SHMInfo) == 0) {
+ GST_WARNING ("Failed to XShmAttach");
+ goto beach;
+ }
+
+ /* Sync to ensure we see any errors we caused */
+ XSync (xcontext->disp, FALSE);
+
+ if (!error_caught) {
+ did_attach = TRUE;
+ /* store whether we succeeded in result */
+ result = TRUE;
+ }
+beach:
+ /* Sync to ensure we swallow any errors we caused and reset error_caught */
+ XSync (xcontext->disp, FALSE);
+ error_caught = FALSE;
+ XSetErrorHandler (handler);
+
+ if (did_attach) {
+ XShmDetach (xcontext->disp, &SHMInfo);
+ XSync (xcontext->disp, FALSE);
+ }
+ if (SHMInfo.shmaddr != ((void *) -1))
+ shmdt (SHMInfo.shmaddr);
+ if (ximage)
+ XDestroyImage (ximage);
+ return result;
+}
+#endif /* HAVE_XSHM */
+
+/* This function gets the X Display and global info about it. Everything is
+ stored in our object and will be cleaned when the object is disposed. Note
+ here that caps for supported format are generated without any window or
+ image creation */
+GstXContext *
+ximageutil_xcontext_get (GstElement * parent, const gchar * display_name)
+{
+ GstXContext *xcontext = NULL;
+ XPixmapFormatValues *px_formats = NULL;
+ gint nb_formats = 0, i;
+
+ xcontext = g_new0 (GstXContext, 1);
+
+ xcontext->disp = XOpenDisplay (display_name);
+ GST_DEBUG_OBJECT (parent, "opened display %p", xcontext->disp);
+ if (!xcontext->disp) {
+ g_free (xcontext);
+ return NULL;
+ }
+ xcontext->screen = DefaultScreenOfDisplay (xcontext->disp);
+ xcontext->screen_num = DefaultScreen (xcontext->disp);
+ xcontext->visual = DefaultVisual (xcontext->disp, xcontext->screen_num);
+ xcontext->root = DefaultRootWindow (xcontext->disp);
+ xcontext->white = XWhitePixel (xcontext->disp, xcontext->screen_num);
+ xcontext->black = XBlackPixel (xcontext->disp, xcontext->screen_num);
+ xcontext->depth = DefaultDepthOfScreen (xcontext->screen);
+
+ xcontext->width = DisplayWidth (xcontext->disp, xcontext->screen_num);
+ xcontext->height = DisplayHeight (xcontext->disp, xcontext->screen_num);
+
+ xcontext->widthmm = DisplayWidthMM (xcontext->disp, xcontext->screen_num);
+ xcontext->heightmm = DisplayHeightMM (xcontext->disp, xcontext->screen_num);
+
+ xcontext->caps = NULL;
+
+ GST_DEBUG_OBJECT (parent, "X reports %dx%d pixels and %d mm x %d mm",
+ xcontext->width, xcontext->height, xcontext->widthmm, xcontext->heightmm);
+ ximageutil_calculate_pixel_aspect_ratio (xcontext);
+
+ /* We get supported pixmap formats at supported depth */
+ px_formats = XListPixmapFormats (xcontext->disp, &nb_formats);
+
+ if (!px_formats) {
+ XCloseDisplay (xcontext->disp);
+ g_free (xcontext);
+ return NULL;
+ }
+
+ /* We get bpp value corresponding to our running depth */
+ for (i = 0; i < nb_formats; i++) {
+ if (px_formats[i].depth == xcontext->depth)
+ xcontext->bpp = px_formats[i].bits_per_pixel;
+ }
+
+ XFree (px_formats);
+
+ xcontext->endianness =
+ (ImageByteOrder (xcontext->disp) ==
+ LSBFirst) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN;
+
+#ifdef HAVE_XSHM
+ /* Search for XShm extension support */
+ if (XShmQueryExtension (xcontext->disp) &&
+ ximageutil_check_xshm_calls (xcontext)) {
+ xcontext->use_xshm = TRUE;
+ GST_DEBUG ("ximageutil is using XShm extension");
+ } else {
+ xcontext->use_xshm = FALSE;
+ GST_DEBUG ("ximageutil is not using XShm extension");
+ }
+#endif /* HAVE_XSHM */
+
+ /* our caps system handles 24/32bpp RGB as big-endian. */
+ if ((xcontext->bpp == 24 || xcontext->bpp == 32) &&
+ xcontext->endianness == G_LITTLE_ENDIAN) {
+ xcontext->endianness = G_BIG_ENDIAN;
+ xcontext->r_mask_output = GUINT32_TO_BE (xcontext->visual->red_mask);
+ xcontext->g_mask_output = GUINT32_TO_BE (xcontext->visual->green_mask);
+ xcontext->b_mask_output = GUINT32_TO_BE (xcontext->visual->blue_mask);
+ if (xcontext->bpp == 24) {
+ xcontext->r_mask_output >>= 8;
+ xcontext->g_mask_output >>= 8;
+ xcontext->b_mask_output >>= 8;
+ }
+ } else {
+ xcontext->r_mask_output = xcontext->visual->red_mask;
+ xcontext->g_mask_output = xcontext->visual->green_mask;
+ xcontext->b_mask_output = xcontext->visual->blue_mask;
+ }
+
+ return xcontext;
+}
+
+/* This function cleans the X context. Closing the Display and unrefing the
+ caps for supported formats. */
+void
+ximageutil_xcontext_clear (GstXContext * xcontext)
+{
+ g_return_if_fail (xcontext != NULL);
+
+ if (xcontext->caps != NULL)
+ gst_caps_unref (xcontext->caps);
+
+ if (xcontext->par) {
+ g_value_unset (xcontext->par);
+ g_free (xcontext->par);
+ }
+
+ XCloseDisplay (xcontext->disp);
+
+ g_free (xcontext);
+}
+
+/* This function calculates the pixel aspect ratio based on the properties
+ * in the xcontext structure and stores it there. */
+void
+ximageutil_calculate_pixel_aspect_ratio (GstXContext * xcontext)
+{
+ gint par[][2] = {
+ {1, 1}, /* regular screen */
+ {16, 15}, /* PAL TV */
+ {11, 10}, /* 525 line Rec.601 video */
+ {54, 59} /* 625 line Rec.601 video */
+ };
+ gint i;
+ gint index;
+ gdouble ratio;
+ gdouble delta;
+
+#define DELTA(idx) (ABS (ratio - ((gdouble) par[idx][0] / par[idx][1])))
+
+ /* first calculate the "real" ratio based on the X values;
+ * which is the "physical" w/h divided by the w/h in pixels of the display */
+ ratio = (gdouble) (xcontext->widthmm * xcontext->height)
+ / (xcontext->heightmm * xcontext->width);
+
+ /* DirectFB's X in 720x576 reports the physical dimensions wrong, so
+ * override here */
+ if (xcontext->width == 720 && xcontext->height == 576) {
+ ratio = 4.0 * 576 / (3.0 * 720);
+ }
+ GST_DEBUG ("calculated pixel aspect ratio: %f", ratio);
+
+ /* now find the one from par[][2] with the lowest delta to the real one */
+ delta = DELTA (0);
+ index = 0;
+
+ for (i = 1; i < sizeof (par) / (sizeof (gint) * 2); ++i) {
+ gdouble this_delta = DELTA (i);
+
+ if (this_delta < delta) {
+ index = i;
+ delta = this_delta;
+ }
+ }
+
+ GST_DEBUG ("Decided on index %d (%d/%d)", index,
+ par[index][0], par[index][1]);
+
+ if (xcontext->par)
+ g_free (xcontext->par);
+ xcontext->par = g_new0 (GValue, 1);
+ g_value_init (xcontext->par, GST_TYPE_FRACTION);
+ gst_value_set_fraction (xcontext->par, par[index][0], par[index][1]);
+ GST_DEBUG ("set xcontext PAR to %d/%d\n",
+ gst_value_get_fraction_numerator (xcontext->par),
+ gst_value_get_fraction_denominator (xcontext->par));
+}
+
+static GstBufferClass *ximagesrc_buffer_parent_class = NULL;
+
+static void
+gst_ximagesrc_buffer_finalize (GstXImageSrcBuffer * ximage)
+{
+ GstElement *parent;
+
+ g_return_if_fail (ximage != NULL);
+
+ parent = ximage->parent;
+ if (parent == NULL) {
+ g_warning ("XImageSrcBuffer->ximagesrc == NULL");
+ goto beach;
+ }
+
+ if (ximage->return_func)
+ ximage->return_func (parent, ximage);
+
+beach:
+
+ GST_MINI_OBJECT_CLASS (ximagesrc_buffer_parent_class)->
+ finalize (GST_MINI_OBJECT (ximage));
+
+ return;
+}
+
+void
+gst_ximage_buffer_free (GstXImageSrcBuffer * ximage)
+{
+ /* make sure it is not recycled */
+ ximage->width = -1;
+ ximage->height = -1;
+ gst_buffer_unref (GST_BUFFER (ximage));
+}
+
+static void
+gst_ximagesrc_buffer_init (GstXImageSrcBuffer * ximage_buffer, gpointer g_class)
+{
+#ifdef HAVE_XSHM
+ ximage_buffer->SHMInfo.shmaddr = ((void *) -1);
+ ximage_buffer->SHMInfo.shmid = -1;
+#endif
+}
+
+static void
+gst_ximagesrc_buffer_class_init (gpointer g_class, gpointer class_data)
+{
+ GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
+
+ ximagesrc_buffer_parent_class = g_type_class_peek_parent (g_class);
+
+ mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
+ gst_ximagesrc_buffer_finalize;
+}
+
+GType
+gst_ximagesrc_buffer_get_type (void)
+{
+ static GType _gst_ximagesrc_buffer_type;
+
+ if (G_UNLIKELY (_gst_ximagesrc_buffer_type == 0)) {
+ static const GTypeInfo ximagesrc_buffer_info = {
+ sizeof (GstBufferClass),
+ NULL,
+ NULL,
+ gst_ximagesrc_buffer_class_init,
+ NULL,
+ NULL,
+ sizeof (GstXImageSrcBuffer),
+ 0,
+ (GInstanceInitFunc) gst_ximagesrc_buffer_init,
+ NULL
+ };
+ _gst_ximagesrc_buffer_type = g_type_register_static (GST_TYPE_BUFFER,
+ "GstXImageSrcBuffer", &ximagesrc_buffer_info, 0);
+ }
+ return _gst_ximagesrc_buffer_type;
+}
+
+/* This function handles GstXImageSrcBuffer creation depending on XShm availability */
+GstXImageSrcBuffer *
+gst_ximageutil_ximage_new (GstXContext * xcontext,
+ GstElement * parent, int width, int height, BufferReturnFunc return_func)
+{
+ GstXImageSrcBuffer *ximage = NULL;
+ gboolean succeeded = FALSE;
+
+ ximage =
+ (GstXImageSrcBuffer *) gst_mini_object_new (GST_TYPE_XIMAGESRC_BUFFER);
+
+ ximage->width = width;
+ ximage->height = height;
+
+#ifdef HAVE_XSHM
+ if (xcontext->use_xshm) {
+ ximage->ximage = XShmCreateImage (xcontext->disp,
+ xcontext->visual, xcontext->depth,
+ ZPixmap, NULL, &ximage->SHMInfo, ximage->width, ximage->height);
+ if (!ximage->ximage) {
+ goto beach;
+ }
+
+ /* we have to use the returned bytes_per_line for our shm size */
+ ximage->size = ximage->ximage->bytes_per_line * ximage->ximage->height;
+ ximage->SHMInfo.shmid = shmget (IPC_PRIVATE, ximage->size,
+ IPC_CREAT | 0777);
+ if (ximage->SHMInfo.shmid == -1)
+ goto beach;
+
+ ximage->SHMInfo.shmaddr = shmat (ximage->SHMInfo.shmid, 0, 0);
+ if (ximage->SHMInfo.shmaddr == ((void *) -1))
+ goto beach;
+
+ /* Delete the SHM segment. It will actually go away automatically
+ * when we detach now */
+ shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0);
+
+ ximage->ximage->data = ximage->SHMInfo.shmaddr;
+ ximage->SHMInfo.readOnly = FALSE;
+
+ if (XShmAttach (xcontext->disp, &ximage->SHMInfo) == 0)
+ goto beach;
+
+ XSync (xcontext->disp, FALSE);
+ } else
+#endif /* HAVE_XSHM */
+ {
+ ximage->ximage = XCreateImage (xcontext->disp,
+ xcontext->visual,
+ xcontext->depth,
+ ZPixmap, 0, NULL, ximage->width, ximage->height, xcontext->bpp, 0);
+ if (!ximage->ximage)
+ goto beach;
+
+ /* we have to use the returned bytes_per_line for our image size */
+ ximage->size = ximage->ximage->bytes_per_line * ximage->ximage->height;
+ ximage->ximage->data = g_malloc (ximage->size);
+
+ XSync (xcontext->disp, FALSE);
+ }
+ succeeded = TRUE;
+
+ GST_BUFFER_DATA (ximage) = (guchar *) ximage->ximage->data;
+ GST_BUFFER_SIZE (ximage) = ximage->size;
+
+ /* Keep a ref to our src */
+ ximage->parent = gst_object_ref (parent);
+ ximage->return_func = return_func;
+beach:
+ if (!succeeded) {
+ gst_ximage_buffer_free (ximage);
+ ximage = NULL;
+ }
+
+ return ximage;
+}
+
+/* This function destroys a GstXImageBuffer handling XShm availability */
+void
+gst_ximageutil_ximage_destroy (GstXContext * xcontext,
+ GstXImageSrcBuffer * ximage)
+{
+ /* We might have some buffers destroyed after changing state to NULL */
+ if (!xcontext)
+ goto beach;
+
+ g_return_if_fail (ximage != NULL);
+
+#ifdef HAVE_XSHM
+ if (xcontext->use_xshm) {
+ if (ximage->SHMInfo.shmaddr != ((void *) -1)) {
+ XShmDetach (xcontext->disp, &ximage->SHMInfo);
+ XSync (xcontext->disp, 0);
+ shmdt (ximage->SHMInfo.shmaddr);
+ }
+ if (ximage->ximage)
+ XDestroyImage (ximage->ximage);
+
+ } else
+#endif /* HAVE_XSHM */
+ {
+ if (ximage->ximage) {
+ XDestroyImage (ximage->ximage);
+ }
+ }
+
+ XSync (xcontext->disp, FALSE);
+beach:
+ if (ximage->parent) {
+ /* Release the ref to our parent */
+ gst_object_unref (ximage->parent);
+ ximage->parent = NULL;
+ }
+
+ return;
+}
--- /dev/null
+/* GStreamer
+ * Copyright (C) <2005> Luca Ognibene <luogni@tin.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_XIMAGEUTIL_H__
+#define __GST_XIMAGEUTIL_H__
+
+#include <gst/gst.h>
+
+#ifdef HAVE_XSHM
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#endif /* HAVE_XSHM */
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#ifdef HAVE_XSHM
+#include <X11/extensions/XShm.h>
+#endif /* HAVE_XSHM */
+
+#include <string.h>
+#include <math.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GstXContext GstXContext;
+typedef struct _GstXWindow GstXWindow;
+typedef struct _GstXImage GstXImage;
+typedef struct _GstXImageSrcBuffer GstXImageSrcBuffer;
+
+/* Global X Context stuff */
+/**
+ * GstXContext:
+ * @disp: the X11 Display of this context
+ * @screen: the default Screen of Display @disp
+ * @screen_num: the Screen number of @screen
+ * @visual: the default Visual of Screen @screen
+ * @root: the root Window of Display @disp
+ * @white: the value of a white pixel on Screen @screen
+ * @black: the value of a black pixel on Screen @screen
+ * @depth: the color depth of Display @disp
+ * @bpp: the number of bits per pixel on Display @disp
+ * @endianness: the endianness of image bytes on Display @disp
+ * @width: the width in pixels of Display @disp
+ * @height: the height in pixels of Display @disp
+ * @widthmm: the width in millimeters of Display @disp
+ * @heightmm: the height in millimeters of Display @disp
+ * @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
+ * @heightmm ratio
+ * @use_xshm: used to known wether of not XShm extension is usable or not even
+ * if the Extension is present
+ * @caps: the #GstCaps that Display @disp can accept
+ *
+ * Structure used to store various informations collected/calculated for a
+ * Display.
+ */
+struct _GstXContext {
+ Display *disp;
+
+ Screen *screen;
+ gint screen_num;
+
+ Visual *visual;
+
+ Window root;
+
+ gulong white, black;
+
+ gint depth;
+ gint bpp;
+ gint endianness;
+
+ gint width, height;
+ gint widthmm, heightmm;
+
+ /* these are the output masks
+ * for buffers from ximagesrc
+ * and are in big endian */
+ guint32 r_mask_output, g_mask_output, b_mask_output;
+
+ GValue *par; /* calculated pixel aspect ratio */
+
+ gboolean use_xshm;
+
+ GstCaps *caps;
+};
+
+/**
+ * GstXWindow:
+ * @win: the Window ID of this X11 window
+ * @width: the width in pixels of Window @win
+ * @height: the height in pixels of Window @win
+ * @internal: used to remember if Window @win was created internally or passed
+ * through the #GstXOverlay interface
+ * @gc: the Graphical Context of Window @win
+ *
+ * Structure used to store informations about a Window.
+ */
+struct _GstXWindow {
+ Window win;
+ gint width, height;
+ gboolean internal;
+ GC gc;
+};
+
+gboolean ximageutil_check_xshm_calls (GstXContext * xcontext);
+
+GstXContext *ximageutil_xcontext_get (GstElement *parent,
+ const gchar *display_name);
+void ximageutil_xcontext_clear (GstXContext *xcontext);
+void ximageutil_calculate_pixel_aspect_ratio (GstXContext * xcontext);
+
+/* custom ximagesrc buffer, copied from ximagesink */
+
+/* BufferReturnFunc is called when a buffer is finalised */
+typedef void (*BufferReturnFunc) (GstElement *parent, GstXImageSrcBuffer *buf);
+
+/**
+ * GstXImageSrcBuffer:
+ * @parent: a reference to the element we belong to
+ * @ximage: the XImage of this buffer
+ * @width: the width in pixels of XImage @ximage
+ * @height: the height in pixels of XImage @ximage
+ * @size: the size in bytes of XImage @ximage
+ *
+ * Subclass of #GstBuffer containing additional information about an XImage.
+ */
+struct _GstXImageSrcBuffer {
+ GstBuffer buffer;
+
+ /* Reference to the ximagesrc we belong to */
+ GstElement *parent;
+
+ XImage *ximage;
+
+#ifdef HAVE_XSHM
+ XShmSegmentInfo SHMInfo;
+#endif /* HAVE_XSHM */
+
+ gint width, height;
+ size_t size;
+
+ BufferReturnFunc return_func;
+};
+
+
+GstXImageSrcBuffer *gst_ximageutil_ximage_new (GstXContext *xcontext,
+ GstElement *parent, int width, int height, BufferReturnFunc return_func);
+
+void gst_ximageutil_ximage_destroy (GstXContext *xcontext,
+ GstXImageSrcBuffer * ximage);
+
+/* Call to manually release a buffer */
+void gst_ximage_buffer_free (GstXImageSrcBuffer *ximage);
+
+#define GST_TYPE_XIMAGESRC_BUFFER (gst_ximagesrc_buffer_get_type())
+#define GST_IS_XIMAGESRC_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_XIMAGESRC_BUFFER))
+#define GST_IS_XIMAGESRC_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_XIMAGESRC_BUFFER))
+#define GST_XIMAGESRC_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBuffer))
+#define GST_XIMAGESRC_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBufferClass))
+#define GST_XIMAGESRC_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_XIMAGESRC_BUFFER, GstXImageSrcBufferClass))
+
+G_END_DECLS
+
+#endif /* __GST_XIMAGEUTIL_H__ */
--- /dev/null
+hildondesktoplib_LTLIBRARIES= \
+ status_menu_load_applet.la \
+ status_area_load_applet.la
+
+
+status_menu_load_applet_la_CPPFLAGS = \
+ $(MAEMO5_LOADAPPLET_CFLAGS)
+
+status_menu_load_applet_la_LDFLAGS = \
+ -module -avoid-version
+
+status_menu_load_applet_la_LIBADD = \
+ $(MAEMO5_LOADAPPLET_LIBS)
+
+status_menu_load_applet_la_SOURCES = \
+ item.c \
+ item.h
+
+
+
+status_area_load_applet_la_CPPFLAGS = \
+ $(MAEMO5_LOADAPPLET_CFLAGS)
+
+status_area_load_applet_la_LDFLAGS = \
+ -module -avoid-version
+
+status_area_load_applet_la_LIBADD = \
+ $(MAEMO5_LOADAPPLET_LIBS)
+
+status_area_load_applet_la_SOURCES = \
+ la_status_area_item.c \
+ la_status_area_item.h
--- /dev/null
+/*
+ Load applet - Maemo5 edition
+
+*/
+
+#include <gtk/gtk.h>
+#include <hildon/hildon.h>
+#include <glib/gerror.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <string.h>
+#include <osso-log.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <sched.h>
+#include "item.h"
+
+#define LOAD_APPLET_STATUS_MENU_ITEM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj, LOAD_APPLET_TYPE_STATUS_MENU_ITEM, LoadAppletStatusMenuItemPrivate))
+
+struct _LoadAppletStatusMenuItemPrivate {
+ gulong screenshot_h;
+ gulong video_h;
+ pid_t rec_pid;
+ gboolean recording;
+
+ DBusError error;
+ GMainLoop *loop;
+ DBusConnection *conn;
+ guint timeout;
+
+};
+
+HD_DEFINE_PLUGIN_MODULE (LoadAppletStatusMenuItem, load_applet_status_menu_item, HD_TYPE_STATUS_MENU_ITEM)
+
+
+
+#define SHUTTER_SOUND "/usr/share/sounds/camera_snd_title_1.wav"
+#define BEEP_SOUND "/usr/share/sounds/ui-default_beep.wav"
+#define MAX_SSHOT_NAME_LEN 64
+static gchar *sshotfilename = NULL;
+static char sshotname[MAX_SSHOT_NAME_LEN];
+static guint screenshot_delay = 20;
+static guint beeps = 0;
+static gint sshotn = 0;
+static gint scastn = 0;
+static gboolean taking = FALSE;
+
+#define MATCH_CAMERA_KEY "type='signal'," \
+ "interface='org.freedesktop.Hal.Device',"
+
+
+static void
+load_applet_status_menu_item_class_finalize(LoadAppletStatusMenuItemClass * klass)
+{
+}
+
+static void
+load_applet_status_menu_item_dispose(GObject * object)
+{
+ G_OBJECT_CLASS(load_applet_status_menu_item_parent_class)->dispose(object);
+}
+
+static void
+load_applet_status_menu_item_class_init(LoadAppletStatusMenuItemClass * klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->dispose = load_applet_status_menu_item_dispose;
+
+ g_type_class_add_private(klass, sizeof(LoadAppletStatusMenuItemPrivate));
+}
+
+/*
+ * Get the filename for next screen-shot. Start with nr.
+ *
+ */
+static int
+get_next_sshot(gint nr, const gchar *suffix)
+{
+ FILE *f;
+ gint n;
+
+ n = nr;
+ f = NULL;
+ do {
+ g_snprintf (sshotname, MAX_SSHOT_NAME_LEN-1, "%s/MyDocs/.images/%s%02d.%s", getenv("HOME"), sshotfilename, n, suffix);
+ f = g_fopen(sshotname, "r");
+ if (f) {
+ fclose(f);
+ n++;
+ }
+ }
+ while(f != NULL);
+
+ return n;
+}
+
+
+/*
+ * Get the filename for next screen-cast. Start with nr.
+ *
+ */
+static int
+get_next_scast(gint nr, const gchar *suffix)
+{
+ FILE *f;
+ gint n;
+
+ n = nr;
+ f = NULL;
+ do {
+ g_snprintf (sshotname, MAX_SSHOT_NAME_LEN-1, "%s/MyDocs/.videos/%s%02d.%s", getenv("HOME"), "screencast", n, suffix);
+ f = g_fopen(sshotname, "r");
+ if (f) {
+ fclose(f);
+ n++;
+ }
+ }
+ while(f != NULL);
+
+ return n;
+}
+
+
+
+/*
+ * Close the menu, make sure it is closed and redrawn
+ */
+static void
+do_little_dance (void)
+{
+ while (gtk_events_pending())
+ {
+ gtk_main_iteration();
+ }
+
+ usleep(1000);
+ sched_yield();
+}
+
+
+/*
+ * Take screeshot using the root window drawable
+ */
+static gboolean
+take_screenshot(void)
+{
+ int width, height;
+ GdkDrawable *root_window;
+ GdkPixbuf *pixbuf;
+ gboolean ret;
+ GError *error = NULL;
+
+ do_little_dance();
+ sshotn = get_next_sshot(sshotn, "png");
+
+
+ root_window = gdk_get_default_root_window();
+ gdk_drawable_get_size(root_window, &width, &height);
+ pixbuf = gdk_pixbuf_get_from_drawable(NULL,
+ root_window,
+ gdk_drawable_get_colormap (root_window),
+ 0, 0,
+ 0, 0,
+ width, height);
+
+
+ ret = gdk_pixbuf_save(pixbuf, sshotname, "png", &error, NULL);
+ g_object_unref(pixbuf);
+
+ //DEBUG
+ //printf("\tSaving %s\n", sshotname);
+
+ return FALSE;
+}
+
+
+/*
+ * Either beep or play shutter sound and make the screenshot
+ */
+static gboolean
+beep_or_shoot(gpointer data)
+{
+ beeps++;
+ if (beeps >= screenshot_delay) {
+ hildon_play_system_sound(SHUTTER_SOUND);
+ take_screenshot();
+ return FALSE;
+ } else {
+ hildon_play_system_sound(BEEP_SOUND);
+ return TRUE;
+ }
+}
+
+
+static DBusHandlerResult
+handle_dbus_events(DBusConnection *connection, DBusMessage *msg, void *user_data)
+{
+ if (taking == FALSE)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ gint message_type = -1;
+ const gchar *interface = dbus_message_get_interface(msg);
+ const gchar *method = dbus_message_get_member(msg);
+ LoadAppletStatusMenuItem *item = (LoadAppletStatusMenuItem*)user_data;
+ item->priv = LOAD_APPLET_STATUS_MENU_ITEM_GET_PRIVATE (item);
+
+ if (!(message_type = dbus_message_get_type(msg)) || !interface || !method)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ switch (message_type) {
+ case DBUS_MESSAGE_TYPE_SIGNAL:
+ if ((g_strcmp0(interface, "org.freedesktop.Hal.Device") == 0) &&
+ (g_strcmp0(method, "PropertyModified") == 0)) {
+ //Camera key pressed. Take screenshot, cancel the waiting loop, remove D-Bus listener
+ gtk_timeout_remove(item->priv->timeout);
+ taking = FALSE;
+ hildon_play_system_sound(SHUTTER_SOUND);
+ take_screenshot();
+ dbus_bus_remove_match(item->priv->conn, MATCH_CAMERA_KEY, &item->priv->error);
+ dbus_connection_unref(item->priv->conn);
+ item->priv->conn = 0;
+ g_main_loop_unref(item->priv->loop);
+ item->priv->loop = NULL;
+ }
+ break;
+ default:
+ break;
+ }
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+
+#ifdef SHOW_PROCESS_INFO
+/*
+ * Show the details dialog (FAKE)
+ *
+ */
+static void
+activate_status_item(GtkMenuItem *item, gpointer data)
+{
+ GtkWidget *dialog;
+ GtkWidget *selector;
+ GtkWidget *content_area;
+ gint i;
+
+ dialog = gtk_dialog_new();
+
+ selector = hildon_touch_selector_new_text ();
+ hildon_touch_selector_set_column_selection_mode (HILDON_TOUCH_SELECTOR (selector),HILDON_TOUCH_SELECTOR_SELECTION_MODE_SINGLE);
+
+ for (i = 1; i <= 10 ; i++) {
+ gchar *label = g_strdup_printf ("Item %d", i);
+ hildon_touch_selector_append_text (HILDON_TOUCH_SELECTOR (selector), label);
+ g_free (label);
+ }
+
+ hildon_touch_selector_unselect_all(HILDON_TOUCH_SELECTOR (selector), 0);
+
+ content_area = GTK_DIALOG(dialog)->vbox;
+ gtk_container_add(GTK_CONTAINER(content_area), selector);
+ gtk_window_set_default_size(GTK_WINDOW(dialog), -1, 480);
+
+ gtk_window_set_title(GTK_WINDOW(dialog), "Select process to kill - FAKE FEATURE");
+ gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE);
+ gtk_dialog_add_button(GTK_DIALOG(dialog), "Kill it", 1);
+
+ gtk_widget_show_all(GTK_WIDGET(dialog));
+ //gtk_dialog_run(GTK_DIALOG(dialog)); <- blocks and won't close status menu
+}
+#endif
+
+
+
+/*
+ * Answer the callback by setting delayed screenshot
+ */
+static void
+activate_delayed_screenshot_item(GtkMenuItem *item, gpointer data)
+{
+ if (taking)
+ return;
+
+ LoadAppletStatusMenuItem *menu_item = (LoadAppletStatusMenuItem*)data;
+ menu_item->priv = LOAD_APPLET_STATUS_MENU_ITEM_GET_PRIVATE (menu_item);
+
+ hildon_banner_show_information(NULL, NULL, "You have 20s to press the camera capture key to take screenshot.");
+ beeps = 0;
+ taking = TRUE;
+ menu_item->priv->timeout = gtk_timeout_add(1000, beep_or_shoot, NULL);
+
+ menu_item->priv->loop = g_main_loop_new(NULL, FALSE);
+ dbus_error_init(&menu_item->priv->error);
+ if ((menu_item->priv->conn = dbus_bus_get(DBUS_BUS_SYSTEM, &menu_item->priv->error)) == NULL) {
+ DLOG_CRIT("LA:Failed to open connection to system bus");
+ dbus_error_free(&menu_item->priv->error);
+ return;
+ }
+ if (!dbus_connection_add_filter(menu_item->priv->conn, handle_dbus_events, (void *)data, 0)) {
+ ULOG_CRIT("LA:Failed to add dbus filter");
+ dbus_error_free(&menu_item->priv->error);
+ return;
+ }
+ dbus_bus_add_match(menu_item->priv->conn, MATCH_CAMERA_KEY, &menu_item->priv->error);
+ if (dbus_error_is_set(&menu_item->priv->error)) {
+ ULOG_WARN("LA:Unable to add match for my key");
+ dbus_error_free(&menu_item->priv->error);
+ }
+ dbus_connection_setup_with_g_main(menu_item->priv->conn, NULL);
+}
+
+
+/*
+ * Answer the callback on video button
+ * If idle, start recording
+ * If already recording, stop
+ */
+static void
+activate_video_item(GtkMenuItem *item, gpointer data)
+{
+ LoadAppletStatusMenuItem *la_item = (LoadAppletStatusMenuItem*)data;
+ pid_t rec_pid;
+ gchar *savefile;
+
+ if (la_item->priv->recording == FALSE) {
+ // We are not recording. Start recording by exec
+ scastn = get_next_scast(scastn, "avi");
+ savefile = g_strdup_printf("location=%s", sshotname);
+ rec_pid = fork();
+ if (rec_pid == 0) {
+ execl("/usr/bin/gst-launch", "/usr/bin/gst-launch", "ximagewsrc", "!", "video/x-raw-rgb,framerate=5/1", "!", "ffmpegcolorspace", "!", "jpegenc", "quality=30", "!", "queue", "!", "mux.", "autoaudiosrc", "!", "audioconvert", "!", "audioresample", "!", "queue", "!", "mux.", "avimux", "name=mux", "!", "filesink", savefile, NULL);
+ exit(0);
+ } else {
+ la_item->priv->recording = TRUE;
+ la_item->priv->rec_pid = rec_pid;
+ }
+ } else {
+ // We are already recording
+ kill(la_item->priv->rec_pid, SIGTERM);
+ la_item->priv->recording = FALSE;
+ }
+}
+
+
+
+
+static void
+load_applet_status_menu_item_init (LoadAppletStatusMenuItem * menu_item)
+{
+ #define ICON_DIR "/usr/share/pixmaps/"
+ #define ICON_VIDEO ICON_DIR"la_video.png"
+ #define ICON_PICTURE ICON_DIR"la_picture.png"
+ #define ICON_PROCESS ICON_DIR"la_process.png"
+
+ GtkWidget *hbox, *icon, *b;
+
+ menu_item->priv = LOAD_APPLET_STATUS_MENU_ITEM_GET_PRIVATE (menu_item);
+
+ hbox = gtk_hbox_new(FALSE, 0);
+
+ sshotfilename = g_strdup("screenshot");
+
+#ifdef SHOW_PROCESS_INFO
+ // Button status
+ b = hildon_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+ hildon_button_set_style(HILDON_BUTTON(b), HILDON_BUTTON_STYLE_PICKER);
+ gtk_widget_show(b);
+ icon = gtk_image_new_from_file(ICON_PROCESS);
+ gtk_widget_show(icon);
+ gtk_button_set_image(GTK_BUTTON(b), GTK_WIDGET(icon));
+ gtk_box_pack_start(GTK_BOX(hbox), b, TRUE, TRUE, 1);
+ g_signal_connect(b, "clicked", G_CALLBACK(activate_status_item), menu_item);
+#endif
+ // Button Video
+ b = gtk_toggle_button_new();
+ gtk_widget_show(b);
+ icon = gtk_image_new_from_file(ICON_VIDEO);
+ gtk_widget_show(icon);
+ gtk_button_set_image(GTK_BUTTON(b), GTK_WIDGET(icon));
+ gtk_box_pack_start(GTK_BOX(hbox), b, TRUE, TRUE, 1);
+ menu_item->priv->screenshot_h = g_signal_connect(b, "clicked", G_CALLBACK(activate_video_item), menu_item);
+ // Button Picture
+ b = hildon_button_new(HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+ gtk_widget_show(b);
+ icon = gtk_image_new_from_file(ICON_PICTURE);
+ gtk_widget_show(icon);
+ gtk_button_set_image(GTK_BUTTON(b), GTK_WIDGET(icon));
+ gtk_box_pack_start(GTK_BOX(hbox), b, TRUE, TRUE, 1);
+ menu_item->priv->screenshot_h = g_signal_connect(b, "clicked", G_CALLBACK(activate_delayed_screenshot_item), menu_item);
+
+ // Pack widgets to menu
+ gtk_widget_show(hbox);
+ gtk_container_add(GTK_CONTAINER(menu_item), hbox);
+ gtk_widget_show(GTK_WIDGET(menu_item));
+
+ // More init
+ menu_item->priv->recording = FALSE;
+}
+
+
+
--- /dev/null
+#ifndef __LOAD_APPLET_STATUS_MENU_ITEM_H__
+#define __LOAD_APPLET_STATUS_MENU_ITEM_H__
+
+#include <libhildondesktop/libhildondesktop.h>
+
+G_BEGIN_DECLS
+#define LOAD_APPLET_TYPE_STATUS_MENU_ITEM (load_applet_status_menu_item_get_type ())
+#define LOAD_APPLET_STATUS_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOAD_APPLET_TYPE_STATUS_MENU_ITEM, LoadAppletStatusMenuItem))
+#define LOAD_APPLET_STATUS_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOAD_APPLET_TYPE_STATUS_MENU_ITEM, LoadAppletStatusMenuItemClass))
+#define LOAD_APPLET_IS_STATUS_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOAD_APPLET_TYPE_STATUS_MENU_ITEM))
+#define LOAD_APPLET_IS_STATUS_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOAD_APPLET_TYPE_STATUS_MENU_ITEM))
+#define LOAD_APPLET_STATUS_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOAD_APPLET_TYPE_STATUS_MENU_ITEM, LoadAppletStatusMenuItemClass))
+typedef struct _LoadAppletStatusMenuItem LoadAppletStatusMenuItem;
+
+typedef struct _LoadAppletStatusMenuItemClass
+ LoadAppletStatusMenuItemClass;
+
+typedef struct _LoadAppletStatusMenuItemPrivate
+ LoadAppletStatusMenuItemPrivate;
+
+struct _LoadAppletStatusMenuItem {
+ HDStatusMenuItem parent;
+
+ LoadAppletStatusMenuItemPrivate *priv;
+};
+
+struct _LoadAppletStatusMenuItemClass {
+ HDStatusMenuItemClass parent;
+};
+
+GType load_applet_status_menu_item_get_type (void);
+
+G_END_DECLS
+#endif
--- /dev/null
+/*
+ * Load applet - Maemo5 edition - status area plugin
+ */
+
+
+#include <gtk/gtk.h>
+#include <hildon/hildon.h>
+#include <glib/gerror.h>
+#include <glib.h>
+#include <string.h>
+#include <libosso.h>
+
+#include "la_status_area_item.h"
+
+#define LA_ICON_WIDTH 16
+#define LA_ICON_HEIGHT 16
+#define LA_BOX_WIDTH 5
+#define LA_BOX_HEIGHT 3
+#define LA_CPU_MAX 5
+
+
+
+#define LOAD_APPLET_STATUS_AREA_ITEM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE (obj, LOAD_APPLET_TYPE_STATUS_AREA_ITEM, LoadAppletStatusAreaItemPrivate))
+
+struct _LoadAppletStatusAreaItemPrivate {
+ guint timeout_id;
+ gint lastU, lastN, lastIO, lastI;
+ guchar last_mem_level;
+ guchar last_cpu_level;
+ GdkPixbuf *pixbuf;
+ GdkPixbuf *pixbuf_on;
+ GdkPixbuf *pixbuf_red;
+ GdkPixbuf *pixbuf_off;
+ osso_context_t *osso;
+ gboolean red;
+};
+
+HD_DEFINE_PLUGIN_MODULE (LoadAppletStatusAreaItem, load_applet_status_area_item, HD_TYPE_STATUS_PLUGIN_ITEM);
+
+
+/*
+ * Read current MEM usage and return indicator between 5 and 1 - how many bars are "full"
+ */
+static guchar
+la_check_mem (LoadAppletStatusAreaItemPrivate *priv)
+{
+ #define MEMFILE "/proc/meminfo"
+ #define MAX_READ_CHARS 128
+ char read_buffer[MAX_READ_CHARS];
+ FILE *fin;
+ int mem_used = 0;
+ int mem_total = 0;
+ int mem_cached = 0;
+ int mem_buffers = 0;
+ int mem_free = 0;
+
+ //Open the memory info file and get current free memory
+ fin = fopen(MEMFILE, "r");
+ if (fin == NULL) {
+ g_warning("Can't open "MEMFILE"\n");
+ return TRUE;
+ }
+ while (fgets(read_buffer, MAX_READ_CHARS, fin) != NULL) {
+ if (strncmp(read_buffer, "MemTotal", 8) == 0) {
+ sscanf(read_buffer + 10, "%d", &mem_total);
+ } else if (strncmp(read_buffer, "MemFree", 6) == 0) {
+ sscanf(read_buffer + 9, "%d", &mem_free);
+ } else if (strncmp(read_buffer, "Buffers", 6) == 0) {
+ sscanf(read_buffer + 9, "%d", &mem_buffers);
+ } else if (strncmp(read_buffer, "Cached", 6) == 0) {
+ sscanf(read_buffer + 8, "%d", &mem_cached);
+ break;
+ }
+ }
+ fclose(fin);
+
+ mem_used = mem_total - mem_free - mem_buffers - mem_cached;
+
+ if (mem_used > 0.9*mem_total)
+ return 5;
+ else if (mem_used > 0.7*mem_total)
+ return 4;
+ else if (mem_used > 0.5*mem_total)
+ return 3;
+ else if (mem_used > 0.3*mem_total)
+ return 2;
+ else
+ return 1;
+}
+
+
+/*
+ * Read current CPU usage and return indicator between 5 and 1 - how many bars are "full"
+ */
+static guchar
+la_check_cpu (LoadAppletStatusAreaItemPrivate *priv)
+{
+ #define CPUFILE "/proc/stat"
+ gint curU, curN, curIO, curI;
+ gint deltaU, deltaN, deltaIO, deltaI;
+ int load, idle;
+ GError *error = NULL;
+ gchar *contents;
+ gsize lenght;
+ gchar **splits;
+
+ if (!g_file_get_contents (CPUFILE, &contents, &lenght, &error)) {
+ fprintf (stderr, "ERR: can't read file %s: %s\n", CPUFILE, error->message);
+ g_error_free (error);
+ return 0;
+ }
+
+ splits = g_strsplit_set (contents, " ", -1);
+
+ sscanf(splits[2], "%d", &curU);
+ sscanf(splits[3], "%d", &curN);
+ sscanf(splits[4], "%d", &curIO);
+ sscanf(splits[5], "%d", &curI);
+
+ g_strfreev (splits);
+ g_free (contents);
+
+ idle = (curI - priv->lastI);
+ if (idle == 0) load = 100;
+ else load = 100-idle;
+ if (load>100) load = 0;
+ deltaU = curU - priv->lastU;
+ deltaN = curN - priv->lastN;
+ deltaIO = curIO - priv->lastIO;
+ deltaI = curI - priv->lastI;
+ priv->lastU = curU;
+ priv->lastN = curN;
+ priv->lastIO = curIO;
+ priv->lastI = curI;
+
+ if (load > 90)
+ return 5;
+ else if (load > 70)
+ return 4;
+ else if (load > 45)
+ return 3;
+ else if (load > 19)
+ return 2;
+ else
+ return 1;
+}
+
+
+
+/*
+ * Compose and blit the current status of memory bars
+ */
+static void
+la_blit_memory_bars (const guchar level, LoadAppletStatusAreaItemPrivate *priv)
+{
+ guint x, y;
+
+ gdk_pixbuf_fill(priv->pixbuf, 0x00000000);
+
+ x = 9;
+ y = 1;
+ if (level > 4)
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ y = 5;
+ if (level > 3)
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ y = 9;
+ if (level > 2)
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ y = 13;
+ if (level > 1)
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ else
+ gdk_pixbuf_composite(priv->pixbuf_off, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+}
+
+
+/*
+ * Compose and blit current status of CPU bars
+ */
+static void
+la_blit_cpu_bars (const guchar level, LoadAppletStatusAreaItemPrivate *priv)
+{
+ guint x, y;
+
+ x = 2;
+ y = 1;
+ if (level > 4)
+ {
+ if (priv->red == TRUE) {
+ gdk_pixbuf_composite(priv->pixbuf_red, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ priv->red = FALSE;
+ } else {
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ priv->red = TRUE;
+ }
+ }
+ y = 5;
+ if (level > 3)
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ y = 9;
+ if (level > 2)
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ y = 13;
+ if (level > 1)
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ else
+ gdk_pixbuf_composite(priv->pixbuf_off, priv->pixbuf, x, y, LA_BOX_WIDTH, LA_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+}
+
+
+/*
+ * Ran to check and update the CPU and memory reading
+ */
+static gboolean
+la_check_load (gpointer data)
+{
+ guchar current_cpu_level;
+ guchar current_mem_level;
+ LoadAppletStatusAreaItem *item = (LoadAppletStatusAreaItem*)data;
+ LoadAppletStatusAreaItemPrivate *priv = (LoadAppletStatusAreaItemPrivate*)item->priv;
+
+ current_cpu_level = la_check_cpu(priv);
+ current_mem_level = la_check_mem(priv);
+ //g_debug(g_strdup_printf("LOADAPLET - UPDATED CPU %d MEM %d", current_cpu_level, current_mem_level));
+
+ //Update and blit only if data changed!
+ if ((current_mem_level != priv->last_mem_level) || (current_cpu_level != priv->last_cpu_level)) {
+ la_blit_memory_bars (current_mem_level, priv);
+ la_blit_cpu_bars (current_cpu_level, priv);
+ if (current_cpu_level == LA_CPU_MAX)
+ priv->red = FALSE;
+ hd_status_plugin_item_set_status_area_icon (HD_STATUS_PLUGIN_ITEM(data), priv->pixbuf);
+ priv->last_mem_level = current_mem_level;
+ priv->last_cpu_level = current_cpu_level;
+ } else if (current_cpu_level == LA_CPU_MAX) {
+ //Pulsate max CPU load icon also when CPU load stays at max
+ la_blit_cpu_bars (current_cpu_level, priv);
+ hd_status_plugin_item_set_status_area_icon (HD_STATUS_PLUGIN_ITEM(data), priv->pixbuf);
+ }
+
+ return TRUE;
+}
+
+/*
+ * Get callback when display state changes
+ */
+static void
+load_applet_status_area_item_display_cb(osso_display_state_t state, gpointer user_data)
+{
+ LoadAppletStatusAreaItem *item = LOAD_APPLET_STATUS_AREA_ITEM(user_data);
+
+ g_return_if_fail (item != NULL && item->priv != NULL);
+
+ if (state == OSSO_DISPLAY_ON)
+ {
+ //Restart the updates, do one right away
+ if (item->priv->timeout_id == -1)
+ {
+ //g_debug("LOADAPPLET - restarting periodic updates");
+ item->priv->timeout_id = gtk_timeout_add(1000, la_check_load, item);
+ }
+ } else {
+ //Suspend the updates - screen is off
+ //g_debug("LOADAPPLET - Turning updates off");
+ if (g_source_remove(item->priv->timeout_id) != TRUE)
+ {
+ //g_error("LOADAPPLET - couldn't stop the updates!the timer still running ...");
+ } else {
+ item->priv->timeout_id = -1;
+ }
+ }
+}
+
+
+/*****************************************************************************
+ *
+ * Boilerplate code area - do not enter
+ *
+ *****************************************************************************/
+
+static void
+load_applet_status_area_item_set_area_icon (LoadAppletStatusAreaItem *item)
+{
+ item->priv = LOAD_APPLET_STATUS_AREA_ITEM_GET_PRIVATE (item);
+
+ hd_status_plugin_item_set_status_area_icon (HD_STATUS_PLUGIN_ITEM(item), item->priv->pixbuf);
+}
+
+
+static void
+load_applet_status_area_item_class_finalize (LoadAppletStatusAreaItemClass *klass)
+{
+}
+
+
+
+static void
+load_applet_status_area_item_finalize (GObject *object)
+{
+ LoadAppletStatusAreaItemPrivate *priv = LOAD_APPLET_STATUS_AREA_ITEM(object)->priv;
+ // Release and clean our stuff
+ G_OBJECT_CLASS (load_applet_status_area_item_parent_class)->finalize (object);
+ if (priv->osso)
+ {
+ osso_deinitialize(priv->osso);
+ priv->osso = NULL;
+ }
+
+}
+
+
+
+static void
+load_applet_status_area_item_class_init (LoadAppletStatusAreaItemClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = load_applet_status_area_item_finalize;
+
+ g_type_class_add_private (klass, sizeof (LoadAppletStatusAreaItemPrivate));
+
+}
+
+static void
+load_applet_status_area_item_init (LoadAppletStatusAreaItem *item)
+{
+ item->priv = LOAD_APPLET_STATUS_AREA_ITEM_GET_PRIVATE (item);
+
+ item->priv->last_mem_level = -1;
+ item->priv->last_cpu_level = -1;
+ item->priv->timeout_id = -1;
+ item->priv->red = FALSE;
+ item->priv->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, LA_ICON_WIDTH, LA_ICON_HEIGHT);
+ gdk_pixbuf_fill(item->priv->pixbuf, 0x00000000);
+ item->priv->pixbuf_on = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, LA_BOX_WIDTH, LA_BOX_HEIGHT);
+ gdk_pixbuf_fill(item->priv->pixbuf_on, 0xffffffff);
+ item->priv->pixbuf_red = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, LA_BOX_WIDTH, LA_BOX_HEIGHT);
+ gdk_pixbuf_fill(item->priv->pixbuf_red, 0xff0000ff);
+ item->priv->pixbuf_off = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, LA_BOX_WIDTH, LA_BOX_HEIGHT);
+ gdk_pixbuf_fill(item->priv->pixbuf_off, 0x777777ff);
+ load_applet_status_area_item_set_area_icon(item);
+
+ item->priv->osso = osso_initialize ("load_applet_status_area_item", "Maemo5", TRUE, NULL);
+ item->priv->timeout_id = gtk_timeout_add(1000, la_check_load, item);
+ osso_hw_set_display_event_cb (item->priv->osso, load_applet_status_area_item_display_cb, item);
+}
+
--- /dev/null
+#ifndef __LOAD_APPLET_STATUS_AREA_ITEM_H__
+#define __LOAD_APPLET_STATUS_AREA_ITEM_H__
+
+#include <libhildondesktop/libhildondesktop.h>
+
+G_BEGIN_DECLS
+
+#define LOAD_APPLET_TYPE_STATUS_AREA_ITEM (load_applet_status_area_item_get_type ())
+#define LOAD_APPLET_STATUS_AREA_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOAD_APPLET_TYPE_STATUS_AREA_ITEM, LoadAppletStatusAreaItem))
+#define LOAD_APPLET_STATUS_AREA_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LOAD_APPLET_TYPE_STATUS_AREA_ITEM, LoadAppletStatusAreaItemClass))
+#define LOAD_APPLET_IS_STATUS_AREA_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOAD_APPLET_TYPE_STATUS_AREA_ITEM))
+#define LOAD_APPLET_IS_STATUS_AREA_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LOAD_APPLET_TYPE_STATUS_AREA_ITEM))
+#define LOAD_APPLET_STATUS_AREA_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LOAD_APPLET_TYPE_STATUS_AREA_ITEM, LoadAppletStatusAreaItemClass))
+
+typedef struct _LoadAppletStatusAreaItem LoadAppletStatusAreaItem;
+typedef struct _LoadAppletStatusAreaItemClass LoadAppletStatusAreaItemClass;
+typedef struct _LoadAppletStatusAreaItemPrivate LoadAppletStatusAreaItemPrivate;
+
+struct _LoadAppletStatusAreaItem {
+ HDStatusPluginItem parent;
+
+ LoadAppletStatusAreaItemPrivate *priv;
+};
+
+struct _LoadAppletStatusAreaItemClass {
+ HDStatusPluginItemClass parent;
+};
+
+GType load_applet_status_area_item_get_type (void);
+
+G_END_DECLS
+
+#endif