merge from EVENTS1 on 20011016
[platform/upstream/gstreamer.git] / plugins / elements / gsttee.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *
5  * gsttee.c: Tee element, one in N out
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "gsttee.h"
24
25
26 GstElementDetails gst_tee_details = {
27   "Tee pipe fitting",
28   "Tee",
29   "1-to-N pipe fitting",
30   VERSION,
31   "Erik Walthinsen <omega@cse.ogi.edu>\n"
32   "Wim Taymans <wim.taymans@chello.be>",
33   "(C) 1999, 2000",
34 };
35
36 /* Tee signals and args */
37 enum {
38   /* FILL ME */
39   LAST_SIGNAL
40 };
41
42 enum {
43   ARG_0,
44   ARG_SILENT,
45   ARG_NUM_PADS,
46   /* FILL ME */
47 };
48
49 GST_PADTEMPLATE_FACTORY (tee_src_factory,
50   "src%d",
51   GST_PAD_SRC,
52   GST_PAD_REQUEST,
53   NULL                  /* no caps */
54 );
55
56 static void     gst_tee_class_init      (GstTeeClass *klass);
57 static void     gst_tee_init            (GstTee *tee);
58
59 static GstPad*  gst_tee_request_new_pad (GstElement *element, GstPadTemplate *temp, const gchar *unused);
60
61 static void     gst_tee_set_property    (GObject *object, guint prop_id, 
62                                          const GValue *value, GParamSpec *pspec);
63 static void     gst_tee_get_property    (GObject *object, guint prop_id, 
64                                          GValue *value, GParamSpec *pspec);
65
66 static void     gst_tee_chain           (GstPad *pad, GstBuffer *buf);
67
68 static GstElementClass *parent_class = NULL;
69 //static guint gst_tee_signals[LAST_SIGNAL] = { 0 };
70
71 GType
72 gst_tee_get_type(void) {
73   static GType tee_type = 0;
74
75   if (!tee_type) {
76     static const GTypeInfo tee_info = {
77       sizeof(GstTeeClass),      NULL,
78       NULL,
79       (GClassInitFunc)gst_tee_class_init,
80       NULL,
81       NULL,
82       sizeof(GstTee),
83       0,
84       (GInstanceInitFunc)gst_tee_init,
85     };
86     tee_type = g_type_register_static (GST_TYPE_ELEMENT, "GstTee", &tee_info, 0);
87   }
88   return tee_type;
89 }
90
91 static void
92 gst_tee_class_init (GstTeeClass *klass) 
93 {
94   GObjectClass *gobject_class;
95   GstElementClass *gstelement_class;
96
97   gobject_class = (GObjectClass*)klass;
98   gstelement_class = (GstElementClass*)klass;
99
100   parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
101
102   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
103     g_param_spec_int ("num_pads", "num_pads", "num_pads",
104                       0, G_MAXINT, 0, G_PARAM_READABLE)); 
105   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
106     g_param_spec_boolean ("silent", "silent", "silent",
107                       FALSE, G_PARAM_READWRITE));
108
109
110
111   gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_tee_set_property);
112   gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_tee_get_property);
113
114   gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR(gst_tee_request_new_pad);
115 }
116
117 static void 
118 gst_tee_init (GstTee *tee) 
119 {
120   tee->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
121   gst_element_add_pad (GST_ELEMENT (tee), tee->sinkpad);
122   gst_pad_set_chain_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_chain));
123
124   tee->numsrcpads = 0;
125   tee->srcpads = NULL;
126   tee->silent = FALSE;
127 }
128
129 static GstPad*
130 gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused) 
131 {
132   gchar *name;
133   GstPad *srcpad;
134   GstTee *tee;
135
136   g_return_val_if_fail (GST_IS_TEE (element), NULL);
137
138   if (templ->direction != GST_PAD_SRC) {
139     g_warning ("gsttee: request new pad that is not a SRC pad\n");
140     return NULL;
141   }
142
143   tee = GST_TEE (element);
144
145   name = g_strdup_printf ("src%d",tee->numsrcpads);
146   
147   srcpad = gst_pad_new_from_template (templ, name);
148   gst_element_add_pad (GST_ELEMENT (tee), srcpad);
149   
150   tee->srcpads = g_slist_prepend (tee->srcpads, srcpad);
151   tee->numsrcpads++;
152   
153   return srcpad;
154 }
155
156 static void
157 gst_tee_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
158 {
159   GstTee *tee;
160
161   /* it's not null if we got it, but it might not be ours */
162   g_return_if_fail (GST_IS_TEE (object));
163
164   tee = GST_TEE (object);
165
166   switch (prop_id) {
167     case ARG_SILENT:
168       tee->silent = g_value_get_boolean (value);
169       break;
170     default:
171       break;
172   }
173 }
174
175 static void
176 gst_tee_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
177 {
178   GstTee *tee;
179
180   /* it's not null if we got it, but it might not be ours */
181   g_return_if_fail (GST_IS_TEE (object));
182
183   tee = GST_TEE (object);
184
185   switch (prop_id) {
186     case ARG_NUM_PADS:
187       g_value_set_int (value, tee->numsrcpads);
188       break;
189     case ARG_SILENT:
190       g_value_set_boolean (value, tee->silent);
191       break;
192     default:
193       break;
194   }
195 }
196
197 /**
198  * gst_tee_chain:
199  * @pad: the pad to follow
200  * @buf: the buffer to pass
201  *
202  * Chain a buffer on a pad.
203  */
204 static void 
205 gst_tee_chain (GstPad *pad, GstBuffer *buf) 
206 {
207   GstTee *tee;
208   GSList *srcpads;
209   gint i;
210
211   g_return_if_fail (pad != NULL);
212   g_return_if_fail (GST_IS_PAD (pad));
213   g_return_if_fail (buf != NULL);
214
215   tee = GST_TEE (gst_pad_get_parent (pad));
216 //  gst_trace_add_entry (NULL, 0, buf, "tee buffer");
217
218   for (i=0; i<tee->numsrcpads-1; i++)
219     gst_buffer_ref (buf);
220   
221   srcpads = tee->srcpads;
222   while (srcpads) {
223     GstPad *outpad = GST_PAD (srcpads->data);
224     srcpads = g_slist_next (srcpads);
225
226     if (!tee->silent)
227       g_print("tee: chain        ******* (%s:%s)t (%d bytes, %llu) \n",
228               GST_DEBUG_PAD_NAME (outpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
229
230     gst_pad_push (outpad, buf);
231   }
232 }
233
234 gboolean
235 gst_tee_factory_init (GstElementFactory *factory)
236 {
237   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (tee_src_factory));
238
239   return TRUE;
240 }
241