mood.c: Fix documentation of int_sqrt().
[paraslash.git] / filter.h
1 /*
2  * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file filter.h Filter-related structures and exported symbols from filter_common.c. */
8
9 /**
10  * Describes one running instance of a filter.
11 */
12 struct filter_node {
13         /** The number in the array of available filters. */
14         unsigned filter_num;
15         /**
16          * Each filter may store any filter-specific information about the particular
17          * instance of the filter here.
18          */
19         void *private_data;
20         /** The list of registered callbacks. */
21         struct list_head callbacks;
22         /** A pointer to the configuration of this instance. */
23         void *conf;
24         /** The parsed command line, merged with options given in the config file. */
25         struct lls_parse_result *lpr;
26         /** The buffer tree node. */
27         struct btr_node *btrn;
28         /** The task corresponding to this filter node. */
29         struct task *task;
30         /** The minimal input queue size, see \ref btr_node_status(). */
31         size_t min_iqs;
32 };
33
34 /**
35  * The structure associated with a paraslash filter.
36  *
37  * Paraslash filters are "modules" which transform an audio stream. struct
38  * filter contains methods which are implemented by each filter.
39  *
40  * Note: As several instances of the same filter may be running at the same
41  * time, all these filter functions must be reentrant; no static non-constant
42  * variables may be used.
43  *
44  * \sa \ref filter_node.
45  */
46 struct filter {
47         /**
48          * Open one instance of this filter.
49          *
50          * This should allocate the output buffer of the given filter node and
51          * do any other filter-specific preparations like initializing the
52          * private_data member of \a fn suitably. The open function is
53          * optional, If it is provided, it is assumed to succeed.
54          */
55         void (*open)(struct filter_node *fn);
56         /**
57          * Close one instance of this filter.
58          *
59          * Free all resources associated with \a fn that were previously
60          * allocated by the open() function. It's OK to set this to NULL if the
61          * filter does not need to perform any cleanup operation.
62          */
63         void (*close)(struct filter_node *fn);
64         /**
65          * Prepare the filter according to command line options.
66          *
67          * In addition to the syntactic checks which are automatically performed
68          * by the lopsub functions, some filters like to also check the command
69          * line arguments semantically. Moreover, since applications may open
70          * the filter many times with the same options, filters need a method
71          * which allows them to precompute once those parts of the setup which
72          * depend only on the command line options.
73          *
74          * If this function pointer is not NULL, the function is called once at
75          * startup. The returned pointer value is made available to the ->open
76          * method via the ->conf pointer of struct filter_node.
77          *
78          * Filters are supposed to abort if the setup fails. If the function
79          * returns, it is assumed to have succeeded.
80          */
81         void *(*setup)(const struct lls_parse_result *lpr);
82         /**
83          * Deallocate precomputed resources.
84          *
85          * This should free whatever ->setup() has allocated.
86          */
87         void (*teardown)(const struct lls_parse_result *lpr, void *conf);
88         /**
89          * Set scheduler timeout and add file descriptors to fd sets.
90          *
91          * This function controls the timeout value for the next call to
92          * select(2). It may decrease the current timeout but shall never
93          * increase it. The second purpose of this function is to add file
94          * descriptors to the two fd sets of the sched structure. The
95          * descriptors in these sets will be watched by the subsequent
96          * select(2) call.
97          */
98         void (*pre_select)(struct sched *s, void *context);
99         /**
100          * Convert (filter) the given data.
101          *
102          * Pointer to the converting function of the filter. On errors, the
103          * post_select function is supposed to return a negative error code.
104          */
105         int (*post_select)(struct sched *s, void *context);
106         /**
107          * Answer a buffer tree query.
108          *
109          * This optional function pointer is used for inter node communications
110          * of the buffer tree nodes. See \ref btr_command_handler for details.
111          */
112         btr_command_handler execute;
113 };
114
115 void print_filter_helps(bool detailed);
116 void print_filter_list(void);
117 int filter_setup(const char *fa, void **conf, struct lls_parse_result **lprp);
118 #define FILTER_CMD(_num) (lls_cmd(_num, filter_cmd_suite))
119 #define FILTER_CMD_OPT(_cmd, _opt) (lls_opt( \
120         LSG_FILTER_CMD_ ## _cmd ## _OPT_ ## _opt, \
121         FILTER_CMD(LSG_FILTER_CMD_CMD_ ## _cmd)))
122 #define FILTER_CMD_OPT_RESULT(_cmd, _opt, _lpr) \
123         (lls_opt_result(LSG_FILTER_CMD_ ## _cmd ## _OPT_ ## _opt, _lpr))
124 #define FILTER_CMD_OPT_GIVEN(_cmd, _opt, _lpr) \
125         (lls_opt_given(FILTER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))
126 #define FILTER_CMD_OPT_UINT32_VAL(_cmd, _opt, _lpr) \
127         (lls_uint32_val(0, FILTER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))
128 #define FILTER_CMD_OPT_STRING_VAL(_cmd, _opt, _lpr) \
129         (lls_string_val(0, FILTER_CMD_OPT_RESULT(_cmd, _opt, _lpr)))
130
131 void generic_filter_pre_select(struct sched *s, void *context);
132 int decoder_execute(const char *cmd, unsigned sample_rate, unsigned channels,
133                 char **result);
134
135 static inline void write_int16_host_endian(char *buf, int val)
136 {
137 #ifdef WORDS_BIGENDIAN
138         *buf = val >> 8;
139         *(buf + 1) = val & 0xff;
140 #else
141         *buf = val & 0xff;
142         *(buf + 1) = val >> 8;
143 #endif
144 }
145
146 const struct filter *filter_get(int filter_num);
147 const char *filter_name(int filter_num);