static void OnNewFrame(object sender, NewFrameEventArgs e) { Logger.Debug("Writing frame on timestamp " + e.Timestamp.ToLocalTime().ToString(@"yyyy-MM-dd HH:mm:ss.ffffff")); server.Write(e.Frame); }
/// <summary> /// 从嵌套的视频源处接收到新的帧 /// </summary> /// <param name="sender">发送者</param> /// <param name="e">新的帧</param> private void OnNestedVideoSourceNewFrame(object sender, NewFrameEventArgs e) { // don't even try doing something if there are no clients if (NewFrame == null) return; // 是否判断跳帧 if (SkipFramesIfBusy) { // 如果还在处理上一帧,则跳帧 if (!isProcessingThreadAvailable.WaitOne(0, false)) { // return in the case if image processing thread is still busy and // we are allowed to skip frames return; } } else { // make sure image processing thread is available in the case we cannot skip frames isProcessingThreadAvailable.WaitOne(); } // pass the image to processing frame and exit lastVideoFrame = (Bitmap)e.Frame.Clone(); isNewFrameAvailable.Set(); }
private void OnVideoSourceNewFrame(object sender, NewFrameEventArgs e) { if (e == null || e.Frame == null) return; DateTime now = DateTime.Now; if (now > e.Timestamp && (now - e.Timestamp).TotalSeconds >= 3) { // 如果时差超过一定时间则丢帧 return; } try { Bitmap frame = e.Frame; // 原始图像翻转 ProcessImageRotation(ref frame); // 原始图像时间戳 ProcessImageTimestamp(e.Timestamp, ref frame); // 原始图像OSD ProcessImageOnScreenDisplay(ref frame); // 原始图像Logo ProcessImageLogo(ref frame); // 原始图像遮挡 ProcessImageProtectionMask(ref frame); // 原始图像移动侦测 ProcessImageMotionDetection(ref frame); // 设置非托管内存 SetUnmanagedLastFrame(frame); // 触发新帧事件 RaiseNewFrameEvent(); } catch (Exception ex) { Logger.Error(ex.Message); } }
private void OnNewFrame(object sender, NewFrameEventArgs e) { try { Bitmap bitmap = new Bitmap(e.Frame.Width, e.Frame.Height, PixelFormat.Format16bppRgb555); Graphics draw = Graphics.FromImage(bitmap); draw.DrawImage(e.Frame, 0, 0); // when new frame arrived, update the latest frame LatestFrame = bitmap; } catch { } if (!_isSending) { lock (_sendLock) { try { _isSending = true; lock (_destLock) { if (Sender != null) { foreach (var dest in Destinations) { _sequenceNumber = _sequenceNumber + 10; // give space to packet sender to split the packet Sender.Send(new StreamPacket(LatestFrame, _sequenceNumber, e.Timestamp, dest)); } } } } finally { _isSending = false; } } } }