Ejemplo n.º 1
0
        /// <summary>
        /// Returns a list of the enabled webcam devices of the system. Returns null if no enabled webcam devices are present. See also: Player.Webcam.DeviceCount.
        /// </summary>
        public WebcamDevice[] GetDevices()
        {
            WebcamDevice[] devices = null;
            HResult        result;

            MFExtern.MFCreateAttributes(out IMFAttributes attributes, 1);
            attributes.SetGUID(MFAttributesClsid.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MFAttributesClsid.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);

            result = MFExtern.MFEnumDeviceSources(attributes, out IMFActivate[] webcams, out int webcamCount);
            if (result == Player.NO_ERROR && webcams != null)
            {
                devices = new WebcamDevice[webcamCount];
                for (int i = 0; i < webcamCount; i++)
                {
                    devices[i] = new WebcamDevice();
#pragma warning disable IDE0059 // Unnecessary assignment of a value
                    webcams[i].GetString(MFAttributesClsid.MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, _base._textBuffer1, _base._textBuffer1.Capacity, out int length);
                    devices[i]._name = _base._textBuffer1.ToString();
                    webcams[i].GetString(MFAttributesClsid.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, _base._textBuffer1, _base._textBuffer1.Capacity, out length);
#pragma warning restore IDE0059 // Unnecessary assignment of a value
                    devices[i]._id = _base._textBuffer1.ToString();

                    Marshal.ReleaseComObject(webcams[i]);
                }
            }
            Marshal.ReleaseComObject(attributes);

            _base._lastError = result;
            return(devices);
        }
Ejemplo n.º 2
0
        internal WebcamFormat GetHighFormat(WebcamDevice webcam, bool photo)
        {
            WebcamFormat format = null;

            WebcamFormat[] formats = GetWebcamFormats(webcam._id, false, false, 0, 0, 0);
            if (formats != null)
            {
                format = formats[0];
                int count     = formats.Length;
                int frameRate = photo ? 1 : 15;

                for (int i = 1; i < count; i++)
                {
                    if (formats[i]._width >= format._width &&
                        formats[i]._height >= format._height &&
                        formats[i]._frameRate >= format._frameRate)
                    {
                        format = formats[i];
                    }
                    else if (formats[i]._width > format._width &&
                             formats[i]._height > format._height &&
                             formats[i]._frameRate >= frameRate)
                    {
                        format = formats[i];
                    }
                }
            }
            return(format);
        }
Ejemplo n.º 3
0
        internal WebcamFormat GetLowFormat(WebcamDevice webcam)
        {
            WebcamFormat format = null;

            WebcamFormat[] formats = GetWebcamFormats(webcam._id, false, false, 0, 0, 0);
            if (formats != null)
            {
                format = formats[0];
                int count = formats.Length;

                for (int i = 1; i < count; i++)
                {
                    if (formats[i]._width <= format._width &&
                        formats[i]._height <= format._height &&
                        formats[i]._height >= 100 &&
                        formats[i]._frameRate <= format._frameRate &&
                        formats[i]._frameRate >= 15)
                    {
                        format = formats[i];
                    }
                }
            }
            return(format);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns the available video output formats (or null) of the specified webcam that match the specified values. The formats can be used with the Player.Play methods for webcams.
 /// </summary>
 /// <param name="webcam">The webcam whose video output formats are to be obtained.</param>
 /// <param name="exact">A value that indicates whether the specified values must exactly match the webcam formats or whether they are minimum values.</param>
 /// <param name="width">The (minimum) width of the video frames. Use -1 to ignore this parameter.</param>
 /// <param name="height">The (minimum) height of the video frames. Use -1 to ignore this parameter.</param>
 /// <param name="frameRate">The (minimum) frame rate of the video output format. Use -1 to ignore this parameter.</param>
 public WebcamFormat[] GetFormats(WebcamDevice webcam, bool exact, int width, int height, float frameRate)
 {
     return(GetWebcamFormats(webcam._id, true, exact, width, height, frameRate));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns the available video output formats of the specified webcam. The formats can be used with the Player.Play methods for webcams.
 /// </summary>
 /// <param name="webcam">The webcam whose video output formats are to be obtained.</param>
 public WebcamFormat[] GetFormats(WebcamDevice webcam)
 {
     return(GetWebcamFormats(webcam._id, false, false, 0, 0, 0));
 }