]> git.sesse.net Git - mlt/commitdiff
fix decklink producer dropping frames after few hours
authorDan Dennedy <dan@dennedy.org>
Wed, 30 May 2012 03:40:11 +0000 (20:40 -0700)
committerDan Dennedy <dan@dennedy.org>
Wed, 30 May 2012 03:40:11 +0000 (20:40 -0700)
mlt_cache_put() was not scalable when using position as a key into the
cache. Its reliance upon mlt_properties for reference-counting cache
items caused its hash tabe to grow too large after a few hundred
thousand frames. This version uses the new mlt_cache_put_frame, which is
simpler and more scalable by only using the cache arrays and copying
data.

src/modules/decklink/producer_decklink.cpp

index 3ae216c290a6b8b3fac0c087d063ac66c887ad67..b535b8c8a4340e0b626160c57c95dad56b5b7ddd 100644 (file)
@@ -254,12 +254,11 @@ public:
 
        mlt_frame getFrame()
        {
-               mlt_frame frame = NULL;
                struct timeval now;
                struct timespec tm;
                double fps = mlt_producer_get_fps( getProducer() );
                mlt_position position = mlt_producer_position( getProducer() );
-               mlt_cache_item cached = mlt_cache_get( m_cache, (void*) position );
+               mlt_frame frame = mlt_cache_get_frame( m_cache, position );
 
                // Allow the buffer to fill to the requested initial buffer level.
                if ( m_isBuffering )
@@ -284,13 +283,7 @@ public:
                        pthread_mutex_unlock( &m_mutex );
                }
 
-               if ( cached )
-               {
-                       // Copy cached frame instead of pulling from queue
-                       frame = mlt_frame_clone( (mlt_frame) mlt_cache_item_data( cached, NULL ), 0 );
-                       mlt_cache_item_close( cached );
-               }
-               else
+               if ( !frame )
                {
                        // Wait if queue is empty
                        pthread_mutex_lock( &m_mutex );
@@ -311,8 +304,10 @@ public:
 
                        // add to cache
                        if ( frame )
-                               mlt_cache_put( m_cache, (void*) position, mlt_frame_clone( frame, 1 ), 0,
-                                       (mlt_destructor) mlt_frame_close );
+                       {
+                               mlt_frame_set_position( frame, position );
+                               mlt_cache_put_frame( m_cache, frame );
+                       }
                }
 
                // Set frame timestamp and properties
@@ -601,7 +596,6 @@ static int get_frame( mlt_producer producer, mlt_frame_ptr frame, int index )
                *frame = mlt_frame_init( MLT_PRODUCER_SERVICE(producer) );
 
        // Calculate the next timecode
-       mlt_frame_set_position( *frame, mlt_producer_position( producer ) );
        mlt_producer_prepare_next( producer );
 
        // Close DeckLink if at end