예제 #1
0
        // 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 <ulong, VideoCapabilities> videocapsList = new Dictionary <ulong, VideoCapabilities>();

            for (int i = 0; i < count; i++)
            {
                try
                {
                    VideoCapabilities vc = new VideoCapabilities(videoStreamConfig, i);

                    ulong key = (((ulong)vc.FrameSize.Height) << 32) |
                                (((ulong)vc.FrameSize.Width) << 16) |
                                ((ulong)(uint)vc.FrameRate);

                    if (!videocapsList.ContainsKey(key))
                    {
                        videocapsList.Add(key, vc);
                    }
                }
                catch
                {
                }
            }

            VideoCapabilities[] videocaps = new VideoCapabilities[videocapsList.Count];
            videocapsList.Values.CopyTo(videocaps, 0);

            return(videocaps);
        }
예제 #2
0
        // Configure specified pin and collect its capabilities if required
        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 = Gimela.Media.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];
            }
        }
예제 #3
0
    // 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<ulong, VideoCapabilities> videocapsList = new Dictionary<ulong, VideoCapabilities>();

      for (int i = 0; i < count; i++)
      {
        try
        {
          VideoCapabilities vc = new VideoCapabilities(videoStreamConfig, i);

          ulong key = (((ulong)vc.FrameSize.Height) << 32) |
                      (((ulong)vc.FrameSize.Width) << 16) |
                        ((ulong)(uint)vc.FrameRate);

          if (!videocapsList.ContainsKey(key))
          {
            videocapsList.Add(key, vc);
          }
        }
        catch
        {
        }
      }

      VideoCapabilities[] videocaps = new VideoCapabilities[videocapsList.Count];
      videocapsList.Values.CopyTo(videocaps, 0);

      return videocaps;
    }
    // Configure specified pin and collect its capabilities if required
    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 = Gimela.Media.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];
      }
    }