]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_filter.c
Cleanup Brian's service metadata contribution.
[mlt] / src / framework / mlt_filter.c
index 3df813fd9951545ab5a1d8f26c387e45b0d54a02..22eaa3fbd4b0e6c2919ee4058e4901a48abc0731 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "mlt_filter.h"
 #include "mlt_frame.h"
+#include "mlt_producer.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -202,7 +203,34 @@ mlt_position mlt_filter_get_length( mlt_filter self )
        return ( out > 0 ) ? ( out - in + 1 ) : 0;
 }
 
-/** Get the relative position of a frame.
+/** Get the position within the filter.
+ *
+ * The position is relative to the in point.
+ * This will only be valid once mlt_filter_process is called.
+ *
+ * \public \memberof mlt_filter_s
+ * \param self a filter
+ * \param frame a frame
+ * \return the position
+ */
+
+mlt_position mlt_filter_get_position( mlt_filter self, mlt_frame frame )
+{
+       mlt_properties properties = MLT_FILTER_PROPERTIES( self );
+       mlt_position in = mlt_properties_get_position( properties, "in" );
+       const char *unique_id = mlt_properties_get( properties, "_unique_id" );
+       char name[20];
+
+       // Make the properties key from unique id
+       strcpy( name, "pos." );
+       strcat( name, unique_id );
+
+       return mlt_properties_get_position( MLT_FRAME_PROPERTIES( frame ), name ) - in;
+}
+
+/** Get the percent complete.
+ *
+ * This will only be valid once mlt_filter_process is called.
  *
  * \public \memberof mlt_filter_s
  * \param self a filter
@@ -213,18 +241,32 @@ mlt_position mlt_filter_get_length( mlt_filter self )
 double mlt_filter_get_progress( mlt_filter self, mlt_frame frame )
 {
        double progress = 0;
+       mlt_position in = mlt_filter_get_in( self );
        mlt_position out = mlt_filter_get_out( self );
 
+       if ( out == 0 )
+       {
+               // If always active, use the frame's producer
+               mlt_producer producer = mlt_frame_get_original_producer( frame );
+               if ( producer )
+               {
+                       in = mlt_producer_get_in( producer );
+                       out = mlt_producer_get_out( producer );
+               }
+       }
        if ( out != 0 )
        {
-               mlt_position in = mlt_filter_get_in( self );
-               mlt_position position = mlt_frame_get_position( frame );
-               progress = ( double ) ( position - in ) / ( double ) ( out - in + 1 );
+               mlt_position position = mlt_filter_get_position( self, frame );
+               progress = ( double ) position / ( double ) ( out - in + 1 );
        }
        return progress;
 }
 
 /** Process the frame.
+ *
+ * When fetching the frame position in a subclass process method, the frame's
+ * position is relative to the filter's producer - not the filter's in point
+ * or timeline.
  *
  * \public \memberof mlt_filter_s
  * \param self a filter
@@ -235,7 +277,19 @@ double mlt_filter_get_progress( mlt_filter self, mlt_frame frame )
 
 mlt_frame mlt_filter_process( mlt_filter self, mlt_frame frame )
 {
-       int disable = mlt_properties_get_int( MLT_FILTER_PROPERTIES( self ), "disable" );
+       mlt_properties properties = MLT_FILTER_PROPERTIES( self );
+       int disable = mlt_properties_get_int( properties, "disable" );
+       const char *unique_id = mlt_properties_get( properties, "_unique_id" );
+       mlt_position position = mlt_frame_get_position( frame );
+       char name[20];
+
+       // Make the properties key from unique id
+       strcpy( name, "pos." );
+       strcat( name, unique_id );
+
+       // Save the position on the frame
+       mlt_properties_set_position( MLT_FRAME_PROPERTIES( frame ), name, position );
+
        if ( disable || self->process == NULL )
                return frame;
        else