]> git.sesse.net Git - mlt/commitdiff
enumerate DeckLink devices when list_devices property is set
authorDan Dennedy <dan@dennedy.org>
Tue, 20 Mar 2012 04:43:06 +0000 (21:43 -0700)
committerDan Dennedy <dan@dennedy.org>
Tue, 20 Mar 2012 04:43:06 +0000 (21:43 -0700)
src/modules/decklink/consumer_decklink.cpp
src/modules/decklink/producer_decklink.cpp

index 288e52f2a3ea8e0f4bec4b65f6c7027ca6b13cc5..5fa468da937633815fb4126b31cdd84869830014 100644 (file)
@@ -114,58 +114,6 @@ public:
                SAFE_RELEASE( m_deckLink );
        }
        
-       bool listDevices( mlt_properties properties )
-       {
-               IDeckLinkIterator* decklinkIterator = NULL;
-               try
-               {
-                       int i = 0;
-#ifdef WIN32
-                       HRESULT result =  CoInitialize( NULL );
-                       if ( FAILED( result ) )
-                               throw "COM initialization failed";
-                       result = CoCreateInstance( CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**) &decklinkIterator );
-                       if ( FAILED( result ) )
-                               throw "The DeckLink drivers are not installed.";
-#else
-                       decklinkIterator = CreateDeckLinkIteratorInstance();
-                       if ( !decklinkIterator )
-                               throw "The DeckLink drivers are not installed.";
-#endif
-                       for ( ; decklinkIterator->Next( &m_deckLink ) == S_OK; i++ )
-                       {
-                               if ( m_deckLink->QueryInterface( IID_IDeckLinkOutput, (void**) &m_deckLinkOutput ) == S_OK )
-                               {
-                                       char *name = NULL;
-                                       if ( m_deckLink->GetModelName( (const char**) &name ) == S_OK )
-                                       {
-                                               const char *format = "device.%d";
-                                               char *key = (char*) calloc( 1, strlen( format ) + 1 );
-
-                                               sprintf( key, format, i );
-                                               mlt_properties_set( properties, key, name );
-                                               mlt_log_verbose( NULL, "[consumer decklink] %s = %s\n", key, name );
-                                               free( key );
-                                               free( name );
-                                       }
-                                       SAFE_RELEASE( m_deckLinkOutput );
-                               }
-                               SAFE_RELEASE( m_deckLink );
-                       }
-                       SAFE_RELEASE( decklinkIterator );
-                       mlt_properties_set_int( properties, "devices", i );
-                       mlt_log_verbose( NULL, "[consumer decklink] devices = %d\n", i );
-
-                       return true;
-               }
-               catch ( const char *error )
-               {
-                       SAFE_RELEASE( decklinkIterator );
-                       mlt_log_error( getConsumer(), "%s\n", error );
-                       return false;
-               }
-       }
-
        bool open( unsigned card = 0 )
        {
                unsigned i = 0;
@@ -703,6 +651,51 @@ static void close( mlt_consumer consumer )
 
 extern "C" {
 
+// Listen for the list_devices property to be set
+static void on_property_changed( void*, mlt_properties properties, const char *name )
+{
+       IDeckLinkIterator* decklinkIterator = NULL;
+       IDeckLink* decklink = NULL;
+       IDeckLinkInput* decklinkOutput = NULL;
+       int i = 0;
+
+       if ( name && !strcmp( name, "list_devices" ) )
+               mlt_event_block( (mlt_event) mlt_properties_get_data( properties, "list-devices-event", NULL ) );
+       else
+               return;
+
+#ifdef WIN32
+       if ( FAILED( CoInitialize( NULL ) ) )
+               return;
+       if ( FAILED( CoCreateInstance( CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**) &decklinkIterator ) ) )
+               return;
+#else
+       if ( !( decklinkIterator = CreateDeckLinkIteratorInstance() ) )
+               return;
+#endif
+       for ( ; decklinkIterator->Next( &decklink ) == S_OK; i++ )
+       {
+               if ( decklink->QueryInterface( IID_IDeckLinkOutput, (void**) &decklinkOutput ) == S_OK )
+               {
+                       char *name = NULL;
+                       if ( decklink->GetModelName( (const char**) &name ) == S_OK )
+                       {
+                               const char *format = "device.%d";
+                               char *key = (char*) calloc( 1, strlen( format ) + 1 );
+
+                               sprintf( key, format, i );
+                               mlt_properties_set( properties, key, name );
+                               free( key );
+                               free( name );
+                       }
+                       SAFE_RELEASE( decklinkOutput );
+               }
+               SAFE_RELEASE( decklink );
+       }
+       SAFE_RELEASE( decklinkIterator );
+       mlt_properties_set_int( properties, "devices", i );
+}
+
 /** Initialise the consumer.
  */
 
@@ -716,17 +709,20 @@ mlt_consumer consumer_decklink_init( mlt_profile profile, mlt_service_type type,
        if ( decklink && !mlt_consumer_init( decklink->getConsumer(), decklink, profile ) )
        {
                // If initialises without error
-               if ( decklink->listDevices( MLT_CONSUMER_PROPERTIES( decklink->getConsumer() ) ) &&
-                        decklink->open( arg? atoi(arg) : 0 ) )
+               if ( decklink->open( arg? atoi(arg) : 0 ) )
                {
                        consumer = decklink->getConsumer();
-                       
+                       mlt_properties properties = MLT_CONSUMER_PROPERTIES( consumer );
+
                        // Setup callbacks
                        consumer->close = close;
                        consumer->start = start;
                        consumer->stop = stop;
                        consumer->is_stopped = is_stopped;
-                       mlt_properties_set( MLT_CONSUMER_PROPERTIES(consumer), "deinterlace_method", "onefield" );
+                       mlt_properties_set( properties, "deinterlace_method", "onefield" );
+
+                       mlt_event event = mlt_events_listen( properties, properties, "property-changed", (mlt_listener) on_property_changed );
+                       mlt_properties_set_data( properties, "list-devices-event", event, 0, NULL, NULL );
                }
        }
 
index 93489091d8dc46955eceaf8ed8e727b3f4150e85..5682a713b58dd3458d9d0c6e7b1350c5cf9a05d5 100644 (file)
@@ -112,55 +112,6 @@ public:
                SAFE_RELEASE( m_decklink );
        }
 
-       bool listDevices( mlt_properties properties )
-       {
-               IDeckLinkIterator* decklinkIterator = NULL;
-               try
-               {
-                       int i = 0;
-#ifdef WIN32
-                       HRESULT result =  CoInitialize( NULL );
-                       if ( FAILED( result ) )
-                               throw "COM initialization failed";
-                       result = CoCreateInstance( CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**) &decklinkIterator );
-                       if ( FAILED( result ) )
-                               throw "The DeckLink drivers are not installed.";
-#else
-                       decklinkIterator = CreateDeckLinkIteratorInstance();
-                       if ( !decklinkIterator )
-                               throw "The DeckLink drivers are not installed.";
-#endif
-                       for ( ; decklinkIterator->Next( &m_decklink ) == S_OK; i++ )
-                       {
-                               if ( m_decklink->QueryInterface( IID_IDeckLinkInput, (void**) &m_decklinkInput ) == S_OK )
-                               {
-                                       char *name = NULL;
-                                       if ( m_decklink->GetModelName( (const char**) &name ) == S_OK )
-                                       {
-                                               const char *format = "device.%d";
-                                               char *key = (char*) calloc( 1, strlen( format ) + 1 );
-
-                                               sprintf( key, format, i );
-                                               mlt_properties_set( properties, key, name );
-                                               free( key );
-                                               free( name );
-                                       }
-                                       SAFE_RELEASE( m_decklinkInput );
-                               }
-                               SAFE_RELEASE( m_decklink );
-                       }
-                       SAFE_RELEASE( decklinkIterator );
-                       mlt_properties_set_int( properties, "devices", i );
-                       return true;
-               }
-               catch ( const char *error )
-               {
-                       SAFE_RELEASE( decklinkIterator );
-                       mlt_log_error( getProducer(), "%s\n", error );
-                       return false;
-               }
-       }
-
        bool open( unsigned card =  0 )
        {
                IDeckLinkIterator* decklinkIterator = NULL;
@@ -178,7 +129,6 @@ public:
                        if ( !decklinkIterator )
                                throw "The DeckLink drivers are not installed.";
 #endif
-
                        // Connect to the Nth DeckLink instance
                        for ( unsigned i = 0; decklinkIterator->Next( &m_decklink ) == S_OK ; i++)
                        {
@@ -682,6 +632,51 @@ static void producer_close( mlt_producer producer )
 
 extern "C" {
 
+// Listen for the list_devices property to be set
+static void on_property_changed( void*, mlt_properties properties, const char *name )
+{
+       IDeckLinkIterator* decklinkIterator = NULL;
+       IDeckLink* decklink = NULL;
+       IDeckLinkInput* decklinkInput = NULL;
+       int i = 0;
+
+       if ( name && !strcmp( name, "list_devices" ) )
+               mlt_event_block( (mlt_event) mlt_properties_get_data( properties, "list-devices-event", NULL ) );
+       else
+               return;
+
+#ifdef WIN32
+       if ( FAILED( CoInitialize( NULL ) ) )
+               return;
+       if ( FAILED( CoCreateInstance( CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**) &decklinkIterator ) ) )
+               return;
+#else
+       if ( !( decklinkIterator = CreateDeckLinkIteratorInstance() ) )
+               return;
+#endif
+       for ( ; decklinkIterator->Next( &decklink ) == S_OK; i++ )
+       {
+               if ( decklink->QueryInterface( IID_IDeckLinkInput, (void**) &decklinkInput ) == S_OK )
+               {
+                       char *name = NULL;
+                       if ( decklink->GetModelName( (const char**) &name ) == S_OK )
+                       {
+                               const char *format = "device.%d";
+                               char *key = (char*) calloc( 1, strlen( format ) + 1 );
+
+                               sprintf( key, format, i );
+                               mlt_properties_set( properties, key, name );
+                               free( key );
+                               free( name );
+                       }
+                       SAFE_RELEASE( decklinkInput );
+               }
+               SAFE_RELEASE( decklink );
+       }
+       SAFE_RELEASE( decklinkIterator );
+       mlt_properties_set_int( properties, "devices", i );
+}
+
 /** Initialise the producer.
  */
 
@@ -694,8 +689,7 @@ mlt_producer producer_decklink_init( mlt_profile profile, mlt_service_type type,
        // If allocated and initializes
        if ( decklink && !mlt_producer_init( producer, decklink ) )
        {
-               if ( decklink->listDevices( MLT_PRODUCER_PROPERTIES( producer ) ) &&
-                        decklink->open( arg? atoi( arg ) : 0 ) )
+               if ( decklink->open( arg? atoi( arg ) : 0 ) )
                {
                        mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
 
@@ -717,6 +711,9 @@ mlt_producer producer_decklink_init( mlt_profile profile, mlt_service_type type,
                        mlt_properties_set_int( properties, "length", INT_MAX );
                        mlt_properties_set_int( properties, "out", INT_MAX - 1 );
                        mlt_properties_set( properties, "eof", "loop" );
+
+                       mlt_event event = mlt_events_listen( properties, properties, "property-changed", (mlt_listener) on_property_changed );
+                       mlt_properties_set_data( properties, "list-devices-event", event, 0, NULL, NULL );
                }
        }