]> git.sesse.net Git - mlt/commitdiff
Add mlt_filter_get_position().
authorDan Dennedy <dan@dennedy.org>
Wed, 9 Mar 2011 07:52:29 +0000 (23:52 -0800)
committerDan Dennedy <dan@dennedy.org>
Fri, 11 Mar 2011 07:15:45 +0000 (23:15 -0800)
src/framework/mlt_filter.c
src/framework/mlt_filter.h
src/mlt++/MltFilter.cpp
src/mlt++/MltFilter.h

index 3df813fd9951545ab5a1d8f26c387e45b0d54a02..309340efde8099e0ff46e38dfe8027863801459e 100644 (file)
@@ -202,7 +202,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
@@ -218,13 +245,17 @@ double mlt_filter_get_progress( mlt_filter self, mlt_frame frame )
        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 +266,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
index d81ae10528847480b359a3c820138c725c2f542a..108aae21918ae8c60137a7080b63ad43a4f6e983 100644 (file)
@@ -65,6 +65,7 @@ extern int mlt_filter_get_track( mlt_filter self );
 extern mlt_position mlt_filter_get_in( mlt_filter self );
 extern mlt_position mlt_filter_get_out( mlt_filter self );
 extern mlt_position mlt_filter_get_length( mlt_filter self );
+extern mlt_position mlt_filter_get_position( mlt_filter self, mlt_frame frame );
 extern double mlt_filter_get_progress( mlt_filter self, mlt_frame frame );
 extern void mlt_filter_close( mlt_filter );
 
index 3f2f0ee8ee13bc59f7d96af88ada9a94dbfa95c5..9da6e6d5dcea62de1596219ac7a4135da3a84648 100644 (file)
@@ -116,6 +116,11 @@ int Filter::get_track( )
        return mlt_filter_get_track( get_filter( ) );
 }
 
+int Filter::get_position( Frame &frame )
+{
+       return mlt_filter_get_position( get_filter( ), frame.get_frame( ) );
+}
+
 double Filter::get_progress( Frame &frame )
 {
        return mlt_filter_get_progress( get_filter( ), frame.get_frame( ) );
index 254015afc0e0d7dff3e0c01ca9e920c07d250ea2..934d0e1edf13f832daa1d34a1c9ca1304961119a 100644 (file)
@@ -51,6 +51,7 @@ namespace Mlt
                        int get_out( );
                        int get_length( );
                        int get_track( );
+                       int get_position( Frame &frame );
                        double get_progress( Frame &frame );
        };
 }