private void GetPinCapabilitiesAndConfigureSizeAndRate(ICaptureGraphBuilder2 graphBuilder, IBaseFilter baseFilter,
Guid pinCategory, VideoCapabilities resolutionToSet, ref VideoCapabilities[] capabilities)
{
object streamConfigObject;
graphBuilder.FindInterface(pinCategory, MediaType.Video, baseFilter, typeof(IAMStreamConfig).GUID, out streamConfigObject);
if (streamConfigObject != null)
{
IAMStreamConfig streamConfig = null;
try
{
streamConfig = (IAMStreamConfig)streamConfigObject;
}
catch (InvalidCastException)
{
}
if (streamConfig != null)
{
if (capabilities == null)
{
try
{
// get all video capabilities
capabilities = Accord.Video.DirectShow.VideoCapabilities.FromStreamConfig(streamConfig);
}
catch
{
}
}
// check if it is required to change capture settings
if (resolutionToSet != null)
{
SetResolution(streamConfig, resolutionToSet);
}
}
Marshal.ReleaseComObject(streamConfigObject);
}
// if failed resolving capabilities, then just create empty capabilities array,
// so we don't try again
if (capabilities == null)
{
capabilities = new VideoCapabilities[0];
}
}