add new method ms_filter_find_neighbours()

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@475 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
This commit is contained in:
smorlat 2009-05-18 16:06:28 +00:00
parent f00fe07efb
commit ada9d79bcb
4 changed files with 110 additions and 89 deletions

View file

@ -352,6 +352,14 @@ void ms_filter_set_notify_callback(MSFilter *f, MSFilterNotifyFunc fn, void *use
*/ */
MSFilterId ms_filter_get_id(MSFilter *f); MSFilterId ms_filter_get_id(MSFilter *f);
/**
* Obtain the list of current filter's neighbours, ie filters that are part of same graph.
*
* Returns: a MSList of MSFilter, that needs to be freed by the caller when no more needed.
**/
MSList * ms_filter_find_neighbours(MSFilter *me);
/** /**
* Destroy a filter object. * Destroy a filter object.
* *

View file

@ -232,6 +232,47 @@ void ms_filter_notify_no_arg(MSFilter *f, unsigned int id){
f->notify(f->notify_ud,id,NULL); f->notify(f->notify_ud,id,NULL);
} }
static void find_filters(MSList **filters, MSFilter *f ){
int i,found;
MSQueue *link;
if (f==NULL) ms_fatal("Bad graph.");
/*ms_message("seeing %s, seen=%i",f->desc->name,f->seen);*/
if (f->seen){
return;
}
f->seen=TRUE;
*filters=ms_list_append(*filters,f);
/* go upstream */
for(i=0;i<f->desc->ninputs;i++){
link=f->inputs[i];
if (link!=NULL) find_filters(filters,link->prev.filter);
}
/* go downstream */
for(i=0,found=0;i<f->desc->noutputs;i++){
link=f->outputs[i];
if (link!=NULL) {
found++;
find_filters(filters,link->next.filter);
}
}
if (f->desc->noutputs>=1 && found==0){
ms_fatal("Bad graph: filter %s has %i outputs, none is connected.",f->desc->name,f->desc->noutputs);
}
}
MSList * ms_filter_find_neighbours(MSFilter *me){
MSList *l=NULL;
MSList *it;
find_filters(&l,me);
/*reset seen boolean for further lookups to succeed !*/
for(it=l;it!=NULL;it=it->next){
MSFilter *f=(MSFilter*)it->data;
f->seen=FALSE;
}
return l;
}
void ms_connection_helper_start(MSConnectionHelper *h){ void ms_connection_helper_start(MSConnectionHelper *h){
h->last.filter=0; h->last.filter=0;
h->last.pin=-1; h->last.pin=-1;

View file

@ -79,33 +79,6 @@ void ms_ticker_destroy(MSTicker *ticker){
ms_free(ticker); ms_free(ticker);
} }
void find_filters(MSList **filters, MSFilter *f ){
int i,found;
MSQueue *link;
if (f==NULL) ms_fatal("Bad graph.");
/*ms_message("seeing %s, seen=%i",f->desc->name,f->seen);*/
if (f->seen){
return;
}
f->seen=TRUE;
*filters=ms_list_append(*filters,f);
/* go upstream */
for(i=0;i<f->desc->ninputs;i++){
link=f->inputs[i];
if (link!=NULL) find_filters(filters,link->prev.filter);
}
/* go downstream */
for(i=0,found=0;i<f->desc->noutputs;i++){
link=f->outputs[i];
if (link!=NULL) {
found++;
find_filters(filters,link->next.filter);
}
}
if (f->desc->noutputs>=1 && found==0){
ms_fatal("Bad graph: filter %s has %i outputs, none is connected.",f->desc->name,f->desc->noutputs);
}
}
static MSList *get_sources(MSList *filters){ static MSList *get_sources(MSList *filters){
MSList *sources=NULL; MSList *sources=NULL;
@ -130,7 +103,7 @@ int ms_ticker_attach(MSTicker *ticker,MSFilter *f)
return 0; return 0;
} }
find_filters(&filters,f); filters=ms_filter_find_neighbours(f);
sources=get_sources(filters); sources=get_sources(filters);
if (sources==NULL){ if (sources==NULL){
ms_fatal("No sources found around filter %s",f->desc->name); ms_fatal("No sources found around filter %s",f->desc->name);
@ -161,7 +134,7 @@ int ms_ticker_detach(MSTicker *ticker,MSFilter *f){
ms_mutex_lock(&ticker->lock); ms_mutex_lock(&ticker->lock);
find_filters(&filters,f); filters=ms_filter_find_neighbours(f);
sources=get_sources(filters); sources=get_sources(filters);
if (sources==NULL){ if (sources==NULL){
ms_fatal("No sources found around filter %s",f->desc->name); ms_fatal("No sources found around filter %s",f->desc->name);

View file

@ -23,8 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "mediastreamer2/msfilter.h" #include "mediastreamer2/msfilter.h"
#include "mediastreamer2/msticker.h" #include "mediastreamer2/msticker.h"
extern void find_filters(MSList **filters, MSFilter *f );
#define UNICODE #define UNICODE
#include <mmsystem.h> #include <mmsystem.h>
@ -723,7 +721,7 @@ static void winsndds_write_preprocess(MSFilter *f){
MSFilter *f_capture_filter=NULL; MSFilter *f_capture_filter=NULL;
WinSndDs *d_capture_filter=NULL; WinSndDs *d_capture_filter=NULL;
find_filters(&filters, f); filters=ms_filter_find_neighbours(f);
if (filters!=NULL) if (filters!=NULL)
{ {
MSList *it; MSList *it;
@ -739,6 +737,7 @@ static void winsndds_write_preprocess(MSFilter *f){
d_capture_filter=(WinSndDs*)f_capture_filter->data; d_capture_filter=(WinSndDs*)f_capture_filter->data;
} }
} }
ms_list_free(filters);
} }
d->stat_input=0; d->stat_input=0;