diff -Naur gst-plugins-base.clean/configure.ac gst-plugins-base/configure.ac
--- gst-plugins-base.clean/configure.ac	2008-02-22 07:27:24.000000000 +0200
+++ gst-plugins-base/configure.ac	2008-02-26 23:24:52.000000000 +0200
@@ -379,6 +379,22 @@
   AG_GST_CHECK_XV
 ])
 
+dnl *** Compiz ***
+translit(dnm, m, l) AM_CONDITIONAL(USE_XCOMPIZ, true)
+AG_GST_CHECK_FEATURE(XCOMPIZ, [X libraries and plugins],
+                  [xcompizsink], [
+  AC_PATH_XTRA
+  
+  dnl now try to find the HEADER
+  AC_CHECK_HEADER(X11/Xlib.h, HAVE_XCOMPIZ="yes", HAVE_XCOMPIZ="no")
+
+  if test "x$HAVE_XCOMPIZ" = "xno"
+  then
+    AC_MSG_NOTICE([cannot find X11 development files])
+  fi
+  AC_SUBST(HAVE_XCOMPIZ)
+])
+
 dnl check for X Shm
 translit(dnm, m, l) AM_CONDITIONAL(USE_XSHM, true)
 AG_GST_CHECK_FEATURE(XSHM, [X Shared Memory extension], , [
@@ -670,6 +686,7 @@
 gst/volume/Makefile
 sys/Makefile
 sys/ximage/Makefile
+sys/xcompiz/Makefile
 sys/xvimage/Makefile
 sys/v4l/Makefile
 ext/Makefile
diff -Naur gst-plugins-base.clean/docs/plugins/gst-plugins-base-plugins.args gst-plugins-base/docs/plugins/gst-plugins-base-plugins.args
--- gst-plugins-base.clean/docs/plugins/gst-plugins-base-plugins.args	2008-02-12 10:13:56.000000000 +0200
+++ gst-plugins-base/docs/plugins/gst-plugins-base-plugins.args	2008-02-26 23:18:43.000000000 +0200
@@ -189,6 +189,66 @@
 </ARG>
 
 <ARG>
+<NAME>GstXCompizSink::display</NAME>
+<TYPE>gchar*</TYPE>
+<RANGE></RANGE>
+<FLAGS>rw</FLAGS>
+<NICK>Display</NICK>
+<BLURB>X Display name.</BLURB>
+<DEFAULT>NULL</DEFAULT>
+</ARG>
+
+<ARG>
+<NAME>GstXCompizSink::pixel-aspect-ratio</NAME>
+<TYPE>gchar*</TYPE>
+<RANGE></RANGE>
+<FLAGS>rw</FLAGS>
+<NICK>Pixel Aspect Ratio</NICK>
+<BLURB>The pixel aspect ratio of the device.</BLURB>
+<DEFAULT>"1/1"</DEFAULT>
+</ARG>
+
+<ARG>
+<NAME>GstXCompizSink::synchronous</NAME>
+<TYPE>gboolean</TYPE>
+<RANGE></RANGE>
+<FLAGS>rw</FLAGS>
+<NICK>Synchronous</NICK>
+<BLURB>When enabled, runs the X display in synchronous mode. (used only for debugging).</BLURB>
+<DEFAULT>FALSE</DEFAULT>
+</ARG>
+
+<ARG>
+<NAME>GstXCompizSink::force-aspect-ratio</NAME>
+<TYPE>gboolean</TYPE>
+<RANGE></RANGE>
+<FLAGS>rw</FLAGS>
+<NICK>Force aspect ratio</NICK>
+<BLURB>When enabled, reverse caps negotiation (scaling) will respect original aspect ratio.</BLURB>
+<DEFAULT>FALSE</DEFAULT>
+</ARG>
+
+<ARG>
+<NAME>GstXCompizSink::handle-events</NAME>
+<TYPE>gboolean</TYPE>
+<RANGE></RANGE>
+<FLAGS>rw</FLAGS>
+<NICK>Handle XEvents</NICK>
+<BLURB>When enabled, XEvents will be selected and handled.</BLURB>
+<DEFAULT>TRUE</DEFAULT>
+</ARG>
+
+<ARG>
+<NAME>GstXCompizSink::handle-expose</NAME>
+<TYPE>gboolean</TYPE>
+<RANGE></RANGE>
+<FLAGS>rw</FLAGS>
+<NICK>Handle expose</NICK>
+<BLURB>When enabled, the current frame will always be drawn in response to X Expose events.</BLURB>
+<DEFAULT>TRUE</DEFAULT>
+</ARG>
+
+<ARG>
 <NAME>GstV4lSrc::autoprobe</NAME>
 <TYPE>gboolean</TYPE>
 <RANGE></RANGE>
diff -Naur gst-plugins-base.clean/docs/plugins/gst-plugins-base-plugins-docs.sgml gst-plugins-base/docs/plugins/gst-plugins-base-plugins-docs.sgml
--- gst-plugins-base.clean/docs/plugins/gst-plugins-base-plugins-docs.sgml	2008-02-12 10:13:56.000000000 +0200
+++ gst-plugins-base/docs/plugins/gst-plugins-base-plugins-docs.sgml	2008-02-26 23:22:28.000000000 +0200
@@ -51,6 +51,7 @@
     <xi:include href="xml/element-vorbistag.xml" />
     <xi:include href="xml/element-ximagesink.xml" />
     <xi:include href="xml/element-xvimagesink.xml" />
+    <xi:include href="xml/element-xcompizsink.xml" />
   </chapter>
 
   <chapter>
@@ -84,6 +85,7 @@
     <xi:include href="xml/plugin-vorbis.xml" />
     <xi:include href="xml/plugin-ximagesink.xml" />
     <xi:include href="xml/plugin-xvimagesink.xml" />
+    <xi:include href="xml/plugin-xcompizsink.xml" />
   </chapter>
 </book>
 
diff -Naur gst-plugins-base.clean/docs/plugins/gst-plugins-base-plugins.interfaces gst-plugins-base/docs/plugins/gst-plugins-base-plugins.interfaces
--- gst-plugins-base.clean/docs/plugins/gst-plugins-base-plugins.interfaces	2008-02-12 10:13:56.000000000 +0200
+++ gst-plugins-base/docs/plugins/gst-plugins-base-plugins.interfaces	2008-02-26 23:19:07.000000000 +0200
@@ -18,6 +18,7 @@
 GstGioSink GstURIHandler
 GstXvImageSink GstImplementsInterface GstPropertyProbe GstXOverlay GstColorBalance GstNavigation
 GstXImageSink GstImplementsInterface GstXOverlay GstNavigation
+GstXCompizSink GstImplementsInterface GstXOverlay GstNavigation
 GstVorbisEnc GstTagSetter
 GstVorbisTag GstTagSetter
 GstAlsaMixerElement GstImplementsInterface GstMixer GstPropertyProbe
diff -Naur gst-plugins-base.clean/docs/plugins/gst-plugins-base-plugins-sections.txt gst-plugins-base/docs/plugins/gst-plugins-base-plugins-sections.txt
--- gst-plugins-base.clean/docs/plugins/gst-plugins-base-plugins-sections.txt	2008-02-12 10:13:56.000000000 +0200
+++ gst-plugins-base/docs/plugins/gst-plugins-base-plugins-sections.txt	2008-02-26 23:59:16.000000000 +0200
@@ -562,6 +562,20 @@
 </SECTION>
 
 <SECTION>
+<FILE>element-xcompizsink</FILE>
+<TITLE>xcompizsink</TITLE>
+GstXCompizSink
+<SUBSECTION Standard>
+GST_XCOMPIZSINK
+GST_XCOMPIZSINK_CLASS
+GST_IS_XCOMPIZSINK
+GST_IS_XCOMPIZSINK_CLASS
+GST_TYPE_XCOMPIZSINK
+GstXCompizSinkClass
+gst_xcompizsink_get_type
+</SECTION>
+
+<SECTION>
 <FILE>element-xvimagesink</FILE>
 <TITLE>xvimagesink</TITLE>
 GstXvImageSink
diff -Naur gst-plugins-base.clean/docs/plugins/inspect/plugin-xcompizsink.xml gst-plugins-base/docs/plugins/inspect/plugin-xcompizsink.xml
--- gst-plugins-base.clean/docs/plugins/inspect/plugin-xcompizsink.xml	1970-01-01 03:00:00.000000000 +0300
+++ gst-plugins-base/docs/plugins/inspect/plugin-xcompizsink.xml	2008-02-26 23:21:13.000000000 +0200
@@ -0,0 +1,28 @@
+<plugin>
+  <name>xcompizsink</name>
+  <description>X11 video output element using Compiz video plugin</description>
+  <filename>../../sys/xcompiz/.libs/libgstxcompizsink.so</filename>
+  <basename>libgstxcompizsink.so</basename>
+  <version>0.10.17.1</version>
+  <license>LGPL</license>
+  <source>gst-plugins-base</source>
+  <package>GStreamer Base Plug-ins CVS/prerelease</package>
+  <origin>Unknown package origin</origin>
+  <elements>
+    <element>
+      <name>xcompizsink</name>
+      <longname>Video sink</longname>
+      <class>Sink/Video</class>
+      <description>A standard X based videosink using Compiz video plugin</description>
+      <author>Julien Moutte &lt;julien@moutte.net&gt;</author>
+      <pads>
+        <caps>
+          <name>sink</name>
+          <direction>sink</direction>
+          <presence>always</presence>
+          <details>video/x-raw-rgb, framerate=(fraction)[ 0/1, 2147483647/1 ], width=(int)[ 1, 2147483647 ], height=(int)[ 1, 2147483647 ]</details>
+        </caps>
+      </pads>
+    </element>
+  </elements>
+</plugin>
diff -Naur gst-plugins-base.clean/sys/Makefile.am gst-plugins-base/sys/Makefile.am
--- gst-plugins-base.clean/sys/Makefile.am	2005-07-07 14:29:29.000000000 +0300
+++ gst-plugins-base/sys/Makefile.am	2008-02-26 23:13:03.000000000 +0200
@@ -16,10 +16,18 @@
 XVIMAGE_DIR=
 endif
 
+
+if USE_XCOMPIZ
+XCOMPIZ_DIR=xcompiz
+else
+XCOMPIZ_DIR=
+endif
+
 SUBDIRS = \
   $(XIMAGE_DIR) \
   $(XVIMAGE_DIR) \
-  $(V4L_DIR)
+  $(V4L_DIR) \
+  $(XCOMPIZ_DIR)
 
 DIST_SUBDIRS = \
   v4l \
diff -Naur gst-plugins-base.clean/sys/xcompiz/Makefile.am gst-plugins-base/sys/xcompiz/Makefile.am
--- gst-plugins-base.clean/sys/xcompiz/Makefile.am	1970-01-01 03:00:00.000000000 +0300
+++ gst-plugins-base/sys/xcompiz/Makefile.am	2008-02-21 15:19:52.000000000 +0200
@@ -0,0 +1,13 @@
+plugin_LTLIBRARIES = libgstxcompizsink.la
+
+libgstxcompizsink_la_SOURCES =  xcompizsink.c xcompiz.c
+libgstxcompizsink_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS)
+libgstxcompizsink_la_LIBADD = \
+	$(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la \
+	$(top_builddir)/gst-libs/gst/video/libgstvideo-$(GST_MAJORMINOR).la \
+	$(GST_BASE_LIBS) \
+	$(X_LIBS) $(XSHM_LIBS)
+libgstxcompizsink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstxcompizsink_la_DEPENDENCIES = $(top_builddir)/gst-libs/gst/video/libgstvideo-$(GST_MAJORMINOR).la
+
+noinst_HEADERS = xcompizsink.h 
diff -Naur gst-plugins-base.clean/sys/xcompiz/Makefile.in gst-plugins-base/sys/xcompiz/Makefile.in
--- gst-plugins-base.clean/sys/xcompiz/Makefile.in	1970-01-01 03:00:00.000000000 +0300
+++ gst-plugins-base/sys/xcompiz/Makefile.in	2008-02-25 10:01:44.000000000 +0200
@@ -0,0 +1,654 @@
+# Makefile.in generated by automake 1.10 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006  Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = sys/xcompiz
+DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/common/m4/as-ac-expand.m4 \
+	$(top_srcdir)/common/m4/as-auto-alt.m4 \
+	$(top_srcdir)/common/m4/as-compiler-flag.m4 \
+	$(top_srcdir)/common/m4/as-libtool.m4 \
+	$(top_srcdir)/common/m4/as-python.m4 \
+	$(top_srcdir)/common/m4/as-scrub-include.m4 \
+	$(top_srcdir)/common/m4/as-version.m4 \
+	$(top_srcdir)/common/m4/ax_create_stdint_h.m4 \
+	$(top_srcdir)/common/m4/gst-arch.m4 \
+	$(top_srcdir)/common/m4/gst-args.m4 \
+	$(top_srcdir)/common/m4/gst-check.m4 \
+	$(top_srcdir)/common/m4/gst-default.m4 \
+	$(top_srcdir)/common/m4/gst-error.m4 \
+	$(top_srcdir)/common/m4/gst-feature.m4 \
+	$(top_srcdir)/common/m4/gst-function.m4 \
+	$(top_srcdir)/common/m4/gst-gettext.m4 \
+	$(top_srcdir)/common/m4/gst-glib2.m4 \
+	$(top_srcdir)/common/m4/gst-plugin-docs.m4 \
+	$(top_srcdir)/common/m4/gst-plugindir.m4 \
+	$(top_srcdir)/common/m4/gst-x11.m4 \
+	$(top_srcdir)/common/m4/gst.m4 \
+	$(top_srcdir)/common/m4/gtk-doc.m4 \
+	$(top_srcdir)/common/m4/pkg.m4 $(top_srcdir)/m4/freetype2.m4 \
+	$(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/gst-alsa.m4 \
+	$(top_srcdir)/m4/gst-fionread.m4 $(top_srcdir)/m4/iconv.m4 \
+	$(top_srcdir)/m4/isc-posix.m4 $(top_srcdir)/m4/lib-ld.m4 \
+	$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
+	$(top_srcdir)/m4/lrint.m4 $(top_srcdir)/m4/lrintf.m4 \
+	$(top_srcdir)/m4/ogg.m4 $(top_srcdir)/m4/progtest.m4 \
+	$(top_srcdir)/m4/vorbis.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
+am__installdirs = "$(DESTDIR)$(plugindir)"
+pluginLTLIBRARIES_INSTALL = $(INSTALL)
+LTLIBRARIES = $(plugin_LTLIBRARIES)
+am__DEPENDENCIES_1 =
+am_libgstxcompizsink_la_OBJECTS = libgstxcompizsink_la-xcompizsink.lo \
+	libgstxcompizsink_la-xcompiz.lo
+libgstxcompizsink_la_OBJECTS = $(am_libgstxcompizsink_la_OBJECTS)
+libgstxcompizsink_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) \
+	$(libgstxcompizsink_la_CFLAGS) $(CFLAGS) \
+	$(libgstxcompizsink_la_LDFLAGS) $(LDFLAGS) -o $@
+DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(libgstxcompizsink_la_SOURCES)
+DIST_SOURCES = $(libgstxcompizsink_la_SOURCES)
+HEADERS = $(noinst_HEADERS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
+ALSA_CFLAGS = @ALSA_CFLAGS@
+ALSA_LIBS = @ALSA_LIBS@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCASFLAGS = @CCASFLAGS@
+CCDEPMODE = @CCDEPMODE@
+CDPARANOIA_LIBS = @CDPARANOIA_LIBS@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFAULT_AUDIOSINK = @DEFAULT_AUDIOSINK@
+DEFAULT_AUDIOSRC = @DEFAULT_AUDIOSRC@
+DEFAULT_VIDEOSINK = @DEFAULT_VIDEOSINK@
+DEFAULT_VIDEOSRC = @DEFAULT_VIDEOSRC@
+DEFAULT_VISUALIZER = @DEFAULT_VISUALIZER@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DEPRECATED_CFLAGS = @DEPRECATED_CFLAGS@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+ERROR_CFLAGS = @ERROR_CFLAGS@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+FT2_CFLAGS = @FT2_CFLAGS@
+FT2_CONFIG = @FT2_CONFIG@
+FT2_LIBS = @FT2_LIBS@
+GCOV = @GCOV@
+GCOV_CFLAGS = @GCOV_CFLAGS@
+GCOV_LIBS = @GCOV_LIBS@
+GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
+GIO_CFLAGS = @GIO_CFLAGS@
+GIO_LDFLAGS = @GIO_LDFLAGS@
+GIO_LIBS = @GIO_LIBS@
+GLIB_CFLAGS = @GLIB_CFLAGS@
+GLIB_LIBS = @GLIB_LIBS@
+GLIB_PREFIX = @GLIB_PREFIX@
+GLIB_REQ = @GLIB_REQ@
+GMSGFMT = @GMSGFMT@
+GNOME_VFS_CFLAGS = @GNOME_VFS_CFLAGS@
+GNOME_VFS_LIBS = @GNOME_VFS_LIBS@
+GREP = @GREP@
+GST_AGE = @GST_AGE@
+GST_ALL_LDFLAGS = @GST_ALL_LDFLAGS@
+GST_BASE_CFLAGS = @GST_BASE_CFLAGS@
+GST_BASE_LIBS = @GST_BASE_LIBS@
+GST_CFLAGS = @GST_CFLAGS@
+GST_CHECK_CFLAGS = @GST_CHECK_CFLAGS@
+GST_CHECK_LIBS = @GST_CHECK_LIBS@
+GST_CONTROLLER_CFLAGS = @GST_CONTROLLER_CFLAGS@
+GST_CONTROLLER_LIBS = @GST_CONTROLLER_LIBS@
+GST_CURRENT = @GST_CURRENT@
+GST_GDP_CFLAGS = @GST_GDP_CFLAGS@
+GST_GDP_LIBS = @GST_GDP_LIBS@
+GST_INSTALL_PLUGINS_HELPER = @GST_INSTALL_PLUGINS_HELPER@
+GST_LEVEL_DEFAULT = @GST_LEVEL_DEFAULT@
+GST_LIBS = @GST_LIBS@
+GST_LIBVERSION = @GST_LIBVERSION@
+GST_LIB_LDFLAGS = @GST_LIB_LDFLAGS@
+GST_LICENSE = @GST_LICENSE@
+GST_LT_LDFLAGS = @GST_LT_LDFLAGS@
+GST_MAJORMINOR = @GST_MAJORMINOR@
+GST_OPTION_CFLAGS = @GST_OPTION_CFLAGS@
+GST_PACKAGE_NAME = @GST_PACKAGE_NAME@
+GST_PACKAGE_ORIGIN = @GST_PACKAGE_ORIGIN@
+GST_PLUGINS_ALL = @GST_PLUGINS_ALL@
+GST_PLUGINS_BASE_CFLAGS = @GST_PLUGINS_BASE_CFLAGS@
+GST_PLUGINS_DIR = @GST_PLUGINS_DIR@
+GST_PLUGINS_SELECTED = @GST_PLUGINS_SELECTED@
+GST_PLUGIN_LDFLAGS = @GST_PLUGIN_LDFLAGS@
+GST_PREFIX = @GST_PREFIX@
+GST_REVISION = @GST_REVISION@
+GST_TOOLS_DIR = @GST_TOOLS_DIR@
+GTK2_CFLAGS = @GTK2_CFLAGS@
+GTK2_LIBS = @GTK2_LIBS@
+GTKDOC_CHECK = @GTKDOC_CHECK@
+GTK_BASE_DIR = @GTK_BASE_DIR@
+GTK_CFLAGS = @GTK_CFLAGS@
+GTK_LIBS = @GTK_LIBS@
+GTK_VERSION = @GTK_VERSION@
+HAVE_CDPARANOIA = @HAVE_CDPARANOIA@
+HAVE_GTK = @HAVE_GTK@
+HAVE_X = @HAVE_X@
+HAVE_XCOMPIZ = @HAVE_XCOMPIZ@
+HAVE_XSHM = @HAVE_XSHM@
+HSTRERROR_LIBS = @HSTRERROR_LIBS@
+HTML_DIR = @HTML_DIR@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INTLLIBS = @INTLLIBS@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBINTL = @LIBINTL@
+LIBM = @LIBM@
+LIBOBJS = @LIBOBJS@
+LIBOIL_CFLAGS = @LIBOIL_CFLAGS@
+LIBOIL_LIBS = @LIBOIL_LIBS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBVISUAL_CFLAGS = @LIBVISUAL_CFLAGS@
+LIBVISUAL_LIBS = @LIBVISUAL_LIBS@
+LN_S = @LN_S@
+LOCALEDIR = @LOCALEDIR@
+LTLIBICONV = @LTLIBICONV@
+LTLIBINTL = @LTLIBINTL@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+MKINSTALLDIRS = @MKINSTALLDIRS@
+MSGFMT = @MSGFMT@
+MSGMERGE = @MSGMERGE@
+OBJEXT = @OBJEXT@
+OGG_CFLAGS = @OGG_CFLAGS@
+OGG_LIBS = @OGG_LIBS@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PACKAGE_VERSION_MAJOR = @PACKAGE_VERSION_MAJOR@
+PACKAGE_VERSION_MICRO = @PACKAGE_VERSION_MICRO@
+PACKAGE_VERSION_MINOR = @PACKAGE_VERSION_MINOR@
+PACKAGE_VERSION_NANO = @PACKAGE_VERSION_NANO@
+PACKAGE_VERSION_RELEASE = @PACKAGE_VERSION_RELEASE@
+PANGO_CFLAGS = @PANGO_CFLAGS@
+PANGO_LIBS = @PANGO_LIBS@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PKG_CONFIG = @PKG_CONFIG@
+PLUGINDIR = @PLUGINDIR@
+POSUB = @POSUB@
+PROFILE_CFLAGS = @PROFILE_CFLAGS@
+PYTHON = @PYTHON@
+PYTHON_EXEC_PREFIX = @PYTHON_EXEC_PREFIX@
+PYTHON_PLATFORM = @PYTHON_PLATFORM@
+PYTHON_PREFIX = @PYTHON_PREFIX@
+PYTHON_VERSION = @PYTHON_VERSION@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+THEORA_CFLAGS = @THEORA_CFLAGS@
+THEORA_LIBS = @THEORA_LIBS@
+USE_NLS = @USE_NLS@
+VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
+VALGRIND_LIBS = @VALGRIND_LIBS@
+VALGRIND_PATH = @VALGRIND_PATH@
+VERSION = @VERSION@
+VORBISENC_LIBS = @VORBISENC_LIBS@
+VORBISFILE_LIBS = @VORBISFILE_LIBS@
+VORBIS_CFLAGS = @VORBIS_CFLAGS@
+VORBIS_LIBS = @VORBIS_LIBS@
+WIN32_LIBS = @WIN32_LIBS@
+XGETTEXT = @XGETTEXT@
+XMKMF = @XMKMF@
+XSHM_LIBS = @XSHM_LIBS@
+XVIDEO_LIBS = @XVIDEO_LIBS@
+X_CFLAGS = @X_CFLAGS@
+X_EXTRA_LIBS = @X_EXTRA_LIBS@
+X_LIBS = @X_LIBS@
+X_PRE_LIBS = @X_PRE_LIBS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+pkgpyexecdir = @pkgpyexecdir@
+pkgpythondir = @pkgpythondir@
+plugindir = @plugindir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+pyexecdir = @pyexecdir@
+pythondir = @pythondir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+plugin_LTLIBRARIES = libgstxcompizsink.la
+libgstxcompizsink_la_SOURCES = xcompizsink.c xcompiz.c
+libgstxcompizsink_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS)
+libgstxcompizsink_la_LIBADD = \
+	$(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la \
+	$(top_builddir)/gst-libs/gst/video/libgstvideo-$(GST_MAJORMINOR).la \
+	$(GST_BASE_LIBS) \
+	$(X_LIBS) $(XSHM_LIBS)
+
+libgstxcompizsink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstxcompizsink_la_DEPENDENCIES = $(top_builddir)/gst-libs/gst/video/libgstvideo-$(GST_MAJORMINOR).la
+noinst_HEADERS = xcompizsink.h 
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+		&& exit 0; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  sys/xcompiz/Makefile'; \
+	cd $(top_srcdir) && \
+	  $(AUTOMAKE) --gnu  sys/xcompiz/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-pluginLTLIBRARIES: $(plugin_LTLIBRARIES)
+	@$(NORMAL_INSTALL)
+	test -z "$(plugindir)" || $(MKDIR_P) "$(DESTDIR)$(plugindir)"
+	@list='$(plugin_LTLIBRARIES)'; for p in $$list; do \
+	  if test -f $$p; then \
+	    f=$(am__strip_dir) \
+	    echo " $(LIBTOOL) --mode=install $(pluginLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(plugindir)/$$f'"; \
+	    $(LIBTOOL) --mode=install $(pluginLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(plugindir)/$$f"; \
+	  else :; fi; \
+	done
+
+uninstall-pluginLTLIBRARIES:
+	@$(NORMAL_UNINSTALL)
+	@list='$(plugin_LTLIBRARIES)'; for p in $$list; do \
+	  p=$(am__strip_dir) \
+	  echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(plugindir)/$$p'"; \
+	  $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(plugindir)/$$p"; \
+	done
+
+clean-pluginLTLIBRARIES:
+	-test -z "$(plugin_LTLIBRARIES)" || rm -f $(plugin_LTLIBRARIES)
+	@list='$(plugin_LTLIBRARIES)'; for p in $$list; do \
+	  dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+	  test "$$dir" != "$$p" || dir=.; \
+	  echo "rm -f \"$${dir}/so_locations\""; \
+	  rm -f "$${dir}/so_locations"; \
+	done
+libgstxcompizsink.la: $(libgstxcompizsink_la_OBJECTS) $(libgstxcompizsink_la_DEPENDENCIES) 
+	$(libgstxcompizsink_la_LINK) -rpath $(plugindir) $(libgstxcompizsink_la_OBJECTS) $(libgstxcompizsink_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgstxcompizsink_la-xcompiz.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgstxcompizsink_la-xcompizsink.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+libgstxcompizsink_la-xcompizsink.lo: xcompizsink.c
+@am__fastdepCC_TRUE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstxcompizsink_la_CFLAGS) $(CFLAGS) -MT libgstxcompizsink_la-xcompizsink.lo -MD -MP -MF $(DEPDIR)/libgstxcompizsink_la-xcompizsink.Tpo -c -o libgstxcompizsink_la-xcompizsink.lo `test -f 'xcompizsink.c' || echo '$(srcdir)/'`xcompizsink.c
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/libgstxcompizsink_la-xcompizsink.Tpo $(DEPDIR)/libgstxcompizsink_la-xcompizsink.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='xcompizsink.c' object='libgstxcompizsink_la-xcompizsink.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstxcompizsink_la_CFLAGS) $(CFLAGS) -c -o libgstxcompizsink_la-xcompizsink.lo `test -f 'xcompizsink.c' || echo '$(srcdir)/'`xcompizsink.c
+
+libgstxcompizsink_la-xcompiz.lo: xcompiz.c
+@am__fastdepCC_TRUE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstxcompizsink_la_CFLAGS) $(CFLAGS) -MT libgstxcompizsink_la-xcompiz.lo -MD -MP -MF $(DEPDIR)/libgstxcompizsink_la-xcompiz.Tpo -c -o libgstxcompizsink_la-xcompiz.lo `test -f 'xcompiz.c' || echo '$(srcdir)/'`xcompiz.c
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/libgstxcompizsink_la-xcompiz.Tpo $(DEPDIR)/libgstxcompizsink_la-xcompiz.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='xcompiz.c' object='libgstxcompizsink_la-xcompiz.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgstxcompizsink_la_CFLAGS) $(CFLAGS) -c -o libgstxcompizsink_la-xcompiz.lo `test -f 'xcompiz.c' || echo '$(srcdir)/'`xcompiz.c
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	    $$tags $$unique; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '    { files[$$0] = 1; } \
+	       END { for (i in files) print i; }'`; \
+	test -z "$(CTAGS_ARGS)$$tags$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$tags $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && cd $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+	    fi; \
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+	  else \
+	    test -f $(distdir)/$$file \
+	    || cp -p $$d/$$file $(distdir)/$$file \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES) $(HEADERS)
+installdirs:
+	for dir in "$(DESTDIR)$(plugindir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-pluginLTLIBRARIES \
+	mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am: install-pluginLTLIBRARIES
+
+install-dvi: install-dvi-am
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-info: install-info-am
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-ps: install-ps-am
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-pluginLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+	clean-libtool clean-pluginLTLIBRARIES ctags distclean \
+	distclean-compile distclean-generic distclean-libtool \
+	distclean-tags distdir dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-html \
+	install-html-am install-info install-info-am install-man \
+	install-pdf install-pdf-am install-pluginLTLIBRARIES \
+	install-ps install-ps-am install-strip installcheck \
+	installcheck-am installdirs maintainer-clean \
+	maintainer-clean-generic mostlyclean mostlyclean-compile \
+	mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+	tags uninstall uninstall-am uninstall-pluginLTLIBRARIES
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff -Naur gst-plugins-base.clean/sys/xcompiz/xcompiz.c gst-plugins-base/sys/xcompiz/xcompiz.c
--- gst-plugins-base.clean/sys/xcompiz/xcompiz.c	1970-01-01 03:00:00.000000000 +0300
+++ gst-plugins-base/sys/xcompiz/xcompiz.c	2008-02-26 12:34:08.000000000 +0200
@@ -0,0 +1,47 @@
+/* GStreamer
+ * Copyright (C) <2003> Julien Moutte <julien@moutte.net>
+ *
+ * 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 "xcompizsink.h"
+
+GST_DEBUG_CATEGORY (gst_debug_xcompizsink);
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+  if (!gst_element_register (plugin, "xcompizsink",
+          GST_RANK_NONE, GST_TYPE_XCOMPIZSINK))
+    return FALSE;
+
+  GST_DEBUG_CATEGORY_INIT (gst_debug_xcompizsink, "xcompizsink", 0,
+      "xcompizsink element");
+
+  return TRUE;
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+    GST_VERSION_MINOR,
+    "xcompizsink",
+    "X11 video output for Compiz",
+    plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
diff -Naur gst-plugins-base.clean/sys/xcompiz/xcompizsink.c gst-plugins-base/sys/xcompiz/xcompizsink.c
--- gst-plugins-base.clean/sys/xcompiz/xcompizsink.c	1970-01-01 03:00:00.000000000 +0300
+++ gst-plugins-base/sys/xcompiz/xcompizsink.c	2008-02-27 00:03:28.000000000 +0200
@@ -0,0 +1,2545 @@
+/* GStreamer
+ * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
+ *
+ * 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-xcompizsink
+ *
+ * <refsect2>
+ * <para>
+ * XImageSink renders video frames to a drawable (XWindow) on a local or remote
+ * display. This element can receive a Window ID from the application through
+ * the XOverlay interface and will then render video frames in this drawable.
+ * If no Window ID was provided by the application, the element will create its
+ * own internal window and render into it.
+ * </para>
+ * <title>Scaling</title>
+ * <para>
+ * As standard XImage rendering to a drawable is not scaled, XImageSink will use
+ * reverse caps negotiation to try to get scaled video frames for the drawable.
+ * This is accomplished by asking the peer pad if it accepts some different caps
+ * which in most cases implies that there is a scaling element in the pipeline,
+ * or that an element generating the video frames can generate them with a 
+ * different geometry. This mechanism is handled during buffer allocations, for
+ * each allocation request the video sink will check the drawable geometry, look
+ * at the
+ * <link linkend="GstXCompizSink--force-aspect-ratio">force-aspect-ratio</link>
+ * property, calculate the geometry of desired video frames and then check that
+ * the peer pad accept those new caps. If it does it will then allocate a buffer
+ * in video memory with this new geometry and return it with the new caps.
+ * </para>
+ * <title>Events</title>
+ * <para>
+ * XImageSink creates a thread to handle events coming from the drawable. There
+ * are several kind of events that can be grouped in 2 big categories: input 
+ * events and window state related events. Input events will be translated to
+ * navigation events and pushed upstream for other elements to react on them.
+ * This includes events such as pointer moves, key press/release, clicks etc...
+ * Other events are used to handle the drawable appearance even when the data
+ * is not flowing (GST_STATE_PAUSED). That means that even when the element is
+ * paused, it will receive expose events from the drawable and draw the latest
+ * frame with correct borders/aspect-ratio.
+ * </para>
+ * <title>Pixel aspect ratio</title>
+ * <para>
+ * When changing state to GST_STATE_READY, XImageSink will open a connection to
+ * the display specified in the
+ * <link linkend="GstXCompizSink--display">display</link> property or the default
+ * display if nothing specified. Once this connection is open it will inspect 
+ * the display configuration including the physical display geometry and 
+ * then calculate the pixel aspect ratio. When caps negotiation will occur, the
+ * video sink will set the calculated pixel aspect ratio on the caps to make 
+ * sure that incoming video frames will have the correct pixel aspect ratio for
+ * this display. Sometimes the calculated pixel aspect ratio can be wrong, it is
+ * then possible to enforce a specific pixel aspect ratio using the
+ * <link linkend="GstXCompizSink--pixel-aspect-ratio">pixel-aspect-ratio</link>
+ * property.
+ * </para>
+ * <title>Examples</title>
+ * <para>
+ * Here is a simple pipeline to test reverse negotiation :
+ * <programlisting>
+ * gst-launch -v videotestsrc ! queue ! xcompizsink
+ * </programlisting>
+ * When the test video signal appears you can resize the window and see that
+ * scaled buffers of the desired size are going to arrive with a short delay.
+ * This illustrates how buffers of desired size are allocated along the way.
+ * If you take away the queue, scaling will happen almost immediately.
+ * </para>
+ * <para>
+ * Here is a simple pipeline to test navigation events :
+ * <programlisting>
+ * gst-launch -v videotestsrc ! navigationtest ! ffmpegcolorspace ! xcompizsink
+ * </programlisting>
+ * While moving the mouse pointer over the test signal you will see a black box
+ * following the mouse pointer. If you press the mouse button somewhere on the 
+ * video and release it somewhere else a green box will appear where you pressed
+ * the button and a red one where you released it. (The navigationtest element
+ * is part of gst-plugins-good.)
+ * </para>
+ * <para>
+ * Here is a simple pipeline to test pixel aspect ratio :
+ * <programlisting>
+ * gst-launch -v videotestsrc ! video/x-raw-rgb, pixel-aspect-ratio=(fraction)4/3 ! videoscale ! xcompizsink
+ * </programlisting>
+ * This is faking a 4/3 pixel aspect ratio caps on video frames produced by
+ * videotestsrc, in most cases the pixel aspect ratio of the display will be
+ * 1/1. This means that videoscale will have to do the scaling to convert 
+ * incoming frames to a size that will match the display pixel aspect ratio
+ * (from 320x240 to 320x180 in this case). Note that you might have to escape 
+ * some characters for your shell like '\(fraction\)'.
+ * </para>
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* Our interfaces */
+#include <gst/interfaces/navigation.h>
+#include <gst/interfaces/xoverlay.h>
+
+/* Object header */
+#include "xcompizsink.h"
+
+/* Debugging category */
+#include <gst/gstinfo.h>
+
+GST_DEBUG_CATEGORY_EXTERN (gst_debug_xcompizsink);
+#define GST_CAT_DEFAULT gst_debug_xcompizsink
+
+typedef struct
+{
+  unsigned long flags;
+  unsigned long functions;
+  unsigned long decorations;
+  long input_mode;
+  unsigned long status;
+}
+MotifWmHints, MwmHints;
+
+#define MWM_HINTS_DECORATIONS   (1L << 1)
+
+static void gst_xcompizsink_reset (GstXCompizSink * xcompizsink);
+static void gst_xcompizsink_ximage_destroy (GstXCompizSink * xcompizsink,
+    GstXCompizBuffer * ximage);
+static void gst_xcompizsink_xwindow_update_geometry (GstXCompizSink * xcompizsink,
+    GstXWindow * xwindow);
+static void gst_xcompizsink_expose (GstXOverlay * overlay);
+
+/* ElementFactory information */
+static const GstElementDetails gst_xcompizsink_details =
+GST_ELEMENT_DETAILS ("Video sink",
+    "Sink/Video",
+    "A standard X based videosink",
+    "JackUn <jack.un@gmail.com>");
+
+static GstStaticPadTemplate gst_xcompizsink_sink_template_factory =
+GST_STATIC_PAD_TEMPLATE ("sink",
+    GST_PAD_SINK,
+    GST_PAD_ALWAYS,
+    GST_STATIC_CAPS ("video/x-raw-rgb, "
+        "framerate = (fraction) [ 0, MAX ], "
+        "width = (int) [ 1, MAX ], " "height = (int) [ 1, MAX ]")
+    );
+
+//GST_BOILERPLATE (GstXCompizSink, gst_xcompizsink, GstElement,
+//   GST_TYPE_ELEMENT);
+    
+enum
+{
+  PROP_0,
+  PROP_DISPLAY,
+  PROP_SYNCHRONOUS,
+  PROP_PIXEL_ASPECT_RATIO,
+  PROP_FORCE_ASPECT_RATIO,
+  PROP_HANDLE_EVENTS,
+  PROP_HANDLE_EXPOSE
+};
+
+static GstVideoSinkClass *parent_class = NULL;
+
+static Atom vo_supporting_wm_check_atom;
+static Atom vo_compiz_video_atom;
+static Atom vo_compiz_video_supported_atom;
+static Atom vo_compiz_video_image_format_rgb_atom;
+static Atom vo_compiz_video_image_format_yv12_atom;
+static int vo_compiz_formats = 0;
+//static int vo_compiz_format = 0;
+//static Atom vo_xprop = None;
+
+
+/* ============================================================= */
+/*                                                               */
+/*                       Private Methods                         */
+/*                                                               */
+/* ============================================================= */
+
+/* ximage buffers */
+
+static GstBufferClass *ximage_buffer_parent_class = NULL;
+
+#define GST_TYPE_XCOMPIZ_BUFFER (gst_ximage_buffer_get_type())
+
+#define GST_IS_XCOMPIZ_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_XCOMPIZ_BUFFER))
+#define GST_XCOMPIZ_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_XCOMPIZ_BUFFER, GstXCompizBuffer))
+#define GST_XCOMPIZ_BUFFER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_XCOMPIZ_BUFFER, GstXCompizBufferClass))
+
+
+static int x11_get_property (GstXCompizSink* xcompizsink, Atom type, Atom **args, unsigned long *nitems)
+{
+    int format;
+    unsigned long bytesafter;
+
+    return (Success ==
+	    XGetWindowProperty(xcompizsink->xcontext->disp, xcompizsink->xcontext->root, type, 0, 16384, False,
+			       AnyPropertyType, &type, &format, nitems,
+			       &bytesafter, (unsigned char **) args)
+	    && *nitems > 0);
+}
+
+
+static gboolean vo_compiz_detect (GstXCompizSink * xcompizsink)
+{
+
+    unsigned long nitems;
+    Atom *args = NULL;
+    int formats = 0;
+    int i;
+    gboolean res=FALSE;
+
+    //if (!x11_update_wm_check_window (xcompizsink))
+    //{
+	//vo_compiz_formats = 0;
+	//return FALSE;
+    //}
+
+    if (x11_get_property (xcompizsink, vo_compiz_video_supported_atom, &args, &nitems))
+    {
+	GST_WARNING_OBJECT (xcompizsink,"Detected wm supports compiz video.");
+	res=TRUE;
+	for (i = 0; i < nitems; i++)
+	{
+	    if (args[i] == vo_compiz_video_image_format_rgb_atom)
+		formats |= COMPIZ_IMAGE_FORMAT_RGB;
+	    else if (args[i] == vo_compiz_video_image_format_yv12_atom)
+		formats |= COMPIZ_IMAGE_FORMAT_YV12;
+	}
+
+	XFree (args);
+    }
+
+    vo_compiz_formats = formats;
+    return res;
+}
+
+static void vo_compiz_init (GstXCompizSink* xcompizsink)
+{
+
+    vo_supporting_wm_check_atom =
+	XInternAtom (xcompizsink->xcontext->disp, "_NET_SUPPORTING_WM_CHECK", FALSE);
+
+    vo_compiz_video_atom = XInternAtom (xcompizsink->xcontext->disp,
+					"_COMPIZ_VIDEO",
+					FALSE);
+
+    vo_compiz_video_supported_atom = XInternAtom (xcompizsink->xcontext->disp,
+						  "_COMPIZ_VIDEO_SUPPORTED",
+						  FALSE);
+
+    vo_compiz_video_image_format_rgb_atom =
+	XInternAtom (xcompizsink->xcontext->disp,
+		     "_COMPIZ_VIDEO_IMAGE_FORMAT_RGB",
+		     FALSE);
+    GST_DEBUG_OBJECT (xcompizsink, "vo_compiz_init %p %p %p %p",
+        vo_supporting_wm_check_atom,
+        vo_compiz_video_atom,
+        vo_compiz_video_supported_atom,
+        vo_compiz_video_image_format_rgb_atom);
+
+	//TODO can i has yv12 ?
+    vo_compiz_video_image_format_yv12_atom =
+	XInternAtom (xcompizsink->xcontext->disp,
+		     "_COMPIZ_VIDEO_IMAGE_FORMAT_YV12",FALSE);
+	vo_compiz_video_image_format_yv12_atom = 0;
+
+    //XSelectInput (xcompizsink->xcontext->disp, xcompizsink->xwindow->win, PropertyChangeMask);
+
+    vo_compiz_detect (xcompizsink);
+    xcompizsink->compiz_inited = TRUE;
+}
+
+
+/* So some words about GstMiniObject, this is pretty messy...
+   GstMiniObject does not use the standard finalizing of GObjects, you are 
+   supposed to call gst_buffer_unref that's going to call gst_mini_objec_unref
+   which will handle its own refcount system and call gst_mini_object_free.
+   gst_mini_object_free will call the class finalize method which is not the 
+   one from GObject, after calling this finalize method it will free the object
+   instance for you if the refcount is still 0 so you should not chain up */
+static void
+gst_xcompiz_buffer_finalize (GstXCompizBuffer * ximage)
+{
+  GstXCompizSink *xcompizsink = NULL;
+  gboolean recycled = FALSE;
+  gboolean running;
+
+  g_return_if_fail (ximage != NULL);
+
+  xcompizsink = ximage->xcompizsink;
+  if (G_UNLIKELY (xcompizsink == NULL)) {
+    GST_WARNING_OBJECT (xcompizsink, "no sink found");
+    goto beach;
+  }
+
+  GST_OBJECT_LOCK (xcompizsink);
+  running = xcompizsink->running;
+  GST_OBJECT_UNLOCK (xcompizsink);
+
+  if (running == FALSE) {
+    /* If the sink is shutting down, need to clear the image */
+    GST_DEBUG_OBJECT (xcompizsink,
+        "destroy image %p because the sink is shutting down", ximage);
+    gst_xcompizsink_ximage_destroy (xcompizsink, ximage);
+  } else if ((ximage->width != GST_VIDEO_SINK_WIDTH (xcompizsink)) ||
+      (ximage->height != GST_VIDEO_SINK_HEIGHT (xcompizsink))) {
+    /* If our geometry changed we can't reuse that image. */
+    GST_DEBUG_OBJECT (xcompizsink,
+        "destroy image %p as its size changed %dx%d vs current %dx%d",
+        ximage, ximage->width, ximage->height,
+        GST_VIDEO_SINK_WIDTH (xcompizsink), GST_VIDEO_SINK_HEIGHT (xcompizsink));
+    gst_xcompizsink_ximage_destroy (xcompizsink, ximage);
+  } else {
+    /* In that case we can reuse the image and add it to our image pool. */
+    GST_LOG_OBJECT (xcompizsink, "recycling image %p in pool", ximage);
+    /* need to increment the refcount again to recycle */
+    gst_buffer_ref (GST_BUFFER_CAST (ximage));
+    g_mutex_lock (xcompizsink->pool_lock);
+    xcompizsink->buffer_pool = g_slist_prepend (xcompizsink->buffer_pool, ximage);
+    g_mutex_unlock (xcompizsink->pool_lock);
+    recycled = TRUE;
+  }
+
+  if (!recycled)
+    GST_MINI_OBJECT_CLASS (ximage_buffer_parent_class)->
+        finalize (GST_MINI_OBJECT (ximage));
+
+beach:
+  return;
+}
+
+static void
+gst_ximage_buffer_free (GstXCompizBuffer * ximage)
+{
+  /* make sure it is not recycled */
+  ximage->width = -1;
+  ximage->height = -1;
+  gst_buffer_unref (GST_BUFFER_CAST (ximage));
+}
+
+static void
+gst_xcompiz_buffer_init (GstXCompizBuffer * ximage_buffer, gpointer g_class)
+{
+#ifdef HAVE_XSHM
+  ximage_buffer->SHMInfo.shmaddr = ((void *) -1);
+  ximage_buffer->SHMInfo.shmid = -1;
+#endif
+}
+
+static void
+gst_xcompiz_buffer_class_init (gpointer g_class, gpointer class_data)
+{
+  GstMiniObjectClass *mini_object_class = GST_MINI_OBJECT_CLASS (g_class);
+
+  ximage_buffer_parent_class = g_type_class_peek_parent (g_class);
+
+  mini_object_class->finalize = (GstMiniObjectFinalizeFunction)
+      gst_xcompiz_buffer_finalize;
+}
+
+GType
+gst_ximage_buffer_get_type (void)
+{
+  static GType _gst_xcompiz_buffer_type;
+
+  if (G_UNLIKELY (_gst_xcompiz_buffer_type == 0)) {
+    static const GTypeInfo xcompiz_buffer_info = {
+      sizeof (GstBufferClass),
+      NULL,
+      NULL,
+      gst_xcompiz_buffer_class_init,
+      NULL,
+      NULL,
+      sizeof (GstXCompizBuffer),
+      0,
+      (GInstanceInitFunc) gst_xcompiz_buffer_init,
+      NULL
+    };
+    _gst_xcompiz_buffer_type = g_type_register_static (GST_TYPE_BUFFER,
+        "GstXCompizBuffer", &xcompiz_buffer_info, 0);
+  }
+  return _gst_xcompiz_buffer_type;
+}
+
+/* X11 stuff */
+
+static gboolean error_caught = FALSE;
+
+static int
+gst_xcompizsink_handle_xerror (Display * display, XErrorEvent * xevent)
+{
+  char error_msg[1024];
+
+  XGetErrorText (display, xevent->error_code, error_msg, 1024);
+  GST_DEBUG ("xcompizsink triggered an XError. error: %s", error_msg);
+  error_caught = TRUE;
+  return 0;
+}
+
+#ifdef HAVE_XSHM                /* Check that XShm calls actually work */
+
+static gboolean
+gst_xcompizsink_check_xshm_calls (GstXCompizSink * xcompizsink,
+    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 (gst_xcompizsink_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));
+    /* Clean up shm seg */
+    shmctl (SHMInfo.shmid, IPC_RMID, 0);
+    goto beach;
+  }
+
+  /* Delete the shared memory segment as soon as we manage to attach. 
+   * This way, it will be deleted as soon as we detach later, and not
+   * leaked if we crash. */
+  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 handles GstXCompizBuffer creation depending on XShm availability */
+static GstXCompizBuffer *
+gst_xcompizsink_ximage_new (GstXCompizSink * xcompizsink, GstCaps * caps)
+{
+  GstXCompizBuffer *ximage = NULL;
+  GstStructure *structure = NULL;
+  gboolean succeeded = FALSE;
+  int (*handler) (Display *, XErrorEvent *);
+  
+  g_return_val_if_fail (GST_IS_XCOMPIZSINK (xcompizsink), NULL);
+
+  ximage = (GstXCompizBuffer *) gst_mini_object_new (GST_TYPE_XCOMPIZ_BUFFER);
+
+  structure = gst_caps_get_structure (caps, 0);
+
+  if (!gst_structure_get_int (structure, "width", &ximage->width) ||
+      !gst_structure_get_int (structure, "height", &ximage->height)) {
+    GST_WARNING ("failed getting geometry from caps %" GST_PTR_FORMAT, caps);
+  }
+
+  GST_DEBUG_OBJECT (xcompizsink, "creating image %p (%dx%d)", ximage,
+      ximage->width, ximage->height);
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  /* Setting an error handler to catch failure */
+  error_caught = FALSE;
+  handler = XSetErrorHandler (gst_xcompizsink_handle_xerror);
+
+
+#ifdef HAVE_XSHM
+  if (xcompizsink->xcontext->use_xshm) {
+  	
+
+    ximage->ximage = XShmCreateImage (xcompizsink->xcontext->disp,
+       xcompizsink->xcontext->visual,
+        xcompizsink->xcontext->depth,
+        ZPixmap, NULL, &ximage->SHMInfo, ximage->width, ximage->height);
+        
+    if (!ximage->ximage || error_caught) {
+      g_mutex_unlock (xcompizsink->x_lock);
+      /* Reset error handler */
+      error_caught = FALSE;
+      XSetErrorHandler (handler);
+      /* Push an error */
+      GST_ELEMENT_ERROR (xcompizsink, RESOURCE, WRITE,
+          ("Failed to create output image buffer of %dx%d pixels",
+              ximage->width, ximage->height),
+          ("could not XShmCreateImage a %dx%d image",
+              ximage->width, ximage->height));
+      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;
+    GST_LOG_OBJECT (xcompizsink,
+        "XShm image size is %" G_GSIZE_FORMAT ", width %d, stride %d",
+        ximage->size, ximage->width, ximage->ximage->bytes_per_line);
+
+    ximage->SHMInfo.shmid = shmget (IPC_PRIVATE, ximage->size,
+        IPC_CREAT | 0777);
+    if (ximage->SHMInfo.shmid == -1) {
+      g_mutex_unlock (xcompizsink->x_lock);
+      GST_ELEMENT_ERROR (xcompizsink, RESOURCE, WRITE,
+          ("Failed to create output image buffer of %dx%d pixels",
+              ximage->width, ximage->height),
+          ("could not get shared memory of %" G_GSIZE_FORMAT " bytes",
+              ximage->size));
+      goto beach;
+    }
+
+    ximage->SHMInfo.shmaddr = shmat (ximage->SHMInfo.shmid, 0, 0);
+    if (ximage->SHMInfo.shmaddr == ((void *) -1)) {
+      g_mutex_unlock (xcompizsink->x_lock);
+      GST_ELEMENT_ERROR (xcompizsink, RESOURCE, WRITE,
+          ("Failed to create output image buffer of %dx%d pixels",
+              ximage->width, ximage->height),
+          ("Failed to shmat: %s", g_strerror (errno)));
+      /* Clean up the shared memory segment */
+      shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0);
+      goto beach;
+    }
+
+    /* Now that we've attached, we can delete the shared memory segment.
+     * This way, it will be deleted as soon as we detach later, and not
+     * leaked if we crash. */
+    shmctl (ximage->SHMInfo.shmid, IPC_RMID, 0);
+
+    ximage->ximage->data = ximage->SHMInfo.shmaddr;
+    ximage->SHMInfo.readOnly = FALSE;
+
+    if (XShmAttach (xcompizsink->xcontext->disp, &ximage->SHMInfo) == 0) {
+      g_mutex_unlock (xcompizsink->x_lock);
+      GST_ELEMENT_ERROR (xcompizsink, RESOURCE, WRITE,
+          ("Failed to create output image buffer of %dx%d pixels",
+              ximage->width, ximage->height), ("Failed to XShmAttach"));
+      goto beach;
+    }
+    
+    
+   GST_WARNING_OBJECT(xcompizsink,"XShmCreatePixmap...");
+
+   ximage->pixmap = XShmCreatePixmap (xcompizsink->xcontext->disp,
+  				xcompizsink->xcontext->root,
+  				ximage->ximage->data,
+  				&ximage->SHMInfo,
+				ximage->width, ximage->height,
+				ximage->ximage->depth);
+	
+	if(xcompizsink->xwindow)			
+	  xcompizsink->xwindow->xprop = 0;
+	
+	/*ximage->pixmap = XCreatePixmap (xcompizsink->xcontext->disp,
+  				xcompizsink->xcontext->root,
+				ximage->width, ximage->height,
+				ximage->ximage->depth);*/
+				
+	//ximage->pixmap_gc = XCreateGC (xcompizsink->xcontext->disp, ximage->pixmap, 0L, NULL);
+
+	GST_WARNING_OBJECT(xcompizsink,"XShmPixmap: %p",ximage->pixmap);
+
+    XSync (xcompizsink->xcontext->disp, FALSE);
+  } else
+#endif /* HAVE_XSHM */
+  {
+    guint allocsize;
+
+    ximage->ximage = XCreateImage (xcompizsink->xcontext->disp,
+        xcompizsink->xcontext->visual,
+        xcompizsink->xcontext->depth,
+        ZPixmap, 0, NULL,
+        ximage->width, ximage->height, xcompizsink->xcontext->bpp, 0);
+        
+    if (!ximage->ximage || error_caught) {
+      g_mutex_unlock (xcompizsink->x_lock);
+      /* Reset error handler */
+      error_caught = FALSE;
+      XSetErrorHandler (handler);
+      /* Push an error */
+      GST_ELEMENT_ERROR (xcompizsink, RESOURCE, WRITE,
+          ("Failed to create output image buffer of %dx%d pixels",
+              ximage->width, ximage->height),
+          ("could not XCreateImage a %dx%d image",
+              ximage->width, ximage->height));
+      goto beach;
+    }
+
+    /* upstream will assume that rowstrides are multiples of 4, but this
+     * doesn't always seem to be the case with XCreateImage() */
+    if ((ximage->ximage->bytes_per_line % 4) != 0) {
+      GST_WARNING_OBJECT (xcompizsink, "returned stride not a multiple of 4 as "
+          "usually assumed");
+    }
+
+    /* we have to use the returned bytes_per_line for our image size */
+    ximage->size = ximage->ximage->bytes_per_line * ximage->ximage->height;
+
+    /* alloc a bit more for unexpected strides to avoid crashes upstream.
+     * FIXME: if we get an unrounded stride, the image will be displayed
+     * distorted, since all upstream elements assume a rounded stride */
+    allocsize =
+        GST_ROUND_UP_4 (ximage->ximage->bytes_per_line) *
+        ximage->ximage->height;
+    ximage->ximage->data = g_malloc (allocsize);
+    GST_LOG_OBJECT (xcompizsink,
+        "non-XShm image size is %" G_GSIZE_FORMAT " (alloced: %u), width %d, "
+        "stride %d", ximage->size, allocsize, ximage->width,
+        ximage->ximage->bytes_per_line);
+        
+    GST_WARNING_OBJECT(xcompizsink,"XPixmap: ");
+  	ximage->pixmap = XCreatePixmap (xcompizsink->xcontext->disp,
+  				xcompizsink->xcontext->root,
+				ximage->width, ximage->height,
+				xcompizsink->xcontext->depth);
+	
+	if(xcompizsink->xwindow)
+	  xcompizsink->xwindow->xprop = 0;
+
+	//ximage->pixmap_gc = XCreateGC (xcompizsink->xcontext->disp, ximage->pixmap, 0L, NULL);
+	
+    XSync (xcompizsink->xcontext->disp, FALSE);
+  }
+
+  /* Reset error handler */
+  error_caught = FALSE;
+  XSetErrorHandler (handler);
+
+  succeeded = TRUE;
+
+  GST_BUFFER_DATA (ximage) = (guchar *) ximage->ximage->data;
+  GST_BUFFER_SIZE (ximage) = ximage->size;
+
+  /* Keep a ref to our sink */
+  ximage->xcompizsink = gst_object_ref (xcompizsink);
+
+  g_mutex_unlock (xcompizsink->x_lock);
+beach:
+  if (!succeeded) {
+    gst_ximage_buffer_free (ximage);
+    ximage = NULL;
+  }
+
+  return ximage;
+}
+
+/* This function destroys a GstXCompizBuffer handling XShm availability */
+static void
+gst_xcompizsink_ximage_destroy (GstXCompizSink * xcompizsink,
+    GstXCompizBuffer * ximage)
+{
+  g_return_if_fail (ximage != NULL);
+  g_return_if_fail (GST_IS_XCOMPIZSINK (xcompizsink));
+
+  /* Hold the object lock to ensure the XContext doesn't disappear */
+  GST_OBJECT_LOCK (xcompizsink);
+
+  /* If the destroyed image is the current one we destroy our reference too */
+  if (xcompizsink->cur_image == ximage) {
+    xcompizsink->cur_image = NULL;
+  }
+
+  /* We might have some buffers destroyed after changing state to NULL */
+  if (!xcompizsink->xcontext) {
+    GST_DEBUG_OBJECT (xcompizsink, "Destroying XImage after XContext");
+#ifdef HAVE_XSHM
+    if (ximage->SHMInfo.shmaddr != ((void *) -1)) {
+      shmdt (ximage->SHMInfo.shmaddr);
+    }
+#endif
+    goto beach;
+  }
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+#ifdef HAVE_XSHM
+  if (xcompizsink->xcontext->use_xshm) {
+    if (ximage->SHMInfo.shmaddr != ((void *) -1)) {
+      XShmDetach (xcompizsink->xcontext->disp, &ximage->SHMInfo);
+      XSync (xcompizsink->xcontext->disp, 0);
+      shmdt (ximage->SHMInfo.shmaddr);
+    }
+    if (ximage->ximage)
+      XDestroyImage (ximage->ximage);
+    if (ximage->pixmap_gc) {
+     XFreeGC(xcompizsink->xcontext->disp,ximage->pixmap_gc);
+    }
+    if (ximage->pixmap) {
+     XFreePixmap(xcompizsink->xcontext->disp,ximage->pixmap);
+    }
+
+  } else
+#endif /* HAVE_XSHM */
+  {
+    if (ximage->ximage) {
+      XDestroyImage (ximage->ximage);
+    }
+    if (ximage->pixmap_gc) {
+     XFreeGC(xcompizsink->xcontext->disp,ximage->pixmap_gc);
+    }
+    if (ximage->pixmap) {
+     XFreePixmap(xcompizsink->xcontext->disp,ximage->pixmap);
+    }
+
+  }
+
+  XSync (xcompizsink->xcontext->disp, FALSE);
+
+  g_mutex_unlock (xcompizsink->x_lock);
+
+beach:
+  GST_OBJECT_UNLOCK (xcompizsink);
+
+  if (ximage->xcompizsink) {
+    /* Release the ref to our sink */
+    ximage->xcompizsink = NULL;
+    gst_object_unref (xcompizsink);
+  }
+
+  return;
+}
+
+/* We are called with the x_lock taken */
+/*
+static void
+gst_xcompizsink_xwindow_draw_borders (GstXCompizSink * xcompizsink,
+    GstXWindow * xwindow, GstVideoRectangle rect)
+{
+  g_return_if_fail (GST_IS_XCOMPIZSINK (xcompizsink));
+  g_return_if_fail (xwindow != NULL);
+
+  XSetForeground (xcompizsink->xcontext->disp, xwindow->gc,
+      xcompizsink->xcontext->black);
+  if (rect.x > 0) {
+    XFillRectangle (xcompizsink->xcontext->disp, xwindow->win, xwindow->gc,
+        0, 0, rect.x, xwindow->height);
+  }
+  if ((rect.x + rect.w) < xwindow->width) {
+    XFillRectangle (xcompizsink->xcontext->disp, xwindow->win, xwindow->gc,
+        rect.x + rect.w, 0, xwindow->width, xwindow->height);
+  }
+
+
+  if (rect.y > 0) {
+    XFillRectangle (xcompizsink->xcontext->disp, xwindow->win, xwindow->gc,
+        0, 0, xwindow->width, rect.y);
+  }
+
+
+  if ((rect.y + rect.h) < xwindow->height) {
+    XFillRectangle (xcompizsink->xcontext->disp, xwindow->win, xwindow->gc,
+        0, rect.y + rect.h, xwindow->width, xwindow->height);
+  }
+}
+*/
+
+/* This function puts a GstXCompizBuffer on a GstXCompizSink's window */
+static gboolean
+gst_xcompizsink_ximage_put (GstXCompizSink * xcompizsink, GstXCompizBuffer * ximage)
+{
+  //GstVideoRectangle  result; //,src, dst,
+  gboolean draw_border = FALSE;
+
+  g_return_val_if_fail (GST_IS_XCOMPIZSINK (xcompizsink), FALSE);
+
+  /* We take the flow_lock. If expose is in there we don't want to run
+     concurrently from the data flow thread */
+  g_mutex_lock (xcompizsink->flow_lock);
+
+  if (G_UNLIKELY (xcompizsink->xwindow == NULL)) {
+    g_mutex_unlock (xcompizsink->flow_lock);
+    return FALSE;
+  }
+
+  /* Draw borders when displaying the first frame. After this
+     draw borders only on expose event. */
+  if (!xcompizsink->cur_image) {
+    draw_border = TRUE;
+  }
+
+  /* Store a reference to the last image we put, lose the previous one */
+  if (ximage && xcompizsink->cur_image != ximage) {
+    if (xcompizsink->cur_image) {
+      GST_LOG_OBJECT (xcompizsink, "unreffing %p", xcompizsink->cur_image);
+      gst_buffer_unref (xcompizsink->cur_image);
+    }
+    GST_LOG_OBJECT (xcompizsink, "reffing %p as our current image", ximage);
+    xcompizsink->cur_image =
+        GST_XCOMPIZ_BUFFER (gst_buffer_ref (GST_BUFFER_CAST (ximage)));
+  }
+
+  /* Expose sends a NULL image, we take the latest frame */
+  if (!ximage) {
+  //  draw_border = TRUE;
+    if (xcompizsink->cur_image) {
+      ximage = xcompizsink->cur_image;
+    } else {
+      g_mutex_unlock (xcompizsink->flow_lock);
+      return TRUE;
+    }
+  }
+
+  gst_xcompizsink_xwindow_update_geometry (xcompizsink, xcompizsink->xwindow);
+
+  //src.w = ximage->width;
+  //src.h = ximage->height;
+  //dst.w = xcompizsink->xwindow->width;
+  //dst.h = xcompizsink->xwindow->height;
+
+  //gst_video_sink_center_rect (src, dst, &result, FALSE);
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  //if (draw_border) {
+   // gst_xcompizsink_xwindow_draw_borders (xcompizsink, xcompizsink->xwindow,
+   //     result);
+  //}
+  
+#ifdef HAVE_XSHM
+  if (xcompizsink->xcontext->use_xshm) {
+    GST_LOG_OBJECT (xcompizsink,
+        "XShmPutImage on %p, pix: %p src:%dx%d - win %dx%d %p",
+        ximage, ximage->pixmap, ximage->width, ximage->height,
+        xcompizsink->xwindow->width, xcompizsink->xwindow->height,xcompizsink->xwindow->win);
+        
+    XShmPutImage (xcompizsink->xcontext->disp, ximage->pixmap,
+        xcompizsink->xwindow->gc/*ximage->pixmap_gc*/,
+        ximage->ximage, 0, 0, 0,0,
+        ximage->width,ximage->height, FALSE);
+  } else
+#endif /* HAVE_XSHM */
+  {
+    GST_LOG_OBJECT (xcompizsink,
+        "XPutImage on %p, pix: %p src:%dx%d - win %dx%d %p",
+        ximage, ximage->pixmap, ximage->width, ximage->height,
+        xcompizsink->xwindow->width, xcompizsink->xwindow->height,xcompizsink->xwindow->win);
+        
+    XPutImage (xcompizsink->xcontext->disp, ximage->pixmap,
+        xcompizsink->xwindow->gc/*ximage->pixmap_gc*/, ximage->ximage, 0, 0, 
+        0,0,ximage->width,ximage->height);
+  }
+ 
+ 
+  if(xcompizsink->compiz_inited && !xcompizsink->xwindow->xprop)//Should be set once or when pixmap changes :P
+  {
+
+	GST_DEBUG_OBJECT(xcompizsink,"Setting Xwindow props");	
+	
+	XSetWindowBackground (xcompizsink->xcontext->disp, xcompizsink->xwindow->win, 0);
+	XClearWindow (xcompizsink->xcontext->disp, xcompizsink->xwindow->win);
+	
+	long data[11];
+	data[0] = ximage->pixmap;
+
+	//if (xcompizsink->im_format == COMPIZ_IMAGE_FORMAT_YV12)// i can has yv12 now? kthnxbai
+	//    data[1] = vo_compiz_video_image_format_yv12_atom;
+	//else
+	    data[1] = vo_compiz_video_image_format_rgb_atom;
+
+	data[2] = ximage->width;
+	data[3] = ximage->height;
+
+
+	data[4] = ximage->width;
+	data[5] = ximage->height;
+	data[6] = 0;//65536;//vo_panscan * 65536;
+
+	data[7]  = GRAVITY_NORTH | GRAVITY_WEST;
+	data[8]  = 0;
+	data[9]  = 0;
+	data[10] = GRAVITY_SOUTH | GRAVITY_EAST;
+	data[11] = 0;
+	data[12] = 0;
+
+	GST_WARNING_OBJECT(xcompizsink,"compiz video atom: %p  win:%p root:%p",vo_compiz_video_atom,
+	xcompizsink->xwindow->win,xcompizsink->xcontext->root);
+	XChangeProperty (xcompizsink->xcontext->disp,
+			 xcompizsink->xwindow->win,
+			 vo_compiz_video_atom,
+			 XA_INTEGER,
+			 32, PropModeReplace, (guchar *) data,
+			 13);
+	xcompizsink->xwindow->xprop=1;
+  }
+
+  XSync (xcompizsink->xcontext->disp, FALSE);
+
+  g_mutex_unlock (xcompizsink->x_lock);
+
+  g_mutex_unlock (xcompizsink->flow_lock);
+
+  return TRUE;
+}
+
+static gboolean
+gst_xcompizsink_xwindow_decorate (GstXCompizSink * xcompizsink,
+    GstXWindow * window)
+{
+  Atom hints_atom = None;
+  MotifWmHints *hints;
+
+  g_return_val_if_fail (GST_IS_XCOMPIZSINK (xcompizsink), FALSE);
+  g_return_val_if_fail (window != NULL, FALSE);
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  hints_atom = XInternAtom (xcompizsink->xcontext->disp, "_MOTIF_WM_HINTS", 1);
+  if (hints_atom == None) {
+    g_mutex_unlock (xcompizsink->x_lock);
+    return FALSE;
+  }
+
+  hints = g_malloc0 (sizeof (MotifWmHints));
+
+  hints->flags |= MWM_HINTS_DECORATIONS;
+  hints->decorations = 1 << 0;
+
+  XChangeProperty (xcompizsink->xcontext->disp, window->win,
+      hints_atom, hints_atom, 32, PropModeReplace,
+      (guchar *) hints, sizeof (MotifWmHints) / sizeof (long));
+
+  XSync (xcompizsink->xcontext->disp, FALSE);
+
+  g_mutex_unlock (xcompizsink->x_lock);
+
+  g_free (hints);
+
+  return TRUE;
+}
+
+/* This function handles a GstXWindow creation */
+static GstXWindow *
+gst_xcompizsink_xwindow_new (GstXCompizSink * xcompizsink, gint width, gint height)
+{
+  GstXWindow *xwindow = NULL;
+  XGCValues values;
+
+  g_return_val_if_fail (GST_IS_XCOMPIZSINK (xcompizsink), NULL);
+
+  xwindow = g_new0 (GstXWindow, 1);
+
+  xwindow->width = width;
+  xwindow->height = height;
+  xwindow->internal = TRUE;
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  xwindow->win = XCreateSimpleWindow (xcompizsink->xcontext->disp,
+      xcompizsink->xcontext->root,
+      0, 0, xwindow->width, xwindow->height, 0, 0, xcompizsink->xcontext->black);
+
+  /* We have to do that to prevent X from redrawing the background on 
+     ConfigureNotify. This takes away flickering of video when resizing. */
+  XSetWindowBackgroundPixmap (xcompizsink->xcontext->disp, xwindow->win, None);
+
+  if (xcompizsink->handle_events) {
+    Atom wm_delete;
+
+    XSelectInput (xcompizsink->xcontext->disp, xwindow->win, ExposureMask |
+        StructureNotifyMask | PointerMotionMask | KeyPressMask |
+        KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask);
+
+    /* Tell the window manager we'd like delete client messages instead of
+     * being killed */
+    wm_delete = XInternAtom (xcompizsink->xcontext->disp,
+        "WM_DELETE_WINDOW", False);
+    (void) XSetWMProtocols (xcompizsink->xcontext->disp, xwindow->win,
+        &wm_delete, 1);
+  }
+
+  xwindow->gc = XCreateGC (xcompizsink->xcontext->disp, xwindow->win,
+      0, &values);
+
+  XMapRaised (xcompizsink->xcontext->disp, xwindow->win);
+
+  XSync (xcompizsink->xcontext->disp, FALSE);
+
+  g_mutex_unlock (xcompizsink->x_lock);
+
+  gst_xcompizsink_xwindow_decorate (xcompizsink, xwindow);
+  
+  xwindow->xprop = 0;
+  xcompizsink->compiz_inited = FALSE;
+
+  gst_x_overlay_got_xwindow_id (GST_X_OVERLAY (xcompizsink), xwindow->win);
+  
+  GST_DEBUG_OBJECT(xcompizsink,"new xwindow id %p",xwindow->win);
+
+  return xwindow;
+}
+
+/* This function destroys a GstXWindow */
+static void
+gst_xcompizsink_xwindow_destroy (GstXCompizSink * xcompizsink,
+    GstXWindow * xwindow)
+{
+  g_return_if_fail (xwindow != NULL);
+  g_return_if_fail (GST_IS_XCOMPIZSINK (xcompizsink));
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  /* If we did not create that window we just free the GC and let it live */
+  if (xwindow->internal)
+    XDestroyWindow (xcompizsink->xcontext->disp, xwindow->win);
+  else
+    XSelectInput (xcompizsink->xcontext->disp, xwindow->win, 0);
+
+  XFreeGC (xcompizsink->xcontext->disp, xwindow->gc);
+
+  XSync (xcompizsink->xcontext->disp, FALSE);
+
+  g_mutex_unlock (xcompizsink->x_lock);
+
+  g_free (xwindow);
+}
+
+static void
+gst_xcompizsink_xwindow_update_geometry (GstXCompizSink * xcompizsink,
+    GstXWindow * xwindow)
+{
+  XWindowAttributes attr;
+
+  g_return_if_fail (xwindow != NULL);
+  g_return_if_fail (GST_IS_XCOMPIZSINK (xcompizsink));
+
+  /* Update the window geometry */
+  g_mutex_lock (xcompizsink->x_lock);
+
+  XGetWindowAttributes (xcompizsink->xcontext->disp,
+      xcompizsink->xwindow->win, &attr);
+
+  xcompizsink->xwindow->width = attr.width;
+  xcompizsink->xwindow->height = attr.height;
+
+  g_mutex_unlock (xcompizsink->x_lock);
+}
+
+static void
+gst_xcompizsink_xwindow_clear (GstXCompizSink * xcompizsink, GstXWindow * xwindow)
+{
+  g_return_if_fail (xwindow != NULL);
+  g_return_if_fail (GST_IS_XCOMPIZSINK (xcompizsink));
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  XSetForeground (xcompizsink->xcontext->disp, xwindow->gc,
+      xcompizsink->xcontext->black);
+
+  XFillRectangle (xcompizsink->xcontext->disp, xwindow->win, xwindow->gc,
+      0, 0, xwindow->width, xwindow->height);
+
+  XSync (xcompizsink->xcontext->disp, FALSE);
+
+  g_mutex_unlock (xcompizsink->x_lock);
+}
+
+/* This function handles XEvents that might be in the queue. It generates
+   GstEvent that will be sent upstream in the pipeline to handle interactivity
+   and navigation.*/
+static void
+gst_xcompizsink_handle_xevents (GstXCompizSink * xcompizsink)
+{
+  XEvent e;
+  guint pointer_x = 0, pointer_y = 0;
+  gboolean pointer_moved = FALSE;
+  gboolean exposed = FALSE, configured = FALSE;
+
+  g_return_if_fail (GST_IS_XCOMPIZSINK (xcompizsink));
+
+  /* Then we get all pointer motion events, only the last position is
+     interesting. */
+  g_mutex_lock (xcompizsink->flow_lock);
+  g_mutex_lock (xcompizsink->x_lock);
+  while (XCheckWindowEvent (xcompizsink->xcontext->disp,
+          xcompizsink->xwindow->win, PointerMotionMask, &e)) {
+    g_mutex_unlock (xcompizsink->x_lock);
+    g_mutex_unlock (xcompizsink->flow_lock);
+
+    switch (e.type) {
+      case MotionNotify:
+        pointer_x = e.xmotion.x;
+        pointer_y = e.xmotion.y;
+        pointer_moved = TRUE;
+        break;
+      default:
+        break;
+    }
+    g_mutex_lock (xcompizsink->flow_lock);
+    g_mutex_lock (xcompizsink->x_lock);
+  }
+
+  if (pointer_moved) {
+    g_mutex_unlock (xcompizsink->x_lock);
+    g_mutex_unlock (xcompizsink->flow_lock);
+
+    GST_DEBUG ("xcompizsink pointer moved over window at %d,%d",
+        pointer_x, pointer_y);
+    gst_navigation_send_mouse_event (GST_NAVIGATION (xcompizsink),
+        "mouse-move", 0, pointer_x, pointer_y);
+
+    g_mutex_lock (xcompizsink->flow_lock);
+    g_mutex_lock (xcompizsink->x_lock);
+  }
+
+  /* We get all remaining events on our window to throw them upstream */
+  while (XCheckWindowEvent (xcompizsink->xcontext->disp,
+          xcompizsink->xwindow->win,
+          KeyPressMask | KeyReleaseMask |
+          ButtonPressMask | ButtonReleaseMask, &e)) {
+    KeySym keysym;
+
+    /* We lock only for the X function call */
+    g_mutex_unlock (xcompizsink->x_lock);
+    g_mutex_unlock (xcompizsink->flow_lock);
+
+    switch (e.type) {
+      case ButtonPress:
+        /* Mouse button pressed/released over our window. We send upstream
+           events for interactivity/navigation */
+        GST_DEBUG ("xcompizsink button %d pressed over window at %d,%d",
+            e.xbutton.button, e.xbutton.x, e.xbutton.x);
+        gst_navigation_send_mouse_event (GST_NAVIGATION (xcompizsink),
+            "mouse-button-press", e.xbutton.button, e.xbutton.x, e.xbutton.y);
+        break;
+      case ButtonRelease:
+        GST_DEBUG ("xcompizsink button %d release over window at %d,%d",
+            e.xbutton.button, e.xbutton.x, e.xbutton.x);
+        gst_navigation_send_mouse_event (GST_NAVIGATION (xcompizsink),
+            "mouse-button-release", e.xbutton.button, e.xbutton.x, e.xbutton.y);
+        break;
+      case KeyPress:
+      case KeyRelease:
+        /* Key pressed/released over our window. We send upstream
+           events for interactivity/navigation */
+        GST_DEBUG ("xcompizsink key %d pressed over window at %d,%d",
+            e.xkey.keycode, e.xkey.x, e.xkey.x);
+        g_mutex_lock (xcompizsink->x_lock);
+        keysym = XKeycodeToKeysym (xcompizsink->xcontext->disp,
+            e.xkey.keycode, 0);
+        g_mutex_unlock (xcompizsink->x_lock);
+        if (keysym != NoSymbol) {
+          char *key_str = NULL;
+
+          g_mutex_lock (xcompizsink->x_lock);
+          key_str = XKeysymToString (keysym);
+          g_mutex_unlock (xcompizsink->x_lock);
+          gst_navigation_send_key_event (GST_NAVIGATION (xcompizsink),
+              e.type == KeyPress ? "key-press" : "key-release", key_str);
+
+        } else {
+          gst_navigation_send_key_event (GST_NAVIGATION (xcompizsink),
+              e.type == KeyPress ? "key-press" : "key-release", "unknown");
+        }
+        break;
+      default:
+        GST_DEBUG_OBJECT (xcompizsink, "xcompizsink unhandled X event (%d)",
+            e.type);
+    }
+    g_mutex_lock (xcompizsink->flow_lock);
+    g_mutex_lock (xcompizsink->x_lock);
+  }
+
+  while (XCheckWindowEvent (xcompizsink->xcontext->disp,
+          xcompizsink->xwindow->win, ExposureMask | StructureNotifyMask, &e)) {
+    switch (e.type) {
+      case Expose:
+        exposed = TRUE;
+        break;
+      case ConfigureNotify:
+        configured = TRUE;
+        break;
+      default:
+        break;
+    }
+  }
+
+  if (xcompizsink->handle_expose && (exposed || configured)) {
+    g_mutex_unlock (xcompizsink->x_lock);
+    g_mutex_unlock (xcompizsink->flow_lock);
+
+    gst_xcompizsink_expose (GST_X_OVERLAY (xcompizsink));
+
+    g_mutex_lock (xcompizsink->flow_lock);
+    g_mutex_lock (xcompizsink->x_lock);
+  }
+
+  /* Handle Display events */
+  while (XPending (xcompizsink->xcontext->disp)) {
+    XNextEvent (xcompizsink->xcontext->disp, &e);
+
+    switch (e.type) {
+      case ClientMessage:{
+        Atom wm_delete;
+
+        wm_delete = XInternAtom (xcompizsink->xcontext->disp,
+            "WM_DELETE_WINDOW", False);
+        if (wm_delete == (Atom) e.xclient.data.l[0]) {
+          /* Handle window deletion by posting an error on the bus */
+          GST_ELEMENT_ERROR (xcompizsink, RESOURCE, NOT_FOUND,
+              ("Output window was closed"), (NULL));
+
+          g_mutex_unlock (xcompizsink->x_lock);
+          gst_xcompizsink_xwindow_destroy (xcompizsink, xcompizsink->xwindow);
+          xcompizsink->xwindow = NULL;
+          g_mutex_lock (xcompizsink->x_lock);
+        }
+        break;
+      }
+      case PropertyNotify:{
+      	if (e.xproperty.atom == vo_compiz_video_supported_atom)
+	    vo_compiz_detect(xcompizsink);//And then quit if no compiz?
+      break;
+      }
+      default:
+        break;
+    }
+  }
+
+  g_mutex_unlock (xcompizsink->x_lock);
+  g_mutex_unlock (xcompizsink->flow_lock);
+}
+
+static gpointer
+gst_xcompizsink_event_thread (GstXCompizSink * xcompizsink)
+{
+  g_return_val_if_fail (GST_IS_XCOMPIZSINK (xcompizsink), NULL);
+
+  GST_OBJECT_LOCK (xcompizsink);
+  while (xcompizsink->running) {
+    GST_OBJECT_UNLOCK (xcompizsink);
+
+    if (xcompizsink->xwindow) {
+      gst_xcompizsink_handle_xevents (xcompizsink);
+    }
+    g_usleep (100000);
+
+    GST_OBJECT_LOCK (xcompizsink);
+  }
+  GST_OBJECT_UNLOCK (xcompizsink);
+
+  return NULL;
+}
+
+/* This function calculates the pixel aspect ratio based on the properties
+ * in the xcontext structure and stores it there. */
+static void
+gst_xcompizsink_calculate_pixel_aspect_ratio (GstXContext * xcontext)
+{
+  static const 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 */
+    {64, 45},                   /* 1280x1024 on 16:9 display */
+    {5, 3},                     /* 1280x1024 on 4:3 display */
+    {4, 3}                      /*  800x600 on 16:9 display */
+  };
+  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]);
+
+  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",
+      gst_value_get_fraction_numerator (xcontext->par),
+      gst_value_get_fraction_denominator (xcontext->par));
+}
+
+/* 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 */
+static GstXContext *
+gst_xcompizsink_xcontext_get (GstXCompizSink * xcompizsink)
+{
+  GstXContext *xcontext = NULL;
+  XPixmapFormatValues *px_formats = NULL;
+  gint nb_formats = 0, i;
+
+  g_return_val_if_fail (GST_IS_XCOMPIZSINK (xcompizsink), NULL);
+
+  xcontext = g_new0 (GstXContext, 1);
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  xcontext->disp = XOpenDisplay (xcompizsink->display_name);
+
+  if (!xcontext->disp) {
+    g_mutex_unlock (xcompizsink->x_lock);
+    g_free (xcontext);
+    GST_ELEMENT_ERROR (xcompizsink, RESOURCE, WRITE,
+        ("Could not initialise X output"), ("Could not open display"));
+    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);
+
+  GST_DEBUG_OBJECT (xcompizsink, "X reports %dx%d pixels and %d mm x %d mm",
+      xcontext->width, xcontext->height, xcontext->widthmm, xcontext->heightmm);
+
+  gst_xcompizsink_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_mutex_unlock (xcompizsink->x_lock);
+    g_free (xcontext->par);
+    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;
+
+  /* Search for XShm extension support */
+#ifdef HAVE_XSHM
+  if (XShmQueryExtension (xcontext->disp) &&
+      gst_xcompizsink_check_xshm_calls (xcompizsink, xcontext)) {
+    xcontext->use_xshm = TRUE;
+    GST_DEBUG ("xcompizsink is using XShm extension");
+  } else
+#endif
+  {
+    xcontext->use_xshm = FALSE;
+    GST_DEBUG ("xcompizsink is not using XShm extension");
+  }
+
+  /* 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->visual->red_mask = GUINT32_TO_BE (xcontext->visual->red_mask);
+    xcontext->visual->green_mask = GUINT32_TO_BE (xcontext->visual->green_mask);
+    xcontext->visual->blue_mask = GUINT32_TO_BE (xcontext->visual->blue_mask);
+    if (xcontext->bpp == 24) {
+      xcontext->visual->red_mask >>= 8;
+      xcontext->visual->green_mask >>= 8;
+      xcontext->visual->blue_mask >>= 8;
+    }
+  }
+
+  /* update object's par with calculated one if not set yet */
+  if (!xcompizsink->par) {
+    xcompizsink->par = g_new0 (GValue, 1);
+    gst_value_init_and_copy (xcompizsink->par, xcontext->par);
+    GST_DEBUG_OBJECT (xcompizsink, "set calculated PAR on object's PAR");
+  }
+  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->visual->red_mask,
+      "green_mask", G_TYPE_INT, xcontext->visual->green_mask,
+      "blue_mask", G_TYPE_INT, xcontext->visual->blue_mask,
+      "width", GST_TYPE_INT_RANGE, 1, G_MAXINT,
+      "height", GST_TYPE_INT_RANGE, 1, G_MAXINT,
+      "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
+  if (xcompizsink->par) {
+    int nom, den;
+
+    nom = gst_value_get_fraction_numerator (xcompizsink->par);
+    den = gst_value_get_fraction_denominator (xcompizsink->par);
+    gst_caps_set_simple (xcontext->caps, "pixel-aspect-ratio",
+        GST_TYPE_FRACTION, nom, den, NULL);
+  }
+
+  g_mutex_unlock (xcompizsink->x_lock);
+
+  /* Setup our event listening thread */
+  GST_OBJECT_LOCK (xcompizsink);
+  xcompizsink->running = TRUE;
+  xcompizsink->event_thread = g_thread_create (
+      (GThreadFunc) gst_xcompizsink_event_thread, xcompizsink, TRUE, NULL);
+  GST_OBJECT_UNLOCK (xcompizsink);
+
+  return xcontext;
+}
+
+/* This function cleans the X context. Closing the Display and unrefing the
+   caps for supported formats. */
+static void
+gst_xcompizsink_xcontext_clear (GstXCompizSink * xcompizsink)
+{
+  GstXContext *xcontext;
+
+  g_return_if_fail (GST_IS_XCOMPIZSINK (xcompizsink));
+
+  GST_OBJECT_LOCK (xcompizsink);
+  if (xcompizsink->xcontext == NULL) {
+    GST_OBJECT_UNLOCK (xcompizsink);
+    return;
+  }
+
+  /* Take the xcontext reference and NULL it while we
+   * clean it up, so that any buffer-alloced buffers 
+   * arriving after this will be freed correctly */
+  xcontext = xcompizsink->xcontext;
+  xcompizsink->xcontext = NULL;
+
+  GST_OBJECT_UNLOCK (xcompizsink);
+
+  gst_caps_unref (xcontext->caps);
+  g_free (xcontext->par);
+  g_free (xcompizsink->par);
+  xcompizsink->par = NULL;
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  XCloseDisplay (xcontext->disp);
+
+  g_mutex_unlock (xcompizsink->x_lock);
+
+  g_free (xcontext);
+}
+
+static void
+gst_xcompizsink_bufferpool_clear (GstXCompizSink * xcompizsink)
+{
+
+  g_mutex_lock (xcompizsink->pool_lock);
+
+  while (xcompizsink->buffer_pool) {
+    GstXCompizBuffer *ximage = xcompizsink->buffer_pool->data;
+
+    xcompizsink->buffer_pool = g_slist_delete_link (xcompizsink->buffer_pool,
+        xcompizsink->buffer_pool);
+    gst_ximage_buffer_free (ximage);
+  }
+
+  g_mutex_unlock (xcompizsink->pool_lock);
+}
+
+/* Element stuff */
+
+static GstCaps *
+gst_xcompizsink_getcaps (GstBaseSink * bsink)
+{
+  GstXCompizSink *xcompizsink;
+  GstCaps *caps;
+  int i;
+
+  xcompizsink = GST_XCOMPIZSINK (bsink);
+
+  if (xcompizsink->xcontext)
+    return gst_caps_ref (xcompizsink->xcontext->caps);
+
+  /* get a template copy and add the pixel aspect ratio */
+  caps =
+      gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SINK (xcompizsink)->
+          sinkpad));
+  for (i = 0; i < gst_caps_get_size (caps); ++i) {
+    GstStructure *structure = gst_caps_get_structure (caps, i);
+
+    if (xcompizsink->par) {
+      int nom, den;
+
+      nom = gst_value_get_fraction_numerator (xcompizsink->par);
+      den = gst_value_get_fraction_denominator (xcompizsink->par);
+      gst_structure_set (structure, "pixel-aspect-ratio",
+          GST_TYPE_FRACTION, nom, den, NULL);
+    }
+  }
+
+  return caps;
+}
+
+static gboolean
+gst_xcompizsink_setcaps (GstBaseSink * bsink, GstCaps * caps)
+{
+  GstXCompizSink *xcompizsink;
+  gboolean ret = TRUE;
+  GstStructure *structure;
+  GstCaps *intersection;
+  const GValue *par;
+  gint new_width, new_height;
+  const GValue *fps;
+
+  xcompizsink = GST_XCOMPIZSINK (bsink);
+
+  if (!xcompizsink->xcontext)
+    return FALSE;
+
+  GST_DEBUG_OBJECT (xcompizsink,
+      "sinkconnect possible caps %" GST_PTR_FORMAT " with given caps %"
+      GST_PTR_FORMAT, xcompizsink->xcontext->caps, caps);
+
+  /* We intersect those caps with our template to make sure they are correct */
+  intersection = gst_caps_intersect (xcompizsink->xcontext->caps, caps);
+  GST_DEBUG_OBJECT (xcompizsink, "intersection returned %" GST_PTR_FORMAT,
+      intersection);
+  if (gst_caps_is_empty (intersection)) {
+    gst_caps_unref (intersection);
+    return FALSE;
+  }
+
+  gst_caps_unref (intersection);
+
+  structure = gst_caps_get_structure (caps, 0);
+
+  ret &= gst_structure_get_int (structure, "width", &new_width);
+  ret &= gst_structure_get_int (structure, "height", &new_height);
+  fps = gst_structure_get_value (structure, "framerate");
+  ret &= (fps != NULL);
+  if (!ret)
+    return FALSE;
+
+  /* if the caps contain pixel-aspect-ratio, they have to match ours,
+   * otherwise linking should fail */
+  par = gst_structure_get_value (structure, "pixel-aspect-ratio");
+  if (par) {
+    if (xcompizsink->par) {
+      if (gst_value_compare (par, xcompizsink->par) != GST_VALUE_EQUAL) {
+        goto wrong_aspect;
+      }
+    } else if (xcompizsink->xcontext->par) {
+      if (gst_value_compare (par, xcompizsink->xcontext->par) != GST_VALUE_EQUAL) {
+        goto wrong_aspect;
+      }
+    }
+  }
+
+  GST_VIDEO_SINK_WIDTH (xcompizsink) = new_width;
+  GST_VIDEO_SINK_HEIGHT (xcompizsink) = new_height;
+  xcompizsink->fps_n = gst_value_get_fraction_numerator (fps);
+  xcompizsink->fps_d = gst_value_get_fraction_denominator (fps);
+
+  /* Notify application to set xwindow id now */
+  g_mutex_lock (xcompizsink->flow_lock);
+  if (!xcompizsink->xwindow) {
+    g_mutex_unlock (xcompizsink->flow_lock);
+    gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (xcompizsink));
+  } else {
+    g_mutex_unlock (xcompizsink->flow_lock);
+  }
+
+  /* Creating our window and our image */
+  if (GST_VIDEO_SINK_WIDTH (xcompizsink) <= 0 ||
+      GST_VIDEO_SINK_HEIGHT (xcompizsink) <= 0) {
+    GST_ELEMENT_ERROR (xcompizsink, CORE, NEGOTIATION, (NULL),
+        ("Invalid image size."));
+    return FALSE;
+  }
+
+  g_mutex_lock (xcompizsink->flow_lock);
+  if (!xcompizsink->xwindow) {
+    xcompizsink->xwindow = gst_xcompizsink_xwindow_new (xcompizsink,
+        GST_VIDEO_SINK_WIDTH (xcompizsink), GST_VIDEO_SINK_HEIGHT (xcompizsink));
+  }
+  g_mutex_unlock (xcompizsink->flow_lock);
+
+  /* If our ximage has changed we destroy it, next chain iteration will create
+     a new one */
+  if ((xcompizsink->ximage) &&
+      ((GST_VIDEO_SINK_WIDTH (xcompizsink) != xcompizsink->ximage->width) ||
+          (GST_VIDEO_SINK_HEIGHT (xcompizsink) != xcompizsink->ximage->height))) {
+    GST_DEBUG_OBJECT (xcompizsink, "our image is not usable anymore, unref %p",
+        xcompizsink->ximage);
+    gst_buffer_unref (GST_BUFFER_CAST (xcompizsink->ximage));
+    xcompizsink->ximage = NULL;
+  }
+
+  vo_compiz_init(xcompizsink);
+  return TRUE;
+
+  /* ERRORS */
+wrong_aspect:
+  {
+    GST_INFO_OBJECT (xcompizsink, "pixel aspect ratio does not match");
+    return FALSE;
+  }
+}
+
+static GstStateChangeReturn
+gst_xcompizsink_change_state (GstElement * element, GstStateChange transition)
+{
+  GstXCompizSink *xcompizsink;
+  GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
+  GstXContext *xcontext = NULL;
+
+  xcompizsink = GST_XCOMPIZSINK (element);
+
+  switch (transition) {
+    case GST_STATE_CHANGE_NULL_TO_READY:
+
+      /* Initializing the XContext */
+      if (xcompizsink->xcontext == NULL) {
+        xcontext = gst_xcompizsink_xcontext_get (xcompizsink);
+        if (xcontext == NULL) {
+          ret = GST_STATE_CHANGE_FAILURE;
+          goto beach;
+        }
+        GST_OBJECT_LOCK (xcompizsink);
+        if (xcontext)
+          xcompizsink->xcontext = xcontext;
+        GST_OBJECT_UNLOCK (xcompizsink);
+      }
+
+      /* call XSynchronize with the current value of synchronous */
+      GST_DEBUG_OBJECT (xcompizsink, "XSynchronize called with %s",
+          xcompizsink->synchronous ? "TRUE" : "FALSE");
+      g_mutex_lock (xcompizsink->x_lock);
+      XSynchronize (xcompizsink->xcontext->disp, xcompizsink->synchronous);
+      g_mutex_unlock (xcompizsink->x_lock);
+      break;
+    case GST_STATE_CHANGE_READY_TO_PAUSED:
+      g_mutex_lock (xcompizsink->flow_lock);
+      if (xcompizsink->xwindow)
+        gst_xcompizsink_xwindow_clear (xcompizsink, xcompizsink->xwindow);
+      g_mutex_unlock (xcompizsink->flow_lock);
+      break;
+    case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
+      break;
+    default:
+      break;
+  }
+
+  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+  switch (transition) {
+    case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
+      break;
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+      xcompizsink->fps_n = 0;
+      xcompizsink->fps_d = 1;
+      GST_VIDEO_SINK_WIDTH (xcompizsink) = 0;
+      GST_VIDEO_SINK_HEIGHT (xcompizsink) = 0;
+      break;
+    case GST_STATE_CHANGE_READY_TO_NULL:
+      gst_xcompizsink_reset (xcompizsink);
+      break;
+    default:
+      break;
+  }
+
+beach:
+  return ret;
+}
+
+static void
+gst_xcompizsink_get_times (GstBaseSink * bsink, GstBuffer * buf,
+    GstClockTime * start, GstClockTime * end)
+{
+  GstXCompizSink *xcompizsink;
+
+  xcompizsink = GST_XCOMPIZSINK (bsink);
+
+  if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
+    *start = GST_BUFFER_TIMESTAMP (buf);
+    if (GST_BUFFER_DURATION_IS_VALID (buf)) {
+      *end = *start + GST_BUFFER_DURATION (buf);
+    } else {
+      if (xcompizsink->fps_n > 0) {
+        *end = *start +
+            gst_util_uint64_scale_int (GST_SECOND, xcompizsink->fps_d,
+            xcompizsink->fps_n);
+      }
+    }
+  }
+}
+
+static GstFlowReturn
+gst_xcompizsink_show_frame (GstBaseSink * bsink, GstBuffer * buf)
+{
+  GstXCompizSink *xcompizsink;
+
+  g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
+
+  xcompizsink = GST_XCOMPIZSINK (bsink);
+
+  /* If this buffer has been allocated using our buffer management we simply
+     put the ximage which is in the PRIVATE pointer */
+  if (GST_IS_XCOMPIZ_BUFFER (buf)) {
+    GST_LOG_OBJECT (xcompizsink, "buffer from our pool, writing directly");
+    if (!gst_xcompizsink_ximage_put (xcompizsink, GST_XCOMPIZ_BUFFER (buf)))
+      goto no_window;
+  } else {
+    /* Else we have to copy the data into our private image, */
+    /* if we have one... */
+    GST_LOG_OBJECT (xcompizsink, "normal buffer, copying from it");
+    if (!xcompizsink->ximage) {
+      GST_DEBUG_OBJECT (xcompizsink, "creating our ximage");
+      xcompizsink->ximage = gst_xcompizsink_ximage_new (xcompizsink,
+          GST_BUFFER_CAPS (buf));
+      if (!xcompizsink->ximage)
+        /* The create method should have posted an informative error */
+        goto no_ximage;
+
+      if (xcompizsink->ximage->size < GST_BUFFER_SIZE (buf)) {
+        GST_ELEMENT_ERROR (xcompizsink, RESOURCE, WRITE,
+            ("Failed to create output image buffer of %dx%d pixels",
+                xcompizsink->ximage->width, xcompizsink->ximage->height),
+            ("XServer allocated buffer size did not match input buffer"));
+
+        gst_xcompizsink_ximage_destroy (xcompizsink, xcompizsink->ximage);
+        xcompizsink->ximage = NULL;
+        goto no_ximage;
+      }
+    }
+    memcpy (GST_BUFFER_DATA (xcompizsink->ximage), GST_BUFFER_DATA (buf),
+        MIN (GST_BUFFER_SIZE (buf), xcompizsink->ximage->size));
+    if (!gst_xcompizsink_ximage_put (xcompizsink, xcompizsink->ximage))
+      goto no_window;
+  }
+
+  return GST_FLOW_OK;
+
+  /* ERRORS */
+no_ximage:
+  {
+    /* No image available. That's very bad ! */
+    GST_DEBUG ("could not create image");
+    return GST_FLOW_ERROR;
+  }
+no_window:
+  {
+    /* No Window available to put our image into */
+    GST_WARNING_OBJECT (xcompizsink, "could not output image - no window");
+    return GST_FLOW_ERROR;
+  }
+}
+
+/* Buffer management
+ *
+ * The buffer_alloc function must either return a buffer with given size and
+ * caps or create a buffer with different caps attached to the buffer. This
+ * last option is called reverse negotiation, ie, where the sink suggests a
+ * different format from the upstream peer. 
+ *
+ * We try to do reverse negotiation when our geometry changes and we like a
+ * resized buffer.
+ */
+static GstFlowReturn
+gst_xcompizsink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
+    GstCaps * caps, GstBuffer ** buf)
+{
+  GstXCompizSink *xcompizsink;
+  GstXCompizBuffer *ximage = NULL;
+  GstStructure *structure = NULL;
+  GstFlowReturn ret = GST_FLOW_OK;
+  GstCaps *alloc_caps;
+  gboolean alloc_unref = FALSE;
+  gint width, height;
+
+  xcompizsink = GST_XCOMPIZSINK (bsink);
+
+  GST_LOG_OBJECT (xcompizsink,
+      "a buffer of %d bytes was requested with caps %" GST_PTR_FORMAT
+      " and offset %" G_GUINT64_FORMAT, size, caps, offset);
+
+  /* assume we're going to alloc what was requested, keep track of
+   * wheter we need to unref or not. When we suggest a new format 
+   * upstream we will create a new caps that we need to unref. */
+  alloc_caps = caps;
+  alloc_unref = FALSE;
+
+  /* get struct to see what is requested */
+  structure = gst_caps_get_structure (caps, 0);
+
+  if (gst_structure_get_int (structure, "width", &width) &&
+      gst_structure_get_int (structure, "height", &height)) {
+    GstVideoRectangle dst, src, result;
+
+    src.w = width;
+    src.h = height;
+
+    /* We take the flow_lock because the window might go away */
+    g_mutex_lock (xcompizsink->flow_lock);
+    if (!xcompizsink->xwindow) {
+      g_mutex_unlock (xcompizsink->flow_lock);
+      goto alloc;
+    }
+
+    /* What is our geometry */
+    gst_xcompizsink_xwindow_update_geometry (xcompizsink, xcompizsink->xwindow);
+    dst.w = xcompizsink->xwindow->width;
+    dst.h = xcompizsink->xwindow->height;
+
+    g_mutex_unlock (xcompizsink->flow_lock);
+
+    if (xcompizsink->keep_aspect) {
+      GST_LOG_OBJECT (xcompizsink, "enforcing aspect ratio in reverse caps "
+          "negotiation");
+      gst_video_sink_center_rect (src, dst, &result, TRUE);
+    } else {
+      GST_LOG_OBJECT (xcompizsink, "trying to resize to window geometry "
+          "ignoring aspect ratio");
+      result.x = result.y = 0;
+      result.w = dst.w;
+      result.h = dst.h;
+    }
+
+    /* We would like another geometry */
+    if (FALSE && (width != result.w || height != result.h)) {
+      int nom, den;
+      GstCaps *desired_caps;
+      GstStructure *desired_struct;
+
+      /* make a copy of the incomming caps to create the new
+       * suggestion. We can't use make_writable because we might
+       * then destroy the original caps which we still need when the
+       * peer does not accept the suggestion. */
+      desired_caps = gst_caps_copy (caps);
+      desired_struct = gst_caps_get_structure (desired_caps, 0);
+
+      GST_DEBUG ("we would love to receive a %dx%d video", result.w, result.h);
+      //gst_structure_set (desired_struct, "width", G_TYPE_INT, result.w, NULL);
+      //gst_structure_set (desired_struct, "height", G_TYPE_INT, result.h, NULL);
+
+      /* PAR property overrides the X calculated one */
+      if (xcompizsink->par) {
+        nom = gst_value_get_fraction_numerator (xcompizsink->par);
+        den = gst_value_get_fraction_denominator (xcompizsink->par);
+        gst_structure_set (desired_struct, "pixel-aspect-ratio",
+            GST_TYPE_FRACTION, nom, den, NULL);
+      } else if (xcompizsink->xcontext->par) {
+        nom = gst_value_get_fraction_numerator (xcompizsink->xcontext->par);
+        den = gst_value_get_fraction_denominator (xcompizsink->xcontext->par);
+        gst_structure_set (desired_struct, "pixel-aspect-ratio",
+            GST_TYPE_FRACTION, nom, den, NULL);
+      }
+
+      /* see if peer accepts our new suggestion, if there is no peer, this 
+       * function returns true. */
+      if (gst_pad_peer_accept_caps (GST_VIDEO_SINK_PAD (xcompizsink),
+              desired_caps)) {
+        gint bpp;
+
+        bpp = size / height / width;
+        /* we will not alloc a buffer of the new suggested caps. Make sure
+         * we also unref this new caps after we set it on the buffer. */
+        alloc_caps = desired_caps;
+        alloc_unref = TRUE;
+        width = result.w;
+        height = result.h;
+        size = bpp * width * height;
+        GST_DEBUG ("peer pad accepts our desired caps %" GST_PTR_FORMAT
+            " buffer size is now %d bytes", desired_caps, size);
+      } else {
+        GST_DEBUG ("peer pad does not accept our desired caps %" GST_PTR_FORMAT,
+            desired_caps);
+        /* we alloc a buffer with the original incomming caps */
+        width = GST_VIDEO_SINK_WIDTH (xcompizsink);
+        height = GST_VIDEO_SINK_HEIGHT (xcompizsink);
+      }
+    }
+  }
+
+alloc:
+  /* Inspect our buffer pool */
+  g_mutex_lock (xcompizsink->pool_lock);
+  while (xcompizsink->buffer_pool) {
+    ximage = (GstXCompizBuffer *) xcompizsink->buffer_pool->data;
+
+    if (ximage) {
+      /* Removing from the pool */
+      xcompizsink->buffer_pool = g_slist_delete_link (xcompizsink->buffer_pool,
+          xcompizsink->buffer_pool);
+
+      /* If the ximage is invalid for our need, destroy */
+      if ((ximage->width != width) || (ximage->height != height)) {
+        gst_ximage_buffer_free (ximage);
+        ximage = NULL;
+      } else {
+        /* We found a suitable ximage */
+        break;
+      }
+    }
+  }
+  g_mutex_unlock (xcompizsink->pool_lock);
+
+  /* We haven't found anything, creating a new one */
+  if (!ximage) {
+    ximage = gst_xcompizsink_ximage_new (xcompizsink, alloc_caps);
+  }
+  /* Now we should have a ximage, set appropriate caps on it */
+  if (ximage) {
+    gst_buffer_set_caps (GST_BUFFER_CAST (ximage), alloc_caps);
+  }
+
+  /* could be our new reffed suggestion or the original unreffed caps */
+  if (alloc_unref)
+    gst_caps_unref (alloc_caps);
+
+  *buf = GST_BUFFER_CAST (ximage);
+
+  return ret;
+}
+
+/* Interfaces stuff */
+
+static gboolean
+gst_xcompizsink_interface_supported (GstImplementsInterface * iface, GType type)
+{
+  g_assert (type == GST_TYPE_NAVIGATION || type == GST_TYPE_X_OVERLAY);
+  return TRUE;
+}
+
+static void
+gst_xcompizsink_interface_init (GstImplementsInterfaceClass * klass)
+{
+  klass->supported = gst_xcompizsink_interface_supported;
+}
+
+static void
+gst_xcompizsink_navigation_send_event (GstNavigation * navigation,
+    GstStructure * structure)
+{
+  GstXCompizSink *xcompizsink = GST_XCOMPIZSINK (navigation);
+  GstEvent *event;
+  gint x_offset, y_offset;
+  gdouble x, y;
+  GstPad *pad = NULL;
+
+  event = gst_event_new_navigation (structure);
+
+  /* We are not converting the pointer coordinates as there's no hardware
+     scaling done here. The only possible scaling is done by videoscale and
+     videoscale will have to catch those events and tranform the coordinates
+     to match the applied scaling. So here we just add the offset if the image
+     is centered in the window.  */
+
+  /* We take the flow_lock while we look at the window */
+  g_mutex_lock (xcompizsink->flow_lock);
+
+  if (!xcompizsink->xwindow) {
+    g_mutex_unlock (xcompizsink->flow_lock);
+    return;
+  }
+
+  x_offset = xcompizsink->xwindow->width - GST_VIDEO_SINK_WIDTH (xcompizsink);
+  y_offset = xcompizsink->xwindow->height - GST_VIDEO_SINK_HEIGHT (xcompizsink);
+
+  g_mutex_unlock (xcompizsink->flow_lock);
+
+  if (gst_structure_get_double (structure, "pointer_x", &x)) {
+    x -= x_offset / 2;
+    gst_structure_set (structure, "pointer_x", G_TYPE_DOUBLE, x, NULL);
+  }
+  if (gst_structure_get_double (structure, "pointer_y", &y)) {
+    y -= y_offset / 2;
+    gst_structure_set (structure, "pointer_y", G_TYPE_DOUBLE, y, NULL);
+  }
+
+  pad = gst_pad_get_peer (GST_VIDEO_SINK_PAD (xcompizsink));
+
+  if (GST_IS_PAD (pad) && GST_IS_EVENT (event)) {
+    gst_pad_send_event (pad, event);
+
+    gst_object_unref (pad);
+  }
+}
+
+static void
+gst_xcompizsink_navigation_init (GstNavigationInterface * iface)
+{
+  iface->send_event = gst_xcompizsink_navigation_send_event;
+}
+
+static void
+gst_xcompizsink_set_xwindow_id (GstXOverlay * overlay, XID xwindow_id)
+{
+
+	GST_DEBUG("Set xid: %p",xwindow_id);	
+  GstXCompizSink *xcompizsink = GST_XCOMPIZSINK (overlay);
+  GstXWindow *xwindow = NULL;
+  XWindowAttributes attr;
+
+	//xwindow_id=0;
+
+  /* We acquire the stream lock while setting this window in the element.
+     We are basically cleaning tons of stuff replacing the old window, putting
+     images while we do that would surely crash */
+  g_mutex_lock (xcompizsink->flow_lock);
+
+  /* If we already use that window return */
+  if (xcompizsink->xwindow && (xwindow_id == xcompizsink->xwindow->win)) {
+	GST_DEBUG("xid already set");
+	xcompizsink->xwindow->xprop = 0;	
+    g_mutex_unlock (xcompizsink->flow_lock);
+    return;
+  }
+
+  /* If the element has not initialized the X11 context try to do so */
+  if (!xcompizsink->xcontext &&
+      !(xcompizsink->xcontext = gst_xcompizsink_xcontext_get (xcompizsink))) {
+    g_mutex_unlock (xcompizsink->flow_lock);
+    /* we have thrown a GST_ELEMENT_ERROR now */
+    return;
+  }
+
+  /* If a window is there already we destroy it */
+  if (xcompizsink->xwindow) {
+    gst_xcompizsink_xwindow_destroy (xcompizsink, xcompizsink->xwindow);
+    xcompizsink->xwindow = NULL;
+    //g_mutex_unlock (xcompizsink->flow_lock);
+    //return;
+  }
+
+  /* If the xid is 0 we go back to an internal window */
+  if (xwindow_id == 0) {
+    /* If no width/height caps nego did not happen window will be created
+       during caps nego then */
+       
+    if (GST_VIDEO_SINK_WIDTH (xcompizsink) && GST_VIDEO_SINK_HEIGHT (xcompizsink)) {
+      xwindow = gst_xcompizsink_xwindow_new (xcompizsink,
+          GST_VIDEO_SINK_WIDTH (xcompizsink),
+          GST_VIDEO_SINK_HEIGHT (xcompizsink));
+    }
+  } else {
+    xwindow = g_new0 (GstXWindow, 1);
+
+	GST_DEBUG_OBJECT(xcompizsink,"Set xprop.");	
+    xwindow->win = xwindow_id;
+    xwindow->xprop=0;
+
+    /* We get window geometry, set the event we want to receive,
+       and create a GC */
+    g_mutex_lock (xcompizsink->x_lock);
+    XGetWindowAttributes (xcompizsink->xcontext->disp, xwindow->win, &attr);
+    xwindow->width = attr.width;
+    xwindow->height = attr.height;
+    xwindow->internal = FALSE;
+    if (xcompizsink->handle_events) {
+      XSelectInput (xcompizsink->xcontext->disp, xwindow->win, ExposureMask |
+          StructureNotifyMask | PointerMotionMask | KeyPressMask |
+          KeyReleaseMask | PropertyChangeMask);
+    }
+
+    xwindow->gc = XCreateGC (xcompizsink->xcontext->disp, xwindow->win, 0, NULL);
+    
+    g_mutex_unlock (xcompizsink->x_lock);
+  }
+
+  if (xwindow)
+    xcompizsink->xwindow = xwindow;
+
+  g_mutex_unlock (xcompizsink->flow_lock);
+}
+
+static void
+gst_xcompizsink_expose (GstXOverlay * overlay)
+{
+  GstXCompizSink *xcompizsink = GST_XCOMPIZSINK (overlay);
+
+  gst_xcompizsink_ximage_put (xcompizsink, NULL);
+}
+
+static void
+gst_xcompizsink_set_event_handling (GstXOverlay * overlay,
+    gboolean handle_events)
+{
+  GstXCompizSink *xcompizsink = GST_XCOMPIZSINK (overlay);
+
+  xcompizsink->handle_events = handle_events;
+
+  g_mutex_lock (xcompizsink->flow_lock);
+
+  if (G_UNLIKELY (!xcompizsink->xwindow)) {
+    g_mutex_unlock (xcompizsink->flow_lock);
+    return;
+  }
+
+  g_mutex_lock (xcompizsink->x_lock);
+
+  if (handle_events) {
+    if (xcompizsink->xwindow->internal) {
+      XSelectInput (xcompizsink->xcontext->disp, xcompizsink->xwindow->win,
+          ExposureMask | StructureNotifyMask | PointerMotionMask |
+          KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PropertyChangeMask);
+    } else {
+      XSelectInput (xcompizsink->xcontext->disp, xcompizsink->xwindow->win,
+          ExposureMask | StructureNotifyMask | PointerMotionMask |
+          KeyPressMask | KeyReleaseMask | PropertyChangeMask);
+    }
+  } else {
+    XSelectInput (xcompizsink->xcontext->disp, xcompizsink->xwindow->win, 0);
+  }
+
+  g_mutex_unlock (xcompizsink->x_lock);
+
+  g_mutex_unlock (xcompizsink->flow_lock);
+}
+
+static void
+gst_xcompizsink_xoverlay_init (GstXOverlayClass * iface)
+{
+  iface->set_xwindow_id = gst_xcompizsink_set_xwindow_id;
+  iface->expose = gst_xcompizsink_expose;
+  iface->handle_events = gst_xcompizsink_set_event_handling;
+}
+
+/* =========================================== */
+/*                                             */
+/*              Init & Class init              */
+/*                                             */
+/* =========================================== */
+
+static void
+gst_xcompizsink_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstXCompizSink *xcompizsink;
+
+  g_return_if_fail (GST_IS_XCOMPIZSINK (object));
+
+  xcompizsink = GST_XCOMPIZSINK (object);
+
+  switch (prop_id) {
+    case PROP_DISPLAY:
+      xcompizsink->display_name = g_strdup (g_value_get_string (value));
+      break;
+    case PROP_SYNCHRONOUS:
+      xcompizsink->synchronous = g_value_get_boolean (value);
+      if (xcompizsink->xcontext) {
+        GST_DEBUG_OBJECT (xcompizsink, "XSynchronize called with %s",
+            xcompizsink->synchronous ? "TRUE" : "FALSE");
+        g_mutex_lock (xcompizsink->x_lock);
+        XSynchronize (xcompizsink->xcontext->disp, xcompizsink->synchronous);
+        g_mutex_unlock (xcompizsink->x_lock);
+      }
+      break;
+    case PROP_FORCE_ASPECT_RATIO:
+      xcompizsink->keep_aspect = g_value_get_boolean (value);
+      break;
+    case PROP_PIXEL_ASPECT_RATIO:
+    {
+      GValue *tmp;
+
+      tmp = g_new0 (GValue, 1);
+      g_value_init (tmp, GST_TYPE_FRACTION);
+
+      if (!g_value_transform (value, tmp)) {
+        GST_WARNING_OBJECT (xcompizsink,
+            "Could not transform string to aspect ratio");
+        g_free (tmp);
+      } else {
+        GST_DEBUG_OBJECT (xcompizsink, "set PAR to %d/%d",
+            gst_value_get_fraction_numerator (tmp),
+            gst_value_get_fraction_denominator (tmp));
+        g_free (xcompizsink->par);
+        xcompizsink->par = tmp;
+      }
+    }
+      break;
+    case PROP_HANDLE_EVENTS:
+      gst_xcompizsink_set_event_handling (GST_X_OVERLAY (xcompizsink),
+          g_value_get_boolean (value));
+      break;
+    case PROP_HANDLE_EXPOSE:
+      xcompizsink->handle_expose = g_value_get_boolean (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_xcompizsink_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstXCompizSink *xcompizsink;
+
+  g_return_if_fail (GST_IS_XCOMPIZSINK (object));
+
+  xcompizsink = GST_XCOMPIZSINK (object);
+
+  switch (prop_id) {
+    case PROP_DISPLAY:
+      g_value_set_string (value, xcompizsink->display_name);
+      break;
+    case PROP_SYNCHRONOUS:
+      g_value_set_boolean (value, xcompizsink->synchronous);
+      break;
+    case PROP_FORCE_ASPECT_RATIO:
+      g_value_set_boolean (value, xcompizsink->keep_aspect);
+      break;
+    case PROP_PIXEL_ASPECT_RATIO:
+      if (xcompizsink->par)
+        g_value_transform (xcompizsink->par, value);
+      break;
+    case PROP_HANDLE_EVENTS:
+      g_value_set_boolean (value, xcompizsink->handle_events);
+      break;
+    case PROP_HANDLE_EXPOSE:
+      g_value_set_boolean (value, xcompizsink->handle_expose);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_xcompizsink_reset (GstXCompizSink * xcompizsink)
+{
+  GThread *thread;
+
+  GST_OBJECT_LOCK (xcompizsink);
+  xcompizsink->running = FALSE;
+  /* grab thread and mark it as NULL */
+  thread = xcompizsink->event_thread;
+  xcompizsink->event_thread = NULL;
+  GST_OBJECT_UNLOCK (xcompizsink);
+
+  /* Wait for our event thread to finish before we clean up our stuff. */
+  if (thread)
+    g_thread_join (thread);
+
+  if (xcompizsink->ximage) {
+    gst_buffer_unref (xcompizsink->ximage);
+    xcompizsink->ximage = NULL;
+  }
+  if (xcompizsink->cur_image) {
+    gst_buffer_unref (xcompizsink->cur_image);
+    xcompizsink->cur_image = NULL;
+  }
+
+  gst_xcompizsink_bufferpool_clear (xcompizsink);
+
+  g_mutex_lock (xcompizsink->flow_lock);
+  if (xcompizsink->xwindow) {
+    gst_xcompizsink_xwindow_clear (xcompizsink, xcompizsink->xwindow);
+    gst_xcompizsink_xwindow_destroy (xcompizsink, xcompizsink->xwindow);
+    xcompizsink->xwindow = NULL;
+  }
+  g_mutex_unlock (xcompizsink->flow_lock);
+
+  gst_xcompizsink_xcontext_clear (xcompizsink);
+}
+
+static void
+gst_xcompizsink_finalize (GObject * object)
+{
+  GstXCompizSink *xcompizsink;
+
+  xcompizsink = GST_XCOMPIZSINK (object);
+
+  gst_xcompizsink_reset (xcompizsink);
+
+  if (xcompizsink->display_name) {
+    g_free (xcompizsink->display_name);
+    xcompizsink->display_name = NULL;
+  }
+  if (xcompizsink->par) {
+    g_free (xcompizsink->par);
+    xcompizsink->par = NULL;
+  }
+  if (xcompizsink->x_lock) {
+    g_mutex_free (xcompizsink->x_lock);
+    xcompizsink->x_lock = NULL;
+  }
+  if (xcompizsink->flow_lock) {
+    g_mutex_free (xcompizsink->flow_lock);
+    xcompizsink->flow_lock = NULL;
+  }
+  if (xcompizsink->pool_lock) {
+    g_mutex_free (xcompizsink->pool_lock);
+    xcompizsink->pool_lock = NULL;
+  }
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gst_xcompizsink_init (GstXCompizSink * xcompizsink)
+{
+  xcompizsink->display_name = NULL;
+  xcompizsink->xcontext = NULL;
+  xcompizsink->xwindow = NULL;
+  xcompizsink->ximage = NULL;
+  xcompizsink->cur_image = NULL;
+
+  xcompizsink->event_thread = NULL;
+  xcompizsink->running = FALSE;
+
+  xcompizsink->fps_n = 0;
+  xcompizsink->fps_d = 1;
+
+  xcompizsink->x_lock = g_mutex_new ();
+  xcompizsink->flow_lock = g_mutex_new ();
+
+  xcompizsink->par = NULL;
+
+  xcompizsink->pool_lock = g_mutex_new ();
+  xcompizsink->buffer_pool = NULL;
+  
+  xcompizsink->compiz_inited = FALSE;
+  xcompizsink->synchronous = FALSE;
+  xcompizsink->keep_aspect = FALSE;
+  xcompizsink->handle_events = TRUE;
+  xcompizsink->handle_expose = TRUE;
+}
+
+static void
+gst_xcompizsink_base_init (gpointer g_class)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+
+  gst_element_class_set_details (element_class, &gst_xcompizsink_details);
+
+  gst_element_class_add_pad_template (element_class,
+      gst_static_pad_template_get (&gst_xcompizsink_sink_template_factory));
+}
+
+static void
+gst_xcompizsink_class_init (GstXCompizSinkClass * klass)
+{
+  GObjectClass *gobject_class;
+  GstElementClass *gstelement_class;
+  GstBaseSinkClass *gstbasesink_class;
+
+  gobject_class = (GObjectClass *) klass;
+  gstelement_class = (GstElementClass *) klass;
+  gstbasesink_class = (GstBaseSinkClass *) klass;
+
+  parent_class = g_type_class_peek_parent (klass);
+
+  gobject_class->finalize = gst_xcompizsink_finalize;
+  gobject_class->set_property = gst_xcompizsink_set_property;
+  gobject_class->get_property = gst_xcompizsink_get_property;
+
+  g_object_class_install_property (gobject_class, PROP_DISPLAY,
+      g_param_spec_string ("display", "Display", "X Display name",
+          NULL, G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_SYNCHRONOUS,
+      g_param_spec_boolean ("synchronous", "Synchronous", "When enabled, runs "
+          "the X display in synchronous mode. (used only for debugging)", FALSE,
+          G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_FORCE_ASPECT_RATIO,
+      g_param_spec_boolean ("force-aspect-ratio", "Force aspect ratio",
+          "When enabled, reverse caps negotiation (scaling) will respect "
+          "original aspect ratio", FALSE, G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_PIXEL_ASPECT_RATIO,
+      g_param_spec_string ("pixel-aspect-ratio", "Pixel Aspect Ratio",
+          "The pixel aspect ratio of the device", "1/1", G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_HANDLE_EVENTS,
+      g_param_spec_boolean ("handle-events", "Handle XEvents",
+          "When enabled, XEvents will be selected and handled", TRUE,
+          G_PARAM_READWRITE));
+  g_object_class_install_property (gobject_class, PROP_HANDLE_EXPOSE,
+      g_param_spec_boolean ("handle-expose", "Handle expose", "When enabled, "
+          "the current frame will always be drawn in response to X Expose "
+          "events", TRUE, G_PARAM_READWRITE));
+
+  gstelement_class->change_state = gst_xcompizsink_change_state;
+
+  gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_xcompizsink_getcaps);
+  gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_xcompizsink_setcaps);
+  gstbasesink_class->buffer_alloc =
+      GST_DEBUG_FUNCPTR (gst_xcompizsink_buffer_alloc);
+  gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_xcompizsink_get_times);
+  gstbasesink_class->preroll = GST_DEBUG_FUNCPTR (gst_xcompizsink_show_frame);
+  gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_xcompizsink_show_frame);
+}
+
+/* ============================================================= */
+/*                                                               */
+/*                       Public Methods                          */
+/*                                                               */
+/* ============================================================= */
+
+/* =========================================== */
+/*                                             */
+/*          Object typing & Creation           */
+/*                                             */
+/* =========================================== */
+
+GType
+gst_xcompizsink_get_type (void)
+{
+  static GType xcompizsink_type = 0;
+
+  if (!xcompizsink_type) {
+    static const GTypeInfo xcompizsink_info = {
+      sizeof (GstXCompizSinkClass),
+      gst_xcompizsink_base_init,
+      NULL,
+      (GClassInitFunc) gst_xcompizsink_class_init,
+      NULL,
+      NULL,
+      sizeof (GstXCompizSink),
+      0,
+      (GInstanceInitFunc) gst_xcompizsink_init,
+    };
+    static const GInterfaceInfo iface_info = {
+      (GInterfaceInitFunc) gst_xcompizsink_interface_init,
+      NULL,
+      NULL,
+    };
+    static const GInterfaceInfo navigation_info = {
+      (GInterfaceInitFunc) gst_xcompizsink_navigation_init,
+      NULL,
+      NULL,
+    };
+    static const GInterfaceInfo overlay_info = {
+      (GInterfaceInitFunc) gst_xcompizsink_xoverlay_init,
+      NULL,
+      NULL,
+    };
+    
+    //GInterfaceInfo *aff = (GInterfaceInfo *)&overlay_info;
+    //aff = NULL;
+
+    xcompizsink_type = g_type_register_static (GST_TYPE_VIDEO_SINK,
+        "GstXCompizSink", &xcompizsink_info, 0);
+
+    g_type_add_interface_static (xcompizsink_type, GST_TYPE_IMPLEMENTS_INTERFACE,
+        &iface_info);
+    g_type_add_interface_static (xcompizsink_type, GST_TYPE_NAVIGATION,
+        &navigation_info);
+    g_type_add_interface_static (xcompizsink_type, GST_TYPE_X_OVERLAY,
+        &overlay_info);
+
+    /* register type and create class in a more safe place instead of at
+     * runtime since the type registration and class creation is not
+     * threadsafe. */
+    g_type_class_ref (gst_ximage_buffer_get_type ());
+  }
+
+  return xcompizsink_type;
+}
diff -Naur gst-plugins-base.clean/sys/xcompiz/xcompizsink.h gst-plugins-base/sys/xcompiz/xcompizsink.h
--- gst-plugins-base.clean/sys/xcompiz/xcompizsink.h	1970-01-01 03:00:00.000000000 +0300
+++ gst-plugins-base/sys/xcompiz/xcompizsink.h	2008-02-26 11:52:27.000000000 +0200
@@ -0,0 +1,246 @@
+/* GStreamer
+ * Copyright (C) <2005> Julien Moutte <julien@moutte.net>
+ *
+ * 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_XCOMPIZSINK_H__
+#define __GST_XCOMPIZSINK_H__
+
+#include <gst/video/gstvideosink.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>
+#include <X11/Xatom.h>
+
+#ifdef HAVE_XSHM
+#include <X11/extensions/XShm.h>
+#endif /* HAVE_XSHM */
+
+#include <string.h>
+#include <math.h>
+
+G_BEGIN_DECLS
+
+#define GRAVITY_WEST  (1 << 0)
+#define GRAVITY_EAST  (1 << 1)
+#define GRAVITY_NORTH (1 << 2)
+#define GRAVITY_SOUTH (1 << 3)
+
+#define COMPIZ_IMAGE_FORMAT_RGB  (1 << 0)
+#define COMPIZ_IMAGE_FORMAT_YV12 (1 << 1)
+
+#define GST_TYPE_XCOMPIZSINK \
+  (gst_xcompizsink_get_type())
+#define GST_XCOMPIZSINK(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_XCOMPIZSINK, GstXCompizSink))
+#define GST_XCOMPIZSINK_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_XCOMPIZSINK, GstXCompizSinkClass))
+#define GST_IS_XCOMPIZSINK(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XCOMPIZSINK))
+#define GST_IS_XCOMPIZSINK_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XCOMPIZSINK))
+
+typedef struct _GstXContext GstXContext;
+typedef struct _GstXWindow GstXWindow;
+
+typedef struct _GstXCompizBuffer GstXCompizBuffer;
+typedef struct _GstXCompizBufferClass GstXCompizBufferClass;
+
+typedef struct _GstXCompizSink GstXCompizSink;
+typedef struct _GstXCompizSinkClass GstXCompizSinkClass;
+
+
+/**
+ * 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;
+  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;
+  int xprop;
+};
+
+/**
+ * GstXCompizBuffer:
+ * @ximagesink: a reference to our #GstXImageSink
+ * @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 _GstXCompizBuffer {
+  GstBuffer buffer;
+
+  /* Reference to the ximagesink we belong to */
+  GstXCompizSink *xcompizsink;
+
+  XImage *ximage;
+  Pixmap pixmap;
+  GC pixmap_gc;
+  
+
+#ifdef HAVE_XSHM
+  XShmSegmentInfo SHMInfo;
+#endif /* HAVE_XSHM */
+
+  gint width, height,im_format;
+  size_t size;
+};
+
+/**
+ * GstXImageSink:
+ * @display_name: the name of the Display we want to render to
+ * @xcontext: our instance's #GstXContext
+ * @xwindow: the #GstXWindow we are rendering to
+ * @ximage: internal #GstXImage used to store incoming buffers and render when
+ * not using the buffer_alloc optimization mechanism
+ * @cur_image: a reference to the last #GstXImage that was put to @xwindow. It
+ * is used when Expose events are received to redraw the latest video frame
+ * @event_thread: a thread listening for events on @xwindow and handling them
+ * @running: used to inform @event_thread if it should run/shutdown
+ * @fps_n: the framerate fraction numerator
+ * @fps_d: the framerate fraction denominator
+ * @x_lock: used to protect X calls as we are not using the XLib in threaded
+ * mode
+ * @flow_lock: used to protect data flow routines from external calls such as
+ * events from @event_thread or methods from the #GstXOverlay interface
+ * @par: used to override calculated pixel aspect ratio from @xcontext
+ * @pool_lock: used to protect the buffer pool
+ * @buffer_pool: a list of #GstXCompizBuffer that could be reused at next buffer
+ * allocation call
+ * @synchronous: used to store if XSynchronous should be used or not (for 
+ * debugging purpose only)
+ * @keep_aspect: used to remember if reverse negotiation scaling should respect
+ * aspect ratio
+ * @handle_events: used to know if we should handle select XEvents or not
+ *
+ * The #GstXImageSink data structure.
+ */
+struct _GstXCompizSink {
+  /* Our element stuff */
+  GstVideoSink videosink;
+
+  char *display_name;
+
+  GstXContext *xcontext;
+  GstXWindow *xwindow;
+  GstXCompizBuffer *ximage;
+  GstXCompizBuffer *cur_image;
+  
+  GThread *event_thread;
+  gboolean running;
+
+  /* Framerate numerator and denominator */
+  gint fps_n;
+  gint fps_d;
+
+  GMutex *x_lock;
+  GMutex *flow_lock;
+  
+  #ifdef HAVE_YV12
+  FOURCC im_format;
+  #endif
+  
+  /* object-set pixel aspect ratio */
+  GValue *par;
+
+  GMutex *pool_lock;
+  GSList *buffer_pool;
+
+  gboolean compiz_inited;
+  gboolean synchronous;
+  gboolean keep_aspect;
+  gboolean handle_events;
+  gboolean handle_expose;
+};
+
+struct _GstXCompizSinkClass {
+  GstVideoSinkClass parent_class;
+};
+
+GType gst_xcompizsink_get_type(void);
+
+G_END_DECLS
+
+#endif /* __GST_XIMAGESINK_H__ */
