// Ok button clicked private void okButton_Click(object sender, EventArgs e) { videoDeviceMoniker = videoDevice.Source; // set video size if (videoCapabilitiesDictionary.Count != 0) { VideoCapabilities caps = videoCapabilitiesDictionary[(string)videoResolutionsCombo.SelectedItem]; videoDevice.VideoResolution = caps; captureSize = caps.FrameSize; } if (configureSnapshots) { // set snapshots size if (snapshotCapabilitiesDictionary.Count != 0) { VideoCapabilities caps = snapshotCapabilitiesDictionary[(string)snapshotResolutionsCombo.SelectedItem]; videoDevice.ProvideSnapshots = true; videoDevice.SnapshotResolution = caps; snapshotSize = caps.FrameSize; } } if (availableVideoInputs.Length != 0) { videoInput = availableVideoInputs[videoInputsCombo.SelectedIndex]; videoDevice.CrossbarVideoInput = videoInput; } }
/// <summary> /// Check if two video capabilities are equal. /// </summary> /// /// <param name="vc2">Second video capability to compare with.</param> /// /// <returns>Returns true if both video capabilities are equal or false otherwise.</returns> /// public bool Equals(VideoCapabilities vc2) { if ((object)vc2 == null) { return(false); } return((FrameSize == vc2.FrameSize) && (BitCount == vc2.BitCount) && (MediaType == vc2.MediaType) && (MinimumFrameRate == vc2.MinimumFrameRate) && (MaximumFrameRate == vc2.MaximumFrameRate)); }
// Retrieve capabilities of a video device static internal VideoCapabilities[] FromStreamConfig(IAMStreamConfig videoStreamConfig) { if (videoStreamConfig == null) { throw new ArgumentNullException("videoStreamConfig"); } // ensure this device reports capabilities int count, size; int hr = videoStreamConfig.GetNumberOfCapabilities(out count, out size); if (hr != 0) { Marshal.ThrowExceptionForHR(hr); } if (count <= 0) { throw new NotSupportedException("This video device does not report capabilities."); } if (size > Marshal.SizeOf(typeof(VideoStreamConfigCaps))) { throw new NotSupportedException("Unable to retrieve video device capabilities. This video device requires a larger VideoStreamConfigCaps structure."); } // group capabilities with similar parameters Dictionary <int, VideoCapabilities> videocapsList = new Dictionary <int, VideoCapabilities>(); for (int i = 0; i < count; i++) { try { VideoCapabilities vc = new VideoCapabilities(videoStreamConfig, i); videocapsList.Add(i, vc); /* * ulong key = (((ulong)vc.MaximumFrameRate) << 48) | * (((ulong)vc.MaximumFrameRate) << 48) | * (((ulong)vc.FrameSize.Height) << 32) | * (((ulong)vc.FrameSize.Width) << 16); * if ( !videocapsList.ContainsKey( key ) ) * { * videocapsList.Add(key, vc); * } * else * { * if ( vc.BitCount > videocapsList[key].BitCount ) * { * videocapsList[key] = vc; * } * } */ } catch { } } VideoCapabilities[] videocaps = new VideoCapabilities[videocapsList.Count]; videocapsList.Values.CopyTo(videocaps, 0); return(videocaps); }