Using Sharpgl with CDeckLinkGLScreenPreviewHelper

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

Nono3551

  • Posts: 5
  • Joined: Fri Aug 13, 2021 2:15 pm
  • Real Name: Michal Zahradnik

Using Sharpgl with CDeckLinkGLScreenPreviewHelper

PostFri Aug 20, 2021 1:52 pm

Hello, I was trying to render preview using SharpDx library and CDeckLinkGLScreenPreviewHelper. I tried two approaches to display preview but none of them was successful. I already made working example using DX9 but I wanted to try OpenGL as well.

I am using WPF in .NET 6. Problem seems to be in threading apartments. Since but I do not know how to deal with it yet and what is correct way so I am gently asking for some help or references. I am also providing code for mentioned approaches which are described in comments. During execution of program one of them is always commented.

Code: Select all
void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame)
        {
            if (openGl != null && openGlInitialized)
            {
                // 1. Approach

                // If I create helper on UI thread and call glHelper.SetFrame(theFrame); here, I get exception:
                // Unable to cast COM object of type 'System.__ComObject' to interface type 'DeckLinkAPI.IDeckLinkGLScreenPreviewHelper'

                this.Dispatcher.Invoke(new Action(() =>
                {
                    // If I create helper on UI thread and set frame here I get:
                    glHelper.SetFrame(theFrame); //System.InvalidCastException: 'Specified cast is not valid.'
                }));


                /////////////////////////////////////////////////////////////////////////////////////////////////////////

                // 2. Approach
                glHelper = new CDeckLinkGLScreenPreviewHelper();
                openGl.RenderContextProvider.MakeCurrent();
                glHelper.InitializeGL(); // this will fail with error:
                                         // Exception thrown at 0x00007FFF81641F2D (vcruntime140.dll) in VideoDirector.Wpf.exe: 0xC0000005:
                                         // Access violation reading location 0x0000000000000000.
                Marshal.ReleaseComObject(glHelper);
            }

            Marshal.ReleaseComObject(theFrame);
        }

Offline

Nono3551

  • Posts: 5
  • Joined: Fri Aug 13, 2021 2:15 pm
  • Real Name: Michal Zahradnik

Re: Using Sharpgl with CDeckLinkGLScreenPreviewHelper

PostTue Aug 24, 2021 2:30 pm

I was able to avoid related issues using conversion class and working on UI thread with parsed frame
Offline

Nono3551

  • Posts: 5
  • Joined: Fri Aug 13, 2021 2:15 pm
  • Real Name: Michal Zahradnik

Re: Using Sharpgl with CDeckLinkGLScreenPreviewHelper

PostTue May 17, 2022 8:42 am

I made example with winui 3 preview. It just work (for a while). Feel free to inspire. Repository here:
https://github.com/nono3551/BM-Capture

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 14 guests