2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
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.
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.
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.
24 #include <gstfakesrc.h>
27 GstElementDetails gst_fakesrc_details = {
30 "Push empty (no data) buffers around",
32 "Erik Walthinsen <omega@cse.ogi.edu>\n"
33 "Wim Taymans <wim.taymans@chello.be>"
38 /* FakeSrc signals and args */
54 #define GST_TYPE_FAKESRC_OUTPUT (gst_fakesrc_output_get_type())
56 gst_fakesrc_output_get_type(void) {
57 static GtkType fakesrc_output_type = 0;
58 static GtkEnumValue fakesrc_output[] = {
59 { FAKESRC_FIRST_LAST_LOOP, "1", "First-Last loop"},
60 { FAKESRC_LAST_FIRST_LOOP, "2", "Last-First loop"},
61 { FAKESRC_PING_PONG, "3", "Ping-Pong"},
62 { FAKESRC_ORDERED_RANDOM, "4", "Ordered Random"},
63 { FAKESRC_RANDOM, "5", "Random"},
64 { FAKESRC_PATTERN_LOOP, "6", "Patttern loop"},
65 { FAKESRC_PING_PONG_PATTERN, "7", "Ping-Pong Pattern"},
66 { FAKESRC_GET_ALWAYS_SUCEEDS, "8", "'_get' Always succeeds"},
69 if (!fakesrc_output_type) {
70 fakesrc_output_type = gtk_type_register_enum("GstFakeSrcOutput", fakesrc_output);
72 return fakesrc_output_type;
75 static void gst_fakesrc_class_init (GstFakeSrcClass *klass);
76 static void gst_fakesrc_init (GstFakeSrc *fakesrc);
78 static void gst_fakesrc_set_arg (GtkObject *object, GtkArg *arg, guint id);
79 static void gst_fakesrc_get_arg (GtkObject *object, GtkArg *arg, guint id);
81 static GstBuffer* gst_fakesrc_get (GstPad *pad);
82 static void gst_fakesrc_loop (GstElement *element);
84 static GstElementClass *parent_class = NULL;
85 static guint gst_fakesrc_signals[LAST_SIGNAL] = { 0 };
88 gst_fakesrc_get_type (void)
90 static GtkType fakesrc_type = 0;
93 static const GtkTypeInfo fakesrc_info = {
96 sizeof(GstFakeSrcClass),
97 (GtkClassInitFunc)gst_fakesrc_class_init,
98 (GtkObjectInitFunc)gst_fakesrc_init,
101 (GtkClassInitFunc)NULL,
103 fakesrc_type = gtk_type_unique (GST_TYPE_ELEMENT, &fakesrc_info);
109 gst_fakesrc_class_init (GstFakeSrcClass *klass)
111 GtkObjectClass *gtkobject_class;
113 gtkobject_class = (GtkObjectClass*)klass;
115 parent_class = gtk_type_class (GST_TYPE_ELEMENT);
117 gtk_object_add_arg_type ("GstFakeSrc::num_sources", GTK_TYPE_INT,
118 GTK_ARG_READWRITE, ARG_NUM_SOURCES);
119 gtk_object_add_arg_type ("GstFakeSrc::loop_based", GTK_TYPE_BOOL,
120 GTK_ARG_READWRITE, ARG_LOOP_BASED);
121 gtk_object_add_arg_type ("GstFakeSrc::output", GST_TYPE_FAKESRC_OUTPUT,
122 GTK_ARG_READWRITE, ARG_OUTPUT);
123 gtk_object_add_arg_type ("GstFakeSrc::pattern", GTK_TYPE_STRING,
124 GTK_ARG_READWRITE, ARG_PATTERN);
125 gtk_object_add_arg_type ("GstFakeSrc::num_buffers", GTK_TYPE_INT,
126 GTK_ARG_READWRITE, ARG_NUM_BUFFERS);
128 gtkobject_class->set_arg = gst_fakesrc_set_arg;
129 gtkobject_class->get_arg = gst_fakesrc_get_arg;
131 gst_fakesrc_signals[SIGNAL_HANDOFF] =
132 gtk_signal_new ("handoff", GTK_RUN_LAST, gtkobject_class->type,
133 GTK_SIGNAL_OFFSET (GstFakeSrcClass, handoff),
134 gtk_marshal_NONE__NONE, GTK_TYPE_NONE, 0);
136 gtk_object_class_add_signals (gtkobject_class, gst_fakesrc_signals,
141 gst_fakesrc_init (GstFakeSrc *fakesrc)
145 // set the default number of
146 fakesrc->numsrcpads = 1;
148 // create our first output pad
149 pad = gst_pad_new("src",GST_PAD_SRC);
150 gst_element_add_pad(GST_ELEMENT(fakesrc),pad);
151 fakesrc->srcpads = g_slist_append(NULL,pad);
153 fakesrc->loop_based = TRUE;
155 if (fakesrc->loop_based)
156 gst_element_set_loop_function (GST_ELEMENT (fakesrc), gst_fakesrc_loop);
158 gst_pad_set_get_function(pad,gst_fakesrc_get);
160 fakesrc->num_buffers = -1;
161 // we're ready right away, since we don't have any args...
162 // gst_element_set_state(GST_ELEMENT(fakesrc),GST_STATE_READY);
166 gst_fakesrc_update_functions (GstFakeSrc *src)
172 GstPad *pad = GST_PAD (pads->data);
174 if (src->loop_based) {
175 gst_element_set_loop_function (GST_ELEMENT (src), gst_fakesrc_loop);
176 gst_pad_set_get_function (pad, NULL);
179 gst_pad_set_get_function (pad, gst_fakesrc_get);
180 gst_element_set_loop_function (GST_ELEMENT (src), NULL);
182 pads = g_slist_next (pads);
187 gst_fakesrc_set_arg (GtkObject *object, GtkArg *arg, guint id)
193 /* it's not null if we got it, but it might not be ours */
194 src = GST_FAKESRC (object);
197 case ARG_NUM_SOURCES:
198 new_numsrcs = GTK_VALUE_INT (*arg);
199 if (new_numsrcs > src->numsrcpads) {
200 while (src->numsrcpads != new_numsrcs) {
201 pad = gst_pad_new(g_strdup_printf("src%d",src->numsrcpads),GST_PAD_SRC);
202 gst_element_add_pad(GST_ELEMENT(src),pad);
203 src->srcpads = g_slist_append(src->srcpads,pad);
206 gst_fakesrc_update_functions (src);
210 src->loop_based = GTK_VALUE_BOOL (*arg);
211 gst_fakesrc_update_functions (src);
217 case ARG_NUM_BUFFERS:
218 src->num_buffers = GTK_VALUE_INT (*arg);
226 gst_fakesrc_get_arg (GtkObject *object, GtkArg *arg, guint id)
230 /* it's not null if we got it, but it might not be ours */
231 g_return_if_fail (GST_IS_FAKESRC (object));
233 src = GST_FAKESRC (object);
236 case ARG_NUM_SOURCES:
237 GTK_VALUE_INT (*arg) = src->numsrcpads;
240 GTK_VALUE_BOOL (*arg) = src->loop_based;
243 GTK_VALUE_INT (*arg) = src->output;
246 GTK_VALUE_STRING (*arg) = src->pattern;
248 case ARG_NUM_BUFFERS:
249 GTK_VALUE_INT (*arg) = src->num_buffers;
252 arg->type = GTK_TYPE_INVALID;
260 * @src: the faksesrc to get
262 * generate an empty buffer and return it
264 * Returns: a new empty buffer
267 gst_fakesrc_get(GstPad *pad)
272 g_return_val_if_fail (pad != NULL, NULL);
274 src = GST_FAKESRC (gst_pad_get_parent (pad));
276 g_return_val_if_fail (GST_IS_FAKESRC (src), NULL);
278 if (src->num_buffers == 0) {
279 gst_pad_set_eos (pad);
283 if (src->num_buffers > 0)
287 g_print("fakesrc: ******* (%s:%s)> \n",GST_DEBUG_PAD_NAME(pad));
288 buf = gst_buffer_new();
290 gtk_signal_emit (GTK_OBJECT (src), gst_fakesrc_signals[SIGNAL_HANDOFF],
298 * @element: the faksesrc to loop
300 * generate an empty buffer and push it to the next element.
303 gst_fakesrc_loop(GstElement *element)
307 g_return_if_fail(element != NULL);
308 g_return_if_fail(GST_IS_FAKESRC(element));
310 src = GST_FAKESRC (element);
318 GstPad *pad = GST_PAD (pads->data);
321 if (src->num_buffers == 0) {
322 gst_pad_set_eos (pad);
326 if (src->num_buffers > 0)
330 buf = gst_buffer_new();
331 g_print("fakesrc: ******* (%s:%s)> \n",GST_DEBUG_PAD_NAME(pad));
333 gtk_signal_emit (GTK_OBJECT (src), gst_fakesrc_signals[SIGNAL_HANDOFF],
335 gst_pad_push (pad, buf);
337 pads = g_slist_next (pads);
339 } while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element));