C# DecklinkAPI with H264 Pro Recorder Issue

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

matt annis

  • Posts: 5
  • Joined: Wed Oct 18, 2017 6:12 am

C# DecklinkAPI with H264 Pro Recorder Issue

PostWed Oct 18, 2017 6:37 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.
Attachments
WindowsFormsApplication1.zip
Code Sample
(88.88 KiB) Downloaded 255 times
error.png
Error message
error.png (10.35 KiB) Viewed 3327 times
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: C# DecklinkAPI with H264 Pro Recorder Issue

PostThu Oct 19, 2017 10:18 pm

Hi Matt,

Thanks for providing your application, I have analysed and the issue is that the DeckLink API requires multithreaded COM apartment. The StreamingDeviceArrived and StartPreview methods should be handled in seperate threads, otherwise COM object m_streamingDevice is not referenced correctly

So under Program.cs, replace [STAThread] with [MTAThread]

FYI: Just this week we published Desktop Video Developer FAQ information on the Blackmagic Support site, there is a section - "[Windows] Using the DeckLink SDK in a C# project" that covers this topic and other pointers for C# development.
https://www.blackmagicdesign.com/support/faq/59024

I hope the FAQ page is useful for you.

Kind Regards
Cameron Nichols
Offline

matt annis

  • Posts: 5
  • Joined: Wed Oct 18, 2017 6:12 am

Re: C# DecklinkAPI with H264 Pro Recorder Issue

PostTue Oct 24, 2017 1:14 am

Thanks Cameron

Running into new issue now. I have created a class library that gets instantiated on an MTA thread. All works properly except that exactly every 15 minutes the program crashes unexpectedly. This happens every 15 minutes exactly very similar to the thread:

viewtopic.php?f=12&t=54343

I have attached a sample application. Simply run the demo then click the record button, give the file a name (IE test.ts) and sit back and wait for it to crash 15 mins later. Nothing else is needed to make this crash, seems like it is coming from the DecklinkAPI.dll

Hoping you have some ideas.
Attachments
ClassLibrary1.zip
(125.06 KiB) Downloaded 339 times
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: C# DecklinkAPI with H264 Pro Recorder Issue

PostMon Jan 29, 2018 4:05 am

Hi Matt,

This issue has been resolved in Desktop Video 10.9.10. Please download from https://www.blackmagicdesign.com/support/family/capture-and-playback

Thanks for raising this issue to our attention.

Kind Regards
Cameron

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 18 guests