Esempio n. 1
0
        public void Start()
        {
            uint audioChannelCount = 2;
            _BMDAudioSampleType audioSampleDepth = _BMDAudioSampleType.bmdAudioSampleType16bitInteger;
            _BMDAudioSampleRate audioSampleRate  = _BMDAudioSampleRate.bmdAudioSampleRate48kHz;

            deckLinkOutput.EnableVideoOutput(displayMode.GetDisplayMode(), _BMDVideoOutputFlags.bmdVideoOutputFlagDefault);
            deckLinkOutput.EnableAudioOutput(audioSampleRate, audioSampleDepth, audioChannelCount, _BMDAudioOutputStreamType.bmdAudioOutputStreamContinuous);

            deckLinkOutput.CreateVideoFrame(frameWidth, frameHeight, frameWidth * 2, _BMDPixelFormat.bmdFormat8BitYUV, _BMDFrameFlags.bmdFrameFlagDefault, out videoFrameBlack);
            FillBlack(videoFrameBlack);

            deckLinkOutput.CreateVideoFrame(frameWidth, frameHeight, frameWidth * 2, _BMDPixelFormat.bmdFormat8BitYUV, _BMDFrameFlags.bmdFrameFlagDefault, out videoFrameBars);
            FillColourBars(videoFrameBars);

            totalFramesScheduled = 0;
            for (uint i = 0; i < framesPerSecond; i++)
            {
                ScheduleNextFrame(true);
            }

            deckLinkOutput.BeginAudioPreroll();

            running = true;
        }
        private void StartRunning()
        {
            m_selectedDevice.VideoFrameCompleted  += new DeckLinkVideoOutputHandler((b) => this.BeginInvoke((Action)(() => { ScheduleNextFrame(b); })));
            m_selectedDevice.AudioOutputRequested += new DeckLinkAudioOutputHandler(() => this.BeginInvoke((Action)(() => { WriteNextAudioSamples(); })));
            m_selectedDevice.PlaybackStopped      += new DeckLinkPlaybackStoppedHandler(() => this.BeginInvoke((Action)(() => { DisableOutput(); })));

            m_outputSignal      = ((StringObjectPair <OutputSignal>)comboBoxOutputSignal.SelectedItem).value;
            m_audioChannelCount = (uint)((int)comboBoxAudioChannels.SelectedItem);
            m_audioSampleDepth  = ((StringObjectPair <_BMDAudioSampleType>)comboBoxAudioDepth.SelectedItem).value;
            m_audioSampleRate   = _BMDAudioSampleRate.bmdAudioSampleRate48kHz;
            //
            //- Extract the IDeckLinkDisplayMode from the display mode popup menu
            m_frameWidth  = m_selectedDisplayMode.GetWidth();
            m_frameHeight = m_selectedDisplayMode.GetHeight();
            m_selectedDisplayMode.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);

            // Set the video output mode
            m_selectedDevice.deckLinkOutput.EnableVideoOutput(m_selectedDisplayMode.GetDisplayMode(), _BMDVideoOutputFlags.bmdVideoOutputFlagDefault);

            // Set the audio output mode
            m_selectedDevice.deckLinkOutput.EnableAudioOutput(m_audioSampleRate, m_audioSampleDepth, m_audioChannelCount, _BMDAudioOutputStreamType.bmdAudioOutputStreamContinuous);

            // Set screen preview callback
            m_selectedDevice.deckLinkOutput.SetScreenPreviewCallback(previewWindow);

            // Generate one second of audio
            m_audioBufferSampleLength = (uint)((m_framesPerSecond * (uint)m_audioSampleRate * m_frameDuration) / m_frameTimescale);
            m_audioBuffer             = Marshal.AllocCoTaskMem((int)(m_audioBufferSampleLength * m_audioChannelCount * ((uint)m_audioSampleDepth / 8)));

            // Zero the buffer (interpreted as audio silence)
            for (int i = 0; i < (m_audioBufferSampleLength * m_audioChannelCount * (uint)m_audioSampleDepth / 8); i++)
            {
                Marshal.WriteInt32(m_audioBuffer, i, 0);
            }
            uint audioSamplesPerFrame = (uint)(((uint)m_audioSampleRate * m_frameDuration) / m_frameTimescale);

            if (m_outputSignal == OutputSignal.kOutputSignalPip)
            {
                FillSine(m_audioBuffer, audioSamplesPerFrame, m_audioChannelCount, m_audioSampleDepth);
            }
            else
            {
                FillSine(new IntPtr(m_audioBuffer.ToInt64() + (audioSamplesPerFrame * m_audioChannelCount * (uint)m_audioSampleDepth / 8)), (m_audioBufferSampleLength - audioSamplesPerFrame), m_audioChannelCount, m_audioSampleDepth);
            }

            // Generate a frame of black
            m_videoFrameBlack = CreateOutputVideoFrame(FillBlack);

            // Generate a frame of colour bars
            m_videoFrameBars = CreateOutputVideoFrame(FillColourBars);

            // Begin video preroll by scheduling a second of frames in hardware
            m_totalFramesScheduled = 0;
            for (uint i = 0; i < m_framesPerSecond; i++)
            {
                ScheduleNextFrame(true);
            }

            // Begin audio preroll.  This will begin calling our audio callback, which will start the DeckLink output stream.
            m_audioBufferOffset = 0;
            m_selectedDevice.deckLinkOutput.BeginAudioPreroll();

            m_running            = true;
            buttonStartStop.Text = "Stop";
        }
        private void StartRunning()
        {
            m_outputSignal      = ((StringObjectPair <OutputSignal>)comboBoxOutputSignal.SelectedItem).value;
            m_audioChannelCount = uint.Parse((string)comboBoxAudioChannels.SelectedItem);
            m_audioSampleDepth  = ((StringObjectPair <_BMDAudioSampleType>)comboBoxAudioDepth.SelectedItem).value;
            m_audioSampleRate   = _BMDAudioSampleRate.bmdAudioSampleRate48kHz;
            //
            //- Extract the IDeckLinkDisplayMode from the display mode popup menu
            IDeckLinkDisplayMode videoDisplayMode;

            videoDisplayMode = ((DisplayModeEntry)comboBoxVideoFormat.SelectedItem).displayMode;
            m_frameWidth     = videoDisplayMode.GetWidth();
            m_frameHeight    = videoDisplayMode.GetHeight();
            videoDisplayMode.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);

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

            // Set the audio output mode
            m_deckLinkOutput.EnableAudioOutput(m_audioSampleRate, m_audioSampleDepth, m_audioChannelCount, _BMDAudioOutputStreamType.bmdAudioOutputStreamContinuous);

            // Generate one second of audio
            m_audioBufferSampleLength = (uint)((m_framesPerSecond * (uint)m_audioSampleRate * m_frameDuration) / m_frameTimescale);
            m_audioBuffer             = Marshal.AllocCoTaskMem((int)(m_audioBufferSampleLength * m_audioChannelCount * ((uint)m_audioSampleDepth / 8)));

            // Zero the buffer (interpreted as audio silence)
            for (int i = 0; i < (m_audioBufferSampleLength * m_audioChannelCount * (uint)m_audioSampleDepth / 8); i++)
            {
                Marshal.WriteInt32(m_audioBuffer, i, 0);
            }
            uint audioSamplesPerFrame = (uint)(((uint)m_audioSampleRate * m_frameDuration) / m_frameTimescale);

            if (m_outputSignal == OutputSignal.kOutputSignalPip)
            {
                FillSine(m_audioBuffer, audioSamplesPerFrame, m_audioChannelCount, m_audioSampleDepth);
            }
            else
            {
                FillSine(new IntPtr(m_audioBuffer.ToInt64() + (audioSamplesPerFrame * m_audioChannelCount * (uint)m_audioSampleDepth / 8)), (m_audioBufferSampleLength - audioSamplesPerFrame), m_audioChannelCount, m_audioSampleDepth);
            }

            // Generate a frame of black
            m_deckLinkOutput.CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth * 2, _BMDPixelFormat.bmdFormat8BitYUV, _BMDFrameFlags.bmdFrameFlagDefault, out m_videoFrameBlack);
            FillBlack(m_videoFrameBlack);

            // Generate a frame of colour bars
            m_deckLinkOutput.CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth * 2, _BMDPixelFormat.bmdFormat8BitYUV, _BMDFrameFlags.bmdFrameFlagDefault, out m_videoFrameBars);
            FillColourBars(m_videoFrameBars);

            // Begin video preroll by scheduling a second of frames in hardware
            m_totalFramesScheduled = 0;
            for (uint i = 0; i < m_framesPerSecond; i++)
            {
                ScheduleNextFrame(true);
            }

            // Begin audio preroll.  This will begin calling our audio callback, which will start the DeckLink output stream.
            m_audioBufferOffset = 0;
            m_deckLinkOutput.BeginAudioPreroll();

            m_running            = true;
            buttonStartStop.Text = "Stop";
        }
Esempio n. 4
0
 public AudioSampleRateEntry(_BMDAudioSampleRate sampleRate)
 {
     this.sampleRate = sampleRate;
 }
Esempio n. 5
0
        public void StartRunning()
        {
            //     m_selectedDevice.VideoFrameCompleted += new DeckLinkVideoOutputHandler((b) => this.BeginInvoke((Action)(() => { ScheduleNextFrame(b); })));
            m_selectedDevice.AudioOutputRequested += new DeckLinkAudioOutputHandler(() => this.BeginInvoke((Action)(() => { WriteNextAudioSamples(); })));
            m_selectedDevice.PlaybackStopped      += new DeckLinkPlaybackStoppedHandler(() => this.BeginInvoke((Action)(() => { DisableOutput(); })));

            m_audioChannelCount = 16;
            m_audioSampleDepth  = _BMDAudioSampleType.bmdAudioSampleType16bitInteger;
            m_audioSampleRate   = _BMDAudioSampleRate.bmdAudioSampleRate48kHz;
            //
            //- Extract the IDeckLinkDisplayMode from the display mode popup menu
            IDeckLinkDisplayMode videoDisplayMode;

            videoDisplayMode = ((DisplayModeEntry)comboBoxVideoFormat.SelectedItem).displayMode;
            m_frameWidth     = videoDisplayMode.GetWidth();
            m_frameHeight    = videoDisplayMode.GetHeight();
            videoDisplayMode.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);
            var mode = videoDisplayMode.GetDisplayMode();

            // Set the video output mode
            m_selectedDevice.deckLinkOutput.EnableVideoOutput(videoDisplayMode.GetDisplayMode(), _BMDVideoOutputFlags.bmdVideoOutputFlagDefault);

            // Set the audio output mode
            m_selectedDevice.deckLinkOutput.EnableAudioOutput(m_audioSampleRate, m_audioSampleDepth, m_audioChannelCount, _BMDAudioOutputStreamType.bmdAudioOutputStreamContinuous);

            // Generate one second of audio
            m_audioBufferSampleLength = (uint)(m_framesPerSecond * audioSamplesPerFrame());
            int m_audioBufferDataLength = (int)(m_audioBufferSampleLength * audioDataPerSample());

            m_audioBuffer          = Marshal.AllocCoTaskMem(m_audioBufferDataLength);
            m_audioBufferAllocated = true;

            lock (m_selectedDevice)
            {
                // Zero the buffer (interpreted as audio silence)
                for (int i = 0; i < m_audioBufferDataLength; i++)
                {
                    Marshal.WriteInt32(m_audioBuffer, i, 0);
                }
                FillSine(new IntPtr(m_audioBuffer.ToInt64()), m_audioBufferSampleLength, m_audioChannelCount, m_audioSampleDepth);
                m_audioBufferReadOffset  = 0;
                m_audioBufferWriteOffset = 0;
            }
            m_videoFrameARGBBars = CreateOutputVideoFrame(FillBGRAColourBars, _BMDPixelFormat.bmdFormat8BitARGB);
            m_videoFrame         = CreateOutputVideoFrame(FillARGBColourBars, _BMDPixelFormat.bmdFormat8BitARGB);
            m_videoFrameBars     = CreateOutputVideoFrame(FillColourBars);

            m_pixelFormat        = _BMDPixelFormat.bmdFormat8BitBGRA;
            m_videoFrameBGRA     = CreateOutputVideoFrame(FillColourBars);
            m_videoFrameBGRABars = CreateOutputVideoFrame(FillBGRAColourBars, _BMDPixelFormat.bmdFormat8BitBGRA);
            m_pixelFormat        = _BMDPixelFormat.bmdFormat8BitARGB;

            m_running            = true;
            buttonStartStop.Text = "Stop";

            // Begin video preroll by scheduling a second of frames in hardware
            m_totalFramesScheduled = 0;
            for (uint i = 0; i < m_prerollFrames; i++)
            {
                ScheduleNextFrame(true);
            }

            // Begin audio preroll.  This will begin calling our audio callback, which will then start the DeckLink output stream - StartScheduledPlayback.
            m_selectedDevice.deckLinkOutput.BeginAudioPreroll();
            // StopRunning();
        }
Esempio n. 6
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");
		}