Ejemplo n.º 1
0
        public void Start()
        {
            _videoSource.FrameReady += (_, frame) =>
            {
                double timeFromLast = DateTime.Now.Subtract(_previousSendTime).TotalSeconds;
                // Exit immediately if we did not find any face or the packet is to fast
                if (frame.Faces.Count == 0 || timeFromLast < 1 / _framerate)
                {
                    return;
                }

                // Prepare the packet to send over the net
                var packet = new VideoDataPacket()
                {
                    Timestamp   = new DateTimeOffset(frame.Timestamp).ToUnixTimeSeconds(),
                    FrameWidth  = frame.FrameWidth,
                    FrameHeight = frame.FrameHeight
                };
                foreach (var face in frame.Faces)
                {
                    var buf = new byte[face.Bounds.Width * face.Bounds.Height * 3];
                    for (var y = 0; y < face.Bounds.Height; y++)
                    {
                        for (var x = 0; x < face.Bounds.Width; x++)
                        {
                            for (var c = 0; c < 3; c++)
                            {
                                buf[(y * face.Bounds.Width + x) * 3 + c] = frame.Image.Data[y + face.Bounds.Top, x + face.Bounds.Left, c];
                            }
                        }
                    }

                    packet.Faces.Add(new VideoDataPacket.Types.Face()
                    {
                        Id       = face.ID,
                        Z        = face.Z,
                        Speaking = face.IsSpeaking,
                        Data     = ByteString.CopyFrom(buf),
                        Rect     = new VideoDataPacket.Types.Rectangle()
                        {
                            Top    = face.Bounds.Top,
                            Left   = face.Bounds.Left,
                            Width  = face.Bounds.Width,
                            Height = face.Bounds.Height
                        }
                    });
                }
                _logger.LogInformation("Video manager send packet with {0} faces", frame.Faces.Count);
                _previousSendTime = DateTime.Now;
                _network.SendPacket(packet);
            };
        }
Ejemplo n.º 2
0
 public void SendPacket(VideoDataPacket p)
 {
     _videoServer.BroadcastPacket(p);
     _logger.LogTrace("Enqueued video packet.");
 }