Example #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);
        }