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

document event queue, allow synchronous notifications on demand, little improvements

parent b2afc218
......@@ -23,12 +23,35 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
typedef struct _MSEventQueue MSEventQueue;
/**
* Creates an event queue to receive notifications from MSFilters.
*
* The queue can be installed to be global with ms_set_global_event_queue().
* The application can then schedule the callbacks for the events
* received by the queue by calling ms_event_queue_pump()
**/
MSEventQueue *ms_event_queue_new();
/**
* Install a global event queue.
*
* All filters currently scheduled by MSTickers will send events (notifications)
* to the event queue.
*
**/
void ms_set_global_event_queue(MSEventQueue *q);
/**
* Run callbacks associated to the events received.
* The user can register a notify callback per filter using
* ms_filter_set_notify_callback() in order to be informed
* of various events generated by a MSFilter.
**/
void ms_event_queue_pump(MSEventQueue *q);
/**
* Destroys an event queue.
**/
void ms_event_queue_destroy(MSEventQueue *q);
#endif
......@@ -131,6 +131,7 @@ struct _MSFilter{
/*private attributes */
uint32_t last_tick;
bool_t seen;
bool_t synchronous_notifies;
};
......@@ -334,15 +335,25 @@ int ms_filter_call_method_noarg(MSFilter *f, unsigned int id);
/**
* Set a callback on filter's to be informed of private filter's event.
* This callback is called from the filter's MSTicker, unless a global event queue
* is created to receive all filter's notification asynchronously.
* See ms_event_queue_new() for details.
*
* @param f A MSFilter object.
* @param fn A MSFilterNotifyFunc that will be called.
* @param userdata A pointer to private data.
*
* Returns: 0 if successfull, -1 otherwise.
*
*/
void ms_filter_set_notify_callback(MSFilter *f, MSFilterNotifyFunc fn, void *userdata);
/**
* Forces the filter to synchronously send notifications, that is
* the notify callback will be called from MSTicker thread instead of being
* run by a MSEventQueue.
*/
void ms_filter_enable_synchronous_notifcations(MSFilter *f, bool_t yesno);
/**
* Get MSFilterId's filter.
*
......@@ -494,7 +505,7 @@ typedef enum _MSFilterInterfaceId MSFilterInterfaceId;
#define MS_SPEEX_EC_ECHO_STATE MS_FILTER_EVENT(MS_SPEEX_EC_ID, 2, void*)
/** @} */
/*private methods*/
/*protected/ private methods*/
void ms_filter_process(MSFilter *f);
void ms_filter_preprocess(MSFilter *f, struct _MSTicker *t);
void ms_filter_postprocess(MSFilter *f);
......
......@@ -23,4 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MS_ITC_SINK_CONNECT MS_FILTER_METHOD(MS_ITC_SINK_ID,0,MSFilter)
#define MS_ITC_SOURCE_UPDATED MS_FILTER_EVENT_NO_ARG(MS_ITC_SOURCE_ID,0)
#endif
......@@ -124,6 +124,11 @@ MSFilterDesc ms_itc_source_desc={
#endif
static void itc_sink_preprocess(MSFilter *f){
MSFilter *other=f->data;
ms_filter_notify(other,MS_ITC_SOURCE_UPDATED,NULL);
}
static void itc_sink_process(MSFilter *f){
MSFilter *other=f->data;
mblk_t *im;
......@@ -139,20 +144,48 @@ static int itc_sink_connect(MSFilter *f, void *data){
static int itc_sink_set_nchannels(MSFilter *f , void *data){
MSFilter *other=f->data;
if (other==NULL){
ms_error("MSItcSink not connected to any source !");
return -1;
}
itc_source_set_nchannels (other,*(int*)data);
return 0;
}
static int itc_sink_set_sr(MSFilter *f , void *data){
MSFilter *other=f->data;
if (other==NULL){
ms_error("MSItcSink not connected to any source !");
return -1;
}
itc_source_set_rate (other,*(int*)data);
return 0;
}
static int itc_sink_get_nchannels(MSFilter *f , void *data){
MSFilter *other=f->data;
if (other==NULL){
ms_error("MSItcSink not connected to any source !");
return -1;
}
return itc_source_get_nchannels (other,data);
}
static int itc_sink_get_sr(MSFilter *f , void *data){
MSFilter *other=f->data;
if (other==NULL){
ms_error("MSItcSink not connected to any source !");
return -1;
}
return itc_source_get_rate (other,data);
}
static MSFilterMethod sink_methods[]={
{ MS_ITC_SINK_CONNECT , itc_sink_connect },
{ MS_FILTER_SET_NCHANNELS , itc_sink_set_nchannels },
{ MS_FILTER_SET_SAMPLE_RATE , itc_sink_set_sr },
{ MS_FILTER_GET_NCHANNELS, itc_sink_get_nchannels },
{ MS_FILTER_GET_SAMPLE_RATE, itc_sink_get_sr },
{ 0, NULL }
};
......@@ -167,7 +200,7 @@ MSFilterDesc ms_itc_sink_desc={
1,
0,
NULL,
NULL,
itc_sink_preprocess,
itc_sink_process,
NULL,
NULL,
......@@ -183,6 +216,7 @@ MSFilterDesc ms_itc_sink_desc={
.category=MS_FILTER_OTHER,
.ninputs=1,
.noutputs=0,
.preprocess=itc_sink_preprocess,
.process=itc_sink_process,
.methods=sink_methods
};
......
......@@ -187,6 +187,10 @@ void ms_filter_set_notify_callback(MSFilter *f, MSFilterNotifyFunc fn, void *ud)
f->notify_ud=ud;
}
void ms_filter_enable_synchronous_notifcations(MSFilter *f, bool_t yesno){
f->synchronous_notifies=yesno;
}
void ms_filter_destroy(MSFilter *f){
if (f->desc->uninit!=NULL)
f->desc->uninit(f);
......
......@@ -133,7 +133,12 @@ static int ms_resample_set_output_sr(MSFilter *obj, void *arg){
static int set_nchannels(MSFilter *f, void *arg){
ResampleData *dt=(ResampleData*)f->data;
int chans=*(int*)arg;
ms_filter_lock(f);
if (dt->nchannels!=chans && dt->handle!=NULL){
speex_resampler_destroy(dt->handle);
dt->handle=NULL;
}
dt->nchannels=*(int*)arg;
ms_filter_unlock(f);
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