annotate libao2/ao_plugin.c @ 5834:ece3a19677b9

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