X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_filter.c;h=6ca7afb4b960fdf2fb6e32ee81690745ab6d12bd;hb=c95736fd9ee742f5e6db06bbe579f23895f55eba;hp=11f4db7520cffd983a5f0781c8b6770a875fe2ba;hpb=5a3b9710ee1fbc6f079465d7a94afb0b17a6e9a2;p=melted diff --git a/src/framework/mlt_filter.c b/src/framework/mlt_filter.c index 11f4db7..6ca7afb 100644 --- a/src/framework/mlt_filter.c +++ b/src/framework/mlt_filter.c @@ -39,11 +39,15 @@ int mlt_filter_init( mlt_filter this, void *child ) this->child = child; if ( mlt_service_init( service, this ) == 0 ) { - mlt_properties properties = mlt_service_properties( service ); + mlt_properties properties = MLT_SERVICE_PROPERTIES( service ); // 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. @@ -78,7 +82,7 @@ mlt_service mlt_filter_service( mlt_filter this ) mlt_properties mlt_filter_properties( mlt_filter this ) { - return mlt_service_properties( mlt_filter_service( this ) ); + return MLT_SERVICE_PROPERTIES( MLT_FILTER_SERVICE( this ) ); } /** Connect this filter to a producers track. Note that a filter only operates @@ -92,8 +96,7 @@ int mlt_filter_connect( mlt_filter this, mlt_service producer, int index ) // If the connection was successful, grab the producer, track and reset in/out if ( ret == 0 ) { - mlt_properties properties = mlt_service_properties( &this->parent ); - this->producer = producer; + mlt_properties properties = MLT_SERVICE_PROPERTIES( &this->parent ); mlt_properties_set_position( properties, "in", 0 ); mlt_properties_set_position( properties, "out", 0 ); mlt_properties_set_int( properties, "track", index ); @@ -107,7 +110,7 @@ int mlt_filter_connect( mlt_filter this, mlt_service producer, int index ) void mlt_filter_set_in_and_out( mlt_filter this, mlt_position in, mlt_position out ) { - mlt_properties properties = mlt_service_properties( &this->parent ); + mlt_properties properties = MLT_SERVICE_PROPERTIES( &this->parent ); mlt_properties_set_position( properties, "in", in ); mlt_properties_set_position( properties, "out", out ); } @@ -117,7 +120,7 @@ void mlt_filter_set_in_and_out( mlt_filter this, mlt_position in, mlt_position o int mlt_filter_get_track( mlt_filter this ) { - mlt_properties properties = mlt_service_properties( &this->parent ); + mlt_properties properties = MLT_SERVICE_PROPERTIES( &this->parent ); return mlt_properties_get_int( properties, "track" ); } @@ -126,7 +129,7 @@ int mlt_filter_get_track( mlt_filter this ) mlt_position mlt_filter_get_in( mlt_filter this ) { - mlt_properties properties = mlt_service_properties( &this->parent ); + mlt_properties properties = MLT_SERVICE_PROPERTIES( &this->parent ); return mlt_properties_get_position( properties, "in" ); } @@ -135,7 +138,7 @@ mlt_position mlt_filter_get_in( mlt_filter this ) mlt_position mlt_filter_get_out( mlt_filter this ) { - mlt_properties properties = mlt_service_properties( &this->parent ); + mlt_properties properties = MLT_SERVICE_PROPERTIES( &this->parent ); return mlt_properties_get_position( properties, "out" ); } @@ -162,10 +165,13 @@ 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 ) + if ( index == track || track == -1 ) { - 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 ); @@ -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,8 +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 ); + } }