/// <summary> /// SetScreenPreviewCallback /// </summary> public void DrawFrame(IDeckLinkVideoFrame theFrame) { if (theFrame == null) { return; } try { if (!_Streaming) { return; } Interlocked.Increment(ref _PreviewCount); Run(() => previewCount.Text = _PreviewCount.ToString()); _GLHelper.SetFrame(theFrame); previewBox.MakeCurrent(); _GLHelper.PaintGL(); previewBox.SwapBuffers(); previewBox.Context.MakeCurrent(null); } finally { Marshal.ReleaseComObject(theFrame); } }
// Explicit implementation of IDeckLinkVideoOutputCallback and IDeckLinkAudioOutputCallback void IDeckLinkVideoOutputCallback.ScheduledFrameCompleted(IDeckLinkVideoFrame completedFrame, _BMDOutputFrameCompletionResult result) { if (FrameDrawnCallback != null) { FrameDrawnCallback((int)m_totalFramesScheduled); } }
void FillARGBColourBars(IDeckLinkVideoFrame theFrame) { IntPtr buffer; int width, height; // UInt32[] bars = { 0xEAEAEAFF, 0x10EAEAFF, 0xEAEA10FF, 0xEA10EAFF, 0x10EA10FF, 0x1010EAFF , 0xEA1010FF, 0x101010FF }; // UInt32[] bars = { 0x101010FF , 0xEA1010FF, 0xEAEA10FF, 0xEA10EAFF, 0x10EA10FF, 0x10EAEAFF, 0x1010EAFF, 0xEAEAEAFF };//reversed UInt32[] bars = { 0xFF101010, 0x10FF1010, 0x1010FF10, 0x101010FF, 0x101010FF, 0x1010FF10, 0x10FF1010, 0xFF101010 };//PruhARGBBGRA int index = 0; theFrame.GetBytes(out buffer); width = theFrame.GetWidth(); height = theFrame.GetHeight(); for (uint y = 0; y < height; y++) { for (uint x = 0; x < width; x++) { // Write directly into unmanaged buffer Marshal.WriteInt32(buffer, index * 4, (Int32)bars[(x * 8) / width]); index++; } } }
// Explicit implementation of IDeckLinkVideoOutputCallback and IDeckLinkAudioOutputCallback void IDeckLinkVideoOutputCallback.ScheduledFrameCompleted(IDeckLinkVideoFrame completedFrame, _BMDOutputFrameCompletionResult result) { // Note: if you throw an exception, it will be ignored by the caller. // When a frame has been completed ScheduleNextFrame(false); }
public void DisplayVideoFrame(IDeckLinkVideoFrame videoFrame) { if (!m_videoOutputEnabled) { throw new DeckLinkOutputNotEnabledException(); } m_deckLinkOutput.DisplayVideoFrameSync(videoFrame); }
// Explicit implementation of IDeckLinkVideoOutputCallback and IDeckLinkAudioOutputCallback void IDeckLinkVideoOutputCallback.ScheduledFrameCompleted(IDeckLinkVideoFrame completedFrame, _BMDOutputFrameCompletionResult result) { // When a video frame has been completed, generate event to schedule next frame var handler = VideoFrameCompletedHandler; // Check whether any subscribers to VideoFrameCompletedHandler event if (handler != null) { handler(this, new DeckLinkOutputFrameCompletitonEventArgs(result)); } }
void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame) { // First, pass the frame to the DeckLink screen preview helper m_previewHelper.SetFrame(theFrame); SetTimecode(theFrame); // Then draw the frame to the scene Render(); System.Runtime.InteropServices.Marshal.ReleaseComObject(theFrame); }
void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame) { if (!glIsInitialized) { return; } // First, pass the frame to the DeckLink screen preview helper SetTimecode(theFrame); m_previewHelper.SetFrame(theFrame); capturedFrames++; Invalidate(); System.Runtime.InteropServices.Marshal.ReleaseComObject(theFrame); }
void SetTimecode(IDeckLinkVideoFrame videoFrame) { IDeckLinkTimecode timecode; m_timeCodeString = "00:00:00:00"; videoFrame.GetTimecode(_BMDTimecodeFormat.bmdTimecodeRP188Any, out timecode); if (timecode != null) { timecode.GetString(out m_timeCodeString); } }
private void VideoFrameArrived(object sender, DeckLinkVideoFrameArrivedEventArgs e) { checkBoxInputValid.Checked = !e.inputInvalid; if (e.inputInvalid) { if (++m_invalidFrameTimeout == kInputInvalidFrameTimeout) { if (MessageBox.Show("Timeout waiting for valid input signal.", "Invalid frame timeout") == DialogResult.OK) { if (m_captureInvalidCancel != null) { m_captureInvalidCancel.Cancel(); } } } } else if (++m_captureFrameIntervalCount == numericUpDownCaptureFrameInterval.Value) { IntPtr bgra32FrameBytes; String outputFileName = m_selectedFolder + "\\image_" + m_captureStillsCount.ToString("D4") + "." + comboBoxFileType.SelectedItem.ToString().ToLower(); if (File.Exists(outputFileName)) { if (MessageBox.Show("File " + outputFileName + " already exists, stopping capture", "File Exists") == DialogResult.OK) { if (m_captureFileExists != null) { m_captureFileExists.Cancel(); } return; } } IDeckLinkVideoFrame bgra32Frame = m_frameConverter.ConvertFrame(e.videoFrame); bgra32Frame.GetBytes(out bgra32FrameBytes); using (Bitmap bgra32Bitmap = new Bitmap(bgra32Frame.GetWidth(), bgra32Frame.GetHeight(), bgra32Frame.GetRowBytes(), PixelFormat.Format32bppArgb, bgra32FrameBytes)) { bgra32Bitmap.Save(outputFileName, (ImageFormat)comboBoxFileType.SelectedItem); } m_captureFrameIntervalCount = 0; m_captureStillsCount++; if (m_captureCountdown != null) { m_captureCountdown.Signal(); } } }
void SetTimecode(IDeckLinkVideoFrame videoFrame) { IDeckLinkTimecode timecode; m_timeCodeString = "--:--:--:--"; videoFrame.GetTimecode(_BMDTimecodeFormat.bmdTimecodeRP188Any, out timecode); videoFrame.GetTimecode(_BMDTimecodeFormat.bmdTimecodeVITC, out timecode); if (timecode != null) { timecode.GetString(out m_timeCodeString); } else { m_timeCodeString = capturedFrames.ToString(); } }
public IDeckLinkVideoFrame ConvertFrame(IDeckLinkVideoFrame srcFrame) { IDeckLinkVideoFrame dstFrame; // Check whether srcFrame is already bmdFormat8BitBGRA if (srcFrame.GetPixelFormat() == _BMDPixelFormat.bmdFormat8BitBGRA) { dstFrame = srcFrame; } else { dstFrame = new Bgra32VideoFrame(srcFrame.GetWidth(), srcFrame.GetHeight(), srcFrame.GetFlags()) as IDeckLinkVideoFrame; m_deckLinkConversion.ConvertFrame(srcFrame, dstFrame); } return(dstFrame); }
void FillBlack(IDeckLinkVideoFrame theFrame) { IntPtr buffer; int width, height; int wordsRemaining; UInt32 black = 0x10801080; int index = 0; theFrame.GetBytes(out buffer); width = theFrame.GetWidth(); height = theFrame.GetHeight(); wordsRemaining = (width * 2 * height) / 4; while (wordsRemaining-- > 0) { Marshal.WriteInt32(buffer, index * 4, (Int32)black); index++; } }
void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame) { // First, pass the frame to the DeckLink screen preview helper //if (theFrame == null) //{ // return; //} try { if (previewHelper != null) { previewHelper.SetFrame(theFrame); Render(); } } finally { Marshal.ReleaseComObject(theFrame); } }
void FillBlack(IDeckLinkVideoFrame theFrame) { IntPtr buffer; int width, height; UInt32[] bars = { 0x11111111, 0xAAAAAAAA, 0x11111111, 0xAAAAAAAA, 0x11111111, 0xAAAAAAAA, 0x11111111, 0xAAAAAAAA }; int index = 0; theFrame.GetBytes(out buffer); width = theFrame.GetWidth(); height = theFrame.GetHeight(); for (uint y = 0; y < height; y++) { for (uint x = 0; x < width; x += 1) { // Write directly into unmanaged buffer Marshal.WriteInt32(buffer, index * 4, (Int32)bars[(x * 8) / width]); index++; } } }
void FillColourBars(IDeckLinkVideoFrame theFrame) { IntPtr buffer; int width, height; UInt32[] bars = { 0xEA80EA80, 0xD292D210, 0xA910A9A5, 0x90229035, 0x6ADD6ACA, 0x51EF515A, 0x286D28EF, 0x10801080 }; int index = 0; theFrame.GetBytes(out buffer); width = theFrame.GetWidth(); height = theFrame.GetHeight(); for (uint y = 0; y < height; y++) { for (uint x = 0; x < width; x += 2) { // Write directly into unmanaged buffer Marshal.WriteInt32(buffer, index * 4, (Int32)bars[(x * 8) / width]); index++; } } }
public void ScheduledFrameCompleted(IDeckLinkVideoFrame completedFrame, _BMDOutputFrameCompletionResult result) { /* * Have the roating cube here as it will * Move at a realtive frequency to the updates * to the decklink card */ if (squareRotx >= 360) { squareRotx = 0.0f; } if (squareRoty >= 360) { squareRoty = 0.0f; } squareRotx += 1.5f; squareRoty += 0.5f; _deckLinkOutput.ScheduleVideoFrame(_videoFrame, (_totalFrames * _frameDuration), _frameDuration, _frameTimescale); _totalFrames++; }
void IDeckLinkVideoOutputCallback.ScheduledFrameCompleted(IDeckLinkVideoFrame completedFrame, _BMDOutputFrameCompletionResult result) { try { switch (result) { case _BMDOutputFrameCompletionResult.bmdOutputFrameDisplayedLate: _nFramesLated++; (new Logger()).WriteNotice("frame lated. total:" + _nFramesLated); break; case _BMDOutputFrameCompletionResult.bmdOutputFrameDropped: _nFramesDropped++; (new Logger()).WriteNotice("frame dropped. total:" + _nFramesDropped); break; case _BMDOutputFrameCompletionResult.bmdOutputFrameFlushed: _nFramesFlushed++; (new Logger()).WriteNotice("frame flushed. total:" + _nFramesFlushed); break; //default: // (new Logger()).WriteDebug4("ScheduledFrameCompleted normal"); // break; } Frame.Video oFrame; Frame.Video[] aFramesOvertimed; long nNow = _cStopWatch.ElapsedMilliseconds; lock (_ahFramesBuffersBinds) { oFrame = _ahFramesBuffersBinds.FirstOrDefault(o => o.Value == completedFrame).Key; if (null != oFrame && _aCurrentFramesIDs.ContainsKey(oFrame.nID)) { (new Logger()).WriteDebug4("frame " + oFrame.nID + " was passed in " + (nNow - _aCurrentFramesIDs[oFrame.nID]) + " ms"); _aCurrentFramesIDs.Remove(oFrame.nID); } else if (0 < oFrame.nID) (new Logger()).WriteError("VERY STRANGE - 1 [id=" + oFrame.nID + "]"); foreach (ulong nVFid in _aCurrentFramesIDs.Keys.Where(o => (Preferences.nQueueDeviceLength * 40 + 500) < nNow - _aCurrentFramesIDs[o])) { (new Logger()).WriteDebug2("There are some over timed frames in decklink buffer: \n"); (new Logger()).WriteDebug2("\t\t[id=" + nVFid + "][delta=" + _aCurrentFramesIDs[nVFid] + "]\n"); } } if (null == oFrame) (new Logger()).WriteWarning("frame is not in _ahFramesBuffersBinds"); else { FrameBufferReleased(oFrame); } long nDelta = _cStopWatch.ElapsedMilliseconds - _nLastScTimeComplited; if (100 < nDelta || 1 > nDelta) (new Logger()).WriteDebug2("Last ScheduledFrameCompleted was " + nDelta + " ms ago"); _nLastScTimeComplited = _cStopWatch.ElapsedMilliseconds; _bNeedToAddFrame = true; #region закаменчено /* */ //bool bFound = false; //IntPtr pFrameLast = IntPtr.Zero; //if (completedFrame != _cFrameEmpty) //{ // IDeckLinkMutableVideoFrame iFrame = (IDeckLinkMutableVideoFrame)completedFrame; // if (0 > _aFramesRecovered.IndexOf(iFrame)) // { // lock (_ahFramesBuffersBinds) // { // foreach (IntPtr pFB in _ahFramesBuffersBinds.Keys.ToArray()) // { // if (iFrame == _ahFramesBuffersBinds[pFB]) // { // _ahFramesBuffersBinds.Remove(pFB); // pFrameLast = pFB; // bFound = true; // break; // } // } // } // } // else // { // bFound = true; // _aFramesRecovered.Remove(iFrame); // } //} //if (!bFound) // throw new Exception("не найден показанный кадр"); //if (Preferences.bFrameLastSave && IntPtr.Zero != pFrameLast) //{ // if (null == aFrameLastBytes) // aFrameLastBytes = new byte[completedFrame.GetHeight() * completedFrame.GetRowBytes()]; // lock (aFrameLastBytes) // Marshal.Copy(pFrameLast, aFrameLastBytes, 0, aFrameLastBytes.Length); //} #endregion } catch (Exception ex) { (new Logger()).WriteError(ex); } }
public void ScheduledFrameCompleted(IDeckLinkVideoFrame completedFrame, _BMDOutputFrameCompletionResult result) { ScheduleFrame(false); }
// Draw Frame public void DrawFrame(IDeckLinkVideoFrame theFrame) { }
// Explicit implementation of IDeckLinkVideoOutputCallback and IDeckLinkAudioOutputCallback void IDeckLinkVideoOutputCallback.ScheduledFrameCompleted(IDeckLinkVideoFrame completedFrame, _BMDOutputFrameCompletionResult result) { // When a video frame has been completed, generate event to schedule next frame VideoFrameCompleted(false); }
public void ScheduledFrameCompleted(IDeckLinkVideoFrame completedFrame, _BMDOutputFrameCompletionResult result) { System.Diagnostics.Debug.WriteLine("ScheduledFrameCompleted: " + result); ScheduleNextFrame(false); }
public void DrawFrame(IDeckLinkVideoFrame theFrame) { System.Diagnostics.Debug.WriteLine("theFrame"); }
void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame iVideoInputFrame, IDeckLinkAudioInputPacket iAudioPacket) { try { if (bAVFrameArrivedAttached) { IDeckLinkVideoFrame iVideoFrame = iVideoInputFrame; IntPtr pBytesVideo = IntPtr.Zero, pBytesAudio = IntPtr.Zero; int nBytesVideoQty = 0, nBytesAudioQty = 0; if (null != iVideoFrame) { if (null != _iDLVideoConversion) { _iDLVideoConversion.ConvertFrame(iVideoFrame, _iVideoFrameTarget); iVideoFrame = _iVideoFrameTarget; } _iVideoFrameLast = iVideoFrame; } else { nFramesDroppedVideo++; iVideoFrame = _iVideoFrameLast; (new Logger()).WriteWarning("video frame dropped"); } if (null != iVideoFrame) { iVideoFrame.GetBytes(out pBytesVideo); if (IntPtr.Zero != pBytesVideo) { nBytesVideoQty = iVideoFrame.GetRowBytes() * iVideoFrame.GetHeight(); nFramesVideo++; } else (new Logger()).WriteWarning("video frame is empty"); } if (null != iAudioPacket) { iAudioPacket.GetBytes(out pBytesAudio); if (IntPtr.Zero != pBytesAudio) { nBytesAudioQty = iAudioPacket.GetSampleFrameCount() * ((int)_BMDAudioSampleType.bmdAudioSampleType16bitInteger / 8) * 2; nFramesAudio++; } else (new Logger()).WriteWarning("audio frame is empty"); } else { nFramesDroppedAudio++; (new Logger()).WriteWarning("audio frame dropped"); } OnAVFrameArrived(nBytesVideoQty, pBytesVideo, nBytesAudioQty, pBytesAudio); } } catch (Exception ex) { (new Logger()).WriteError(ex); } }