Video in C# Winforms: DrawFrame Not Being Called

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

AndrewSinger

  • Posts: 4
  • Joined: Fri Aug 26, 2016 8:08 pm

Video in C# Winforms: DrawFrame Not Being Called

PostFri Aug 26, 2016 8:19 pm

Hi,

I'm Andrew Singer and I'm hitting issues when trying to use the API in a C# context. I'm using Winforms and have isolated my most likely problem to the fact that IDeckLinkScreenPreviewCallback::DrawFrame is only being called for about a second and then is only called sporadically (will run for a second or two a couple times over the course of a few minutes).

I've confirmed the settings and referenced the C++ examples and SDK documentation multiple times but have run out of ideas at this point. Below is my Winforms code and I'm wondering if I'm missing some setup or configuration steps.

Thanks,
Andrew

Code is running on an MTA thread, I've tried referencing both the COM component directly as well as the Interop.DeckLinkAPI.dll. Settings have been confirmed and a signal can be found when using them in the CapturePreview sln in the SDK. GL conrtrol and painting code have been removed for clarity, and their removal didn't effect the issue. I can attach the project code if that would help.

Code: Select all
public partial class TesterMcTesterson3 : Form, IDeckLinkScreenPreviewCallback
    {
        private IDeckLinkGLScreenPreviewHelper m_deckLinkScreenPreviewHelper;
        private int frameCount = 0;


        public TesterMcTesterson3()
        {

            InitializeComponent();

            InitializeDecklink();

        }

        private IDeckLink m_deckLink;
        private IDeckLinkInput m_deckLinkInput;
        private void InitializeDecklink()
        {
            IDeckLinkIterator deckLinkIterator = new CDeckLinkIterator();

            // Get the first DeckLink card
            deckLinkIterator.Next(out m_deckLink);
            if (m_deckLink == null)
            {
                MessageBox.Show("This application requires a DeckLink PCI card.\nYou will not be able to use the features of this application until a DeckLink PCI card is installed.", "Error");
                Environment.Exit(1);
            }

            m_deckLinkInput = (IDeckLinkInput)m_deckLink;
            m_deckLinkScreenPreviewHelper = new CDeckLinkGLScreenPreviewHelper();
            m_deckLinkInput.SetScreenPreviewCallback(this);

            m_deckLinkInput.EnableVideoInput(_BMDDisplayMode.bmdModeHD720p5994, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault);
            //m_deckLinkInput.EnableAudioInput(_BMDAudioSampleRate.bmdAudioSampleRate48kHz, _BMDAudioSampleType.bmdAudioSampleType16bitInteger, 2);
            m_deckLinkInput.StartStreams();
        }


        public void DrawFrame(IDeckLinkVideoFrame theFrame)
        {
            m_deckLinkScreenPreviewHelper.SetFrame(theFrame);

            frameCount++;
            this.Invoke(new Action(delegate
            {
                this.label1.Text = frameCount.ToString();
            }));
        }
    }
Andrew Singer
Offline

Nicholas Gill

Blackmagic Design

  • Posts: 169
  • Joined: Mon May 04, 2015 10:28 pm

Re: Video in C# Winforms: DrawFrame Not Being Called

PostTue Aug 30, 2016 4:24 am

Hi Andrew,

One common reason for the described behaviour when using .NET languages is that the C# COM Interop layer / GC doesn't release the video frames in a timely manner, causing the video capture operation to run out of free video frames.

This can be corrected by manually releasing the IDeckLinkVideoFrame instance, e.g. via:
Code: Select all
System.Runtime.InteropServices.Marshal.ReleaseComObject(theFrame);

Cheers,

-nick
Offline

AndrewSinger

  • Posts: 4
  • Joined: Fri Aug 26, 2016 8:08 pm

Re: Video in C# Winforms: DrawFrame Not Being Called

PostTue Aug 30, 2016 3:23 pm

Thanks Nick, that fixed the DrawFrame issue!

-Andrew
Andrew Singer

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 8 guests