private void GetPinCapabilitiesAndConfigureSizeAndRate( ICaptureGraphBuilder2 graphBuilder, IBaseFilter baseFilter,
Guid pinCategory, Size size, int frameRate, 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 = AForge.Video.DirectShow.VideoCapabilities.FromStreamConfig( streamConfig );
}
catch
{
}
}
// check if it is required to change capture settings
if ( ( frameRate != 0 ) || ( ( size.Width != 0 ) && ( size.Height != 0 ) ) )
{
SetFrameSizeAndRate( streamConfig, size, frameRate );
}
}
}
// if failed resolving capabilities, then just create empty capabilities array,
// so we don't try again
if ( capabilities == null )
{
capabilities = new VideoCapabilities[0];
}
}