From: Dan Dennedy Date: Fri, 17 May 2013 17:22:14 +0000 (-0700) Subject: Add mlt_property_get_double_pos() and mlt_property_get_int_pos(). X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=6a4487ef0f78017bf0e5c0e1ec53b707a3205681;p=mlt Add mlt_property_get_double_pos() and mlt_property_get_int_pos(). --- diff --git a/src/framework/mlt_property.c b/src/framework/mlt_property.c index 21c6e08c..eab9f37e 100644 --- a/src/framework/mlt_property.c +++ b/src/framework/mlt_property.c @@ -27,6 +27,7 @@ #endif #include "mlt_property.h" +#include "mlt_animation.h" #include #include @@ -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; +} diff --git a/src/framework/mlt_property.h b/src/framework/mlt_property.h index dae50bab..c87f657f 100644 --- a/src/framework/mlt_property.h +++ b/src/framework/mlt_property.h @@ -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 diff --git a/src/tests/test_properties/test_properties.cpp b/src/tests/test_properties/test_properties.cpp index b8eb494c..b0bd50a9 100644 --- a/src/tests/test_properties/test_properties.cpp +++ b/src/tests/test_properties/test_properties.cpp @@ -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)