Initialize a DeckLink Device with DeckLinkIterator

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

makoe29

  • Posts: 16
  • Joined: Wed Apr 14, 2021 11:53 am
  • Real Name: Marco Könemann

Initialize a DeckLink Device with DeckLinkIterator

PostMon May 24, 2021 12:44 pm

Hello everybody,

this is my first time using the DeckLink SDK and I have a question about the DeckLink Itertor. For my understanding the DeckLink iterator have to be called at the beginning of the program. I had written a few lines of code. Normally, I should get an error message when no device is connected, but my program returns in every situation (device connected - no device connected) 0.

Code: Select all
/**
* Main class
*/
class StartProgram {
public:
   int initializeDeckLink();
};


/**
* Main entry point to the DeckLink API.
* Accesses a available DeckLink device.
*/
int StartProgram::initializeDeckLink() {

   HRESULT result;

   IDeckLinkIterator* deckLinkIterator = NULL;

   //initialize COM is necessary
   result = CoInitialize(NULL);

   if (FAILED(result)) {
      throw runtime_error("COM can't be initialized.");
   }


   //enumerate all DeckLink Devices
   result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&deckLinkIterator);

   if (FAILED(result)) {
      throw runtime_error("No DeckLink Device found.");
   }
}

int main() {
   //Create VideoMeter object and initialize the DeckLink
   StartProgram start;
   start.initializeDeckLink();
   return 0;
}

What i'am doing wrong. I read the documentation and some post here, but that doesn't help me.

Kind regards,
Marco
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: Initialize a DeckLink Device with DeckLinkIterator

PostTue Jun 08, 2021 12:50 am

Hi Marco,

Thanks for providing the code segment. The runtime_error will only occur when the Desktop Video software is not installed (when CLSID_CDeckLinkIterator is not registered). To check whether a device is connected, you need to call IDeckLinkIterator::Next() to iterate through connected devices:
Code: Select all
// Add to initializeDeckLink
IDeckLink* deckLink = nullptr;
result = deckLinkIterator->Next(&deckLink);

if (result == S_OK)
{
    // Device connected, deckLink is valid
}
else if (result == S_FALSE)
{
    // No (more) devices connected
}

// Ensure that you release deckLinkIterator
deckLinkIterator->Release();
deckLinkIterator = nullptr;

If you have multiple devices connected, then you can call IDeckLinkIterator::Next within a while loop to iterate each IDeckLink object.

Regards
Cameron
Offline

makoe29

  • Posts: 16
  • Joined: Wed Apr 14, 2021 11:53 am
  • Real Name: Marco Könemann

Re: Initialize a DeckLink Device with DeckLinkIterator

PostWed Jun 16, 2021 12:59 pm

Hi Cameron,

thanks for your advices. I finish the initializition some days after my post and it works like you describe it.

kind regards
Marco

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 16 guests