#include "mlt_filter.h"
#include "mlt_frame.h"
+#include "mlt_producer.h"
#include <stdio.h>
#include <stdlib.h>
mlt_filter mlt_filter_new( )
{
mlt_filter self = calloc( 1, sizeof( struct mlt_filter_s ) );
- if ( self != NULL )
- mlt_filter_init( self, NULL );
- return self;
+ if ( self != NULL && mlt_filter_init( self, NULL ) == 0 )
+ {
+ return self;
+ }
+ else
+ {
+ free(self);
+ return NULL;
+ }
}
/** Get the service class interface.
return ( out > 0 ) ? ( out - in + 1 ) : 0;
}
+/** Get the duration.
+ *
+ * This version works with filters with no explicit in and out by getting the
+ * length of the frame's producer.
+ *
+ * \public \memberof mlt_filter_s
+ * \param self a filter
+ * \param frame a frame from which to get its producer
+ * \return the duration or zero if unlimited
+ */
+
+mlt_position mlt_filter_get_length2( mlt_filter self, mlt_frame frame )
+{
+ mlt_properties properties = MLT_SERVICE_PROPERTIES( &self->parent );
+ mlt_position in = mlt_properties_get_position( properties, "in" );
+ mlt_position out = mlt_properties_get_position( properties, "out" );
+
+ if ( out == 0 && frame )
+ {
+ // If always active, use the frame's producer
+ mlt_producer producer = mlt_frame_get_original_producer( frame );
+ if ( producer )
+ {
+ producer = mlt_producer_cut_parent( producer );
+ in = mlt_producer_get_in( producer );
+ out = mlt_producer_get_out( producer );
+ }
+ }
+ return ( out > 0 ) ? ( out - in + 1 ) : 0;
+}
+
/** Get the position within the filter.
*
* The position is relative to the in point.
char name[20];
// Make the properties key from unique id
- strcpy( name, "pos." );
- strcat( name, unique_id );
+ snprintf( name, 20, "pos.%s", unique_id );
+ name[20 - 1] = '\0';
return mlt_properties_get_position( MLT_FRAME_PROPERTIES( frame ), name ) - in;
}
double mlt_filter_get_progress( mlt_filter self, mlt_frame frame )
{
- double progress = 0;
- mlt_position out = mlt_filter_get_out( self );
-
- if ( out != 0 )
- {
- mlt_position in = mlt_filter_get_in( self );
- mlt_position position = mlt_filter_get_position( self, frame );
- progress = ( double ) position / ( double ) ( out - in + 1 );
- }
- return progress;
+ double position = mlt_filter_get_position( self, frame );
+ double length = mlt_filter_get_length2( self, frame );
+ return position / length;
}
/** Process the frame.
char name[20];
// Make the properties key from unique id
- strcpy( name, "pos." );
- strcat( name, unique_id );
+ snprintf( name, 20, "pos.%s", unique_id );
+ name[20 -1] = '\0';
// Save the position on the frame
mlt_properties_set_position( MLT_FRAME_PROPERTIES( frame ), name, position );