BEAST/BSE - Better Audio System and Sound Engine  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bseenginenode.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __BSE_ENGINE_NODE_H__
3 #define __BSE_ENGINE_NODE_H__
4 
5 #include "bseengine.hh"
6 #include "gslcommon.hh"
7 
8 G_BEGIN_DECLS
9 
10 #define ENGINE_NODE(module) ((EngineNode*) (module))
11 #define ENGINE_NODE_N_OSTREAMS(node) ((node)->module.klass->n_ostreams)
12 #define ENGINE_NODE_N_ISTREAMS(node) ((node)->module.klass->n_istreams)
13 #define ENGINE_NODE_N_JSTREAMS(node) ((node)->module.klass->n_jstreams)
14 #define ENGINE_NODE_IS_CONSUMER(node) ((node)->is_consumer && \
15  (node)->output_nodes == NULL)
16 #define ENGINE_NODE_IS_INTEGRATED(node) ((node)->integrated)
17 #define ENGINE_NODE_IS_VIRTUAL(node) ((node)->virtual_node)
18 #define ENGINE_NODE_IS_SUSPENDED(nod,s) ((s) < (nod)->next_active)
19 #define ENGINE_NODE_IS_DEFERRED(node) (FALSE)
20 #define ENGINE_NODE_IS_SCHEDULED(node) (ENGINE_NODE (node)->sched_tag)
21 #define ENGINE_NODE_IS_CHEAP(node) (((node)->module.klass->mflags & BSE_COST_CHEAP) != 0)
22 #define ENGINE_NODE_IS_EXPENSIVE(node) (((node)->module.klass->mflags & BSE_COST_EXPENSIVE) != 0)
23 #define ENGINE_NODE_LOCK(node) (node)->rec_mutex.lock()
24 #define ENGINE_NODE_UNLOCK(node) (node)->rec_mutex.unlock()
25 #define ENGINE_MODULE_IS_VIRTUAL(mod) (ENGINE_NODE_IS_VIRTUAL (ENGINE_NODE (mod)))
26 
27 
28 /* --- typedefs --- */
29 typedef struct _EngineNode EngineNode;
30 typedef struct _EngineSchedule EngineSchedule;
31 
32 /* --- transactions --- */
33 typedef union _EngineTimedJob EngineTimedJob;
34 typedef enum /*< skip >*/
35 {
36  ENGINE_JOB_NOP,
37  ENGINE_JOB_SYNC,
38  ENGINE_JOB_INTEGRATE,
39  ENGINE_JOB_DISCARD,
40  ENGINE_JOB_ICONNECT,
41  ENGINE_JOB_JCONNECT,
42  ENGINE_JOB_IDISCONNECT,
43  ENGINE_JOB_JDISCONNECT,
44  ENGINE_JOB_KILL_INPUTS,
45  ENGINE_JOB_KILL_OUTPUTS,
46  ENGINE_JOB_SET_CONSUMER,
47  ENGINE_JOB_UNSET_CONSUMER,
48  ENGINE_JOB_FORCE_RESET,
49  ENGINE_JOB_ACCESS,
50  ENGINE_JOB_SUSPEND,
51  ENGINE_JOB_RESUME,
52  ENGINE_JOB_ADD_POLL,
53  ENGINE_JOB_REMOVE_POLL,
54  ENGINE_JOB_ADD_TIMER,
55  ENGINE_JOB_PROBE_JOB,
56  ENGINE_JOB_FLOW_JOB,
57  ENGINE_JOB_BOUNDARY_JOB,
58  ENGINE_JOB_MESSAGE,
59  ENGINE_JOB_LAST
60 } EngineJobType;
61 struct _BseJob
62 {
63  EngineJobType job_id;
64  BseJob *next;
65  union {
66  struct {
67  EngineNode *node;
68  gboolean free_with_job;
69  gchar *message;
70  } data;
71  struct {
72  Bse::Mutex *lock_mutex;
73  Bse::Cond *lock_cond;
74  gboolean *lock_p;
75  } sync;
76  struct {
77  EngineNode *node;
78  guint64 stamp;
79  } tick;
80  struct {
81  EngineNode *dest_node;
82  guint dest_ijstream;
83  EngineNode *src_node;
84  guint src_ostream;
85  } connection;
86  struct {
87  EngineNode *node;
88  BseEngineAccessFunc access_func;
89  gpointer data;
90  BseFreeFunc free_func;
91  } access;
92  struct {
93  BseEnginePollFunc poll_func;
94  gpointer data;
95  BseFreeFunc free_func;
96  guint n_fds;
97  GPollFD *fds;
98  } poll;
99  struct {
100  BseEngineTimerFunc timer_func;
101  gpointer data;
102  BseFreeFunc free_func;
103  } timer;
104  struct {
105  EngineNode *node;
106  EngineTimedJob *tjob;
107  } timed_job;
108  };
109 };
110 struct _BseTrans
111 {
112  BseJob *jobs_head;
113  BseJob *jobs_tail;
114  guint comitted : 1;
115  BseTrans *cqt_next; /* com-thread-queue */
116 };
118 {
119  struct {
120  EngineJobType type; /* common */
121  EngineTimedJob *next; /* common */
122  guint64 tick_stamp; /* common */
123  };
124  struct {
125  EngineJobType type; /* common */
126  EngineTimedJob *next; /* common */
127  guint64 tick_stamp; /* common */
128  gpointer data;
129  BseEngineProbeFunc probe_func;
130  BseOStream *ostreams;
131  guint n_ostreams;
132  } probe;
133  struct {
134  EngineJobType type; /* common */
135  EngineTimedJob *next; /* common */
136  guint64 tick_stamp; /* common */
137  gpointer data;
138  BseFreeFunc free_func;
139  BseEngineAccessFunc access_func;
140  } access;
141 };
142 
143 
144 /* --- module nodes --- */
145 typedef struct
146 {
147  EngineNode *src_node;
148  guint src_stream; /* ostream of src_node */
149  /* valid if istream[].connected, setup by scheduler */
150  EngineNode *real_node; /* set to NULL if !connected */
151  guint real_stream; /* ostream of real_node */
152 } EngineInput;
153 typedef struct
154 {
155  EngineNode *src_node;
156  guint src_stream; /* ostream of src_node */
157  /* valid if < jstream[].n_connections, setup by scheduler */
158  EngineNode *real_node;
159  guint real_stream; /* ostream of real_node */
160 } EngineJInput;
161 typedef struct
162 {
163  gfloat *buffer;
164  guint n_outputs;
165 } EngineOutput;
166 struct _EngineNode /* fields sorted by order of processing access */
167 {
168  BseModule module;
169  Bse::Mutex rec_mutex; /* processing lock */
170  guint64 counter; /* <= Bse::TickStamp::current() */
171  EngineInput *inputs; /* [ENGINE_NODE_N_ISTREAMS()] */
172  EngineJInput **jinputs; /* [ENGINE_NODE_N_JSTREAMS()][jstream->jcount] */
173  EngineOutput *outputs; /* [ENGINE_NODE_N_OSTREAMS()] */
174  /* timed jobs */
175  EngineTimedJob *flow_jobs; /* active jobs */
176  EngineTimedJob *probe_jobs; /* probe requests */
177  EngineTimedJob *boundary_jobs; /* active jobs */
178  EngineTimedJob *tjob_head, *tjob_tail; /* trash list */
179  /* suspend/activation time */
180  guint64 next_active; /* result of suspend state updates */
181  /* master-node-list */
182  EngineNode *mnl_next;
183  EngineNode *mnl_prev;
184  guint integrated : 1;
185  guint virtual_node : 1;
186  guint is_consumer : 1;
187  /* suspension */
188  guint update_suspend : 1; /* whether suspend state needs updating */
189  guint in_suspend_call : 1; /* recursion barrier during suspend state updates */
190  guint needs_reset : 1; /* flagged at resumption */
191  /* scheduler */
192  guint cleared_ostreams : 1; /* whether ostream[].connected was cleared already */
193  guint sched_tag : 1; /* whether this node is contained in the schedule */
194  guint sched_recurse_tag : 1; /* recursion flag used during scheduling */
195  guint sched_leaf_level;
196  guint64 local_active; /* local suspend state stamp */
197  EngineNode *toplevel_next; /* master-consumer-list, FIXME: overkill, using a SfiRing is good enough */
198  SfiRing *output_nodes; /* EngineNode* ring of nodes in ->outputs[] */
199 };
200 
201 G_END_DECLS
202 
203 #endif /* __BSE_ENGINE_NODE_H__ */
void(* BseEngineProbeFunc)(gpointer data, guint n_values, guint64 tick_stamp, guint n_ostreams, BseOStream **ostreams_p)
Definition: bseengine.hh:38
Definition: bseenginenode.hh:145
Definition: bseenginenode.hh:161
Definition: bseenginenode.hh:61
Definition: bseengineschedule.hh:21
void(* BseEngineAccessFunc)(BseModule *module, gpointer data)
Definition: bsedefs.hh:128
Definition: bseenginenode.hh:153
Definition: bseenginenode.hh:166
Definition: sfiring.hh:23
Definition: bseenginenode.hh:110
gboolean(* BseEnginePollFunc)(gpointer data, guint n_values, glong *timeout_p, guint n_fds, const GPollFD *fds, gboolean revents_filled)
Definition: bseengine.hh:30
Definition: bseenginenode.hh:117