Commit 7af64431 authored by Simon Morlat's avatar Simon Morlat

add ms_ticker_attach_multiple()

parent 1b517a0b
......@@ -117,6 +117,18 @@ MS2_PUBLIC void ms_ticker_set_priority(MSTicker *ticker, MSTickerPrio prio);
*/
MS2_PUBLIC int ms_ticker_attach(MSTicker *ticker,MSFilter *f);
/**
* Attach a chain of filters to a ticker.
* The processing chain will be executed until ms_ticker_detach
* will be called.
* This variadic can be used to attach multiple chains in a single call. The argument list MUST be NULL terminated.
*
* @param ticker A #MSTicker object.
* @param f A #MSFilter object.
*
* Returns: 0 if successfull, -1 otherwise.
*/
MS2_PUBLIC int ms_ticker_attach_multiple(MSTicker *ticker,MSFilter *f,...);
/**
* Dettach a chain of filters to a ticker.
* The processing chain will no more be executed.
......
......@@ -113,31 +113,42 @@ static MSList *get_sources(MSList *filters){
return sources;
}
int ms_ticker_attach(MSTicker *ticker,MSFilter *f)
int ms_ticker_attach(MSTicker *ticker, MSFilter *f){
return ms_ticker_attach_multiple(ticker,f,NULL);
}
int ms_ticker_attach_multiple(MSTicker *ticker,MSFilter *f,...)
{
MSList *sources=NULL;
MSList *filters=NULL;
MSList *it;
if (f->ticker!=NULL) {
ms_message("Filter %s is already being scheduled; nothing to do.",f->desc->name);
return 0;
}
filters=ms_filter_find_neighbours(f);
sources=get_sources(filters);
if (sources==NULL){
ms_fatal("No sources found around filter %s",f->desc->name);
ms_list_free(filters);
return -1;
MSList *total_sources=NULL;
va_list l;
va_start(l,f);
do{
if (f->ticker==NULL) {
filters=ms_filter_find_neighbours(f);
sources=get_sources(filters);
if (sources==NULL){
ms_fatal("No sources found around filter %s",f->desc->name);
ms_list_free(filters);
break;
}
/*run preprocess on each filter: */
for(it=filters;it!=NULL;it=it->next)
ms_filter_preprocess((MSFilter*)it->data,ticker);
ms_list_free(filters);
total_sources=ms_list_concat(total_sources,sources);
}else ms_message("Filter %s is already being scheduled; nothing to do.",f->desc->name);
}while ((f=va_arg(l,MSFilter*))!=NULL);
va_end(l);
if (total_sources){
ms_mutex_lock(&ticker->lock);
ticker->execution_list=ms_list_concat(ticker->execution_list,total_sources);
ms_mutex_unlock(&ticker->lock);
}
/*run preprocess on each filter: */
for(it=filters;it!=NULL;it=it->next)
ms_filter_preprocess((MSFilter*)it->data,ticker);
ms_mutex_lock(&ticker->lock);
ticker->execution_list=ms_list_concat(ticker->execution_list,sources);
ms_mutex_unlock(&ticker->lock);
ms_list_free(filters);
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment