]> git.sesse.net Git - mlt/blobdiff - src/tests/test_properties/test_properties.cpp
Add Catmull-Rom spline smooth animation interpolation.
[mlt] / src / tests / test_properties / test_properties.cpp
index 34aa080870a6090e6bf122a5fc49d9a58136ead3..1aac05cf9133bb476aaaee56f3eb3683f08ae561 100644 (file)
 #include <mlt++/Mlt.h>
 using namespace Mlt;
 
+extern "C" {
+#define __DARWIN__
+#include <framework/mlt_property.h>
+#include <framework/mlt_animation.h>
+}
+
 class TestProperties: public QObject
 {
     Q_OBJECT
@@ -80,9 +86,9 @@ private Q_SLOTS:
     void SetAndGetInt64()
     {
         Properties p;
-        qint64 i = 1LL << 32;
-        p.set("key", (int64_t)i);
-        QCOMPARE((qint64)p.get_int64("key"), i);
+        int64_t i = 1LL << 32;
+        p.set("key", i);
+        QCOMPARE(p.get_int64("key"), i);
     }
 
     void SetAndGetData()
@@ -111,11 +117,11 @@ private Q_SLOTS:
     {
         Properties p;
         const char *s = "-1";
-        qint64 i = -1;
-        p.set("key", (int64_t)i);
+        int64_t i = -1;
+        p.set("key", i);
         QCOMPARE(p.get("key"), s);
         p.set("key", s);
-        QCOMPARE((qint64)p.get_int64("key"), i);
+        QCOMPARE(p.get_int64("key"), i);
     }
 
     void DoubleFromString()
@@ -304,6 +310,307 @@ private Q_SLOTS:
         p.set("key", "0,125");
         QCOMPARE(p.get_double("key"), double(1) / double(8));
     }
+
+    void DoubleAnimation()
+    {
+        locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+        locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+        double fps = 25.0;
+        mlt_animation a = mlt_animation_new();
+        struct mlt_animation_item_s item;
+
+        mlt_animation_parse(a, "50=1; 60=60; 100=0", 100, fps, locale);
+        mlt_animation_remove(a, 60);
+        char *a_serialized = mlt_animation_serialize(a);
+        QCOMPARE(a_serialized, "50=1;100=0");
+        if (a_serialized) free(a_serialized);
+        item.property = mlt_property_init();
+
+        mlt_animation_get_item(a, &item, 10);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 1.0);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 50);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 1.0);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 75);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.5);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 100);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.0);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 110);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.0);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_property_close(item.property);
+        mlt_animation_close(a);
+    }
+
+    void IntAnimation()
+    {
+        locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+        locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+        double fps = 25.0;
+        mlt_animation a = mlt_animation_new();
+        struct mlt_animation_item_s item;
+
+        mlt_animation_parse(a, "50=100; 60=60; 100=0", 100, fps, locale);
+        mlt_animation_remove(a, 60);
+        char *a_serialized = mlt_animation_serialize(a);
+        QCOMPARE(a_serialized, "50=100;100=0");
+        if (a_serialized) free(a_serialized);
+        item.property = mlt_property_init();
+
+        mlt_animation_get_item(a, &item, 10);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 50);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 75);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 50);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 100);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 110);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_property_close(item.property);
+        mlt_animation_close(a);
+    }
+
+    void AnimationWithTimeValueKeyframes()
+    {
+        locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+        locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+        double fps = 25.0;
+        mlt_animation a = mlt_animation_new();
+        struct mlt_animation_item_s item;
+
+        mlt_animation_parse(a, ":2.0=1; :4.0=0", 100, fps, locale);
+        char *a_serialized = mlt_animation_serialize(a);
+        // Time serializes to frame units :-\.
+        QCOMPARE(a_serialized, "50=1;100=0");
+        if (a_serialized) free(a_serialized);
+        item.property = mlt_property_init();
+
+        mlt_animation_get_item(a, &item, 10);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 1.0);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 50);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 1.0);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 75);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.5);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 100);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.0);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 110);
+        QCOMPARE(mlt_property_get_double(item.property, fps, locale), 0.0);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_property_close(item.property);
+        mlt_animation_close(a);
+    }
+
+    void DiscreteIntAnimation()
+    {
+        locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+        locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+        double fps = 25.0;
+        mlt_animation a = mlt_animation_new();
+        struct mlt_animation_item_s item;
+
+        mlt_animation_parse(a, "50|=100; 60|=60; 100|=0", 100, fps, locale);
+        char *a_serialized = mlt_animation_serialize(a);
+        QCOMPARE(a_serialized, "50|=100;60|=60;100|=0");
+        if (a_serialized) free(a_serialized);
+        item.property = mlt_property_init();
+
+        mlt_animation_get_item(a, &item, 10);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 50);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 55);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 100);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 60);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 60);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 75);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 60);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 100);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 110);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_property_close(item.property);
+        mlt_animation_close(a);
+    }
+
+    void StringAnimation()
+    {
+        locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+        locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+        double fps = 25.0;
+        mlt_animation a = mlt_animation_new();
+        struct mlt_animation_item_s item;
+
+        mlt_animation_parse(a, "50=hello world; 60=\"good night\"; 100=bar", 100, fps, locale);
+        char *a_serialized = mlt_animation_serialize(a);
+        QCOMPARE(a_serialized, "50=hello world;60=\"good night\";100=bar");
+        if (a_serialized) free(a_serialized);
+        item.property = mlt_property_init();
+
+        mlt_animation_get_item(a, &item, 10);
+        QCOMPARE(mlt_property_get_string(item.property), "hello world");
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 50);
+        QCOMPARE(mlt_property_get_string(item.property), "hello world");
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 75);
+        QCOMPARE(mlt_property_get_string(item.property), "\"good night\"");
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 100);
+        QCOMPARE(mlt_property_get_string(item.property), "bar");
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 110);
+        QCOMPARE(mlt_property_get_string(item.property), "bar");
+        QCOMPARE(item.is_key, 0);
+
+        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);
+    }
+
+    void SmoothIntAnimation()
+    {
+        locale_t locale;
+#if defined(__linux__) || defined(__DARWIN__)
+        locale = newlocale( LC_NUMERIC_MASK, "POSIX", NULL );
+#endif
+        double fps = 25.0;
+        mlt_animation a = mlt_animation_new();
+        struct mlt_animation_item_s item;
+
+        mlt_animation_parse(a, "0=80;10~=80; 20~=30; 30~=40; 40~=28; 50=90; 60=0; 70=60; 80=20", 100, fps, locale);
+        item.property = mlt_property_init();
+        char *a_serialized = mlt_animation_serialize(a);
+        QCOMPARE(a_serialized, "0=80;10~=80;20~=30;30~=40;40~=28;50=90;60=0;70=60;80=20");
+        if (a_serialized) free(a_serialized);
+
+        mlt_animation_get_item(a, &item, 10);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 80);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 50);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 90);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 55);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 45);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 60);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 0);
+        QCOMPARE(item.is_key, 1);
+
+        mlt_animation_get_item(a, &item, 75);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 40);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 100);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 20);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_animation_get_item(a, &item, 110);
+        QCOMPARE(mlt_property_get_int(item.property, fps, locale), 20);
+        QCOMPARE(item.is_key, 0);
+
+        mlt_property_close(item.property);
+        mlt_animation_close(a);
+    }
 };
 
 QTEST_APPLESS_MAIN(TestProperties)