Represents a DirectShow filter (e.g. video capture device, compression codec).
To save a chosen filer for later recall save the MonikerString property on the filter:
string savedMonikerString = myFilter.MonikerString;
To recall the filter create a new Filter class and pass the string to the constructor:
Filter mySelectedFilter = new Filter(savedMonikerString);
Inheritance: IComparable
Esempio n. 1
0
        /// <summary> 
        /// Populate the InnerList with a list of filters from a particular category 
        /// </summary>
        protected void GetFilters(Guid category)
        {
            int hr;
            object comObj = null;
            ICreateDevEnum enumDev = null;
            UCOMIEnumMoniker enumMon = null;
            var mon = new UCOMIMoniker[1];

            try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID(Uuid.Clsid.SystemDeviceEnum);
                if (srvType == null)
                    throw new NotImplementedException("System Device Enumerator");
                comObj = Activator.CreateInstance(srvType);
                enumDev = (ICreateDevEnum)comObj;

                // Create an enumerator to find filters in category
                hr = enumDev.CreateClassEnumerator(ref category, out enumMon, 0);
                if (hr != 0)
                    return;
                    //throw new NotSupportedException("No devices of the category");


                // Loop through the enumerator
                int f;

                do
                {
                    // Next filter
                    hr = enumMon.Next(1, mon, out f);

                    if ((hr != 0) || (mon[0] == null))
                        break;

                    // Add the filter
                    var filter = new Filter(mon[0]);
                    InnerList.Add(filter);

                    // Release resources
                    Marshal.ReleaseComObject(mon[0]);
                    mon[0] = null;
                } while (true);

                // Sort
                InnerList.Sort();
            }
            finally
            {
                enumDev = null;
                if (mon[0] != null)
                    Marshal.ReleaseComObject(mon[0]); mon[0] = null;
                if (enumMon != null)
                    Marshal.ReleaseComObject(enumMon); enumMon = null;
                if (comObj != null)
                    Marshal.ReleaseComObject(comObj); comObj = null;
            }
        }
Esempio n. 2
0
        public void Unload()
        {
            if (Capture != null)
            {
                Capture.StopPreview();
                Capture.Dispose();
            }

            VideoDevice = null;

            GC.Collect();
        }
Esempio n. 3
0
        /// <summary>
        /// Default constructor of the Capture class.
        /// </summary>
        /// <param name="videoDevice">The video device to be the source.</param>
        /// <exception cref="ArgumentException">If no video device is provided.</exception>
        public CaptureWebcam(Filter videoDevice)
        {
            if (videoDevice == null)
                throw new ArgumentException("The videoDevice parameter must be set to a valid Filter.\n");

            this.VideoDevice = videoDevice;

            CreateGraph();
        }