- Posts: 5
- Joined: Wed Oct 18, 2017 6:12 am
Hello
I am attempting to use the SDK from within C# for connecting and controlling the H264 pro recorder and have run into an issue. I have tried this with both the Decklink ActiveX control and by creating my own TLB/DLL by using MIDL on the DecklinkAPI.idl.
The problem is that a IDecklink object that arrives through the StreamingDeviceArrived event handler can be saved to a global variable for referencing elsewhere in the code but it throws a com exception when used/cast anywhere else outside the StreamingDeviceArrived function. Below is a quick and dirty code snippet
public partial class Form1 : Form, DeckLinkAPI.IBMDStreamingDeviceNotificationCallback, DeckLinkAPI.IBMDStreamingH264InputCallback
{
CBMDStreamingDiscovery m_streamingDiscovery; //BM Streaming Discovery Object
IDeckLink m_streamingDevice; //BM IDeckLink Object
IBMDStreamingDeviceInput m_streamingDeviceInput;
public Form1()
{
InitializeComponent();
m_streamingDiscovery = new BMDStreamingDiscovery();
m_streamingDiscovery.InstallDeviceNotifications(this);
...
}
//StreamingDeviceArrived Event Handler
public void StreamingDeviceArrived(IDeckLink device)
{
if (m_streamingDevice != null)
return;
m_streamingDevice = device;
m_streamingDeviceInput = (IBMDStreamingDeviceInput)m_streamingDevice;
m_streamingDeviceInput.SetCallback(this);
//m_streamingDeviceInput.StartCapture();
...
}
private void StartPreview()
{
string modelName;
m_streamingDevice.GetModelName(out modelName);
....
}
}
When the StreamDeviceArrived event handler triggers all seems fine, the other event handlers are implemented and fire also. The problem occurs when I call the StartPreview method (or any method that uses the global variable). As soon as the code hits the reference to m_streamingDevice it throws the attached (pic) InvalidCastException.
I'm banging my head against the wall on this one, I can start receiving Mpeg2TS packets in the Mpeg2TSPackarrived function if I un-comment out the StartCapture line in the StreamingDeviceArrived fucntion but the problem is that the IDecklink object cannot be stored globally for use/reference in any other function.
I have also provided functioning sample code to demonstrate this.
I am attempting to use the SDK from within C# for connecting and controlling the H264 pro recorder and have run into an issue. I have tried this with both the Decklink ActiveX control and by creating my own TLB/DLL by using MIDL on the DecklinkAPI.idl.
The problem is that a IDecklink object that arrives through the StreamingDeviceArrived event handler can be saved to a global variable for referencing elsewhere in the code but it throws a com exception when used/cast anywhere else outside the StreamingDeviceArrived function. Below is a quick and dirty code snippet
public partial class Form1 : Form, DeckLinkAPI.IBMDStreamingDeviceNotificationCallback, DeckLinkAPI.IBMDStreamingH264InputCallback
{
CBMDStreamingDiscovery m_streamingDiscovery; //BM Streaming Discovery Object
IDeckLink m_streamingDevice; //BM IDeckLink Object
IBMDStreamingDeviceInput m_streamingDeviceInput;
public Form1()
{
InitializeComponent();
m_streamingDiscovery = new BMDStreamingDiscovery();
m_streamingDiscovery.InstallDeviceNotifications(this);
...
}
//StreamingDeviceArrived Event Handler
public void StreamingDeviceArrived(IDeckLink device)
{
if (m_streamingDevice != null)
return;
m_streamingDevice = device;
m_streamingDeviceInput = (IBMDStreamingDeviceInput)m_streamingDevice;
m_streamingDeviceInput.SetCallback(this);
//m_streamingDeviceInput.StartCapture();
...
}
private void StartPreview()
{
string modelName;
m_streamingDevice.GetModelName(out modelName);
....
}
}
When the StreamDeviceArrived event handler triggers all seems fine, the other event handlers are implemented and fire also. The problem occurs when I call the StartPreview method (or any method that uses the global variable). As soon as the code hits the reference to m_streamingDevice it throws the attached (pic) InvalidCastException.
I'm banging my head against the wall on this one, I can start receiving Mpeg2TS packets in the Mpeg2TSPackarrived function if I un-comment out the StartCapture line in the StreamingDeviceArrived fucntion but the problem is that the IDecklink object cannot be stored globally for use/reference in any other function.
I have also provided functioning sample code to demonstrate this.
- Attachments
-
- WindowsFormsApplication1.zip
- Code Sample
- (88.88 KiB) Downloaded 262 times
-
- Error message
- error.png (10.35 KiB) Viewed 3376 times