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