First THREADED backport attempt, focusing on adding locks and making sure the API...
[platform/upstream/gstreamer.git] / gst / gstbin.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstbin.h: Header for GstBin container object
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 #ifndef __GST_BIN_H__
25 #define __GST_BIN_H__
26
27 #include <gst/gstelement.h>
28 #include <gst/gstiterator.h>
29
30 G_BEGIN_DECLS
31
32 GST_EXPORT GType _gst_bin_type;
33
34 #define GST_TYPE_BIN             (_gst_bin_type)
35 #define GST_IS_BIN(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_BIN))
36 #define GST_IS_BIN_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_BIN))
37 #define GST_BIN_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BIN, GstBinClass))
38 #define GST_BIN(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_BIN, GstBin))
39 #define GST_BIN_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_BIN, GstBinClass))
40 #define GST_BIN_CAST(obj)        ((GstBin*)(obj))
41
42 /**
43  * GstBinFlags:
44  * @GST_BIN_FLAG_MANAGER: this bin is a manager of child elements, i.e.
45  * a pipeline or thread.
46  * @GST_BIN_SELF_SCHEDULABLE: the bin iterates itself.
47  * @GST_BIN_FLAG_PREFER_COTHREADS: we prefer to have cothreads when its
48  * an option, over chain-based.
49  * @GST_BIN_FLAG_FIXED_CLOCK: bin has one clock that cannot be changed.
50  * @GST_BIN_STATE_LOCKED: indicator that we are in a non-recursive
51  * state-change on the bin, or that kids should not change parent state.
52  * Both are internally used to prevent infinitely recursive loops of
53  * state changes. Since they are mutually exclusive and serve the same
54  * purpose, we use the same flag for them.
55  * @GST_BIN_FLAG_LAST: the last enum in the series of flags in a bin,
56  * derived classes can use this as first value in a list of flags.
57  *
58  * GstBinFlags are a set of flags specific to bins. Most are set/used
59  * internally. They can be checked using the GST_FLAG_IS_SET () macro,
60  * and (un)set using GST_FLAG_SET () and GST_FLAG_UNSET ().
61  */
62 typedef enum {
63   GST_BIN_FLAG_FIXED_CLOCK              = GST_ELEMENT_FLAG_LAST,
64   GST_BIN_FLAG_MANAGER,
65   GST_BIN_SELF_SCHEDULABLE,
66   GST_BIN_STATE_LOCKED,
67   /* padding */
68   GST_BIN_FLAG_LAST             = GST_ELEMENT_FLAG_LAST + 5
69 } GstBinFlags;
70
71 /*typedef struct _GstBin GstBin; */
72 /*typedef struct _GstBinClass GstBinClass; */
73
74 #define GST_BIN_NUMCHILDREN(bin)        (GST_BIN_CAST(bin)->numchildren);
75 #define GST_BIN_CHILDREN(bin)           (GST_BIN_CAST(bin)->children);
76 #define GST_BIN_CHILDREN_COOKIE(bin)    (GST_BIN_CAST(bin)->children_cookie);
77
78 struct _GstBin {
79   GstElement     element;
80
81   /*< public >*/ /* with LOCK */
82   /* our children, subclass are supposed to update these
83    * fields to reflect their state with _iterate_*() */
84   gint           numchildren;
85   GList         *children;
86   guint32        children_cookie;
87
88   GstElementState child_states[GST_NUM_STATES];
89
90   /*< private >*/
91   gpointer _gst_reserved[GST_PADDING];
92 };
93
94 struct _GstBinClass {
95   GstElementClass parent_class;
96
97   /*< public >*/
98
99   /* run a full iteration of operation */
100   gboolean      (*iterate)              (GstBin *bin);
101   void          (*child_state_change)   (GstBin *bin, GstElementState oldstate, 
102                                          GstElementState newstate, GstElement *element);
103
104
105   /* signals */
106   void          (*element_added)        (GstBin *bin, GstElement *child);
107   void          (*element_removed)      (GstBin *bin, GstElement *child);
108
109   /*< protected >*/
110   /* vtable */
111   gboolean      (*add_element)          (GstBin *bin, GstElement *element);
112   gboolean      (*remove_element)       (GstBin *bin, GstElement *element);
113
114   /*< private >*/
115   gpointer _gst_reserved[GST_PADDING];
116 };
117
118 GType           gst_bin_get_type                (void);
119 GstElement*     gst_bin_new                     (const gchar *name);
120
121 /* add and remove elements from the bin */
122 gboolean        gst_bin_add                     (GstBin *bin, GstElement *element);
123 gboolean        gst_bin_remove                  (GstBin *bin, GstElement *element);
124
125 /* retrieve a single child */
126 GstElement*     gst_bin_get_by_name              (GstBin *bin, const gchar *name);
127 GstElement*     gst_bin_get_by_name_recurse_up   (GstBin *bin, const gchar *name);
128 GstElement*     gst_bin_get_by_interface         (GstBin *bin, GType interface);
129
130 /* retrieve multiple children */
131 GstIterator*    gst_bin_iterate_elements         (GstBin *bin);
132 GstIterator*    gst_bin_iterate_recurse          (GstBin *bin);
133 GstIterator*    gst_bin_iterate_recurse_up       (GstBin *bin);
134
135 GstIterator*    gst_bin_iterate_sinks            (GstBin *bin);
136 GstIterator*    gst_bin_iterate_all_by_interface (GstBin *bin, GType interface);
137
138 gboolean        gst_bin_iterate                 (GstBin *bin);
139
140 GstElementStateReturn gst_bin_sync_children_state (GstBin *bin);
141
142 /* internal */
143 /* one of our childs signaled a state change */
144 void            gst_bin_child_state_change              (GstBin *bin, GstElementState oldstate, 
145                                                          GstElementState newstate, GstElement *child);
146
147 G_END_DECLS
148
149
150 #endif /* __GST_BIN_H__ */