]> git.sesse.net Git - mlt/commitdiff
Add mlt_property_get_double_pos() and mlt_property_get_int_pos().
authorDan Dennedy <dan@dennedy.org>
Fri, 17 May 2013 17:22:14 +0000 (10:22 -0700)
committerDan Dennedy <dan@dennedy.org>
Fri, 31 May 2013 23:58:12 +0000 (16:58 -0700)
src/framework/mlt_property.c
src/framework/mlt_property.h
src/tests/test_properties/test_properties.cpp

index 21c6e08c7cd4f81c6e48ab47bbbdac5d64d7530d..eab9f37e9c669a7b1ffd7b71fd89462dd5ab28ba 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 
 #include "mlt_property.h"
+#include "mlt_animation.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -77,6 +78,7 @@ struct mlt_property_s
        mlt_serialiser serialiser;
 
        pthread_mutex_t mutex;
+       mlt_animation animation;
 };
 
 /** Construct a property and initialize it
@@ -85,21 +87,9 @@ struct mlt_property_s
 
 mlt_property mlt_property_init( )
 {
-       mlt_property self = malloc( sizeof( struct mlt_property_s ) );
-       if ( self != NULL )
-       {
-               self->types = 0;
-               self->prop_int = 0;
-               self->prop_position = 0;
-               self->prop_double = 0;
-               self->prop_int64 = 0;
-               self->prop_string = NULL;
-               self->data = NULL;
-               self->length = 0;
-               self->destructor = NULL;
-               self->serialiser = NULL;
+       mlt_property self = calloc( 1, sizeof( *self ) );
+       if ( self )
                pthread_mutex_init( &self->mutex, NULL );
-       }
        return self;
 }
 
@@ -120,6 +110,9 @@ static inline void mlt_property_clear( mlt_property self )
        if ( self->types & mlt_prop_string )
                free( self->prop_string );
 
+       if ( self->animation )
+               mlt_animation_close( self->animation );
+
        // Wipe stuff
        self->types = 0;
        self->prop_int = 0;
@@ -131,6 +124,7 @@ static inline void mlt_property_clear( mlt_property self )
        self->length = 0;
        self->destructor = NULL;
        self->serialiser = NULL;
+       self->animation = NULL;
 }
 
 /** Set the property to an integer value.
@@ -971,3 +965,58 @@ int mlt_property_interpolate(mlt_property self, mlt_property previous, mlt_prope
        }
        return error;
 }
+
+static void refresh_animation( mlt_property self, double fps, locale_t locale, int length  )
+{
+       if ( !self->animation )
+       {
+               self->animation = mlt_animation_new();
+               mlt_animation_parse( self->animation, self->prop_string, length, fps, locale );
+       }
+       else
+       {
+               mlt_animation_refresh( self->animation, self->prop_string, length );
+       }
+}
+
+double mlt_property_get_double_pos( mlt_property self, double fps, locale_t locale, int position, int length )
+{
+       double result;
+       if ( ( self->types & mlt_prop_string ) && self->prop_string )
+       {
+               struct mlt_animation_item_s item;
+               item.property = mlt_property_init();
+
+               refresh_animation( self, fps, locale, length );
+               mlt_animation_get_item( self->animation, &item, position );
+               result = mlt_property_get_double( item.property, fps, locale );
+
+               mlt_property_close( item.property );
+       }
+       else
+       {
+               result = mlt_property_get_double( self, fps, locale );
+       }
+       return result;
+}
+
+int mlt_property_get_int_pos( mlt_property self, double fps, locale_t locale, int position, int length )
+{
+       int result;
+       if ( ( self->types & mlt_prop_string ) && self->prop_string )
+       {
+               struct mlt_animation_item_s item;
+               item.property = mlt_property_init();
+
+               refresh_animation( self, fps, locale, length );
+               mlt_animation_get_item( self->animation, &item, position );
+               result = mlt_property_get_int( item.property, fps, locale );
+
+               mlt_property_close( item.property );
+       }
+       else
+       {
+               result = mlt_property_get_int( self, fps, locale );
+       }
+       return result;
+}
index dae50bab37199025959ed60d611bc419c394c249..c87f657febcae5918ca0500f24e373f948095251 100644 (file)
@@ -56,5 +56,7 @@ extern void mlt_property_pass( mlt_property self, mlt_property that );
 extern char *mlt_property_get_time( mlt_property self, mlt_time_format, double fps, locale_t );
 extern int mlt_property_interpolate(mlt_property self, mlt_property previous, mlt_property next,
                                      double position, int length, double fps, locale_t locale  );
+extern double mlt_property_get_double_pos(mlt_property self, double fps, locale_t locale, int position, int length );
+extern int mlt_property_get_int_pos(mlt_property self, double fps, locale_t locale, int position, int length );
 
 #endif
index b8eb494cbd6c1eaab07ab71ee6d385b947b8d4b9..b0bd50a9005926becc5fcce9e5af09a75ad8b62b 100644 (file)
@@ -521,6 +521,48 @@ private Q_SLOTS:
         mlt_property_close(item.property);
         mlt_animation_close(a);
     }
+
+    void test_property_get_double_pos()
+    {
+        locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+        locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+        double fps = 25.0;
+        mlt_property p = mlt_property_init();
+        mlt_property_set_string(p, "10=100; 20=200");
+        QCOMPARE(mlt_property_get_double(p, fps, locale), 10.0);
+        QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 0, 100), 100.0);
+        QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 15, 100), 150.0);
+        QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 20, 100), 200.0);
+
+        mlt_property_set_string(p, "1.5");
+        QCOMPARE(mlt_property_get_double(p, fps, locale), 1.5);
+        QCOMPARE(mlt_property_get_double_pos(p, fps, locale, 10, 100), 1.5);
+
+        mlt_property_close(p);
+    }
+
+    void test_property_get_int_pos()
+    {
+        locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+        locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+        double fps = 25.0;
+        mlt_property p = mlt_property_init();
+        mlt_property_set_string(p, "10=100; 20=200");
+        QCOMPARE(mlt_property_get_int(p, fps, locale), 10);
+        QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 0, 100), 100);
+        QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 15, 100), 150);
+        QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 20, 100), 200);
+
+        mlt_property_set_string(p, "1.5");
+        QCOMPARE(mlt_property_get_int(p, fps, locale), 1);
+        QCOMPARE(mlt_property_get_int_pos(p, fps, locale, 10, 100), 1);
+
+        mlt_property_close(p);
+    }
 };
 
 QTEST_APPLESS_MAIN(TestProperties)