event fix for playlist and consumer-stopped event
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 2 Sep 2004 15:54:19 +0000 (15:54 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Thu, 2 Sep 2004 15:54:19 +0000 (15:54 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@404 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_consumer.c
src/framework/mlt_consumer.h
src/framework/mlt_events.c
src/framework/mlt_events.h
src/framework/mlt_playlist.c
src/modules/avformat/consumer_avformat.c
src/modules/core/consumer_null.c
src/modules/dv/consumer_libdv.c
src/modules/sdl/consumer_sdl.c
src/modules/westley/consumer_westley.c

index f363248..6074655 100644 (file)
@@ -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.
 */
 
index a3e05b5..2439b97 100644 (file)
@@ -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
index e42dabb..e128965 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#include <pthread.h>
 
 #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.
 */
 
index b6639cd..7045771 100644 (file)
@@ -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 );
index be707f6..2f75219 100644 (file)
@@ -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" );
 
index 1e801ce..a7fd977 100644 (file)
@@ -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;
 }
 
index ae456b5..937e013 100644 (file)
@@ -154,6 +154,9 @@ static void *consumer_thread( void *arg )
                }
        }
 
+       // Indicate that the consumer is stopped
+       mlt_consumer_stopped( this );
+
        return NULL;
 }
 
index 132cb6d..93fabd6 100644 (file)
@@ -419,6 +419,8 @@ static void *consumer_thread( void *arg )
        // Tidy up
        mlt_pool_release( dv_frame );
 
+       mlt_consumer_stopped( this );
+
        return NULL;
 }
 
index de43e43..62e59f0 100644 (file)
@@ -600,6 +600,8 @@ static void *video_thread( void *arg )
                mlt_frame_close( next );
        }
 
+       mlt_consumer_stopped( &this->parent );
+
        return NULL;
 }
 
index 632ee4b..4e8fbb0 100644 (file)
@@ -564,6 +564,8 @@ static int consumer_start( mlt_consumer this )
        
        mlt_consumer_stop( this );
 
+       mlt_consumer_stopped( this );
+
        return 0;
 }