我正在尝试使用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 ++ QueryInterface:
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库here。