s/gst_element_install_std_props/gst_element_class_install_std_props/ -- it just makes...
[platform/upstream/gstreamer.git] / gst / elements / gstfakesink.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstfakesink.c: 
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
24 #include <gstfakesink.h>
25
26
27 GstElementDetails gst_fakesink_details = {
28   "Fake Sink",
29   "Sink",
30   "Black hole for data",
31   VERSION,
32   "Erik Walthinsen <omega@cse.ogi.edu>",
33   "(C) 1999",
34 };
35
36
37 /* FakeSink signals and args */
38 enum {
39   /* FILL ME */
40   SIGNAL_HANDOFF,
41   LAST_SIGNAL
42 };
43
44 enum {
45   ARG_0,
46   ARG_NUM_SINKS,
47   ARG_SILENT,
48   ARG_DUMP,
49   ARG_LAST_MESSAGE,
50 };
51
52 GST_PADTEMPLATE_FACTORY (fakesink_sink_factory,
53   "sink%d",
54   GST_PAD_SINK,
55   GST_PAD_REQUEST,
56   NULL                  /* no caps */
57 );
58
59
60 static void     gst_fakesink_class_init         (GstFakeSinkClass *klass);
61 static void     gst_fakesink_init               (GstFakeSink *fakesink);
62
63 static GstPad*  gst_fakesink_request_new_pad    (GstElement *element, GstPadTemplate *templ, const
64                                                  gchar *unused);
65
66 static void     gst_fakesink_set_property       (GObject *object, guint prop_id, 
67                                                  const GValue *value, GParamSpec *pspec);
68 static void     gst_fakesink_get_property       (GObject *object, guint prop_id, 
69                                                  GValue *value, GParamSpec *pspec);
70
71 static void     gst_fakesink_chain              (GstPad *pad, GstBuffer *buf);
72
73 static GstElementClass *parent_class = NULL;
74 static guint gst_fakesink_signals[LAST_SIGNAL] = { 0 };
75
76 GType
77 gst_fakesink_get_type (void) 
78 {
79   static GType fakesink_type = 0;
80
81   if (!fakesink_type) {
82     static const GTypeInfo fakesink_info = {
83       sizeof(GstFakeSinkClass),      NULL,
84       NULL,
85       (GClassInitFunc)gst_fakesink_class_init,
86       NULL,
87       NULL,
88       sizeof(GstFakeSink),
89       0,
90       (GInstanceInitFunc)gst_fakesink_init,
91     };
92     fakesink_type = g_type_register_static (GST_TYPE_ELEMENT, "GstFakeSink", &fakesink_info, 0);
93   }
94   return fakesink_type;
95 }
96
97 static void
98 gst_fakesink_class_init (GstFakeSinkClass *klass) 
99 {
100   GObjectClass *gobject_class;
101   GstElementClass *gstelement_class;
102
103   gobject_class = (GObjectClass*)klass;
104   gstelement_class = (GstElementClass*)klass;
105
106   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
107
108   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_SINKS,
109     g_param_spec_int ("num_sinks", "num_sinks", "num_sinks",
110                       1, G_MAXINT, 1, G_PARAM_READABLE)); 
111   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
112     g_param_spec_string ("last_message", "last_message", "last_message",
113                          NULL, G_PARAM_READABLE));
114
115
116   gst_element_class_install_std_props (
117           GST_ELEMENT_CLASS (klass),
118           "silent", ARG_SILENT, G_PARAM_READWRITE,
119           "dump",   ARG_DUMP,   G_PARAM_READWRITE,
120           NULL);
121
122   gst_fakesink_signals[SIGNAL_HANDOFF] =
123     g_signal_new ("handoff", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
124                     G_STRUCT_OFFSET (GstFakeSinkClass, handoff), NULL, NULL,
125                     g_cclosure_marshal_VOID__POINTER, G_TYPE_NONE, 1,
126                     G_TYPE_POINTER);
127
128   gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_fakesink_set_property);
129   gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_fakesink_get_property);
130
131   gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR (gst_fakesink_request_new_pad);
132 }
133
134 static void 
135 gst_fakesink_init (GstFakeSink *fakesink) 
136 {
137   GstPad *pad;
138   pad = gst_pad_new ("sink", GST_PAD_SINK);
139   gst_element_add_pad (GST_ELEMENT (fakesink), pad);
140   gst_pad_set_chain_function (pad, GST_DEBUG_FUNCPTR (gst_fakesink_chain));
141
142   fakesink->silent = FALSE;
143   fakesink->dump = FALSE;
144   fakesink->last_message = NULL;
145 }
146
147 static GstPad*
148 gst_fakesink_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused)
149 {
150   gchar *name;
151   GstPad *sinkpad;
152   GstFakeSink *fakesink;
153
154   g_return_val_if_fail (GST_IS_FAKESINK (element), NULL);
155
156   if (templ->direction != GST_PAD_SINK) {
157     g_warning ("gstfakesink: request new pad that is not a SINK pad\n");
158     return NULL;
159   }
160
161   fakesink = GST_FAKESINK (element);
162
163   name = g_strdup_printf ("sink%d", GST_ELEMENT (fakesink)->numsinkpads);
164
165   sinkpad = gst_pad_new_from_template (templ, name);
166   gst_element_add_pad (GST_ELEMENT (fakesink), sinkpad);
167
168   return sinkpad;
169 }
170
171 static void
172 gst_fakesink_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
173 {
174   GstFakeSink *sink;
175
176   /* it's not null if we got it, but it might not be ours */
177   sink = GST_FAKESINK (object);
178
179   switch (prop_id) {
180     case ARG_SILENT:
181       sink->silent = g_value_get_boolean (value);
182       break;
183     case ARG_DUMP:
184       sink->dump = g_value_get_boolean (value);
185       break;
186     default:
187       break;
188   }
189 }
190
191 static void   
192 gst_fakesink_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
193 {
194   GstFakeSink *sink;
195  
196   /* it's not null if we got it, but it might not be ours */
197   g_return_if_fail (GST_IS_FAKESINK (object));
198  
199   sink = GST_FAKESINK (object);
200   
201   switch (prop_id) {
202     case ARG_NUM_SINKS:
203       g_value_set_int (value, GST_ELEMENT (sink)->numsinkpads);
204       break;
205     case ARG_SILENT:
206       g_value_set_boolean (value, sink->silent);
207       break;
208     case ARG_DUMP:
209       g_value_set_boolean (value, sink->dump);
210       break;
211     case ARG_LAST_MESSAGE:
212       g_value_set_string (value, sink->last_message);
213       break;
214     default:
215       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
216       break;
217   }
218 }
219
220 static void 
221 gst_fakesink_chain (GstPad *pad, GstBuffer *buf) 
222 {
223   GstFakeSink *fakesink;
224
225   g_return_if_fail (pad != NULL);
226   g_return_if_fail (GST_IS_PAD (pad));
227   g_return_if_fail (buf != NULL);
228
229   fakesink = GST_FAKESINK (gst_pad_get_parent (pad));
230
231   if (!fakesink->silent) { 
232     if (fakesink->last_message) 
233       g_free (fakesink->last_message);
234
235     fakesink->last_message = g_strdup_printf ("chain   ******* (%s:%s)< (%d bytes, %lld) %p",
236                 GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf), buf);
237     
238     g_object_notify (G_OBJECT (fakesink), "last_message");
239   }
240
241   g_signal_emit (G_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF], 0, buf, pad);
242
243   if (fakesink->dump)
244   {
245     gst_util_dump_mem (GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
246   }
247
248   gst_buffer_unref (buf);
249 }
250
251 gboolean
252 gst_fakesink_factory_init (GstElementFactory *factory)
253 {
254   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (fakesink_sink_factory));
255
256   return TRUE;
257 }