Exemple #1
0
        void RemoveDevice(IDeckLink decklinkDevice)
        {
            // Stop capture if the selected device was removed
            if (m_selectedDevice != null && m_selectedDevice.deckLink == decklinkDevice)
            {
                if (m_selectedDevice.isCapturing)
                {
                    StopCapture();
                }

                comboBoxInputDevice.SelectedIndex = -1;
                m_selectedDevice = null;
            }

            // Remove the device from the dropdown
            comboBoxInputDevice.BeginUpdate();
            foreach (StringObjectPair <DeckLinkDevice> item in comboBoxInputDevice.Items)
            {
                if (item.value.deckLink == decklinkDevice)
                {
                    comboBoxInputDevice.Items.Remove(item);
                    break;
                }
            }
            comboBoxInputDevice.EndUpdate();

            if (comboBoxInputDevice.Items.Count == 0)
            {
                buttonStartStop.Enabled = false;
                EnableInterface(false);
            }
        }
        void RemoveDevice(IDeckLink decklinkDevice)
        {
            // Stop capture if the selected device was removed
            if (m_selectedDevice != null && m_selectedDevice.deckLink == decklinkDevice && m_running)
            {
                // Stop running and disable output, we will not receive ScheduledPlaybackHasStopped callback
                StopRunning();
                DisableOutput();
            }

            // Remove the device from the dropdown
            comboBoxOutputDevice.BeginUpdate();
            foreach (StringObjectPair <DeckLinkOutputDevice> item in comboBoxOutputDevice.Items)
            {
                if (item.value.deckLink == decklinkDevice)
                {
                    comboBoxOutputDevice.Items.Remove(item);
                    break;
                }
            }
            comboBoxOutputDevice.EndUpdate();

            if (comboBoxOutputDevice.Items.Count == 0)
            {
                EnableInterface(false);
                m_selectedDevice = null;
            }
            else if (m_selectedDevice.deckLink == decklinkDevice)
            {
                comboBoxOutputDevice.SelectedIndex = 0;
                buttonStartStop.Enabled            = true;
            }
        }
        public DLDirect(IDeckLink deckLink, IDeckLinkDisplayMode displayMode)
        {
            PreRollFrameCount = 4;

            this.displayMode = displayMode;
            this.m_deckLink  = deckLink;

            DisplayWidth  = displayMode.GetWidth();
            DisplayHeight = displayMode.GetHeight();

            m_running = false;

            // Get the IDeckLinkOutput interface
            m_deckLinkOutput = (IDeckLinkOutput)m_deckLink;

            // Provide this class as a delegate to the audio and video output interfaces
            m_deckLinkOutput.SetScheduledFrameCompletionCallback(this);

            m_frameWidth  = displayMode.GetWidth();
            m_frameHeight = displayMode.GetHeight();

            displayMode.GetFrameRate(out m_frameDuration, out m_frameTimescale);

            // Calculate the number of frames per second, rounded up to the nearest integer.  For example, for NTSC (29.97 FPS), framesPerSecond == 30.
            m_framesPerSecond = (uint)((m_frameTimescale + (m_frameDuration - 1)) / m_frameDuration);
            FPS = (int)m_framesPerSecond;

            // Set the video output mode
            m_deckLinkOutput.EnableVideoOutput(displayMode.GetDisplayMode(), _BMDVideoOutputFlags.bmdVideoOutputFlagDefault);

            // Generate the frame used for playback
            m_deckLinkOutput.CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth * 4, _BMDPixelFormat.bmdFormat8BitBGRA, _BMDFrameFlags.bmdFrameFlagDefault, out m_videoFramePlayback);
            m_totalFramesScheduled = 0;
        }
Exemple #4
0
        void IDeckLinkDeviceNotificationCallback.DeckLinkDeviceArrived(IDeckLink device)
        {
            logger.Verb("IDeckLinkDeviceNotificationCallback::DeckLinkDeviceArrived()");

            DeckLinkDeviceDescription inputDescr = null;
            var inputDevice = new DeckLinkInput(device);

            if (inputDevice.Init())
            {
                inputDescr = inputDevice.GetDeviceDescription();
                inputDevices.Add(inputDevice);

                InputDeviceArrived?.Invoke(inputDescr);
            }

            if (inputDescr == null)
            {//  нас интересуют только decklink input
                if (inputDevice != null)
                {
                    inputDevice.Dispose();
                    inputDevice = null;
                }

                if (device != null)
                {
                    Marshal.ReleaseComObject(device);
                    device = null;
                }
            }
        }
Exemple #5
0
        public static List <DisplayModeItem> GetDisplayModeItems(IDeckLink m_deckLink)
        {
            List <DisplayModeItem> outList = new List <DisplayModeItem>();

            IDeckLinkOutput m_deckLinkOutput = (IDeckLinkOutput)m_deckLink;

            IDeckLinkDisplayModeIterator displayModeIterator;

            m_deckLinkOutput.GetDisplayModeIterator(out displayModeIterator);

            while (true)
            {
                IDeckLinkDisplayMode deckLinkDisplayMode;

                displayModeIterator.Next(out deckLinkDisplayMode);
                if (deckLinkDisplayMode == null)
                {
                    break;
                }

                outList.Add(new DisplayModeItem(deckLinkDisplayMode));
            }

            return(outList);
        }
Exemple #6
0
        void IDeckLinkDeviceNotificationCallback.DeckLinkDeviceRemoved(IDeckLink device)
        {// Удаление не проверялось т.к не было в наличии устройств поддерживающий динамическое отключение
            logger.Verb("IDeckLinkDeviceNotificationCallback::DeckLinkDeviceRemoved()");

            try
            {
                var inputDevice = inputDevices.FirstOrDefault(d => d.deckLink == device);

                DeckLinkDeviceDescription inputDescr = inputDevice?.GetDeviceDescription();
                if (inputDescr != null)
                {
                    bool removed = inputDevices.Remove(inputDevice);
                    Debug.Assert(removed, "removed");

                    InputDeviceRemoved?.Invoke(inputDescr);
                }

                if (inputDevice != null)
                {
                    inputDevice.Dispose();
                    inputDevice = null;
                }
            }
            finally
            {
                if (device != null)
                {
                    var refCount = Marshal.ReleaseComObject(device);
                    Debug.Assert(refCount == 0, "refCount == 0");

                    device = null;
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// Construct a physical Mini-recorder device
 /// </summary>
 /// <param name="d"></param>
 /// <param name="channels"></param>
 public InputDevice(IDeckLink d, int channels)
 {
     device = d as IDeckLinkInput;
     if (device == null)
     {
         throw new ApplicationException("Not a Decklink input device");
     }
     this.channels = channels;
     d.GetDisplayName(out name);
 }
Exemple #8
0
        void IDeckLinkDeviceNotificationCallback.DeckLinkDeviceRemoved(IDeckLink deckLinkDevice)
        {
            EventHandler <DeckLinkDiscoveryEventArgs> handler = DeviceRemoved;

            // Check whether there are any subscribers to DeviceRemoved event
            if (handler != null)
            {
                handler(this, new DeckLinkDiscoveryEventArgs(deckLinkDevice));
            }
        }
        public DeckLinkInputDevice(IDeckLink deckLink) : base(deckLink)
        {
            if (!CaptureDevice)
            {
                throw new DeckLinkInputInvalidException();
            }

            // Query input interface
            m_deckLinkInput = (IDeckLinkInput)deckLink;
        }
Exemple #10
0
        public void DeckLinkDeviceRemoved(IDeckLink deckLinkDevice)
        {
            string displayName;
            string modelName;

            deckLinkDevice.GetDisplayName(out displayName);
            deckLinkDevice.GetModelName(out modelName);

            Run(() => notifications.Text = string.Format("Device disconnected! {0}", FormatDevice(displayName, modelName)));
        }
Exemple #11
0
        public void Open(DeviceRegister.DeviceIndex device, _BMDDisplayMode mode, _BMDVideoInputFlags flags)
        {
            if (Ready)
            {
                Close();
            }

            WorkerThread.Singleton.PerformBlocking(() =>
            {
                this.Lock.AcquireWriterLock(10000);
                try
                {
                    if (device == null)
                    {
                        throw (new Exception("No device selected"));
                    }

                    IDeckLink rawDevice = DeviceRegister.Singleton.GetDeviceHandle(device.Index);
                    FDevice             = rawDevice as IDeckLinkInput;
                    FMode  = mode;
                    FFlags = flags;

                    if (FDevice == null)
                    {
                        throw (new Exception("No input device connected"));
                    }

                    _BMDDisplayModeSupport displayModeSupported;

                    FDevice.DoesSupportVideoMode(FMode, FPixelFormat, flags, out displayModeSupported, out FDisplayMode);

                    Width  = FDisplayMode.GetWidth();
                    Height = FDisplayMode.GetHeight();

                    FDevice.EnableVideoInput(FMode, FPixelFormat, FFlags);
                    FDevice.SetCallback(this);
                    FDevice.StartStreams();

                    Reinitialise = true;
                    Ready        = true;
                    FreshData    = false;
                }
                catch (Exception e)
                {
                    Ready        = false;
                    Reinitialise = false;
                    FreshData    = false;
                    throw;
                }
                finally
                {
                    this.Lock.ReleaseWriterLock();
                }
            });
        }
Exemple #12
0
        public void Open(IDeckLink device, _BMDDisplayMode mode, _BMDVideoInputFlags flags)
        {
            if (Ready)
            {
                Close();
            }

            try
            {
                this.Lock.AcquireWriterLock(10000);
            }
            catch
            {
            }
            try
            {
                FDevice = device as IDeckLinkInput;
                FMode   = mode;
                FFlags  = flags;

                if (FDevice == null)
                {
                    throw (new Exception("No input device connected"));
                }

                _BMDDisplayModeSupport displayModeSupported;

                FDevice.DoesSupportVideoMode(FMode, FPixelFormat, flags, out displayModeSupported, out FDisplayMode);

                Width  = FDisplayMode.GetWidth();
                Height = FDisplayMode.GetHeight();

                FDevice.EnableVideoInput(FMode, FPixelFormat, FFlags);
                FDevice.SetCallback(this);
                FDevice.StartStreams();

                Reinitialise = true;
                Ready        = true;
                FreshData    = false;
            }
            catch (Exception e)
            {
                Ready        = false;
                Reinitialise = false;
                FreshData    = false;
                throw (e);
            }
            finally
            {
                this.Lock.ReleaseWriterLock();
            }
        }
Exemple #13
0
        private int GetAudioChannelCount(IDeckLink dl)
        {
            var attr = dl as IDeckLinkAttributes;

            if (attr == null)
            {
                return(0);
            }
            long chans;

            attr.GetInt(_BMDDeckLinkAttributeID.BMDDeckLinkMaximumAudioChannels, out chans);
            return((int)chans);
        }
        public void ConfigureDeckLinks(int DLIdx, int DLDisplayModeIdx)
        {
            IDeckLink dl = DLHelper.GetDeckLinks()[DLIdx];

            IDeckLinkDisplayMode dl1DisplayMode = DLHelper.GetDisplayModes(dl)[DLDisplayModeIdx];

            output = new DLDirect(dl, dl1DisplayMode);

            output.FrameDrawnCallback = NextFrame;

            DisplayWidth  = output.DisplayWidth;
            DisplayHeight = output.DisplayHeight;
        }
Exemple #15
0
        void IBMDStreamingDeviceNotificationCallback.StreamingDeviceModeChanged(IDeckLink device, _BMDStreamingDeviceMode mode)
        {
            if (mode == deviceMode)
            {
                return;
            }

            deviceMode = mode;

            if (callback != null)
            {
                callback.DeviceModeChanged(mode);
            }
        }
Exemple #16
0
        public DeckLinkOutputDevice(IDeckLink deckLink) : base(deckLink)
        {
            if (!PlaybackDevice)
            {
                throw new DeckLinkOutputInvalidException();
            }

            // Query output interface
            m_deckLinkOutput = (IDeckLinkOutput)deckLink;

            // Provide the delegate to the audio and video output interfaces
            m_deckLinkOutput.SetScheduledFrameCompletionCallback(this);
            m_deckLinkOutput.SetAudioCallback(this);
        }
		public void Open(IDeckLink device, _BMDDisplayMode mode, _BMDVideoInputFlags flags)
		{
			if (Ready)
				Close();

			try
			{
				this.Lock.AcquireWriterLock(10000);
			}
			catch
			{

			}
			try
			{
				FDevice = device as IDeckLinkInput;
				FMode = mode;
				FFlags = flags;

				if (FDevice == null)
					throw (new Exception("No input device connected"));

				_BMDDisplayModeSupport displayModeSupported;

				FDevice.DoesSupportVideoMode(FMode, FPixelFormat, flags, out displayModeSupported, out FDisplayMode);

				Width = FDisplayMode.GetWidth();
				Height = FDisplayMode.GetHeight();

				FDevice.EnableVideoInput(FMode, FPixelFormat, FFlags);
				FDevice.SetCallback(this);
				FDevice.StartStreams();

				Reinitialise = true;
				Ready = true;
				FreshData = false;
			}
			catch (Exception e)
			{
				Ready = false;
				Reinitialise = false;
				FreshData = false;
				throw (e);
			}
			finally
			{
				this.Lock.ReleaseWriterLock();
			}
		}
        public static bool GetDeviceByHandle(string deviceHandle, out IDeckLink deckLink)
        {
            logger.Verb("GetDeviceByName(...) " + deviceHandle);

            bool Success = false;

            deckLink = null;
            IDeckLinkIterator deckLinkIterator = null;

            try
            {
                deckLinkIterator = new CDeckLinkIterator();

                int index = 0;
                do
                {
                    if (deckLink != null)
                    {
                        Marshal.ReleaseComObject(deckLink);
                        deckLink = null;
                    }

                    deckLinkIterator.Next(out deckLink);
                    if (deckLink != null)
                    {
                        ((IDeckLinkProfileAttributes)deckLink).GetString(_BMDDeckLinkAttributeID.BMDDeckLinkDeviceHandle, out string handle);
                        if (deviceHandle == handle)
                        {
                            break;
                        }
                    }
                    index++;
                }while (deckLink != null);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            finally
            {
                if (deckLinkIterator != null)
                {
                    Marshal.ReleaseComObject(deckLinkIterator);
                    deckLinkIterator = null;
                }
            }

            return(Success);
        }
Exemple #19
0
        public DeckLinkDevice(IDeckLink deckLink)
        {
            m_deckLink = deckLink;

            // Get input interface
            try
            {
                m_deckLinkInput = (IDeckLinkInput)m_deckLink;
            }
            catch (InvalidCastException)
            {
                // No output interface found, eg in case of DeckLink Mini Monitor
                return;
            }
        }
Exemple #20
0
            internal void Dispose()
            {
                if (deckLink != null)
                {
                    var refCount = Marshal.ReleaseComObject(deckLink);
                    Debug.Assert(refCount == 0, "refCount == 0");

                    deckLink = null;

                    deckLinkStatus = null;
                    deckLinkInput  = null;
                    deckLinkAttrs  = null;

                    initialized = false;
                }
            }
Exemple #21
0
        public void ConfigureDeckLinks(int DL1Idx, int DL2Idx, int DL1DisplayModeIdx, int DL2DisplayModeIdx)
        {
            IDeckLink dl1 = DLHelper.GetDeckLinks()[DL1Idx];
            IDeckLink dl2 = DLHelper.GetDeckLinks()[DL2Idx];

            IDeckLinkDisplayMode dl1DisplayMode = DLHelper.GetDisplayModes(dl1)[DL1DisplayModeIdx];
            IDeckLinkDisplayMode dl2DisplayMode = DLHelper.GetDisplayModes(dl2)[DL2DisplayModeIdx];

            output_A = new DLDirect(dl1, dl1DisplayMode);
            output_B = new DLDirect(dl2, dl2DisplayMode);

            output_A.FrameDrawnCallback = NextFrame;

            DisplayWidth  = output_A.DisplayWidth;
            DisplayHeight = output_A.DisplayHeight;
        }
        public static bool GetDeviceByIndex(int inputIndex, out IDeckLink deckLink)
        {
            logger.Verb("GetDeviceByIndex(...) " + inputIndex);

            bool Success = false;

            deckLink = null;
            IDeckLinkIterator deckLinkIterator = null;

            try
            {
                deckLinkIterator = new CDeckLinkIterator();

                int index = 0;
                do
                {
                    if (deckLink != null)
                    {
                        Marshal.ReleaseComObject(deckLink);
                        deckLink = null;
                    }

                    deckLinkIterator.Next(out deckLink);
                    if (index == inputIndex)
                    {
                        Success = true;
                        break;
                    }

                    index++;
                }while (deckLink != null);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            finally
            {
                if (deckLinkIterator != null)
                {
                    Marshal.ReleaseComObject(deckLinkIterator);
                    deckLinkIterator = null;
                }
            }

            return(Success);
        }
Exemple #23
0
        void AddDevice(IDeckLink decklinkDevice)
        {
            DeckLinkOutputDevice deckLink = new DeckLinkOutputDevice(decklinkDevice);

            if (deckLink.deckLinkOutput != null)
            {
                comboBoxOutputDevice.BeginUpdate();
                comboBoxOutputDevice.Items.Add(new StringObjectPair <DeckLinkOutputDevice>(deckLink.deviceName, deckLink));
                comboBoxOutputDevice.EndUpdate();

                if (comboBoxOutputDevice.Items.Count == m_number)
                {
                    comboBoxOutputDevice.SelectedIndex = m_number - 1;
                    //  StartRunning();
                }
            }
        }
        void AddDevice(IDeckLink decklinkDevice)
        {
            DeckLinkOutputDevice deckLink = new DeckLinkOutputDevice(decklinkDevice);

            if (deckLink.deckLinkOutput != null)
            {
                comboBoxOutputDevice.BeginUpdate();
                comboBoxOutputDevice.Items.Add(new StringObjectPair <DeckLinkOutputDevice>(deckLink.deviceName, deckLink));
                comboBoxOutputDevice.EndUpdate();

                if (comboBoxOutputDevice.Items.Count == 1)
                {
                    comboBoxOutputDevice.SelectedIndex = 0;

                    EnableInterface(true);
                }
            }
        }
            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;
                }
            }
        public DeckLinkOutputDevice(IDeckLink deckLink)
        {
            m_deckLink = deckLink;

            // Get output interface
            try
            {
                m_deckLinkOutput = (IDeckLinkOutput)m_deckLink;
            }
            catch (InvalidCastException)
            {
                // No output interface found, eg in case of DeckLink Mini Recorder
                return;
            }

            // Provide the delegate to the audio and video output interfaces
            m_deckLinkOutput.SetScheduledFrameCompletionCallback(this);
            m_deckLinkOutput.SetAudioCallback(this);
        }
Exemple #27
0
        void IBMDStreamingDeviceNotificationCallback.StreamingDeviceRemoved(IDeckLink device)
        {
            // We only care about removal of the device we are using
            if (device != streamingDevice)
            {
                return;
            }

            streamingDeviceInput.SetCallback(null);

            streamingDeviceInput = null;
            streamingDevice      = null;

            StopStreaming();

            if (callback != null)
            {
                callback.DeviceRemoved();
            }
        }
        void AddDevice(IDeckLink decklinkInputDevice)
        {
            DeckLinkInputDevice deckLink = new DeckLinkInputDevice(decklinkInputDevice);


            if (deckLink.deckLinkInput != null)
            {
                comboBoxInputDevice.BeginUpdate();
                comboBoxInputDevice.Items.Add(new StringObjectPair <DeckLinkInputDevice>(deckLink.deviceName, deckLink));
                comboBoxInputDevice.EndUpdate();
                deckLink.SetID(m_mainWindow, m_number);


                if (comboBoxInputDevice.Items.Count == m_number)
                {
                    comboBoxInputDevice.SelectedIndex = m_number - 1;
                    EnableInterface(true);
                    buttonStartStop.Enabled = true;
//                    StartCapture();
                }
            }
        }
Exemple #29
0
		private void Refresh()
		{
			FSerialPort.SliceCount = FInput.SliceCount;
			FSerialPortName.SliceCount = FInput.SliceCount;
			FPinOutStatus.SliceCount = FInput.SliceCount;

			for (int i = 0; i < FInput.SliceCount; i++)
			{
				try
				{
					IDeckLink device = FInput[i];
					IDeckLinkAttributes attributes;

					attributes.GetFloat(_BMDDeckLinkAttributeID.

					FPinOutStatus[i] = "Not implemented (no reference material available)";
				}
				catch (Exception e)
				{
					FPinOutStatus[i] = e.Message;
				}
			}
		}
Exemple #30
0
 private void StartDecklinkInput(DeckLinkAPI.IDeckLink device)
 {
     this.device = device;
     input = (DeckLinkAPI.IDeckLinkInput)device;
     input.SetCallback(this);
     input.EnableVideoInput(_BMDDisplayMode.bmdModeHD1080p25, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault);
     input.StartStreams();
     frameCount = 0;
 }
Exemple #31
0
 // DeckLink Device Removed
 public void DeckLinkDeviceRemoved(IDeckLink deckLinkDevice)
 {
 }
Exemple #32
0
 // DeckLink Device Arrived
 public void DeckLinkDeviceArrived(IDeckLink deckLinkDevice)
 {
 }
Exemple #33
0
		public Source(IDeckLink device, ModeRegister.Mode mode, bool useDeviceCallbacks)
		{
			this.Initialise(device, mode, useDeviceCallbacks);
		}
Exemple #34
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;
			}
		}
Exemple #35
0
		private Decklink(IDeckLink cDevice)
		{
			(new Logger()).WriteDebug3("in");
			try
			{
				nAudioQueueLength = nAudioQueueLengthPrevious = 0;
				nBTLAudioQueueLengthPrevious = nBTLVideoQueueLengthPrevious = nVideoQueueLengthPrevious = 0;
				_iDLDevice = cDevice;
				if(Preferences.bDeviceInput)
					_iDLInput = (IDeckLinkInput)_iDLDevice;
				else
					_iDLOutput = (IDeckLinkOutput)_iDLDevice;

				IDeckLinkDisplayModeIterator cDisplayModeIterator;
				IDeckLinkDisplayMode cNextDLDisplayMode;
				string sDisplayModeName = "";

				string sMessage = "decklink supported modes:<br>";
				if (Preferences.bDeviceInput)
				{
					_iDLInputDisplayMode = null;
					_iDLInput.GetDisplayModeIterator(out cDisplayModeIterator);
					while (true)
					{
						cDisplayModeIterator.Next(out cNextDLDisplayMode);
						if (cNextDLDisplayMode == null)
							break;
						cNextDLDisplayMode.GetName(out sDisplayModeName);
						if (null == _iDLInputDisplayMode && sDisplayModeName.ToLower().Contains(Preferences.sVideoFormat))
						{
							sMessage += "selected:";
							_iDLInputDisplayMode = cNextDLDisplayMode;
						}
						else
							sMessage += "\t";
						sMessage += sDisplayModeName + "<br>";
					}
					(new Logger()).WriteNotice(sMessage);
					if (null == _iDLInputDisplayMode)
						throw new Exception("can't find " + Preferences.sVideoFormat + " mode within specified device for input");
				}
				else
				{
					_nFramesAudioDropped = 0;
					_iDLOutputDisplayMode = null;
					_iDLOutput.GetDisplayModeIterator(out cDisplayModeIterator);
					while (true)
					{

						cDisplayModeIterator.Next(out cNextDLDisplayMode);
						if (cNextDLDisplayMode == null)
							break;
						cNextDLDisplayMode.GetName(out sDisplayModeName);
						if (null == _iDLOutputDisplayMode && sDisplayModeName.ToLower().Contains(Preferences.sVideoFormat))
						{
							sMessage += "selected:";
							_iDLOutputDisplayMode = cNextDLDisplayMode;
						}
						else
							sMessage += "\t";
						sMessage += sDisplayModeName + "<br>";
					}
					(new Logger()).WriteNotice(sMessage);
					if (null == _iDLOutputDisplayMode)
						throw new Exception("can't find " + Preferences.sVideoFormat + " mode within specified device for output");
					stArea = new Area(0, 0, (ushort)_iDLOutputDisplayMode.GetWidth(), (ushort)_iDLOutputDisplayMode.GetHeight());

					long nFrameDuration, nFrameTimescale;
					_iDLOutputDisplayMode.GetFrameRate(out nFrameDuration, out nFrameTimescale);
					_nFPS = (ushort)((nFrameTimescale + (nFrameDuration - 1)) / nFrameDuration); //до ближайшего целого - взято из примера деклинка

					_bDoWritingFrames = false;
					_aqWritingFrames = new Queue<byte[]>();
					_cThreadWritingFramesWorker = new System.Threading.Thread(WritingFramesWorker);
					_cThreadWritingFramesWorker.IsBackground = true;
					_cThreadWritingFramesWorker.Priority = System.Threading.ThreadPriority.Normal;
					_cThreadWritingFramesWorker.Start();

					if (Preferences.bAudio)
					{
						switch (Preferences.nAudioBitDepth)
						{
							case 32:
								_eAudioSampleDepth = _BMDAudioSampleType.bmdAudioSampleType32bitInteger;
								break;
							case 16:
							default:
								_eAudioSampleDepth = _BMDAudioSampleType.bmdAudioSampleType16bitInteger;
								break;
						}
						switch (Preferences.nAudioSamplesRate)
						{
							case 48000:
								_eAudioSampleRate = _BMDAudioSampleRate.bmdAudioSampleRate48kHz;
								break;
							default:
								throw new Exception("unsupported audio sample rate [" + Preferences.nAudioSamplesRate + "]");
						}
						//_pAudioSamplesBuffer = Marshal.AllocCoTaskMem((int)_nAudioFrameSize_InBytes);
						_cAudioBuffer = new AudioBuffer();
						_nAudioBufferCapacity_InSamples = Preferences.nAudioSamplesPerFrame * Preferences.nQueueDeviceLength;
						//for (int nIndx = 0; _nAudioFrameSize_InBytes > nIndx; nIndx++)
						//    Marshal.WriteByte(_pAudioSamplesBuffer, nIndx, 0);

						_nTimescale = (ushort)_eAudioSampleRate;
						_nFrameDuration = (ushort)(_nTimescale / _nFPS);
					}
					if (null != Preferences.cDownStreamKeyer)
						_iDeckLinkKeyer = (IDeckLinkKeyer)_iDLDevice;
				}
			}
			catch (Exception ex)
			{
				(new Logger()).WriteError(ex);
				throw;
			}
			(new Logger()).WriteDebug4("return");
		}