producer_framebuffer.c: interpret negative speed as reverse
[melted] / src / modules / kdenlive / producer_framebuffer.c
index 4bdf92a..10dc22f 100644 (file)
@@ -18,7 +18,6 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "producer_framebuffer.h"
 #include <framework/mlt.h>
 
 #include <stdio.h>
@@ -83,6 +82,11 @@ static int framebuffer_get_image( mlt_frame this, uint8_t **image, mlt_image_for
 
        if( first_image == NULL )
        {
+               mlt_properties props = MLT_FRAME_PROPERTIES( this );
+               mlt_properties test_properties = MLT_FRAME_PROPERTIES( first_frame );
+               mlt_properties_set_double( test_properties, "consumer_aspect_ratio", mlt_properties_get_double( props, "consumer_aspect_ratio" ) );
+               mlt_properties_set( test_properties, "rescale.interp", mlt_properties_get( props, "rescale.interp" ) );
+
                error = mlt_frame_get_image( first_frame, &first_image, format, width, height, writable );
 
                if( error != 0 ) {
@@ -109,8 +113,8 @@ static int framebuffer_get_image( mlt_frame this, uint8_t **image, mlt_image_for
 static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index )
 {
        // Construct a new frame
-       *frame = mlt_frame_init( );
-       mlt_properties properties = MLT_PRODUCER_PROPERTIES(this);
+       *frame = mlt_frame_init( MLT_PRODUCER_SERVICE( this ) );
+       mlt_properties properties = MLT_PRODUCER_PROPERTIES( this );
 
        if( frame != NULL )
        {
@@ -167,10 +171,6 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
 
                        // Get the frame
                        mlt_service_get_frame( MLT_PRODUCER_SERVICE( real_producer ), &first_frame, index );
-
-                       double ratio = mlt_properties_get_double( MLT_PRODUCER_PROPERTIES( real_producer ), "aspect_ratio" ) * (double) mlt_properties_get_int( MLT_FRAME_PROPERTIES( first_frame ), "width" ) / (double) mlt_properties_get_int( MLT_FRAME_PROPERTIES( first_frame ), "height" ) / ( (double) mlt_properties_get_int(MLT_FRAME_PROPERTIES( *frame ), "width" ) / (double) mlt_properties_get_int( MLT_FRAME_PROPERTIES( *frame ), "height" ));
-
-                       mlt_properties_set_double( properties, "ratio_fix", ratio );
                }
 
                // Make sure things are in their place
@@ -186,19 +186,18 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
 
                // Give the returned frame temporal identity
                mlt_frame_set_position( *frame, mlt_producer_position( this ) );
-               mlt_properties_set_double( MLT_FRAME_PROPERTIES(*frame), "aspect_ratio", mlt_properties_get_double( properties, "ratio_fix" ));
        }
 
        return 0;
 }
 
 
-mlt_producer producer_framebuffer_init( char *arg )
+mlt_producer producer_framebuffer_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
 {
-
+       if ( !arg ) return NULL;
        mlt_producer this = NULL;
        this = calloc( 1, sizeof( struct mlt_producer_s ) );
-        mlt_producer_init( this, NULL );
+       mlt_producer_init( this, NULL );
 
        // Wrap fezzik
        mlt_producer real_producer;
@@ -206,8 +205,8 @@ mlt_producer producer_framebuffer_init( char *arg )
        // Check if a speed was specified.
        /** 
 
-       * Speed must be appended to the filename with ':'. To play your video at 50%:
-        inigo framebuffer:my_video.mpg:0.5
+       * Speed must be appended to the filename with '?'. To play your video at 50%:
+        inigo framebuffer:my_video.mpg?0.5
 
        * Stroboscope effect can be obtained by adding a stobe=x parameter, where
         x is the number of frames that will be ignored.
@@ -219,25 +218,23 @@ mlt_producer producer_framebuffer_init( char *arg )
 
        **/
 
-       double speed;
-
-       int count;
+       double speed = 0.0;
        char *props = strdup( arg );
-       char *ptr = props;
-       count = strcspn( ptr, ":" );
-       ptr[count] = '\0';
-
-       real_producer = mlt_factory_producer( "fezzik", props );
-
-       ptr += count + 1;
-       ptr += strspn( ptr, ":" );
-       count = strcspn( ptr, ":" );
-       ptr[count] = '\0';
-       speed = atof(ptr);
-       free( props );
+       char *ptr = strrchr( props, '?' );
        
-       if (speed == 0.0) speed = 1.0;
+       if ( ptr )
+       {
+               speed = atof( ptr + 1 );
+               if ( speed != 0.0 )
+                       // If speed was valid, then strip it and the delimiter.
+                       // Otherwise, an invalid speed probably means this '?' was not a delimiter.
+                       *ptr = '\0';
+       }
+               
+       real_producer = mlt_factory_producer( profile, "fezzik", props );
+       free( props );
 
+       if (speed == 0.0) speed = 1.0;
 
        if ( this != NULL && real_producer != NULL)
        {
@@ -246,19 +243,26 @@ mlt_producer producer_framebuffer_init( char *arg )
 
                // Fezzik normalised it for us already
                mlt_properties_set_int( properties, "fezzik_normalised", 1);
+               mlt_properties_set( properties, "resource", arg);
 
                // Store the producer and fitler
                mlt_properties_set_data( properties, "producer", real_producer, 0, ( mlt_destructor )mlt_producer_close, NULL );
 
                // Grab some stuff from the real_producer
-               mlt_properties_pass_list( properties, MLT_PRODUCER_PROPERTIES( real_producer ), "length,resource,width,height" );
+               mlt_properties_pass_list( properties, MLT_PRODUCER_PROPERTIES( real_producer ), "length, width,height" );
 
+               if ( speed < 0 )
+               {
+                       speed = -speed;
+                       mlt_properties_set_int( properties, "reverse", 1 );
+               }
 
                if ( speed != 1.0 )
                {
-                       double real_length = (double)  mlt_producer_get_length( real_producer );
-                       mlt_properties_set_position( properties, "length", real_length / speed );
+                       double real_length = ( (double)  mlt_producer_get_length( real_producer ) ) / speed;
+                       mlt_properties_set_position( properties, "length", real_length );
                }
+               mlt_properties_set_position( properties, "out", mlt_producer_get_length( this ) - 1 );
 
                // Since we control the seeking, prevent it from seeking on its own
                mlt_producer_set_speed( real_producer, 0 );