2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #ifndef __GST_ELEMENT_H__
22 #define __GST_ELEMENT_H__
25 #include <gnome-xml/parser.h>
26 #include <gst/gstlog.h>
27 #include <gst/gstobject.h>
28 #include <gst/gstpad.h>
29 #include <gst/cothreads.h>
34 #endif /* __cplusplus */
38 GST_STATE_NONE_PENDING = -1,
41 GST_STATE_PLAYING = 2,
46 GST_STATE_FAILURE = 0,
47 GST_STATE_SUCCESS = 1,
49 } GstElementStateReturn;
51 static inline char *_gst_print_statename(int state) {
53 case -1: return "none pending";break;
54 case 0: return "null";break;
55 case 1: return "ready";break;
56 case 2: return "playing";break;
57 case 3: return "paused";break;
63 #define GST_STATE(obj) (GST_ELEMENT(obj)->current_state)
64 #define GST_STATE_PENDING(obj) (GST_ELEMENT(obj)->pending_state)
66 #define GST_STATE_TRANSITION(obj) ((GST_STATE(obj)<<4) | GST_STATE_PENDING(obj))
67 #define GST_STATE_NULL_TO_READY ((GST_STATE_NULL<<4) | GST_STATE_READY)
68 #define GST_STATE_READY_TO_PLAYING ((GST_STATE_READY<<4) | GST_STATE_PLAYING)
69 #define GST_STATE_PLAYING_TO_PAUSED ((GST_STATE_PLAYING<<4) | GST_STATE_PAUSED)
70 #define GST_STATE_PAUSED_TO_PLAYING ((GST_STATE_PAUSED<<4) | GST_STATE_PLAYING)
71 #define GST_STATE_PLAYING_TO_READY ((GST_STATE_PLAYING<<4) | GST_STATE_READY)
72 #define GST_STATE_READY_TO_NULL ((GST_STATE_READY<<4) | GST_STATE_NULL)
74 #define GST_TYPE_ELEMENT \
75 (gst_element_get_type())
76 #define GST_ELEMENT(obj) \
77 (GTK_CHECK_CAST((obj),GST_TYPE_ELEMENT,GstElement))
78 #define GST_ELEMENT_CLASS(klass) \
79 (GTK_CHECK_CLASS_CAST((klass),GST_TYPE_ELEMENT,GstElementClass))
80 #define GST_IS_ELEMENT(obj) \
81 (GTK_CHECK_TYPE((obj),GST_TYPE_ELEMENT))
82 #define GST_IS_ELEMENT_CLASS(klass) \
83 (GTK_CHECK_CLASS_TYPE((klass),GST_TYPE_ELEMENT))
86 // element is complex (for some def.) and generally require a cothread
87 GST_ELEMENT_COMPLEX = GST_OBJECT_FLAG_LAST,
88 // input and output pads aren't directly coupled to each other
89 // examples: queues, multi-output async readers, etc.
90 GST_ELEMENT_DECOUPLED,
91 // this element should be placed in a thread if at all possible
92 GST_ELEMENT_THREAD_SUGGESTED,
93 // this element is incable of seeking (FIXME: does this apply to filters?)
96 // there is a new loopfunction ready for placement
97 GST_ELEMENT_NEW_LOOPFUNC,
98 // the cothread holding this element needs to be stopped
99 GST_ELEMENT_COTHREAD_STOPPING,
100 // the element has to be scheduled as a cothread for any sanity
101 GST_ELEMENT_USE_COTHREAD,
103 /* use some padding for future expansion */
104 GST_ELEMENT_FLAG_LAST = GST_OBJECT_FLAG_LAST + 8,
107 #define GST_ELEMENT_IS_THREAD_SUGGESTED(obj) (GST_FLAG_IS_SET(obj,GST_ELEMENT_THREAD_SUGGESTED))
108 #define GST_ELEMENT_IS_COTHREAD_STOPPING(obj) (GST_FLAG_IS_SET(obj,GST_ELEMENT_COTHREAD_STOPPING))
111 typedef struct _GstElement GstElement;
112 typedef struct _GstElementClass GstElementClass;
113 typedef struct _GstElementDetails GstElementDetails;
114 typedef struct _GstElementFactory GstElementFactory;
116 typedef void (*GstElementLoopFunction) (GstElement *element);
123 guint8 current_state;
124 guint8 pending_state;
126 GstElementLoopFunction loopfunc;
127 cothread_state *threadstate;
137 struct _GstElementClass {
138 GstObjectClass parent_class;
140 /* the elementfactory that created us */
141 GstElementFactory *elementfactory;
143 /* signal callbacks */
144 void (*state_change) (GstElement *element,GstElementState state);
145 void (*new_pad) (GstElement *element,GstPad *pad);
146 void (*new_ghost_pad) (GstElement *element,GstPad *pad);
147 void (*error) (GstElement *element,gchar *error);
150 // gboolean (*start) (GstElement *element,GstElementState state);
151 // gboolean (*stop) (GstElement *element);
153 /* change the element state */
154 GstElementStateReturn (*change_state) (GstElement *element);
156 /* create or read XML representation of self */
157 xmlNodePtr (*save_thyself) (GstElement *element, xmlNodePtr parent);
158 void (*restore_thyself) (GstElement *element, xmlNodePtr self, GHashTable *elements);
161 struct _GstElementDetails {
162 gchar *longname; /* long, english name */
163 gchar *klass; /* type of element, kinda */
164 gchar *description; /* insights of one form or another */
165 gchar *version; /* version of the element */
166 gchar *author; /* who wrote this thing? */
167 gchar *copyright; /* copyright details (year, etc.) */
170 struct _GstElementFactory {
171 gchar *name; /* name of element */
172 GtkType type; /* unique GtkType of element */
174 GstElementDetails *details; /* pointer to details struct */
179 GtkType gst_element_get_type (void);
180 GstElement* gst_element_new (void);
181 #define gst_element_destroy(element) gst_object_destroy (GST_OBJECT (element))
183 void gst_element_set_loop_function (GstElement *element,
184 GstElementLoopFunction loop);
186 void gst_element_set_name (GstElement *element, gchar *name);
187 const gchar* gst_element_get_name (GstElement *element);
189 void gst_element_set_manager (GstElement *element, GstElement *manager);
190 GstElement* gst_element_get_manager (GstElement *element);
192 void gst_element_add_pad (GstElement *element, GstPad *pad);
193 GstPad* gst_element_get_pad (GstElement *element, gchar *name);
194 GList* gst_element_get_pad_list (GstElement *element);
195 void gst_element_add_ghost_pad (GstElement *element, GstPad *pad);
197 void gst_element_connect (GstElement *src, gchar *srcpadname,
198 GstElement *dest, gchar *destpadname);
200 /* called by the app to set the state of the element */
201 gint gst_element_set_state (GstElement *element, GstElementState state);
203 void gst_element_error (GstElement *element, gchar *error);
205 GstElementFactory* gst_element_get_factory (GstElement *element);
206 int gst_element_loopfunc_wrapper (int argc,char **argv);
208 /* XML write and read */
209 xmlNodePtr gst_element_save_thyself (GstElement *element, xmlNodePtr parent);
210 GstElement* gst_element_load_thyself (xmlNodePtr parent, GHashTable *elements);
218 GstElementFactory* gst_elementfactory_new (gchar *name,GtkType type,
219 GstElementDetails *details);
220 void gst_elementfactory_destroy (GstElementFactory *elementfactory);
222 void gst_elementfactory_add_padtemplate (GstElementFactory *elementfactory,
223 GstPadTemplate *pad);
225 GstElementFactory* gst_elementfactory_find (gchar *name);
226 GList* gst_elementfactory_get_list (void);
228 gboolean gst_elementfactory_can_src_caps (GstElementFactory *factory,
230 gboolean gst_elementfactory_can_sink_caps (GstElementFactory *factory,
233 GstElement* gst_elementfactory_create (GstElementFactory *factory,
235 // FIXME this name is wrong, probably so is the one above it
236 GstElement* gst_elementfactory_make (gchar *factoryname, gchar *name);
238 xmlNodePtr gst_elementfactory_save_thyself (GstElementFactory *factory, xmlNodePtr parent);
239 GstElementFactory* gst_elementfactory_load_thyself (xmlNodePtr parent);
243 #endif /* __cplusplus */
246 #endif /* __GST_ELEMENT_H__ */