summaryrefslogtreecommitdiffstats
path: root/gst/frei0r
diff options
context:
space:
mode:
authorDave Robillard <dave@drobilla.net>2009-06-19 21:03:10 -0400
committerDave Robillard <dave@drobilla.net>2009-06-19 21:03:10 -0400
commit23953f27c870c42ce369d717bc15b7f8001691a1 (patch)
tree19b3999c7b0c36fcefcbbcaaaa9102f612670ca7 /gst/frei0r
parentd365eafd8f2cdb1ded93fe4bd95e568026abf0da (diff)
parent925e83ee60c5406b2e5f0f39b0da0f90370efc27 (diff)
downloadgst-plugins-bad-23953f27c870c42ce369d717bc15b7f8001691a1.tar.gz
gst-plugins-bad-23953f27c870c42ce369d717bc15b7f8001691a1.tar.bz2
gst-plugins-bad-23953f27c870c42ce369d717bc15b7f8001691a1.zip
Merge branch 'fdo' into lv2
Diffstat (limited to 'gst/frei0r')
-rw-r--r--gst/frei0r/Makefile.am15
-rw-r--r--gst/frei0r/frei0r.h567
-rw-r--r--gst/frei0r/gstfrei0r.c598
-rw-r--r--gst/frei0r/gstfrei0r.h91
-rw-r--r--gst/frei0r/gstfrei0rfilter.c241
-rw-r--r--gst/frei0r/gstfrei0rfilter.h63
-rw-r--r--gst/frei0r/gstfrei0rmixer.c782
-rw-r--r--gst/frei0r/gstfrei0rmixer.h75
-rw-r--r--gst/frei0r/gstfrei0rsrc.c411
-rw-r--r--gst/frei0r/gstfrei0rsrc.h69
10 files changed, 2912 insertions, 0 deletions
diff --git a/gst/frei0r/Makefile.am b/gst/frei0r/Makefile.am
new file mode 100644
index 00000000..400801d9
--- /dev/null
+++ b/gst/frei0r/Makefile.am
@@ -0,0 +1,15 @@
+plugin_LTLIBRARIES = libgstfrei0r.la
+
+libgstfrei0r_la_SOURCES = \
+ gstfrei0r.c \
+ gstfrei0rfilter.c \
+ gstfrei0rsrc.c \
+ gstfrei0rmixer.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 gstfrei0rsrc.h gstfrei0rmixer.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..0f7ba5c5
--- /dev/null
+++ b/gst/frei0r/gstfrei0r.c
@@ -0,0 +1,598 @@
+/* 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 "gstfrei0rsrc.h"
+#include "gstfrei0rmixer.h"
+
+#include <string.h>
+
+GST_DEBUG_CATEGORY (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, -G_MAXDOUBLE, G_MAXDOUBLE, 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;
+ gchar *prop_nick_full;
+
+ prop_name_full = g_strconcat (prop_name, "-r", NULL);
+ prop_nick_full = g_strconcat (param_info->name, "-R", NULL);
+ g_object_class_install_property (gobject_class, count++,
+ g_param_spec_float (prop_name_full, prop_nick_full,
+ param_info->explanation, 0.0, 1.0, 0.0,
+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ g_free (prop_name_full);
+ g_free (prop_nick_full);
+
+ prop_name_full = g_strconcat (prop_name, "-g", NULL);
+ prop_nick_full = g_strconcat (param_info->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);
+ g_free (prop_nick_full);
+
+ prop_name_full = g_strconcat (prop_name, "-b", NULL);
+ prop_nick_full = g_strconcat (param_info->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);
+ g_free (prop_nick_full);
+
+ properties[i].n_prop_ids = 3;
+ break;
+ }
+ case F0R_PARAM_POSITION:{
+ gchar *prop_name_full;
+ gchar *prop_nick_full;
+
+ prop_name_full = g_strconcat (prop_name, "-x", NULL);
+ prop_nick_full = g_strconcat (param_info->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);
+ g_free (prop_nick_full);
+
+ prop_name_full = g_strconcat (prop_name, "-Y", NULL);
+ prop_nick_full = g_strconcat (param_info->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);
+ g_free (prop_nick_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, };
+ gint i;
+ f0r_plugin_info_t info = { NULL, };
+ f0r_instance_t *instance = 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 */
+ g_module_symbol (module, "f0r_update", (gpointer *) & ftable.update);
+ g_module_symbol (module, "f0r_update2", (gpointer *) & ftable.update2);
+
+ if (!ftable.init ()) {
+ GST_WARNING ("Failed to initialize plugin");
+ g_module_close (module);
+ return FALSE;
+ }
+
+ if (!ftable.update && !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);
+ ftable.deinit ();
+ g_module_close (module);
+ return FALSE;
+ }
+
+ if (info.color_model > F0R_COLOR_MODEL_PACKED32) {
+ GST_WARNING ("Unsupported color model %d", info.color_model);
+ ftable.deinit ();
+ g_module_close (module);
+ return FALSE;
+ }
+
+ for (i = 0; i < info.num_params; i++) {
+ f0r_param_info_t pinfo = { NULL, };
+
+ ftable.get_param_info (&pinfo, i);
+ if (pinfo.type > F0R_PARAM_STRING) {
+ GST_WARNING ("Unsupported parameter type %d", pinfo.type);
+ ftable.deinit ();
+ g_module_close (module);
+ return FALSE;
+ }
+ }
+
+ instance = ftable.construct (640, 480);
+ if (!instance) {
+ GST_WARNING ("Failed to instanciate plugin '%s'", info.name);
+ ftable.deinit ();
+ g_module_close (module);
+ return FALSE;
+ }
+ ftable.destruct (instance);
+
+ switch (info.plugin_type) {
+ case F0R_PLUGIN_TYPE_FILTER:
+ ret = gst_frei0r_filter_register (plugin, &info, &ftable);
+ break;
+ case F0R_PLUGIN_TYPE_SOURCE:
+ ret = gst_frei0r_src_register (plugin, &info, &ftable);
+ break;
+ case F0R_PLUGIN_TYPE_MIXER2:
+ case F0R_PLUGIN_TYPE_MIXER3:
+ ret = gst_frei0r_mixer_register (plugin, &info, &ftable);
+ break;
+ default:
+ break;
+ }
+
+ if (!ret)
+ goto invalid_frei0r_plugin;
+
+ return ret;
+
+invalid_frei0r_plugin:
+ GST_ERROR ("Invalid frei0r plugin");
+ ftable.deinit ();
+ 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..43d8fc67
--- /dev/null
+++ b/gst/frei0r/gstfrei0rfilter.c
@@ -0,0 +1,241 @@
+/* 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"
+
+GST_DEBUG_CATEGORY_EXTERN (frei0r_debug);
+#define GST_CAT_DEFAULT frei0r_debug
+
+typedef struct
+{
+ f0r_plugin_info_t info;
+ GstFrei0rFuncTable ftable;
+} GstFrei0rFilterClassData;
+
+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/Effect/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->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;
+ gboolean ret = FALSE;
+
+ tmp = g_strdup_printf ("frei0r-filter-%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;
+ }
+
+ 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);
+ ret = gst_element_register (plugin, type_name, GST_RANK_NONE, type);
+
+ g_free (type_name);
+ return ret;
+}
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__ */
diff --git a/gst/frei0r/gstfrei0rmixer.c b/gst/frei0r/gstfrei0rmixer.c
new file mode 100644
index 00000000..745c330e
--- /dev/null
+++ b/gst/frei0r/gstfrei0rmixer.c
@@ -0,0 +1,782 @@
+/* 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 "gstfrei0rmixer.h"
+
+GST_DEBUG_CATEGORY_EXTERN (frei0r_debug);
+#define GST_CAT_DEFAULT frei0r_debug
+
+typedef struct
+{
+ f0r_plugin_info_t info;
+ GstFrei0rFuncTable ftable;
+} GstFrei0rMixerClassData;
+
+static void
+gst_frei0r_mixer_reset (GstFrei0rMixer * self)
+{
+ GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (self);
+
+ if (self->f0r_instance) {
+ klass->ftable->destruct (self->f0r_instance);
+ self->f0r_instance = NULL;
+ }
+
+ gst_caps_replace (&self->caps, NULL);
+ gst_event_replace (&self->newseg_event, NULL);
+}
+
+static void
+gst_frei0r_mixer_finalize (GObject * object)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (object);
+ GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (object);
+
+ if (self->property_cache)
+ gst_frei0r_property_cache_free (klass->properties, self->property_cache,
+ klass->n_properties);
+ self->property_cache = NULL;
+
+ if (self->collect)
+ gst_object_unref (self->collect);
+ self->collect = NULL;
+
+ G_OBJECT_CLASS (g_type_class_peek_parent (klass))->finalize (object);
+}
+
+static void
+gst_frei0r_mixer_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (object);
+ GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_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_mixer_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (object);
+ GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_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 GstStateChangeReturn
+gst_frei0r_mixer_change_state (GstElement * element, GstStateChange transition)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (element);
+ GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (self);
+ GstStateChangeReturn ret;
+
+ switch (transition) {
+ case GST_STATE_CHANGE_NULL_TO_READY:
+ break;
+ case GST_STATE_CHANGE_READY_TO_PAUSED:
+ gst_collect_pads_start (self->collect);
+ break;
+ case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
+ break;
+ default:
+ break;
+ }
+
+ /* Stop before calling the parent's state change function as
+ * GstCollectPads might take locks and we would deadlock in that
+ * case
+ */
+ if (transition == GST_STATE_CHANGE_PAUSED_TO_READY)
+ gst_collect_pads_stop (self->collect);
+
+ ret =
+ GST_ELEMENT_CLASS (g_type_class_peek_parent (klass))->change_state
+ (element, transition);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
+ break;
+ case GST_STATE_CHANGE_PAUSED_TO_READY:
+ gst_frei0r_mixer_reset (self);
+ break;
+ case GST_STATE_CHANGE_READY_TO_NULL:
+ break;
+ default:
+ break;
+ }
+
+ return ret;
+}
+
+static GstCaps *
+gst_frei0r_mixer_get_caps (GstPad * pad)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (gst_pad_get_parent (pad));
+ GstCaps *caps = NULL;
+
+ if (self->caps) {
+ caps = gst_caps_ref (self->caps);
+ } else {
+ GstCaps *tmp, *tmp1;
+
+ tmp = gst_caps_copy (gst_pad_get_pad_template_caps (self->src));
+ tmp1 = gst_pad_peer_get_caps (pad);
+ if (tmp1) {
+ caps = gst_caps_intersect (tmp, tmp1);
+ gst_caps_unref (tmp1);
+ gst_caps_unref (tmp);
+ } else {
+ caps = tmp;
+ }
+
+ tmp = caps;
+ tmp1 = gst_pad_peer_get_caps (self->sink0);
+ if (tmp1) {
+ caps = gst_caps_intersect (tmp, tmp1);
+ gst_caps_unref (tmp);
+ gst_caps_unref (tmp1);
+ }
+
+ tmp = caps;
+ tmp1 = gst_pad_peer_get_caps (self->sink1);
+ if (tmp1) {
+ caps = gst_caps_intersect (tmp, tmp1);
+ gst_caps_unref (tmp);
+ gst_caps_unref (tmp1);
+ }
+
+ if (self->sink2) {
+ tmp = caps;
+ tmp1 = gst_pad_peer_get_caps (self->sink2);
+ if (tmp1) {
+ caps = gst_caps_intersect (tmp, tmp1);
+ gst_caps_unref (tmp);
+ gst_caps_unref (tmp1);
+ }
+ }
+ }
+
+ gst_object_unref (self);
+
+ return caps;
+}
+
+static gboolean
+gst_frei0r_mixer_set_caps (GstPad * pad, GstCaps * caps)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (gst_pad_get_parent (pad));
+ GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (self);
+ gboolean ret = TRUE;
+
+ gst_caps_replace (&self->caps, caps);
+
+ if (pad != self->src)
+ ret &= gst_pad_set_caps (self->src, caps);
+ if (pad != self->sink0)
+ ret &= gst_pad_set_caps (self->sink0, caps);
+ if (pad != self->sink1)
+ ret &= gst_pad_set_caps (self->sink1, caps);
+ if (pad != self->sink2 && self->sink2)
+ ret &= gst_pad_set_caps (self->sink2, caps);
+
+ if (ret) {
+ if (!gst_video_format_parse_caps (caps, &self->fmt, &self->width,
+ &self->height)) {
+ ret = FALSE;
+ goto out;
+ }
+
+ 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, self->width, self->height);
+
+ }
+out:
+
+ gst_object_unref (self);
+
+ return ret;
+}
+
+static gboolean
+gst_frei0r_mixer_src_query_duration (GstFrei0rMixer * self, GstQuery * query)
+{
+ gint64 min;
+ gboolean res;
+ GstFormat format;
+ GstIterator *it;
+ gboolean done;
+
+ /* parse format */
+ gst_query_parse_duration (query, &format, NULL);
+
+ min = -1;
+ res = TRUE;
+ done = FALSE;
+
+ /* Take minimum of all durations */
+ it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (self));
+ while (!done) {
+ GstIteratorResult ires;
+ gpointer item;
+
+ ires = gst_iterator_next (it, &item);
+ switch (ires) {
+ case GST_ITERATOR_DONE:
+ done = TRUE;
+ break;
+ case GST_ITERATOR_OK:
+ {
+ GstPad *pad = GST_PAD_CAST (item);
+ gint64 duration;
+
+ /* ask sink peer for duration */
+ res &= gst_pad_query_peer_duration (pad, &format, &duration);
+ /* take min from all valid return values */
+ if (res) {
+ /* valid unknown length, stop searching */
+ if (duration == -1) {
+ min = duration;
+ done = TRUE;
+ }
+ /* else see if smaller than current min */
+ else if (duration < min)
+ min = duration;
+ }
+ gst_object_unref (pad);
+ break;
+ }
+ case GST_ITERATOR_RESYNC:
+ min = -1;
+ res = TRUE;
+ gst_iterator_resync (it);
+ break;
+ default:
+ res = FALSE;
+ done = TRUE;
+ break;
+ }
+ }
+ gst_iterator_free (it);
+
+ if (res) {
+ /* and store the min */
+ GST_DEBUG_OBJECT (self, "Total duration in format %s: %"
+ GST_TIME_FORMAT, gst_format_get_name (format), GST_TIME_ARGS (min));
+ gst_query_set_duration (query, format, min);
+ }
+
+ return res;
+}
+
+static gboolean
+gst_frei0r_mixer_src_query_latency (GstFrei0rMixer * self, GstQuery * query)
+{
+ GstClockTime min, max;
+ gboolean live;
+ gboolean res;
+ GstIterator *it;
+ gboolean done;
+
+ res = TRUE;
+ done = FALSE;
+
+ live = FALSE;
+ min = 0;
+ max = GST_CLOCK_TIME_NONE;
+
+ /* Take maximum of all latency values */
+ it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (self));
+ while (!done) {
+ GstIteratorResult ires;
+ gpointer item;
+
+ ires = gst_iterator_next (it, &item);
+ switch (ires) {
+ case GST_ITERATOR_DONE:
+ done = TRUE;
+ break;
+ case GST_ITERATOR_OK:
+ {
+ GstPad *pad = GST_PAD_CAST (item);
+ GstQuery *peerquery;
+ GstClockTime min_cur, max_cur;
+ gboolean live_cur;
+
+ peerquery = gst_query_new_latency ();
+
+ /* Ask peer for latency */
+ res &= gst_pad_peer_query (pad, peerquery);
+
+ /* take max from all valid return values */
+ if (res) {
+ gst_query_parse_latency (peerquery, &live_cur, &min_cur, &max_cur);
+
+ if (min_cur > min)
+ min = min_cur;
+
+ if (max_cur != GST_CLOCK_TIME_NONE &&
+ ((max != GST_CLOCK_TIME_NONE && max_cur > max) ||
+ (max == GST_CLOCK_TIME_NONE)))
+ max = max_cur;
+
+ live = live || live_cur;
+ }
+
+ gst_query_unref (peerquery);
+ gst_object_unref (pad);
+ break;
+ }
+ case GST_ITERATOR_RESYNC:
+ live = FALSE;
+ min = 0;
+ max = GST_CLOCK_TIME_NONE;
+ res = TRUE;
+ gst_iterator_resync (it);
+ break;
+ default:
+ res = FALSE;
+ done = TRUE;
+ break;
+ }
+ }
+ gst_iterator_free (it);
+
+ if (res) {
+ /* store the results */
+ GST_DEBUG_OBJECT (self, "Calculated total latency: live %s, min %"
+ GST_TIME_FORMAT ", max %" GST_TIME_FORMAT,
+ (live ? "yes" : "no"), GST_TIME_ARGS (min), GST_TIME_ARGS (max));
+ gst_query_set_latency (query, live, min, max);
+ }
+
+ return res;
+}
+
+static gboolean
+gst_frei0r_mixer_src_query (GstPad * pad, GstQuery * query)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (gst_pad_get_parent (pad));
+ gboolean ret = FALSE;
+
+ switch (GST_QUERY_TYPE (query)) {
+ case GST_QUERY_POSITION:
+ ret = gst_pad_query (self->sink0, query);
+ break;
+ case GST_QUERY_DURATION:
+ ret = gst_frei0r_mixer_src_query_duration (self, query);
+ break;
+ case GST_QUERY_LATENCY:
+ ret = gst_frei0r_mixer_src_query_latency (self, query);
+ break;
+ default:
+ ret = gst_pad_query_default (pad, query);
+ break;
+ }
+
+ gst_object_unref (self);
+
+ return ret;
+}
+
+static gboolean
+gst_frei0r_mixer_sink_query (GstPad * pad, GstQuery * query)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (gst_pad_get_parent (pad));
+ gboolean ret = gst_pad_query (self->src, query);
+
+ gst_object_unref (self);
+
+ return ret;
+}
+
+static gboolean
+forward_event_func (GstPad * pad, GValue * ret, GstEvent * event)
+{
+ gst_event_ref (event);
+ GST_LOG_OBJECT (pad, "About to send event %s", GST_EVENT_TYPE_NAME (event));
+ if (!gst_pad_push_event (pad, event)) {
+ g_value_set_boolean (ret, FALSE);
+ GST_WARNING_OBJECT (pad, "Sending event %p (%s) failed.",
+ event, GST_EVENT_TYPE_NAME (event));
+ } else {
+ GST_LOG_OBJECT (pad, "Sent event %p (%s).",
+ event, GST_EVENT_TYPE_NAME (event));
+ }
+ gst_object_unref (pad);
+ return TRUE;
+}
+
+static gboolean
+forward_event (GstFrei0rMixer * self, GstEvent * event)
+{
+ GstIterator *it;
+ GValue vret = { 0 };
+
+ GST_LOG_OBJECT (self, "Forwarding event %p (%s)", event,
+ GST_EVENT_TYPE_NAME (event));
+
+ g_value_init (&vret, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&vret, TRUE);
+ it = gst_element_iterate_sink_pads (GST_ELEMENT_CAST (self));
+ gst_iterator_fold (it, (GstIteratorFoldFunction) forward_event_func, &vret,
+ event);
+ gst_iterator_free (it);
+ gst_event_unref (event);
+
+ return g_value_get_boolean (&vret);
+}
+
+static gboolean
+gst_frei0r_mixer_src_event (GstPad * pad, GstEvent * event)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (gst_pad_get_parent (pad));
+ gboolean ret = FALSE;
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_QOS:
+ /* QoS might be tricky */
+ ret = FALSE;
+ break;
+ case GST_EVENT_SEEK:
+ {
+ GstSeekFlags flags;
+
+ /* parse the seek parameters */
+ gst_event_parse_seek (event, NULL, NULL, &flags, NULL, NULL, NULL, NULL);
+
+ /* check if we are flushing */
+ if (flags & GST_SEEK_FLAG_FLUSH) {
+ /* make sure we accept nothing anymore and return WRONG_STATE */
+ gst_collect_pads_set_flushing (self->collect, TRUE);
+
+ /* flushing seek, start flush downstream, the flush will be done
+ * when all pads received a FLUSH_STOP. */
+ gst_pad_push_event (self->src, gst_event_new_flush_start ());
+ }
+
+ ret = forward_event (self, event);
+ break;
+ }
+ case GST_EVENT_NAVIGATION:
+ /* navigation is rather pointless. */
+ ret = FALSE;
+ break;
+ default:
+ /* just forward the rest for now */
+ ret = forward_event (self, event);
+ break;
+ }
+
+ gst_object_unref (self);
+
+ return ret;
+}
+
+static gboolean
+gst_frei0r_mixer_sink0_event (GstPad * pad, GstEvent * event)
+{
+ GstFrei0rMixer *self = GST_FREI0R_MIXER (gst_pad_get_parent (pad));
+ gboolean ret = FALSE;
+
+ GST_DEBUG ("Got %s event on pad %s:%s", GST_EVENT_TYPE_NAME (event),
+ GST_DEBUG_PAD_NAME (pad));
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_NEWSEGMENT:
+ gst_event_replace (&self->newseg_event, event);
+ break;
+ default:
+ break;
+ }
+
+ /* now GstCollectPads can take care of the rest, e.g. EOS */
+ ret = self->collect_event (pad, event);
+
+ gst_object_unref (self);
+
+ return ret;
+}
+
+static GstFlowReturn
+gst_frei0r_mixer_collected (GstCollectPads * pads, GstFrei0rMixer * self)
+{
+ GstBuffer *inbuf0 = NULL, *inbuf1 = NULL, *inbuf2 = NULL;
+ GstBuffer *outbuf = NULL;
+ GstFlowReturn ret = GST_FLOW_OK;
+ GSList *l;
+ GstFrei0rMixerClass *klass = GST_FREI0R_MIXER_GET_CLASS (self);
+ gdouble time;
+
+ if (G_UNLIKELY (!self->f0r_instance))
+ return GST_FLOW_NOT_NEGOTIATED;
+
+ if (self->newseg_event) {
+ gst_pad_push_event (self->src, self->newseg_event);
+ self->newseg_event = NULL;
+ }
+
+ if ((ret =
+ gst_pad_alloc_buffer_and_set_caps (self->src, GST_BUFFER_OFFSET_NONE,
+ gst_video_format_get_size (self->fmt, self->width, self->height),
+ GST_PAD_CAPS (self->src), &outbuf)) != GST_FLOW_OK)
+ return ret;
+
+ for (l = pads->data; l; l = l->next) {
+ GstCollectData *cdata = l->data;
+
+ if (cdata->pad == self->sink0)
+ inbuf0 = gst_collect_pads_pop (pads, cdata);
+ else if (cdata->pad == self->sink1)
+ inbuf1 = gst_collect_pads_pop (pads, cdata);
+ else if (cdata->pad == self->sink2)
+ inbuf2 = gst_collect_pads_pop (pads, cdata);
+ }
+
+ if (!inbuf0 || !inbuf1 || (!inbuf2 && self->sink2))
+ goto eos;
+
+ gst_buffer_copy_metadata (outbuf, inbuf0,
+ GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
+ time = ((gdouble) GST_BUFFER_TIMESTAMP (outbuf)) / GST_SECOND;
+
+ klass->ftable->update2 (self->f0r_instance, time,
+ (const guint32 *) GST_BUFFER_DATA (inbuf0),
+ (const guint32 *) GST_BUFFER_DATA (inbuf1),
+ (inbuf2) ? (const guint32 *) GST_BUFFER_DATA (inbuf2) : NULL,
+ (guint32 *) GST_BUFFER_DATA (outbuf));
+
+ gst_buffer_unref (inbuf0);
+ gst_buffer_unref (inbuf1);
+ if (inbuf2)
+ gst_buffer_unref (inbuf2);
+
+ ret = gst_pad_push (self->src, outbuf);
+
+ return ret;
+
+eos:
+ {
+ GST_DEBUG_OBJECT (self, "no data available, must be EOS");
+ gst_buffer_unref (outbuf);
+
+ if (inbuf0)
+ gst_buffer_unref (inbuf0);
+ if (inbuf1)
+ gst_buffer_unref (inbuf1);
+ if (inbuf2)
+ gst_buffer_unref (inbuf2);
+
+ gst_pad_push_event (self->src, gst_event_new_eos ());
+ return GST_FLOW_UNEXPECTED;
+ }
+}
+
+static void
+gst_frei0r_mixer_class_init (GstFrei0rMixerClass * klass,
+ GstFrei0rMixerClassData * class_data)
+{
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+ GstElementClass *gstelement_class = (GstElementClass *) klass;
+ GstPadTemplate *templ;
+ GstCaps *caps;
+ gchar *author;
+
+ klass->ftable = &class_data->ftable;
+ klass->info = &class_data->info;
+
+ gobject_class->finalize = gst_frei0r_mixer_finalize;
+ gobject_class->set_property = gst_frei0r_mixer_set_property;
+ gobject_class->get_property = gst_frei0r_mixer_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_0", GST_PAD_SINK, GST_PAD_ALWAYS,
+ gst_caps_ref (caps));
+ gst_element_class_add_pad_template (gstelement_class, templ);
+
+ templ =
+ gst_pad_template_new ("sink_1", GST_PAD_SINK, GST_PAD_ALWAYS,
+ gst_caps_ref (caps));
+ gst_element_class_add_pad_template (gstelement_class, templ);
+
+ if (klass->info->plugin_type == F0R_PLUGIN_TYPE_MIXER3) {
+ templ =
+ gst_pad_template_new ("sink_2", GST_PAD_SINK, GST_PAD_ALWAYS,
+ gst_caps_ref (caps));
+ gst_element_class_add_pad_template (gstelement_class, templ);
+ }
+ gst_caps_unref (caps);
+
+ gstelement_class->change_state =
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_change_state);
+}
+
+static void
+gst_frei0r_mixer_init (GstFrei0rMixer * self, GstFrei0rMixerClass * klass)
+{
+ self->property_cache =
+ gst_frei0r_property_cache_init (klass->properties, klass->n_properties);
+
+ self->collect = gst_collect_pads_new ();
+ gst_collect_pads_set_function (self->collect,
+ (GstCollectPadsFunction) gst_frei0r_mixer_collected, self);
+
+ self->src =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_CLASS (klass), "src"), "src");
+ gst_pad_set_getcaps_function (self->src,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_get_caps));
+ gst_pad_set_setcaps_function (self->src,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_set_caps));
+ gst_pad_set_query_function (self->src,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_src_query));
+ gst_pad_set_event_function (self->src,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_src_event));
+ gst_element_add_pad (GST_ELEMENT_CAST (self), self->src);
+
+ self->sink0 =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_CLASS (klass), "sink_0"), "sink_0");
+ gst_pad_set_getcaps_function (self->sink0,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_get_caps));
+ gst_pad_set_setcaps_function (self->sink0,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_set_caps));
+ gst_pad_set_query_function (self->sink0,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_sink_query));
+ gst_collect_pads_add_pad (self->collect, self->sink0,
+ sizeof (GstCollectData));
+ self->collect_event = (GstPadEventFunction) GST_PAD_EVENTFUNC (self->sink0);
+ gst_pad_set_event_function (self->sink0,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_sink0_event));
+ gst_element_add_pad (GST_ELEMENT_CAST (self), self->sink0);
+
+ self->sink1 =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_CLASS (klass), "sink_1"), "sink_1");
+ gst_pad_set_getcaps_function (self->sink1,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_get_caps));
+ gst_pad_set_setcaps_function (self->sink1,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_set_caps));
+ gst_pad_set_query_function (self->sink0,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_sink_query));
+ gst_collect_pads_add_pad (self->collect, self->sink1,
+ sizeof (GstCollectData));
+ gst_element_add_pad (GST_ELEMENT_CAST (self), self->sink1);
+
+ if (klass->info->plugin_type == F0R_PLUGIN_TYPE_MIXER3) {
+ self->sink2 =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_CLASS (klass), "sink_2"), "sink_2");
+ gst_pad_set_getcaps_function (self->sink2,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_get_caps));
+ gst_pad_set_setcaps_function (self->sink2,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_set_caps));
+ gst_pad_set_query_function (self->sink0,
+ GST_DEBUG_FUNCPTR (gst_frei0r_mixer_sink_query));
+ gst_collect_pads_add_pad (self->collect, self->sink2,
+ sizeof (GstCollectData));
+ gst_element_add_pad (GST_ELEMENT_CAST (self), self->sink2);
+ }
+
+}
+
+gboolean
+gst_frei0r_mixer_register (GstPlugin * plugin, const f0r_plugin_info_t * info,
+ const GstFrei0rFuncTable * ftable)
+{
+ GTypeInfo typeinfo = {
+ sizeof (GstFrei0rMixerClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) gst_frei0r_mixer_class_init,
+ NULL,
+ NULL,
+ sizeof (GstFrei0rMixer),
+ 0,
+ (GInstanceInitFunc) gst_frei0r_mixer_init
+ };
+ GType type;
+ gchar *type_name, *tmp;
+ GstFrei0rMixerClassData *class_data;
+ gboolean ret = FALSE;
+
+ if (ftable->update2 == NULL)
+ return FALSE;
+
+ tmp = g_strdup_printf ("frei0r-mixer-%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;
+ }
+
+ class_data = g_new0 (GstFrei0rMixerClassData, 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_ELEMENT, type_name, &typeinfo, 0);
+ ret = gst_element_register (plugin, type_name, GST_RANK_NONE, type);
+
+ g_free (type_name);
+ return ret;
+}
diff --git a/gst/frei0r/gstfrei0rmixer.h b/gst/frei0r/gstfrei0rmixer.h
new file mode 100644
index 00000000..548b70ec
--- /dev/null
+++ b/gst/frei0r/gstfrei0rmixer.h
@@ -0,0 +1,75 @@
+/* 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_MIXER_H__
+#define __GST_FREI0R_MIXER_H__
+
+#include <gst/gst.h>
+#include <gst/video/video.h>
+#include <gst/base/gstcollectpads.h>
+
+#include "frei0r.h"
+#include "gstfrei0r.h"
+
+G_BEGIN_DECLS
+
+#define GST_FREI0R_MIXER(obj) \
+ ((GstFrei0rMixer *) obj)
+#define GST_FREI0R_MIXER_CLASS(klass) \
+ ((GstFrei0rMixerClass *) klass)
+#define GST_FREI0R_MIXER_GET_CLASS(obj) \
+ ((GstFrei0rMixerClass *) g_type_class_peek (G_TYPE_FROM_INSTANCE (obj)))
+
+typedef struct _GstFrei0rMixer GstFrei0rMixer;
+typedef struct _GstFrei0rMixerClass GstFrei0rMixerClass;
+
+struct _GstFrei0rMixer {
+ GstElement parent;
+
+ GstCollectPads *collect;
+ GstPad *src;
+ GstPad *sink0, *sink1, *sink2;
+
+ GstCaps *caps;
+ GstVideoFormat fmt;
+ gint width, height;
+
+ GstEvent *newseg_event;
+
+ GstPadEventFunction collect_event;
+
+ f0r_instance_t *f0r_instance;
+ GstFrei0rPropertyValue *property_cache;
+};
+
+struct _GstFrei0rMixerClass {
+ GstElementClass parent;
+
+ f0r_plugin_info_t *info;
+ GstFrei0rFuncTable *ftable;
+
+ GstFrei0rProperty *properties;
+ gint n_properties;
+};
+
+gboolean gst_frei0r_mixer_register (GstPlugin *plugin, const f0r_plugin_info_t *info, const GstFrei0rFuncTable *ftable);
+
+G_END_DECLS
+
+#endif /* __GST_FREI0R_MIXER_H__ */
diff --git a/gst/frei0r/gstfrei0rsrc.c b/gst/frei0r/gstfrei0rsrc.c
new file mode 100644
index 00000000..a713e1e9
--- /dev/null
+++ b/gst/frei0r/gstfrei0rsrc.c
@@ -0,0 +1,411 @@
+/* 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 "gstfrei0rsrc.h"
+
+GST_DEBUG_CATEGORY_EXTERN (frei0r_debug);
+#define GST_CAT_DEFAULT frei0r_debug
+
+typedef struct
+{
+ f0r_plugin_info_t info;
+ GstFrei0rFuncTable ftable;
+} GstFrei0rSrcClassData;
+
+static gboolean
+gst_frei0r_src_set_caps (GstBaseSrc * src, GstCaps * caps)
+{
+ GstFrei0rSrc *self = GST_FREI0R_SRC (src);
+ GstFrei0rSrcClass *klass = GST_FREI0R_SRC_GET_CLASS (src);
+
+ if (!gst_video_format_parse_caps (caps, &self->fmt, &self->width,
+ &self->height)
+ || !gst_video_parse_caps_framerate (caps, &self->fps_n, &self->fps_d))
+ 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, self->width, self->height);
+
+ return TRUE;
+}
+
+static GstCaps *
+gst_frei0r_src_get_caps (GstBaseSrc * src)
+{
+ if (GST_PAD_CAPS (GST_BASE_SRC_PAD (src)))
+ return gst_caps_ref (GST_PAD_CAPS (GST_BASE_SRC_PAD (src)));
+ else
+ return
+ gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)));
+}
+
+static GstFlowReturn
+gst_frei0r_src_create (GstPushSrc * src, GstBuffer ** buf)
+{
+ GstFrei0rSrc *self = GST_FREI0R_SRC (src);
+ GstFrei0rSrcClass *klass = GST_FREI0R_SRC_GET_CLASS (src);
+ guint size, newsize;
+ GstFlowReturn ret = GST_FLOW_OK;
+ GstBuffer *outbuf = NULL;
+ gdouble time;
+
+ *buf = NULL;
+
+ if (G_UNLIKELY (!self->f0r_instance))
+ return GST_FLOW_NOT_NEGOTIATED;
+
+ newsize = gst_video_format_get_size (self->fmt, self->width, self->height);
+
+ ret =
+ gst_pad_alloc_buffer_and_set_caps (GST_BASE_SRC_PAD (src),
+ GST_BUFFER_OFFSET_NONE, newsize, GST_PAD_CAPS (GST_BASE_SRC_PAD (src)),
+ &outbuf);
+ if (ret != GST_FLOW_OK)
+ return ret;
+
+ /* Format might have changed */
+ size = GST_BUFFER_SIZE (outbuf);
+ newsize = gst_video_format_get_size (self->fmt, self->width, self->height);
+
+ if (size != newsize) {
+ gst_buffer_unref (outbuf);
+ outbuf = gst_buffer_new_and_alloc (newsize);
+ gst_buffer_set_caps (outbuf, GST_PAD_CAPS (GST_BASE_SRC_PAD (src)));
+ }
+
+ GST_BUFFER_TIMESTAMP (outbuf) =
+ gst_util_uint64_scale (self->n_frames, GST_SECOND * self->fps_d,
+ self->fps_n);
+ GST_BUFFER_OFFSET (outbuf) = self->n_frames;
+ self->n_frames++;
+ GST_BUFFER_OFFSET_END (outbuf) = self->n_frames;
+ GST_BUFFER_DURATION (outbuf) =
+ gst_util_uint64_scale (self->n_frames, GST_SECOND * self->fps_d,
+ self->fps_n) - GST_BUFFER_TIMESTAMP (outbuf);
+
+ time = ((gdouble) GST_BUFFER_TIMESTAMP (outbuf)) / GST_SECOND;
+
+ if (klass->ftable->update2)
+ klass->ftable->update2 (self->f0r_instance, time, NULL, NULL, NULL,
+ (guint32 *) GST_BUFFER_DATA (outbuf));
+ else
+ klass->ftable->update (self->f0r_instance, time, NULL,
+ (guint32 *) GST_BUFFER_DATA (outbuf));
+
+ *buf = outbuf;
+
+ return GST_FLOW_OK;
+}
+
+static gboolean
+gst_frei0r_src_start (GstBaseSrc * basesrc)
+{
+ GstFrei0rSrc *self = GST_FREI0R_SRC (basesrc);
+
+ self->n_frames = 0;
+
+ return TRUE;
+}
+
+static gboolean
+gst_frei0r_src_stop (GstBaseSrc * basesrc)
+{
+ GstFrei0rSrc *self = GST_FREI0R_SRC (basesrc);
+ GstFrei0rSrcClass *klass = GST_FREI0R_SRC_GET_CLASS (basesrc);
+
+ if (self->f0r_instance) {
+ klass->ftable->destruct (self->f0r_instance);
+ self->f0r_instance = NULL;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+gst_frei0r_src_is_seekable (GstBaseSrc * psrc)
+{
+ return TRUE;
+}
+
+static gboolean
+gst_frei0r_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
+{
+ GstClockTime time;
+ GstFrei0rSrc *self = GST_FREI0R_SRC (bsrc);
+
+ segment->time = segment->start;
+ time = segment->last_stop;
+
+ /* now move to the time indicated */
+ if (self->fps_n) {
+ self->n_frames = gst_util_uint64_scale (time,
+ self->fps_n, self->fps_d * GST_SECOND);
+ } else {
+ self->n_frames = 0;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+gst_frei0r_src_query (GstBaseSrc * bsrc, GstQuery * query)
+{
+ gboolean res;
+ GstFrei0rSrc *self = GST_FREI0R_SRC (bsrc);
+ GstFrei0rSrcClass *klass = GST_FREI0R_SRC_GET_CLASS (self);
+
+ switch (GST_QUERY_TYPE (query)) {
+ case GST_QUERY_CONVERT:
+ {
+ GstFormat src_fmt, dest_fmt;
+ gint64 src_val, dest_val;
+
+ gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
+ if (src_fmt == dest_fmt) {
+ dest_val = src_val;
+ goto done;
+ }
+
+ switch (src_fmt) {
+ case GST_FORMAT_DEFAULT:
+ switch (dest_fmt) {
+ case GST_FORMAT_TIME:
+ /* frames to time */
+ if (self->fps_n) {
+ dest_val = gst_util_uint64_scale (src_val,
+ self->fps_d * GST_SECOND, self->fps_n);
+ } else {
+ dest_val = 0;
+ }
+ break;
+ default:
+ goto error;
+ }
+ break;
+ case GST_FORMAT_TIME:
+ switch (dest_fmt) {
+ case GST_FORMAT_DEFAULT:
+ /* time to frames */
+ if (self->fps_n) {
+ dest_val = gst_util_uint64_scale (src_val,
+ self->fps_n, self->fps_d * GST_SECOND);
+ } else {
+ dest_val = 0;
+ }
+ break;
+ default:
+ goto error;
+ }
+ break;
+ default:
+ goto error;
+ }
+ done:
+ gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
+ res = TRUE;
+ break;
+ }
+ default:
+ res =
+ GST_BASE_SRC_CLASS (g_type_class_peek_parent (klass))->query (bsrc,
+ query);
+ }
+ return res;
+
+ /* ERROR */
+error:
+ {
+ GST_DEBUG_OBJECT (self, "query failed");
+ return FALSE;
+ }
+}
+
+static void
+gst_frei0r_src_src_fixate (GstPad * pad, GstCaps * caps)
+{
+ GstStructure *structure;
+
+ structure = gst_caps_get_structure (caps, 0);
+
+ gst_structure_fixate_field_nearest_int (structure, "width", 320);
+ gst_structure_fixate_field_nearest_int (structure, "height", 240);
+ gst_structure_fixate_field_nearest_fraction (structure, "framerate", 30, 1);
+}
+
+static void
+gst_frei0r_src_finalize (GObject * object)
+{
+ GstFrei0rSrc *self = GST_FREI0R_SRC (object);
+ GstFrei0rSrcClass *klass = GST_FREI0R_SRC_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_src_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
+{
+ GstFrei0rSrc *self = GST_FREI0R_SRC (object);
+ GstFrei0rSrcClass *klass = GST_FREI0R_SRC_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_src_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstFrei0rSrc *self = GST_FREI0R_SRC (object);
+ GstFrei0rSrcClass *klass = GST_FREI0R_SRC_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_src_class_init (GstFrei0rSrcClass * klass,
+ GstFrei0rSrcClassData * class_data)
+{
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+ GstElementClass *gstelement_class = (GstElementClass *) klass;
+ GstPushSrcClass *gstpushsrc_class = (GstPushSrcClass *) klass;
+ GstBaseSrcClass *gstbasesrc_class = (GstBaseSrcClass *) klass;
+ GstPadTemplate *templ;
+ GstCaps *caps;
+ gchar *author;
+
+ klass->ftable = &class_data->ftable;
+ klass->info = &class_data->info;
+
+ gobject_class->finalize = gst_frei0r_src_finalize;
+ gobject_class->set_property = gst_frei0r_src_set_property;
+ gobject_class->get_property = gst_frei0r_src_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,
+ "Src/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, caps);
+ gst_element_class_add_pad_template (gstelement_class, templ);
+
+ gstbasesrc_class->set_caps = gst_frei0r_src_set_caps;
+ gstbasesrc_class->get_caps = gst_frei0r_src_get_caps;
+ gstbasesrc_class->is_seekable = gst_frei0r_src_is_seekable;
+ gstbasesrc_class->do_seek = gst_frei0r_src_do_seek;
+ gstbasesrc_class->query = gst_frei0r_src_query;
+ gstbasesrc_class->start = gst_frei0r_src_start;
+ gstbasesrc_class->stop = gst_frei0r_src_stop;
+
+ gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_frei0r_src_create);
+}
+
+static void
+gst_frei0r_src_init (GstFrei0rSrc * self, GstFrei0rSrcClass * klass)
+{
+ GstPad *pad = GST_BASE_SRC_PAD (self);
+
+ self->property_cache =
+ gst_frei0r_property_cache_init (klass->properties, klass->n_properties);
+
+ gst_pad_set_fixatecaps_function (pad, gst_frei0r_src_src_fixate);
+
+ gst_base_src_set_format (GST_BASE_SRC_CAST (self), GST_FORMAT_TIME);
+}
+
+gboolean
+gst_frei0r_src_register (GstPlugin * plugin, const f0r_plugin_info_t * info,
+ const GstFrei0rFuncTable * ftable)
+{
+ GTypeInfo typeinfo = {
+ sizeof (GstFrei0rSrcClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) gst_frei0r_src_class_init,
+ NULL,
+ NULL,
+ sizeof (GstFrei0rSrc),
+ 0,
+ (GInstanceInitFunc) gst_frei0r_src_init
+ };
+ GType type;
+ gchar *type_name, *tmp;
+ GstFrei0rSrcClassData *class_data;
+ gboolean ret = FALSE;
+
+ tmp = g_strdup_printf ("frei0r-src-%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;
+ }
+
+ class_data = g_new0 (GstFrei0rSrcClassData, 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_PUSH_SRC, type_name, &typeinfo, 0);
+ ret = gst_element_register (plugin, type_name, GST_RANK_NONE, type);
+
+ g_free (type_name);
+ return ret;
+}
diff --git a/gst/frei0r/gstfrei0rsrc.h b/gst/frei0r/gstfrei0rsrc.h
new file mode 100644
index 00000000..291a644b
--- /dev/null
+++ b/gst/frei0r/gstfrei0rsrc.h
@@ -0,0 +1,69 @@
+/* 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_SRC_H__
+#define __GST_FREI0R_SRC_H__
+
+#include <gst/gst.h>
+#include <gst/video/video.h>
+#include <gst/base/gstpushsrc.h>
+
+#include "frei0r.h"
+#include "gstfrei0r.h"
+
+G_BEGIN_DECLS
+
+#define GST_FREI0R_SRC(obj) \
+ ((GstFrei0rSrc *) obj)
+#define GST_FREI0R_SRC_CLASS(klass) \
+ ((GstFrei0rSrcClass *) klass)
+#define GST_FREI0R_SRC_GET_CLASS(obj) \
+ ((GstFrei0rSrcClass *) g_type_class_peek (G_TYPE_FROM_INSTANCE (obj)))
+
+typedef struct _GstFrei0rSrc GstFrei0rSrc;
+typedef struct _GstFrei0rSrcClass GstFrei0rSrcClass;
+
+struct _GstFrei0rSrc {
+ GstPushSrc parent;
+
+ f0r_instance_t *f0r_instance;
+ GstFrei0rPropertyValue *property_cache;
+
+ GstVideoFormat fmt;
+ gint width, height;
+ gint fps_n, fps_d;
+
+ guint64 n_frames;
+};
+
+struct _GstFrei0rSrcClass {
+ GstPushSrcClass parent;
+
+ f0r_plugin_info_t *info;
+ GstFrei0rFuncTable *ftable;
+
+ GstFrei0rProperty *properties;
+ gint n_properties;
+};
+
+gboolean gst_frei0r_src_register (GstPlugin *plugin, const f0r_plugin_info_t *info, const GstFrei0rFuncTable *ftable);
+
+G_END_DECLS
+
+#endif /* __GST_FREI0R_SRC_H__ */