public void Display(DeviceData dev) { graph = this.CreateGraphics(); new Thread(() => { slave = new Slavery.Slave(dev, 360, 720); slave.ScreenService.FrameArrived += ScreenService_FrameArrived; slave.ScreenService?.Start(); // 加入设备管理器 Program.Slaves.Add(new SlavedDevice() { Key = slave.Device.Serial, Object = slave }); }) { IsBackground = true }.Start(); }
public Manipulate(Slave slave) { this.slave = slave; var adb = AdbClient.Instance; client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); new Thread(() => { new AdbClient(AdbServer.Instance.EndPoint) .ExecuteRemoteCommand($"/data/local/tmp/minitouch", slave.Device, this); }) { IsBackground = true }.Start(); client.Connect(IPAddress.Loopback, slave.ManipulatePort); sendCommand("hello", () => { Thread.Sleep(1000); sendCommand("world", () => Touch(Point.Empty)); }); }
public void Display(Slavery.Slave sl) { view.Display(sl); view.Invalidate(); this.Invalidate(); }
public void Display(Slavery.Slave sl) { this.slave = sl; slave.ScreenService.FrameArrived += ScreenService_FrameArrived; graph = this.CreateGraphics(); }
public Form SetSlave(Slavery.Slave slave) { this.slave = slave; adb = new AdbClient(AdbServer.Instance.EndPoint); return(this); }
public Screen(Slave slave, int virtualWid, int virtualHei) { // initialize this.port = slave.ScreenPort; _dev = slave; // 获取屏幕大小 var adb = new AdbClient(AdbServer.Instance.EndPoint); adb.ExecuteRemoteCommand("dumpsys window", slave.Device, this); // 等待执行完毕 while (!flushed) { Thread.Sleep(100); } // 运行 new Thread(() => { var realSiz = $"{Width}x{Height}"; var virtualSiz = $"{virtualWid}x{virtualHei}"; // 启动minicap new AdbClient(AdbServer.Instance.EndPoint) .ExecuteRemoteCommand($"LD_LIBRARY_PATH=/data/local/tmp/ /data/local/tmp/minicap -S -P {realSiz}@{virtualSiz}/0", slave.Device, this); }) { IsBackground = true }.Start(); // 等待minicap服务启动 Thread.Sleep(1000); // 转发 AdbClient.Instance.CreateForward(slave.Device, new ForwardSpec() { Port = port, Protocol = ForwardProtocol.Tcp }, new ForwardSpec() { Protocol = ForwardProtocol.LocalAbstract, SocketName = "minicap" }, true); client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); new Thread(() => { #if DEBUG var secAccu = 0.0; var frameAccu = 0; #endif while (true) { if (!started) { Thread.Sleep(100); continue; } try { var before = DateTime.Now; // 帧前4字节为长度 var lenBuf = new byte[4]; client.Receive(lenBuf, 4, SocketFlags.None); var length = BitConverter.ToInt32(lenBuf, 0); if (length <= 0) { // wrong frame continue; } if (length / 1024 > 1000) { continue; } var frameBuf = new byte[length]; int len = 0; var ms = new MemoryStream(); while (ms.Length < length) { len = client.Receive(frameBuf, length - (int)ms.Length, SocketFlags.None); ms.Write(frameBuf, 0, len); } var imgBuffer = ms.ToArray(); // jpeg header if ((imgBuffer[0] != 0xff || imgBuffer[1] != 0xD8)) { continue; } var img = Image.FromStream(ms, true, true); FrameArrived?.Invoke(slave.Device, this, img); GC.Collect(); var subTime = DateTime.Now.Subtract(before); var frameTime = 1000 / frameLimiter; //// 还没消耗够1frame所需的时间 //if (subTime.TotalMilliseconds < frameTime) //{ // Thread.Sleep(frameTime - (int)subTime.TotalMilliseconds); //} #if DEBUG secAccu += subTime.TotalMilliseconds < frameTime ? frameTime : subTime.TotalMilliseconds; if (secAccu >= 1000) { //Debug.WriteLine($"***************** frame rate: {frameAccu}"); frameAccu = 0; secAccu = 0; } //Debug.WriteLine($"frame size: {imgBuffer.Length / 1024} kB."); //Debug.WriteLine($"proc time: {subTime.TotalMilliseconds} ms."); ++frameAccu; #endif } catch (Exception ex) { Program.Logs.WriteLog("读取帧字节出错!", ex.Message, Core.LogLevel.Exception); } } }) { IsBackground = true }.Start(); }
public Overseer(Slave slave) { this.slave = slave; }