Пример #1
0
        /// <summary>
        /// Calback function for new frame
        /// </summary>
        /// <param name="videoFrame"></param>
        /// <param name="audioPacket"></param>
        public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            // The conditions under which either of these cases occur are unclear but an overstreched processor doesn't help
            if (videoFrame == null || audioPacket == null)
            {
                return;
            }

            IDeckLinkTimecode timecode;

            videoFrame.GetTimecode(config.TimecodeFormat, out timecode);

            if (audioPacket.GetSampleFrameCount() != config.SamplesPerSlot * config.SlotsPerFrame)
            {
                throw new ApplicationException("Wrong buffer size");
            }

            IntPtr buffer;

            audioPacket.GetBytes(out buffer);
            var audioFingerprints = GetAudioFingerprints(buffer, config);

            var timecodeBcd = timecode?.GetBCD() ?? 0;

            FingerprintCreated?.Invoke(this, new FingerprintEventArgs(timecodeBcd, (byte)config.SlotsPerFrame, 0, audioFingerprints));

            // The documentation suggests that neither of these are necessary
            // BM's own code does the former
            // Including these doesn't make anything go bang so, in for a penny...
            Marshal.ReleaseComObject(videoFrame);
            Marshal.ReleaseComObject(audioPacket);
        }
Пример #2
0
        public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            IntPtr data;

            videoFrame.GetBytes(out data);
            ImageUtils.RawYUV2RGBA(data, FOutput.Data, FOutput.Image.ImageAttributes.PixelsPerFrame);
            //FOutput.Image.SetPixels(data);
            FOutput.Send();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);
        }
Пример #3
0
 public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
 {
     this.Lock.AcquireWriterLock(5000);
     try
     {
         videoFrame.GetBytes(out FData);
         System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);
         FreshData = true;
     }
     catch
     {
     }
     finally
     {
         this.Lock.ReleaseWriterLock();
     }
 }
Пример #4
0
        public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            try
            {
                if (videoFrame != null)
                {
                    IntPtr srcPtr;
                    videoFrame.GetBytes(out srcPtr);
                    System.Runtime.InteropServices.Marshal.Copy(srcPtr, mediaFrameBuffer, 0, videoFrame.GetRowBytes() * videoFrame.GetHeight());
                    pipeServer.SendPacket(mediaFrameBuffer, 0, videoFrame.GetRowBytes() * videoFrame.GetHeight());
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);
                    //unsafe
                    //{
                    //    fixed (byte* p = mediaFrameBuffer)
                    //    {
                    //        IntPtr ptr = (IntPtr)p;
                    //        Bitmap bmp = new Bitmap(960, 1080, 1920*2, System.Drawing.Imaging.PixelFormat.Format32bppRgb, ptr);
                    //        frameCount++;
                    //        //if (frameCount % 25 == 0)
                    //        {
                    //            if (InvokeRequired) this.Invoke((Action)(() =>
                    //            {
                    //                //this.frameCounterLabel.Text = "Frame count: " + frameCount++;

                    //                pictureBox.Image = bmp;
                    //            }));
                    //        }
                    //    }
                    //}
                }

                if (audioPacket != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(audioPacket);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Пример #5
0
        // Video Input Frame Arrival
        public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            IntPtr data;
            int    size = videoFrame.GetRowBytes() * videoFrame.GetHeight();

            videoFrame.GetBytes(out data);

            byte[] array = new byte[size];
            Marshal.Copy(data, array, 0, size);

            frameBuffer = array;

            /*int pixel;
             * bool fullVideo = false;
             * bool fullGraphics = false;
             * bool raceTag = false;
             * bool doubleBox = false;
             * bool lowerThird = false;
             * bool racing = false;
             *
             * Console.Clear();
             *
             * // Race Tag
             * if (PixelMatchesColor(array, 64200, 142, 48, 115) || PixelMatchesColor(array, 64200, 142, 48, 116))
             * {
             *  raceTag = true;
             *  Console.WriteLine("Race Tag: TRUE");
             * }
             * else
             *  Console.WriteLine("Race Tag: FALSE");
             * PrintColor(array, 64200);
             *
             * // Full Graphics
             * if (PixelMatchesColor(array, 25620, 141, 35, 118))
             * {
             *  fullGraphics = true;
             *  Console.WriteLine("Full Graphics: TRUE");
             * }
             * else
             *  Console.WriteLine("Full Graphics: FALSE");
             * PrintColor(array, 25620);
             *
             * // Lower Third
             * if (PixelMatchesColor(array, 832030, 140, 61, 119))
             * {
             *  lowerThird = true;
             *  Console.WriteLine("Lower Third: TRUE");
             * }
             * else
             *  Console.WriteLine("Lower Third: FALSE");
             * PrintColor(array, 832030);
             *
             * // Full Video
             * if (!PixelMatchesColor(array, 256150, 131, 216, 126))
             * {
             *  fullVideo = true;
             *  Console.WriteLine("Full Video: TRUE");
             * }
             * else
             *  Console.WriteLine("Full Video: FALSE");
             * PrintColor(array, 256150);
             *
             * // Double Box
             * if (PixelMatchesColor(array, 705200, 143, 48, 115))
             * {
             *  doubleBox = true;
             *  Console.WriteLine("Double Box: TRUE");
             * }
             * else
             *  Console.WriteLine("Double Box: FALSE");
             * PrintColor(array, 705200);
             *
             * // Racing
             * if (raceTag && !lowerThird && fullVideo && !fullGraphics)
             * {
             *  racing = true;
             *  Console.WriteLine("Racing: TRUE");
             * }
             * else
             *  Console.WriteLine("Racing: FALSE"); */
        }
Пример #6
0
        void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            if (videoFrame != null)
            {
                bool inputSignal = videoFrame.GetFlags().HasFlag(_BMDFrameFlags.bmdFrameHasNoInputSource);
                if (inputSignal != m_validInputSignal)
                {
                    m_validInputSignal = inputSignal;
                    InputSignalChanged(m_validInputSignal);
                }
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);
        }
Пример #7
0
 public DeckLinkAudioPacketArrivedEventArgs(IDeckLinkAudioInputPacket audioPacket)
 {
     this.audioPacket = audioPacket;
 }
Пример #8
0
        void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            if (videoFrame != null)
            {
                bool inputSignalAbsent = videoFrame.GetFlags().HasFlag(_BMDFrameFlags.bmdFrameHasNoInputSource);

                // Detect change in input signal, restart stream when valid stream detected
                if (!inputSignalAbsent && m_prevInputSignalAbsent)
                {
                    m_deckLinkInput.StopStreams();
                    m_deckLinkInput.FlushStreams();
                    m_deckLinkInput.StartStreams();
                }
                m_prevInputSignalAbsent = inputSignalAbsent;

                // Register video frame received event
                var handler = VideoFrameArrivedHandler;

                // Check whether there are any subscribers to VideoFrameArrivedHandler
                if (handler != null)
                {
                    handler(this, new DeckLinkVideoFrameArrivedEventArgs(videoFrame, inputSignalAbsent));
                }
            }

            if (audioPacket != null)
            {
                // Register audio packet received event
                var handler = AudioPacketArrivedHandler;

                // Check whether there are any subscribers to AudioPacketArrivedHandler
                if (handler != null)
                {
                    handler(this, new DeckLinkAudioPacketArrivedEventArgs(audioPacket));
                }
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);
        }
Пример #9
0
		public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
		{
			this.Lock.AcquireWriterLock(5000);
			try
			{
				videoFrame.GetBytes(out FData);
				System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);
				FreshData = true;
			}
			catch
			{

			}
			finally
			{
				this.Lock.ReleaseWriterLock();
			}
		}
Пример #10
0
        public void VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            if (videoFrame == null && audioPacket == null)
            {
                return;
            }
            try
            {
                if (!_Streaming)
                {
                    return;
                }
                if (!_VideoLock.Wait(TimeSpan.Zero))
                {
                    return;
                }
                try
                {
                    Interlocked.Increment(ref _FrameCount);
                    Run(() => frameCount.Text = _FrameCount.ToString());

                    if (videoFrame != null)
                    {
                        var rowBytes = videoFrame.GetRowBytes();
                        var height   = videoFrame.GetHeight();

                        IntPtr framePointer;
                        videoFrame.GetBytes(out framePointer);

                        var frame = new byte[rowBytes * height];
                        Marshal.Copy(framePointer, frame, 0, frame.Length);

                        if (writeRaw.Checked)
                        {
                            _VideoWriter.Write(frame);
                        }

                        if (writeEncoded.Checked)
                        {
                            _EncodeTask.Write(frame, 0, frame.Length);
                        }
                    }

                    if (audioPacket != null)
                    {
                        IntPtr audioPointer;
                        audioPacket.GetBytes(out audioPointer);

                        var frameCount = audioPacket.GetSampleFrameCount();

                        var audio = new byte[frameCount * _AudioChannels * (_AudioSampleDepth / 8)];
                        Marshal.Copy(audioPointer, audio, 0, audio.Length);

                        if (writeRaw.Checked)
                        {
                            _AudioWriter.Write(audio);
                        }
                    }
                }
                finally
                {
                    _VideoLock.Release();
                }
            }
            finally
            {
                if (videoFrame != null)
                {
                    Marshal.ReleaseComObject(videoFrame);
                }
                if (audioPacket != null)
                {
                    Marshal.ReleaseComObject(audioPacket);
                }
            }
        }
Пример #11
0
		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);
            }
        }
Пример #12
0
        void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            if (videoFrame != null)
            {
                try
                {
                    var frameFlags = videoFrame.GetFlags();

                    bool inputSignal = frameFlags.HasFlag(_BMDFrameFlags.bmdFrameHasNoInputSource);

                    if (inputSignal != validInputSignal)
                    {
                        validInputSignal = inputSignal;
                        InputSignalChanged?.Invoke(validInputSignal);
                    }
                    else
                    {
                        int width  = videoFrame.GetWidth();
                        int height = videoFrame.GetHeight();
                        int stride = videoFrame.GetRowBytes();
                        var format = videoFrame.GetPixelFormat();

                        var bufferLength = stride * height;
                        videoFrame.GetBytes(out IntPtr pBuffer);

                        VideoDataArrived?.Invoke(pBuffer, bufferLength, 0);


                        //var f = File.Create(@"d:\testBMP2\" + DateTime.Now.ToString("HH_mm_ss_fff") + " " + width + "x" + height + "_" + format + ".raw");

                        //byte[] data = new byte[bufferLength];
                        //Marshal.Copy(pBuffer, data, 0, data.Length);
                        //f.Write(data, 0, data.Length);
                        //f.Close();
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(videoFrame);
                }
            }


            if (audioPacket != null)
            {
                try
                {
                    long packetTime = 0;
                    //audioPacket.GetPacketTime(out packetTime, 30000);

                    int sampleSize   = ((int)AudioSampleType / 8); //32bit
                    int samplesCount = audioPacket.GetSampleFrameCount();
                    int dataLength   = sampleSize * AudioChannelsCount * samplesCount;

                    if (dataLength > 0)
                    {
                        audioPacket.GetBytes(out IntPtr pBuffer);

                        if (pBuffer != IntPtr.Zero)
                        {
                            byte[] data = new byte[dataLength];
                            Marshal.Copy(pBuffer, data, 0, data.Length);

                            AudioDataArrived?.Invoke(data, packetTime);
                        }
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(audioPacket);
                }
            }
        }
Пример #13
0
        void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            IntPtr audioData = (IntPtr)0;
            IntPtr videoData = (IntPtr)0;

            if (videoFrame != null)
            {
                bool inputSignalChange = videoFrame.GetFlags().HasFlag(_BMDFrameFlags.bmdFrameHasNoInputSource);
                if (inputSignalChange != m_validInputSignal)
                {
                    m_validInputSignal = inputSignalChange;
                    InputSignalChanged(m_validInputSignal);
                }
                if (inputSignalChange == false) //i.e. frame is valid
                {
                    videoFrame.GetBytes(out videoData);
                    m_mainWindow.callFrameLoop(m_number, videoData);
                }
            }
            if (audioPacket != null)
            {
                audioPacket.GetBytes(out audioData);
                m_mainWindow.handleAudio(m_number, audioData);
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(audioPacket);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(videoFrame);
        }