]> git.sesse.net Git - mlt/blobdiff - src/modules/decklink/consumer_decklink.cpp
Notify dropped frame in decklink.
[mlt] / src / modules / decklink / consumer_decklink.cpp
index 02c326829dee6bfdcaae6c92a535019f4b44829e..1d3eaab7e55c8be7bfede501e2c2cbbe3488dfe4 100644 (file)
 #include <unistd.h>
 #include <sys/time.h>
 #include <limits.h>
+#ifdef WIN32
+#include <objbase.h>
+#include "DeckLinkAPI_h.h"
+#else
 #include "DeckLinkAPI.h"
+#endif
 
 static const unsigned PREROLL_MINIMUM = 3;
 
@@ -93,14 +98,30 @@ public:
        
        bool open( unsigned card = 0 )
        {
-               IDeckLinkIterator* deckLinkIterator = CreateDeckLinkIteratorInstance();
                unsigned i = 0;
+#ifdef WIN32
+               IDeckLinkIterator* deckLinkIterator = NULL;
+               HRESULT result =  CoInitialize( NULL );
+               if ( FAILED( result ) )
+               {
+                       mlt_log_error( getConsumer(), "COM initialization failed\n" );
+                       return false;
+               }
+               result = CoCreateInstance( CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**) &deckLinkIterator );
+               if ( FAILED( result ) )
+               {
+                       mlt_log_error( getConsumer(), "The DeckLink drivers not installed.\n" );
+                       return false;
+               }
+#else
+               IDeckLinkIterator* deckLinkIterator = CreateDeckLinkIteratorInstance();
                
                if ( !deckLinkIterator )
                {
                        mlt_log_error( getConsumer(), "The DeckLink drivers not installed.\n" );
                        return false;
                }
+#endif
                
                // Connect to the Nth DeckLink instance
                do {
@@ -127,7 +148,11 @@ public:
                m_deckLinkKeyer = 0;
                if ( m_deckLink->QueryInterface( IID_IDeckLinkAttributes, (void**) &deckLinkAttributes ) == S_OK )
                {
+#ifdef WIN32
+                       BOOL flag = FALSE;
+#else
                        bool flag = false;
+#endif
                        if ( deckLinkAttributes->GetFlag( BMDDeckLinkSupportsInternalKeying, &flag ) == S_OK && flag )
                        {
                                if ( m_deckLink->QueryInterface( IID_IDeckLinkKeyer, (void**) &m_deckLinkKeyer ) != S_OK )
@@ -255,11 +280,16 @@ public:
                if ( !mlt_frame_get_audio( frame, (void**) &pcm, &format, &frequency, &m_channels, &samples ) )
                {
                        uint32_t written = 0;
+                       BMDTimeValue streamTime = m_count * frequency * m_duration / m_timescale;
 
-                       m_deckLinkOutput->ScheduleAudioSamples( pcm, samples, m_count * frequency / m_fps, frequency, &written );
+#ifdef WIN32
+                       m_deckLinkOutput->ScheduleAudioSamples( pcm, samples, streamTime, frequency, (unsigned long*) &written );
+#else
+                       m_deckLinkOutput->ScheduleAudioSamples( pcm, samples, streamTime, frequency, &written );
+#endif
 
-                       if ( written != samples )
-                               mlt_log_verbose( getConsumer(), "renderAudio: samples=%d, written=%d\n", samples, written );
+                       if ( written != (uint32_t) samples )
+                               mlt_log_verbose( getConsumer(), "renderAudio: samples=%d, written=%u\n", samples, written );
                }
        }
 
@@ -325,9 +355,9 @@ public:
                                        // Normal non-keyer playout - needs byte swapping
                                        if ( !progressive && m_displayMode->GetFieldDominance() == bmdUpperFieldFirst )
                                                // convert lower field first to top field first
-                                               swab( image, buffer + stride, stride * ( m_height - 1 ) );
+                                               swab( (char*) image, (char*) buffer + stride, stride * ( m_height - 1 ) );
                                        else
-                                               swab( image, buffer, stride * m_height );
+                                               swab( (char*) image, (char*) buffer, stride * m_height );
                                }
                                else if ( !mlt_properties_get_int( MLT_FRAME_PROPERTIES( frame ), "test_image" ) )
                                {
@@ -414,6 +444,11 @@ public:
                        mlt_log_verbose( getConsumer(), "ScheduledFrameCompleted: bmdOutputFrameDisplayedLate == completed\n");
                        m_count++;
                }
+               if(bmdOutputFrameDropped == completed)
+               {
+                       mlt_log_verbose( getConsumer(), "ScheduledFrameCompleted: bmdOutputFrameDropped == completed\n");
+                       m_count++;
+               }
 
                return S_OK;
        }