]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
event: add public API to compute pool consumption when scheduling event
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 27 Jun 2022 08:46:54 +0000 (17:46 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 27 Jun 2022 08:46:54 +0000 (17:46 +0900)
In design of ALSA Sequencer, delivery of event consumes cell in client
pool. For usual event, it's one cell. For variable length of event, it's
multiple cells including the total length of event.

ALSASeq.ClientPool class has properties to express the number of cells
and free cells in client pool. When comparing to the properties,
applications get to know whether the scheduling operation is blocked or
not.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/seq/alsaseq.map
src/seq/event.c
src/seq/event.h
tests/alsaseq-event

index 73f9ab137be5f3fa3bd9c1bd15109475857b9934..7de2c8a0cb616066d501354605f71c16341450d7 100644 (file)
@@ -217,6 +217,7 @@ ALSA_GOBJECT_0_3_0 {
     "alsaseq_event_set_connect_data";
     "alsaseq_event_get_result_data";
     "alsaseq_event_set_result_data";
+    "alsaseq_event_calculate_pool_consumption";
 
     "alsaseq_user_client_schedule_events";
     "alsaseq_user_client_schedule_event";
index ca5872f68cf4582ec1ab91e420beacb0e605398a..4cf1f703513d1a1e3a02759ebea86d0dcdf7feb6 100644 (file)
@@ -1620,6 +1620,22 @@ gboolean alsaseq_event_set_result_data(ALSASeqEvent *self, const ALSASeqEventDat
     return TRUE;
 }
 
+/**
+ * alsaseq_event_calculate_pool_consumption:
+ * @self: A [struct@Event].
+ * @cells: (out): The number of consumed cells in client pool.
+ *
+ * Calculate the number of cells in client pool to be consumed when the event is delivered.
+ * The comparison to properties of [class@ClientPool] is useful when scheduling the event.
+ */
+void alsaseq_event_calculate_pool_consumption(const ALSASeqEvent *self, guint *cells)
+{
+    g_return_if_fail(self != NULL);
+    g_return_if_fail(cells != NULL);
+
+    *cells = seq_event_calculate_flattened_length(self, TRUE) / sizeof(*self);
+}
+
 void seq_event_copy_flattened(const ALSASeqEvent *self, guint8 *buf, gsize length)
 {
     memcpy(buf, self, sizeof(*self));
index 0d040f4f7777587ec0d14af5c11578b734801c4e..d18e5f41bd1bd4eaf760a689aa9797818e75d1ea 100644 (file)
@@ -107,6 +107,8 @@ gboolean alsaseq_event_get_result_data(const ALSASeqEvent *self,
 gboolean alsaseq_event_set_result_data(ALSASeqEvent *self, const ALSASeqEventDataResult *data,
                                        GError **error);
 
+void alsaseq_event_calculate_pool_consumption(const ALSASeqEvent *self, guint *cells);
+
 G_END_DECLS
 
 #endif
index bb409d3b8e1718aad2c15d63813be8e8c55ad780..072df918b4b84454a60f74402990bb731876bd42 100644 (file)
@@ -55,6 +55,7 @@ methods = (
     'set_connect_data',
     'get_result_data',
     'set_result_data',
+    'calculate_pool_consumption',
 )
 
 if not test_struct(target_type, methods):