From: lilo_booter Date: Thu, 2 Sep 2004 15:54:19 +0000 (+0000) Subject: event fix for playlist and consumer-stopped event X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=f44c1d4653f43c8e7a63e6c3895f6f1f0ee0103b;p=melted event fix for playlist and consumer-stopped event git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@404 d19143bc-622f-0410-bfdd-b5b2a6649095 --- diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index f363248..6074655 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -83,6 +83,8 @@ int mlt_consumer_init( mlt_consumer this, void *child ) // Hmm - default all consumers to yuv422 :-/ this->format = mlt_image_yuv422; + + mlt_events_register( properties, "consumer-stopped", NULL ); } return error; } @@ -477,6 +479,15 @@ mlt_frame mlt_consumer_rt_frame( mlt_consumer this ) return frame; } +/** Callback for the implementation to indicate a stopped condition. +*/ + +void mlt_consumer_stopped( mlt_consumer this ) +{ + mlt_properties_set_int( mlt_consumer_properties( this ), "running", 0 ); + mlt_events_fire( mlt_consumer_properties( this ), "consumer-stopped", NULL ); +} + /** Stop the consumer. */ diff --git a/src/framework/mlt_consumer.h b/src/framework/mlt_consumer.h index a3e05b5..2439b97 100644 --- a/src/framework/mlt_consumer.h +++ b/src/framework/mlt_consumer.h @@ -65,6 +65,7 @@ extern mlt_frame mlt_consumer_get_frame( mlt_consumer self ); extern mlt_frame mlt_consumer_rt_frame( mlt_consumer self ); extern int mlt_consumer_stop( mlt_consumer self ); extern int mlt_consumer_is_stopped( mlt_consumer self ); +extern void mlt_consumer_stopped( mlt_consumer self ); extern void mlt_consumer_close( mlt_consumer ); #endif diff --git a/src/framework/mlt_events.c b/src/framework/mlt_events.c index e42dabb..e128965 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; @@ -319,6 +320,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. */ diff --git a/src/framework/mlt_events.h b/src/framework/mlt_events.h index b6639cd..7045771 100644 --- a/src/framework/mlt_events.h +++ b/src/framework/mlt_events.h @@ -34,6 +34,10 @@ extern void mlt_events_block( mlt_properties self, void *service ); extern void mlt_events_unblock( mlt_properties self, void *service ); extern void mlt_events_disconnect( mlt_properties self, void *service ); +extern mlt_event mlt_events_setup_wait_for( mlt_properties self, char *id ); +extern void mlt_events_wait_for( mlt_properties self, mlt_event event ); +extern void mlt_events_close_wait_for( mlt_properties self, mlt_event event ); + extern void mlt_event_inc_ref( mlt_event self ); extern void mlt_event_block( mlt_event self ); extern void mlt_event_unblock( mlt_event self ); diff --git a/src/framework/mlt_playlist.c b/src/framework/mlt_playlist.c index be707f6..2f75219 100644 --- a/src/framework/mlt_playlist.c +++ b/src/framework/mlt_playlist.c @@ -203,6 +203,7 @@ static int mlt_playlist_virtual_append( mlt_playlist this, mlt_producer producer this->list[ this->count ]->frame_out = out; this->list[ this->count ]->frame_count = out - in + 1; this->list[ this->count ]->event = mlt_events_listen( properties, this, "producer-changed", ( mlt_listener )mlt_playlist_listener ); + mlt_event_inc_ref( this->list[ this->count ]->event ); mlt_properties_set( properties, "eof", "pause" ); diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index 1e801ce..a7fd977 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -965,6 +965,8 @@ static void *consumer_thread( void *arg ) // Just in case we terminated on pause mlt_properties_set_int( properties, "running", 0 ); + mlt_consumer_stopped( this ); + return NULL; } diff --git a/src/modules/core/consumer_null.c b/src/modules/core/consumer_null.c index ae456b5..937e013 100644 --- a/src/modules/core/consumer_null.c +++ b/src/modules/core/consumer_null.c @@ -154,6 +154,9 @@ static void *consumer_thread( void *arg ) } } + // Indicate that the consumer is stopped + mlt_consumer_stopped( this ); + return NULL; } diff --git a/src/modules/dv/consumer_libdv.c b/src/modules/dv/consumer_libdv.c index 132cb6d..93fabd6 100644 --- a/src/modules/dv/consumer_libdv.c +++ b/src/modules/dv/consumer_libdv.c @@ -419,6 +419,8 @@ static void *consumer_thread( void *arg ) // Tidy up mlt_pool_release( dv_frame ); + mlt_consumer_stopped( this ); + return NULL; } diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index de43e43..62e59f0 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -600,6 +600,8 @@ static void *video_thread( void *arg ) mlt_frame_close( next ); } + mlt_consumer_stopped( &this->parent ); + return NULL; } diff --git a/src/modules/westley/consumer_westley.c b/src/modules/westley/consumer_westley.c index 632ee4b..4e8fbb0 100644 --- a/src/modules/westley/consumer_westley.c +++ b/src/modules/westley/consumer_westley.c @@ -564,6 +564,8 @@ static int consumer_start( mlt_consumer this ) mlt_consumer_stop( this ); + mlt_consumer_stopped( this ); + return 0; }