Added an arg to fakesink so that it doesn't printf.
[platform/upstream/gstreamer.git] / plugins / 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_SOURCES,
47   ARG_SILENT,
48 };
49
50
51 static void     gst_fakesink_class_init (GstFakeSinkClass *klass);
52 static void     gst_fakesink_init       (GstFakeSink *fakesink);
53
54 static void     gst_fakesink_set_arg    (GtkObject *object, GtkArg *arg, guint id);
55 static void     gst_fakesink_get_arg    (GtkObject *object, GtkArg *arg, guint id);
56
57 static void     gst_fakesink_chain      (GstPad *pad,GstBuffer *buf);
58
59 static GstElementClass *parent_class = NULL;
60 static guint gst_fakesink_signals[LAST_SIGNAL] = { 0 };
61
62 GtkType
63 gst_fakesink_get_type (void) 
64 {
65   static GtkType fakesink_type = 0;
66
67   if (!fakesink_type) {
68     static const GtkTypeInfo fakesink_info = {
69       "GstFakeSink",
70       sizeof(GstFakeSink),
71       sizeof(GstFakeSinkClass),
72       (GtkClassInitFunc)gst_fakesink_class_init,
73       (GtkObjectInitFunc)gst_fakesink_init,
74       (GtkArgSetFunc)NULL,
75       (GtkArgGetFunc)NULL,
76       (GtkClassInitFunc)NULL,
77     };
78     fakesink_type = gtk_type_unique (GST_TYPE_ELEMENT, &fakesink_info);
79   }
80   return fakesink_type;
81 }
82
83 static void
84 gst_fakesink_class_init (GstFakeSinkClass *klass) 
85 {
86   GtkObjectClass *gtkobject_class;
87
88   gtkobject_class = (GtkObjectClass*)klass;
89
90   parent_class = gtk_type_class (GST_TYPE_ELEMENT);
91
92   gtk_object_add_arg_type ("GstFakeSink::num_sources", GTK_TYPE_INT,
93                            GTK_ARG_READWRITE, ARG_NUM_SOURCES);
94   gtk_object_add_arg_type ("GstFakeSink::silent", GTK_TYPE_BOOL,
95                            GTK_ARG_READWRITE, ARG_SILENT);
96
97   gst_fakesink_signals[SIGNAL_HANDOFF] =
98     gtk_signal_new ("handoff", GTK_RUN_LAST, gtkobject_class->type,
99                     GTK_SIGNAL_OFFSET (GstFakeSinkClass, handoff),
100                     gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0);
101
102   gtk_object_class_add_signals (gtkobject_class, gst_fakesink_signals,
103                                     LAST_SIGNAL);
104
105   gtkobject_class->set_arg = gst_fakesink_set_arg;
106   gtkobject_class->get_arg = gst_fakesink_get_arg;
107 }
108
109 static void 
110 gst_fakesink_init (GstFakeSink *fakesink) 
111 {
112   GstPad *pad;
113   pad = gst_pad_new ("sink", GST_PAD_SINK);
114   gst_element_add_pad (GST_ELEMENT (fakesink), pad);
115   gst_pad_set_chain_function (pad, gst_fakesink_chain);
116   fakesink->sinkpads = g_slist_prepend (NULL, pad);
117   fakesink->numsinkpads = 1;
118   fakesink->silent = FALSE;
119
120   // we're ready right away, since we don't have any args...
121 //  gst_element_set_state(GST_ELEMENT(fakesink),GST_STATE_READY);
122 }
123
124 static void
125 gst_fakesink_set_arg (GtkObject *object, GtkArg *arg, guint id)
126 {
127   GstFakeSink *sink;
128   gint new_numsinks;
129   GstPad *pad;
130
131   /* it's not null if we got it, but it might not be ours */
132   sink = GST_FAKESINK (object);
133
134   switch(id) {
135     case ARG_NUM_SOURCES:
136       new_numsinks = GTK_VALUE_INT (*arg);
137       while (sink->numsinkpads < new_numsinks) {
138         pad = gst_pad_new (g_strdup_printf ("sink%d", sink->numsinkpads), GST_PAD_SINK);
139         gst_pad_set_chain_function (pad, gst_fakesink_chain);
140         gst_element_add_pad (GST_ELEMENT (sink), pad);
141         sink->sinkpads = g_slist_append (sink->sinkpads, pad);
142         sink->numsinkpads++;
143       }
144       break;
145     case ARG_SILENT:
146       sink->silent = GTK_VALUE_BOOL (*arg);
147       break;
148     default:
149       break;
150   }
151 }
152
153 static void   
154 gst_fakesink_get_arg (GtkObject *object, GtkArg *arg, guint id)
155 {
156   GstFakeSink *sink;
157  
158   /* it's not null if we got it, but it might not be ours */
159   g_return_if_fail (GST_IS_FAKESINK (object));
160  
161   sink = GST_FAKESINK (object);
162   
163   switch (id) {
164     case ARG_NUM_SOURCES:
165       GTK_VALUE_INT (*arg) = sink->numsinkpads;
166       break;
167     case ARG_SILENT:
168       GTK_VALUE_BOOL (*arg) = sink->silent;
169       break;
170     default:
171       arg->type = GTK_TYPE_INVALID;
172       break;
173   }
174 }
175
176 /**
177  * gst_fakesink_chain:
178  * @pad: the pad this faksink is connected to
179  * @buf: the buffer that has to be absorbed
180  *
181  * take the buffer from the pad and unref it without doing
182  * anything with it.
183  */
184 static void 
185 gst_fakesink_chain (GstPad *pad, GstBuffer *buf) 
186 {
187   GstFakeSink *fakesink;
188
189   g_return_if_fail (pad != NULL);
190   g_return_if_fail (GST_IS_PAD (pad));
191   g_return_if_fail (buf != NULL);
192
193   fakesink = GST_FAKESINK (gst_pad_get_parent (pad));
194   if (!fakesink->silent)
195     g_print("fakesink: ******* (%s:%s)< \n",GST_DEBUG_PAD_NAME(pad));
196   
197   gst_buffer_unref (buf);
198
199   gtk_signal_emit (GTK_OBJECT (fakesink), gst_fakesink_signals[SIGNAL_HANDOFF],
200                               fakesink);
201
202 }