Mercurial > mplayer.hg
annotate libaf/af.c @ 7579:24860f7c716f
change i18n to autodetect
author | pontscho |
---|---|
date | Wed, 02 Oct 2002 09:24:34 +0000 |
parents | 8819fdf88b5d |
children | 31d0ea35c66b |
rev | line source |
---|---|
7568 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 | |
5 #ifdef HAVE_MALLOC_H | |
6 #include <malloc.h> | |
7 #endif | |
8 | |
9 #include "../config.h" | |
10 #include "../mp_msg.h" | |
11 | |
12 #include "af.h" | |
13 | |
14 // Static list of filters | |
15 extern af_info_t af_info_dummy; | |
16 extern af_info_t af_info_delay; | |
17 extern af_info_t af_info_channels; | |
18 extern af_info_t af_info_format; | |
19 extern af_info_t af_info_resample; | |
20 | |
21 static af_info_t* filter_list[]={ \ | |
22 &af_info_dummy,\ | |
23 &af_info_delay,\ | |
24 &af_info_channels,\ | |
25 &af_info_format,\ | |
26 &af_info_resample,\ | |
27 NULL \ | |
28 }; | |
29 | |
30 /* Find a filter in the static list of filters using it's name. This | |
31 function is used internally */ | |
32 af_info_t* af_find(char*name) | |
33 { | |
34 int i=0; | |
35 while(filter_list[i]){ | |
36 if(!strcmp(filter_list[i]->name,name)) | |
37 return filter_list[i]; | |
38 i++; | |
39 } | |
40 mp_msg(MSGT_AFILTER,MSGL_ERR,"Couldn't find audio filter '%s'\n",name); | |
41 return NULL; | |
42 } | |
43 | |
44 // Function for creating a new filter of type name | |
45 af_instance_t* af_create(char* name) | |
46 { | |
47 // Allocate space for the new filter and reset all pointers | |
48 af_instance_t* new=malloc(sizeof(af_instance_t)); | |
49 if(!new){ | |
50 mp_msg(MSGT_AFILTER,MSGL_ERR,"Could not allocate memory\n"); | |
51 return NULL; | |
52 } | |
53 memset(new,0,sizeof(af_instance_t)); | |
54 | |
55 // Find filter from name | |
56 new->info=af_find(name); | |
57 | |
58 // Initialize the new filter | |
59 if(new->info && (AF_OK==new->info->open(new))) | |
60 return new; | |
61 | |
62 free(new); | |
63 mp_msg(MSGT_AFILTER,MSGL_ERR,"Couldn't create audio filter '%s'\n",name); | |
64 return NULL; | |
65 } | |
66 | |
67 /* Create and insert a new filter of type name before the filter in the | |
68 argument. This function can be called during runtime, the return | |
69 value is the new filter */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
70 af_instance_t* af_prepend(af_stream_t* s, af_instance_t* af, char* name) |
7568 | 71 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
72 // Create the new filter and make sure it is OK |
7568 | 73 af_instance_t* new=af_create(name); |
74 if(!new) | |
75 return NULL; | |
76 // Update pointers | |
77 new->next=af; | |
78 if(af){ | |
79 new->prev=af->prev; | |
80 af->prev=new; | |
81 } | |
82 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
83 s->last=new; |
7568 | 84 if(new->prev) |
85 new->prev->next=new; | |
86 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
87 s->first=new; |
7568 | 88 return new; |
89 } | |
90 | |
91 /* Create and insert a new filter of type name after the filter in the | |
92 argument. This function can be called during runtime, the return | |
93 value is the new filter */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
94 af_instance_t* af_append(af_stream_t* s, af_instance_t* af, char* name) |
7568 | 95 { |
96 // Create the new filter and make sure it is OK | |
97 af_instance_t* new=af_create(name); | |
98 if(!new) | |
99 return NULL; | |
100 // Update pointers | |
101 new->prev=af; | |
102 if(af){ | |
103 new->next=af->next; | |
104 af->next=new; | |
105 } | |
106 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
107 s->first=new; |
7568 | 108 if(new->next) |
109 new->next->prev=new; | |
110 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
111 s->last=new; |
7568 | 112 return new; |
113 } | |
114 | |
115 // Uninit and remove the filter "af" | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
116 void af_remove(af_stream_t* s, af_instance_t* af) |
7568 | 117 { |
118 if(!af) return; | |
119 | |
120 // Detach pointers | |
121 if(af->prev) | |
122 af->prev->next=af->next; | |
123 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
124 s->first=af->next; |
7568 | 125 if(af->next) |
126 af->next->prev=af->prev; | |
127 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
128 s->last=af->prev; |
7568 | 129 |
130 // Uninitialize af and free memory | |
131 af->uninit(af); | |
132 free(af); | |
133 } | |
134 | |
135 /* Reinitializes all filters downstream from the filter given in the argument */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
136 int af_reinit(af_stream_t* s, af_instance_t* af) |
7568 | 137 { |
138 if(!af) | |
139 return AF_ERROR; | |
140 | |
141 do{ | |
142 af_data_t in; // Format of the input to current filter | |
143 int rv=0; // Return value | |
144 | |
145 // Check if this is the first filter | |
146 if(!af->prev) | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
147 memcpy(&in,&(s->input),sizeof(af_data_t)); |
7568 | 148 else |
149 memcpy(&in,af->prev->data,sizeof(af_data_t)); | |
150 // Reset just in case... | |
151 in.audio=NULL; | |
152 in.len=0; | |
153 | |
154 rv = af->control(af,AF_CONTROL_REINIT,&in); | |
155 switch(rv){ | |
156 case AF_OK: | |
157 break; | |
158 case AF_FALSE:{ // Configuration filter is needed | |
159 af_instance_t* new = NULL; | |
160 // Insert channels filter | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
161 if((af->prev?af->prev->data->nch:s->input.nch) != in.nch){ |
7568 | 162 // Create channels filter |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
163 if(NULL == (new = af_prepend(s,af,"channels"))) |
7568 | 164 return AF_ERROR; |
165 // Set number of output channels | |
166 if(AF_OK != (rv = new->control(new,AF_CONTROL_CHANNELS,&in.nch))) | |
167 return rv; | |
168 // Initialize channels filter | |
169 if(!new->prev) | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
170 memcpy(&in,&(s->input),sizeof(af_data_t)); |
7568 | 171 else |
172 memcpy(&in,new->prev->data,sizeof(af_data_t)); | |
173 if(AF_OK != (rv = new->control(new,AF_CONTROL_REINIT,&in))) | |
174 return rv; | |
175 } | |
176 // Insert format filter | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
177 if(((af->prev?af->prev->data->format:s->input.format) != in.format) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
178 ((af->prev?af->prev->data->bps:s->input.bps) != in.bps)){ |
7568 | 179 // Create format filter |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
180 if(NULL == (new = af_prepend(s,af,"format"))) |
7568 | 181 return AF_ERROR; |
182 // Set output format | |
183 if(AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT,&in))) | |
184 return rv; | |
185 // Initialize format filter | |
186 if(!new->prev) | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
187 memcpy(&in,&(s->input),sizeof(af_data_t)); |
7568 | 188 else |
189 memcpy(&in,new->prev->data,sizeof(af_data_t)); | |
190 if(AF_OK != (rv = new->control(new,AF_CONTROL_REINIT,&in))) | |
191 return rv; | |
192 } | |
193 if(!new) // Should _never_ happen | |
194 return AF_ERROR; | |
195 af=new; | |
196 break; | |
197 } | |
198 case AF_DETACH:{ // Filter is redundant and wants to be unloaded | |
199 af_instance_t* aft=af->prev; | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
200 af_remove(s,af); |
7568 | 201 if(aft) |
202 af=aft; | |
203 else | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
204 af=s->first; // Restart configuration |
7568 | 205 break; |
206 } | |
207 default: | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
208 mp_msg(MSGT_AFILTER,MSGL_ERR,"Reinitialization did not work, audio filter '%s' returned error code %i\n",af->info->name,rv); |
7568 | 209 return AF_ERROR; |
210 } | |
211 af=af->next; | |
212 }while(af); | |
213 return AF_OK; | |
214 } | |
215 | |
216 /* Find filter in the dynamic filter list using it's name This | |
217 function is used for finding already initialized filters */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
218 af_instance_t* af_get(af_stream_t* s, char* name) |
7568 | 219 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
220 af_instance_t* af=s->first; |
7568 | 221 while(af->next != NULL){ |
222 if(!strcmp(af->info->name,name)) | |
223 return af; | |
224 af=af->next; | |
225 } | |
226 return NULL; | |
227 } | |
228 | |
229 // 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
|
230 void af_uninit(af_stream_t* s) |
7568 | 231 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
232 while(s->first) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
233 af_remove(s,s->first); |
7568 | 234 } |
235 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
236 /* Initialize the stream "s". This function creates a new filter list |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
237 if necessary 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
|
238 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
|
239 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
|
240 reentrant i.e. if called with 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
|
241 stream will be reinitialized. The return value is 0 if success and |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
242 -1 if failure */ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
243 int af_init(af_stream_t* s) |
7568 | 244 { |
245 int cfg=SLOW; // configuration type | |
246 int i=0; | |
247 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
248 // Sanity check |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
249 if(!s) return -1; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
250 |
7568 | 251 // Precaution in case caller is misbehaving |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
252 s->input.audio = s->output.audio = NULL; |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
253 s->input.len = s->output.len = 0; |
7568 | 254 |
255 // Figure out how fast the machine is | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
256 if(s->cfg.force) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
257 cfg=s->cfg.force; |
7568 | 258 else{ |
259 # if defined(HAVE_SSE) || defined(HAVE_3DNOWEX) | |
260 cfg=FAST; | |
261 # else | |
262 cfg=SLOW; | |
263 # endif | |
264 } | |
265 | |
266 // Check if this is the first call | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
267 if(!s->first){ |
7568 | 268 // Add all filters in the list (if there are any) |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
269 if(!s->cfg.list){ // To make automatic format conversion work |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
270 if(!af_append(s,s->first,"dummy")) |
7568 | 271 return -1; |
272 } | |
273 else{ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
274 while(s->cfg.list[i]){ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
275 if(!af_append(s,s->last,s->cfg.list[i++])) |
7568 | 276 return -1; |
277 } | |
278 } | |
279 } | |
280 | |
281 // Init filters | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
282 if(AF_OK != af_reinit(s,s->first)) |
7568 | 283 return -1; |
284 | |
285 // Check output format | |
286 if(cfg!=FORCE){ | |
287 af_instance_t* af = NULL; // New filter | |
288 // Check output frequency if not OK fix with resample | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
289 if(s->last->data->rate!=s->output.rate){ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
290 if(NULL==(af=af_get(s,"resample"))){ |
7568 | 291 if(cfg==SLOW){ |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
292 if(!strcmp(s->first->info->name,"format")) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
293 af = af_append(s,s->first,"resample"); |
7568 | 294 else |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
295 af = af_prepend(s,s->first,"resample"); |
7568 | 296 } |
297 else{ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
298 if(!strcmp(s->last->info->name,"format")) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
299 af = af_prepend(s,s->last,"resample"); |
7568 | 300 else |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
301 af = af_append(s,s->last,"resample"); |
7568 | 302 } |
303 } | |
304 // Init the new filter | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
305 if(!af || (AF_OK != af->control(af,AF_CONTROL_RESAMPLE,&(s->output.rate)))) |
7568 | 306 return -1; |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
307 if(AF_OK != af_reinit(s,af)) |
7568 | 308 return -1; |
309 } | |
310 | |
311 // Check number of output channels fix if not OK | |
312 // If needed always inserted last -> easy to screw up other filters | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
313 if(s->last->data->nch!=s->output.nch){ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
314 if(!strcmp(s->last->info->name,"format")) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
315 af = af_prepend(s,s->last,"channels"); |
7568 | 316 else |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
317 af = af_append(s,s->last,"channels"); |
7568 | 318 // Init the new filter |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
319 if(!af || (AF_OK != af->control(af,AF_CONTROL_CHANNELS,&(s->output.nch)))) |
7568 | 320 return -1; |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
321 if(AF_OK != af_reinit(s,af)) |
7568 | 322 return -1; |
323 } | |
324 | |
325 // Check output format fix if not OK | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
326 if((s->last->data->format != s->output.format) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
327 (s->last->data->bps != s->output.bps)){ |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
328 if(strcmp(s->last->info->name,"format")) |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
329 af = af_append(s,s->last,"format"); |
7568 | 330 else |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
331 af = s->last; |
7568 | 332 // Init the new filter |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
333 if(!af ||(AF_OK != af->control(af,AF_CONTROL_FORMAT,&(s->output)))) |
7568 | 334 return -1; |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
335 if(AF_OK != af_reinit(s,af)) |
7568 | 336 return -1; |
337 } | |
338 | |
339 // Re init again just in case | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
340 if(AF_OK != af_reinit(s,s->first)) |
7568 | 341 return -1; |
342 | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
343 if((s->last->data->format != s->output.format) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
344 (s->last->data->bps != s->output.bps) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
345 (s->last->data->nch != s->output.nch) || |
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
346 (s->last->data->rate != s->output.rate)) { |
7568 | 347 // Something is stuffed audio out will not work |
348 mp_msg(MSGT_AFILTER,MSGL_ERR,"Unable to setup filter system can not meet sound-card demands, please report this error on MPlayer development mailing list. \n"); | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
349 af_uninit(s); |
7568 | 350 return -1; |
351 } | |
352 } | |
353 return 0; | |
354 } | |
355 | |
356 // 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
|
357 af_data_t* af_play(af_stream_t* s, af_data_t* data) |
7568 | 358 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
359 af_instance_t* af=s->first; |
7568 | 360 // Iterate through all filters |
361 do{ | |
362 data=af->play(af,data); | |
363 af=af->next; | |
364 }while(af); | |
365 return data; | |
366 } | |
367 | |
368 /* Helper function used to calculate the exact buffer length needed | |
369 when buffers are resized */ | |
370 inline int af_lencalc(frac_t mul, int len){ | |
371 register int q = len*mul.n; | |
372 return q/mul.d + q%mul.d; | |
373 } | |
374 | |
375 /* Calculate how long the output from the filters will be given the | |
376 input length "len" */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
377 int af_outputlen(af_stream_t* s, int len) |
7568 | 378 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
379 af_instance_t* af=s->first; |
7568 | 380 frac_t mul = {1,1}; |
381 // Iterate through all filters | |
382 do{ | |
383 mul.n *= af->mul.n; | |
384 mul.d *= af->mul.d; | |
385 af=af->next; | |
386 }while(af); | |
387 return af_lencalc(mul,len); | |
388 } | |
389 | |
390 /* Calculate how long the input to the filters should be to produce a | |
391 certain output length, i.e. the return value of this function is | |
392 the input length required to produce the output length "len". */ | |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
393 int af_inputlen(af_stream_t* s, int len) |
7568 | 394 { |
7571
8819fdf88b5d
Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents:
7568
diff
changeset
|
395 af_instance_t* af=s->first; |
7568 | 396 frac_t mul = {1,1}; |
397 // Iterate through all filters | |
398 do{ | |
399 mul.d *= af->mul.n; | |
400 mul.n *= af->mul.d; | |
401 af=af->next; | |
402 }while(af); | |
403 return af_lencalc(mul,len); | |
404 } | |
405 | |
406 /* Helper function called by the macro with the same name this | |
407 function should not be called directly */ | |
408 inline int af_resize_local_buffer(af_instance_t* af, af_data_t* data) | |
409 { | |
410 // Calculate new length | |
411 register int len = af_lencalc(af->mul,data->len); | |
412 mp_msg(MSGT_AFILTER,MSGL_V,"Reallocating memory in module %s, old len = %i, new len = %i\n",af->info->name,af->data->len,len); | |
413 // If there is a buffer free it | |
414 if(af->data->audio) | |
415 free(af->data->audio); | |
416 // Create new buffer and check that it is OK | |
417 af->data->audio = malloc(len); | |
418 if(!af->data->audio){ | |
419 mp_msg(MSGT_AFILTER,MSGL_ERR,"Could not allocate memory \n"); | |
420 return AF_ERROR; | |
421 } | |
422 af->data->len=len; | |
423 return AF_OK; | |
424 } |