Mercurial > mplayer.hg
annotate libao2/ao_plugin.c @ 11654:8bdbc6a93d74
added <systemitem> tag for fontconfig, some wording
author | paszczi |
---|---|
date | Tue, 16 Dec 2003 22:57:34 +0000 |
parents | 12b1790038b0 |
children | 99798c3cdb93 |
rev | line source |
---|---|
6237 | 1 #include "../config.h" |
2 | |
3096 | 3 #include <stdio.h> |
4 #include <stdlib.h> | |
6237 | 5 #include <string.h> |
3096 | 6 |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
7 #include "afmt.h" |
3096 | 8 #include "audio_out.h" |
9 #include "audio_out_internal.h" | |
10 | |
11 #include "audio_plugin.h" | |
12 | |
13 static ao_info_t info = | |
14 { | |
15 "Plugin audio output", | |
16 "plugin", | |
17 "Anders", | |
18 "" | |
19 }; | |
20 | |
21 LIBAO_EXTERN(plugin) | |
22 | |
3107 | 23 #define plugin(i) (ao_plugin_local_data.plugins[i]) |
24 #define driver() (ao_plugin_local_data.driver) | |
3096 | 25 |
3107 | 26 // local data |
3096 | 27 typedef struct ao_plugin_local_data_s |
28 { | |
4313 | 29 void* buf; // Output data buffer |
30 int len; // Amount of data in buffer | |
6027
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
31 int channels; |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
32 int format; |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
33 int bpm; //bit of format |
4313 | 34 float bps; // Bytes per second out |
35 ao_functions_t* driver; // Output driver | |
3107 | 36 ao_plugin_functions_t** plugins; // List of used plugins |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
37 ao_plugin_functions_t* available_plugins[NPL]; // List of available plugins |
3096 | 38 } ao_plugin_local_data_t; |
39 | |
6027
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
40 static ao_plugin_local_data_t ao_plugin_local_data={NULL,0,0,0,0,0.0,NULL,NULL,AO_PLUGINS}; |
3096 | 41 |
4313 | 42 // global data |
4896 | 43 volatile ao_plugin_data_t ao_plugin_data; // Data used by the plugins |
4859 | 44 ao_plugin_cfg_t ao_plugin_cfg=CFG_DEFAULTS; // Set in cfg-mplayer.h |
3096 | 45 |
46 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
8979
diff
changeset
|
47 static int control(int cmd,void *arg){ |
3107 | 48 switch(cmd){ |
49 case AOCONTROL_SET_PLUGIN_DRIVER: | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
8979
diff
changeset
|
50 ao_plugin_local_data.driver=arg; |
3107 | 51 return CONTROL_OK; |
4859 | 52 case AOCONTROL_GET_VOLUME: |
53 case AOCONTROL_SET_VOLUME: | |
54 { | |
55 int r=audio_plugin_volume.control(cmd,arg); | |
56 if(CONTROL_OK != r) | |
57 return driver()->control(cmd,arg); | |
58 else | |
59 return r; | |
60 } | |
3107 | 61 default: |
62 return driver()->control(cmd,arg); | |
63 } | |
64 return CONTROL_UNKNOWN; | |
65 } | |
66 | |
67 // Recursive function for adding plugins | |
68 // return 1 for success and 0 for error | |
69 int add_plugin(int i,char* cfg){ | |
70 int cnt=0; | |
71 // Find end of plugin name | |
72 while((cfg[cnt]!=',')&&(cfg[cnt]!='\0')&&(cnt<100)) cnt++; | |
73 if(cnt >= 100) | |
74 return 0; | |
75 | |
3680 | 76 // Is this the last iteration or just another plugin |
3107 | 77 if(cfg[cnt]=='\0'){ |
5773 | 78 ao_plugin_local_data.plugins=malloc((i+2)*sizeof(ao_plugin_functions_t*)); |
3107 | 79 if(ao_plugin_local_data.plugins){ |
80 ao_plugin_local_data.plugins[i+1]=NULL; | |
81 // Find the plugin matching the cfg string name | |
82 cnt=0; | |
83 while(ao_plugin_local_data.available_plugins[cnt] && cnt<20){ | |
84 if(0==strcmp(ao_plugin_local_data.available_plugins[cnt]->info->short_name,cfg)){ | |
85 ao_plugin_local_data.plugins[i]=ao_plugin_local_data.available_plugins[cnt]; | |
86 return 1; | |
87 } | |
88 cnt++; | |
89 } | |
90 printf("[plugin]: Invalid plugin: %s \n",cfg); | |
91 return 0; | |
92 } | |
93 else | |
94 return 0; | |
95 } else { | |
96 cfg[cnt]='\0'; | |
97 if(add_plugin(i+1,&cfg[cnt+1])){ | |
98 cnt=0; | |
99 // Find the plugin matching the cfg string name | |
100 while(ao_plugin_local_data.available_plugins[cnt] && cnt < 20){ | |
101 if(0==strcmp(ao_plugin_local_data.available_plugins[cnt]->info->short_name,cfg)){ | |
102 ao_plugin_local_data.plugins[i]=ao_plugin_local_data.available_plugins[cnt]; | |
103 return 1; | |
104 } | |
105 cnt++; | |
106 } | |
107 printf("[plugin]: Invalid plugin: %s \n",cfg); | |
108 return 0; | |
109 } | |
110 else | |
111 return 0; | |
112 } | |
113 return 0; // Will never happen... | |
3096 | 114 } |
115 | |
116 // open & setup audio device and plugins | |
117 // return: 1=success 0=fail | |
118 static int init(int rate,int channels,int format,int flags){ | |
6319
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
119 int use_plugin[NPL]; |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
120 int x,npl,unused=0; |
3096 | 121 int ok=1; |
6319
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
122 char *config; |
3096 | 123 |
4313 | 124 // Create list of plugins from cfg option |
3096 | 125 int i=0; |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
126 if(ao_plugin_cfg.plugin_list){ |
8979 | 127 config = malloc(strlen(ao_plugin_cfg.plugin_list)+1); |
6319
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
128 if(!config) return 0; |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
129 if(!strcpy(config, ao_plugin_cfg.plugin_list) || !add_plugin(i,config)){ |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
130 free(config); |
3107 | 131 return 0; |
6319
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
132 } |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
133 free(config); |
3107 | 134 } |
3096 | 135 |
136 /* Set input parameters and itterate through plugins each plugin | |
137 changes the parameters according to its output */ | |
6027
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
138 |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
139 ao_plugin_local_data.format=format; |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
140 ao_plugin_local_data.channels=channels; |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
141 ao_plugin_local_data.bpm=audio_out_format_bits(format); |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
142 |
3096 | 143 ao_plugin_data.rate=rate; |
144 ao_plugin_data.channels=channels; | |
145 ao_plugin_data.format=format; | |
146 ao_plugin_data.sz_mult=1; | |
147 ao_plugin_data.sz_fix=0; | |
148 ao_plugin_data.delay_mult=1; | |
149 ao_plugin_data.delay_fix=0; | |
6319
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
150 |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
6372
diff
changeset
|
151 for(i=0;i<NPL && plugin(i);i++){ |
6319
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
152 use_plugin[i]=plugin(i)->init(); |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
153 if(!use_plugin[i]) plugin(i)->uninit(); |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
154 } |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
155 npl=i; |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
6372
diff
changeset
|
156 for(i=0;i<npl && plugin(i);i++) |
6319
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
157 if(!use_plugin[i+unused]){ |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
158 unused++; |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
6372
diff
changeset
|
159 for(x=i;x<npl && plugin(x+1);x++) plugin(x)=plugin(x+1); |
6319
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
160 plugin(x)=NULL; |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
161 npl--; |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
162 i--; |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
163 } |
76baa05a63ab
disables those plugins that can't handle the audio format.
arpi
parents:
6237
diff
changeset
|
164 i=npl; |
3096 | 165 |
4313 | 166 // Calculate bps |
167 ao_plugin_local_data.bps=(float)(ao_plugin_data.rate * | |
168 ao_plugin_data.channels); | |
6027
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
169 ao_plugin_local_data.bps*=audio_out_format_bits(ao_plugin_data.format)/8; |
4313 | 170 |
3107 | 171 // This should never happen but check anyway |
172 if(NULL==ao_plugin_local_data.driver) | |
173 return 0; | |
174 | |
3096 | 175 ok = driver()->init(ao_plugin_data.rate, |
3107 | 176 ao_plugin_data.channels, |
177 ao_plugin_data.format, | |
178 flags); | |
3096 | 179 if(!ok) return 0; |
180 | |
181 /* Now that the driver is initialized we can calculate and set the | |
182 input and output buffers for each plugin */ | |
183 ao_plugin_data.len=driver()->get_space(); | |
3107 | 184 while((i>0) && ok) |
3194
1648d11fc36c
commandline configuration of audio plugins now through struct, format conversion plugin added
anders
parents:
3107
diff
changeset
|
185 ok=plugin(--i)->control(AOCONTROL_PLUGIN_SET_LEN,0); |
3107 | 186 |
187 if(!ok) return 0; | |
3096 | 188 |
4374
0a95c5074c50
Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents:
4313
diff
changeset
|
189 // Allocate output buffer |
4313 | 190 if(ao_plugin_local_data.buf) |
191 free(ao_plugin_local_data.buf); | |
192 ao_plugin_local_data.buf=malloc(MAX_OUTBURST); | |
193 | |
194 if(!ao_plugin_local_data.buf) return 0; | |
195 | |
3096 | 196 return 1; |
197 } | |
198 | |
199 // close audio device | |
200 static void uninit(){ | |
201 int i=0; | |
202 driver()->uninit(); | |
203 while(plugin(i)) | |
204 plugin(i++)->uninit(); | |
3107 | 205 if(ao_plugin_local_data.plugins) |
206 free(ao_plugin_local_data.plugins); | |
5050 | 207 ao_plugin_local_data.plugins=NULL; |
4313 | 208 if(ao_plugin_local_data.buf) |
209 free(ao_plugin_local_data.buf); | |
5050 | 210 ao_plugin_local_data.buf=NULL; |
3096 | 211 } |
212 | |
213 // stop playing and empty buffers (for seeking/pause) | |
214 static void reset(){ | |
215 int i=0; | |
216 driver()->reset(); | |
217 while(plugin(i)) | |
218 plugin(i++)->reset(); | |
4313 | 219 ao_plugin_local_data.len=0; |
3096 | 220 } |
221 | |
222 // stop playing, keep buffers (for pause) | |
223 static void audio_pause(){ | |
224 driver()->pause(); | |
225 } | |
226 | |
227 // resume playing, after audio_pause() | |
228 static void audio_resume(){ | |
229 driver()->resume(); | |
230 } | |
231 | |
232 // return: how many bytes can be played without blocking | |
233 static int get_space(){ | |
6027
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
234 double sz; |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
235 int isz; |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
236 sz=(double)(driver()->get_space()); |
4313 | 237 if(sz+(double)ao_plugin_local_data.len > (double)MAX_OUTBURST) |
238 sz=(double)MAX_OUTBURST-(double)ao_plugin_local_data.len; | |
3096 | 239 sz*=ao_plugin_data.sz_mult; |
240 sz+=ao_plugin_data.sz_fix; | |
6027
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
241 isz=(int)(sz); |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
242 isz-=isz%(ao_plugin_local_data.channels*ao_plugin_local_data.bpm/8); |
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
243 return isz; |
3096 | 244 } |
245 | |
246 // plays 'len' bytes of 'data' | |
247 // return: number of bytes played | |
248 static int play(void* data,int len,int flags){ | |
4313 | 249 int l,i=0; |
250 // Limit length to avoid over flow in plugins | |
4922 | 251 int tmp = get_space(); |
3096 | 252 int ret_len =(tmp<len)?tmp:len; |
6372 | 253 // keep all channels of each sample together |
254 ret_len -= ret_len % (ao_plugin_local_data.channels*ao_plugin_local_data.bpm/8); | |
4375 | 255 if(ret_len){ |
256 // Filter data | |
257 ao_plugin_data.len=ret_len; | |
258 ao_plugin_data.data=data; | |
6027
7c26ef54ff14
fixed sdl+resample bug coused by float point to int rounding error
iive
parents:
5773
diff
changeset
|
259 |
4376 | 260 while(plugin(i)) |
4375 | 261 plugin(i++)->play(); |
262 // Copy data to output buffer | |
263 memcpy(ao_plugin_local_data.buf+ao_plugin_local_data.len, | |
264 ao_plugin_data.data,ao_plugin_data.len); | |
265 // Send data to output | |
266 l=driver()->play(ao_plugin_local_data.buf, | |
267 ao_plugin_data.len+ao_plugin_local_data.len,flags); | |
268 // Save away unsent data | |
269 ao_plugin_local_data.len=ao_plugin_data.len+ao_plugin_local_data.len-l; | |
270 memcpy(ao_plugin_local_data.buf,ao_plugin_local_data.buf+l, | |
271 ao_plugin_local_data.len); | |
272 } | |
3096 | 273 return ret_len; |
274 } | |
275 | |
276 // return: delay in seconds between first and last sample in buffer | |
277 static float get_delay(){ | |
278 float delay=driver()->get_delay(); | |
4313 | 279 delay+=(float)ao_plugin_local_data.len/ao_plugin_local_data.bps; |
3096 | 280 delay*=ao_plugin_data.delay_mult; |
281 delay+=ao_plugin_data.delay_fix; | |
282 return delay; | |
283 } | |
284 | |
285 | |
3279
d6ea11bed983
Commandline interface to ao_plugin updated according to mplayers complex parameter format and plugin pl_format finished (alpha code needs testing)
anders
parents:
3194
diff
changeset
|
286 |
d6ea11bed983
Commandline interface to ao_plugin updated according to mplayers complex parameter format and plugin pl_format finished (alpha code needs testing)
anders
parents:
3194
diff
changeset
|
287 |