Beispiel #1
0
        private void SendVideoFrame(Bitmap frame)
        {
            var bitmapData = frame.LockBits(new Rectangle(0, 0, frame.Width, frame.Height), ImageLockMode.ReadOnly, frame.PixelFormat);

            byte[] bytes = new byte[bitmapData.Stride * frame.Height];

            Marshal.Copy(bitmapData.Scan0, bytes, 0, bytes.Length);

            try
            {
                VpxImage img = VpxImage.Create(VpxImageFormat.VPX_IMG_FMT_I420, (ushort)frame.Width, (ushort)frame.Height, 1);

                byte[] dest = new byte[frame.Width * frame.Height * 4];
                VpxHelper.RgbToYuv420(img, bytes, (ushort)frame.Width, (ushort)frame.Height);

                int length = toxav.PrepareVideoFrame(CallIndex, dest, (IntPtr)img.Pointer);
                img.Free();

                if (length > 0)
                {
                    byte[] bytesToSend = new byte[length];
                    Array.Copy(dest, bytesToSend, length);

                    ToxAvError error = toxav.SendVideo(CallIndex, bytesToSend);
                    if (error != ToxAvError.None)
                    {
                        Debug.WriteLine(string.Format("Could not send video frame: {0}, {1}", error, length));
                    }
                }
                else
                {
                    Debug.WriteLine(string.Format("Could not prepare frame: {0}", (ToxAvError)length));
                }
            }
            catch
            {
                Debug.WriteLine(string.Format("Could not convert frame"));
            }

            frame.Dispose();
        }