Commit 0a684a3d authored by Sebastian Dröge's avatar Sebastian Dröge

frei0r: First version of a frei0r wrapper plugin

Currently this only supports frei0r filters.
parent d45e804d
......@@ -265,6 +265,7 @@ AG_GST_CHECK_PLUGIN(dtmf)
AG_GST_CHECK_PLUGIN(dvdspu)
AG_GST_CHECK_PLUGIN(festival)
AG_GST_CHECK_PLUGIN(freeze)
AG_GST_CHECK_PLUGIN(frei0r)
AG_GST_CHECK_PLUGIN(h264parse)
AG_GST_CHECK_PLUGIN(hdvparse)
AG_GST_CHECK_PLUGIN(id3tag)
......@@ -1557,6 +1558,7 @@ gst/dtmf/Makefile
gst/dvdspu/Makefile
gst/festival/Makefile
gst/freeze/Makefile
gst/frei0r/Makefile
gst/h264parse/Makefile
gst/hdvparse/Makefile
gst/id3tag/Makefile
......
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
This diff is collapsed.
This diff is collapsed.
/* 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__ */
/* 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));
}
/* 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__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment