0808059dac3f7450aaa73c27d6afd4d382c62e94
[paraslash.git] / filter.h
1 /*
2 * Copyright (C) 2005-2011 Andre Noll <maan@systemlinux.org>
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 /** The list of supported filters. */
10 enum filter_enum {FILTER_ENUM};
11
12 /**
13 * Describes one running instance of a filter.
14 */
15 struct filter_node {
16 /** The number in the array of available filters. */
17 unsigned filter_num;
18 /**
19 * Each filter may store any filter-specific information about the particular
20 * instance of the filter here.
21 */
22 void *private_data;
23 /** The list of registered callbacks. */
24 struct list_head callbacks;
25 /** A pointer to the configuration of this instance. */
26 void *conf;
27 struct btr_node *btrn;
28 struct task task;
29 size_t min_iqs;
30 };
31
32 /**
33 * The structure associated with a paraslash filter.
34 *
35 * Paraslash filters are "modules" which are used to transform an audio stream.
36 * struct filter contains pointers to functions that must be supplied by the
37 * filter code in order to be used by the driving application (currently
38 * para_audiod and para_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 * \sa mp3dec_filter.c, oggdec_filter.c, wav_filter.c, compress_filter.c, filter_node
44 */
45 struct filter {
46 /** The name of the filter. */
47 const char *name;
48 /**
49 * Pointer to the filter init routine.
50 *
51 * This function is only called once at startup. It must initialize the
52 * other non-optional function pointers of this structure.
53 */
54 void (*init)(struct filter *f);
55 /**
56 * Open one instance of this filter.
57 *
58 * This should allocate the output buffer of the given filter node and do any
59 * other filter-specific preparations like initializing the private_data member
60 * of \a fn suitably. The open function is assumed to succeed.
61 */
62 void (*open)(struct filter_node *fn);
63 /**
64 * Close one instance of this filter.
65 *
66 * Free all resources of associated with \a fn that were previously allocated
67 * by the open() function. It's OK to leave this alone if the filter does not
68 * need any cleanups.
69 */
70 void (*close)(struct filter_node *fn);
71 /**
72 * A pointer to the filter's command line parser.
73 *
74 * If this optional function pointer is not NULL, any filter options
75 * are passed from the main program to this command line parser once at
76 * application startup. The command line parser should check its
77 * command line options given by \a argc and \a argv and abort on
78 * errors. Success must be indicated by a non-negative return value. In
79 * this case the function should return a pointer to the
80 * filter-specific configuration data determined by \a argc and \a
81 * argv. On failure, a negative paraslash error code must be returned.
82 */
83 int (*parse_config)(int argc, char **argv, void **config);
84 /**
85 * Deallocate the memory for the configuration.
86 *
87 * This is called to free whatever ->parse_config() has allocated.
88 */
89 void (*free_config)(void *conf);
90
91 /** The help texts for this filter. */
92 struct ggo_help help;
93 /**
94 * Set scheduler timeout and add file descriptors to fd sets.
95 *
96 * This function is used to control the timeout value for select. It
97 * only allowed to decrease the current value. The second purpose of
98 * this function is to set file descriptors to be watched by the
99 * subsequent select call to the two fd sets.
100 */
101 void (*pre_select)(struct sched *s, struct task *t);
102 /**
103 * Convert (filter) the given data.
104 *
105 * Pointer to the converting function of the filter. On errors, the
106 * post_select function is supposed to set t->error to a (negative)
107 * error code.
108 */
109 void (*post_select)(struct sched *s, struct task *t);
110 /**
111 * Answer a buffer tree query.
112 *
113 * This optional function pointer is used for inter node communications
114 * of the buffer tree nodes. See \ref btr_command_handler for details.
115 */
116 btr_command_handler execute;
117 };
118
119 void filter_init(void);
120 int check_filter_arg(char *filter_arg, void **conf);
121 void print_filter_helps(int detailed);
122 void generic_filter_pre_select(struct sched *s, struct task *t);
123 int decoder_execute(const char *cmd, unsigned sample_rate, unsigned channels,
124 char **result);
125
126 static inline void write_int16_host_endian(char *buf, int val)
127 {
128 #ifdef WORDS_BIGENDIAN
129 *buf = val >> 8;
130 *(buf + 1) = val & 0xff;
131 #else
132 *buf = val & 0xff;
133 *(buf + 1) = val >> 8;
134 #endif
135 }
136
137 DECLARE_FILTER_INITS
138
139 #define FOR_EACH_SUPPORTED_FILTER(j) for (j = 0; j < NUM_SUPPORTED_FILTERS; j++)
140
141 /** The filter array, one structure for each supported filter. */
142 extern struct filter filters[NUM_SUPPORTED_FILTERS];