我正在尝试使用DeckLink.net dll 在 C# 中重新创建来自 Blackmagic Design 的 DeckLink SDK 的 StreamingPreview 示例。
当我运行下面的代码时,它似乎工作:通知已安装,我什至收到设备到达事件(我也可以查询设备的属性)但我得到一个AccessViolationException。它必须连接到 streamingDiscovery.InstallDeviceNotifications() 行,并且只有在我实际插入设备并因此收到通知时才能得到它。
你能帮帮我吗?
我的 C# 代码:
class DeckLink : IBMDStreamingDeviceNotificationCallback
{
// Native values
private static int S_OK = 0;
private static int E_FAIL = 1;
int result;
private IBMDStreamingDiscovery streamingDiscovery;
public DeckLink()
{
try
{
streamingDiscovery = (IBMDStreamingDiscovery)new StreamingDiscovery();
}
catch (Exception)
{
Console.WriteLine("This application requires the Blackmagic Streaming drivers installed.\nPlease install the Blackmagic Streaming drivers to use the features of this application.");
goto bail;
}
result = streamingDiscovery.InstallDeviceNotifications(this);
if (result == E_FAIL)
{
Console.WriteLine("Failed to install device notifications for the Blackmagic Streaming devices");
goto bail;
}
Console.WriteLine("Device notifications for the Blackmagic Streaming devices were successfully installed");
return;
bail:
if (streamingDiscovery != null)
{
streamingDiscovery = null;
}
return;
}
public int StreamingDeviceArrived(Blackmagic.DeckLink.IDeckLink device)
{
Console.WriteLine("Device arrived");
return S_OK;
}
public int StreamingDeviceModeChanged(Blackmagic.DeckLink.IDeckLink device, Blackmagic.DeckLink.BMDStreamingDeviceMode mode)
{
throw new NotImplementedException();
}
public int StreamingDeviceRemoved(Blackmagic.DeckLink.IDeckLink device)
{
throw new NotImplementedException();
}
}
这些来自 SDK 的 C++ 示例:
result = CoCreateInstance(CLSID_CBMDStreamingDiscovery, NULL, CLSCTX_ALL, IID_IBMDStreamingDiscovery, (void**)&m_streamingDiscovery);
if (FAILED(result))
{
MessageBox(_T("This application requires the Blackmagic Streaming drivers installed.\nPlease install the Blackmagic Streaming drivers to use the features of this application."), _T("Error"));
goto bail;
}
// Note: at this point you may get device notification messages!
result = m_streamingDiscovery->InstallDeviceNotifications(this);
if (FAILED(result))
{
MessageBox(_T("Failed to install device notifications for the Blackmagic Streaming devices"), _T("Error"));
goto bail;
}
C++ 查询接口:
if (ppv == NULL)
return E_POINTER;
*ppv = NULL;
if (iid == IID_IUnknown)
{
*ppv = static_cast<IUnknown*>(static_cast<IBMDStreamingDeviceNotificationCallback*>(this));
AddRef();
result = S_OK;
}
else if (iid == IID_IBMDStreamingDeviceNotificationCallback)
{
*ppv = static_cast<IBMDStreamingDeviceNotificationCallback*>(this);
AddRef();
result = S_OK;
}
else if (iid == IID_IBMDStreamingH264InputCallback)
{
*ppv = static_cast<IBMDStreamingH264InputCallback*>(this);
AddRef();
result = S_OK;
}
return result;
我还在这里上传了 SDK 的示例和 dotNet 库。