private void SetResolution(IAMStreamConfig streamConfig, VideoCapabilities resolution)
{
if (resolution == null)
{
return;
}
// iterate through device's capabilities to find mediaType for desired resolution
int capabilitiesCount = 0, capabilitySize = 0;
AMMediaType newMediaType = null;
VideoStreamConfigCaps caps = new VideoStreamConfigCaps();
streamConfig.GetNumberOfCapabilities(out capabilitiesCount, out capabilitySize);
for (int i = 0; i < capabilitiesCount; i++)
{
try
{
VideoCapabilities vc = new VideoCapabilities(streamConfig, i);
if (resolution == vc)
{
if (streamConfig.GetStreamCaps(i, out newMediaType, caps) == 0)
{
break;
}
}
}
catch
{
}
}
// set the new format
if (newMediaType != null)
{
streamConfig.SetFormat(newMediaType);
newMediaType.Dispose();
}
}