X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_producer.c;h=4fda305526c0d8a056de87431d23b0a00dd82f19;hb=909d149697331a560edb1924f58fc58c5a25aaea;hp=fc161f5d534c90b28631f19d99fb90394802eb97;hpb=4db14da139d0cce1807d5f3530b271238786b795;p=melted diff --git a/src/framework/mlt_producer.c b/src/framework/mlt_producer.c index fc161f5..4fda305 100644 --- a/src/framework/mlt_producer.c +++ b/src/framework/mlt_producer.c @@ -31,6 +31,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 ); /** Constructor */ @@ -58,6 +59,13 @@ int mlt_producer_init( mlt_producer this, void *child ) // The parent is the service mlt_service parent = &this->parent; + // Define the parent close + parent->close = ( mlt_destructor )mlt_producer_close; + parent->close_object = this; + + // For convenience, we'll assume the close_object is this + this->close_object = this; + // Get the properties of the parent mlt_properties properties = mlt_service_properties( parent ); @@ -84,12 +92,24 @@ int mlt_producer_init( mlt_producer this, void *child ) // Override service get_frame parent->get_frame = producer_get_frame; + + mlt_events_listen( properties, this, "property-changed", ( mlt_listener )mlt_producer_property_changed ); + mlt_events_register( properties, "producer-changed", NULL ); } } return error; } +/** Listener for property changes. +*/ + +static void mlt_producer_property_changed( mlt_service owner, mlt_producer this, char *name ) +{ + if ( !strcmp( name, "in" ) || !strcmp( name, "out" ) || !strcmp( name, "length" ) ) + mlt_events_fire( mlt_producer_properties( this ), "producer-changed", NULL ); +} + /** Create a new producer. */ @@ -194,6 +214,8 @@ double mlt_producer_get_fps( mlt_producer this ) int mlt_producer_set_in_and_out( mlt_producer this, mlt_position in, mlt_position out ) { + mlt_properties properties = mlt_producer_properties( this ); + // Correct ins and outs if necessary if ( in < 0 ) in = 0; @@ -214,8 +236,11 @@ int mlt_producer_set_in_and_out( mlt_producer this, mlt_position in, mlt_positio } // Set the values - mlt_properties_set_position( mlt_producer_properties( this ), "in", in ); - mlt_properties_set_position( mlt_producer_properties( this ), "out", out ); + mlt_events_block( properties, properties ); + mlt_properties_set_position( properties, "in", in ); + mlt_properties_set_position( properties, "out", out ); + mlt_events_unblock( properties, properties ); + mlt_events_fire( properties, "producer-changed", NULL ); return 0; } @@ -289,8 +314,18 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind } else { + mlt_properties properties = mlt_producer_properties( this ); + mlt_filter *filters = mlt_properties_get_data( properties, "_filters", NULL ); + int count = mlt_properties_get_int( properties, "_filter_count" ); + int i; + // Get the frame from the implementation result = this->get_frame( this, frame, index ); + + // Process the frame with the attached filters + for ( i = 0; i < count; i ++ ) + if ( filters[ i ] != NULL ) + mlt_filter_process( filters[ i ], *frame ); } // Copy the fps and speed of the producer onto the frame @@ -304,13 +339,115 @@ static int producer_get_frame( mlt_service service, mlt_frame_ptr frame, int ind return 0; } +/** Attach a filter. +*/ + +int mlt_producer_attach( mlt_producer this, mlt_filter filter ) +{ + int error = this == NULL || filter == NULL; + if ( error == 0 ) + { + int i = 0; + int size = 0; + mlt_properties properties = mlt_producer_properties( this ); + mlt_filter *filters = mlt_properties_get_data( properties, "_filters", &size ); + int count = mlt_properties_get_int( properties, "_filter_count" ); + + for ( i = 0; error == 0 && i < count; i ++ ) + if ( filters[ i ] == filter ) + error = 1; + + if ( error == 0 ) + { + if ( count == size ) + { + size += 10; + filters = realloc( filters, size * sizeof( mlt_filter ) ); + mlt_properties_set_data( properties, "_filters", filters, size, NULL, NULL ); + } + + if ( filters != NULL ) + { + mlt_properties_inc_ref( mlt_filter_properties( filter ) ); + filters[ count ++ ] = filter; + mlt_properties_set_int( properties, "_filter_count", count ); + } + else + { + error = 2; + } + } + } + return error; +} + +/** Detach a filter. +*/ + +int mlt_producer_detach( mlt_producer this, mlt_filter filter ) +{ + int error = this == NULL || filter == NULL; + if ( error == 0 ) + { + int i = 0; + int size = 0; + mlt_properties properties = mlt_producer_properties( this ); + mlt_filter *filters = mlt_properties_get_data( properties, "_filters", &size ); + int count = mlt_properties_get_int( properties, "_filter_count" ); + + for ( i = 0; i < count; i ++ ) + if ( filters[ i ] == filter ) + break; + + if ( i < count ) + { + mlt_filter filter = filters[ i ]; + filters[ i ] = NULL; + for ( i ++ ; i < count; i ++ ) + filters[ i - 1 ] = filters[ i ]; + mlt_properties_set_int( properties, "_filter_count", -- count ); + mlt_filter_close( filter ); + } + } + return error; +} + +/** Retrieve a filter. +*/ + +mlt_filter mlt_producer_filter( mlt_producer this, int index ) +{ + mlt_filter filter = NULL; + if ( this != NULL ) + { + mlt_properties properties = mlt_producer_properties( this ); + mlt_filter *filters = mlt_properties_get_data( properties, "_filters", NULL ); + int count = mlt_properties_get_int( properties, "_filter_count" ); + if ( index >= 0 && index < count ) + filter = filters[ index ]; + } + return filter; +} + /** Close the producer. */ void mlt_producer_close( mlt_producer this ) { - if ( this->close != NULL ) - this->close( this ); - else - mlt_service_close( &this->parent ); + if ( this != NULL && mlt_properties_dec_ref( mlt_producer_properties( this ) ) <= 0 ) + { + mlt_properties properties = mlt_producer_properties( this ); + mlt_filter *filters = mlt_properties_get_data( properties, "_filters", NULL ); + int count = mlt_properties_get_int( properties, "_filter_count" ); + + while( count -- ) + mlt_producer_detach( this, filters[ 0 ] ); + + this->parent.close = NULL; + + if ( this->close != NULL ) + this->close( this->close_object ); + else + mlt_service_close( &this->parent ); + } }