Exemplo n.º 1
0
        private HResult UpdateDeviceList()
        {
            // Remove any previous list
            cbDeviceList.Items.Clear();
            cbDeviceList.Text = "";

            // Query MF for the devices
            MFDevice [] arDevices = MFDevice.GetDevicesOfCat(CLSID.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);

            // Walk the list
            cbDeviceList.BeginUpdate();
            for (int iDevice = 0; iDevice < arDevices.Length; iDevice++)
            {
                // Add it to the combo box
                cbDeviceList.Items.Add(arDevices[iDevice]);
            }
            cbDeviceList.EndUpdate();

            // If there's at least 1 item
            if (cbDeviceList.Items.Count > 0)
            {
                // Select the first item.
                cbDeviceList.SelectedIndex = 0;
            }

            return(0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns an array of DsDevices of type devcat.
        /// </summary>
        /// <param name="cat">Any one of FilterCategory</param>
        public static MFDevice[] GetDevicesOfCat(Guid FilterCategory)
        {
            // Use arrayList to build the retun list since it is easily resizable
            MFDevice[]    devret = null;
            IMFActivate[] ppDevices;

            //////////

            HResult       hr          = 0;
            IMFAttributes pAttributes = null;

            // Initialize an attribute store. We will use this to
            // specify the enumeration parameters.

            hr = MFExtern.MFCreateAttributes(out pAttributes, 1);

            // Ask for source type = video capture devices
            if (hr >= 0)
            {
                hr = pAttributes.SetGUID(
                    MFAttributesClsid.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
                    FilterCategory
                    );
            }

            // Enumerate devices.
            int cDevices;

            if (hr >= 0)
            {
                hr = MFExtern.MFEnumDeviceSources(pAttributes, out ppDevices, out cDevices);

                if (hr >= 0)
                {
                    devret = new MFDevice[cDevices];

                    for (int x = 0; x < cDevices; x++)
                    {
                        devret[x] = new MFDevice(ppDevices[x]);
                    }
                }
            }

            if (pAttributes != null)
            {
                Marshal.ReleaseComObject(pAttributes);
            }

            return(devret);
        }
Exemplo n.º 3
0
        private HResult GetSelectedDevice(out IMFActivate ppActivate)
        {
            // First get the index of the selected item in the combo box.
            int iListIndex = cbDeviceList.SelectedIndex;

            if (iListIndex < 0)
            {
                ppActivate = null;
                return(HResult.E_FAIL);
            }

            // Parse out the IMFActivate
            MFDevice di = cbDeviceList.SelectedItem as MFDevice;

            ppActivate = di.Activator;

            return(0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns an array of DsDevices of type devcat.
        /// </summary>
        /// <param name="cat">Any one of FilterCategory</param>
        public static MFDevice[] GetDevicesOfCat(Guid FilterCategory)
        {
            // Use arrayList to build the retun list since it is easily resizable
            MFDevice[] devret = null;
            IMFActivate[] ppDevices;

            //////////

            int hr = 0;
            IMFAttributes pAttributes = null;

            // Initialize an attribute store. We will use this to
            // specify the enumeration parameters.

            hr = MFExtern.MFCreateAttributes(out pAttributes, 1);

            // Ask for source type = video capture devices
            if (hr >= 0)
            {
                hr = pAttributes.SetGUID(
                    MFAttributesClsid.MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
                    FilterCategory
                    );
            }

            // Enumerate devices.
            int cDevices;
            if (hr >= 0)
            {
                hr = MFExtern.MFEnumDeviceSources(pAttributes, out ppDevices, out cDevices);

                if (hr >= 0)
                {
                    devret = new MFDevice[cDevices];

                    for (int x = 0; x < cDevices; x++)
                    {
                        devret[x] = new MFDevice(ppDevices[x]);
                    }
                }
            }

            if (pAttributes != null)
            {
                Marshal.ReleaseComObject(pAttributes);
            }

            return devret;
        }