]> git.sesse.net Git - mlt/commitdiff
enumerate available devices in decklink module
authorDan Dennedy <dan@dennedy.org>
Thu, 15 Mar 2012 05:28:50 +0000 (22:28 -0700)
committerDan Dennedy <dan@dennedy.org>
Thu, 15 Mar 2012 05:28:50 +0000 (22:28 -0700)
src/modules/decklink/consumer_decklink.cpp
src/modules/decklink/consumer_decklink.yml
src/modules/decklink/producer_decklink.cpp
src/modules/decklink/producer_decklink.yml

index 39c251f238ef544c7f29870bd8fed5eadba34465..8645506b95e26df6f8e8e502067b15fbe7994d8c 100644 (file)
@@ -103,6 +103,59 @@ public:
                        m_deckLink->Release();
        }
        
+       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 );
+                                       }
+                                       m_deckLinkOutput->Release();
+                               }
+                               m_deckLink->Release();
+                       }
+                       decklinkIterator->Release();
+                       mlt_properties_set_int( properties, "devices", i );
+                       mlt_log_verbose( NULL, "[consumer decklink] devices = %d\n", i );
+
+                       return true;
+               }
+               catch ( const char *error )
+               {
+                       if ( decklinkIterator )
+                               decklinkIterator->Release();
+                       mlt_log_error( getConsumer(), "%s\n", error );
+                       return false;
+               }
+       }
+
        bool open( unsigned card = 0 )
        {
                unsigned i = 0;
@@ -656,7 +709,8 @@ 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->open( arg? atoi(arg) : 0 ) )
+               if ( decklink->listDevices( MLT_CONSUMER_PROPERTIES( decklink->getConsumer() ) ) &&
+                        decklink->open( arg? atoi(arg) : 0 ) )
                {
                        consumer = decklink->getConsumer();
                        
index 92c24c92b4dfa79af1017bfa3914082102d46c06..513236be522a346534d9b19b0ac5a3cf9f3113a0 100644 (file)
@@ -79,3 +79,15 @@ parameters:
     maximum: 1
     default: 1
     widget: slider
+
+  - identifier: devices
+    title: Number of devices
+    type: integer
+    readonly: yes
+    minimum: 0
+
+  - identifier: device.*
+    title: Device model
+    description: The model name of each device that provides output.
+    type: string
+    readonly: yes
index 77ed44b2b864ecb2cea777b0b1fe74e4de93d20e..b3a3c8a818e8787af4a8d56242239b90613bc13d 100644 (file)
@@ -104,6 +104,56 @@ public:
                        m_decklink->Release();
        }
 
+       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 );
+                                       }
+                                       m_decklinkInput->Release();
+                               }
+                               m_decklink->Release();
+                       }
+                       decklinkIterator->Release();
+                       mlt_properties_set_int( properties, "devices", i );
+                       return true;
+               }
+               catch ( const char *error )
+               {
+                       if ( decklinkIterator )
+                               decklinkIterator->Release();
+                       mlt_log_error( getProducer(), "%s\n", error );
+                       return false;
+               }
+       }
+
        bool open( unsigned card =  0 )
        {
                IDeckLinkIterator* decklinkIterator = NULL;
@@ -633,7 +683,8 @@ 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->open( arg? atoi( arg ) : 0 ) )
+               if ( decklink->listDevices( MLT_PRODUCER_PROPERTIES( producer ) ) &&
+                        decklink->open( arg? atoi( arg ) : 0 ) )
                {
                        mlt_properties properties = MLT_PRODUCER_PROPERTIES( producer );
 
index bc8fa63de9afb49434ad0ed5f2b329fd261bfec8..6cea8851f41404bff01f6feaf8bc09e682619c6f 100644 (file)
@@ -84,3 +84,15 @@ parameters:
     maximum: 1
     default: 0
     widget: checkbox
+
+  - identifier: devices
+    title: Number of devices
+    type: integer
+    readonly: yes
+    minimum: 0
+
+  - identifier: device.*
+    title: Device model
+    description: The model name of each device that accepts input.
+    type: string
+    readonly: yes