summaryrefslogtreecommitdiffstats
path: root/gst
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2009-06-12 14:59:28 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-06-19 11:03:13 +0200
commit0a684a3d04df59a64bb674882fac58b7467eeffb (patch)
treebd5ac288f15d7a4c97d1d44937dc0464365b153c /gst
parentd45e804d5a185291f7ca389bea2badd8569eb323 (diff)
downloadgst-plugins-bad-0a684a3d04df59a64bb674882fac58b7467eeffb.tar.gz
gst-plugins-bad-0a684a3d04df59a64bb674882fac58b7467eeffb.tar.bz2
gst-plugins-bad-0a684a3d04df59a64bb674882fac58b7467eeffb.zip
frei0r: First version of a frei0r wrapper plugin
Currently this only supports frei0r filters.
Diffstat (limited to 'gst')
-rw-r--r--gst/frei0r/Makefile.am13
-rw-r--r--gst/frei0r/frei0r.h567
-rw-r--r--gst/frei0r/gstfrei0r.c546
-rw-r--r--gst/frei0r/gstfrei0r.h91
-rw-r--r--gst/frei0r/gstfrei0rfilter.c255
-rw-r--r--gst/frei0r/gstfrei0rfilter.h63
6 files changed, 1535 insertions, 0 deletions
diff --git a/gst/frei0r/Makefile.am b/gst/frei0r/Makefile.am
new file mode 100644
index 00000000..be951cb1
--- /dev/null
+++ b/gst/frei0r/Makefile.am
@@ -0,0 +1,13 @@
+plugin_LTLIBRARIES = libgstfrei0r.la
+
+libgstfrei0r_la_SOURCES = \
+ gstfrei0r.c \
+ gstfrei0rfilter.c
+
+libgstfrei0r_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
+libgstfrei0r_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) \
+ -lgstvideo-@GST_MAJORMINOR@
+libgstfrei0r_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
+libgstfrei0r_la_LIBTOOLFLAGS = --tag=disable-static
+
+noinst_HEADERS = gstfrei0r.h gstfrei0rfilter.h frei0r.h
diff --git a/gst/frei0r/frei0r.h b/gst/frei0r/frei0r.h
new file mode 100644
index 00000000..f6b81d2b
--- /dev/null
+++ b/gst/frei0r/frei0r.h
@@ -0,0 +1,567 @@
+/** @mainpage frei0r - a minimalistic plugin API for video effects
+ *
+ * @section sec_intro Introduction
+ *
+ * This is frei0r - a minimalistic plugin API for video effects.
+ *
+ * The main emphasis is on simplicity - there are many different applications
+ * that use video effects, and they all have different requirements regarding
+ * their internal plugin API. And that's why frei0r does not try to be a
+ * one-in-all general video plugin API, but instead an API for the most
+ * common video effects: simple filters, sources and mixers that can be
+ * controlled by parameters.
+ *
+ * It's our hope that this way these simple effects can be shared between
+ * many applications, avoiding their reimplementation by different
+ * projects.
+ *
+ * On the other hand, this is not meant as a competing standard to
+ * more ambitious efforts that try to satisfy the needs of many different
+ * applications and more complex effects.
+ *
+ *
+ * @section sec_overview Overview
+ *
+ * If you are new to frei0r, the best thing is probably to have
+ * a look at the <a href="frei0r_8h-source.html">frei0r header</a>,
+ * which is quite simple.
+ *
+ * After that, you might want to look at the
+ * <a href="frei0r_8h.html">frei0r functions</a> in more detail.
+ *
+ * When developing a new frei0r effect, you have to choose
+ * - which effect type to use (\ref PLUGIN_TYPE),
+ * - which color model to use (\ref COLOR_MODEL), and
+ * - which parameter types (\ref PARAM_TYPE) your effect will support.
+ *
+ * To round things up, you should decide whether your effect should have
+ * an associated icon (\ref icons), and where it will be installed
+ * (\ref pluglocations).
+ *
+ * @section sec_changes Changes
+ *
+ * @subsection sec_changes_1_0_1_1 From frei0r 1.0 to frei0r 1.1
+ *
+ * - added specifications for plugin locations
+ * - added specifications for frei0r icons
+ * - added RGBA8888 color model
+ * - added packed32 color model
+ * - added better specification of color models
+ * - added string type
+ * - added bounds to resolution (8 <= width, height <= 2048)
+ * - width and height must be an integer multiple of 8
+ * - frame data must be 16 byte aligned
+ * - improved update specification (must not change parameters,
+ * must restore fpu state)
+ * - added note for applications to ignore effects with unknown fields
+ * - added new plugin types mixer2 and mixer3
+ * - added section about \ref concurrency
+ */
+
+
+/**
+ * \addtogroup pluglocations Plugin Locations
+ * @section sec_pluglocations Plugin Locations
+ *
+ * For Unix platforms there are rules for the location of frei0r plugins.
+ *
+ * frei0r 1.x plugin files should be located in
+ *
+ * - (1) /usr/lib/frei0r-1/\<vendor\>
+ * - (2) /usr/local/lib/frei0r-1/\<vendor\>
+ * - (3) $HOME/.frei0r-1/lib/\<vendor\>
+ *
+ * Examples:
+ *
+ * - /usr/lib/frei0r-1/mob/flippo.so
+ * - /usr/lib/frei0r-1/drone/flippo.so
+ * - /usr/local/lib/frei0r-1/gephex/coma/invert0r.so
+ * - /home/martin/.frei0r-1/lib/martin/test.so
+ *
+ * Like in these examples plugins should be placed in "vendor" subdirs
+ * to reduce name clashes.
+ *
+ * @subsection sec_order Plugin Loading Order
+ *
+ * The application shall load plugins in the following order: 3, 2, 1.
+ * If a name clash occurs (two or more frei0r plugins with identical
+ * effect name), the plugins in directory 3 have precedence over plugins
+ * in directory 2, and those in directory 2 have precedence over plugins
+ * in directory 1.
+ *
+ * This makes it possible for users to "override" effects that are
+ * installed in system wide directories by placing plugins in their
+ * home directory.
+ *
+ * The order of loading plugins inside each of the directories
+ * 1, 2, and 3 is not defined.
+ */
+
+/**
+ *\addtogroup icons Icons for frei0r effects
+ * @section sec_icons Icons for frei0r effects
+ *
+ * Each frei0r effect can have an associated icon.
+ *
+ * @subsection sec_icon_format Icon Format
+ *
+ * The format of frei0r icons must be png.
+ * Recommended resolution is 64x64.
+ * The icon filename of an effect with effect name "frei0r"
+ * must be "frei0r.png".
+ *
+ * @subsection sec_icon_location Icon location
+ *
+ * The exact location where the application should look for the
+ * plugin is platform dependant.
+ *
+ * For Windows platforms, the icon should be at the same place as
+ * the plugin containing the effect.
+ *
+ * For Unix platforms, the following mapping from plugin location
+ * to icon location must be used:
+ *
+ * Let \<plugin_path\>/\<plugin\> be a frei0r plugin with name \<effect_name\>.
+ * Then the corresponding icon (if any) shall be located in
+ * \<icon_path\>/\<effect_name\>.png.
+ * \<icon_path\> can be obtained in the following way:
+ *
+ * @verbatim
+ <plugin_path> | <icon_path>
+ ----------------------------------------------------------------------------
+ $HOME/.frei0r-1/lib/<vendor> | $HOME/.frei0r-1/icons/<vendor>
+ /usr/local/lib/frei0r-1/<vendor> | /usr/local/share/frei0r-1/icons/<vendor>
+ /usr/lib/frei0r-1/<vendor> | /usr/share/frei0r-1/icons/<vendor>
+ * | <plugin_path>
+ @endverbatim
+ *
+ * (The wildcard '*' stands for any other plugin_path)
+ *
+ * For other platforms, no location is defined. We recommend to use the
+ * plugin path where possible.
+ */
+
+/**
+ * \addtogroup concurrency Concurrency
+ * @section sec_concurrency Concurrency
+ *
+ * - \ref f0r_init
+ * - \ref f0r_deinit
+ *
+ * These methods must not be called more than once. It is obvious that no
+ * concurrent calls are allowed.
+ *
+ *
+ * - \ref f0r_get_plugin_info
+ * - \ref f0r_get_param_info
+ * - \ref f0r_construct
+ * - \ref f0r_destruct
+ *
+ * Concurrent calls of these functions are allowed.
+ *
+ *
+ * - \ref f0r_set_param_value
+ * - \ref f0r_get_param_value
+ * - \ref f0r_update
+ * - \ref f0r_update2
+ *
+ * If a thread is in one of these methods its allowed for another thread to
+ * enter one of theses methods for a different effect instance. But for one
+ * effect instance only one thread is allowed to execute any of these methods.
+ */
+
+
+
+/** \file
+ * \brief This file defines the frei0r api, version 1.1.
+ *
+ * A conforming plugin must implement and export all functions declared in
+ * this header.
+ *
+ * A conforming application must accept only those plugins which use
+ * allowed values for the described fields.
+ */
+
+#ifndef INCLUDED_FREI0R_H
+#define INCLUDED_FREI0R_H
+
+#include <inttypes.h>
+
+/**
+ * The frei0r API major version
+ */
+#define FREI0R_MAJOR_VERSION 1
+
+/**
+ * The frei0r API minor version
+ */
+#define FREI0R_MINOR_VERSION 1
+
+//---------------------------------------------------------------------------
+
+/**
+ * f0r_init() is called once when the plugin is loaded by the application.
+ * \see f0r_deinit
+ */
+int f0r_init();
+
+/**
+ * f0r_deinit is called once when the plugin is unloaded by the application.
+ * \see f0r_init
+ */
+void f0r_deinit();
+
+//---------------------------------------------------------------------------
+
+/** \addtogroup PLUGIN_TYPE Type of the Plugin
+ * These defines determine whether the plugin is a
+ * source, a filter or one of the two mixer types
+ * @{
+ */
+
+/** one input and one output */
+#define F0R_PLUGIN_TYPE_FILTER 0
+/** just one output */
+#define F0R_PLUGIN_TYPE_SOURCE 1
+/** two inputs and one output */
+#define F0R_PLUGIN_TYPE_MIXER2 2
+/** three inputs and one output */
+#define F0R_PLUGIN_TYPE_MIXER3 3
+
+/** @} */
+
+//---------------------------------------------------------------------------
+
+/** \addtogroup COLOR_MODEL Color Models
+ * List of supported color models.
+ *
+ * Note: the color models are endian independent, because the
+ * color components are defined by their positon in memory, not
+ * by their significance in an uint32_t value.
+ *
+ * For effects that work on the color components,
+ * RGBA8888 is the recommended color model for frei0r-1.1 effects.
+ * For effects that only work on pixels, PACKED32 is the recommended
+ * color model since it helps the application to avoid unnecessary
+ * color conversions.
+ *
+ * Effects can choose an appropriate color model, applications must support
+ * all color models and do conversions if necessary. Source effects
+ * must not use the PACKED32 color model because the application must know
+ * in which color model the created framebuffers are represented.
+ *
+ * For each color model, a frame consists of width*height pixels which
+ * are stored row-wise and consecutively in memory. The size of a pixel is
+ * 4 bytes. There is no extra pitch parameter
+ * (i.e. the pitch is simply width*4).
+ *
+ * The following additional constraints must be honored:
+ * - The top-most line of a frame is stored first in memory.
+ * - A frame must be aligned to a 16 byte border in memory.
+ * - The width and height of a frame must be positive
+ * - The width and height of a frame must be integer multiples of 8
+ *
+ * These constraints make sure that each line is stored at an address aligned
+ * to 16 byte.
+ */
+/*@{*/
+/**
+ * In BGRA8888, each pixel is represented by 4 consecutive
+ * unsigned bytes, where the first byte value represents
+ * the blue, the second the green, and the third the red color
+ * component of the pixel. The last value represents the
+ * alpha value.
+ */
+#define F0R_COLOR_MODEL_BGRA8888 0
+
+/**
+ * In RGBA8888, each pixel is represented by 4 consecutive
+ * unsigned bytes, where the first byte value represents
+ * the red, the second the green, and the third the blue color
+ * component of the pixel. The last value represents the
+ * alpha value.
+ */
+#define F0R_COLOR_MODEL_RGBA8888 1
+
+/**
+ * In PACKED32, each pixel is represented by 4 consecutive
+ * bytes, but it is not defined how the color componets are
+ * stored. The true color format could be RGBA8888,
+ * BGRA8888, a packed 32 bit YUV format, or any other
+ * color format that stores pixels in 32 bit.
+ *
+ * This is useful for effects that don't work on color but
+ * only on pixels (for example a mirror effect).
+ *
+ * Note that source effects must not use this color model.
+ */
+#define F0R_COLOR_MODEL_PACKED32 2
+/*@}*/
+
+/**
+ * The f0r_plugin_info_t structure is filled in by the plugin
+ * to tell the application about its name, type, number of parameters,
+ * and version.
+ *
+ * An application should ignore (i.e. not use) frei0r effects that
+ * have unknown values in the plugin_type or color_model field.
+ * It should also ignore effects with a too high frei0r_version.
+ *
+ * This is necessary to be able to extend the frei0r spec (e.g.
+ * by adding new color models or plugin types) in a way that does not
+ * result in crashes when loading effects that make use of these
+ * extensions into an older application.
+ *
+ * All strings are unicode, 0-terminated, and the encoding is utf-8.
+ */
+typedef struct f0r_plugin_info
+{
+ const char* name; /**< The (short) name of the plugin */
+ const char* author; /**< The plugin author */
+ /** The plugin type
+ * \see PLUGIN_TYPE
+ */
+ int plugin_type;
+ int color_model; /**< The color model used */
+ int frei0r_version; /**< The frei0r major version this plugin is built for*/
+ int major_version; /**< The major version of the plugin */
+ int minor_version; /**< The minor version of the plugin */
+ int num_params; /**< The number of parameters of the plugin */
+ const char* explanation; /**< An optional explanation string */
+} f0r_plugin_info_t;
+
+
+/**
+ * Is called once after init. The plugin has to fill in the values in info.
+ *
+ * \param info Pointer to an info struct allocated by the application.
+ */
+void f0r_get_plugin_info(f0r_plugin_info_t* info);
+
+//---------------------------------------------------------------------------
+
+/** \addtogroup PARAM_TYPE Parameter Types
+ *
+ * @{
+ */
+
+
+/**
+ * Parameter type for boolean values
+ * \see f0r_param_bool
+ */
+#define F0R_PARAM_BOOL 0
+
+/**
+ * Parameter type for doubles
+ * \see f0r_param_double
+ */
+#define F0R_PARAM_DOUBLE 1
+
+/**
+ * Parameter type for color
+ * \see f0r_param_color
+ */
+#define F0R_PARAM_COLOR 2
+/**
+ * Parameter type for position
+ * \see f0r_param_position
+ */
+#define F0R_PARAM_POSITION 3
+
+/**
+ * Parameter type for string
+ * \see f0r_param_string
+ */
+#define F0R_PARAM_STRING 4
+
+/**
+ * The boolean type. The allowed range of values is [0, 1].
+ * [0, 0.5[ is mapped to false and [0.5, 1] is mapped to true.
+ */
+typedef double f0r_param_bool;
+
+/**
+ * The double type. The allowed range of values is [0, 1].
+ */
+typedef double f0r_param_double;
+
+/**
+ * The color type. All three color components are in the range [0, 1].
+ */
+typedef struct f0r_param_color
+{
+ float r; /**< red color component */
+ float g; /**< green color component */
+ float b; /**< blue color component */
+} f0r_param_color_t;
+
+/**
+ * The position type. Both position coordinates are in the range [0, 1].
+ */
+typedef struct f0r_param_position
+{
+ double x; /**< x coordinate */
+ double y; /**< y coordinate */
+} f0r_param_position_t;
+
+
+/**
+ * The string type.
+ * Zero terminated array of 8-bit values in utf-8 encoding
+ */
+typedef char f0r_param_string;
+
+/** @} */
+
+
+/**
+ * Similar to f0r_plugin_info_t, this structure is filled by the plugin
+ * for every parameter.
+ *
+ * All strings are unicode, 0-terminated, and the encoding is utf-8.
+ */
+typedef struct f0r_param_info
+{
+ const char* name; /**<The (short) name of the param */
+ int type; /**<The type (see the F0R_PARAM_* defines) */
+ const char* explanation; /**<Optional explanation (can be 0) */
+} f0r_param_info_t;
+
+/**
+ * f0r_get_param_info is called by the application to query the type of
+ * each parameter.
+ *
+ * \param info is allocated by the application and filled by the plugin
+ * \param param_index the index of the parameter to be queried (from 0 to
+ * num_params-1)
+ */
+void f0r_get_param_info(f0r_param_info_t* info, int param_index);
+
+//---------------------------------------------------------------------------
+
+/**
+ * Transparent instance pointer of the frei0r effect.
+ */
+typedef void* f0r_instance_t;
+
+/**
+ * Constructor for effect instances. The plugin returns a pointer to
+ * its internal instance structure.
+ *
+ * The resolution has to be an integer multiple of 8,
+ * must be greater than 0 and be at most 2048 in both dimensions.
+ *
+ * \param width The x-resolution of the processed video frames
+ * \param height The y-resolution of the processed video frames
+ * \returns 0 on failure or a pointer != 0 on success
+ *
+ * \see f0r_destruct
+ */
+f0r_instance_t f0r_construct(unsigned int width, unsigned int height);
+
+/**
+ * Destroys an effect instance.
+ *
+ * \param instance The pointer to the plugins internal instance structure.
+ *
+ * \see f0r_construct
+ */
+void f0r_destruct(f0r_instance_t instance);
+
+//---------------------------------------------------------------------------
+
+/**
+ * Transparent parameter handle.
+ */
+typedef void* f0r_param_t;
+
+/**
+ * This function allows the application to set the parameter values of an
+ * effect instance. Validity of the parameter pointer is handled by the
+ * application thus the data must be copied by the effect.
+ *
+ * \param instance the effect instance
+ * \param param pointer to the parameter value
+ * \param param_index index of the parameter
+ *
+ * \see f0r_get_param_value
+ */
+void f0r_set_param_value(f0r_instance_t instance,
+ f0r_param_t param, int param_index);
+
+/**
+ * This function allows the application to query the parameter values of an
+ * effect instance.
+ *
+ * \param instance the effect instance
+ * \param param pointer to the parameter value
+ * \param param_index index of the parameter
+ *
+ * \see f0r_set_param_value
+ */
+void f0r_get_param_value(f0r_instance_t instance,
+ f0r_param_t param, int param_index);
+
+//---------------------------------------------------------------------------
+
+/**
+ * This is where the core effect processing happens. The application calls it
+ * after it has set the necessary parameter values.
+ * inframe and outframe must be aligned to an integer multiple of 16 bytes
+ * in memory.
+ *
+ * This funcition should not alter the parameters of the effect in any
+ * way (\ref f0r_get_param_value should return the same values after a call
+ * to \ref f0r_update as before the call).
+ *
+ * The function is responsible to restore the fpu state (e.g. rounding mode)
+ * and mmx state if applicable before it returns to the caller.
+ *
+ * The host mustn't call \ref f0r_update for effects of type
+ * \ref F0R_PLUGIN_TYPE_MIXER2 and \ref F0R_PLUGIN_TYPE_MIXER3.
+ *
+ * \param instance the effect instance
+ * \param time the application time in seconds but with subsecond resolution
+ * (e.g. milli-second resolution). The resolution should be at least
+ * the inter-frame period of the application.
+ * \param inframe the incoming video frame (can be zero for sources)
+ * \param outframe the resulting video frame
+ *
+ * \see f0r_update2
+ */
+void f0r_update(f0r_instance_t instance,
+ double time, const uint32_t* inframe, uint32_t* outframe);
+
+//---------------------------------------------------------------------------
+
+/**
+ * For effects of type \ref F0R_PLUGIN_TYPE_SOURCE or
+ * \ref F0R_PLUGIN_TYPE_FILTER this method is optional. The \ref f0r_update
+ * method must still be exported for these two effect types. If both are
+ * provided the behavior of them must be the same.
+ *
+ * Effects of type \ref F0R_PLUGIN_TYPE_MIXER2 or \ref F0R_PLUGIN_TYPE_MIXER3 must provide the new \ref f0r_update2 method.
+
+ * \param instance the effect instance
+ * \param time the application time in seconds but with subsecond resolution
+ * (e.g. milli-second resolution). The resolution should be at least
+ * the inter-frame period of the application.
+ * \param inframe1 the first incoming video frame (can be zero for sources)
+ * \param inframe2 the second incoming video frame
+ (can be zero for sources and filters)
+ * \param inframe3 the third incoming video frame
+ (can be zero for sources, filters and mixer3)
+ * \param outframe the resulting video frame
+ *
+ * \see f0r_update
+ */
+void f0r_update2(f0r_instance_t instance,
+ double time,
+ const uint32_t* inframe1,
+ const uint32_t* inframe2,
+ const uint32_t* inframe3,
+ uint32_t* outframe);
+//---------------------------------------------------------------------------
+
+#endif
diff --git a/gst/frei0r/gstfrei0r.c b/gst/frei0r/gstfrei0r.c
new file mode 100644
index 00000000..6af64948
--- /dev/null
+++ b/gst/frei0r/gstfrei0r.c
@@ -0,0 +1,546 @@
+/* GStreamer
+ * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ *
+ * 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 "gstfrei0r.h"
+#include "gstfrei0rfilter.h"
+
+#include <string.h>
+
+GST_DEBUG_CATEGORY_STATIC (frei0r_debug);
+#define GST_CAT_DEFAULT frei0r_debug
+
+GstCaps *
+gst_frei0r_caps_from_color_model (gint color_model)
+{
+ switch (color_model) {
+ case F0R_COLOR_MODEL_BGRA8888:
+ return gst_caps_from_string (GST_VIDEO_CAPS_BGRA);
+ case F0R_COLOR_MODEL_RGBA8888:
+ return gst_caps_from_string (GST_VIDEO_CAPS_RGBA);
+ case F0R_COLOR_MODEL_PACKED32:
+ return gst_caps_from_string (GST_VIDEO_CAPS_BGRA " ; "
+ GST_VIDEO_CAPS_RGBA " ; "
+ GST_VIDEO_CAPS_ABGR " ; "
+ GST_VIDEO_CAPS_ARGB " ; "
+ GST_VIDEO_CAPS_BGRx " ; "
+ GST_VIDEO_CAPS_RGBx " ; "
+ GST_VIDEO_CAPS_xBGR " ; "
+ GST_VIDEO_CAPS_xRGB " ; " GST_VIDEO_CAPS_YUV ("AYUV"));
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
+void
+gst_frei0r_klass_install_properties (GObjectClass * gobject_class,
+ GstFrei0rFuncTable * ftable, GstFrei0rProperty * properties,
+ gint n_properties)
+{
+ gint i, count = 1;
+ f0r_instance_t *instance = ftable->construct (640, 480);
+
+ g_assert (instance);
+
+ for (i = 0; i < n_properties; i++) {
+ f0r_param_info_t *param_info = &properties[i].info;
+ gchar *prop_name;
+
+ ftable->get_param_info (param_info, i);
+
+ prop_name = g_ascii_strdown (param_info->name, -1);
+ g_strcanon (prop_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-');
+
+ properties[i].prop_id = count;
+ properties[i].prop_idx = i;
+
+ ftable->get_param_value (instance, &properties[i].default_value, i);
+ if (param_info->type == F0R_PARAM_STRING)
+ properties[i].default_value.data.s =
+ g_strdup (properties[i].default_value.data.s);
+
+ switch (param_info->type) {
+ case F0R_PARAM_BOOL:
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_boolean (prop_name, param_info->name,
+ param_info->explanation, FALSE,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ properties[i].n_prop_ids = 1;
+ break;
+ case F0R_PARAM_DOUBLE:
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_double (prop_name, param_info->name,
+ param_info->explanation, 0.0, 1.0, 0.0,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ properties[i].n_prop_ids = 1;
+ break;
+ case F0R_PARAM_STRING:
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_string (prop_name, param_info->name,
+ param_info->explanation, NULL,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ properties[i].n_prop_ids = 1;
+ break;
+ case F0R_PARAM_COLOR:{
+ gchar *prop_name_full;
+
+ /* FIXME: Full name, i.e. -R */
+
+ prop_name_full = g_strconcat (prop_name, "-r", NULL);
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_float (prop_name_full, param_info->name,
+ param_info->explanation, 0.0, 1.0, 0.0,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ g_free (prop_name_full);
+ prop_name_full = g_strconcat (prop_name, "-g", NULL);
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_float (prop_name_full, param_info->name,
+ param_info->explanation, 0.0, 1.0, 0.0,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ g_free (prop_name_full);
+ prop_name_full = g_strconcat (prop_name, "-b", NULL);
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_float (prop_name_full, param_info->name,
+ param_info->explanation, 0.0, 1.0, 0.0,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ g_free (prop_name_full);
+
+ properties[i].n_prop_ids = 3;
+ break;
+ }
+ case F0R_PARAM_POSITION:{
+ gchar *prop_name_full;
+
+ prop_name_full = g_strconcat (prop_name, "-x", NULL);
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_double (prop_name_full, param_info->name,
+ param_info->explanation, 0.0, 1.0, 0.0,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ g_free (prop_name_full);
+ prop_name_full = g_strconcat (prop_name, "-y", NULL);
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_double (prop_name_full, param_info->name,
+ param_info->explanation, 0.0, 1.0, 0.0,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ g_free (prop_name_full);
+
+ properties[i].n_prop_ids = 2;
+ break;
+ }
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ g_free (prop_name);
+ }
+
+ ftable->destruct (instance);
+}
+
+GstFrei0rPropertyValue *
+gst_frei0r_property_cache_init (GstFrei0rProperty * properties,
+ gint n_properties)
+{
+ gint i;
+ GstFrei0rPropertyValue *ret = g_new0 (GstFrei0rPropertyValue, n_properties);
+
+ for (i = 0; i < n_properties; i++) {
+ memcpy (&ret[i].data, &properties[i].default_value,
+ sizeof (GstFrei0rPropertyValue));
+
+ if (properties[i].info.type == F0R_PARAM_STRING)
+ ret[i].data.s = g_strdup (ret[i].data.s);
+ }
+
+ return ret;
+}
+
+void
+gst_frei0r_property_cache_free (GstFrei0rProperty * properties,
+ GstFrei0rPropertyValue * property_cache, gint n_properties)
+{
+ gint i;
+
+ for (i = 0; i < n_properties; i++) {
+ if (properties[i].info.type == F0R_PARAM_STRING)
+ g_free (property_cache[i].data.s);
+ }
+ g_free (property_cache);
+}
+
+f0r_instance_t *
+gst_frei0r_instance_construct (GstFrei0rFuncTable * ftable,
+ GstFrei0rProperty * properties, gint n_properties,
+ GstFrei0rPropertyValue * property_cache, gint width, gint height)
+{
+ f0r_instance_t *instance = ftable->construct (width, height);
+ gint i;
+
+ for (i = 0; i < n_properties; i++) {
+ if (properties[i].info.type == F0R_PARAM_STRING)
+ ftable->set_param_value (instance, property_cache[i].data.s, i);
+ else
+ ftable->set_param_value (instance, &property_cache[i].data, i);
+ }
+
+ return instance;
+}
+
+gboolean
+gst_frei0r_get_property (f0r_instance_t * instance, GstFrei0rFuncTable * ftable,
+ GstFrei0rProperty * properties, gint n_properties,
+ GstFrei0rPropertyValue * property_cache, guint prop_id, GValue * value)
+{
+ gint i;
+ GstFrei0rProperty *prop = NULL;
+
+ for (i = 0; i < n_properties; i++) {
+ if (properties[i].prop_id <= prop_id &&
+ properties[i].prop_id + properties[i].n_prop_ids > prop_id) {
+ prop = &properties[i];
+ break;
+ }
+ }
+
+ if (!prop)
+ return FALSE;
+
+ switch (prop->info.type) {
+ case F0R_PARAM_BOOL:{
+ gdouble d;
+
+ if (instance)
+ ftable->get_param_value (instance, &d, prop->prop_idx);
+ else
+ d = property_cache[prop->prop_idx].data.b ? 1.0 : 0.0;
+
+ g_value_set_boolean (value, (d < 0.5) ? FALSE : TRUE);
+ break;
+ }
+ case F0R_PARAM_DOUBLE:{
+ gdouble d;
+
+ if (instance)
+ ftable->get_param_value (instance, &d, prop->prop_idx);
+ else
+ d = property_cache[prop->prop_idx].data.d;
+
+ g_value_set_double (value, d);
+ break;
+ }
+ case F0R_PARAM_STRING:{
+ const gchar *s;
+
+ if (instance)
+ ftable->get_param_value (instance, &s, prop->prop_idx);
+ else
+ s = property_cache[prop->prop_idx].data.s;
+ g_value_set_string (value, s);
+ break;
+ }
+ case F0R_PARAM_COLOR:{
+ f0r_param_color_t color;
+
+ if (instance)
+ ftable->get_param_value (instance, &color, prop->prop_idx);
+ else
+ color = property_cache[prop->prop_idx].data.color;
+
+ switch (prop_id - prop->prop_id) {
+ case 0:
+ g_value_set_float (value, color.r);
+ break;
+ case 1:
+ g_value_set_float (value, color.g);
+ break;
+ case 2:
+ g_value_set_float (value, color.b);
+ break;
+ }
+ break;
+ }
+ case F0R_PARAM_POSITION:{
+ f0r_param_position_t position;
+
+ if (instance)
+ ftable->get_param_value (instance, &position, prop->prop_idx);
+ else
+ position = property_cache[prop->prop_idx].data.position;
+
+ switch (prop_id - prop->prop_id) {
+ case 0:
+ g_value_set_double (value, position.x);
+ break;
+ case 1:
+ g_value_set_double (value, position.y);
+ break;
+ }
+ break;
+ }
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ return TRUE;
+}
+
+gboolean
+gst_frei0r_set_property (f0r_instance_t * instance, GstFrei0rFuncTable * ftable,
+ GstFrei0rProperty * properties, gint n_properties,
+ GstFrei0rPropertyValue * property_cache, guint prop_id,
+ const GValue * value)
+{
+ GstFrei0rProperty *prop = NULL;
+ gint i;
+
+ for (i = 0; i < n_properties; i++) {
+ if (properties[i].prop_id <= prop_id &&
+ properties[i].prop_id + properties[i].n_prop_ids > prop_id) {
+ prop = &properties[i];
+ break;
+ }
+ }
+
+ if (!prop)
+ return FALSE;
+
+ switch (prop->info.type) {
+ case F0R_PARAM_BOOL:{
+ gboolean b = g_value_get_boolean (value);
+ gdouble d = b ? 1.0 : 0.0;
+
+ if (instance)
+ ftable->set_param_value (instance, &d, prop->prop_idx);
+ property_cache[prop->prop_idx].data.b = b;
+ break;
+ }
+ case F0R_PARAM_DOUBLE:{
+ gdouble d = g_value_get_double (value);
+
+ if (instance)
+ ftable->set_param_value (instance, &d, prop->prop_idx);
+ property_cache[prop->prop_idx].data.d = d;
+ break;
+ }
+ case F0R_PARAM_STRING:{
+ gchar *s = g_value_dup_string (value);
+
+ /* Copies the string */
+ if (instance)
+ ftable->set_param_value (instance, s, prop->prop_idx);
+ property_cache[prop->prop_idx].data.s = s;
+ break;
+ }
+ case F0R_PARAM_COLOR:{
+ gfloat f = g_value_get_float (value);
+ f0r_param_color_t *color = &property_cache[prop->prop_idx].data.color;
+
+ switch (prop_id - prop->prop_id) {
+ case 0:
+ color->r = f;
+ break;
+ case 1:
+ color->g = f;
+ break;
+ case 2:
+ color->b = f;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ if (instance)
+ ftable->set_param_value (instance, color, prop->prop_idx);
+ break;
+ }
+ case F0R_PARAM_POSITION:{
+ gdouble d = g_value_get_double (value);
+ f0r_param_position_t *position =
+ &property_cache[prop->prop_idx].data.position;
+
+ switch (prop_id - prop->prop_id) {
+ case 0:
+ position->x = d;
+ break;
+ case 1:
+ position->y = d;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ if (instance)
+ ftable->set_param_value (instance, position, prop->prop_idx);
+ break;
+ }
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+register_plugin (GstPlugin * plugin, const gchar * filename)
+{
+ GModule *module;
+ gboolean ret = FALSE;
+ GstFrei0rFuncTable ftable = { NULL, };
+ f0r_plugin_info_t info = { NULL, };
+
+ GST_DEBUG ("Registering plugin '%s'", filename);
+
+ module = g_module_open (filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
+ if (!module) {
+ GST_WARNING ("Failed to load plugin");
+ return FALSE;
+ }
+
+ if (!g_module_symbol (module, "f0r_init", (gpointer *) & ftable.init)) {
+ GST_INFO ("No frei0r plugin");
+ g_module_close (module);
+ return FALSE;
+ }
+
+ if (!g_module_symbol (module, "f0r_deinit", (gpointer *) & ftable.deinit) ||
+ !g_module_symbol (module, "f0r_construct",
+ (gpointer *) & ftable.construct)
+ || !g_module_symbol (module, "f0r_destruct",
+ (gpointer *) & ftable.destruct)
+ || !g_module_symbol (module, "f0r_get_plugin_info",
+ (gpointer *) & ftable.get_plugin_info)
+ || !g_module_symbol (module, "f0r_get_param_info",
+ (gpointer *) & ftable.get_param_info)
+ || !g_module_symbol (module, "f0r_set_param_value",
+ (gpointer *) & ftable.set_param_value)
+ || !g_module_symbol (module, "f0r_get_param_value",
+ (gpointer *) & ftable.get_param_value))
+ goto invalid_frei0r_plugin;
+
+ /* One of these must exist */
+ if (!g_module_symbol (module, "f0r_update", (gpointer *) & ftable.update) &&
+ !g_module_symbol (module, "f0r_update2", (gpointer *) & ftable.update2))
+ goto invalid_frei0r_plugin;
+
+ ftable.get_plugin_info (&info);
+
+ if (info.frei0r_version > 1) {
+ GST_WARNING ("Unsupported frei0r version %d", info.frei0r_version);
+ g_module_close (module);
+ return FALSE;
+ }
+
+ if (info.color_model > F0R_COLOR_MODEL_PACKED32) {
+ GST_WARNING ("Unsupported color model %d", info.color_model);
+ g_module_close (module);
+ return FALSE;
+ }
+
+ switch (info.plugin_type) {
+ case F0R_PLUGIN_TYPE_FILTER:
+ ret = gst_frei0r_filter_register (plugin, &info, &ftable);
+ break;
+ case F0R_PLUGIN_TYPE_SOURCE:
+ case F0R_PLUGIN_TYPE_MIXER2:
+ case F0R_PLUGIN_TYPE_MIXER3:
+ GST_WARNING
+ ("Source, Mixer2 and Mixer3 frei0r plugins not supported yet");
+ g_module_close (module);
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+
+invalid_frei0r_plugin:
+ GST_ERROR ("Invalid frei0r plugin");
+ g_module_close (module);
+
+ return FALSE;
+}
+
+static gboolean
+register_plugins (GstPlugin * plugin, const gchar * path)
+{
+ GDir *dir;
+ gchar *filename;
+ const gchar *entry_name;
+ gboolean ret = FALSE;
+
+ GST_DEBUG ("Scanning director '%s' for frei0r plugins", path);
+
+ dir = g_dir_open (path, 0, NULL);
+ if (!dir)
+ return FALSE;
+
+ while ((entry_name = g_dir_read_name (dir))) {
+ filename = g_build_filename (path, entry_name, NULL);
+ if ((g_str_has_suffix (filename, G_MODULE_SUFFIX)
+#ifdef GST_EXTRA_MODULE_SUFFIX
+ || g_str_has_suffix (filename, GST_EXTRA_MODULE_SUFFIX)
+#endif
+ ) && g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
+ ret |= register_plugin (plugin, filename);
+ } else if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
+ ret |= register_plugins (plugin, filename);
+ }
+ g_free (filename);
+ }
+ g_dir_close (dir);
+
+ return ret;
+}
+
+static gboolean
+plugin_init (GstPlugin * plugin)
+{
+ const gchar *homedir;
+ gchar *path;
+
+ GST_DEBUG_CATEGORY_INIT (frei0r_debug, "frei0r", 0, "frei0r");
+
+ gst_plugin_add_dependency_simple (plugin,
+ "HOME/.frei0r-1/lib",
+ "/usr/lib/frei0r-1:/usr/local/lib/frei0r-1",
+ NULL, GST_PLUGIN_DEPENDENCY_FLAG_RECURSE);
+
+ register_plugins (plugin, "/usr/lib/frei0r-1");
+ register_plugins (plugin, "/usr/local/lib/frei0r-1");
+
+ homedir = g_get_home_dir ();
+ path = g_build_filename (homedir, ".frei0r-1", NULL);
+ register_plugins (plugin, path);
+ g_free (path);
+
+ return TRUE;
+}
+
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "frei0r",
+ "frei0r plugin library",
+ plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
diff --git a/gst/frei0r/gstfrei0r.h b/gst/frei0r/gstfrei0r.h
new file mode 100644
index 00000000..91e5e097
--- /dev/null
+++ b/gst/frei0r/gstfrei0r.h
@@ -0,0 +1,91 @@
+/* GStreamer
+ * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ *
+ * 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_FREI0R_H__
+#define __GST_FREI0R_H__
+
+#include <gst/gst.h>
+
+#include "frei0r.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GstFrei0rFuncTable GstFrei0rFuncTable;
+typedef struct _GstFrei0rProperty GstFrei0rProperty;
+typedef struct _GstFrei0rPropertyValue GstFrei0rPropertyValue;
+
+struct _GstFrei0rPropertyValue {
+ union {
+ gboolean b;
+ gdouble d;
+ gchar *s;
+ f0r_param_position_t position;
+ f0r_param_color_t color;
+ } data;
+};
+
+struct _GstFrei0rProperty {
+ guint prop_id;
+ guint n_prop_ids;
+
+ gint prop_idx;
+ f0r_param_info_t info;
+
+ GstFrei0rPropertyValue default_value;
+};
+
+struct _GstFrei0rFuncTable {
+ int (*init) (void);
+ void (*deinit) (void);
+
+ f0r_instance_t (*construct) (unsigned int width, unsigned int height);
+ void (*destruct) (f0r_instance_t instance);
+
+ void (*get_plugin_info) (f0r_plugin_info_t* info);
+ void (*get_param_info) (f0r_param_info_t* info, int param_index);
+
+ void (*set_param_value) (f0r_instance_t instance,
+ f0r_param_t param, int param_index);
+ void (*get_param_value) (f0r_instance_t instance,
+ f0r_param_t param, int param_index);
+
+ void (*update) (f0r_instance_t instance,
+ double time, const uint32_t* inframe, uint32_t* outframe);
+ void (*update2) (f0r_instance_t instance,
+ double time,
+ const uint32_t* inframe1,
+ const uint32_t* inframe2,
+ const uint32_t* inframe3,
+ uint32_t* outframe);
+};
+
+void gst_frei0r_klass_install_properties (GObjectClass *gobject_class, GstFrei0rFuncTable *ftable, GstFrei0rProperty *properties, gint n_properties);
+
+f0r_instance_t * gst_frei0r_instance_construct (GstFrei0rFuncTable *ftable, GstFrei0rProperty *properties, gint n_properties, GstFrei0rPropertyValue *property_cache, gint width, gint height);
+
+GstFrei0rPropertyValue * gst_frei0r_property_cache_init (GstFrei0rProperty *properties, gint n_properties);
+void gst_frei0r_property_cache_free (GstFrei0rProperty *properties, GstFrei0rPropertyValue *property_cache, gint n_properties);
+
+GstCaps * gst_frei0r_caps_from_color_model (gint color_model);
+gboolean gst_frei0r_get_property (f0r_instance_t *instance, GstFrei0rFuncTable *ftable, GstFrei0rProperty *properties, gint n_properties, GstFrei0rPropertyValue *property_cache, guint prop_id, GValue *value);
+gboolean gst_frei0r_set_property (f0r_instance_t *instance, GstFrei0rFuncTable *ftable, GstFrei0rProperty *properties, gint n_properties, GstFrei0rPropertyValue *property_cache, guint prop_id, const GValue *value);
+
+G_END_DECLS
+
+#endif /* __GST_FREI0R_H__ */
diff --git a/gst/frei0r/gstfrei0rfilter.c b/gst/frei0r/gstfrei0rfilter.c
new file mode 100644
index 00000000..7862be6c
--- /dev/null
+++ b/gst/frei0r/gstfrei0rfilter.c
@@ -0,0 +1,255 @@
+/* GStreamer
+ * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ *
+ * 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 <string.h>
+
+#include "gstfrei0r.h"
+#include "gstfrei0rfilter.h"
+
+typedef struct
+{
+ f0r_plugin_info_t info;
+ GstFrei0rFuncTable ftable;
+} GstFrei0rFilterClassData;
+
+static gboolean
+gst_frei0r_filter_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
+ guint * size)
+{
+ GstVideoFormat fmt;
+ gint width, height;
+
+ if (!gst_video_format_parse_caps (caps, &fmt, &width, &height))
+ return FALSE;
+
+ *size = gst_video_format_get_size (fmt, width, height);
+ return TRUE;
+}
+
+static gboolean
+gst_frei0r_filter_set_caps (GstBaseTransform * trans, GstCaps * incaps,
+ GstCaps * outcaps)
+{
+ GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
+ GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (trans);
+ GstVideoFormat fmt;
+ gint width, height;
+
+ if (!gst_video_format_parse_caps (incaps, &fmt, &width, &height))
+ return FALSE;
+
+ if (self->f0r_instance) {
+ klass->ftable->destruct (self->f0r_instance);
+ self->f0r_instance = NULL;
+ }
+
+ self->f0r_instance =
+ gst_frei0r_instance_construct (klass->ftable, klass->properties,
+ klass->n_properties, self->property_cache, width, height);
+
+ return TRUE;
+}
+
+static gboolean
+gst_frei0r_filter_stop (GstBaseTransform * trans)
+{
+ GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
+ GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (trans);
+
+ if (self->f0r_instance) {
+ klass->ftable->destruct (self->f0r_instance);
+ self->f0r_instance = NULL;
+ }
+
+ return TRUE;
+}
+
+static GstFlowReturn
+gst_frei0r_filter_transform (GstBaseTransform * trans, GstBuffer * inbuf,
+ GstBuffer * outbuf)
+{
+ GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
+ GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (trans);
+ gdouble time;
+
+ if (!self->f0r_instance)
+ return GST_FLOW_NOT_NEGOTIATED;
+
+ time = ((gdouble) GST_BUFFER_TIMESTAMP (inbuf)) / GST_SECOND;
+
+ if (klass->ftable->update2)
+ klass->ftable->update2 (self->f0r_instance, time,
+ (const guint32 *) GST_BUFFER_DATA (inbuf), NULL, NULL,
+ (guint32 *) GST_BUFFER_DATA (outbuf));
+ else
+ klass->ftable->update (self->f0r_instance, time,
+ (const guint32 *) GST_BUFFER_DATA (inbuf),
+ (guint32 *) GST_BUFFER_DATA (outbuf));
+
+ return GST_FLOW_OK;
+}
+
+static void
+gst_frei0r_filter_finalize (GObject * object)
+{
+ GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
+ GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
+
+ if (self->f0r_instance) {
+ klass->ftable->destruct (self->f0r_instance);
+ self->f0r_instance = NULL;
+ }
+
+ if (self->property_cache)
+ gst_frei0r_property_cache_free (klass->properties, self->property_cache,
+ klass->n_properties);
+ self->property_cache = NULL;
+
+ G_OBJECT_CLASS (g_type_class_peek_parent (klass))->finalize (object);
+}
+
+static void
+gst_frei0r_filter_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
+{
+ GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
+ GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
+
+ if (!gst_frei0r_get_property (self->f0r_instance, klass->ftable,
+ klass->properties, klass->n_properties, self->property_cache, prop_id,
+ value))
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+}
+
+static void
+gst_frei0r_filter_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
+ GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
+
+ if (!gst_frei0r_set_property (self->f0r_instance, klass->ftable,
+ klass->properties, klass->n_properties, self->property_cache, prop_id,
+ value))
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+}
+
+static void
+gst_frei0r_filter_class_init (GstFrei0rFilterClass * klass,
+ GstFrei0rFilterClassData * class_data)
+{
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+ GstElementClass *gstelement_class = (GstElementClass *) klass;
+ GstBaseTransformClass *gsttrans_class = (GstBaseTransformClass *) klass;
+ GstPadTemplate *templ;
+ GstCaps *caps;
+ gchar *author;
+
+ klass->ftable = &class_data->ftable;
+ klass->info = &class_data->info;
+
+ gobject_class->finalize = gst_frei0r_filter_finalize;
+ gobject_class->set_property = gst_frei0r_filter_set_property;
+ gobject_class->get_property = gst_frei0r_filter_get_property;
+
+ klass->n_properties = klass->info->num_params;
+ klass->properties = g_new0 (GstFrei0rProperty, klass->n_properties);
+
+ gst_frei0r_klass_install_properties (gobject_class, klass->ftable,
+ klass->properties, klass->n_properties);
+
+ author =
+ g_strdup_printf
+ ("Sebastian Dröge <sebastian.droege@collabora.co.uk>, %s",
+ class_data->info.author);
+ gst_element_class_set_details_simple (gstelement_class, class_data->info.name,
+ "Filter/Editor/Video", class_data->info.explanation, author);
+ g_free (author);
+
+ caps = gst_frei0r_caps_from_color_model (class_data->info.color_model);
+
+ templ =
+ gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
+ gst_caps_ref (caps));
+ gst_element_class_add_pad_template (gstelement_class, templ);
+
+ templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
+ gst_element_class_add_pad_template (gstelement_class, templ);
+
+ gsttrans_class->get_unit_size =
+ GST_DEBUG_FUNCPTR (gst_frei0r_filter_get_unit_size);
+ gsttrans_class->set_caps = GST_DEBUG_FUNCPTR (gst_frei0r_filter_set_caps);
+ gsttrans_class->stop = GST_DEBUG_FUNCPTR (gst_frei0r_filter_stop);
+ gsttrans_class->transform = GST_DEBUG_FUNCPTR (gst_frei0r_filter_transform);
+}
+
+static void
+gst_frei0r_filter_init (GstFrei0rFilter * self, GstFrei0rFilterClass * klass)
+{
+ self->property_cache =
+ gst_frei0r_property_cache_init (klass->properties, klass->n_properties);
+}
+
+gboolean
+gst_frei0r_filter_register (GstPlugin * plugin, const f0r_plugin_info_t * info,
+ const GstFrei0rFuncTable * ftable)
+{
+ GTypeInfo typeinfo = {
+ sizeof (GstFrei0rFilterClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) gst_frei0r_filter_class_init,
+ NULL,
+ NULL,
+ sizeof (GstFrei0rFilter),
+ 0,
+ (GInstanceInitFunc) gst_frei0r_filter_init
+ };
+ GType type;
+ gchar *type_name, *tmp;
+ GstFrei0rFilterClassData *class_data;
+
+ tmp = g_strdup_printf ("frei0r-%s", info->name);
+ type_name = g_ascii_strdown (tmp, -1);
+ g_free (tmp);
+ g_strcanon (type_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-');
+
+ if (g_type_from_name (type_name)) {
+ GST_WARNING ("Type '%s' already exists", type_name);
+ return FALSE;
+ }
+
+ if (!ftable->init ()) {
+ GST_ERROR ("Initializing plugin failed");
+ return FALSE;
+ }
+
+ class_data = g_new0 (GstFrei0rFilterClassData, 1);
+ memcpy (&class_data->info, info, sizeof (f0r_plugin_info_t));
+ memcpy (&class_data->ftable, ftable, sizeof (GstFrei0rFuncTable));
+ typeinfo.class_data = class_data;
+
+ type =
+ g_type_register_static (GST_TYPE_VIDEO_FILTER, type_name, &typeinfo, 0);
+ return (gst_element_register (plugin, type_name, GST_RANK_NONE, type));
+}
diff --git a/gst/frei0r/gstfrei0rfilter.h b/gst/frei0r/gstfrei0rfilter.h
new file mode 100644
index 00000000..ded2172b
--- /dev/null
+++ b/gst/frei0r/gstfrei0rfilter.h
@@ -0,0 +1,63 @@
+/* GStreamer
+ * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
+ *
+ * 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_FREI0R_FILTER_H__
+#define __GST_FREI0R_FILTER_H__
+
+#include <gst/gst.h>
+#include <gst/video/video.h>
+#include <gst/video/gstvideofilter.h>
+
+#include "frei0r.h"
+#include "gstfrei0r.h"
+
+G_BEGIN_DECLS
+
+#define GST_FREI0R_FILTER(obj) \
+ ((GstFrei0rFilter *) obj)
+#define GST_FREI0R_FILTER_CLASS(klass) \
+ ((GstFrei0rFilterClass *) klass)
+#define GST_FREI0R_FILTER_GET_CLASS(obj) \
+ ((GstFrei0rFilterClass *) g_type_class_peek (G_TYPE_FROM_INSTANCE (obj)))
+
+typedef struct _GstFrei0rFilter GstFrei0rFilter;
+typedef struct _GstFrei0rFilterClass GstFrei0rFilterClass;
+
+struct _GstFrei0rFilter {
+ GstVideoFilter parent;
+
+ f0r_instance_t *f0r_instance;
+ GstFrei0rPropertyValue *property_cache;
+};
+
+struct _GstFrei0rFilterClass {
+ GstVideoFilterClass parent;
+
+ f0r_plugin_info_t *info;
+ GstFrei0rFuncTable *ftable;
+
+ GstFrei0rProperty *properties;
+ gint n_properties;
+};
+
+gboolean gst_frei0r_filter_register (GstPlugin *plugin, const f0r_plugin_info_t *info, const GstFrei0rFuncTable *ftable);
+
+G_END_DECLS
+
+#endif /* __GST_FREI0R_FILTER_H__ */