]> git.sesse.net Git - mlt/blobdiff - src/framework/mlt_cache.c
Restrict auto-profile frame rate to a sane value.
[mlt] / src / framework / mlt_cache.c
index 5a158680f168d0c959e1ecc9fe21f19a2e93138e..0ab2456b177866ac6c177127dbb20d029f401630 100644 (file)
@@ -34,7 +34,7 @@
 #define MAX_CACHE_SIZE (200)
 
 /** the default number of data objects to cache per line */
-#define DEFAULT_CACHE_SIZE (10)
+#define DEFAULT_CACHE_SIZE (4)
 
 /** \brief Cache item class
  *
@@ -83,6 +83,7 @@ struct mlt_cache_s
 {
        int count;             /**< the number of items currently in the cache */
        int size;              /**< the maximum number of items permitted in the cache <= \p MAX_CACHE_SIZE */
+       int is_frames;         /**< indicates if this cache is used to cache frames */
        void* *current;        /**< pointer to the current array of pointers */
        void* A[ MAX_CACHE_SIZE ];
        void* B[ MAX_CACHE_SIZE ];
@@ -122,6 +123,13 @@ static void cache_object_close( mlt_cache cache, void *object, void* data )
 {
        char key[19];
 
+       if ( cache->is_frames )
+       {
+               // Frame caches are easy - just close the object as mlt_frame.
+               mlt_frame_close( object );
+               return;
+       }
+
        // Fetch the cache item from the active list by its owner's address
        sprintf( key, "%p", object );
        mlt_cache_item item = mlt_properties_get_data( cache->active, key, NULL );
@@ -448,8 +456,10 @@ mlt_cache_item mlt_cache_get( mlt_cache cache, void *object )
                sprintf( key, "%p", *hit );
                result = mlt_properties_get_data( cache->active, key, NULL );
                if ( result && result->data )
+               {
                        result->refcount++;
-               mlt_log( NULL, MLT_LOG_DEBUG, "%s: get %d = %p, %p\n", __FUNCTION__, cache->count - 1, *hit, result->data );
+                       mlt_log( NULL, MLT_LOG_DEBUG, "%s: get %d = %p, %p\n", __FUNCTION__, cache->count - 1, *hit, result->data );
+               }
 
                // swap the current array
                cache->current = alt;
@@ -480,7 +490,7 @@ static mlt_frame* shuffle_get_frame( mlt_cache cache, mlt_position position )
                while ( i-- && !hit )
                {
                        mlt_frame *o = (mlt_frame*) &cache->current[ i ];
-                       if ( mlt_frame_get_position( *o ) == position )
+                       if ( mlt_frame_original_position( *o ) == position )
                                hit = o;
                }
                // if there was no hit, we will not be shuffling out an entry
@@ -497,7 +507,7 @@ static mlt_frame* shuffle_get_frame( mlt_cache cache, mlt_position position )
        {
                mlt_frame *o = (mlt_frame*) &cache->current[ i ];
 
-               if ( !hit && mlt_frame_get_position( *o ) == position )
+               if ( !hit && mlt_frame_original_position( *o ) == position )
                {
                        hit = o;
                }
@@ -526,7 +536,7 @@ static mlt_frame* shuffle_get_frame( mlt_cache cache, mlt_position position )
 void mlt_cache_put_frame( mlt_cache cache, mlt_frame frame )
 {
        pthread_mutex_lock( &cache->mutex );
-       mlt_frame *hit = shuffle_get_frame( cache, mlt_frame_get_position( frame ) );
+       mlt_frame *hit = shuffle_get_frame( cache, mlt_frame_original_position( frame ) );
        mlt_frame *alt = (mlt_frame*) ( cache->current == cache->A ? cache->B : cache->A );
 
        // add the frame to the cache
@@ -555,6 +565,7 @@ void mlt_cache_put_frame( mlt_cache cache, mlt_frame frame )
 
        // swap the current array
        cache->current = (void**) alt;
+       cache->is_frames = 1;
        pthread_mutex_unlock( &cache->mutex );
 }