2 * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file filter.h Filter-related structures and exported symbols from filter_common.c. */
10 * Describes one running instance of a filter.
13 /** The number in the array of available filters. */
16 * Each filter may store any filter-specific information about the particular
17 * instance of the filter here.
20 /** The list of registered callbacks. */
21 struct list_head callbacks;
22 /** A pointer to the configuration of this instance. */
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. */
30 /** The minimal input queue size, see \ref btr_node_status(). */
35 * The structure associated with a paraslash filter.
37 * Paraslash filters are "modules" which transform an audio stream. struct
38 * filter contains methods which are implemented by each filter.
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.
44 * \sa mp3dec_filter.c, oggdec_filter.c, wav_filter.c, compress_filter.c, filter_node
48 * Open one instance of this filter.
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.
55 void (*open)(struct filter_node *fn);
57 * Close one instance of this filter.
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.
63 void (*close)(struct filter_node *fn);
65 * Prepare the filter according to command line options.
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.
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.
78 * Filters are supposed to abort if the setup fails. If the function
79 * returns, it is assumed to have succeeded.
81 void *(*setup)(const struct lls_parse_result *lpr);
83 * Deallocate precomputed resources.
85 * This should free whatever ->setup() has allocated.
87 void (*teardown)(const struct lls_parse_result *lpr, void *conf);
89 * Set scheduler timeout and add file descriptors to fd sets.
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
98 void (*pre_select)(struct sched *s, void *context);
100 * Convert (filter) the given data.
102 * Pointer to the converting function of the filter. On errors, the
103 * post_select function is supposed to return a negative error code.
105 int (*post_select)(struct sched *s, void *context);
107 * Answer a buffer tree query.
109 * This optional function pointer is used for inter node communications
110 * of the buffer tree nodes. See \ref btr_command_handler for details.
112 btr_command_handler execute;
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)))
131 void generic_filter_pre_select(struct sched *s, void *context);
132 int decoder_execute(const char *cmd, unsigned sample_rate, unsigned channels,
135 static inline void write_int16_host_endian(char *buf, int val)
137 #ifdef WORDS_BIGENDIAN
139 *(buf + 1) = val & 0xff;
142 *(buf + 1) = val >> 8;
146 /** Make a filter pointer from the filter number. */
147 const struct filter *filter_get(int filter_num);
148 const char *filter_name(int filter_num);