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; } }
public Source(IDeckLink device, ModeRegister.Mode mode, bool useDeviceCallbacks) { this.Initialise(device, mode, useDeviceCallbacks); }