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