Page 1 of 1

EnableVideoInput systematically fails

PostPosted: Wed Dec 20, 2017 3:34 pm
by Ali Mouizina
hi everyone,

I have an intensity shuttle USB 3.0 and Intensity Pro 4K. I am using the SDK in one of my project. I followed the sample code provided in the SDK but I have a failure for EnableVideoInput with the error code E_FAIL.

When I reboot the computer, the code sometimes works. The two devices are not plugged at the same time.

Here is the code for the device initialization, do you see anything wrong ?

Code: Select all
 HRESULT                  result;
    // Initialize COM on this thread
    result = CoInitialize(NULL);
    if (FAILED(result))
    {
        Ktc::LogError("{},{}: Initialization of COM failed - result = {}.\n", __FUNCTION__, __LINE__, result);
        return 1;
    }

    // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
    result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&deckLinkIterator);
    if (FAILED(result))
    {
        Ktc::LogError("{},{}: A DeckLink iterator could not be created.  The DeckLink drivers may not be installed. {}", __FUNCTION__, __LINE__, result);
        return 1;
    }

    // We can get the version of the API like this:
    result = deckLinkIterator->QueryInterface(IID_IDeckLinkAPIInformation, (void**)&deckLinkAPIInformation);
    if (result == S_OK)
    {
        LONGLONG      deckLinkVersion;
        int            dlVerMajor, dlVerMinor, dlVerPoint;

        // We can also use the BMDDeckLinkAPIVersion flag with GetString
        deckLinkAPIInformation->GetInt(BMDDeckLinkAPIVersion, &deckLinkVersion);

        dlVerMajor = (deckLinkVersion & 0xFF000000) >> 24;
        dlVerMinor = (deckLinkVersion & 0x00FF0000) >> 16;
        dlVerPoint = (deckLinkVersion & 0x0000FF00) >> 8;

        deckLinkAPIInformation->Release();
    }

    if (deckLinkIterator->Next(&deckLink) == S_OK)
    {
        // Get input interface
        if (deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput) != S_OK)
            return false;

        // Check if input mode detection is supported.
        if (deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes) == S_OK)
        {
            if (deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &supportsFormatDetection) != S_OK)
                supportsFormatDetection = false;

            deckLinkAttributes->Release();
        }

        // Retrieve and cache mode list
        if (deckLinkInput->GetDisplayModeIterator(&displayModeIterator) == S_OK)
        {
            while (displayModeIterator->Next(&displayMode) == S_OK)
                modeList.push_back(displayMode);

            displayModeIterator->Release();
        }

        // Enable input video mode detection if the device supports it
        if (supportsFormatDetection == TRUE)
            videoInputFlags |= bmdVideoInputEnableFormatDetection;

        // Set capture callback
        deckLinkInput->SetCallback((IDeckLinkInputCallback *)dlCallback);

        // Set the video input mode
        HRESULT error_ = deckLinkInput->EnableVideoInput(bmdModeHD1080i50, bmdFormat8BitYUV, videoInputFlags);

        if (FAILED(error_)) {
          switch (error_) {
          case E_INVALIDARG:
            Ktc::LogError("{},{}: video mode invalid.", __FUNCTION__, __LINE__);
            break;
          case E_ACCESSDENIED:
            Ktc::LogError("{},{}: access denied.", __FUNCTION__, __LINE__);
            break;
          case E_OUTOFMEMORY:
            Ktc::LogError("{},{}: out of memory.", __FUNCTION__, __LINE__);
            break;
          default:
            Ktc::LogError("{},{}: unknown error {}", __FUNCTION__, __LINE__, error_);
          }
          return false;
        }

        // Start the capture
        if (deckLinkInput->StartStreams() != S_OK)
        {
            return false;
        }
    }

Re: EnableVideoInput systematically fails

PostPosted: Thu Dec 21, 2017 10:06 pm
by Cameron Nichols
Hi Ali,

I have reviewed and run through the code locally and it appears to run OK.

I suspect the card is remnant capture state and only resolved on reboot. When you terminate the application, are you properly stopping capture via IDeckLinkInput::StopStreams and IDeckLinkInput::DisableVideoInput commands (StopStreams at a minimum)?

Kind Regards
Cameron