public CaptureSelection() { InitializeComponent(); //Oculus code if (OculusClient.isHMDPresent() == true) { detectedLabel.Text = "Rift Detected; Data should be valid."; //Scan oculus angles. I store them in a Vector3 with 3 values for each axis. //It's a quaternion, so I convert it to Euler angles (X, Y, Z) Vector3 oculusAngles = Helpers.ToEulerAngles(OculusClient.GetPredictedOrientation()); //Format the float angles and send them to the labels XLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.X); YLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Y); ZLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Z); //Scan Oculus's resolution and format it Vector2 oculusResolution = OculusClient.GetScreenResolution(); resolutionLabel.Text = String.Format(oculusResolution.X + "x" + oculusResolution.Y); } else { detectedLabel.Text = "No Rift Detected; Data is invalid."; } //Scott's code var screens = System.Windows.Forms.Screen.AllScreens; var mapInstanceToUserFriendly = new Dictionary<string, string>(); try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM WmiMonitorID"); foreach (ManagementObject queryObj in searcher.Get()) { string instanceName = (string)queryObj["InstanceName"]; string userFriendlyName = ""; if ((instanceName != null) && (queryObj["UserFriendlyName"] != null)) { UInt16[] arrUserFriendlyName = (UInt16[])(queryObj["UserFriendlyName"]); foreach (UInt16 arrValue in arrUserFriendlyName) { if (arrValue == 0) break; userFriendlyName += Convert.ToChar(arrValue); } instanceName = instanceName.Replace('\\', '#'); string[] splitInstance = instanceName.Split('_'); if ((splitInstance != null) && (splitInstance.Length >= 1)) { instanceName = splitInstance[0]; mapInstanceToUserFriendly[instanceName] = userFriendlyName; } } } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message + ". Exiting.", "Ocucam - Error"); Environment.Exit(-1); } var mapIdsToDisplay = new Dictionary<int, Display>(); DISPLAY_DEVICE d = new DISPLAY_DEVICE(); d.cb = Marshal.SizeOf(d); try { for (int id = 0; EnumDisplayDevices(null, (uint)id, ref d, 0); id++) { string name = d.DeviceName; d.cb = Marshal.SizeOf(d); EnumDisplayDevices(name, 0, ref d, EDD_GET_DEVICE_INTERFACE_NAME); foreach (string instanceName in mapInstanceToUserFriendly.Keys) { if (d.DeviceID.Contains(instanceName)) { mapIdsToDisplay[id] = new Display(id, mapInstanceToUserFriendly[instanceName], instanceName); break; } } d.cb = Marshal.SizeOf(d); } } catch (Exception ex) { MessageBox.Show("Error enumerating display devices. Exiting.", "Ocucam - Error"); Environment.Exit(-1); } DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory(); if (captureCategory.Objects.Count < 2) { if (captureCategory.Objects.Count == 0) { MessageBox.Show("System must have at least two distinct video capture devices. None were found. Exiting.", "Ocucam - Error"); } else { MessageBox.Show("System must have at least two distinct video capture devices. Only one was found. Exiting.", "Ocucam - Error"); } Environment.Exit(-1); } RegistryKey softwareKey = Registry.CurrentUser.OpenSubKey("Software", true); RegistryKey scottCutlerKey = softwareKey.CreateSubKey("Scott Cutler"); RegistryKey ocucamKey = scottCutlerKey.CreateSubKey("Ocucam"); string leftEyeDevicePathReg = (string)ocucamKey.GetValue("leftEyeDevicePath", ""); string rightEyeDevicePathReg = (string)ocucamKey.GetValue("rightEyeDevicePath", ""); string displayDeviceInstanceReg = (string)ocucamKey.GetValue("displayDeviceInstance", ""); checkBoxFullScreen.Checked = ((string)ocucamKey.GetValue("fullScreen", "True") == "True") ? true : false; ocucamKey.Close(); scottCutlerKey.Close(); softwareKey.Close(); captureCategory.Objects.Sort((a, b) => { return a.DevicePath.CompareTo(b.DevicePath); }); var objectCount = new Dictionary<string, int>(); foreach (var captureDevice in captureCategory.Objects) { if (objectCount.ContainsKey(captureDevice.DevicePath)) { objectCount[captureDevice.DevicePath]++; } else { objectCount.Add(captureDevice.DevicePath, 1); } DSDeviceWrap dw = new DSDeviceWrap(captureDevice, objectCount[captureDevice.DevicePath]); leftEyeDevice.Items.Add(dw); if (leftEyeDevicePathReg == captureDevice.DevicePath) { leftEyeDevice.SelectedIndex = leftEyeDevice.Items.Count - 1; } rightEyeDevice.Items.Add(dw); if (rightEyeDevicePathReg == captureDevice.DevicePath) { rightEyeDevice.SelectedIndex = rightEyeDevice.Items.Count - 1; } } foreach (var displayId in mapIdsToDisplay.Keys) { comboBoxDisplay.Items.Add(mapIdsToDisplay[displayId]); if (displayDeviceInstanceReg == mapIdsToDisplay[displayId].instance) { comboBoxDisplay.SelectedIndex = comboBoxDisplay.Items.Count - 1; } } }
protected override HRESULT OnInitInterfaces() { m_Renderer = new VMR9Renderer(); m_Renderer.FilterGraph = m_GraphBuilder; IVMRFilterConfig9 _config = (IVMRFilterConfig9)m_Renderer.QueryInterface(typeof(IVMRFilterConfig9).GUID); HRESULT hr; if (_config != null) { hr = (HRESULT)_config.SetRenderingMode(VMR9Mode.Renderless); hr.Assert(); hr = (HRESULT)_config.SetNumberOfStreams(2); hr.Assert(); } m_mixerControl = (IVMRMixerControl9)m_Renderer.QueryInterface(typeof(IVMRMixerControl9).GUID); m_mixerControl.SetBackgroundClr((int)0xbf7f2f); VMR9MixerPrefs mixerPrefs; m_mixerControl.GetMixingPrefs(out mixerPrefs); m_mixerControl.SetMixingPrefs(mixerPrefs); IVMRSurfaceAllocatorNotify9 _notify = (IVMRSurfaceAllocatorNotify9)m_Renderer.QueryInterface(typeof(IVMRSurfaceAllocatorNotify9).GUID); if (_notify != null) { hr = (HRESULT)_notify.AdviseSurfaceAllocator(new IntPtr(g_ciUsedID), this); hr.Assert(); hr = (HRESULT)this.AdviseNotify(_notify); hr.Assert(); } DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory(); List <DSFilter> capFilters = new List <DSFilter>(); foreach (var captureDevice in captureCategory.Objects) { if (captureDevice.DevicePath == m_leftEyeDevicePath) { capFilters.Add(captureDevice.Filter); break; } } foreach (var captureDevice in captureCategory.Objects) { if (captureDevice.DevicePath == m_rightEyeDevicePath) { capFilters.Add(captureDevice.Filter); break; } } if (capFilters.Count < 2) { MessageBox.Show("Not enough capture devices found (" + capFilters.Count.ToString() + " device(s))"); throw new Exception(); } for (int i = 0; i < 2; i++) { if (capFilters[i] == null) { return(E_FAIL); } DSPin capturePin = null; foreach (var outputPin in capFilters[i].Output) { if (outputPin.Name == "Capture") { capturePin = outputPin; break; } } AMMediaType mjpgMediaType = null; int maxPixels = -1; foreach (var mediaType in capturePin.MediaTypes) { VideoInfoHeader videoInfo = new VideoInfoHeader(); videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.formatPtr, typeof(VideoInfoHeader)); // pick the highest res mode... if ((videoInfo.BmiHeader.Width * videoInfo.BmiHeader.Height) > maxPixels) { maxPixels = videoInfo.BmiHeader.Width * videoInfo.BmiHeader.Height; mjpgMediaType = mediaType; //break; } } capFilters[i].OutputPin.Format = mjpgMediaType; capFilters[i].FilterGraph = m_GraphBuilder; capFilters[i].Connect(m_Renderer); } VMR9NormalizedRect r1 = new VMR9NormalizedRect(0, 0, 0.5f, 1f); VMR9NormalizedRect r2 = new VMR9NormalizedRect(0.5f, 0f, 1f, 1f); int rt0 = m_mixerControl.SetOutputRect(0, ref r1); int rt1 = m_mixerControl.SetOutputRect(1, ref r2); hr = base.OnInitInterfaces(); return(hr); }
public CaptureSelection() { InitializeComponent(); //Oculus code if (OculusClient.isHMDPresent() == true) { detectedLabel.Text = "Rift Detected; Data should be valid."; //Scan oculus angles. I store them in a Vector3 with 3 values for each axis. //It's a quaternion, so I convert it to Euler angles (X, Y, Z) Vector3 oculusAngles = Helpers.ToEulerAngles(OculusClient.GetPredictedOrientation()); //Format the float angles and send them to the labels XLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.X); YLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Y); ZLabel.Text = String.Format("{0:0,0.0000000}", oculusAngles.Z); //Scan Oculus's resolution and format it Vector2 oculusResolution = OculusClient.GetScreenResolution(); resolutionLabel.Text = String.Format(oculusResolution.X + "x" + oculusResolution.Y); } else { detectedLabel.Text = "No Rift Detected; Data is invalid."; } //Scott's code var screens = System.Windows.Forms.Screen.AllScreens; var mapInstanceToUserFriendly = new Dictionary <string, string>(); try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM WmiMonitorID"); foreach (ManagementObject queryObj in searcher.Get()) { string instanceName = (string)queryObj["InstanceName"]; string userFriendlyName = ""; if ((instanceName != null) && (queryObj["UserFriendlyName"] != null)) { UInt16[] arrUserFriendlyName = (UInt16[])(queryObj["UserFriendlyName"]); foreach (UInt16 arrValue in arrUserFriendlyName) { if (arrValue == 0) { break; } userFriendlyName += Convert.ToChar(arrValue); } instanceName = instanceName.Replace('\\', '#'); string[] splitInstance = instanceName.Split('_'); if ((splitInstance != null) && (splitInstance.Length >= 1)) { instanceName = splitInstance[0]; mapInstanceToUserFriendly[instanceName] = userFriendlyName; } } } } catch (ManagementException e) { MessageBox.Show("An error occurred while querying for WMI data: " + e.Message + ". Exiting.", "Ocucam - Error"); Environment.Exit(-1); } var mapIdsToDisplay = new Dictionary <int, Display>(); DISPLAY_DEVICE d = new DISPLAY_DEVICE(); d.cb = Marshal.SizeOf(d); try { for (int id = 0; EnumDisplayDevices(null, (uint)id, ref d, 0); id++) { string name = d.DeviceName; d.cb = Marshal.SizeOf(d); EnumDisplayDevices(name, 0, ref d, EDD_GET_DEVICE_INTERFACE_NAME); foreach (string instanceName in mapInstanceToUserFriendly.Keys) { if (d.DeviceID.Contains(instanceName)) { mapIdsToDisplay[id] = new Display(id, mapInstanceToUserFriendly[instanceName], instanceName); break; } } d.cb = Marshal.SizeOf(d); } } catch (Exception ex) { MessageBox.Show("Error enumerating display devices. Exiting.", "Ocucam - Error"); Environment.Exit(-1); } DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory(); if (captureCategory.Objects.Count < 2) { if (captureCategory.Objects.Count == 0) { MessageBox.Show("System must have at least two distinct video capture devices. None were found. Exiting.", "Ocucam - Error"); } else { MessageBox.Show("System must have at least two distinct video capture devices. Only one was found. Exiting.", "Ocucam - Error"); } Environment.Exit(-1); } RegistryKey softwareKey = Registry.CurrentUser.OpenSubKey("Software", true); RegistryKey scottCutlerKey = softwareKey.CreateSubKey("Scott Cutler"); RegistryKey ocucamKey = scottCutlerKey.CreateSubKey("Ocucam"); string leftEyeDevicePathReg = (string)ocucamKey.GetValue("leftEyeDevicePath", ""); string rightEyeDevicePathReg = (string)ocucamKey.GetValue("rightEyeDevicePath", ""); string displayDeviceInstanceReg = (string)ocucamKey.GetValue("displayDeviceInstance", ""); checkBoxFullScreen.Checked = ((string)ocucamKey.GetValue("fullScreen", "True") == "True") ? true : false; ocucamKey.Close(); scottCutlerKey.Close(); softwareKey.Close(); captureCategory.Objects.Sort((a, b) => { return(a.DevicePath.CompareTo(b.DevicePath)); }); var objectCount = new Dictionary <string, int>(); foreach (var captureDevice in captureCategory.Objects) { if (objectCount.ContainsKey(captureDevice.DevicePath)) { objectCount[captureDevice.DevicePath]++; } else { objectCount.Add(captureDevice.DevicePath, 1); } DSDeviceWrap dw = new DSDeviceWrap(captureDevice, objectCount[captureDevice.DevicePath]); leftEyeDevice.Items.Add(dw); if (leftEyeDevicePathReg == captureDevice.DevicePath) { leftEyeDevice.SelectedIndex = leftEyeDevice.Items.Count - 1; } rightEyeDevice.Items.Add(dw); if (rightEyeDevicePathReg == captureDevice.DevicePath) { rightEyeDevice.SelectedIndex = rightEyeDevice.Items.Count - 1; } } foreach (var displayId in mapIdsToDisplay.Keys) { comboBoxDisplay.Items.Add(mapIdsToDisplay[displayId]); if (displayDeviceInstanceReg == mapIdsToDisplay[displayId].instance) { comboBoxDisplay.SelectedIndex = comboBoxDisplay.Items.Count - 1; } } }
protected override HRESULT OnInitInterfaces() { m_Renderer = new VMR9Renderer(); m_Renderer.FilterGraph = m_GraphBuilder; IVMRFilterConfig9 _config = (IVMRFilterConfig9)m_Renderer.QueryInterface(typeof(IVMRFilterConfig9).GUID); HRESULT hr; if (_config != null) { hr = (HRESULT)_config.SetRenderingMode(VMR9Mode.Renderless); hr.Assert(); hr = (HRESULT)_config.SetNumberOfStreams(2); hr.Assert(); } m_mixerControl = (IVMRMixerControl9)m_Renderer.QueryInterface(typeof(IVMRMixerControl9).GUID); m_mixerControl.SetBackgroundClr((int)0xbf7f2f); VMR9MixerPrefs mixerPrefs; m_mixerControl.GetMixingPrefs(out mixerPrefs); m_mixerControl.SetMixingPrefs(mixerPrefs); IVMRSurfaceAllocatorNotify9 _notify = (IVMRSurfaceAllocatorNotify9)m_Renderer.QueryInterface(typeof(IVMRSurfaceAllocatorNotify9).GUID); if (_notify != null) { hr = (HRESULT)_notify.AdviseSurfaceAllocator(new IntPtr(g_ciUsedID), this); hr.Assert(); hr = (HRESULT)this.AdviseNotify(_notify); hr.Assert(); } DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory(); List<DSFilter> capFilters = new List<DSFilter>(); foreach (var captureDevice in captureCategory.Objects) { if (captureDevice.DevicePath == m_leftEyeDevicePath) { capFilters.Add(captureDevice.Filter); break; } } foreach (var captureDevice in captureCategory.Objects) { if (captureDevice.DevicePath == m_rightEyeDevicePath) { capFilters.Add(captureDevice.Filter); break; } } if (capFilters.Count < 2) { MessageBox.Show("Not enough capture devices found (" + capFilters.Count.ToString() + " device(s))"); throw new Exception(); } for (int i = 0; i < 2; i++) { if (capFilters[i] == null) { return E_FAIL; } DSPin capturePin = null; foreach (var outputPin in capFilters[i].Output) { if (outputPin.Name == "Capture") { capturePin = outputPin; break; } } AMMediaType mjpgMediaType = null; int maxPixels = -1; foreach (var mediaType in capturePin.MediaTypes) { VideoInfoHeader videoInfo = new VideoInfoHeader(); videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.formatPtr, typeof(VideoInfoHeader)); // pick the highest res mode... if ((videoInfo.BmiHeader.Width * videoInfo.BmiHeader.Height) > maxPixels) { maxPixels = videoInfo.BmiHeader.Width * videoInfo.BmiHeader.Height; mjpgMediaType = mediaType; //break; } } capFilters[i].OutputPin.Format = mjpgMediaType; capFilters[i].FilterGraph = m_GraphBuilder; capFilters[i].Connect(m_Renderer); } VMR9NormalizedRect r1 = new VMR9NormalizedRect(0, 0, 0.5f, 1f); VMR9NormalizedRect r2 = new VMR9NormalizedRect(0.5f, 0f, 1f, 1f); int rt0 = m_mixerControl.SetOutputRect(0, ref r1); int rt1 = m_mixerControl.SetOutputRect(1, ref r2); hr = base.OnInitInterfaces(); return hr; }