Getting Video Output in C# Through SDK - Trying IDeckLinkDX9

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

Getting Video Output in C# Through SDK - Trying IDeckLinkDX9

PostFri Sep 02, 2016 3:37 pm

Hi,

I'm still trying to get a preview video stream in C#, but am in the same place with the DirectX PreviewHelper (IDeckLinkDX9ScreenPreviewHelper) as I am with the GL Helper (viewtopic.php?f=12&t=51423&sid=a7550db6d8f9f8ae3712923afa9f67bb#p297128).

I've got a DX9 sample together (using SharpDX), but it just shows a black window. The sample for that is below.

Interestingly, however, if I draw a white triangle on the dx scene, then it will show both the target rect and the triangle with a color that's currently in the feed (image attached) which will change as the source changes, though is still only a single color from the feed. Can attach code for that too, in case it's helpful.

Would be very appreciative of any pointers on this path or to see any functional video output from the card through C# (the DirectShow example crashes the system it's run on, so that path unfortunately isn't open). If it just won't work in C# though, knowing that would help me too.

Thanks,
Andrew


Code: Select all
class simpleBMDXTest : IDeckLinkInputCallback, IDeckLinkScreenPreviewCallback
    {
        private IDeckLink m_deckLink;
        private IDeckLinkInput m_deckLinkInput;
        private Device device;
        private RenderForm form;
        private Direct3D direct3D;
        public static IDeckLinkDX9ScreenPreviewHelper m_DeckLinkDX9ScreenPreviewHelper;

        private int frameCount = 0;
        private bool dxInitialized;

        public unsafe simpleBMDXTest()
        {
            InitializeBlackMagicDevice();

            PresentParameters pp = new PresentParameters()
            {
                BackBufferFormat = Format.Unknown,
                BackBufferCount = 2,
                Windowed = true,
                SwapEffect = SwapEffect.Discard,
                PresentationInterval = PresentInterval.Default
            };

            m_DeckLinkDX9ScreenPreviewHelper = new CDeckLinkDX9ScreenPreviewHelper();

            direct3D = new Direct3D();
            form = new RenderForm("BlackMagic DX9 Render Test Form");
            form.Size = new Size(650, 650);

            device = new Device(direct3D, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded, pp);
            device.Viewport = new RawViewport() { Height = 650, Width = 650, X = 0, Y = 0 };
            m_DeckLinkDX9ScreenPreviewHelper.Initialize((IntPtr)device.NativePointer);

            var ptr = device.NativePointer;
            Console.WriteLine(ptr);

            var tagRect = new tagRECT()
            {
                top = 10,
                left = 10,
                right = 400,
                bottom = 400
            };

            RenderLoop.Run(form, () =>
            {
                device.BeginScene();

                m_DeckLinkDX9ScreenPreviewHelper.Render(tagRect);

                device.EndScene();
                device.Present();
            });

            device.Dispose();
            direct3D.Dispose();
        }

        private void InitializeBlackMagicDevice()
        {
            IDeckLink m_deckLink;
            IDeckLinkIterator deckLinkIterator = new CDeckLinkIterator();
            deckLinkIterator.Next(out m_deckLink);

            m_deckLinkInput = (IDeckLinkInput)m_deckLink;
            m_deckLinkInput.SetScreenPreviewCallback(this);

            m_deckLinkInput.EnableVideoInput(_BMDDisplayMode.bmdModeHD720p5994, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault);
            m_deckLinkInput.StartStreams();
        }

        void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame)
        {
            m_DeckLinkDX9ScreenPreviewHelper.SetFrame(theFrame);

            System.Runtime.InteropServices.Marshal.ReleaseComObject(theFrame);
        }

        void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame video, IDeckLinkAudioInputPacket audio)
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(video);
        }

        void IDeckLinkInputCallback.VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents e, IDeckLinkDisplayMode m, _BMDDetectedVideoInputFormatFlags f)
        {

        }
    }
Attachments
blackmagic-directx.png
blackmagic-directx.png (5.08 KiB) Viewed 4572 times
Andrew Singer
Offline

Carlos Filipe

  • Posts: 5
  • Joined: Sun Mar 27, 2016 1:46 pm

Re: Getting Video Output in C# Through SDK - Trying IDeckLin

PostTue Sep 06, 2016 4:31 pm

Hi Andrew,
I'm using VS 2010 and I choose aForge 2.2.5 library, it's working fine...
Well, using VB.Net but is the same thing as C#
However, only a few HDMI input formats are working, like:
- 576i25 (720x576 - PAL i)
- 576p50 (720x576 - PAL)
- 720p50 (1280x720)
- 1080i25 (1920x1080 i)

I made a broadcasting software with scrolling messages and banners
If you need it I can send it to you, it's an evaluation version but you can see the picture, only a message on the screen comes with this version.
Offline

vijay.meganathan

  • Posts: 4
  • Joined: Thu Feb 16, 2017 4:22 pm

Re: Getting Video Output in C# Through SDK - Trying IDeckLin

PostMon Feb 20, 2017 3:35 pm

Do you have sample solution?
Offline

Philippe Beau

  • Posts: 2
  • Joined: Tue Mar 14, 2017 7:25 am

Re: Getting Video Output in C# Through SDK - Trying IDeckLin

PostWed Mar 15, 2017 6:29 pm

Dear All,

Do you arrive to have working with aForge 2.2.5 ? VideoCapture is not working with VS 2015/2017 and aForge 2.2.5. But working with aForge 2.2.4 :(

Any idea ?

Regards

Philippe
Offline

Salem Jabri

  • Posts: 6
  • Joined: Thu Sep 28, 2017 4:28 pm

Re: Getting Video Output in C# Through SDK - Trying IDeckLin

PostSun Oct 08, 2017 10:01 am

Hi Andrew.
I am having the same problem.
No video being displayed.
Did you find a solution?
Code: Select all
using System;
using System.Drawing;
using System.Windows.Forms;
using DeckLinkAPI;
using Direct3D = Microsoft.DirectX.Direct3D;

namespace CapturePreviewCSharp
{
    public partial class PreviewWindow : Control, IDeckLinkScreenPreviewCallback
    {
        private IDeckLinkDX9ScreenPreviewHelper m_previewHelper;
        private string                          m_timeCodeString;

        private Direct3D.Device                 m_d3DDevice;
        private Direct3D.Font                   m_d3DFont;
        tagRECT rect;
        public PreviewWindow()
        {
            m_previewHelper = new CDeckLinkDX9ScreenPreviewHelper();
            InitializeComponent();
        }

        public void InitD3D()
        {
            var d3dpp = new Direct3D.PresentParameters();
            d3dpp.BackBufferFormat = Direct3D.Format.Unknown;                   
            d3dpp.BackBufferCount = 2;
            d3dpp.Windowed = true;
            d3dpp.SwapEffect = Direct3D.SwapEffect.Discard;
            d3dpp.DeviceWindow = this;
            d3dpp.PresentationInterval = Direct3D.PresentInterval.Default;

            m_d3DDevice = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, Direct3D.CreateFlags.HardwareVertexProcessing | Direct3D.CreateFlags.MultiThreaded, d3dpp);

            m_d3DDevice.DeviceReset += device_DeviceReset;
            device_DeviceReset(m_d3DDevice, null);

           

            unsafe
            {
                m_previewHelper.Initialize((IntPtr)m_d3DDevice.UnmanagedComPointer);
            }
        }

        void device_DeviceReset(object sender, EventArgs e)
        {
            System.Drawing.Font systemfont = new System.Drawing.Font(FontFamily.GenericMonospace, 14f, FontStyle.Regular);
            m_d3DFont = new Microsoft.DirectX.Direct3D.Font(m_d3DDevice, systemfont);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
        }

        void Render()
        {
            m_d3DDevice.Clear(Direct3D.ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
            m_d3DDevice.BeginScene();

            rect = new tagRECT();
            rect.top = 0;
            rect.left = 0;
            rect.bottom = 1080;
            rect.right = 1920;

           

            m_previewHelper.Render(ref rect);

           

            // Draw the timecode top-center with a slight drop-shadow
            Rectangle rc = m_d3DFont.MeasureString(null, m_timeCodeString, Direct3D.DrawTextFormat.Center, Color.Black);
            int x = (m_d3DDevice.Viewport.Width / 2) - (rc.Width / 2);
            int y = 10;
            m_d3DFont.DrawText(null, m_timeCodeString, x + 1, y + 1, Color.Black);
            m_d3DFont.DrawText(null, m_timeCodeString, x, y, Color.White);

           

            m_d3DDevice.EndScene();
            m_d3DDevice.Present();
        }

        void SetTimecode(IDeckLinkVideoFrame videoFrame)
        {
            IDeckLinkTimecode timecode;

            m_timeCodeString = "00:00:00:00";

            videoFrame.GetTimecode(_BMDTimecodeFormat.bmdTimecodeRP188Any, out timecode);

            if (timecode != null)
                timecode.GetString(out m_timeCodeString);
        }

        void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame)
        {
            // First, pass the frame to the DeckLink screen preview helper
            m_previewHelper.SetFrame(theFrame);
            SetTimecode(theFrame);

            // Then draw the frame to the scene
            Render();

            System.Runtime.InteropServices.Marshal.ReleaseComObject(theFrame);
        }
    }
}



Return to Software Developers

Who is online

Users browsing this forum: No registered users and 14 guests