Mercurial > mplayer.hg
annotate libaf/af.h @ 7666:407031aeedcf
cosmetics :)
author | arpi |
---|---|
date | Tue, 08 Oct 2002 17:59:52 +0000 |
parents | fbd5445cc853 |
children | 1d3a3dc1f488 |
rev | line source |
---|---|
7568 | 1 #ifndef __aop_h__ |
2 #define __aop_h__ | |
3 | |
4 struct af_instance_s; | |
5 | |
6 // Audio data chunk | |
7 typedef struct af_data_s | |
8 { | |
9 void* audio; // data buffer | |
10 int len; // buffer length | |
11 int rate; // sample rate | |
12 int nch; // number of channels | |
13 int format; // format | |
14 int bps; // bytes per sample | |
15 } af_data_t; | |
16 | |
17 // Fraction, used to calculate buffer lengths | |
18 typedef struct frac_s | |
19 { | |
20 int n; // Numerator | |
21 int d; // Denominator | |
22 } frac_t; | |
23 | |
7615 | 24 // Flags used for defining the behavour of an audio filter |
25 #define AF_FLAGS_REENTRANT 0x00000000 | |
26 #define AF_FLAGS_NOT_REENTRANT 0x00000001 | |
27 | |
7568 | 28 /* Audio filter information not specific for current instance, but for |
29 a specific filter */ | |
30 typedef struct af_info_s | |
31 { | |
32 const char *info; | |
33 const char *name; | |
34 const char *author; | |
35 const char *comment; | |
7615 | 36 const int flags; |
7568 | 37 int (*open)(struct af_instance_s* vf); |
38 } af_info_t; | |
39 | |
40 // Linked list of audio filters | |
41 typedef struct af_instance_s | |
42 { | |
43 af_info_t* info; | |
44 int (*control)(struct af_instance_s* af, int cmd, void* arg); | |
45 void (*uninit)(struct af_instance_s* af); | |
46 af_data_t* (*play)(struct af_instance_s* af, af_data_t* data); | |
47 void* setup; // setup data for this specific instance and filter | |
48 af_data_t* data; // configuration for outgoing data stream | |
49 struct af_instance_s* next; | |
50 struct af_instance_s* prev; | |
7665
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
51 double delay; // Delay caused by the filter [ms] |
7568 | 52 frac_t mul; /* length multiplier: how much does this instance change |
53 the length of the buffer. */ | |
54 }af_instance_t; | |
55 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
56 // Initialization types |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
57 #define SLOW 1 |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
58 #define FAST 2 |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
59 #define FORCE 3 |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
60 |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
61 // Configuration switches |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
62 typedef struct af_cfg_s{ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
63 int force; // Initialization type |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
64 char** list; /* list of names of plugins that are added to filter |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
65 list during first initialization of stream */ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
66 }af_cfg_t; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
67 |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
68 // Current audio stream |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
69 typedef struct af_stream_s |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
70 { |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
71 // The first and last filter in the list |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
72 af_instance_t* first; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
73 af_instance_t* last; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
74 // Storage for input and output data formats |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
75 af_data_t input; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
76 af_data_t output; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
77 // Cofiguration for this stream |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
78 af_cfg_t cfg; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
79 }af_stream_t; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
80 |
7568 | 81 /********************************************* |
82 // Control parameters | |
83 */ | |
84 | |
85 /* The control system is divided into 3 levels | |
86 mandatory calls - all filters must answer to all of these | |
87 optional calls - are optional | |
88 filter specific calls - applies only to some filters | |
89 */ | |
90 | |
91 #define AF_CONTROL_MANDATORY_BASE 0 | |
92 #define AF_CONTROL_OPTIONAL_BASE 100 | |
93 #define AF_CONTROL_FILTER_SPECIFIC_BASE 200 | |
94 | |
95 // MANDATORY CALLS | |
96 | |
97 /* Reinitialize filter. The optional argument contains the new | |
98 configuration in form of a af_data_t struct. If the filter does not | |
99 support the new format the struct should be changed and AF_FALSE | |
100 should be returned. If the incoming and outgoing data streams are | |
101 identical the filter can return AF_DETACH. This will remove the | |
102 filter. */ | |
103 #define AF_CONTROL_REINIT 1 + AF_CONTROL_MANDATORY_BASE | |
104 | |
105 // OPTIONAL CALLS | |
106 | |
107 | |
108 // FILTER SPECIFIC CALLS | |
109 | |
110 // Set output rate in resample | |
111 #define AF_CONTROL_RESAMPLE 1 + AF_CONTROL_FILTER_SPECIFIC_BASE | |
112 // Set output format in format | |
113 #define AF_CONTROL_FORMAT 2 + AF_CONTROL_FILTER_SPECIFIC_BASE | |
114 // Set number of output channels in channels | |
115 #define AF_CONTROL_CHANNELS 3 + AF_CONTROL_FILTER_SPECIFIC_BASE | |
116 // Set delay length in delay | |
117 #define AF_CONTROL_SET_DELAY_LEN 4 + AF_CONTROL_FILTER_SPECIFIC_BASE | |
118 /********************************************* | |
119 // Return values | |
120 */ | |
121 | |
122 #define AF_DETACH 2 | |
123 #define AF_OK 1 | |
124 #define AF_TRUE 1 | |
125 #define AF_FALSE 0 | |
126 #define AF_UNKNOWN -1 | |
127 #define AF_ERROR -2 | |
128 #define AF_NA -3 | |
129 | |
130 | |
131 | |
132 // Export functions | |
133 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
134 /* Initialize the stream "s". This function creates a new fileterlist |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
135 if nessesary according to the values set in input and output. Input |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
136 and output should contain the format of the current movie and the |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
137 formate of the preferred output respectively. The function is |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
138 reentreant i.e. if called wit an already initialized stream the |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
139 stream will be reinitialized. The return value is 0 if sucess and |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
140 -1 if failure */ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
141 int af_init(af_stream_t* s); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
142 |
7568 | 143 // Uninit and remove all filters |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
144 void af_uninit(af_stream_t* s); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
145 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
146 /* Add filter during execution. This function adds the filter "name" |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
147 to the stream s. The filter will be inserted somewhere nice in the |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
148 list of filters. The return value is a pointer to the new filter, |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
149 If the filter couldn't be added the return value is NULL. */ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
150 af_instance_t* af_add(af_stream_t* s, char* name); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
151 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
152 // Uninit and remove the filter "af" |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
153 void af_remove(af_stream_t* s, af_instance_t* af); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
154 |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
155 /* Find filter in the dynamic filter list using it's name This |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
156 function is used for finding already initialized filters */ |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
157 af_instance_t* af_get(af_stream_t* s, char* name); |
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
158 |
7568 | 159 // Filter data chunk through the filters in the list |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
160 af_data_t* af_play(af_stream_t* s, af_data_t* data); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
161 |
7568 | 162 /* Calculate how long the output from the filters will be given the |
7589 | 163 input length "len". The calculated length is >= the actual |
164 length */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
165 int af_outputlen(af_stream_t* s, int len); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
166 |
7568 | 167 /* Calculate how long the input to the filters should be to produce a |
168 certain output length, i.e. the return value of this function is | |
7589 | 169 the input length required to produce the output length "len". The |
170 calculated length is <= the actual length */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
171 int af_inputlen(af_stream_t* s, int len); |
7649
90e16aa8ae5f
Adding functionality for adding filters during execution
anders
parents:
7615
diff
changeset
|
172 |
7598
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
173 /* Calculate how long the input IN to the filters should be to produce |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
174 a certain output length OUT but with the following three constraints: |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
175 1. IN <= max_insize, where max_insize is the maximum possible input |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
176 block length |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
177 2. OUT <= max_outsize, where max_outsize is the maximum possible |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
178 output block length |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
179 3. If possible OUT >= len. |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
180 Return -1 in case of error */ |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
181 int af_calc_insize_constrained(af_stream_t* s, int len, |
48f8c731efb5
Adding function for estimating required buffer length
anders
parents:
7591
diff
changeset
|
182 int max_outsize,int max_insize); |
7568 | 183 |
7665
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
184 /* Calculate the total delay caused by the filters */ |
fbd5445cc853
Adding function for calculating the delay caused by the filters
anders
parents:
7649
diff
changeset
|
185 double af_calc_delay(af_stream_t* s); |
7568 | 186 |
187 // Helper functions and macros used inside the audio filters | |
188 | |
189 /* Helper function called by the macro with the same name only to be | |
190 called from inside filters */ | |
191 int af_resize_local_buffer(af_instance_t* af, af_data_t* data); | |
192 | |
193 /* Helper function used to calculate the exact buffer length needed | |
7589 | 194 when buffers are resized. The returned length is >= than what is |
195 needed */ | |
196 int af_lencalc(frac_t mul, af_data_t* data); | |
7568 | 197 |
198 /* Memory reallocation macro: if a local buffer is used (i.e. if the | |
199 filter doesn't operate on the incoming buffer this macro must be | |
200 called to ensure the buffer is big enough. */ | |
201 #define RESIZE_LOCAL_BUFFER(a,d)\ | |
7591 | 202 ((a->data->len < af_lencalc(a->mul,d))?af_resize_local_buffer(a,d):AF_OK) |
7568 | 203 |
204 #ifndef min | |
205 #define min(a,b)(((a)>(b))?(b):(a)) | |
206 #endif | |
207 | |
208 #ifndef max | |
209 #define max(a,b)(((a)>(b))?(a):(b)) | |
210 #endif | |
211 | |
212 #endif |