diff options
Diffstat (limited to 'libao2/ao_plugin.c')
-rw-r--r-- | libao2/ao_plugin.c | 117 |
1 files changed, 100 insertions, 17 deletions
diff --git a/libao2/ao_plugin.c b/libao2/ao_plugin.c index 9bf8d9b5c7..56e500e2ac 100644 --- a/libao2/ao_plugin.c +++ b/libao2/ao_plugin.c @@ -18,24 +18,98 @@ static ao_info_t info = LIBAO_EXTERN(plugin) -#define plugin(i) (ao_plugin_local_data.ao_plugins[i]) -#define driver() (ao_plugin_local_data.ao_driver) +#define plugin(i) (ao_plugin_local_data.plugins[i]) +#define driver() (ao_plugin_local_data.driver) -/* local data */ +#define NPL 2 //Number of PLugins + +extern ao_plugin_functions_t audio_plugin_delay; + +// local data typedef struct ao_plugin_local_data_s { - ao_plugin_functions_t** ao_plugins; /* List of all plugins */ - ao_functions_t* ao_driver; /* ao driver used by ao_plugin */ + char* cfg_plugins; // List of plugins read from cfg-file + ao_functions_t* driver; // Output driver set in mplayer.c + ao_plugin_functions_t** plugins; // List of used plugins + ao_plugin_functions_t* available_plugins[NPL]; // List of abailabel plugins } ao_plugin_local_data_t; -ao_plugin_local_data_t ao_plugin_local_data; +ao_plugin_local_data_t ao_plugin_local_data={ + NULL, + NULL, + NULL, + { + &audio_plugin_delay, + NULL + } +}; -/* gloabal data */ +// gloabal data ao_plugin_data_t ao_plugin_data; + // to set/get/query special features/parameters static int control(int cmd,int arg){ - return driver()->control(cmd,arg); + switch(cmd){ + case AOCONTROL_SET_PLUGIN_DRIVER: + ao_plugin_local_data.driver=(ao_functions_t*)arg; + return CONTROL_OK; + case AOCONTROL_SET_PLUGIN_LIST: + ao_plugin_local_data.cfg_plugins=(char*)arg; + return CONTROL_OK; + default: + return driver()->control(cmd,arg); + } + return CONTROL_UNKNOWN; +} + +// Recursive function for adding plugins +// return 1 for success and 0 for error +int add_plugin(int i,char* cfg){ + int cnt=0; + // Find end of plugin name + while((cfg[cnt]!=',')&&(cfg[cnt]!='\0')&&(cnt<100)) cnt++; + if(cnt >= 100) + return 0; + + // Is this the last itteration or just another plugin + if(cfg[cnt]=='\0'){ + ao_plugin_local_data.plugins=malloc((i+1)*sizeof(ao_plugin_functions_t*)); + if(ao_plugin_local_data.plugins){ + ao_plugin_local_data.plugins[i+1]=NULL; + // Find the plugin matching the cfg string name + cnt=0; + while(ao_plugin_local_data.available_plugins[cnt] && cnt<20){ + if(0==strcmp(ao_plugin_local_data.available_plugins[cnt]->info->short_name,cfg)){ + ao_plugin_local_data.plugins[i]=ao_plugin_local_data.available_plugins[cnt]; + return 1; + } + cnt++; + } + printf("[plugin]: Invalid plugin: %s \n",cfg); + return 0; + } + else + return 0; + } else { + cfg[cnt]='\0'; + if(add_plugin(i+1,&cfg[cnt+1])){ + cnt=0; + // Find the plugin matching the cfg string name + while(ao_plugin_local_data.available_plugins[cnt] && cnt < 20){ + if(0==strcmp(ao_plugin_local_data.available_plugins[cnt]->info->short_name,cfg)){ + ao_plugin_local_data.plugins[i]=ao_plugin_local_data.available_plugins[cnt]; + return 1; + } + cnt++; + } + printf("[plugin]: Invalid plugin: %s \n",cfg); + return 0; + } + else + return 0; + } + return 0; // Will never happen... } // open & setup audio device and plugins @@ -43,11 +117,12 @@ static int control(int cmd,int arg){ static int init(int rate,int channels,int format,int flags){ int ok=1; - /* FIXME these are cfg file parameters */ + /* Create list of plugins from cfg option */ int i=0; - ao_plugin_local_data.ao_plugins=malloc((i+1)*sizeof(ao_plugin_functions_t*)); - plugin(i)=NULL; - ao_plugin_local_data.ao_driver=audio_out_drivers[1]; + if(ao_plugin_local_data.cfg_plugins){ + if(!add_plugin(i,ao_plugin_local_data.cfg_plugins)) + return 0; + } /* Set input parameters and itterate through plugins each plugin changes the parameters according to its output */ @@ -64,15 +139,23 @@ static int init(int rate,int channels,int format,int flags){ if(!ok) return 0; + // This should never happen but check anyway + if(NULL==ao_plugin_local_data.driver) + return 0; + ok = driver()->init(ao_plugin_data.rate, - ao_plugin_data.channels, - ao_plugin_data.format, - flags); + ao_plugin_data.channels, + ao_plugin_data.format, + flags); if(!ok) return 0; /* Now that the driver is initialized we can calculate and set the input and output buffers for each plugin */ ao_plugin_data.len=driver()->get_space(); + while((i>0) && ok) + ok=plugin(--i)->control(AOCONTROL_PLUGIN_SET_LEN,ao_plugin_data.len); + + if(!ok) return 0; return 1; } @@ -83,8 +166,8 @@ static void uninit(){ driver()->uninit(); while(plugin(i)) plugin(i++)->uninit(); - if(ao_plugin_local_data.ao_plugins) - free(ao_plugin_local_data.ao_plugins); + if(ao_plugin_local_data.plugins) + free(ao_plugin_local_data.plugins); } // stop playing and empty buffers (for seeking/pause) |