private void UpdateVideoSources() { List <ComboBoxItem> items = new List <ComboBoxItem>(); var captureProperties = Config.Data.ScreenCaptureProperties; int monitorIndex = 1; foreach (var screen in Screen.AllScreens) { var friendlyName = MediaToolkit.Utils.DisplayHelper.GetFriendlyScreenName(screen); var bounds = screen.Bounds; ScreenCaptureDevice device = new ScreenCaptureDevice { CaptureRegion = bounds, DisplayRegion = bounds, Name = screen.DeviceName, Resolution = bounds.Size, Properties = captureProperties, DeviceId = screen.DeviceName, }; var monitorDescr = bounds.Width + "x" + bounds.Height; if (!string.IsNullOrEmpty(friendlyName)) { monitorDescr = friendlyName + " " + monitorDescr; } var monitorName = "Screen " + monitorIndex + " (" + monitorDescr + ")"; //var name = screen.DeviceName; //if (!string.IsNullOrEmpty(friendlyName)) //{ // name += " (" + friendlyName + " " + bounds.Width + "x" + bounds.Height + ") "; //} device.Name = monitorName; items.Add(new ComboBoxItem { Name = monitorName,//screen.DeviceName,//+ "" + s.Bounds.ToString(), Tag = device, }); monitorIndex++; } if (items.Count > 1) { var allScreenRect = SystemInformation.VirtualScreen; ScreenCaptureDevice device = new ScreenCaptureDevice { DisplayRegion = allScreenRect, CaptureRegion = allScreenRect, Resolution = allScreenRect.Size, Properties = captureProperties, Name = "All Screens (" + allScreenRect.Width + "x" + allScreenRect.Height + ")", DeviceId = "AllScreens", }; items.Add(new ComboBoxItem { Name = device.Name,//+ "" + s.Bounds.ToString(), Tag = device, }); } var customRegion = Config.Data.SelectAreaRectangle; ScreenCaptureDevice customRegionDescr = new ScreenCaptureDevice { CaptureRegion = customRegion, DisplayRegion = Rectangle.Empty, Resolution = customRegion.Size, Properties = captureProperties, Name = "Screen Region", DeviceId = "ScreenRegion", }; items.Add(new ComboBoxItem { Name = customRegionDescr.Name, Tag = customRegionDescr, }); var captDevices = MediaToolkit.MediaFoundation.MfTool.FindUvcDevices(); if (captDevices.Count > 0) { var captItems = captDevices.Select(d => new ComboBoxItem { Name = d.Name, Tag = d, }); items.AddRange(captItems); } WindowCaptureDevice windowCapture = new WindowCaptureDevice { ProcName = "NotFound", hWnd = IntPtr.Zero, ClientRect = Rectangle.Empty, Resolution = Size.Empty, Properties = captureProperties, Name = "_Application Window", DeviceId = "AppWindow", }; Process p = Process.GetProcessesByName("calc").FirstOrDefault(); if (p != null) { var hwnd = p.MainWindowHandle; var procName = p.ProcessName; var clientRect = User32.GetClientRect(hwnd); windowCapture.ProcName = procName; windowCapture.hWnd = hwnd; windowCapture.ClientRect = clientRect; windowCapture.Resolution = clientRect.Size; windowCapture.Name = "_Application Window (" + procName + ")"; } items.Add(new ComboBoxItem { Name = windowCapture.Name, Tag = windowCapture, }); videoSourceItems = new BindingList <ComboBoxItem>(items); videoSourceComboBox.DisplayMember = "Name"; videoSourceComboBox.DataSource = videoSourceItems; }
public void Setup(VideoCaptureDevice captDeviceSettings) { if (captDeviceSettings.CaptureMode == CaptureMode.Screen) { ScreenCaptSettings = (ScreenCaptureDevice)captDeviceSettings; LoadCaptureTypes(); var captureProps = ScreenCaptSettings.Properties; captureMouseCheckBox.Checked = captureProps.CaptureMouse; var fps = captureProps.Fps; if (fps > fpsNumeric.Maximum) { fps = (int)fpsNumeric.Maximum; } else if (fps < fpsNumeric.Minimum) { fps = (int)fpsNumeric.Minimum; } var captureType = captureProps.CaptureType; var captureItem = captureTypes.FirstOrDefault(i => (VideoCaptureType)i.Tag == captureType) ?? captureTypes.FirstOrDefault(); captureTypesComboBox.SelectedItem = captureItem; fpsNumeric.Value = fps; showDebugInfoCheckBox.Checked = captureProps.ShowDebugInfo; showCaptureBorderCheckBox.Checked = captureProps.ShowDebugBorder; screenCaptureDetailsPanel.Visible = true; } else if (captDeviceSettings.CaptureMode == CaptureMode.AppWindow) { WindowsCaptSettings = (WindowCaptureDevice)captDeviceSettings; LoadCaptureTypes(); var captureProps = WindowsCaptSettings.Properties; captureMouseCheckBox.Checked = captureProps.CaptureMouse; var fps = captureProps.Fps; if (fps > fpsNumeric.Maximum) { fps = (int)fpsNumeric.Maximum; } else if (fps < fpsNumeric.Minimum) { fps = (int)fpsNumeric.Minimum; } var captureType = captureProps.CaptureType; var captureItem = captureTypes.FirstOrDefault(i => (VideoCaptureType)i.Tag == captureType) ?? captureTypes.FirstOrDefault(); captureTypesComboBox.SelectedItem = captureItem; fpsNumeric.Value = fps; showDebugInfoCheckBox.Checked = captureProps.ShowDebugInfo; showCaptureBorderCheckBox.Checked = captureProps.ShowDebugBorder; screenCaptureDetailsPanel.Visible = true; } }