void ReceivedVideoCallback(object obj) { object[] objs = (object[])obj; AdHocDesktop_TcpCommand command = (AdHocDesktop_TcpCommand)objs[0]; byte[] buffer = (byte[])objs[1]; lock (this) { if (command == AdHocDesktop_TcpCommand.StreamingCamera) { using (Bitmap drawImage = ImageUtil.ByteToBitmap(buffer)) { using (Graphics g = videoPanel.CreateGraphics()) { g.DrawImage(drawImage, new Rectangle(new Point(0, 0), videoPanel.Size)); } } } else { try { byte[] image = null; if (previousBuffer == null) { previousBuffer = GZipUtil.Decompress(buffer); image = previousBuffer; } else { byte[] currentBuffer = GZipUtil.Decompress(buffer); image = ImageUtil.RecompareImage(previousBuffer, currentBuffer); } using (Bitmap drawImage = ImageUtil.ByteToBitmap(image))//, width, height, width * 3, PixelFormat.Format24bppRgb)) { using (Graphics g = videoPanel.CreateGraphics()) { g.DrawImage(drawImage, new Rectangle(new Point(0, 0), videoPanel.Size)); } } previousBuffer = null; previousBuffer = image; image = null; } catch (Exception) { } } } }
void SendStreaming(AdHocDesktop_TcpClient client, byte[] buffer, AdHocDesktop_TcpCommand command) { bandwidthInput += (buffer == null ? 0 : buffer.Length); List <AdHocDesktop_TcpClient> groups = groupTable[client.Identifier]; for (int i = 0; i < groups.Count; i++) { if (!groups[i].IsConnected) { groups.RemoveAt(i); i--; } } for (int i = 0; i < groups.Count; i++) { AdHocDesktop_TcpClient dest = groups[i]; if (winceClients.Contains(dest.Identifier)) { Size size = new Size(240, 180); if (command == AdHocDesktop_TcpCommand.StreamingCamera) { using (Bitmap b = ImageUtil.ByteToBitmap(buffer)) { buffer = ImageUtil.ResizeBitmapToJpegByte(b, size); } } else if (command == AdHocDesktop_TcpCommand.StreamingScreen) { using (Bitmap b = ImageUtil.ByteToBitmap(GZipUtil.Decompress(buffer))) { buffer = GZipUtil.Compress(ImageUtil.ResizeBitmapToByte(b, size)); } } } dest.Send(new AdHocDesktop_TcpObject(command, client.Identifier, dest.Identifier, buffer)); bandwidthOutput += (buffer == null ? 0 : buffer.Length); } }