]> git.sesse.net Git - mlt/commitdiff
Make decklink mlt_consumer_start more asynchronous.
authorDan Dennedy <dan@dennedy.org>
Fri, 11 Nov 2011 03:35:29 +0000 (19:35 -0800)
committerDan Dennedy <dan@dennedy.org>
Sat, 12 Nov 2011 20:07:39 +0000 (12:07 -0800)
This puts preroll into a thread to make it more asynchronous - a problem
noticed with multi consumer.

src/modules/decklink/consumer_decklink.cpp

index bbb0e4e06472c52f3028a8c92352f708c5a43f0b..fd41046d9d1a4ff0142f059be4311f576d44b2e5 100644 (file)
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 #include <limits.h>
+#include <pthread.h>
 #ifdef WIN32
 #include <objbase.h>
 #include "DeckLinkAPI_h.h"
@@ -58,6 +59,7 @@ private:
        uint32_t                    m_preroll;
        uint32_t                    m_acnt;
        bool                        m_reprio;
+       pthread_t                   m_prerollThread;
 
        IDeckLinkDisplayMode* getDisplayMode()
        {
@@ -178,10 +180,28 @@ public:
                
                return true;
        }
-       
+
+
+       void* preroll_thread()
+       {
+               // preroll frames
+               for ( unsigned i = 0; i < m_preroll; i++ )
+                       ScheduleNextFrame( true );
+
+               // start scheduled playback
+               m_deckLinkOutput->StartScheduledPlayback( 0, m_timescale, 1.0 );
+
+               return 0;
+       }
+
+       static void* preroll_thread_proxy( void* arg )
+       {
+               DeckLinkConsumer* self = static_cast< DeckLinkConsumer* >( arg );
+               return self->preroll_thread();
+       }
+
        bool start( unsigned preroll )
        {
-               unsigned i;
                mlt_properties properties = MLT_CONSUMER_PROPERTIES( getConsumer() );
 
                // Initialize members
@@ -241,12 +261,8 @@ public:
                m_preroll = preroll;
                m_reprio = false;
 
-               // preroll frames
-               for( i = 0; i < preroll; i++ )
-                       ScheduleNextFrame( true );
-
-               // start scheduled playback
-               m_deckLinkOutput->StartScheduledPlayback( 0, m_timescale, 1.0 );
+               // Do preroll in thread to ensure asynchronicity of mlt_consumer_start().
+               pthread_create( &m_prerollThread, NULL, preroll_thread_proxy, this );
 
                // Set the running state
                mlt_properties_set_int( properties, "running", 1 );
@@ -275,6 +291,10 @@ public:
                        m_deckLinkOutput->DisableVideoOutput();
                }
 
+               if ( m_prerollThread )
+                       pthread_join( m_prerollThread, NULL );
+               m_prerollThread = 0;
+
                return true;
        }