C++:使用 Blackmagic DeckLink SDK 读取访问冲突this-> x was nullptr

问题描述

我根据 Blackmagic Decklink SDK 编写了一个小程序。当我使用 DeckLinkInput 接口时,我收到读取访问冲突消息“this->dl_input was nulltr”。 经过数小时的调试,我不知道如何解决这个问题。也许一个问题是我是 C++ 的新手。 我写了以下代码:

class ControlVideo {
    
public:
    HRESULT result;
    
    IDeckLink *deckLink = nullptr;
    IDeckLinkInput *dl_input = nullptr;
    IDeckLinkInputCallback *theCallback = nullptr;
    IDeckLinkDisplayMode *dl_displayMode = nullptr;
    IDeckLinkDisplayModeIterator* dl_displayModeIterator = nullptr;
            
    bool inputCallback(IDeckLinkInput* dl_input);
    bool startCapture();
};
    
/**
 * Function that initializes the input callback
 * The callback will be called for each incoming frame
 */
bool ControlVideo::inputCallback(IDeckLinkInput *dl_input) {
        
    if (dl_input == nullptr) {
        std::cout << "DECKLINK INPUT IS NULLPOINTER.";
    }
    else {
        if (dl_input->SetCallback(theCallback) == S_OK) {
            std::cout << "Input Callback called. \n";
            return true;
        }
        else {
            std::cout << "DeckLink Callback fails. \n";
            return false;
        }
    }
} 
    
/**
 * Function that start the stream
 */
bool ControlVideo::startCapture() {
    
    ControlVideo ctrlVideo;
    
    //make a callback for each incoming frame
    ctrlVideo.inputCallback(dl_input);
    
    if (dl_input->StartStreams() == S_OK) {
        std::cout << "Stream has been started. \n";
        return true;
    }
    else {
        throw std::runtime_error("Error: Stream can not been started. \n");
        return false;
    }
}
    
    
int main() {
    //Create object and initialize the DeckLink
    InitializeDecklink init;
    init.initializeDevice();
    init.printDevice();
    
    ControlVideo ctrlVideo;
    ctrlVideo.startCapture();
        
    return 0;
}

谁能告诉我我做错了什么?谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)