This is a megapatch with the following changes:
[platform/upstream/gstreamer.git] / gst / elements / gstidentity.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstidentity.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 <gstidentity.h>
25
26
27 GstElementDetails gst_identity_details = {
28   "Identity",
29   "Filter",
30   "Pass data without modification",
31   VERSION,
32   "Erik Walthinsen <omega@cse.ogi.edu>",
33   "(C) 1999",
34 };
35
36
37 /* Identity signals and args */
38 enum {
39   /* FILL ME */
40   LAST_SIGNAL
41 };
42
43 enum {
44   ARG_0,
45   ARG_LOOP_BASED,
46   ARG_SLEEP_TIME,
47 };
48
49
50 static void gst_identity_class_init     (GstIdentityClass *klass);
51 static void gst_identity_init           (GstIdentity *identity);
52
53 static void gst_identity_set_arg        (GtkObject *object, GtkArg *arg, guint id);
54 static void gst_identity_get_arg        (GtkObject *object, GtkArg *arg, guint id);
55
56 static void gst_identity_chain          (GstPad *pad, GstBuffer *buf);
57
58 static GstElementClass *parent_class = NULL;
59 //static guint gst_identity_signals[LAST_SIGNAL] = { 0 };
60
61 GtkType
62 gst_identity_get_type (void) 
63 {
64   static GtkType identity_type = 0;
65
66   if (!identity_type) {
67     static const GtkTypeInfo identity_info = {
68       "GstIdentity",
69       sizeof(GstIdentity),
70       sizeof(GstIdentityClass),
71       (GtkClassInitFunc)gst_identity_class_init,
72       (GtkObjectInitFunc)gst_identity_init,
73       (GtkArgSetFunc)gst_identity_set_arg,
74       (GtkArgGetFunc)gst_identity_get_arg,
75       (GtkClassInitFunc)NULL,
76     };
77     identity_type = gtk_type_unique (GST_TYPE_ELEMENT, &identity_info);
78   }
79   return identity_type;
80 }
81
82 static void 
83 gst_identity_class_init (GstIdentityClass *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 ("GstIdentity::loop_based", GTK_TYPE_BOOL,
92                            GTK_ARG_READWRITE, ARG_LOOP_BASED);
93   gtk_object_add_arg_type ("GstIdentity::sleep_time", GTK_TYPE_UINT,
94                            GTK_ARG_READWRITE, ARG_SLEEP_TIME);
95
96   gtkobject_class->set_arg = gst_identity_set_arg;  
97   gtkobject_class->get_arg = gst_identity_get_arg;
98 }
99
100 static void 
101 gst_identity_init (GstIdentity *identity) 
102 {
103   identity->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
104   gst_element_add_pad (GST_ELEMENT (identity), identity->sinkpad);
105   gst_pad_set_chain_function (identity->sinkpad, gst_identity_chain);
106   
107   identity->srcpad = gst_pad_new ("src", GST_PAD_SRC);
108   gst_element_add_pad (GST_ELEMENT (identity), identity->srcpad);
109
110   identity->loop_based = FALSE;
111   identity->sleep_time = 10000;
112 }
113
114 static void 
115 gst_identity_chain (GstPad *pad, GstBuffer *buf) 
116 {
117   GstIdentity *identity;
118
119   g_return_if_fail (pad != NULL);
120   g_return_if_fail (GST_IS_PAD (pad));
121   g_return_if_fail (buf != NULL);
122
123   identity = GST_IDENTITY (gst_pad_get_parent (pad));
124   g_print("identity: ******* (%s:%s)i \n",GST_DEBUG_PAD_NAME(pad));
125   
126   gst_pad_push (identity->srcpad, buf);
127
128   usleep (identity->sleep_time);
129 }
130
131 static void 
132 gst_identity_loop (GstElement *element) 
133 {
134   GstIdentity *identity;
135   GstBuffer *buf;
136
137   g_return_if_fail (element != NULL);
138   g_return_if_fail (GST_IS_IDENTITY (element));
139
140   identity = GST_IDENTITY (element);
141   
142   do {
143     buf = gst_pad_pull (identity->sinkpad);
144     g_print("identity: ******* (%s:%s)i \n",GST_DEBUG_PAD_NAME(identity->sinkpad));
145
146     gst_pad_push (identity->srcpad, buf);
147
148     usleep (identity->sleep_time);
149
150   } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element));
151 }
152
153 static void 
154 gst_identity_set_arg (GtkObject *object, GtkArg *arg, guint id) 
155 {
156   GstIdentity *identity;
157
158   /* it's not null if we got it, but it might not be ours */
159   g_return_if_fail (GST_IS_IDENTITY (object));
160   
161   identity = GST_IDENTITY (object);
162
163   switch(id) {
164     case ARG_LOOP_BASED:
165       identity->loop_based = GTK_VALUE_BOOL (*arg);
166       if (identity->loop_based) {
167         gst_element_set_loop_function (GST_ELEMENT (identity), gst_identity_loop);
168         gst_pad_set_chain_function (identity->sinkpad, NULL);
169       }
170       else {
171         gst_pad_set_chain_function (identity->sinkpad, gst_identity_chain);
172         gst_element_set_loop_function (GST_ELEMENT (identity), NULL);
173       }
174       break;
175     case ARG_SLEEP_TIME:
176       identity->sleep_time = GTK_VALUE_UINT (*arg);
177       break;
178     default:
179       break;
180   }
181 }
182
183 static void gst_identity_get_arg(GtkObject *object,GtkArg *arg,guint id) {
184   GstIdentity *identity;
185
186   /* it's not null if we got it, but it might not be ours */
187   g_return_if_fail (GST_IS_IDENTITY (object));
188   
189   identity = GST_IDENTITY (object);
190
191   switch (id) {
192     case ARG_LOOP_BASED:
193       GTK_VALUE_BOOL (*arg) = identity->loop_based;
194       break;
195     case ARG_SLEEP_TIME:
196       GTK_VALUE_UINT (*arg) = identity->sleep_time;
197       break;
198     default:
199       arg->type = GTK_TYPE_INVALID;
200       break;
201   }
202 }