2 * Copyright (C) 2005-2009 Andre Noll <maan@systemlinux.org>
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. */
9 /** The list of supported filters. */
10 enum filter_enum {FILTER_ENUM};
13 * Describes one running instance of a filter.
16 /** The number in the array of available filters. */
18 /** The filter chain this filter node belongs to. */
19 struct filter_chain *fc;
21 * Each filter may store any filter-specific information about the particular
22 * instance of the filter here.
25 /** The output buffer. */
27 /** The size of the output buffer. */
29 /** The number of bytes currently loaded in \a buf. */
31 /** The list of registered callbacks. */
32 struct list_head callbacks;
33 /** A pointer to the configuration of this instance. */
37 /** Describes one running instance of a chain of filters */
39 /** The length of the filter chain. */
40 unsigned int num_filters;
42 * The number of channels of the current stream.
44 * Set by the decoding filter.
46 unsigned int channels;
48 * Current sample rate in Hz.
50 * Set by the decoding filter.
52 unsigned int samplerate;
53 /** The list containing all filter nodes in this filter chain. */
54 struct filter_node *filter_nodes;
56 * The input buffer of the filter chain.
58 * This is set to point to the output buffer of the receiving application (the
59 * buffer used to read from stdin for para_filter; the output buffer of the
60 * current receiver for para_audiod).
64 * The output buffer of the filter chain.
66 * Points to the output buffer of the last filter in the filter chain.
69 /** Contains the number of bytes loaded in the input buffer. */
71 /** Contains the number of bytes loaded in the output buffer. */
73 /** Pointer to the error variable of the receiving application. */
75 /** Pointer to the error variable of the writing application. */
77 /** The task associated with the filter chain. */
81 #define FOR_EACH_FILTER_NODE(fn, fc, i) for (i = 0; i < (fc)->num_filters \
82 && (fn = (fc)->filter_nodes + i); i++)
86 * Used to manage grab clients.
88 * An application using paraslash's filter subsystem may register any number of
89 * callbacks for each filter_node. It is possible to attach a filter callback
90 * while the filter is running. This is used for stream grabbing in
91 * para_audiod: Whenever a client sends the 'grab' command, para_audiod adds a
92 * filter callback to the list of callbacks for the filter node specified in
95 struct filter_callback {
96 /** All callbacks are organized in a doubly linked list. */
97 struct list_head node;
101 * If not \p NULL, the filter subsystem calls this function whenever the filter
102 * consumed some or all of its input buffer. A pointer to the buffer of consumed
103 * data, its length and a pointer to the own \a filter_callback structure are passed
104 * to \a input_cb. The input callback is expected to return a negative value on errors.
106 int (*input_cb)(char *buf, size_t len, struct filter_callback *fc);
108 * The output callback.
110 * If not NULL, this is called whenever the filter produces output. A pointer
111 * to the output data, its length and a pointer to the own \a filter_callback
112 * structure are passed to \a output_cb. Like the input callback, the output
113 * callback is expected to return a negative value on errors.
115 int (*output_cb)(char *buf, size_t len, struct filter_callback *fc);
117 * The callback close function.
119 * This gets called whenever the input/output callback returned an error, or if
120 * the filter chain is going to be destroyed, e.g. because the end of the
121 * stream was encountered. It is assumed to succeed.
123 void (*close)(struct filter_callback *fc);
128 * The structure associated with a paraslash filter.
130 * Paraslash filters are "modules" which are used to transform an audio stream.
131 * struct filter contains pointers to functions that must be supplied by the
132 * filter code in order to be used by the driving application (currently
133 * para_audiod and para_filter).
135 * Note: As several instances of the same filter may be running at the same
136 * time, all these filter functions must be reentrant; no static non-constant
137 * variables may be used.
138 * \sa mp3dec_filter.c, oggdec_filter.c, wav_filter.c, compress_filter.c, filter_node
141 /** The name of the filter. */
144 * Pointer to the filter init routine.
146 * This function is only called once at startup. It must initialize the
147 * other non-optional function pointers of this structure.
149 void (*init)(struct filter *f);
151 * Open one instance of this filter.
153 * This should allocate the output buffer of the given filter node and do any
154 * other filter-specific preparations like initializing the private_data member
155 * of \a fn suitably. The open function is assumed to succeed.
157 void (*open)(struct filter_node *fn);
159 * Convert (filter) the given data.
161 * Pointer to the converting function of the filter. It should convert the
162 * given input buffer \a inbuf which is of length \a len to the previously
163 * reserved output buffer of \a fn. On success, it must return the number of
164 * bytes it consumed from \a inbuf. On errors, a negative number indicating the
165 * kind of the error must be returned.
167 * A zero return value just means that nothing was converted (probably because
168 * the input buffer was too small). This is not interpreted as an error.
170 ssize_t (*convert)(char *inbuf, size_t len, struct filter_node *fn);
172 * Close one instance of this filter.
174 * Free all resources of associated with \a fn that were previously allocated
175 * by the open() function.
177 void (*close)(struct filter_node *fn);
179 * A pointer to the filter's command line parser.
181 * If this optional function pointer is not NULL, any filter options
182 * are passed from the main program to this command line parser once at
183 * application startup. The command line parser should check its
184 * command line options given by \a argc and \a argv and abort on
185 * errors. Success must be indicated by a non-negative return value. In
186 * this case the function should return a pointer to the
187 * filter-specific configuration data determined by \a argc and \a
188 * argv. On failure, a negative paraslash error code must be returned.
190 int (*parse_config)(int argc, char **argv, void **config);
192 /** The help texts for this filter. */
193 struct ggo_help help;
196 void close_filters(struct filter_chain *fc);
197 void filter_init(void);
198 int check_filter_arg(char *filter_arg, void **conf);
199 void filter_post_select(__a_unused struct sched *s, struct task *t);
200 void print_filter_helps(int detailed);
202 static inline void write_int16_host_endian(char *buf, int val)
204 #ifdef WORDS_BIGENDIAN
206 *(buf + 1) = val & 0xff;
209 *(buf + 1) = val >> 8;
215 #define FOR_EACH_SUPPORTED_FILTER(j) for (j = 0; j < NUM_SUPPORTED_FILTERS; j++)
217 /** The filter array, one structure for each supported filter. */
218 extern struct filter filters[NUM_SUPPORTED_FILTERS];