-1

我根据 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;
}

有人可以告诉我我做错了什么吗?谢谢你。

4

1 回答 1

0

这个函数对我来说似乎是错误的,并返回一个可能错误的 bool 值:

在第一个 if 子句中,没有返回,我会说应该返回 false。此外,这dl_input永远不会更新,因此始终是 nullptr。

/**
 * 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.";
        return false; // this is missing
    }
    if (dl_input->SetCallback(theCallback) == S_OK) {
         std::cout << "Input Callback called. \n";
         return true;
    }
    std::cout << "DeckLink Callback fails. \n";
    return false;
} 

此外,如果您在“if”部分本身返回,则不需要编写 if-else,因为您要么从 if 返回,要么执行“else”部分。没有其他可能

于 2021-06-16T12:37:37.913 回答