Example #1
0
        // Get VideoFrame
        unsafe public void *GetVideoFramePointer()
        {
            deckLinkOutput.CreateVideoFrame(1920, 1080, 1920 * 4, _BMDPixelFormat.bmdFormat8BitBGRA, _BMDFrameFlags.bmdFrameFlagFlipVertical, out videoFrame);
            IntPtr frameBytes;

            videoFrame.GetBytes(out frameBytes);
            return(frameBytes.ToPointer());
        }
Example #2
0
        public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            this.Lock.AcquireWriterLock(5000);
            try
            {
                FConverter.ConvertFrame(videoFrame, rgbFrame);

                rgbFrame.GetBytes(out FData);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);

                FreshData = true;
            }
            catch
            {
            }
            finally
            {
                this.Lock.ReleaseWriterLock();
            }
        }
Example #3
0
        public void Initialise(IDeckLink device, ModeRegister.Mode mode, bool useDeviceCallbacks)
        {
            Stop();

            try
            {
                WorkerThread.Singleton.PerformBlocking(() => {
                    //--
                    //attach to device
                    //
                    if (device == null)
                    {
                        throw (new Exception("No device"));
                    }
                    if (mode == null)
                    {
                        throw (new Exception("No mode selected"));
                    }

                    FDevice = device;

                    var outputDevice = FDevice as IDeckLinkOutput;
                    if (outputDevice == null)
                    {
                        throw (new Exception("Device does not support output"));
                    }
                    FOutputDevice = outputDevice;
                    //
                    //--


                    //--
                    //set memory allocator
                    //
                    FOutputDevice.SetVideoOutputFrameMemoryAllocator(FMemoryAllocator);
                    //
                    //--


                    //--
                    //select mode
                    //
                    _BMDDisplayModeSupport support;
                    IDeckLinkDisplayMode displayMode;
                    FOutputDevice.DoesSupportVideoMode(mode.DisplayModeHandle.GetDisplayMode(), mode.PixelFormat, mode.Flags, out support, out displayMode);
                    if (support == _BMDDisplayModeSupport.bmdDisplayModeNotSupported)
                    {
                        throw (new Exception("Mode not supported"));
                    }

                    this.Mode    = mode;
                    this.FWidth  = Mode.Width;
                    this.FHeight = Mode.Height;

                    Mode.DisplayModeHandle.GetFrameRate(out this.FFrameDuration, out this.FFrameTimescale);
                    //
                    //--


                    //--
                    //enable the output
                    //
                    FOutputDevice.EnableVideoOutput(Mode.DisplayModeHandle.GetDisplayMode(), Mode.Flags);
                    //
                    //--


                    //--
                    //generate frames
                    IntPtr data;
                    FOutputDevice.CreateVideoFrame(FWidth, FHeight, Mode.CompressedWidth * 4, Mode.PixelFormat, _BMDFrameFlags.bmdFrameFlagDefault, out FVideoFrame);
                    FVideoFrame.GetBytes(out data);
                    FillBlack(data);
                    //
                    //--

                    //--
                    //scheduled playback
                    if (useDeviceCallbacks == true)
                    {
                        FOutputDevice.SetScheduledFrameCompletionCallback(this);
                        this.FFrameIndex = 0;
                        for (int i = 0; i < (int)this.Framerate; i++)
                        {
                            ScheduleFrame(true);
                        }
                        FOutputDevice.StartScheduledPlayback(0, 100, 1.0);
                    }
                    //
                    //--

                    FRunning = true;
                });
            }
            catch (Exception e)
            {
                this.FWidth   = 0;
                this.FHeight  = 0;
                this.FRunning = false;
                throw;
            }
        }
Example #4
0
        void Draw()
        {
            //Show the window
            _win.Visible = true;

            while (_win.Exists)
            {
                #region FBO Buffer
                _fbo.Begin();
                //Set the projection type
                Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, _fbo.Width / (float)_fbo.Height, 1.0f, 64.0f);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadMatrix(ref projection);

                //Set the 3D view
                Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, Vector3.UnitZ, Vector3.UnitY);
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadMatrix(ref modelview);

                GL.Translate(0f, 0.0f, 3.0f);
                GL.Rotate(squareRotx, 1.0f, 0.0f, 0.0f);
                GL.Rotate(squareRoty, 0.0f, 1.0f, 0.0f);
                _texLogo.Bind();

                GL.Begin(BeginMode.Quads);
                #region Draw Sqaure
                GL.TexCoord2(0.0f, 1.0f);
                GL.Vertex3(-0.5f, -0.5f, 0.5f);
                GL.TexCoord2(1.0f, 1.0f);
                GL.Vertex3(0.5f, -0.5f, 0.5f);
                GL.TexCoord2(1.0f, 0.0f);
                GL.Vertex3(0.5f, 0.5f, 0.5f);
                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex3(-0.5f, 0.5f, 0.5f);

                GL.TexCoord2(0.0f, 1.0f);
                GL.Vertex3(-0.5f, -0.5f, -0.5f);
                GL.TexCoord2(1.0f, 1.0f);
                GL.Vertex3(-0.5f, 0.5f, -0.5f);
                GL.TexCoord2(1.0f, 0.0f);
                GL.Vertex3(0.5f, 0.5f, -0.5f);
                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex3(0.5f, -0.5f, -0.5f);

                GL.TexCoord2(0.0f, 1.0f);
                GL.Vertex3(-0.5f, -0.5f, 0.5f);
                GL.TexCoord2(1.0f, 1.0f);
                GL.Vertex3(-0.5f, 0.5f, 0.5f);
                GL.TexCoord2(1.0f, 0.0f);
                GL.Vertex3(-0.5f, 0.5f, -0.5f);
                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex3(-0.5f, -0.5f, -0.5f);

                GL.TexCoord2(0.0f, 1.0f);
                GL.Vertex3(0.5f, -0.5f, -0.5f);
                GL.TexCoord2(1.0f, 1.0f);
                GL.Vertex3(0.5f, 0.5f, -0.5f);
                GL.TexCoord2(1.0f, 0.0f);
                GL.Vertex3(0.5f, 0.5f, 0.5f);
                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex3(0.5f, -0.5f, 0.5f);

                GL.TexCoord2(0.0f, 1.0f);
                GL.Vertex3(-0.5f, 0.5f, 0.5f);
                GL.TexCoord2(1.0f, 1.0f);
                GL.Vertex3(0.5f, 0.5f, 0.5f);
                GL.TexCoord2(1.0f, 0.0f);
                GL.Vertex3(0.5f, 0.5f, -0.5f);
                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex3(-0.5f, 0.5f, -0.5f);

                GL.TexCoord2(0.0f, 1.0f);
                GL.Vertex3(-0.5f, -0.5f, 0.5f);
                GL.TexCoord2(1.0f, 1.0f);
                GL.Vertex3(-0.5f, -0.5f, -0.5f);
                GL.TexCoord2(1.0f, 0.0f);
                GL.Vertex3(0.5f, -0.5f, -0.5f);
                GL.TexCoord2(0.0f, 0.0f);
                GL.Vertex3(0.5f, -0.5f, 0.5f);
                #endregion
                GL.End();

                //Create a Buffer and store the frame
                IntPtr buffer;
                _videoFrame.GetBytes(out buffer);
                GL.ReadPixels(0, 0, 1280, 720, PixelFormat.Bgra, PixelType.UnsignedInt8888Reversed, buffer);

                _fbo.End();
                #endregion

                int width  = _win.Size.Width;
                int height = _win.Size.Height;

                #region Back Buffer
                GL.Viewport(0, 0, width, height);

                //Set projection to 2D plane
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadIdentity();
                GL.Ortho(0, width, height, 0, -1, 1);
                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadIdentity();

                //Draw a full screen Quad with the FBO texture
                _fbo.ColorTexture.Bind();

                //Draw the framebuffer as a quad to a screen
                GL.Begin(PrimitiveType.Quads);
                GL.TexCoord2(0, 1); GL.Vertex2(0, 0);
                GL.TexCoord2(0, 0); GL.Vertex2(0, height);
                GL.TexCoord2(1, 0); GL.Vertex2(width, height);
                GL.TexCoord2(1, 1); GL.Vertex2(width, 0);
                GL.End();

                Texture.Unbind();
                #endregion

                Thread.Sleep(5);
                _context.SwapBuffers();
                _win.ProcessEvents();
            }
        }