Пример #1
0
 /// <summary>
 /// loop through the list of the differnet sizes and FPS
 /// </summary>
 /// <param name="lst"></param>
 /// <param name="instance"></param>
 /// <returns></returns>
 private static bool InSizeFpsList(List <CamSizeFPS> lst, CamSizeFPS instance)
 {
     foreach (CamSizeFPS c in lst)
     {
         if (c.CompareTo(instance) == 0)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #2
0
 public int CompareTo(object obj)
 {
     if (obj is CamSizeFPS)
     {
         CamSizeFPS csf = (CamSizeFPS)obj;
         return((csf.Height + csf.Width + csf.FPS).CompareTo(this.Height + this.Width + this.FPS));
     }
     else
     {
         throw new ArgumentException("Object is not a CamSizeFPS");
     }
 }
Пример #3
0
        private bool ParametersOK(CamSizeFPS instance)
        {
            if (instance.FPS < minFps || instance.FPS > maxFps)
            {
                return(false);
            }

            if (instance.Width < minWidth || instance.Width > maxWidth)
            {
                return(false);
            }

            if (instance.Height < minHeight || instance.Height > maxHeight)
            {
                return(false);
            }

            return(true);
        }
Пример #4
0
    private bool ParametersOK(CamSizeFPS instance)
    {
      if (instance.FPS < minFps || instance.FPS > maxFps)
        return false;

      if (instance.Width < minWidth || instance.Width > maxWidth)
        return false;

      if (instance.Height < minHeight || instance.Height > maxHeight)
        return false;

      return true;
    }
Пример #5
0
 /// <summary>
 /// loop through the list of the differnet sizes and FPS
 /// </summary>
 /// <param name="lst"></param>
 /// <param name="instance"></param>
 /// <returns></returns>
 private static bool InSizeFpsList(List<CamSizeFPS> lst, CamSizeFPS instance)
 {
   foreach (CamSizeFPS c in lst)
     if (c.CompareTo(instance) == 0)
       return true;
   return false;
 }
Пример #6
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;
    }
Пример #7
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);
        }