Tractor frame handling reworked; fix to composite for key diffs of 1; added mlt_consu...
[melted] / src / framework / mlt_consumer.c
index aadbb07..2a05df1 100644 (file)
@@ -53,6 +53,7 @@ int mlt_consumer_init( mlt_consumer this, void *child )
                        mlt_properties_set_int( properties, "width", 720 );
                        mlt_properties_set_int( properties, "height", 576 );
                        mlt_properties_set_int( properties, "progressive", 0 );
+                       mlt_properties_set_double( properties, "aspect_ratio", 128.0 / 117.0 );
                }
                else
                {
@@ -61,11 +62,9 @@ int mlt_consumer_init( mlt_consumer this, void *child )
                        mlt_properties_set_int( properties, "width", 720 );
                        mlt_properties_set_int( properties, "height", 480 );
                        mlt_properties_set_int( properties, "progressive", 0 );
+                       mlt_properties_set_double( properties, "aspect_ratio", 72.0 / 79.0 );
                }
 
-               // Default aspect ratio
-               mlt_properties_set_double( properties, "aspect_ratio", 4.0 / 3.0 );
-
                // Default rescaler for all consumers
                mlt_properties_set( properties, "rescale", "bilinear" );
 
@@ -78,6 +77,22 @@ int mlt_consumer_init( mlt_consumer this, void *child )
        return error;
 }
 
+/** Create a new consumer.
+*/
+
+mlt_consumer mlt_consumer_new( )
+{
+       // Create the memory for the structure
+       mlt_consumer this = malloc( sizeof( struct mlt_consumer_s ) );
+
+       // Initialise it
+       if ( this != NULL )
+               mlt_consumer_init( this, NULL );
+
+       // Return it
+       return this;
+}
+
 /** Get the parent service object.
 */
 
@@ -223,19 +238,20 @@ static void *consumer_read_ahead_thread( void *arg )
 
        // Average time for get_frame and get_image
        int count = 1;
+       int skipped = 0;
        int64_t time_wait = 0;
        int64_t time_frame = 0;
        int64_t time_image = 0;
 
        // Get the first frame
-       gettimeofday( &ante, NULL );
        frame = mlt_consumer_get_frame( this );
-       time_frame = time_difference( &ante );
 
        // Get the image of the first frame
        mlt_frame_get_image( frame, &image, &this->format, &width, &height, 0 );
        mlt_properties_set_int( mlt_frame_properties( frame ), "rendered", 1 );
-       time_image = time_difference( &ante );
+
+       // Get the starting time (can ignore the times above)
+       gettimeofday( &ante, NULL );
 
        // Continue to read ahead
        while ( this->ahead )
@@ -257,18 +273,30 @@ static void *consumer_read_ahead_thread( void *arg )
                count ++;
 
                // Get the image
-               if ( ( time_frame + time_image + time_wait ) / count < 40000 )
+               if ( ( time_frame + time_image ) / count < ( 40000 - ( time_wait / count ) ) )
                {
                        // Get the image, mark as rendered and time it
                        mlt_frame_get_image( frame, &image, &this->format, &width, &height, 0 );
                        mlt_properties_set_int( mlt_frame_properties( frame ), "rendered", 1 );
                        time_image += time_difference( &ante );
+
+                       // Reset the skipped count
+                       skipped = 0;
                }
                else
                {
-                       // This is wrong, but it avoids slower machines getting starved 
-                       // It is, after all, impossible to go back in time :-/
-                       time_image -= ( time_image / count / 8 );
+                       // Increment the number of sequentially skipped frames
+                       skipped ++;
+
+                       // If we've reached an unacceptable level, reset everything
+                       if ( skipped > 10 )
+                       {
+                               skipped = 0;
+                               time_frame = 0;
+                               time_image = 0;
+                               time_wait = 0;
+                               count = 0;
+                       }
                }
        }
 
@@ -405,4 +433,3 @@ void mlt_consumer_close( mlt_consumer this )
        else
                mlt_service_close( &this->parent );
 }
-