BEAST/BSE - Better Audio System and Sound Engine
0.8.2
|
00001 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html 00002 #ifndef __BSE_ENGINE_NODE_H__ 00003 #define __BSE_ENGINE_NODE_H__ 00004 00005 #include "bseengine.hh" 00006 #include "gslcommon.hh" 00007 00008 G_BEGIN_DECLS 00009 00010 #define ENGINE_NODE(module) ((EngineNode*) (module)) 00011 #define ENGINE_NODE_N_OSTREAMS(node) ((node)->module.klass->n_ostreams) 00012 #define ENGINE_NODE_N_ISTREAMS(node) ((node)->module.klass->n_istreams) 00013 #define ENGINE_NODE_N_JSTREAMS(node) ((node)->module.klass->n_jstreams) 00014 #define ENGINE_NODE_IS_CONSUMER(node) ((node)->is_consumer && \ 00015 (node)->output_nodes == NULL) 00016 #define ENGINE_NODE_IS_INTEGRATED(node) ((node)->integrated) 00017 #define ENGINE_NODE_IS_VIRTUAL(node) ((node)->virtual_node) 00018 #define ENGINE_NODE_IS_SUSPENDED(nod,s) ((s) < (nod)->next_active) 00019 #define ENGINE_NODE_IS_DEFERRED(node) (FALSE) 00020 #define ENGINE_NODE_IS_SCHEDULED(node) (ENGINE_NODE (node)->sched_tag) 00021 #define ENGINE_NODE_IS_CHEAP(node) (((node)->module.klass->mflags & BSE_COST_CHEAP) != 0) 00022 #define ENGINE_NODE_IS_EXPENSIVE(node) (((node)->module.klass->mflags & BSE_COST_EXPENSIVE) != 0) 00023 #define ENGINE_NODE_LOCK(node) (node)->rec_mutex.lock() 00024 #define ENGINE_NODE_UNLOCK(node) (node)->rec_mutex.unlock() 00025 #define ENGINE_MODULE_IS_VIRTUAL(mod) (ENGINE_NODE_IS_VIRTUAL (ENGINE_NODE (mod))) 00026 00027 00028 /* --- typedefs --- */ 00029 typedef struct _EngineNode EngineNode; 00030 typedef struct _EngineSchedule EngineSchedule; 00031 00032 /* --- transactions --- */ 00033 typedef union _EngineTimedJob EngineTimedJob; 00034 typedef enum /*< skip >*/ 00035 { 00036 ENGINE_JOB_NOP, 00037 ENGINE_JOB_SYNC, 00038 ENGINE_JOB_INTEGRATE, 00039 ENGINE_JOB_DISCARD, 00040 ENGINE_JOB_ICONNECT, 00041 ENGINE_JOB_JCONNECT, 00042 ENGINE_JOB_IDISCONNECT, 00043 ENGINE_JOB_JDISCONNECT, 00044 ENGINE_JOB_KILL_INPUTS, 00045 ENGINE_JOB_KILL_OUTPUTS, 00046 ENGINE_JOB_SET_CONSUMER, 00047 ENGINE_JOB_UNSET_CONSUMER, 00048 ENGINE_JOB_FORCE_RESET, 00049 ENGINE_JOB_ACCESS, 00050 ENGINE_JOB_SUSPEND, 00051 ENGINE_JOB_RESUME, 00052 ENGINE_JOB_ADD_POLL, 00053 ENGINE_JOB_REMOVE_POLL, 00054 ENGINE_JOB_ADD_TIMER, 00055 ENGINE_JOB_PROBE_JOB, 00056 ENGINE_JOB_FLOW_JOB, 00057 ENGINE_JOB_BOUNDARY_JOB, 00058 ENGINE_JOB_MESSAGE, 00059 ENGINE_JOB_LAST 00060 } EngineJobType; 00061 struct _BseJob 00062 { 00063 EngineJobType job_id; 00064 BseJob *next; 00065 union { 00066 struct { 00067 EngineNode *node; 00068 gboolean free_with_job; 00069 gchar *message; 00070 } data; 00071 struct { 00072 Bse::Mutex *lock_mutex; 00073 Bse::Cond *lock_cond; 00074 gboolean *lock_p; 00075 } sync; 00076 struct { 00077 EngineNode *node; 00078 guint64 stamp; 00079 } tick; 00080 struct { 00081 EngineNode *dest_node; 00082 guint dest_ijstream; 00083 EngineNode *src_node; 00084 guint src_ostream; 00085 } connection; 00086 struct { 00087 EngineNode *node; 00088 BseEngineAccessFunc access_func; 00089 gpointer data; 00090 BseFreeFunc free_func; 00091 } access; 00092 struct { 00093 BseEnginePollFunc poll_func; 00094 gpointer data; 00095 BseFreeFunc free_func; 00096 guint n_fds; 00097 GPollFD *fds; 00098 } poll; 00099 struct { 00100 BseEngineTimerFunc timer_func; 00101 gpointer data; 00102 BseFreeFunc free_func; 00103 } timer; 00104 struct { 00105 EngineNode *node; 00106 EngineTimedJob *tjob; 00107 } timed_job; 00108 }; 00109 }; 00110 struct _BseTrans 00111 { 00112 BseJob *jobs_head; 00113 BseJob *jobs_tail; 00114 guint comitted : 1; 00115 BseTrans *cqt_next; /* com-thread-queue */ 00116 }; 00117 union _EngineTimedJob 00118 { 00119 struct { 00120 EngineJobType type; /* common */ 00121 EngineTimedJob *next; /* common */ 00122 guint64 tick_stamp; /* common */ 00123 }; 00124 struct { 00125 EngineJobType type; /* common */ 00126 EngineTimedJob *next; /* common */ 00127 guint64 tick_stamp; /* common */ 00128 gpointer data; 00129 BseEngineProbeFunc probe_func; 00130 BseOStream *ostreams; 00131 guint n_ostreams; 00132 } probe; 00133 struct { 00134 EngineJobType type; /* common */ 00135 EngineTimedJob *next; /* common */ 00136 guint64 tick_stamp; /* common */ 00137 gpointer data; 00138 BseFreeFunc free_func; 00139 BseEngineAccessFunc access_func; 00140 } access; 00141 }; 00142 00143 00144 /* --- module nodes --- */ 00145 typedef struct 00146 { 00147 EngineNode *src_node; 00148 guint src_stream; /* ostream of src_node */ 00149 /* valid if istream[].connected, setup by scheduler */ 00150 EngineNode *real_node; /* set to NULL if !connected */ 00151 guint real_stream; /* ostream of real_node */ 00152 } EngineInput; 00153 typedef struct 00154 { 00155 EngineNode *src_node; 00156 guint src_stream; /* ostream of src_node */ 00157 /* valid if < jstream[].n_connections, setup by scheduler */ 00158 EngineNode *real_node; 00159 guint real_stream; /* ostream of real_node */ 00160 } EngineJInput; 00161 typedef struct 00162 { 00163 gfloat *buffer; 00164 guint n_outputs; 00165 } EngineOutput; 00166 struct _EngineNode /* fields sorted by order of processing access */ 00167 { 00168 BseModule module; 00169 Bse::Mutex rec_mutex; /* processing lock */ 00170 guint64 counter; /* <= Bse::TickStamp::current() */ 00171 EngineInput *inputs; /* [ENGINE_NODE_N_ISTREAMS()] */ 00172 EngineJInput **jinputs; /* [ENGINE_NODE_N_JSTREAMS()][jstream->jcount] */ 00173 EngineOutput *outputs; /* [ENGINE_NODE_N_OSTREAMS()] */ 00174 /* timed jobs */ 00175 EngineTimedJob *flow_jobs; /* active jobs */ 00176 EngineTimedJob *probe_jobs; /* probe requests */ 00177 EngineTimedJob *boundary_jobs; /* active jobs */ 00178 EngineTimedJob *tjob_head, *tjob_tail; /* trash list */ 00179 /* suspend/activation time */ 00180 guint64 next_active; /* result of suspend state updates */ 00181 /* master-node-list */ 00182 EngineNode *mnl_next; 00183 EngineNode *mnl_prev; 00184 guint integrated : 1; 00185 guint virtual_node : 1; 00186 guint is_consumer : 1; 00187 /* suspension */ 00188 guint update_suspend : 1; /* whether suspend state needs updating */ 00189 guint in_suspend_call : 1; /* recursion barrier during suspend state updates */ 00190 guint needs_reset : 1; /* flagged at resumption */ 00191 /* scheduler */ 00192 guint cleared_ostreams : 1; /* whether ostream[].connected was cleared already */ 00193 guint sched_tag : 1; /* whether this node is contained in the schedule */ 00194 guint sched_recurse_tag : 1; /* recursion flag used during scheduling */ 00195 guint sched_leaf_level; 00196 guint64 local_active; /* local suspend state stamp */ 00197 EngineNode *toplevel_next; /* master-consumer-list, FIXME: overkill, using a SfiRing is good enough */ 00198 SfiRing *output_nodes; /* EngineNode* ring of nodes in ->outputs[] */ 00199 }; 00200 00201 G_END_DECLS 00202 00203 #endif /* __BSE_ENGINE_NODE_H__ */