This is a megapatch with the following changes:
[platform/upstream/gstreamer.git] / tests / old / examples / plugins / example.c
1 /* Gnome-Streamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
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 #include "example.h"
21
22 /* elementfactory information */
23 static GstElementDetails example_details = {
24   "An example plugin",
25   "Example",
26   "Shows the basic structure of a plugin",
27   VERSION,
28   "your name <your.name@your.isp>",
29   "(C) 2000",
30 };
31
32 /* Example signals and args */
33 enum {
34   /* FILL ME */
35   LAST_SIGNAL
36 };
37
38 enum {
39   ARG_0,
40   ARG_ACTIVE
41 };
42
43 static GstPadFactory sink_factory = {
44   "sink",                                       /* the name of the pads */
45   GST_PAD_FACTORY_SINK,                         /* type of the pad */
46   GST_PAD_FACTORY_ALWAYS,                       /* ALWAYS/SOMETIMES */
47   GST_PAD_FACTORY_CAPS(
48   "example_sink",                                       /* the name of the caps */
49      "unknown/unknown",                                 /* the mime type of the caps */
50      "something",       GST_PROPS_INT (1),              /* a property */
51      "foo",             GST_PROPS_BOOLEAN (TRUE)        /* another property */
52   ),
53   NULL
54 };
55
56 static GstPadFactory src_factory = {
57   "src",
58   GST_PAD_FACTORY_SRC,
59   GST_PAD_FACTORY_ALWAYS,
60   GST_PAD_FACTORY_CAPS(
61   "example_src",
62     "unknown/unknown"
63   ),
64   NULL
65 };
66
67
68 static void     gst_example_class_init          (GstExampleClass *klass);
69 static void     gst_example_init                (GstExample *example);
70
71 static void     gst_example_chain               (GstPad *pad, GstBuffer *buf);
72
73 static void     gst_example_set_arg             (GtkObject *object,GtkArg *arg,guint id);
74 static void     gst_example_get_arg             (GtkObject *object,GtkArg *arg,guint id);
75
76 GstPadTemplate *src_template, *sink_template;
77
78 static GstElementClass *parent_class = NULL;
79 //static guint gst_example_signals[LAST_SIGNAL] = { 0 };
80
81 GtkType
82 gst_example_get_type(void) 
83 {
84   static GtkType example_type = 0;
85
86   if (!example_type) {
87     static const GtkTypeInfo example_info = {
88       "GstExample",
89       sizeof(GstExample),
90       sizeof(GstExampleClass),
91       (GtkClassInitFunc)gst_example_class_init,
92       (GtkObjectInitFunc)gst_example_init,
93       (GtkArgSetFunc)gst_example_set_arg,
94       (GtkArgGetFunc)gst_example_get_arg,
95       (GtkClassInitFunc)NULL,
96     };
97     example_type = gtk_type_unique(GST_TYPE_ELEMENT,&example_info);
98   }
99   return example_type;
100 }
101
102 static void 
103 gst_example_class_init (GstExampleClass *klass) 
104 {
105   GtkObjectClass *gtkobject_class;
106   GstElementClass *gstelement_class;
107
108   gtkobject_class = (GtkObjectClass*)klass;
109   gstelement_class = (GstElementClass*)klass;
110
111   parent_class = gtk_type_class(GST_TYPE_ELEMENT);
112
113   gtk_object_add_arg_type("GstExample::active", GTK_TYPE_INT,
114                           GTK_ARG_READWRITE, ARG_ACTIVE);
115
116   gtkobject_class->set_arg = gst_example_set_arg;  
117   gtkobject_class->get_arg = gst_example_get_arg;
118 }
119
120 static void 
121 gst_example_init(GstExample *example) 
122 {
123   example->sinkpad = gst_pad_new_from_template (sink_template, "sink");
124   gst_element_add_pad(GST_ELEMENT(example),example->sinkpad);
125   gst_pad_set_chain_function(example->sinkpad,gst_example_chain);
126
127   example->srcpad = gst_pad_new_from_template (src_template, "src");
128   gst_element_add_pad(GST_ELEMENT(example),example->srcpad);
129
130   example->active = FALSE;
131 }
132
133 static void 
134 gst_example_chain (GstPad *pad, GstBuffer *buf) 
135 {
136   GstExample *example;
137
138   g_return_if_fail(pad != NULL);
139   g_return_if_fail(GST_IS_PAD(pad));
140   g_return_if_fail(buf != NULL);
141   //g_return_if_fail(GST_IS_BUFFER(buf));
142
143   example = GST_EXAMPLE(gst_pad_get_parent (pad));
144
145   g_return_if_fail(example != NULL);
146   g_return_if_fail(GST_IS_EXAMPLE(example));
147
148   if (example->active) {
149     /* DO STUFF */
150   }
151
152   gst_pad_push(example->srcpad,buf);
153 }
154
155 static void 
156 gst_example_set_arg (GtkObject *object,GtkArg *arg,guint id) 
157 {
158   GstExample *example;
159
160   /* it's not null if we got it, but it might not be ours */
161   g_return_if_fail(GST_IS_EXAMPLE(object));
162   example = GST_EXAMPLE(object);
163
164   switch(id) {
165     case ARG_ACTIVE:
166       example->active = GTK_VALUE_INT(*arg);
167       g_print("example: set active to %d\n",example->active);
168       break;
169     default:
170       break;
171   }
172 }
173
174 static void 
175 gst_example_get_arg (GtkObject *object,GtkArg *arg,guint id) 
176 {
177   GstExample *example;
178
179   /* it's not null if we got it, but it might not be ours */
180   g_return_if_fail(GST_IS_EXAMPLE(object));
181   example = GST_EXAMPLE(object);
182
183   switch (id) {
184     case ARG_ACTIVE:
185       GTK_VALUE_INT(*arg) = example->active;
186       break;
187     default:
188       arg->type = GTK_TYPE_INVALID;
189       break;
190   }
191 }
192
193 GstPlugin*
194 plugin_init (GModule *module) 
195 {
196   GstPlugin *plugin;
197   GstElementFactory *factory;
198
199   plugin = gst_plugin_new("example");
200   g_return_val_if_fail(plugin != NULL, NULL);
201
202   factory = gst_elementfactory_new("example", GST_TYPE_EXAMPLE, &example_details);
203   g_return_val_if_fail(factory != NULL, NULL);
204
205   sink_template = gst_padtemplate_new (&sink_factory);
206   gst_elementfactory_add_padtemplate (factory, sink_template);
207
208   src_template = gst_padtemplate_new (&src_factory);
209   gst_elementfactory_add_padtemplate (factory, src_template);
210
211   gst_plugin_add_factory (plugin, factory);
212
213   return plugin;
214 }