]> git.sesse.net Git - mlt/commitdiff
Yet more sdl hacking, region memory leak fix, mlt_position changed to int32_t, experi...
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 3 Mar 2004 13:00:41 +0000 (13:00 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Wed, 3 Mar 2004 13:00:41 +0000 (13:00 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@184 d19143bc-622f-0410-bfdd-b5b2a6649095

16 files changed:
src/framework/mlt_multitrack.c
src/framework/mlt_pool.c
src/framework/mlt_pool.h
src/framework/mlt_properties.c
src/framework/mlt_property.c
src/framework/mlt_service.c
src/framework/mlt_service.h
src/framework/mlt_types.h
src/inigo/inigo.c
src/modules/avformat/producer_avformat.c
src/modules/core/filter_region.c
src/modules/core/transition_composite.c
src/modules/core/transition_composite.h
src/modules/gtk2/producer_pixbuf.c
src/modules/sdl/consumer_sdl.c
src/modules/westley/consumer_westley.c

index ca3103acc2483dcc7c71924719d310841aa4a511..323d1ee9e3da4ac5807bc053646a6b3e600f4eb4 100644 (file)
@@ -212,7 +212,7 @@ mlt_producer mlt_multitrack_track( mlt_multitrack this, int track )
 
 static int position_compare( const void *p1, const void *p2 )
 {
-       return *( int64_t * )p1 - *( int64_t * )p2;
+       return *( mlt_position * )p1 - *( mlt_position * )p2;
 }
 
 static int add_unique( mlt_position *array, int size, mlt_position position )
@@ -251,7 +251,7 @@ mlt_position mlt_multitrack_clip( mlt_multitrack this, mlt_whence whence, int in
        mlt_position position = 0;
        int i = 0;
        int j = 0;
-       int64_t *map = malloc( 1000 * sizeof( mlt_position ) );
+       mlt_position *map = malloc( 1000 * sizeof( mlt_position ) );
        int count = 0;
 
        for ( i = 0; i < this->count; i ++ )
@@ -284,7 +284,7 @@ mlt_position mlt_multitrack_clip( mlt_multitrack this, mlt_whence whence, int in
        }
 
        // Now sort the map
-       qsort( map, count, sizeof( int64_t ), position_compare );
+       qsort( map, count, sizeof( mlt_position ), position_compare );
 
        // Now locate the requested index
        switch( whence )
index daa0d297b28e0573f44327cde91529e4283cf856..72e11baf589db2e75610db2e451bc8fc6208c163 100644 (file)
@@ -242,6 +242,47 @@ void *mlt_pool_alloc( int size )
        return pool_fetch( pool );
 }
 
+/** Allocate size bytes from the pool.
+*/
+
+void *mlt_pool_realloc( void *ptr, int size )
+{
+       // Result to return
+       void *result = NULL;
+
+       // Check if we actually have an address
+       if ( ptr != NULL )
+       {
+               // Get the release pointer
+               mlt_release that = ptr - sizeof( struct mlt_release_s );
+
+               // If the current pool this ptr belongs to is big enough
+               if ( size > that->pool->size - sizeof( struct mlt_release_s ) )
+               {
+                       // Allocate
+                       result = mlt_pool_alloc( size );
+
+                       // Copy
+                       memcpy( result, ptr, that->pool->size - sizeof( struct mlt_release_s ) );
+
+                       // Release
+                       mlt_pool_release( ptr );
+               }
+               else
+               {
+                       // Nothing to do
+                       result = ptr;
+               }
+       }
+       else
+       {
+               // Simply allocate
+               result = mlt_pool_alloc( size );
+       }
+
+       return result;
+}
+
 /** Release the allocated memory.
 */
 
index 7a9c1cbe23731298fc51692825703767910d7f9e..682a960f78281e08b8d74e912b6e8e6c7fbf6da5 100644 (file)
@@ -23,6 +23,7 @@
 
 extern void mlt_pool_init( );
 extern void *mlt_pool_alloc( int size );
+extern void *mlt_pool_realloc( void *ptr, int size );
 extern void mlt_pool_release( void *release );
 extern void mlt_pool_close( );
 
index a774ca1d06727cfc5640d394f14fc6cf3b543547..cebaa900d144677dd4adf9b5f9e5f90b83545118 100644 (file)
@@ -33,6 +33,7 @@
 
 typedef struct
 {
+       int hash[ 199 ];
        char **name;
        mlt_property *value;
        int count;
@@ -72,6 +73,15 @@ mlt_properties mlt_properties_new( )
        return this;
 }
 
+static inline int generate_hash( char *name )
+{
+       int hash = 0;
+       int i = 1;
+       while ( *name )
+               hash = ( hash + ( i ++ * ( *name ++ & 31 ) ) ) % 199;
+       return hash;
+}
+
 /** Special case - when a container (such as fezzik) is protecting another 
        producer, we need to ensure that properties are passed through to the
        real producer.
@@ -142,15 +152,22 @@ int mlt_properties_pass( mlt_properties this, mlt_properties that, char *prefix
 /** Locate a property by name
 */
 
-static mlt_property mlt_properties_find( mlt_properties this, char *name )
+static inline mlt_property mlt_properties_find( mlt_properties this, char *name )
 {
-       mlt_property value = NULL;
        property_list *list = this->private;
+       mlt_property value = NULL;
        int i = 0;
+       int key = generate_hash( name );
+
+       // Check if we're hashed
+       if ( list->count > 0 &&
+                name[ 0 ] == list->name[ list->hash[ key ] ][ 0 ] && 
+                !strcmp( list->name[ list->hash[ key ] ], name ) )
+               value = list->value[ list->hash[ key ] ];
 
        // Locate the item 
        for ( i = 0; value == NULL && i < list->count; i ++ )
-               if ( !strcmp( list->name[ i ], name ) )
+               if ( name[ 0 ] == list->name[ i ][ 0 ] && !strcmp( list->name[ i ], name ) )
                        value = list->value[ i ];
 
        return value;
@@ -162,6 +179,7 @@ static mlt_property mlt_properties_find( mlt_properties this, char *name )
 static mlt_property mlt_properties_add( mlt_properties this, char *name )
 {
        property_list *list = this->private;
+       int key = generate_hash( name );
 
        // Check that we have space and resize if necessary
        if ( list->count == list->size )
@@ -175,6 +193,9 @@ static mlt_property mlt_properties_add( mlt_properties this, char *name )
        list->name[ list->count ] = strdup( name );
        list->value[ list->count ] = mlt_property_init( );
 
+       // Assign to hash table
+       list->hash[ key ] = list->count;
+
        // Return and increment count accordingly
        return list->value[ list->count ++ ];
 }
index 0a475299d34855770d8a8fdb32eac6fd127a5dba..eaa19675ba5134f8d49d45449d04bb32db25d100 100644 (file)
@@ -31,7 +31,7 @@
 
 mlt_property mlt_property_init( )
 {
-       return calloc( sizeof( struct mlt_property_s ), 1 );
+       return calloc( 1, sizeof( struct mlt_property_s ) );
 }
 
 /** Clear a property.
@@ -219,7 +219,7 @@ char *mlt_property_get_string( mlt_property this )
                {
                        this->types |= mlt_prop_string;
                        this->prop_string = malloc( 32 );
-                       sprintf( this->prop_string, "%lld", this->prop_position );
+                       sprintf( this->prop_string, "%d", this->prop_position );
                }
                else if ( this->types & mlt_prop_int64 )
                {
index f432aae8774b2288c647908e654ef8dda873715e..62112d9653f20f66a572c50bb436b28f8de4b724 100644 (file)
@@ -75,14 +75,6 @@ int mlt_service_init( mlt_service this, void *child )
        return mlt_properties_init( &this->parent, this );
 }
 
-/** Return the properties object.
-*/
-
-mlt_properties mlt_service_properties( mlt_service this )
-{
-       return &this->parent;
-}
-
 /** Connect a producer service.
        Returns: > 0 warning, == 0 success, < 0 serious error
                         1 = this service does not accept input
index 8ad43a8ffefb6affde3b911814f364bd629d8273..21168cd842dbd25f6f93efc69731958d18fe38e2 100644 (file)
@@ -63,7 +63,7 @@ struct mlt_service_s
 */
 
 extern int mlt_service_init( mlt_service this, void *child );
-extern mlt_properties mlt_service_properties( mlt_service this );
+//extern mlt_properties mlt_service_properties( mlt_service this );
 extern int mlt_service_connect_producer( mlt_service this, mlt_service producer, int index );
 extern mlt_service_state mlt_service_get_state( mlt_service this );
 extern void mlt_service_close( mlt_service this );
@@ -76,5 +76,13 @@ extern int mlt_service_get_frame( mlt_service this, mlt_frame_ptr frame, int ind
 extern int mlt_service_is_active( mlt_service this );
 extern mlt_service mlt_service_get_producer( mlt_service this );
 
+/** Return the properties object.
+*/
+
+static inline mlt_properties mlt_service_properties( mlt_service this )
+{
+       return &this->parent;
+}
+
 #endif
 
index adc199f32de36e1c0594946a66c49f3ffc387416..f55bc9ab5003c01089f245e0ac74a7c385f059dd 100644 (file)
@@ -33,7 +33,7 @@ typedef enum
 }
 mlt_whence;
 
-typedef int64_t mlt_position;
+typedef int32_t mlt_position;
 typedef struct mlt_frame_s *mlt_frame, **mlt_frame_ptr;
 typedef struct mlt_properties_s *mlt_properties;
 typedef struct mlt_service_s *mlt_service;
index acbd83edf8db03f2c48abf633b96f1b23c658eae..563371a76178c68d09e07ce4155a82f3a6f6cd78 100644 (file)
@@ -64,7 +64,7 @@ static void transport_action( mlt_producer producer, char *value )
                                                if ( time == last )
                                                        break;
                                                last = time;
-                                               fprintf( stderr, "%d: %lld\n", i, time );
+                                               fprintf( stderr, "%d: %d\n", i, time );
                                        }
                                }
                                break;
@@ -168,7 +168,7 @@ static void transport( mlt_producer producer, mlt_consumer consumer )
                        transport_action( producer, ( char * )&value );
 
                if ( mlt_properties_get_int( properties, "stats_off" ) == 0 )
-                       fprintf( stderr, "Current Position: %10lld\r", mlt_producer_position( producer ) );
+                       fprintf( stderr, "Current Position: %10d\r", mlt_producer_position( producer ) );
        }
 
        fprintf( stderr, "\n" );
index c8fe492d6e9f1230d7f97d45432dfa61542c4802..8400f41e320334f356f085df86044a8842cfc5d2 100644 (file)
@@ -41,6 +41,21 @@ static int producer_get_frame( mlt_producer this, mlt_frame_ptr frame, int index
 static int avformat_initialised = 0;
 static pthread_mutex_t avformat_mutex;
 
+void *av_malloc( unsigned int size )
+{
+       return mlt_pool_alloc( size );
+}
+
+void *av_realloc( void *ptr, unsigned int size )
+{
+       return mlt_pool_realloc( ptr, size );
+}
+
+void av_free( void *ptr )
+{
+       return mlt_pool_release( ptr );
+}
+
 /** Constructor for libavformat.
 */
 
@@ -72,8 +87,8 @@ mlt_producer producer_avformat_init( char *file )
                        // Initialise avformat if necessary
                        if ( avformat_initialised == 0 )
                        {
-                               pthread_mutex_init( &avformat_mutex, NULL );
                                avformat_initialised = 1;
+                               pthread_mutex_init( &avformat_mutex, NULL );
                                av_register_all( );
                        }
 
index 8e11f3777c6d11f782ba8c8be6ae68dce4d0ea61..b6ef9708701d30576b2d83435bbf65f85568dfca 100644 (file)
@@ -66,6 +66,10 @@ static int create_instance( mlt_filter this, char *name, char *value, int count
                // Counstruct key
                sprintf( key, "%s.", name );
 
+               // Just in case, let's assume that the filter here has a composite
+               mlt_properties_set( mlt_filter_properties( filter ), "composite.start", "0%,0%:100%x100%" );
+               mlt_properties_set( mlt_filter_properties( filter ), "composite.fill", "true" );
+
                // Pass all the key properties on the filter down
                mlt_properties_pass( mlt_filter_properties( filter ), properties, key );
 
@@ -114,6 +118,12 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // Look for the first filter
        mlt_filter filter = mlt_properties_get_data( properties, "_filter_0", NULL );
 
+       // Get the unique id of the filter (used to reacquire the producer position)
+       char *name = mlt_properties_get( properties, "_unique_id" );
+
+       // Get the original producer position
+       mlt_position position = mlt_properties_get_position( mlt_frame_properties( frame ), name );
+
        // Create a composite if we don't have one
        if ( composite == NULL )
        {
@@ -172,6 +182,9 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
        // Only continue if we have both filter and composite
        if ( composite != NULL && filter != NULL )
        {
+               // Get the resource of this filter (could be a shape [rectangle/circle] or an alpha provider of choice
+               char *resource =  mlt_properties_get( properties, "resource" );
+
                // String to hold the filter to query on
                char id[ 256 ];
 
@@ -179,7 +192,7 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                int i = 0;
 
                // We will get the 'b frame' from the composite
-               mlt_frame b_frame = composite_copy_region( composite, frame );
+               mlt_frame b_frame = composite_copy_region( composite, frame, position );
 
                // Make sure the filter is in the correct position
                while ( filter != NULL )
@@ -194,30 +207,35 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                        filter = mlt_properties_get_data( properties, id, NULL );
                }
 
+               // Hmm - this is probably going to go wrong....
+               mlt_frame_set_position( frame, position );
+
                // Get the b frame and process with composite if successful
                mlt_transition_process( composite, frame, b_frame );
 
-               // See if we have a shape producer
-               // Copy the alpha mask from the shape frame to the b_frame
-               char *resource =  mlt_properties_get( properties, "resource" );
-
+               // If we have a shape producer copy the alpha mask from the shape frame to the b_frame
                if ( strcmp( resource, "rectangle" ) != 0 )
                {
-                       if ( strcmp( resource, "circle" ) == 0 )
-                       {
-                               resource = strdup( "pixbuf" );
-                               mlt_properties_set( properties, "producer.resource", "<svg width='100' height='100'><circle cx='50' cy='50' r='50' fill='black'/></svg>" );
-                       }
-
                        // Get the producer from the filter
                        mlt_producer producer = mlt_properties_get_data( properties, "producer", NULL );
 
+                       // If We have no producer then create one
                        if ( producer == NULL )
                        {
                                // Get the factory producer service
                                char *factory = mlt_properties_get( properties, "factory" );
 
-                               // Create the producer
+                               // Special case circle resource
+                               if ( strcmp( resource, "circle" ) == 0 )
+                               {
+                                       // Special case to ensure that fezzik produces a pixbuf with a NULL constructor
+                                       resource = "pixbuf";
+
+                                       // Specify the svg circle
+                                       mlt_properties_set( properties, "producer.resource", "<svg width='100' height='100'><circle cx='50' cy='50' r='50' fill='black'/></svg>" );
+                               }
+
+                               // Create the producer 
                                producer = mlt_factory_producer( factory, resource );
 
                                // If we have one
@@ -237,17 +255,12 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                }
                        }
 
+                       // Now use the shape producer
                        if ( producer != NULL )
                        {
                                // We will get the alpha frame from the producer
                                mlt_frame shape_frame = NULL;
 
-                               // Get the unique id of the filter (used to reacquire the producer position)
-                               char *name = mlt_properties_get( properties, "_unique_id" );
-
-                               // Get the original producer position
-                               mlt_position position = mlt_properties_get_position( mlt_frame_properties( frame ), name );
-
                                // Make sure the producer is in the correct position
                                mlt_producer_seek( producer, position );
 
@@ -269,26 +282,17 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
                                                b_frame->get_alpha_mask = filter_get_alpha_mask;
                                        }
                                        
-                                       // Get the image
-                                       error = mlt_frame_get_image( frame, image, format, width, height, 0 );
-
-                                       // Close the b frame
-                                       mlt_frame_close( b_frame );
-                                       b_frame = NULL;
-
-                                       // Close the shape frame
-                                       mlt_frame_close( shape_frame );
+                                       // Ensure that the shape frame will be closed
+                                       mlt_properties_set_data( mlt_frame_properties( b_frame ), "shape_frame", shape_frame, 0, ( mlt_destructor )mlt_frame_close, NULL );
                                }
                        }
                }
-               if ( b_frame != NULL )
-               {
-                       // Get the image
-                       error = mlt_frame_get_image( frame, image, format, width, height, 0 );
 
-                       // Close the b frame
-                       mlt_frame_close( b_frame );
-               }
+               // Get the image
+               error = mlt_frame_get_image( frame, image, format, width, height, 0 );
+
+               // Close the b frame
+               mlt_frame_close( b_frame );
        }
 
        return error;
@@ -299,6 +303,15 @@ static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format
 
 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
 {
+       // Get the properties of the frame
+       mlt_properties properties = mlt_frame_properties( frame );
+
+       // Get a unique name to store the frame position
+       char *name = mlt_properties_get( mlt_filter_properties( this ), "_unique_id" );
+
+       // Assign the current position to the name
+       mlt_properties_set_position( properties, name, mlt_frame_get_position( frame ) );
+
        // Push the filter on to the frame
        mlt_frame_push_service( frame, this );
 
index d9c1bf40c3ff5deb62d2229d0ab45ba689426577..42f23eba1699024b871d485eee272a350e2136d2 100644 (file)
@@ -285,15 +285,12 @@ static void alignment_calculate( struct geometry_s *geometry )
 /** Calculate the position for this frame.
 */
 
-static float position_calculate( mlt_transition this, mlt_frame frame )
+static float position_calculate( mlt_transition this, mlt_position position )
 {
        // Get the in and out position
        mlt_position in = mlt_transition_get_in( this );
        mlt_position out = mlt_transition_get_out( this );
 
-       // Get the position
-       mlt_position position = mlt_frame_get_position( frame );
-
        // Now do the calcs
        return ( float )( position - in ) / ( float )( out - in + 1 );
 }
@@ -562,7 +559,7 @@ struct geometry_s *composite_calculate( struct geometry_s *result, mlt_transitio
        return start;
 }
 
-mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame )
+mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame, mlt_position frame_position )
 {
        // Create a frame to return
        mlt_frame b_frame = mlt_frame_init( );
@@ -574,7 +571,7 @@ mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame )
        mlt_properties b_props = mlt_frame_properties( b_frame );
 
        // Get the position
-       float position = position_calculate( this, a_frame );
+       float position = position_calculate( this, frame_position );
 
        // Destination image
        uint8_t *dest = NULL;
@@ -630,6 +627,9 @@ mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame )
        mlt_properties_set_int( b_props, "width", w );
        mlt_properties_set_int( b_props, "height", h );
 
+       // Assign this position to the b frame
+       mlt_frame_set_position( b_frame, frame_position );
+
        // Return the frame
        return b_frame;
 }
@@ -719,7 +719,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
 static mlt_frame composite_process( mlt_transition this, mlt_frame a_frame, mlt_frame b_frame )
 {
        // Propogate the transition properties to the b frame
-       mlt_properties_set_double( mlt_frame_properties( b_frame ), "relative_position", position_calculate( this, a_frame ) );
+       mlt_properties_set_double( mlt_frame_properties( b_frame ), "relative_position", position_calculate( this, mlt_frame_get_position( a_frame ) ) );
        mlt_frame_push_service( a_frame, this );
        mlt_frame_push_get_image( a_frame, transition_get_image );
        mlt_frame_push_frame( a_frame, b_frame );
index 7ae477544de17c38a1815f52a569e44ccf9d285d..28ba6bad36e6ef986d2aef4095fc97ceb7351327 100644 (file)
@@ -26,6 +26,6 @@
 extern mlt_transition transition_composite_init( char *arg );
 
 // Courtesy functionality - allows regionalised filtering
-extern mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame );
+extern mlt_frame composite_copy_region( mlt_transition this, mlt_frame a_frame, mlt_position position );
 
 #endif
index 5e341fee528e9718db4b3e392b5041d26240da71..88355b9a2e093d14b1bf6b03cc8175f49e512db2 100644 (file)
@@ -401,11 +401,9 @@ static void producer_close( mlt_producer parent )
        mlt_pool_release( this->image );
        parent->close = NULL;
        mlt_producer_close( parent );
-       while ( *this->filenames )
-       {
-               free( *this->filenames );
-               this->filenames++;
-       }
+       while ( this->count -- )
+               free( this->filenames[ this->count ] );
+       free( this->filenames );
        free( this );
 }
 
index f2d9fe798928a8018c9da2e5a6b27823ce2fed3f..8ddabcdad85ac98638b76dd18e04d9a18444ba8e 100644 (file)
@@ -55,6 +55,7 @@ struct consumer_sdl_s
        SDL_Surface *sdl_screen;
        SDL_Overlay *sdl_overlay;
        uint8_t *buffer;
+       int time_taken;
 };
 
 /** Forward references to static functions.
@@ -335,6 +336,15 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame, int64_t elap
        mlt_properties_set_position( mlt_frame_properties( frame ), "playtime", playtime );
        mlt_properties_set_double( mlt_frame_properties( frame ), "consumer_scale", ( double )height / mlt_properties_get_double( properties, "height" ) );
 
+       if ( !this->playing )
+       {
+               struct timeb render;
+               mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
+               ftime( &render );
+               this->time_taken = ( ( int64_t )render.time * 1000 + render.millitm ) - ( ( int64_t )before.time * 1000 + before.millitm );
+               mlt_properties_set( mlt_frame_properties( frame ), "rendered", "true" );
+       }
+
        // Push this frame to the back of the queue
        mlt_deque_push_back( this->queue, frame );
        frame = NULL;
@@ -354,7 +364,7 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame, int64_t elap
                        {
                                frame = mlt_deque_pop_front( this->queue );
                        }
-                       else if ( playtime > elapsed + 60 || mlt_deque_count( this->queue ) < 12 )
+                       else if ( playtime > elapsed + 100 )
                        {
                                // no frame to show or remove
                                frame = NULL;
@@ -362,9 +372,13 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame, int64_t elap
                        }
                        else if ( playtime < elapsed - 20 )
                        {
-                               if ( candidate != NULL )
-                                       mlt_frame_close( candidate );
+                               mlt_frame_close( candidate );
                                candidate = mlt_deque_pop_front( this->queue );
+                               if ( mlt_properties_get( mlt_frame_properties( frame ), "rendered" ) == NULL )
+                               {
+                                       mlt_frame_close( candidate );
+                                       candidate = NULL;
+                               }
                                frame = NULL;
                        }
                        else
@@ -380,21 +394,17 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame, int64_t elap
                        mlt_frame_close( candidate );
        }
 
+       struct timeb render;
+       ftime( &render );
+
        if ( this->playing && frame != NULL )
        {
-               struct timeb after;
 
                // Get the image, width and height
                mlt_frame_get_image( frame, &image, &vfmt, &width, &height, 0 );
-
-               ftime( &after );
-               //fprintf( stderr, "showing %lld at %lld\n", playtime, elapsed );
-               int processing = ( ( int64_t )after.time * 1000 + after.millitm ) - ( ( int64_t )before.time * 1000 + before.millitm );
-
-               int delay = playtime - elapsed - processing;
-               struct timespec slow = { 0, ( delay % 1000 ) * 500000 };
-               if ( slow.tv_nsec > 1000000 )
-                       nanosleep( &slow, NULL );
+               ftime( &render );
+               if ( mlt_properties_get( mlt_frame_properties( frame ), "rendered" ) == NULL )
+                       this->time_taken = ( ( int64_t )render.time * 1000 + render.millitm ) - ( ( int64_t )before.time * 1000 + before.millitm );
 
                // Handle events
                if ( this->sdl_screen != NULL )
@@ -504,6 +514,33 @@ static int consumer_play_video( consumer_sdl this, mlt_frame frame, int64_t elap
        if ( frame != NULL )
                mlt_frame_close( frame );
 
+       struct timeb after;
+       ftime( &after );
+       int processing = ( ( int64_t )after.time * 1000 + after.millitm ) - ( ( int64_t )render.time * 1000 + render.millitm );
+       int delay = playtime - elapsed - processing;
+
+       if ( delay > this->time_taken && mlt_deque_count( this->queue ) )
+       {
+               mlt_frame next = mlt_deque_peek_front( this->queue );
+               playtime = mlt_properties_get_position( mlt_frame_properties( next ), "playtime" );
+               if ( playtime > elapsed + delay )
+               {
+                       struct timeb render;
+                       mlt_frame_get_image( next, &image, &vfmt, &width, &height, 0 );
+                       ftime( &render );
+                       this->time_taken = ( ( int64_t )render.time * 1000 + render.millitm ) - ( ( int64_t )after.time * 1000 + after.millitm );
+                       mlt_properties_set( mlt_frame_properties( next ), "rendered", "true" );
+               }
+               else
+               {
+                       this->time_taken /= 2;
+               }
+       }
+       else
+       {
+               this->time_taken /= 2;
+       }
+
        return 0;
 }
 
index 437d9f4c159f3adb8d298f74bd26b1e8c0009721..7f2048f8c84bf3c81cba11c8e3dd25b929149bf0 100644 (file)
@@ -233,7 +233,7 @@ static void serialise_service( serialise_context context, mlt_service service, x
                                                                char length[ 20 ];
                                                                length[ 19 ] = '\0';
                                                                xmlNode *entry = xmlNewChild( child, NULL, "blank", NULL );
-                                                               snprintf( length, 19, "%lld", info.frame_count );
+                                                               snprintf( length, 19, "%d", info.frame_count );
                                                                xmlNewProp( entry, "length", length );
                                                        }
                                                        else