예제 #1
0
    /// <summary>
    /// Returns the <see cref="CameraInfo"/> for the given <see cref="DsDevice"/>.
    /// </summary>
    /// <param name="dev">A <see cref="DsDevice"/> to parse name and capabilities for.</param>
    /// <returns>The <see cref="CameraInfo"/> for the given device.</returns>
    private CameraInfo Caps(DsDevice dev)
    {
      var camerainfo = new CameraInfo();

      // Get the graphbuilder object
      var graphBuilder = (IFilterGraph2)new FilterGraph();

      // Get the ICaptureGraphBuilder2
      var capGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

      IBaseFilter capFilter = null;

      try
      {
        int hr = capGraph.SetFiltergraph(graphBuilder);
        DsError.ThrowExceptionForHR(hr);

        // Add the video device
        hr = graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
        //        DsError.ThrowExceptionForHR(hr);

        if (hr != 0)
        {
          Console.WriteLine("Error in m_graphBuilder.AddSourceFilterForMoniker(). Could not add source filter. Message: " + DsError.GetErrorText(hr));
          return null;
        }

        //hr = m_graphBuilder.AddFilter(capFilter, "Ds.NET Video Capture Device");
        //DsError.ThrowExceptionForHR(hr);

        object o = null;
        DsGuid cat = PinCategory.Capture;
        DsGuid type = MediaType.Interleaved;
        DsGuid iid = typeof(IAMStreamConfig).GUID;

        // Check if Video capture filter is in use
        hr = capGraph.RenderStream(cat, MediaType.Video, capFilter, null, null);
        if (hr != 0)
        {
          return null;
        }

        //hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Interleaved, capFilter, typeof(IAMStreamConfig).GUID, out o);
        //if (hr != 0)
        //{
        hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter,
                                    typeof(IAMStreamConfig).GUID, out o);
        DsError.ThrowExceptionForHR(hr);
        //}

        var videoStreamConfig = o as IAMStreamConfig;

        int iCount = 0;
        int iSize = 0;

        try
        {
          if (videoStreamConfig != null) videoStreamConfig.GetNumberOfCapabilities(out iCount, out iSize);
        }
        catch (Exception)
        {
          //ErrorLogger.ProcessException(ex, false);
          return null;
        }

        pscc = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VideoStreamConfigCaps)));

        camerainfo.Name = dev.Name;
        camerainfo.DirectshowDevice = dev;

        for (int i = 0; i < iCount; i++)     
        {
          VideoStreamConfigCaps scc;

          try
          {
            AMMediaType curMedType;
            if (videoStreamConfig != null) hr = videoStreamConfig.GetStreamCaps(i, out curMedType, pscc);
            Marshal.ThrowExceptionForHR(hr);
            scc = (VideoStreamConfigCaps)Marshal.PtrToStructure(pscc, typeof(VideoStreamConfigCaps));


            var CSF = new CamSizeFPS();
            CSF.FPS = (int)(10000000 / scc.MinFrameInterval);
            CSF.Height = scc.InputSize.Height;
            CSF.Width = scc.InputSize.Width;

            if (!InSizeFpsList(camerainfo.SupportedSizesAndFPS, CSF))
              if (ParametersOK(CSF))
                camerainfo.SupportedSizesAndFPS.Add(CSF);
          }
          catch (Exception)
          {
            //ErrorLogger.ProcessException(ex, false);
          }
        }

        Marshal.FreeCoTaskMem(pscc);
      }
      finally
      {
        if (graphBuilder != null)
        {
          Marshal.ReleaseComObject(graphBuilder);
        }
        if (capFilter != null)
        {
          Marshal.ReleaseComObject(capFilter);
        }
        if (capGraph != null)
        {
          Marshal.ReleaseComObject(capGraph);
        }
      }

      return camerainfo;
    }
예제 #2
0
        /// <summary>
        /// Returns the <see cref="CameraInfo"/> for the given <see cref="DsDevice"/>.
        /// </summary>
        /// <param name="dev">A <see cref="DsDevice"/> to parse name and capabilities for.</param>
        /// <returns>The <see cref="CameraInfo"/> for the given device.</returns>
        private CameraInfo Caps(DsDevice dev)
        {
            var camerainfo = new CameraInfo();

            // Get the graphbuilder object
            var graphBuilder = (IFilterGraph2) new FilterGraph();

            // Get the ICaptureGraphBuilder2
            var capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            IBaseFilter capFilter = null;

            try
            {
                int hr = capGraph.SetFiltergraph(graphBuilder);
                DsError.ThrowExceptionForHR(hr);

                // Add the video device
                hr = graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
                //        DsError.ThrowExceptionForHR(hr);

                if (hr != 0)
                {
                    Console.WriteLine("Error in m_graphBuilder.AddSourceFilterForMoniker(). Could not add source filter. Message: " + DsError.GetErrorText(hr));
                    return(null);
                }

                //hr = m_graphBuilder.AddFilter(capFilter, "Ds.NET Video Capture Device");
                //DsError.ThrowExceptionForHR(hr);

                object o    = null;
                DsGuid cat  = PinCategory.Capture;
                DsGuid type = MediaType.Interleaved;
                DsGuid iid  = typeof(IAMStreamConfig).GUID;

                // Check if Video capture filter is in use
                hr = capGraph.RenderStream(cat, MediaType.Video, capFilter, null, null);
                if (hr != 0)
                {
                    return(null);
                }

                //hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Interleaved, capFilter, typeof(IAMStreamConfig).GUID, out o);
                //if (hr != 0)
                //{
                hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter,
                                            typeof(IAMStreamConfig).GUID, out o);
                DsError.ThrowExceptionForHR(hr);
                //}

                var videoStreamConfig = o as IAMStreamConfig;

                int iCount = 0;
                int iSize  = 0;

                try
                {
                    if (videoStreamConfig != null)
                    {
                        videoStreamConfig.GetNumberOfCapabilities(out iCount, out iSize);
                    }
                }
                catch (Exception)
                {
                    //ErrorLogger.ProcessException(ex, false);
                    return(null);
                }

                pscc = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VideoStreamConfigCaps)));

                camerainfo.Name             = dev.Name;
                camerainfo.DirectshowDevice = dev;

                for (int i = 0; i < iCount; i++)
                {
                    VideoStreamConfigCaps scc;

                    try
                    {
                        AMMediaType curMedType;
                        if (videoStreamConfig != null)
                        {
                            hr = videoStreamConfig.GetStreamCaps(i, out curMedType, pscc);
                        }
                        Marshal.ThrowExceptionForHR(hr);
                        scc = (VideoStreamConfigCaps)Marshal.PtrToStructure(pscc, typeof(VideoStreamConfigCaps));


                        var CSF = new CamSizeFPS();
                        CSF.FPS    = (int)(10000000 / scc.MinFrameInterval);
                        CSF.Height = scc.InputSize.Height;
                        CSF.Width  = scc.InputSize.Width;

                        if (!InSizeFpsList(camerainfo.SupportedSizesAndFPS, CSF))
                        {
                            if (ParametersOK(CSF))
                            {
                                camerainfo.SupportedSizesAndFPS.Add(CSF);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //ErrorLogger.ProcessException(ex, false);
                    }
                }

                Marshal.FreeCoTaskMem(pscc);
            }
            finally
            {
                if (graphBuilder != null)
                {
                    Marshal.ReleaseComObject(graphBuilder);
                }
                if (capFilter != null)
                {
                    Marshal.ReleaseComObject(capFilter);
                }
                if (capGraph != null)
                {
                    Marshal.ReleaseComObject(capGraph);
                }
            }

            return(camerainfo);
        }
예제 #3
0
파일: DXCapture.cs 프로젝트: DeSciL/Ogama
    /// <summary>
    /// Returns the maximum and minimum capabilities of the 
    /// given <see cref="CameraInfo"/> for FPS and size.
    /// </summary>
    /// <param name="camera">The <see cref="CameraInfo"/> to be checked for.</param>
    /// <param name="minFramerate">Out. The minimum available framerate of this device.</param>
    /// <param name="maxFramerate">Out. The maximum available framerate of this device.</param>
    /// <param name="minWidth">Out. The minimum available width of this device.</param>
    /// <param name="maxWidth">Out. The maximum available width of this device.</param>
    /// <param name="minHeight">Out. The minimum available height of this device.</param>
    /// <param name="maxHeight">Out. The maximum available height of this device.</param>
    public void GetMaxMinCaps(
      CameraInfo camera,
      out int minFramerate,
      out int maxFramerate,
      out int minWidth,
      out int maxWidth,
      out int minHeight,
      out int maxHeight)
    {
      minFramerate = int.MaxValue;
      maxFramerate = 0;
      minWidth = int.MaxValue;
      maxWidth = 0;
      minHeight = int.MaxValue;
      maxHeight = 0;

      if (camera.Name == "OgamaScreenCapture Filter")
      {
        minFramerate = 1;
        maxFramerate = 100;
        minWidth = 1;
        maxWidth = 3000;
        minHeight = 1;
        maxHeight = 3000;
        return;
      }

      foreach (CamSizeFPS cap in camera.SupportedSizesAndFPS)
      {
        if (cap.FPS < minFramerate)
        {
          minFramerate = (int)cap.FPS;
        }

        if (cap.FPS > maxFramerate)
        {
          maxFramerate = (int)cap.FPS;
        }

        if (cap.Width < minWidth)
        {
          minWidth = (int)cap.Width;
        }

        if (cap.Width > maxWidth)
        {
          maxWidth = (int)cap.Width;
        }

        if (cap.Height < minHeight)
        {
          minHeight = (int)cap.Height;
        }

        if (cap.Height > maxHeight)
        {
          maxHeight = (int)cap.Height;
        }
      }
    }
예제 #4
0
  /// <summary>
  /// Initializes a new instance of the WebcamProperties class.
  /// </summary>
  /// <param name="newVideoInputDevice">The friendly name of the video input device to use.</param>
  /// <param name="newAudioInputDevice">The friendly name of the audio input device to use.</param>
  /// <param name="newVideoCompressor">The friendly name of the video compressor to use.</param>
  /// <param name="newAudioCompressor">The friendly name of the audio compressor to use.</param>
  /// <param name="newFrameRate">The frame rate for the video stream.</param>
  /// <param name="newVideoSize">The size of the video stream.</param>
  /// <param name="newFilename">The filename for the video recording.</param>
  /// <param name="newCaptureMode">The <see cref="CaptureMode"/> flags for the recording.</param>
  /// <param name="newPreviewWindow">The <see cref="Control"/> where the preview
  /// should be shown or null, if no preview should be shown.</param>
  public CaptureDeviceProperties(
    string newVideoInputDevice,
    string newAudioInputDevice,
    string newVideoCompressor,
    string newAudioCompressor,
    int newFrameRate,
    Size newVideoSize,
    string newFilename,
    CaptureMode newCaptureMode,
    Control newPreviewWindow)
 {
    this.videoInputDevice = new CameraInfo();
    this.videoInputDevice.Name = newVideoInputDevice;
    this.videoCompressor = newVideoCompressor;
    this.audioInputDevice = newAudioInputDevice;
    this.audioCompressor = newAudioCompressor;
    this.frameRate = newFrameRate;
    this.videoSize = newVideoSize;
    this.filename = newFilename;
    this.captureMode = newCaptureMode;
    this.previewWindow = newPreviewWindow;
 }
예제 #5
0
파일: DXCapture.cs 프로젝트: DeSciL/Ogama
    private void CheckFramerateAndSize(CameraInfo camera, int newFrameRate, Size newFrameSize)
    {
      if (camera != null)
      {
        int minFramerate;
        int maxFramerate;
        int minWidth;
        int maxWidth;
        int minHeight;
        int maxHeight;

        this.GetMaxMinCaps(
          camera,
          out minFramerate,
          out maxFramerate,
          out minWidth,
          out maxWidth,
          out minHeight,
          out maxHeight);

        CamSizeFPS defaultMode = camera.SupportedSizesAndFPS[camera.SupportedSizesAndFPS.Count - 1];

        if (newFrameRate > minFramerate && newFrameRate < maxFramerate)
        {
          this.captureDeviceProperties.FrameRate = newFrameRate;
        }
        else
        {
          this.captureDeviceProperties.FrameRate = defaultMode.FPS;
        }

        if (newFrameSize.Width >= minWidth && newFrameSize.Width <= maxWidth &&
          newFrameSize.Height >= minHeight && newFrameSize.Height <= maxHeight)
        {
          this.captureDeviceProperties.VideoSize = newFrameSize;
        }
        else
        {
          this.captureDeviceProperties.VideoSize =
            new Size(defaultMode.Width, defaultMode.Height);
        }
      }
    }