From 55f4b82288ba162eeeedf63bbb99455cccd04b8d Mon Sep 17 00:00:00 2001 From: lilo_booter Date: Wed, 8 Sep 2004 08:04:41 +0000 Subject: [PATCH] More work with events git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@412 d19143bc-622f-0410-bfdd-b5b2a6649095 --- src/framework/mlt_consumer.c | 9 +++++++++ src/framework/mlt_producer.c | 10 ++++++++++ src/framework/mlt_service.c | 11 +++++++++++ src/modules/avformat/consumer_avformat.c | 1 + src/modules/core/consumer_null.c | 1 + src/modules/dv/consumer_libdv.c | 1 + src/modules/sdl/consumer_sdl.c | 13 +++++++++++++ 7 files changed, 46 insertions(+), 0 deletions(-) diff --git a/src/framework/mlt_consumer.c b/src/framework/mlt_consumer.c index 6074655..0f2a97f 100644 --- a/src/framework/mlt_consumer.c +++ b/src/framework/mlt_consumer.c @@ -28,6 +28,8 @@ #include #include +static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ); + /** Public final methods */ @@ -84,11 +86,18 @@ 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-frame-show", ( mlt_transmitter )mlt_consumer_frame_show ); mlt_events_register( properties, "consumer-stopped", NULL ); } return error; } +static void mlt_consumer_frame_show( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) +{ + if ( listener != NULL ) + listener( owner, this, ( mlt_frame )args[ 0 ] ); +} + /** Create a new consumer. */ diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index acfaad1..79038fb 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -32,6 +32,7 @@ static int producer_get_frame( mlt_service this, mlt_frame_ptr frame, int index ); static void mlt_producer_property_changed( mlt_service owner, mlt_producer this, char *name ); +static void mlt_producer_service_changed( mlt_service owner, mlt_producer this ); /** Constructor */ @@ -93,6 +94,7 @@ int mlt_producer_init( mlt_producer this, void *child ) // Override service get_frame parent->get_frame = producer_get_frame; + mlt_events_listen( properties, this, "service-changed", ( mlt_listener )mlt_producer_service_changed ); mlt_events_listen( properties, this, "property-changed", ( mlt_listener )mlt_producer_property_changed ); mlt_events_register( properties, "producer-changed", NULL ); } @@ -110,6 +112,14 @@ static void mlt_producer_property_changed( mlt_service owner, mlt_producer this, mlt_events_fire( mlt_producer_properties( this ), "producer-changed", NULL ); } +/** Listener for service changes. +*/ + +static void mlt_producer_service_changed( mlt_service owner, mlt_producer this ) +{ + mlt_events_fire( mlt_producer_properties( this ), "producer-changed", NULL ); +} + /** Create a new producer. */ diff --git a/src/framework/mlt_service.c b/src/framework/mlt_service.c index 0851b9a..bc0cf33 100644 --- a/src/framework/mlt_service.c +++ b/src/framework/mlt_service.c @@ -86,6 +86,7 @@ int mlt_service_init( mlt_service this, void *child ) this->parent.close_object = this; mlt_events_init( &this->parent ); + mlt_events_register( &this->parent, "service-changed", NULL ); mlt_events_register( &this->parent, "property-changed", ( mlt_transmitter )mlt_service_property_changed ); } @@ -298,6 +299,11 @@ int mlt_service_get_frame( mlt_service this, mlt_frame_ptr frame, int index ) return 0; } +static void mlt_service_filter_changed( mlt_service owner, mlt_service this ) +{ + mlt_events_fire( mlt_service_properties( this ), "service-changed", NULL ); +} + /** Attach a filter. */ @@ -324,9 +330,12 @@ int mlt_service_attach( mlt_service this, mlt_filter filter ) if ( base->filters != NULL ) { + mlt_properties props = mlt_filter_properties( filter ); mlt_properties_inc_ref( mlt_filter_properties( filter ) ); base->filters[ base->filter_count ++ ] = filter; mlt_events_fire( properties, "service-changed", NULL ); + mlt_events_listen( props, this, "service-changed", ( mlt_listener )mlt_service_filter_changed ); + mlt_events_listen( props, this, "property-changed", ( mlt_listener )mlt_service_filter_changed ); } else { @@ -359,6 +368,7 @@ int mlt_service_detach( mlt_service this, mlt_filter filter ) for ( i ++ ; i < base->filter_count; i ++ ) base->filters[ i - 1 ] = base->filters[ i ]; base->filter_count --; + mlt_events_disconnect( mlt_filter_properties( filter ), this ); mlt_filter_close( filter ); mlt_events_fire( properties, "service-changed", NULL ); } @@ -397,6 +407,7 @@ void mlt_service_close( mlt_service this ) mlt_service_base *base = this->local; int i = 0; int count = base->filter_count; + mlt_events_block( mlt_service_properties( this ), this ); while( count -- ) mlt_service_detach( this, base->filters[ 0 ] ); free( base->filters ); diff --git a/src/modules/avformat/consumer_avformat.c b/src/modules/avformat/consumer_avformat.c index a7fd977..6bb672a 100644 --- a/src/modules/avformat/consumer_avformat.c +++ b/src/modules/avformat/consumer_avformat.c @@ -851,6 +851,7 @@ static void *consumer_thread( void *arg ) uint8_t *p; uint8_t *q; + mlt_events_fire( properties, "consumer-frame-show", frame, NULL ); mlt_frame_get_image( frame, &image, &img_fmt, &img_width, &img_height, 0 ); q = image; diff --git a/src/modules/core/consumer_null.c b/src/modules/core/consumer_null.c index 937e013..57452e1 100644 --- a/src/modules/core/consumer_null.c +++ b/src/modules/core/consumer_null.c @@ -150,6 +150,7 @@ static void *consumer_thread( void *arg ) if ( frame != NULL ) { // Close the frame + mlt_events_fire( properties, "consumer-frame-show", frame, NULL ); mlt_frame_close( frame ); } } diff --git a/src/modules/dv/consumer_libdv.c b/src/modules/dv/consumer_libdv.c index 93fabd6..6dce526 100644 --- a/src/modules/dv/consumer_libdv.c +++ b/src/modules/dv/consumer_libdv.c @@ -220,6 +220,7 @@ static int consumer_encode_video( mlt_consumer this, uint8_t *dv_frame, mlt_fram uint8_t *image = NULL; // Get the image + mlt_events_fire( this_properties, "consumer-frame-show", frame, NULL ); mlt_frame_get_image( frame, &image, &fmt, &width, &height, 0 ); // Check that we get what we expected diff --git a/src/modules/sdl/consumer_sdl.c b/src/modules/sdl/consumer_sdl.c index 39b8894..d162580 100644 --- a/src/modules/sdl/consumer_sdl.c +++ b/src/modules/sdl/consumer_sdl.c @@ -72,6 +72,7 @@ static int consumer_is_stopped( mlt_consumer parent ); static void consumer_close( mlt_consumer parent ); static void *consumer_thread( void * ); static int consumer_get_dimensions( int *width, int *height ); +static void consumer_sdl_event( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ); /** This is what will be called by the factory - anything can be passed in via the argument, but keep it simple. @@ -162,6 +163,9 @@ mlt_consumer consumer_sdl_init( char *arg ) parent->stop = consumer_stop; parent->is_stopped = consumer_is_stopped; + // Register specific events + mlt_events_register( this->properties, "consumer-sdl-event", ( mlt_transmitter )consumer_sdl_event ); + // Return the consumer produced return parent; } @@ -173,6 +177,12 @@ mlt_consumer consumer_sdl_init( char *arg ) return NULL; } +static void consumer_sdl_event( mlt_listener listener, mlt_properties owner, mlt_service this, void **args ) +{ + if ( listener != NULL ) + listener( owner, this, ( SDL_Event * )args[ 0 ] ); +} + int consumer_start( mlt_consumer parent ) { consumer_sdl this = parent->child; @@ -382,6 +392,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) if ( mlt_properties_get_int( properties, "video_off" ) == 0 ) { // Get the image, width and height + mlt_events_fire( properties, "consumer-frame-show", frame, NULL ); mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 ); // Handle events @@ -393,6 +404,8 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame ) while ( SDL_PollEvent( &event ) ) { + mlt_events_fire( this->properties, "consumer-sdl-event", &event, NULL ); + switch( event.type ) { case SDL_VIDEORESIZE: -- 1.7.4.4