public MainForm() { InitializeComponent(); mediaStreamer = new MediaStreamer(); mediaStreamer.StateChanged += MediaStreamer_StateChanged; //Validate session... currentSession = Config.Data.Session; usbManager = new UsbDeviceManager(); usbManager.Init(UsbCategory.VideoCamera); usbManager.UsbDeviceArrival += UsbManager_UsbDeviceArrival; usbManager.UsbDeviceMoveComplete += UsbManager_UsbDeviceMoveComplete; syncContext = SynchronizationContext.Current; InitControls(); var startupParams = Program.StartupParams; if (startupParams.IsSystem) { var caption = this.Text; caption = caption + " (" + startupParams.UserName + ")"; this.Text = caption; } }
public void Shutdown() { logger.Debug("SystemManager::Shutdown() " + Initialized); //if (!Initialized) //{ // return; //} SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged; SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch; if (notifyHandles != null && notifyHandles.Count > 0) { foreach (var handle in notifyHandles.Values) { var result = UsbDeviceManager.UnregisterNotification(handle); } } if (notifyWindow != null) { notifyWindow.DestroyWindow(); notifyWindow = null; } Initialized = false; }
bool IWndMessageProcessor.ProcessMessage(Message m) { bool result = false; switch ((uint)m.Msg) { case WM.DEVICECHANGE: { uint eventCode = (uint)m.WParam; if (eventCode == DBT.DEVICEARRIVAL || eventCode == DBT.DEVICEREMOVECOMPLETE) { if (UsbDeviceManager.TryPtrToDeviceInfo(m.LParam, out UsbDeviceInfo di)) { // получили информацию о подключенном устройстве в виде: // \\?\USB#VID_0A89&PID_000C#6&2c24ce2e&0&4#{a5dcbf10-6530-11d2-901f-00c04fb951ed} bool deviceArraval = (eventCode == DBT.DEVICEARRIVAL); if (di.ClassGuid == UsbCategory.Audio || di.ClassGuid == UsbCategory.AudioDevice) { // update audio sources... logger.Debug("Audio USB " + (deviceArraval ? "arrival: " : "moved: ") + di.FriendlyName + " {" + di.Name + "}"); VideoSourcesChanged?.Invoke(di.Name); } else if (di.ClassGuid == UsbCategory.VideoCamera || di.ClassGuid == UsbCategory.Video) { // update video sources... logger.Debug("Video USB " + (deviceArraval ? "arrival: " : "moved: ") + di.FriendlyName + " {" + di.Name + "}"); AudioSourcesChanged?.Invoke(di.Name); } else { } result = true; } else { //TODO: //... } } //logger.Debug("WM_DEVICECHANGE"); break; } } return(result); }
private void RegisterNotification(IntPtr hWnd, Guid classId) { if (notifyHandles == null) { notifyHandles = new Dictionary <Guid, IntPtr>(); } var notifyHandle = UsbDeviceManager.RegisterNotification(hWnd, classId); if (notifyHandle != IntPtr.Zero) { notifyHandles.Add(classId, notifyHandle); } else { logger.Warn($"Fail to register {classId} notifications"); } }
protected override void WndProc(ref Message m) { if (this.Disposing) { base.WndProc(ref m); return; } switch ((uint)m.Msg) { case WM.DEVICECHANGE: { uint eventCode = (uint)m.WParam; if (eventCode == DBT.DEVICEARRIVAL || eventCode == DBT.DEVICEREMOVECOMPLETE) { if (UsbDeviceManager.TryPtrToDeviceName(m.LParam, out string deviceName)) { // получили информацию о подключенном устройстве в виде: // \\?\USB#VID_0A89&PID_000C#6&2c24ce2e&0&4#{a5dcbf10-6530-11d2-901f-00c04fb951ed} if (eventCode == DBT.DEVICEARRIVAL) { OnUsbDeviceArrival(deviceName); } else { OnUsbDeviceMoveComplete(deviceName); } } else { //TODO: //... } } //logger.Debug("WM_DEVICECHANGE"); return; } } base.WndProc(ref m); }