2
* Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
26
#include "gstfrei0r.h"
27
#include "gstfrei0rfilter.h"
29
GST_DEBUG_CATEGORY_EXTERN (frei0r_debug);
30
#define GST_CAT_DEFAULT frei0r_debug
34
f0r_plugin_info_t info;
35
GstFrei0rFuncTable ftable;
36
} GstFrei0rFilterClassData;
39
gst_frei0r_filter_set_caps (GstBaseTransform * trans, GstCaps * incaps,
42
GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
45
if (!gst_video_format_parse_caps (incaps, &fmt, &self->width, &self->height))
52
gst_frei0r_filter_stop (GstBaseTransform * trans)
54
GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
55
GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (trans);
57
if (self->f0r_instance) {
58
klass->ftable->destruct (self->f0r_instance);
59
self->f0r_instance = NULL;
62
self->width = self->height = 0;
68
gst_frei0r_filter_transform (GstBaseTransform * trans, GstBuffer * inbuf,
71
GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
72
GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (trans);
75
if (G_UNLIKELY (self->width <= 0 || self->height <= 0))
76
return GST_FLOW_NOT_NEGOTIATED;
78
if (G_UNLIKELY (!self->f0r_instance)) {
80
gst_frei0r_instance_construct (klass->ftable, klass->properties,
81
klass->n_properties, self->property_cache, self->width, self->height);
82
if (G_UNLIKELY (!self->f0r_instance))
83
return GST_FLOW_ERROR;
86
time = ((gdouble) GST_BUFFER_TIMESTAMP (inbuf)) / GST_SECOND;
88
if (klass->ftable->update2)
89
klass->ftable->update2 (self->f0r_instance, time,
90
(const guint32 *) GST_BUFFER_DATA (inbuf), NULL, NULL,
91
(guint32 *) GST_BUFFER_DATA (outbuf));
93
klass->ftable->update (self->f0r_instance, time,
94
(const guint32 *) GST_BUFFER_DATA (inbuf),
95
(guint32 *) GST_BUFFER_DATA (outbuf));
101
gst_frei0r_filter_finalize (GObject * object)
103
GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
104
GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
106
if (self->f0r_instance) {
107
klass->ftable->destruct (self->f0r_instance);
108
self->f0r_instance = NULL;
111
if (self->property_cache)
112
gst_frei0r_property_cache_free (klass->properties, self->property_cache,
113
klass->n_properties);
114
self->property_cache = NULL;
116
G_OBJECT_CLASS (g_type_class_peek_parent (klass))->finalize (object);
120
gst_frei0r_filter_get_property (GObject * object, guint prop_id, GValue * value,
123
GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
124
GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
126
if (!gst_frei0r_get_property (self->f0r_instance, klass->ftable,
127
klass->properties, klass->n_properties, self->property_cache, prop_id,
129
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
133
gst_frei0r_filter_set_property (GObject * object, guint prop_id,
134
const GValue * value, GParamSpec * pspec)
136
GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
137
GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
139
if (!gst_frei0r_set_property (self->f0r_instance, klass->ftable,
140
klass->properties, klass->n_properties, self->property_cache, prop_id,
142
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
146
gst_frei0r_filter_class_init (GstFrei0rFilterClass * klass,
147
GstFrei0rFilterClassData * class_data)
149
GObjectClass *gobject_class = (GObjectClass *) klass;
150
GstElementClass *gstelement_class = (GstElementClass *) klass;
151
GstBaseTransformClass *gsttrans_class = (GstBaseTransformClass *) klass;
152
GstPadTemplate *templ;
156
klass->ftable = &class_data->ftable;
157
klass->info = &class_data->info;
159
gobject_class->finalize = gst_frei0r_filter_finalize;
160
gobject_class->set_property = gst_frei0r_filter_set_property;
161
gobject_class->get_property = gst_frei0r_filter_get_property;
163
klass->n_properties = klass->info->num_params;
164
klass->properties = g_new0 (GstFrei0rProperty, klass->n_properties);
166
gst_frei0r_klass_install_properties (gobject_class, klass->ftable,
167
klass->properties, klass->n_properties);
171
("Sebastian Dröge <sebastian.droege@collabora.co.uk>, %s",
172
class_data->info.author);
173
gst_element_class_set_details_simple (gstelement_class, class_data->info.name,
174
"Filter/Effect/Video", class_data->info.explanation, author);
177
caps = gst_frei0r_caps_from_color_model (class_data->info.color_model);
180
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
181
gst_caps_ref (caps));
182
gst_element_class_add_pad_template (gstelement_class, templ);
184
templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
185
gst_element_class_add_pad_template (gstelement_class, templ);
187
gsttrans_class->set_caps = GST_DEBUG_FUNCPTR (gst_frei0r_filter_set_caps);
188
gsttrans_class->stop = GST_DEBUG_FUNCPTR (gst_frei0r_filter_stop);
189
gsttrans_class->transform = GST_DEBUG_FUNCPTR (gst_frei0r_filter_transform);
193
gst_frei0r_filter_init (GstFrei0rFilter * self, GstFrei0rFilterClass * klass)
195
self->property_cache =
196
gst_frei0r_property_cache_init (klass->properties, klass->n_properties);
197
gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SINK_PAD (self));
198
gst_pad_use_fixed_caps (GST_BASE_TRANSFORM_SRC_PAD (self));
202
gst_frei0r_filter_register (GstPlugin * plugin, const f0r_plugin_info_t * info,
203
const GstFrei0rFuncTable * ftable)
205
GTypeInfo typeinfo = {
206
sizeof (GstFrei0rFilterClass),
209
(GClassInitFunc) gst_frei0r_filter_class_init,
212
sizeof (GstFrei0rFilter),
214
(GInstanceInitFunc) gst_frei0r_filter_init
217
gchar *type_name, *tmp;
218
GstFrei0rFilterClassData *class_data;
219
gboolean ret = FALSE;
221
tmp = g_strdup_printf ("frei0r-filter-%s", info->name);
222
type_name = g_ascii_strdown (tmp, -1);
224
g_strcanon (type_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-');
226
if (g_type_from_name (type_name)) {
227
GST_WARNING ("Type '%s' already exists", type_name);
231
class_data = g_new0 (GstFrei0rFilterClassData, 1);
232
memcpy (&class_data->info, info, sizeof (f0r_plugin_info_t));
233
memcpy (&class_data->ftable, ftable, sizeof (GstFrei0rFuncTable));
234
typeinfo.class_data = class_data;
237
g_type_register_static (GST_TYPE_VIDEO_FILTER, type_name, &typeinfo, 0);
238
ret = gst_element_register (plugin, type_name, GST_RANK_NONE, type);