~ubuntu-branches/ubuntu/quantal/gst-plugins-bad-multiverse0.10/quantal

« back to all changes in this revision

Viewing changes to gst/frei0r/gstfrei0rfilter.c

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-12-07 08:54:28 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20091207085428-ml6aaukf0p2ph34d
Tags: 0.10.17-0ubuntu1
* New upstream release.
* Add myself to maintainer.
* Fix misc lintian warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GStreamer
 
2
 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include "config.h"
 
22
#endif
 
23
 
 
24
#include <string.h>
 
25
 
 
26
#include "gstfrei0r.h"
 
27
#include "gstfrei0rfilter.h"
 
28
 
 
29
GST_DEBUG_CATEGORY_EXTERN (frei0r_debug);
 
30
#define GST_CAT_DEFAULT frei0r_debug
 
31
 
 
32
typedef struct
 
33
{
 
34
  f0r_plugin_info_t info;
 
35
  GstFrei0rFuncTable ftable;
 
36
} GstFrei0rFilterClassData;
 
37
 
 
38
static gboolean
 
39
gst_frei0r_filter_set_caps (GstBaseTransform * trans, GstCaps * incaps,
 
40
    GstCaps * outcaps)
 
41
{
 
42
  GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
 
43
  GstVideoFormat fmt;
 
44
 
 
45
  if (!gst_video_format_parse_caps (incaps, &fmt, &self->width, &self->height))
 
46
    return FALSE;
 
47
 
 
48
  return TRUE;
 
49
}
 
50
 
 
51
static gboolean
 
52
gst_frei0r_filter_stop (GstBaseTransform * trans)
 
53
{
 
54
  GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
 
55
  GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (trans);
 
56
 
 
57
  if (self->f0r_instance) {
 
58
    klass->ftable->destruct (self->f0r_instance);
 
59
    self->f0r_instance = NULL;
 
60
  }
 
61
 
 
62
  self->width = self->height = 0;
 
63
 
 
64
  return TRUE;
 
65
}
 
66
 
 
67
static GstFlowReturn
 
68
gst_frei0r_filter_transform (GstBaseTransform * trans, GstBuffer * inbuf,
 
69
    GstBuffer * outbuf)
 
70
{
 
71
  GstFrei0rFilter *self = GST_FREI0R_FILTER (trans);
 
72
  GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (trans);
 
73
  gdouble time;
 
74
 
 
75
  if (G_UNLIKELY (self->width <= 0 || self->height <= 0))
 
76
    return GST_FLOW_NOT_NEGOTIATED;
 
77
 
 
78
  if (G_UNLIKELY (!self->f0r_instance)) {
 
79
    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;
 
84
  }
 
85
 
 
86
  time = ((gdouble) GST_BUFFER_TIMESTAMP (inbuf)) / GST_SECOND;
 
87
 
 
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));
 
92
  else
 
93
    klass->ftable->update (self->f0r_instance, time,
 
94
        (const guint32 *) GST_BUFFER_DATA (inbuf),
 
95
        (guint32 *) GST_BUFFER_DATA (outbuf));
 
96
 
 
97
  return GST_FLOW_OK;
 
98
}
 
99
 
 
100
static void
 
101
gst_frei0r_filter_finalize (GObject * object)
 
102
{
 
103
  GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
 
104
  GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
 
105
 
 
106
  if (self->f0r_instance) {
 
107
    klass->ftable->destruct (self->f0r_instance);
 
108
    self->f0r_instance = NULL;
 
109
  }
 
110
 
 
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;
 
115
 
 
116
  G_OBJECT_CLASS (g_type_class_peek_parent (klass))->finalize (object);
 
117
}
 
118
 
 
119
static void
 
120
gst_frei0r_filter_get_property (GObject * object, guint prop_id, GValue * value,
 
121
    GParamSpec * pspec)
 
122
{
 
123
  GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
 
124
  GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
 
125
 
 
126
  if (!gst_frei0r_get_property (self->f0r_instance, klass->ftable,
 
127
          klass->properties, klass->n_properties, self->property_cache, prop_id,
 
128
          value))
 
129
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
130
}
 
131
 
 
132
static void
 
133
gst_frei0r_filter_set_property (GObject * object, guint prop_id,
 
134
    const GValue * value, GParamSpec * pspec)
 
135
{
 
136
  GstFrei0rFilter *self = GST_FREI0R_FILTER (object);
 
137
  GstFrei0rFilterClass *klass = GST_FREI0R_FILTER_GET_CLASS (object);
 
138
 
 
139
  if (!gst_frei0r_set_property (self->f0r_instance, klass->ftable,
 
140
          klass->properties, klass->n_properties, self->property_cache, prop_id,
 
141
          value))
 
142
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
143
}
 
144
 
 
145
static void
 
146
gst_frei0r_filter_class_init (GstFrei0rFilterClass * klass,
 
147
    GstFrei0rFilterClassData * class_data)
 
148
{
 
149
  GObjectClass *gobject_class = (GObjectClass *) klass;
 
150
  GstElementClass *gstelement_class = (GstElementClass *) klass;
 
151
  GstBaseTransformClass *gsttrans_class = (GstBaseTransformClass *) klass;
 
152
  GstPadTemplate *templ;
 
153
  GstCaps *caps;
 
154
  gchar *author;
 
155
 
 
156
  klass->ftable = &class_data->ftable;
 
157
  klass->info = &class_data->info;
 
158
 
 
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;
 
162
 
 
163
  klass->n_properties = klass->info->num_params;
 
164
  klass->properties = g_new0 (GstFrei0rProperty, klass->n_properties);
 
165
 
 
166
  gst_frei0r_klass_install_properties (gobject_class, klass->ftable,
 
167
      klass->properties, klass->n_properties);
 
168
 
 
169
  author =
 
170
      g_strdup_printf
 
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);
 
175
  g_free (author);
 
176
 
 
177
  caps = gst_frei0r_caps_from_color_model (class_data->info.color_model);
 
178
 
 
179
  templ =
 
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);
 
183
 
 
184
  templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
 
185
  gst_element_class_add_pad_template (gstelement_class, templ);
 
186
 
 
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);
 
190
}
 
191
 
 
192
static void
 
193
gst_frei0r_filter_init (GstFrei0rFilter * self, GstFrei0rFilterClass * klass)
 
194
{
 
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));
 
199
}
 
200
 
 
201
gboolean
 
202
gst_frei0r_filter_register (GstPlugin * plugin, const f0r_plugin_info_t * info,
 
203
    const GstFrei0rFuncTable * ftable)
 
204
{
 
205
  GTypeInfo typeinfo = {
 
206
    sizeof (GstFrei0rFilterClass),
 
207
    NULL,
 
208
    NULL,
 
209
    (GClassInitFunc) gst_frei0r_filter_class_init,
 
210
    NULL,
 
211
    NULL,
 
212
    sizeof (GstFrei0rFilter),
 
213
    0,
 
214
    (GInstanceInitFunc) gst_frei0r_filter_init
 
215
  };
 
216
  GType type;
 
217
  gchar *type_name, *tmp;
 
218
  GstFrei0rFilterClassData *class_data;
 
219
  gboolean ret = FALSE;
 
220
 
 
221
  tmp = g_strdup_printf ("frei0r-filter-%s", info->name);
 
222
  type_name = g_ascii_strdown (tmp, -1);
 
223
  g_free (tmp);
 
224
  g_strcanon (type_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-');
 
225
 
 
226
  if (g_type_from_name (type_name)) {
 
227
    GST_WARNING ("Type '%s' already exists", type_name);
 
228
    return FALSE;
 
229
  }
 
230
 
 
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;
 
235
 
 
236
  type =
 
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);
 
239
 
 
240
  g_free (type_name);
 
241
  return ret;
 
242
}