initial import from CVS gstreamer/gst-template/gst-plugin
[gst-scaletempo-rj.git] / src / gstplugin.c
blob9bc4e075d532baaadce8340f738640d3e7edd137
1 /*
2 * GStreamer
3 * Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org>
4 * Copyright 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 * Alternatively, the contents of this file may be used under the
25 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
26 * which case the following provisions apply instead of the ones
27 * mentioned above:
29 * This library is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU Library General Public
31 * License as published by the Free Software Foundation; either
32 * version 2 of the License, or (at your option) any later version.
34 * This library is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 * Library General Public License for more details.
39 * You should have received a copy of the GNU Library General Public
40 * License along with this library; if not, write to the
41 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
42 * Boston, MA 02111-1307, USA.
45 /**
46 * SECTION:element-plugin
48 * <refsect2>
49 * <title>Example launch line</title>
50 * <para>
51 * <programlisting>
52 * gst-launch -v -m audiotestsrc ! plugin ! fakesink silent=TRUE
53 * </programlisting>
54 * </para>
55 * </refsect2>
58 #ifdef HAVE_CONFIG_H
59 # include <config.h>
60 #endif
62 #include <gst/gst.h>
64 #include "gstplugin.h"
66 GST_DEBUG_CATEGORY_STATIC (gst_plugin_template_debug);
67 #define GST_CAT_DEFAULT gst_plugin_template_debug
69 /* Filter signals and args */
70 enum
72 /* FILL ME */
73 LAST_SIGNAL
76 enum
78 ARG_0,
79 ARG_SILENT
82 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
83 GST_PAD_SINK,
84 GST_PAD_ALWAYS,
85 GST_STATIC_CAPS ("ANY")
88 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
89 GST_PAD_SRC,
90 GST_PAD_ALWAYS,
91 GST_STATIC_CAPS ("ANY")
94 GST_BOILERPLATE (GstPluginTemplate, gst_plugin_template, GstElement,
95 GST_TYPE_ELEMENT);
97 static void gst_plugin_template_set_property (GObject * object, guint prop_id,
98 const GValue * value, GParamSpec * pspec);
99 static void gst_plugin_template_get_property (GObject * object, guint prop_id,
100 GValue * value, GParamSpec * pspec);
102 static gboolean gst_plugin_template_set_caps (GstPad * pad, GstCaps * caps);
103 static GstFlowReturn gst_plugin_template_chain (GstPad * pad, GstBuffer * buf);
105 static void
106 gst_plugin_template_base_init (gpointer gclass)
108 static GstElementDetails element_details = {
109 "PluginTemplate",
110 "Generic/PluginTemplate",
111 "Generic Template Element",
112 "Thomas Vander Stichele <thomas@apestaart.org>"
114 GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
116 gst_element_class_add_pad_template (element_class,
117 gst_static_pad_template_get (&src_factory));
118 gst_element_class_add_pad_template (element_class,
119 gst_static_pad_template_get (&sink_factory));
120 gst_element_class_set_details (element_class, &element_details);
123 /* initialize the plugin's class */
124 static void
125 gst_plugin_template_class_init (GstPluginTemplateClass * klass)
127 GObjectClass *gobject_class;
128 GstElementClass *gstelement_class;
130 gobject_class = (GObjectClass *) klass;
131 gstelement_class = (GstElementClass *) klass;
133 gobject_class->set_property = gst_plugin_template_set_property;
134 gobject_class->get_property = gst_plugin_template_get_property;
136 g_object_class_install_property (gobject_class, ARG_SILENT,
137 g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?",
138 FALSE, G_PARAM_READWRITE));
141 /* initialize the new element
142 * instantiate pads and add them to element
143 * set functions
144 * initialize structure
146 static void
147 gst_plugin_template_init (GstPluginTemplate * filter,
148 GstPluginTemplateClass * gclass)
150 GstElementClass *klass = GST_ELEMENT_GET_CLASS (filter);
152 filter->sinkpad =
153 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
154 "sink"), "sink");
155 gst_pad_set_setcaps_function (filter->sinkpad,
156 GST_DEBUG_FUNCPTR(gst_plugin_template_set_caps));
157 gst_pad_set_getcaps_function (filter->sinkpad,
158 GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
160 filter->srcpad =
161 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
162 "src"), "src");
163 gst_pad_set_getcaps_function (filter->srcpad,
164 GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
166 gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
167 gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
168 gst_pad_set_chain_function (filter->sinkpad,
169 GST_DEBUG_FUNCPTR(gst_plugin_template_chain));
170 filter->silent = FALSE;
173 static void
174 gst_plugin_template_set_property (GObject * object, guint prop_id,
175 const GValue * value, GParamSpec * pspec)
177 GstPluginTemplate *filter = GST_PLUGIN_TEMPLATE (object);
179 switch (prop_id) {
180 case ARG_SILENT:
181 filter->silent = g_value_get_boolean (value);
182 break;
183 default:
184 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
185 break;
189 static void
190 gst_plugin_template_get_property (GObject * object, guint prop_id,
191 GValue * value, GParamSpec * pspec)
193 GstPluginTemplate *filter = GST_PLUGIN_TEMPLATE (object);
195 switch (prop_id) {
196 case ARG_SILENT:
197 g_value_set_boolean (value, filter->silent);
198 break;
199 default:
200 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
201 break;
205 /* GstElement vmethod implementations */
207 /* this function handles the link with other elements */
208 static gboolean
209 gst_plugin_template_set_caps (GstPad * pad, GstCaps * caps)
211 GstPluginTemplate *filter;
212 GstPad *otherpad;
214 filter = GST_PLUGIN_TEMPLATE (gst_pad_get_parent (pad));
215 otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad;
217 return gst_pad_set_caps (pad, caps);
220 /* chain function
221 * this function does the actual processing
224 static GstFlowReturn
225 gst_plugin_template_chain (GstPad * pad, GstBuffer * buf)
227 GstPluginTemplate *filter;
229 filter = GST_PLUGIN_TEMPLATE (GST_OBJECT_PARENT (pad));
231 if (filter->silent == FALSE)
232 g_print ("I'm plugged, therefore I'm in.\n");
234 /* just push out the incoming buffer without touching it */
235 return gst_pad_push (filter->srcpad, buf);
239 /* entry point to initialize the plug-in
240 * initialize the plug-in itself
241 * register the element factories and pad templates
242 * register the features
244 * exchange the string 'plugin' with your elemnt name
246 static gboolean
247 plugin_init (GstPlugin * plugin)
249 /* exchange the strings 'plugin' and 'Template plugin' with your
250 * plugin name and description */
251 GST_DEBUG_CATEGORY_INIT (gst_plugin_template_debug, "plugin",
252 0, "Template plugin");
254 return gst_element_register (plugin, "myelement",
255 GST_RANK_NONE, GST_TYPE_PLUGIN_TEMPLATE);
258 /* this is the structure that gstreamer looks for to register plugins
260 * exchange the strings 'plugin' and 'Template plugin' with you plugin name and
261 * description
263 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
264 GST_VERSION_MINOR,
265 "plugin",
266 "Template plugin",
267 plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/")