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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
1 #include <stdio.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
2 #include <stdlib.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
3 #include <string.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
4
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
5 #ifdef HAVE_MALLOC_H
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
6 #include <malloc.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
7 #endif
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
8
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
9 #include "../config.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
10 #include "../mp_msg.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
11
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
12 #include "af.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
13
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
14 // Static list of filters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
15 extern af_info_t af_info_dummy;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
16 extern af_info_t af_info_delay;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
17 extern af_info_t af_info_channels;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
18 extern af_info_t af_info_format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
19 extern af_info_t af_info_resample;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
20
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
21 static af_info_t* filter_list[]={ \
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
22 &af_info_dummy,\
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
23 &af_info_delay,\
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
24 &af_info_channels,\
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
25 &af_info_format,\
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
26 &af_info_resample,\
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
27 NULL \
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
28 };
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
29
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
30 /* Find a filter in the static list of filters using it's name. This
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
31 function is used internally */
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
32 af_info_t* af_find(char*name)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
33 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
34 int i=0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
35 while(filter_list[i]){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
36 if(!strcmp(filter_list[i]->name,name))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
37 return filter_list[i];
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
38 i++;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
39 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
40 mp_msg(MSGT_AFILTER,MSGL_ERR,"Couldn't find audio filter '%s'\n",name);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
41 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
42 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
43
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
44 // Function for creating a new filter of type name
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
45 af_instance_t* af_create(char* name)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
46 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
47 // Allocate space for the new filter and reset all pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
48 af_instance_t* new=malloc(sizeof(af_instance_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
49 if(!new){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
50 mp_msg(MSGT_AFILTER,MSGL_ERR,"Could not allocate memory\n");
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
51 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
52 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
53 memset(new,0,sizeof(af_instance_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
54
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
55 // Find filter from name
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
56 new->info=af_find(name);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
57
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
58 // Initialize the new filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
59 if(new->info && (AF_OK==new->info->open(new)))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
60 return new;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
61
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
62 free(new);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
63 mp_msg(MSGT_AFILTER,MSGL_ERR,"Couldn't create audio filter '%s'\n",name);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
64 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
65 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
66
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
67 /* Create and insert a new filter of type name before the filter in the
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
68 argument. This function can be called during runtime, the return
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
73 af_instance_t* new=af_create(name);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
74 if(!new)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
75 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
76 // Update pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
77 new->next=af;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
78 if(af){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
79 new->prev=af->prev;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
80 af->prev=new;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
81 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
84 if(new->prev)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
85 new->prev->next=new;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
88 return new;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
89 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
90
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
91 /* Create and insert a new filter of type name after the filter in the
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
92 argument. This function can be called during runtime, the return
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
95 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
96 // Create the new filter and make sure it is OK
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
97 af_instance_t* new=af_create(name);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
98 if(!new)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
99 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
100 // Update pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
101 new->prev=af;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
102 if(af){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
103 new->next=af->next;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
104 af->next=new;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
105 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
108 if(new->next)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
109 new->next->prev=new;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
112 return new;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
113 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
114
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
117 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
118 if(!af) return;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
119
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
120 // Detach pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
121 if(af->prev)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
122 af->prev->next=af->next;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
125 if(af->next)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
126 af->next->prev=af->prev;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
129
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
130 // Uninitialize af and free memory
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
131 af->uninit(af);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
132 free(af);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
133 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
134
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
137 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
138 if(!af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
139 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
140
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
141 do{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
142 af_data_t in; // Format of the input to current filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
143 int rv=0; // Return value
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
144
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
145 // Check if this is the first filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
148 else
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
149 memcpy(&in,af->prev->data,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
150 // Reset just in case...
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
151 in.audio=NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
152 in.len=0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
153
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
154 rv = af->control(af,AF_CONTROL_REINIT,&in);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
155 switch(rv){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
156 case AF_OK:
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
157 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
158 case AF_FALSE:{ // Configuration filter is needed
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
159 af_instance_t* new = NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
164 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
165 // Set number of output channels
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
166 if(AF_OK != (rv = new->control(new,AF_CONTROL_CHANNELS,&in.nch)))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
167 return rv;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
168 // Initialize channels filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
171 else
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
172 memcpy(&in,new->prev->data,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
173 if(AF_OK != (rv = new->control(new,AF_CONTROL_REINIT,&in)))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
174 return rv;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
175 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
181 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
182 // Set output format
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
183 if(AF_OK != (rv = new->control(new,AF_CONTROL_FORMAT,&in)))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
184 return rv;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
185 // Initialize format filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
188 else
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
189 memcpy(&in,new->prev->data,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
190 if(AF_OK != (rv = new->control(new,AF_CONTROL_REINIT,&in)))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
191 return rv;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
192 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
193 if(!new) // Should _never_ happen
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
194 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
195 af=new;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
196 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
197 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
198 case AF_DETACH:{ // Filter is redundant and wants to be unloaded
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
201 if(aft)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
202 af=aft;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
205 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
206 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
209 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
210 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
211 af=af->next;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
212 }while(af);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
213 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
214 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
215
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
216 /* Find filter in the dynamic filter list using it's name This
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
221 while(af->next != NULL){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
222 if(!strcmp(af->info->name,name))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
223 return af;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
224 af=af->next;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
225 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
226 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
227 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
228
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
234 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
244 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
245 int cfg=SLOW; // configuration type
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
246 int i=0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
254
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
258 else{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
259 # if defined(HAVE_SSE) || defined(HAVE_3DNOWEX)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
260 cfg=FAST;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
261 # else
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
262 cfg=SLOW;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
263 # endif
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
264 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
265
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
271 return -1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
272 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
276 return -1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
277 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
278 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
279 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
280
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
283 return -1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
284
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
285 // Check output format
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
286 if(cfg!=FORCE){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
287 af_instance_t* af = NULL; // New filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
296 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
302 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
303 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
308 return -1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
309 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
310
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
311 // Check number of output channels fix if not OK
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
322 return -1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
323 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
324
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
336 return -1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
337 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
338
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
341 return -1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
347 // Something is stuffed audio out will not work
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
350 return -1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
351 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
352 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
353 return 0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
354 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
355
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
360 // Iterate through all filters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
361 do{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
362 data=af->play(af,data);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
363 af=af->next;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
364 }while(af);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
365 return data;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
366 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
367
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
368 /* Helper function used to calculate the exact buffer length needed
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
369 when buffers are resized */
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
370 inline int af_lencalc(frac_t mul, int len){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
371 register int q = len*mul.n;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
372 return q/mul.d + q%mul.d;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
373 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
374
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
375 /* Calculate how long the output from the filters will be given the
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
380 frac_t mul = {1,1};
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
381 // Iterate through all filters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
382 do{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
383 mul.n *= af->mul.n;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
384 mul.d *= af->mul.d;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
385 af=af->next;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
386 }while(af);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
387 return af_lencalc(mul,len);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
388 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
389
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
390 /* Calculate how long the input to the filters should be to produce a
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
391 certain output length, i.e. the return value of this function is
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
396 frac_t mul = {1,1};
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
397 // Iterate through all filters
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
398 do{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
399 mul.d *= af->mul.n;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
400 mul.n *= af->mul.d;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
401 af=af->next;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
402 }while(af);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
403 return af_lencalc(mul,len);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
404 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
405
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
406 /* Helper function called by the macro with the same name this
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
407 function should not be called directly */
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
408 inline int af_resize_local_buffer(af_instance_t* af, af_data_t* data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
409 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
410 // Calculate new length
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
411 register int len = af_lencalc(af->mul,data->len);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
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);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
413 // If there is a buffer free it
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
414 if(af->data->audio)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
415 free(af->data->audio);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
416 // Create new buffer and check that it is OK
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
417 af->data->audio = malloc(len);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
418 if(!af->data->audio){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
419 mp_msg(MSGT_AFILTER,MSGL_ERR,"Could not allocate memory \n");
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
420 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
421 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
422 af->data->len=len;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
423 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
424 }