fix template, too
[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 = GST_ELEMENT_DETAILS (
28   "Video Filter Template",
29   "Filter/Video",
30   "Template for a video filter",
31   "David Schleef <ds@schleef.org>",
32 );
33
34 /* GstVideotemplate signals and args */
35 enum {
36   /* FILL ME */
37   LAST_SIGNAL
38 };
39
40 enum {
41   ARG_0,
42   /* FILL ME */
43 };
44
45 static void     gst_videotemplate_class_init    (gpointer g_class);
46 static void     gst_videotemplate_class_init    (GstVideotemplateClass *klass);
47 static void     gst_videotemplate_init          (GstVideotemplate *videotemplate);
48
49 static void     gst_videotemplate_set_property          (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
50 static void     gst_videotemplate_get_property          (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
51
52 static void gst_videotemplate_planar411(GstVideofilter *videofilter, void *dest, void *src);
53 static void gst_videotemplate_setup(GstVideofilter *videofilter);
54
55 static GstVideotemplateClass *this_class = NULL;
56 static GstVideofilterClass *parent_class = NULL;
57 static GstElementClass *element_class = NULL;
58
59 GType
60 gst_videotemplate_get_type (void)
61 {
62   static GType videotemplate_type = 0;
63
64   if (!videotemplate_type) {
65     static const GTypeInfo videotemplate_info = {
66       sizeof(GstVideotemplateClass),
67       gst_videotemplate_class_init,
68       NULL,
69       (GClassInitFunc)gst_videotemplate_class_init,
70       NULL,
71       NULL,
72       sizeof(GstVideotemplate),
73       0,
74       (GInstanceInitFunc)gst_videotemplate_init,
75     };
76     videotemplate_type = g_type_register_static(GST_TYPE_VIDEOFILTER, "GstVideotemplate", &videotemplate_info, 0);
77   }
78   return videotemplate_type;
79 }
80
81 static GstVideofilterFormat gst_videotemplate_formats[] = {
82   { "I420", 12, gst_videotemplate_planar411, },
83 };
84
85   
86 static void
87 gst_videotemplate_class_init (gpointer g_class)
88 {
89   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
90   
91   factory = gst_element_set_details (element_class, &videotemplate_details);
92
93   gst_element_class_add_pad_template (element_class, GST_PAD_TEMPLATE_GET (gst_videotemplate_sink_template_factory));
94   gst_element_class_add_pad_template (element_class, GST_PAD_TEMPLATE_GET (gst_videotemplate_src_template_factory));
95 }
96 static void
97 gst_videotemplate_class_init (GstVideotemplateClass *klass)
98 {
99   GObjectClass *gobject_class;
100   GstElementClass *gstelement_class;
101   GstVideofilterClass *gstvideofilter_class;
102   int i;
103
104   gobject_class = (GObjectClass*)klass;
105   gstelement_class = (GstElementClass*)klass;
106   gstvideofilter_class = (GstVideofilterClass *)klass;
107
108 #if 0
109   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_METHOD,
110       g_param_spec_enum("method","method","method",
111       GST_TYPE_VIDEOTEMPLATE_METHOD, GST_VIDEOTEMPLATE_METHOD_90R,
112       G_PARAM_READWRITE));
113 #endif
114
115   this_class = klass;
116   parent_class = g_type_class_ref(GST_TYPE_VIDEOFILTER);
117   element_class = g_type_class_ref(GST_TYPE_ELEMENT);
118
119   gobject_class->set_property = gst_videotemplate_set_property;
120   gobject_class->get_property = gst_videotemplate_get_property;
121
122   gstvideofilter_class->setup = gst_videotemplate_setup;
123
124   for(i=0;i<G_N_ELEMENTS(gst_videotemplate_formats);i++){
125     gst_videofilter_class_add_format(gstvideofilter_class,
126         gst_videotemplate_formats + i);
127   }
128 }
129
130 static GstCaps *gst_videotemplate_get_capslist(void)
131 {
132   GstVideofilterClass *klass;
133
134   klass = g_type_class_ref(GST_TYPE_VIDEOFILTER);
135
136   return gst_videofilter_class_get_capslist(klass);
137 }
138
139 static GstPadTemplate *
140 gst_videotemplate_src_template_factory(void)
141 {
142   static GstPadTemplate *templ = NULL;
143
144   if(!templ){
145     GstCaps *caps = GST_CAPS_NEW("src","video/x-raw-yuv",
146                 "width", GST_PROPS_INT_RANGE (1, G_MAXINT),
147                 "height", GST_PROPS_INT_RANGE (1, G_MAXINT),
148                 "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
149
150     caps = gst_caps_intersect(caps, gst_videotemplate_get_capslist ());
151
152     templ = GST_PAD_TEMPLATE_NEW("src", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
153   }
154   return templ;
155 }
156
157 static GstPadTemplate *
158 gst_videotemplate_sink_template_factory(void)
159 {
160   static GstPadTemplate *templ = NULL;
161
162   if(!templ){
163     GstCaps *caps = GST_CAPS_NEW("src","video/x-raw-yuv",
164                 "width", GST_PROPS_INT_RANGE (0, G_MAXINT),
165                 "height", GST_PROPS_INT_RANGE (0, G_MAXINT),
166                 "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT));
167
168     caps = gst_caps_intersect(caps, gst_videotemplate_get_capslist ());
169
170     templ = GST_PAD_TEMPLATE_NEW("src", GST_PAD_SINK, GST_PAD_ALWAYS, caps);
171   }
172   return templ;
173 }
174
175 static void
176 gst_videotemplate_init (GstVideotemplate *videotemplate)
177 {
178   GstVideofilter *videofilter;
179
180   GST_DEBUG("gst_videotemplate_init");
181
182   videofilter = GST_VIDEOFILTER(videotemplate);
183
184   videofilter->sinkpad = gst_pad_new_from_template (
185                   GST_PAD_TEMPLATE_GET (gst_videotemplate_sink_template_factory),
186                   "sink");
187
188   videofilter->srcpad = gst_pad_new_from_template (
189                   GST_PAD_TEMPLATE_GET (gst_videotemplate_src_template_factory),
190                   "src");
191
192   gst_videofilter_postinit(GST_VIDEOFILTER(videotemplate));
193 }
194
195 static void
196 gst_videotemplate_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
197 {
198   GstVideotemplate *src;
199
200   /* it's not null if we got it, but it might not be ours */
201   g_return_if_fail(GST_IS_VIDEOTEMPLATE(object));
202   src = GST_VIDEOTEMPLATE(object);
203
204   GST_DEBUG("gst_videotemplate_set_property");
205   switch (prop_id) {
206 #if 0
207     case ARG_METHOD:
208       src->method = g_value_get_enum (value);
209       break;
210 #endif
211     default:
212       break;
213   }
214 }
215
216 static void
217 gst_videotemplate_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
218 {
219   GstVideotemplate *src;
220
221   /* it's not null if we got it, but it might not be ours */
222   g_return_if_fail(GST_IS_VIDEOTEMPLATE(object));
223   src = GST_VIDEOTEMPLATE(object);
224
225   switch (prop_id) {
226 #if 0
227     case ARG_METHOD:
228       g_value_set_enum (value, src->method);
229       break;
230 #endif
231     default:
232       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
233       break;
234   }
235 }
236
237 static gboolean plugin_init (GstPlugin *plugin)
238 {
239   GstElementFactory *factory;
240
241   if(!gst_library_load("gstvideofilter"))
242     return FALSE;
243
244   return gst_element_register (plugin, "videotemplate", GST_RANK_NONE, GST_TYPE_VIDEOTEMPLATE);
245 }
246
247 GST_PLUGIN_DEFINE (
248   GST_VERSION_MAJOR,
249   GST_VERSION_MINOR,
250   "videotemplate",
251   "Template for a video filter",
252   plugin_init,
253   VERSION,
254   GST_LICENSE,
255   GST_COPYRIGHT,
256   GST_PACKAGE,
257   GST_ORIGIN
258 )
259
260 static void gst_videotemplate_setup(GstVideofilter *videofilter)
261 {
262   GstVideotemplate *videotemplate;
263
264   g_return_if_fail(GST_IS_VIDEOTEMPLATE(videofilter));
265   videotemplate = GST_VIDEOTEMPLATE(videofilter);
266
267   /* if any setup needs to be done, do it here */
268
269 }
270
271 static void gst_videotemplate_planar411(GstVideofilter *videofilter,
272     void *dest, void *src)
273 {
274   GstVideotemplate *videotemplate;
275
276   g_return_if_fail(GST_IS_VIDEOTEMPLATE(videofilter));
277   videotemplate = GST_VIDEOTEMPLATE(videofilter);
278
279   /* do something interesting here */
280 }
281