private void TryNotifyDeviceConnected(DeviceData dev) { if (dev.State != DeviceState.Online) { return; } Task <int> task = new Task <int>(() => { var ret = ExcuteAdbShellCmd("dumpsys window displays |head -n 3", dev.Serial); log_.Debug($"OnDeviceChanged {ret}"); Regex regex = new Regex(@"init=(\d+)x(\d+)"); var m = regex.Match(ret); if (m.Success) { Size sz = new Size(); sz.Width = Convert.ToInt32(m.Groups[1].Value); sz.Height = Convert.ToInt32(m.Groups[2].Value); double rate = sz.Height * 1.0 / Display_height; var e2 = new UsbDeviceEventArgs(dev); e2.screen_size = sz; e2.display_zoom_rate = rate; OnDeviceConnected?.Invoke(this, e2); } return(1); }); task.Start(); }
public void StartScrcpyServer(UsbDeviceEventArgs dev) { Task <int> task = new Task <int>(() => { try { OnVideoDataArrived cb = OnMirrorImageArrive; RegistVideoCB(cb); GC.KeepAlive(cb); OnScrcpyLog cb2 = OnScrcpyLog1; RegistScrcpyLogCB(cb2); GC.KeepAlive(cb); SetADBFolderPath(Marshal.StringToHGlobalAnsi(adb_path_) , Marshal.StringToHGlobalAnsi(adb_svr_path_)); IntPtr[] sbs = GetCommand($"-s {dev.GetSerial()} -m {Display_height} -b 2M"); var ret = RunScrcpy(sbs.Length, sbs); return(ret); } catch (Exception e) { log_.Error($"StartScrcpyServer {e.ToString()}"); } finally { OnDeviceDisconnected?.Invoke(this, dev); if (!adb_server_.GetStatus().IsRunning) { adb_server_.RestartServer(); } } return(-1); }); task.Start(); }