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<uint, VideoCapabilities> videocapsList = new Dictionary<uint, VideoCapabilities>();
for (int i = 0; i < count; i++)
{
try
{
VideoCapabilities vc = new VideoCapabilities(videoStreamConfig, i);
uint key = (((uint)vc.FrameSize.Height) << 32) |
(((uint)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;
}