annotate libao2/ao_plugin.c @ 11402:b0c13371ebdf

remove uncommon langinfo code and replace it by more common setlocal. patch by Steven M. Schultz <sms@2BSD.COM>
author alex
date Thu, 06 Nov 2003 22:28:55 +0000
parents 12b1790038b0
children 99798c3cdb93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6237
2eec40929570 warning fixes (string.h is required for memset)
pl
parents: 6027
diff changeset
1 #include "../config.h"
2eec40929570 warning fixes (string.h is required for memset)
pl
parents: 6027
diff changeset
2
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
3 #include <stdio.h>
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
4 #include <stdlib.h>
6237
2eec40929570 warning fixes (string.h is required for memset)
pl
parents: 6027
diff changeset
5 #include <string.h>
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
8 #include "audio_out.h"
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
9 #include "audio_out_internal.h"
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
10
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
11 #include "audio_plugin.h"
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
12
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
13 static ao_info_t info =
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
14 {
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
15 "Plugin audio output",
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
16 "plugin",
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
17 "Anders",
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
21 LIBAO_EXTERN(plugin)
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
22
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
23 #define plugin(i) (ao_plugin_local_data.plugins[i])
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
24 #define driver() (ao_plugin_local_data.driver)
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
25
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
26 // local data
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
27 typedef struct ao_plugin_local_data_s
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
28 {
4313
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
29 void* buf; // Output data buffer
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
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
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
34 float bps; // Bytes per second out
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
35 ao_functions_t* driver; // Output driver
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
38 } ao_plugin_local_data_t;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
41
4313
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
42 // global data
4896
120027e44f80 10l... gcc 3.x fix
arpi
parents: 4859
diff changeset
43 volatile ao_plugin_data_t ao_plugin_data; // Data used by the plugins
4859
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
44 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
45
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
48 switch(cmd){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
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
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
51 return CONTROL_OK;
4859
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
52 case AOCONTROL_GET_VOLUME:
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
53 case AOCONTROL_SET_VOLUME:
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
54 {
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
55 int r=audio_plugin_volume.control(cmd,arg);
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
56 if(CONTROL_OK != r)
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
57 return driver()->control(cmd,arg);
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
58 else
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
59 return r;
c72b386debb4 Adding SW volume control
anders
parents: 4376
diff changeset
60 }
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
61 default:
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
62 return driver()->control(cmd,arg);
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
63 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
64 return CONTROL_UNKNOWN;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
65 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
66
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
67 // Recursive function for adding plugins
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
68 // return 1 for success and 0 for error
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
69 int add_plugin(int i,char* cfg){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
70 int cnt=0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
71 // Find end of plugin name
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
72 while((cfg[cnt]!=',')&&(cfg[cnt]!='\0')&&(cnt<100)) cnt++;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
73 if(cnt >= 100)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
74 return 0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
75
3680
2cc5737ec923 fix comment typo
steve
parents: 3486
diff changeset
76 // Is this the last iteration or just another plugin
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
77 if(cfg[cnt]=='\0'){
5773
4c6b5ab80de2 memory leak(off by 1 bug)
iive
parents: 5050
diff changeset
78 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
79 if(ao_plugin_local_data.plugins){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
80 ao_plugin_local_data.plugins[i+1]=NULL;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
81 // Find the plugin matching the cfg string name
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
82 cnt=0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
83 while(ao_plugin_local_data.available_plugins[cnt] && cnt<20){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
84 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
85 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
86 return 1;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
87 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
88 cnt++;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
89 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
90 printf("[plugin]: Invalid plugin: %s \n",cfg);
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
91 return 0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
92 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
93 else
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
94 return 0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
95 } else {
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
96 cfg[cnt]='\0';
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
97 if(add_plugin(i+1,&cfg[cnt+1])){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
98 cnt=0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
99 // Find the plugin matching the cfg string name
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
100 while(ao_plugin_local_data.available_plugins[cnt] && cnt < 20){
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
101 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
102 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
103 return 1;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
104 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
105 cnt++;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
106 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
107 printf("[plugin]: Invalid plugin: %s \n",cfg);
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
108 return 0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
109 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
110 else
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
111 return 0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
112 }
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
113 return 0; // Will never happen...
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
114 }
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
115
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
116 // open & setup audio device and plugins
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
117 // return: 1=success 0=fail
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
123
4313
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
124 // Create list of plugins from cfg option
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
arpi
parents: 7472
diff changeset
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
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
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
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
134 }
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
135
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
136 /* Set input parameters and itterate through plugins each plugin
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
143 ao_plugin_data.rate=rate;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
144 ao_plugin_data.channels=channels;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
145 ao_plugin_data.format=format;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
146 ao_plugin_data.sz_mult=1;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
147 ao_plugin_data.sz_fix=0;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
148 ao_plugin_data.delay_mult=1;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
165
4313
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
166 // Calculate bps
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
167 ao_plugin_local_data.bps=(float)(ao_plugin_data.rate *
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
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
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
170
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
171 // This should never happen but check anyway
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
172 if(NULL==ao_plugin_local_data.driver)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
173 return 0;
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
174
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
175 ok = driver()->init(ao_plugin_data.rate,
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
176 ao_plugin_data.channels,
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
177 ao_plugin_data.format,
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
178 flags);
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
179 if(!ok) return 0;
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 /* Now that the driver is initialized we can calculate and set the
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
182 input and output buffers for each plugin */
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
183 ao_plugin_data.len=driver()->get_space();
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
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
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
186
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
187 if(!ok) return 0;
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
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);
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
192 ao_plugin_local_data.buf=malloc(MAX_OUTBURST);
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
193
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
194 if(!ao_plugin_local_data.buf) return 0;
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
195
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
196 return 1;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
197 }
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
198
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
199 // close audio device
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
200 static void uninit(){
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
201 int i=0;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
202 driver()->uninit();
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
203 while(plugin(i))
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
204 plugin(i++)->uninit();
3107
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
205 if(ao_plugin_local_data.plugins)
ef2287ccc42b Changes to audio out plugin, first plugin added
anders
parents: 3096
diff changeset
206 free(ao_plugin_local_data.plugins);
5050
b6d83ac1e3e0 Bugfix for sig11 when playing multiple files
anders
parents: 4922
diff changeset
207 ao_plugin_local_data.plugins=NULL;
4313
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
208 if(ao_plugin_local_data.buf)
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
209 free(ao_plugin_local_data.buf);
5050
b6d83ac1e3e0 Bugfix for sig11 when playing multiple files
anders
parents: 4922
diff changeset
210 ao_plugin_local_data.buf=NULL;
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
211 }
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 // stop playing and empty buffers (for seeking/pause)
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
214 static void reset(){
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
215 int i=0;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
216 driver()->reset();
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
217 while(plugin(i))
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
218 plugin(i++)->reset();
4313
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
219 ao_plugin_local_data.len=0;
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
220 }
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
221
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
222 // stop playing, keep buffers (for pause)
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
223 static void audio_pause(){
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
224 driver()->pause();
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
225 }
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
226
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
227 // resume playing, after audio_pause()
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
228 static void audio_resume(){
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
229 driver()->resume();
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
230 }
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
231
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
232 // return: how many bytes can be played without blocking
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
237 if(sz+(double)ao_plugin_local_data.len > (double)MAX_OUTBURST)
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
238 sz=(double)MAX_OUTBURST-(double)ao_plugin_local_data.len;
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
239 sz*=ao_plugin_data.sz_mult;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
244 }
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
245
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
246 // plays 'len' bytes of 'data'
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
247 // return: number of bytes played
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
248 static int play(void* data,int len,int flags){
4313
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
249 int l,i=0;
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
250 // Limit length to avoid over flow in plugins
4922
619a8032fdd2 Buggfix for buffer overflow calculation in plugins
anders
parents: 4896
diff changeset
251 int tmp = get_space();
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
252 int ret_len =(tmp<len)?tmp:len;
6372
075cca2558f9 Applying patch from Eric that fixes 6ch resampling
anders
parents: 6319
diff changeset
253 // keep all channels of each sample together
075cca2558f9 Applying patch from Eric that fixes 6ch resampling
anders
parents: 6319
diff changeset
254 ret_len -= ret_len % (ao_plugin_local_data.channels*ao_plugin_local_data.bpm/8);
4375
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
255 if(ret_len){
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
256 // Filter data
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
257 ao_plugin_data.len=ret_len;
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
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
118ae69769be Oops forgot to remove debug message :)
anders
parents: 4375
diff changeset
260 while(plugin(i))
4375
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
261 plugin(i++)->play();
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
262 // Copy data to output buffer
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
263 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
264 ao_plugin_data.data,ao_plugin_data.len);
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
265 // Send data to output
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
266 l=driver()->play(ao_plugin_local_data.buf,
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
267 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
268 // Save away unsent data
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
269 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
270 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
271 ao_plugin_local_data.len);
bd108c2796ab Fixed sig 11 caused by buffer full in ao driver
anders
parents: 4374
diff changeset
272 }
3096
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
273 return ret_len;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
274 }
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
275
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
276 // return: delay in seconds between first and last sample in buffer
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
277 static float get_delay(){
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
278 float delay=driver()->get_delay();
4313
1dbffed555a6 Added buffering of output data
anders
parents: 3680
diff changeset
279 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
280 delay*=ao_plugin_data.delay_mult;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
281 delay+=ao_plugin_data.delay_fix;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
282 return delay;
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
283 }
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
284
15abd9121737 ao_plugin.c and plugin headers added
anders
parents:
diff changeset
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