X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_filter.c;h=37f91db3b8ed7cbd63660b0a907fb42d586fcb98;hb=d8c7fca58da2a1d5b2bb3f917bcf9798bd68bc1b;hp=d83e42fbd4436848164b64e9cad6baabffa3d61b;hpb=efe08354d45db7bf5478ffa17c35330a3e0d415c;p=melted diff --git a/src/framework/mlt_filter.c b/src/framework/mlt_filter.c index d83e42f..37f91db 100644 --- a/src/framework/mlt_filter.c +++ b/src/framework/mlt_filter.c @@ -44,6 +44,10 @@ int mlt_filter_init( mlt_filter this, void *child ) // Override the get_frame method service->get_frame = filter_get_frame; + // Define the destructor + service->close = ( mlt_destructor )mlt_filter_close; + service->close_object = this; + // Default in, out, track properties mlt_properties_set_position( properties, "in", 0 ); mlt_properties_set_position( properties, "out", 0 ); @@ -70,7 +74,7 @@ mlt_filter mlt_filter_new( ) mlt_service mlt_filter_service( mlt_filter this ) { - return &this->parent; + return this != NULL ? &this->parent : NULL; } /** Get the properties associated to this filter. @@ -93,7 +97,6 @@ int mlt_filter_connect( mlt_filter this, mlt_service producer, int index ) if ( ret == 0 ) { mlt_properties properties = mlt_service_properties( &this->parent ); - this->producer = producer; mlt_properties_set_position( properties, "in", 0 ); mlt_properties_set_position( properties, "out", 0 ); mlt_properties_set_int( properties, "track", index ); @@ -162,14 +165,17 @@ static int filter_get_frame( mlt_service service, mlt_frame_ptr frame, int index int in = mlt_filter_get_in( this ); int out = mlt_filter_get_out( this ); + // Get the producer this is connected to + mlt_service producer = mlt_service_producer( &this->parent ); + // If the frame request is for this filters track, we need to process it if ( index == track ) { - int ret = mlt_service_get_frame( this->producer, frame, index ); + int ret = mlt_service_get_frame( producer, frame, index ); if ( ret == 0 ) { mlt_position position = mlt_frame_get_position( *frame ); - if ( position >= in && ( out == 0 || position < out ) ) + if ( position >= in && ( out == 0 || position <= out ) ) *frame = mlt_filter_process( this, *frame ); return 0; } @@ -181,7 +187,7 @@ static int filter_get_frame( mlt_service service, mlt_frame_ptr frame, int index } else { - return mlt_service_get_frame( this->producer, frame, index ); + return mlt_service_get_frame( producer, frame, index ); } } @@ -190,9 +196,17 @@ static int filter_get_frame( mlt_service service, mlt_frame_ptr frame, int index void mlt_filter_close( mlt_filter this ) { - if ( this->close != NULL ) - this->close( this ); - else - mlt_service_close( &this->parent ); + if ( this != NULL && mlt_properties_dec_ref( mlt_filter_properties( this ) ) <= 0 ) + { + if ( this->close != NULL ) + { + this->close( this ); + } + else + { + this->parent.close = NULL; + mlt_service_close( &this->parent ); + } + free( this ); + } } -