add formats to base class, not the actual videofilter class
[platform/upstream/gst-plugins-good.git] / gst / videofilter / gstvideotemplate.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2003> David Schleef <ds@schleef.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21
22 /*#define DEBUG_ENABLED */
23 #include <gstvideotemplate.h>
24
25
26 /* elementfactory information */
27 static GstElementDetails videotemplate_details = {
28   "Video Filter Template",
29   "Filter/Video",
30   "LGPL",
31   "Template for a video filter",
32   VERSION,
33   "David Schleef <ds@schleef.org>",
34   "(C) 2003",
35 };
36
37 /* GstVideotemplate signals and args */
38 enum {
39   /* FILL ME */
40   LAST_SIGNAL
41 };
42
43 enum {
44   ARG_0,
45   /* FILL ME */
46 };
47
48 static void     gst_videotemplate_class_init    (GstVideotemplateClass *klass);
49 static void     gst_videotemplate_init          (GstVideotemplate *videotemplate);
50
51 static void     gst_videotemplate_set_property          (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
52 static void     gst_videotemplate_get_property          (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
53
54 static void gst_videotemplate_planar411(GstVideofilter *videofilter, void *dest, void *src);
55 static void gst_videotemplate_setup(GstVideofilter *videofilter);
56
57 static GstVideotemplateClass *this_class = NULL;
58 static GstVideofilterClass *parent_class = NULL;
59 static GstElementClass *element_class = NULL;
60
61 GType
62 gst_videotemplate_get_type (void)
63 {
64   static GType videotemplate_type = 0;
65
66   if (!videotemplate_type) {
67     static const GTypeInfo videotemplate_info = {
68       sizeof(GstVideotemplateClass),      NULL,
69       NULL,
70       (GClassInitFunc)gst_videotemplate_class_init,
71       NULL,
72       NULL,
73       sizeof(GstVideotemplate),
74       0,
75       (GInstanceInitFunc)gst_videotemplate_init,
76     };
77     videotemplate_type = g_type_register_static(GST_TYPE_VIDEOFILTER, "GstVideotemplate", &videotemplate_info, 0);
78   }
79   return videotemplate_type;
80 }
81
82 static GstVideofilterFormat gst_videotemplate_formats[] = {
83   { "I420", 12, gst_videotemplate_planar411, },
84 };
85
86 static void
87 gst_videotemplate_class_init (GstVideotemplateClass *klass)
88 {
89   GObjectClass *gobject_class;
90   GstElementClass *gstelement_class;
91   GstVideofilterClass *gstvideofilter_class;
92   int i;
93
94   gobject_class = (GObjectClass*)klass;
95   gstelement_class = (GstElementClass*)klass;
96   gstvideofilter_class = (GstVideofilterClass *)klass;
97
98 #if 0
99   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_METHOD,
100       g_param_spec_enum("method","method","method",
101       GST_TYPE_VIDEOTEMPLATE_METHOD, GST_VIDEOTEMPLATE_METHOD_90R,
102       G_PARAM_READWRITE));
103 #endif
104
105   this_class = klass;
106   parent_class = g_type_class_ref(GST_TYPE_VIDEOFILTER);
107   element_class = g_type_class_ref(GST_TYPE_ELEMENT);
108
109   gobject_class->set_property = gst_videotemplate_set_property;
110   gobject_class->get_property = gst_videotemplate_get_property;
111
112   gstvideofilter_class->setup = gst_videotemplate_setup;
113
114   for(i=0;i<G_N_ELEMENTS(gst_videotemplate_formats);i++){
115     gst_videofilter_class_add_format(gstvideofilter_class,
116         gst_videotemplate_formats + i);
117   }
118 }
119
120 static GstCaps *gst_videotemplate_get_capslist(void)
121 {
122   GstVideofilterClass *klass;
123
124   klass = g_type_class_ref(GST_TYPE_VIDEOFILTER);
125
126   return gst_videofilter_class_get_capslist(klass);
127 }
128
129 static GstPadTemplate *
130 gst_videotemplate_src_template_factory(void)
131 {
132   static GstPadTemplate *templ = NULL;
133
134   if(!templ){
135     GstCaps *caps = GST_CAPS_NEW("src","video/raw",
136                 "width", GST_PROPS_INT_RANGE (0, G_MAXINT),
137                 "height", GST_PROPS_INT_RANGE (0, G_MAXINT));
138
139     caps = gst_caps_intersect(caps, gst_videotemplate_get_capslist ());
140
141     templ = GST_PAD_TEMPLATE_NEW("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
142   }
143   return templ;
144 }
145
146 static GstPadTemplate *
147 gst_videotemplate_sink_template_factory(void)
148 {
149   static GstPadTemplate *templ = NULL;
150
151   if(!templ){
152     GstCaps *caps = GST_CAPS_NEW("sink","video/raw",
153                 "width", GST_PROPS_INT_RANGE (0, G_MAXINT),
154                 "height", GST_PROPS_INT_RANGE (0, G_MAXINT));
155
156     caps = gst_caps_intersect(caps, gst_videotemplate_get_capslist ());
157
158     templ = GST_PAD_TEMPLATE_NEW("src", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
159   }
160   return templ;
161 }
162
163 static void
164 gst_videotemplate_init (GstVideotemplate *videotemplate)
165 {
166   GstVideofilter *videofilter;
167
168   GST_DEBUG("gst_videotemplate_init");
169
170   videofilter = GST_VIDEOFILTER(videotemplate);
171
172   videofilter->sinkpad = gst_pad_new_from_template (
173                   GST_PAD_TEMPLATE_GET (gst_videotemplate_sink_template_factory),
174                   "sink");
175
176   videofilter->srcpad = gst_pad_new_from_template (
177                   GST_PAD_TEMPLATE_GET (gst_videotemplate_src_template_factory),
178                   "src");
179
180   gst_videofilter_postinit(GST_VIDEOFILTER(videotemplate));
181 }
182
183 static void
184 gst_videotemplate_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
185 {
186   GstVideotemplate *src;
187
188   /* it's not null if we got it, but it might not be ours */
189   g_return_if_fail(GST_IS_VIDEOTEMPLATE(object));
190   src = GST_VIDEOTEMPLATE(object);
191
192   GST_DEBUG("gst_videotemplate_set_property");
193   switch (prop_id) {
194 #if 0
195     case ARG_METHOD:
196       src->method = g_value_get_enum (value);
197       break;
198 #endif
199     default:
200       break;
201   }
202 }
203
204 static void
205 gst_videotemplate_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
206 {
207   GstVideotemplate *src;
208
209   /* it's not null if we got it, but it might not be ours */
210   g_return_if_fail(GST_IS_VIDEOTEMPLATE(object));
211   src = GST_VIDEOTEMPLATE(object);
212
213   switch (prop_id) {
214 #if 0
215     case ARG_METHOD:
216       g_value_set_enum (value, src->method);
217       break;
218 #endif
219     default:
220       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
221       break;
222   }
223 }
224
225 static gboolean plugin_init (GModule *module, GstPlugin *plugin)
226 {
227   GstElementFactory *factory;
228
229   if(!gst_library_load("gstvideofilter"))
230     return FALSE;
231
232   /* create an elementfactory for the videotemplate element */
233   factory = gst_element_factory_new("videotemplate",GST_TYPE_VIDEOTEMPLATE,
234                                    &videotemplate_details);
235   g_return_val_if_fail(factory != NULL, FALSE);
236
237   gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (gst_videotemplate_sink_template_factory));
238   gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (gst_videotemplate_src_template_factory));
239
240   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
241
242   return TRUE;
243 }
244
245 GstPluginDesc plugin_desc = {
246   GST_VERSION_MAJOR,
247   GST_VERSION_MINOR,
248   "videotemplate",
249   plugin_init
250 };
251
252 static void gst_videotemplate_setup(GstVideofilter *videofilter)
253 {
254   GstVideotemplate *videotemplate;
255
256   g_return_if_fail(GST_IS_VIDEOTEMPLATE(videofilter));
257   videotemplate = GST_VIDEOTEMPLATE(videofilter);
258
259   /* if any setup needs to be done, do it here */
260
261 }
262
263 static void gst_videotemplate_planar411(GstVideofilter *videofilter,
264     void *dest, void *src)
265 {
266   GstVideotemplate *videotemplate;
267
268   g_return_if_fail(GST_IS_VIDEOTEMPLATE(videofilter));
269   videotemplate = GST_VIDEOTEMPLATE(videofilter);
270
271   /* do something interesting here */
272 }
273