DirectShow filter information.
Inheritance: IComparable
 private void StartDevice(FilterInfo device)
 {
     CMyVideoCaptureDevice videoSource = new CMyVideoCaptureDevice(device.MonikerString);
     videoSource.DeviceName = device.Name;
     videoSource.NewFrame += new NewFrameEventHandler(NewFrame_Handler);
     videoSource.Start();
 }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("请选择设备录像!");
                return;
            }

            this.Size = new Size(659, 415);
            foreach (FilterInfo i in devices)
            {
                if (i.Name == this.comboBox1.SelectedItem.ToString())
                {
                    currentDevice = i;
                }
            }
            currentVideoSource = Camera.connectDevice(currentDevice);
            if (this.comboBox2.SelectedIndex == -1)
            {
                currentVideoSource.DesiredFrameRate = 1;
            }
            else
            {
                currentVideoSource.DesiredFrameRate = int.Parse(this.comboBox2.SelectedItem.ToString());
            }
            currentVideoSource.DesiredFrameSize = new System.Drawing.Size(this.pixtureBox.Width, this.pixtureBox.Height);
            currentVideoSource.NewFrame        += videosource_NewFrame;
            Camera.openDevice(currentVideoSource);

            button1.Enabled = false;
            button2.Enabled = true;
            button3.Enabled = true;
            button4.Enabled = true;
        }
Exemple #3
0
 /// <summary>
 /// 开启摄像功能
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnStart_Click(object sender, EventArgs e)
 {
     AForge.Video.DirectShow.FilterInfo videoDevice = (AForge.Video.DirectShow.FilterInfo)comboBox1.Items[comboBox1.SelectedIndex];
     _videoSource           = new VideoCaptureDevice(videoDevice.MonikerString);
     _videoSource.NewFrame += VideoSource_NewFrame;// 更新帧图
     _videoSource.Start();
 }
Exemple #4
0
 private Webcam()
 {
     _videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
     _currentDevice = _videoDevices.Cast<FilterInfo>().First();
     _videoSource = new VideoCaptureDevice(_currentDevice.MonikerString);
     _videoSource.NewFrame += _videoSource_NewFrame;
     _takePicture = false;
 }
        private void OnCurrentDeviceChanged(FilterInfo filterInfo)
        {
            if (_currentDevice != null)
            {
                _currentDevice.Stop();
                _currentDevice.NewFrame -= DeviceOnNewFrame;
            }
            _currentDevice = new VideoCaptureDevice(filterInfo.MonikerString);

            CurrentDeviceCapabilities = new ObservableCollection<VideoCapabilities>(_currentDevice.VideoCapabilities);
            SelectedDeviceCapabilities = CurrentDeviceCapabilities.FirstOrDefault();

            _currentDevice.NewFrame += DeviceOnNewFrame;
        }
Exemple #6
0
        /// <summary>
        /// Create an instance of the filter.
        /// </summary>
        /// 
        /// <param name="filterMoniker">Filter's moniker string.</param>
        /// 
        /// <returns>Returns filter's object, which implements <b>IBaseFilter</b> interface.</returns>
        /// 
        /// <remarks>The returned filter's object should be released using <b>Marshal.ReleaseComObject()</b>.</remarks>
        /// 
        public static object CreateFilter( string filterMoniker )
        {
            object filterObject = null;
            object comObj = null;
            ICreateDevEnum enumDev;
            IEnumMoniker enumMon = null;
            var devMon = new IMoniker[1];

            try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum);
                if (srvType == null)
                    throw new ApplicationException("Failed creating device enumerator");

                // create device enumerator
                comObj = Activator.CreateInstance(srvType);
                enumDev = (ICreateDevEnum)comObj;

                // Create an enumerator to find filters of specified category

                Guid cat = FilterCategory.VideoInputDevice;
                int hr = enumDev.CreateClassEnumerator(ref cat, out enumMon, 0);
                if (hr != 0)
                    throw new ApplicationException("No devices of the category");

                // Collect all filters
                IntPtr n = IntPtr.Zero;
                while (true)
                {
                    // Get next filter
                    hr = enumMon.Next(1, devMon, n);
                    if ((hr != 0) || (devMon[0] == null))
                        break;

                    // Add the filter
                    var filter = new FilterInfo(devMon[0]);
                    if (filter.MonikerString == filterMoniker)
                    {
                        Guid filterId = typeof(IBaseFilter).GUID;
                        devMon[0].BindToObject(null, null, ref filterId, out filterObject);
                        break;
                    }

                    // Release COM object
                    Marshal.ReleaseComObject(devMon[0]);
                    devMon[0] = null;
                }
            }
            catch
            {
            }
            finally
            {
                // release all COM objects
                enumDev = null;
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                    comObj = null;
                }
                if (enumMon != null)
                {
                    Marshal.ReleaseComObject(enumMon);
                    enumMon = null;
                }
                if (devMon[0] != null)
                {
                    Marshal.ReleaseComObject(devMon[0]);
                    devMon[0] = null;
                }
            }
            return filterObject;

            //// filter's object
            //object filterObject = null;
            //// bind context and moniker objects
            //IBindCtx bindCtx = null;
            //IMoniker moniker = null;

            //int n = 0;

            //// create bind context
            //if ( Win32.CreateBindCtx( 0, out bindCtx ) == 0 )
            //{
            //    // convert moniker`s string to a moniker
            //    if ( Win32.MkParseDisplayName( bindCtx, filterMoniker, ref n, out moniker ) == 0 )
            //    {
            //        // get device base filter
            //        Guid filterId = typeof( IBaseFilter ).GUID;
            //        moniker.BindToObject( null, null, ref filterId, out filterObject );

            //        Marshal.ReleaseComObject( moniker );
            //    }
            //    Marshal.ReleaseComObject( bindCtx );
            //}
            //return filterObject;
        }
Exemple #7
0
        // Collect filters of specified category
        private void CollectFilters( Guid category )
        {
            object			comObj = null;
            ICreateDevEnum	enumDev;
            IEnumMoniker	enumMon = null;
            var		devMon = new IMoniker[1];

            try
            {
                // Get the system device enumerator
                Type srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum );
                if ( srvType == null )
                    throw new ApplicationException( "Failed creating device enumerator" );

                // create device enumerator
                comObj = Activator.CreateInstance( srvType );
                enumDev = (ICreateDevEnum) comObj;

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

                // Collect all filters
                IntPtr n = IntPtr.Zero;
                while ( true )
                {
                    // Get next filter
                    hr = enumMon.Next( 1, devMon, n );
                    if ( ( hr != 0 ) || ( devMon[0] == null ) )
                        break;

                    // Add the filter
                    var filter = new FilterInfo( devMon[0] );
                    InnerList.Add( filter );

                    // Release COM object
                    Marshal.ReleaseComObject( devMon[0] );
                    devMon[0] = null;
                }

                // Sort the collection
                InnerList.Sort( );
            }
            catch
            {
            }
            finally
            {
                // release all COM objects
                enumDev = null;
                if ( comObj != null )
                {
                    Marshal.ReleaseComObject( comObj );
                    comObj = null;
                }
                if ( enumMon != null )
                {
                    Marshal.ReleaseComObject( enumMon );
                    enumMon = null;
                }
                if ( devMon[0] != null )
                {
                    Marshal.ReleaseComObject( devMon[0] );
                    devMon[0] = null;
                }
            }
        }
Exemple #8
0
        // Display property page for the specified object
        private void DisplayPropertyPage( IntPtr parentWindow, object sourceObject )
        {
            try
            {
                // retrieve ISpecifyPropertyPages interface of the device
                var pPropPages = (ISpecifyPropertyPages) sourceObject;

                // get property pages from the property bag
                CAUUID caGUID;
                pPropPages.GetPages( out caGUID );

                // get filter info
                var filterInfo = new FilterInfo( _deviceMoniker );

                // create and display the OlePropertyFrame
                Win32.OleCreatePropertyFrame( parentWindow, 0, 0, filterInfo.Name, 1, ref sourceObject, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero );

                // release COM objects
                Marshal.FreeCoTaskMem( caGUID.pElems );
            }
            catch
            {
            }
        }
Exemple #9
0
 private void DeviceSetting_ApplyDevices(AForge.Video.DirectShow.FilterInfo cameraInfo, CSCore.CoreAudioAPI.MMDevice microphoneInfo, CSCore.CoreAudioAPI.MMDevice speakerInfo)
 {
     StopMedia();
     StartMedia(cameraInfo, microphoneInfo, speakerInfo);
 }