Пример #1
0
            public Instance(int deviceID, string modeString, uint textureHandle, EnumEntry format, EnumEntry usage, SyncLoop syncLoop)
            {
                IDeckLink device = null;

                WorkerThread.Singleton.PerformBlocking(() => {
                    device = DeviceRegister.Singleton.GetDeviceHandle(deviceID);
                });

                try
                {
                    ModeRegister.Mode mode = null;
                    WorkerThread.Singleton.PerformBlocking(() =>
                    {
                        mode = ModeRegister.Singleton.Modes[modeString];
                    });

                    bool useCallback = syncLoop != SyncLoop.DeckLink;
                    this.Source      = new Source(device, mode, useCallback);
                    this.ReadTexture = new ReadTexture(mode.CompressedWidth, mode.Height, textureHandle, format, usage);
                    this.FBuffer     = new byte[this.ReadTexture.BufferLength];

                    if (useCallback)
                    {
                        this.Source.NewFrame += Source_NewFrame;
                    }
                }
                catch
                {
                    if (this.Source != null)
                    {
                        this.Source.Dispose();
                    }
                    if (this.ReadTexture != null)
                    {
                        this.ReadTexture.Dispose();
                    }
                    if (this.FBuffer != null)
                    {
                        this.FBuffer = null;
                    }
                    throw;
                }
            }
Пример #2
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;
            }
        }
Пример #3
0
 public Source(IDeckLink device, ModeRegister.Mode mode, bool useDeviceCallbacks)
 {
     this.Initialise(device, mode, useDeviceCallbacks);
 }