1b916eecf632cc834b46703007097d6a02e6413a
2 * Copyright (C) 2005-2008 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_chain.c. */
11 * Describes one running instance of a filter.
14 /** The number in the array of available filters. */
16 /** The filter chain this filter node belongs to. */
17 struct filter_chain
*fc
;
19 * Each filter may store any filter-specific information about the particular
20 * instance of the filter here.
23 /** The output buffer. */
25 /** The size of the output buffer. */
27 /** The number of bytes currently loaded in \a buf. */
29 /** The list of registered callbacks. */
30 struct list_head callbacks
;
31 /** A pointer to the configuration of this instance. */
35 /** Describes one running instance of a chain of filters */
37 unsigned int num_filters
;
39 * The number of channels of the current stream.
41 * Set by the decoding filter.
43 unsigned int channels
;
45 * Current sample rate in Hz.
47 * Set by the decoding filter.
49 unsigned int samplerate
;
50 /** The list containing all filter nodes in this filter chain. */
51 struct filter_node
*filter_nodes
;
53 * The input buffer of the filter chain.
55 * This is set to point to the output buffer of the receiving application (the
56 * buffer used to read from stdin for para_filter; the output buffer of the
57 * current receiver for para_audiod).
61 * The output buffer of the filter chain.
63 * Points to the output buffer of the last filter in the filter chain.
66 /** Contains the number of bytes loaded in the input buffer. */
68 /** Contains the number of bytes loaded in the output buffer. */
70 /** Pointer to the error variable of the receiving application. */
72 /** Pointer to the error variable of the writing application. */
74 /** The task associated with the filter chain. */
78 #define FOR_EACH_FILTER_NODE(fn, fc, i) for (i = 0; i < (fc)->num_filters \
79 && (fn = (fc)->filter_nodes + i); i++)
83 * Used to manage grab clients.
85 * An application using paraslash's filter subsystem may register any number of
86 * callbacks for each filter_node. It is possible to attach a filter callback
87 * while the filter is running. This is used for stream grabbing in
88 * para_audiod: Whenever a client sends the 'grab' command, para_audiod adds a
89 * filter callback to the list of callbacks for the filter node specified in
92 struct filter_callback
{
93 /** All callbacks are organized in a doubly linked list. */
94 struct list_head node
;
98 * May be initialized by the application before registering the callback. This
99 * pointer is not used by the filter subsystem. It is provided for use within
100 * the input/output/close callback functions.
104 * The input callback.
106 * In not \p NULL, the filter subsystem calls this function whenever the filter
107 * consumed some or all of its input buffer. A pointer to the buffer of consumed
108 * data, its length and a pointer to the own \a filter_callback structure are passed
109 * to \a input_cb. The input callback is expected to return a negative value on errors.
111 int (*input_cb
)(char *buf
, size_t len
, struct filter_callback
*fc
);
113 * The output callback.
115 * If not NULL, this is called whenever the filter produces output. A pointer
116 * to the output data, its length and a pointer to the own \a filter_callback
117 * structure are passed to \a output_cb. Like the input callback, the output
118 * callback is expected to return a negative value on errors.
120 int (*output_cb
)(char *buf
, size_t len
, struct filter_callback
*fc
);
122 * The callback close function.
124 * This gets called whenever the input/output callback returned an error, or if
125 * the filter chain is going to be destroyed, e.g. because the end of the
126 * stream was encountered. It is assumed to succeed.
128 void (*close
)(struct filter_callback
*fc
);
133 * The structure associated with a paraslash filter.
135 * Paraslash filters are "modules" which are used to transform an audio stream.
136 * struct filter contains pointers to functions that must be supplied by the
137 * filter code in order to be used by the driving application (currently
138 * para_audiod and para_filter).
140 * Note: As several instances of the same filter may be running at the same
141 * time, all these filter functions must be reentrant; no static non-constant
142 * variables may be used.
143 * \sa mp3dec.c, oggdec.c, wav.c, compress.c, filter_node
146 /** The name of the filter. */
149 * Pointer to the filter init routine.
151 * This function is only called once at startup. It must initialize the
152 * other non-optional function pointers of this structure.
154 void (*init
)(struct filter
*f
);
156 * Open one instance of this filter.
158 * This should allocate the output buffer of the given filter node and do any
159 * other filter-specific preparations like initializing the private_data member
160 * of \a fn suitably. The open function is assumed to succeed.
162 void (*open
)(struct filter_node
*fn
);
164 * Convert (filter) the given data.
166 * Pointer to the converting function of the filter. It should convert the
167 * given input buffer \a inbuf which is of length \a len to the previously
168 * reserved output buffer of \a fn. On success, it must return the number of
169 * bytes it consumed from \a inbuf. On errors, a negative number indicating the
170 * kind of the error must be returned.
172 * A zero return value just means that nothing was converted (probably because
173 * the input buffer was too small). This is not interpreted as an error.
175 ssize_t (*convert
)(char *inbuf
, size_t len
, struct filter_node
*fn
);
177 * Close one instance of this filter.
179 * Free all resources of associated with \a fn that were previously allocated
180 * by the open() function.
182 void (*close
)(struct filter_node
*fn
);
184 * Print the help text for this filter and exit.
186 * This is optional and it is not necessary to initialize this pointer if
187 * the filter does not have a help text.
189 void (*print_help
)(void);
191 * A pointer to the filter's command line parser.
193 * If this optional function pointer is not NULL, any filter options are passed
194 * from the main program to this command line parser once at application
195 * startup. The command line parser should check its command line options given
196 * by \a argc and \a argv and abort on errors. On success, it should return a
197 * pointer to the filter-specific configuration data determined by \a argc and
200 void *(*parse_config
)(int argc
, char **argv
);
203 void close_filters(struct filter_chain
*fc
);
204 void filter_init(struct filter
*all_filters
);
205 int check_filter_arg(char *filter_arg
, void **conf
);
206 void filter_pre_select(__a_unused
struct sched
*s
, struct task
*t
);
209 static inline void write_int16_host_endian(char *buf
, int val
)
211 #ifdef WORDS_BIGENDIAN
213 *(buf
+ 1) = val
& 0xff;
216 *(buf
+ 1) = val
>> 8;
222 extern struct filter filters
[];
223 #define DECLARE_EXTERN_FILTER_INIT(name) \
224 extern void name ## _init(struct filter *f)
226 #define FILTER_INIT(filter) { \
228 .init = filter ## _init, \
229 .parse_config = NULL, \
233 /* filters that are always present */
234 DECLARE_EXTERN_FILTER_INIT(wav
);
235 /* wav is always the first filter */
236 #define WAV_FILTER_NUM 0
237 DECLARE_EXTERN_FILTER_INIT(compress
);
239 /* next the optional filters */
241 DECLARE_EXTERN_FILTER_INIT(mp3dec
);
242 #define MP3DEC_FILTER FILTER_INIT(mp3dec)
244 #define MP3DEC_FILTER
248 DECLARE_EXTERN_FILTER_INIT(aacdec
);
249 #define AACDEC_FILTER FILTER_INIT(aacdec)
251 #define AACDEC_FILTER
254 #ifdef HAVE_OGGVORBIS
255 DECLARE_EXTERN_FILTER_INIT(oggdec
);
256 #define OGGDEC_FILTER FILTER_INIT(oggdec)
258 #define OGGDEC_FILTER
262 /** define an array of all available filters */
263 #define DEFINE_FILTER_ARRAY(filters) struct filter filters[] = { \
265 FILTER_INIT(compress) \