X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_filter.c;h=ccdf45dab3c0638960684be788d8523e96008e0a;hb=95f429b56026f5897ebad9060608b6631dcf7515;hp=9c0a295234443da8b29cf4105fe6313eb04f6e8c;hpb=e4c9ccbcef39cadaccbad655bc6e36e825bf3dde;p=melted diff --git a/src/framework/mlt_filter.c b/src/framework/mlt_filter.c index 9c0a295..ccdf45d 100644 --- a/src/framework/mlt_filter.c +++ b/src/framework/mlt_filter.c @@ -44,9 +44,13 @@ 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_timecode( properties, "in", 0 ); - mlt_properties_set_timecode( properties, "out", 0 ); + mlt_properties_set_position( properties, "in", 0 ); + mlt_properties_set_position( properties, "out", 0 ); mlt_properties_set_int( properties, "track", 0 ); return 0; @@ -54,14 +58,28 @@ int mlt_filter_init( mlt_filter this, void *child ) return 1; } +/** Create a new filter. +*/ + +mlt_filter mlt_filter_new( ) +{ + mlt_filter this = calloc( 1, sizeof( struct mlt_filter_s ) ); + if ( this != NULL ) + mlt_filter_init( this, NULL ); + return this; +} + /** Get the service associated to this filter */ mlt_service mlt_filter_service( mlt_filter this ) { - return &this->parent; + return this != NULL ? &this->parent : NULL; } +/** Get the properties associated to this filter. +*/ + mlt_properties mlt_filter_properties( mlt_filter this ) { return mlt_service_properties( mlt_filter_service( this ) ); @@ -79,9 +97,8 @@ 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_timecode( properties, "in", 0 ); - mlt_properties_set_timecode( properties, "out", 0 ); + mlt_properties_set_position( properties, "in", 0 ); + mlt_properties_set_position( properties, "out", 0 ); mlt_properties_set_int( properties, "track", index ); } @@ -91,11 +108,11 @@ int mlt_filter_connect( mlt_filter this, mlt_service producer, int index ) /** Tune the in/out points. */ -void mlt_filter_set_in_and_out( mlt_filter this, mlt_timecode in, mlt_timecode out ) +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_set_timecode( properties, "in", in ); - mlt_properties_set_timecode( properties, "out", out ); + mlt_properties_set_position( properties, "in", in ); + mlt_properties_set_position( properties, "out", out ); } /** Return the track that this filter is operating on. @@ -110,25 +127,25 @@ int mlt_filter_get_track( mlt_filter this ) /** Get the in point. */ -mlt_timecode mlt_filter_get_in( mlt_filter this ) +mlt_position mlt_filter_get_in( mlt_filter this ) { mlt_properties properties = mlt_service_properties( &this->parent ); - return mlt_properties_get_timecode( properties, "in" ); + return mlt_properties_get_position( properties, "in" ); } /** Get the out point. */ -mlt_timecode mlt_filter_get_out( mlt_filter this ) +mlt_position mlt_filter_get_out( mlt_filter this ) { mlt_properties properties = mlt_service_properties( &this->parent ); - return mlt_properties_get_timecode( properties, "out" ); + return mlt_properties_get_position( properties, "out" ); } /** Process the frame. */ -static mlt_frame filter_process( mlt_filter this, mlt_frame frame ) +mlt_frame mlt_filter_process( mlt_filter this, mlt_frame frame ) { if ( this->process == NULL ) return frame; @@ -148,17 +165,21 @@ 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 ) { - if ( !mlt_frame_is_test_card( *frame ) ) + mlt_position position = mlt_frame_get_position( *frame ); + if ( position >= in && ( out == 0 || position <= out ) ) { - mlt_timecode timecode = mlt_frame_get_timecode( *frame ); - if ( timecode >= in && ( out == 0 || timecode < out ) ) - *frame = filter_process( this, *frame ); + mlt_frame_set_position( *frame, position - in ); + *frame = mlt_filter_process( this, *frame ); + mlt_frame_set_position( *frame, position + in ); } return 0; } @@ -170,7 +191,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 ); } } @@ -179,9 +200,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 ); + } } -