Convenience functionality for properties load and miracle_server_id function
[melted] / src / framework / mlt_filter.c
index 5aefd13..37f91db 100644 (file)
@@ -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.
@@ -192,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 );
-       free( this );
+       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 );
+       }
 }