X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_events.c;h=a9ee7433c6b6ce825bb2bd3230d534a551c1c10e;hb=b79a3f74f655a4ab8bb087454624d11eca6d9b34;hp=e42dabb1cfd9b15aafe250dfc355575f2262705b;hpb=909d149697331a560edb1924f58fc58c5a25aaea;p=melted diff --git a/src/framework/mlt_events.c b/src/framework/mlt_events.c index e42dabb..a9ee743 100644 --- a/src/framework/mlt_events.c +++ b/src/framework/mlt_events.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "mlt_properties.h" #include "mlt_events.h" @@ -57,7 +58,7 @@ struct mlt_event_struct void mlt_event_inc_ref( mlt_event this ) { - if ( this != NULL && this->owner != NULL ) + if ( this != NULL ) this->ref_count ++; } @@ -84,7 +85,7 @@ void mlt_event_unblock( mlt_event this ) void mlt_event_close( mlt_event this ) { - if ( this != NULL && this->owner != NULL ) + if ( this != NULL ) { if ( -- this->ref_count == 1 ) this->owner = NULL; @@ -227,11 +228,10 @@ mlt_event mlt_events_listen( mlt_properties this, void *service, char *id, mlt_l event->listener = listener; event->service = service; mlt_properties_set_data( listeners, temp, event, 0, ( mlt_destructor )mlt_event_close, NULL ); + mlt_event_inc_ref( event ); } } - if ( event != NULL ) - mlt_event_inc_ref( event ); } } return event; @@ -319,6 +319,56 @@ void mlt_events_disconnect( mlt_properties this, void *service ) } } +typedef struct +{ + int done; + pthread_cond_t cond; + pthread_mutex_t mutex; +} +condition_pair; + +static void mlt_events_listen_for( mlt_properties this, condition_pair *pair ) +{ + pthread_mutex_lock( &pair->mutex ); + if ( pair->done == 0 ) + { + pthread_cond_signal( &pair->cond ); + pthread_mutex_unlock( &pair->mutex ); + } +} + +mlt_event mlt_events_setup_wait_for( mlt_properties this, char *id ) +{ + condition_pair *pair = malloc( sizeof( condition_pair ) ); + pair->done = 0; + pthread_cond_init( &pair->cond, NULL ); + pthread_mutex_init( &pair->mutex, NULL ); + pthread_mutex_lock( &pair->mutex ); + return mlt_events_listen( this, pair, id, ( mlt_listener )mlt_events_listen_for ); +} + +void mlt_events_wait_for( mlt_properties this, mlt_event event ) +{ + if ( event != NULL ) + { + condition_pair *pair = event->service; + pthread_cond_wait( &pair->cond, &pair->mutex ); + } +} + +void mlt_events_close_wait_for( mlt_properties this, mlt_event event ) +{ + if ( event != NULL ) + { + condition_pair *pair = event->service; + event->owner = NULL; + pair->done = 0; + pthread_mutex_unlock( &pair->mutex ); + pthread_mutex_destroy( &pair->mutex ); + pthread_cond_destroy( &pair->cond ); + } +} + /** Fetch the events object. */