From: Andre Noll Date: Thu, 7 Oct 2021 17:22:47 +0000 (+0200) Subject: Consolidate receiver/filter/writer {pre,post}_select() docs. X-Git-Tag: v0.7.1~6^2~4 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=7e0a0badba66c0cdcb0dcbc8cf3d0f5b71001ca3;p=paraslash.git Consolidate receiver/filter/writer {pre,post}_select() docs. The documentation of these three ->pre_select() and ->post_select() methods overlapped quite a bit. Some comments stated general properties of the sched API which fit better in the documentation of sched.h, so move these bits there. Improve the text a bit while at it and avoid talking about select(2) and fd sets as these are implementation details. Instead, focus on the general concept of fd monitoring. Pure comment cleanups, no code changes. --- diff --git a/filter.h b/filter.h index 69d4dfee..96f3dbae 100644 --- a/filter.h +++ b/filter.h @@ -28,16 +28,18 @@ struct filter_node { }; /** - * The structure associated with a paraslash filter. + * Describes a method to convert audio data. * - * Paraslash filters are "modules" which transform an audio stream. struct - * filter contains methods which are implemented by each filter. + * Paraslash filters are "modules" which transform the data of an audio stream. + * This structure contains the methods which have to be implemented by each + * filter. * - * Note: As several instances of the same filter may be running at the same - * time, all these filter functions must be reentrant; no static non-constant - * variables may be used. + * As several instances of the same filter may be running at the same time, all + * filter methods must be reentrant and no static non-constant variables must + * be used. * - * \sa \ref filter_node. + * \sa \ref filter_node, struct \ref receiver, struct \ref writer, struct \ref + * sched. */ struct filter { /** @@ -81,23 +83,9 @@ struct filter { * This should free whatever ->setup() has allocated. */ void (*teardown)(const struct lls_parse_result *lpr, void *conf); - /** - * Set scheduler timeout and add file descriptors to fd sets. - * - * This function controls the timeout value for the next call to - * select(2). It may decrease the current timeout but shall never - * increase it. The second purpose of this function is to add file - * descriptors to the two fd sets of the sched structure. The - * descriptors in these sets will be watched by the subsequent - * select(2) call. - */ + /** Force a zero timeout if data is available in the buffer tree. */ void (*pre_select)(struct sched *s, void *context); - /** - * Convert (filter) the given data. - * - * Pointer to the converting function of the filter. On errors, the - * post_select function is supposed to return a negative error code. - */ + /** Convert (filter) input data into output data. */ int (*post_select)(struct sched *s, void *context); /** * Answer a buffer tree query. diff --git a/filter_common.c b/filter_common.c index add788a8..4702df6c 100644 --- a/filter_common.c +++ b/filter_common.c @@ -169,15 +169,14 @@ void print_filter_list(void) } /** - * Set select timeout of the scheduler. + * Request a minimal timeout if not idle. * - * \param s The scheduler. - * \param context Pointer to the filter node (task context). + * \param s The scheduler instance. + * \param context Pointer to the filter node. * - * This looks at the status of the btr node of the filter. If data is available - * in the input queue of the filter, or if an error occurred, a minimal timeout - * for the next select call is requested from the scheduler. Otherwise the - * scheduler timeout is left unchanged. + * If the buffer tree node of the given filter node has data available (or is + * in error state) a minimal I/O timeout is requested from the scheduler. + * Otherwise the function does nothing. */ void generic_filter_pre_select(struct sched *s, void *context) { diff --git a/recv.h b/recv.h index 36b0f1db..2976cad6 100644 --- a/recv.h +++ b/recv.h @@ -34,9 +34,18 @@ struct receiver_node { }; /** - * Describes one supported paraslash receiver. + * Describes a possible data source for audio streams. * - * \sa \ref http_recv.c, \ref udp_recv.c. + * A paraslash receiver is a modular piece of software which is capable of + * receiving an audio data stream from a data source. Received audio data is + * fed to consumers through the buffer tree mechanism. + * + * This structure contains the methods which have to be implemented by each + * receiver. + * + * \sa \ref http_recv.c, \ref udp_recv.c, \ref dccp_recv.c, \ref afh_recv.c, + * struct \ref receiver_node, struct \ref filter, struct \ref writer, struct + * \ref sched. */ struct receiver { /** @@ -45,8 +54,6 @@ struct receiver { * This should allocate the output buffer of the given receiver node * and prepare it for retrieving the audio stream according to the * configuration stored in rn->lpr. - * - * \sa struct \ref receiver_node. */ int (*open)(struct receiver_node *rn); /** @@ -58,30 +65,9 @@ struct receiver { * \sa \ref receiver_node. */ void (*close)(struct receiver_node *rn); - /** - * Add file descriptors to fd_sets and compute timeout for select(2). - * - * If this is not NULL, the function is called in each iteration of the - * scheduler's select loop. The receiver may define it to add file - * descriptors to the file descriptor sets given by s. Those will be - * monitored in the subsequent call to select(2). The function may also - * lower the timeout value of s to make select(2) return earlier if no - * file descriptors are ready for I/O. - * - * \sa select(2), \ref time.c, struct \ref sched. - */ + /** Ask the scheduler to monitor receive fds. */ void (*pre_select)(struct sched *s, void *context); - /** - * Evaluate the result from select(2). - * - * This is called after the call to select(2). It should check all file - * descriptors which were added to any of the fd sets in the previous - * call to ->pre_select() and perform (non-blocking) I/O operations on - * those fds which are ready for I/O, for example in order to establish - * a connection or to receive a part of the audio stream. - * - * \sa select(2), struct \ref receiver. - */ + /** Receive data and make it available to consumers. */ int (*post_select)(struct sched *s, void *context); /** * Answer a buffer tree query. diff --git a/recv_common.c b/recv_common.c index 31fd81f1..169a4967 100644 --- a/recv_common.c +++ b/recv_common.c @@ -98,17 +98,17 @@ void print_receiver_helps(bool detailed) } /** - * Simple pre-select hook, used by all receivers. + * Request a minimal timeout in case of buffer tree errors. * - * \param s Scheduler info. - * \param rn The receiver node. + * \param s The scheduler instance. + * \param rn The buffer tree node is derived from this. * - * This requests a minimal delay from the scheduler if the status of the buffer - * tree node indicates an error/eof condition. No file descriptors are added to - * the fd sets of \a s. + * If the buffer tree node of the given receiver node is in error or EOF state, + * a minimal I/O timeout is requested from the scheduler. Otherwise, the + * function does nothing. No file descriptors are asked to be monitored. * - * \return The status of the btr node of the receiver node, i.e. the return - * value of the underlying call to \ref btr_node_status(). + * \return The status of of the receiver node's buffer tree node. That is, the + * return value of the underlying call to \ref btr_node_status(). */ int generic_recv_pre_select(struct sched *s, struct receiver_node *rn) { diff --git a/sched.h b/sched.h index d9e85244..f89b89ff 100644 --- a/sched.h +++ b/sched.h @@ -11,6 +11,8 @@ * function which is called from the scheduler main loop before it calls * select(). Similarly, each task must define a post_select function which is * called after the select call. + * + * \sa select(2), poll(2). */ struct sched { /** Initial value (in milliseconds) before any pre_select call. */ @@ -36,18 +38,27 @@ struct task_info { /** Used for log messages and by \ref get_task_list(). */ const char *name; /** - * The optional pre select method. + * Configure watch fds and impose an upper bound on the I/O timeout. + * + * If this is not NULL, the function is called at each iteration of the + * scheduler's main loop. Its purpose is to tell the scheduler that + * certain file descriptors should be monitored for readiness for I/O. + * The function may also lower the scheduler's timeout value (but shall + * never increase it) to impose an upper bound on the waiting time in + * case no file descriptors happen to be ready. * - * Its purpose is to add file descriptors to the fd sets of the - * scheduler and to decrease the select timeout if necessary. + * \sa \ref time.c. */ void (*pre_select)(struct sched *s, void *context); /** - * The mandatory post select method. + * Perform I/O on file descriptors which are ready for I/O. + * + * This mandatory hook is called after the system call which monitors + * file descriptors returns. The function should perform non-blocking + * I/O on those file descriptors which are reported as being ready. * - * Its purpose is to evaluate and act upon the results of the previous - * select call. If this function returns a negative value, the - * scheduler unregisters the task. + * If this function returns a negative value, the scheduler unregisters + * the task. */ int (*post_select)(struct sched *s, void *context); /** diff --git a/write.h b/write.h index 833cb69a..f654c7e9 100644 --- a/write.h +++ b/write.h @@ -20,20 +20,22 @@ struct writer_node { size_t min_iqs; }; -/** Describes one supported writer. */ +/** + * Describes a data sink for audio streams. + * + * A paraslash writer obtains data via the buffer tree mechanism from its + * parent node. It consumes data without producing output on its own. + * + * This structure contains the methods which have to be implemented by each + * writer. + * + * \sa struct \ref writer_node, struct \ref receiver, struct \ref filter, + * struct \ref sched. + */ struct writer { - /** - * Prepare the fd sets for select. - * - * This is called from scheduler. It may use the sched pointer to add - * any file descriptors or to decrease the select timeout. - */ + /** Ask the scheduler to check whether data can be written. */ void (*pre_select)(struct sched *s, void *context); - /** - * Write audio data. - * - * Called from the post_select function of the writer node's task. - */ + /** Write audio data. */ int (*post_select)(struct sched *s, void *context); /** * Close one instance of the writer.