Why Black Window Not Live Video?

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

Muhammad Ramadan

  • Posts: 11
  • Joined: Wed May 11, 2016 8:50 am
  • Location: Cairo,Egypt

Why Black Window Not Live Video?

PostThu May 26, 2016 11:21 am

Why Black Window Not Live Video?

What is My Fault?

Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DeckLinkAPI;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using System.Runtime.InteropServices;

namespace VideoGrapperUltraStudioSDI
{
    public partial class Form1 : Form, IDeckLinkInputCallback, IDeckLinkScreenPreviewCallback
       
    {
        private IDeckLink m_deckLink;
        private IDeckLinkInput m_deckLinkInput;
        private Device m_device;
        public static IDeckLinkDX9ScreenPreviewHelper m_ph;
        public tagRECT rc;
        public Rectangle rect;
       

        public unsafe Form1()
        {
            InitializeComponent();

            PresentParameters pp = new PresentParameters();

            //m_ph.Set3DPreviewFormat(_BMD3DPreviewFormat.bmd3DPreviewFormatDefault);
           

            pp.BackBufferFormat = Format.Unknown;
            pp.BackBufferCount = 2;
            pp.Windowed = true;
            pp.SwapEffect = SwapEffect.Discard;
           
            pp.PresentationInterval = PresentInterval.Default;


            m_device = new Device(0,
                                  DeviceType.Hardware,
                                  this,
                                  CreateFlags.SoftwareVertexProcessing,
                                   pp);

            m_ph = new CDeckLinkDX9ScreenPreviewHelper();

            m_ph.Initialize((IntPtr)m_device.UnmanagedComPointer);

            //
            rc = new tagRECT();

            rect = new Rectangle();
            rect = m_device.ScissorRectangle;
            rc.bottom = rect.Bottom;
            rc.top = rect.Top;
            rc.right = rect.Right;
            rc.left = rect.Left;
            //

            IDeckLinkIterator deckLinkIterator = new CDeckLinkIterator();

            deckLinkIterator.Next(out m_deckLink);

            m_deckLinkInput = (IDeckLinkInput)m_deckLink;

           // _BMDDisplayModeSupport displayModeSupport;
           // IDeckLinkDisplayMode displayMode = null;
          //  m_deckLinkInput.DoesSupportVideoMode(_BMDDisplayMode.bmdModeHD720p50, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault, out displayModeSupport, out displayMode);
            //m_deckLinkInput.DoesSupportVideoMode(_BMDDisplayMode.bmdModeHD1080i5994, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault,out displayModeSupport,out displayMode);
            m_deckLinkInput.EnableVideoInput(_BMDDisplayMode.bmdModeHD720p50, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault);
            m_deckLinkInput.SetCallback(this);
            m_deckLinkInput.SetScreenPreviewCallback(this);
           
            m_deckLinkInput.StartStreams();

         
        }

        public void VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode newDisplayMode, _BMDDetectedVideoInputFormatFlags detectedSignalFlags)
        {
            throw new NotImplementedException();
        }

        public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
           
            System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);
           
        }

        //Called when a new frame is available for the preview display
        public void DrawFrame(IDeckLinkVideoFrame theFrame)
        {
            m_ph.SetFrame(theFrame);
            //m_ph.Set3DPreviewFormat(_BMD3DPreviewFormat.bmd3DPreviewFormatTopBottom);
            reDraw();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(theFrame);
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {

           // timer1.Enabled = true;
           // timer1.Start();
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
             //timer1.Enabled = true;
             //timer1.Start();
           
        }

        private void reDraw()
        {
           
            m_device.BeginScene();
            m_ph.Render(ref rc);
           
            m_device.EndScene();
            m_device.Present();
         
         
        }

        /*private void Form1_Paint(object sender, PaintEventArgs e)
        {
            timer1.Enabled = true;
            timer1.Start();
        }*/

        /*private void timer1_Tick(object sender, EventArgs e)
        {
           
        }*/

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            //reDraw();
        }

       

       

       
    }
}
Attachments
Capture.PNG
Capture.PNG (27.03 KiB) Viewed 785 times

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 29 guests