public static bool GetDevicesOfCat( Guid cat, out ArrayList devs ) { devs = null; int hr; object comObj = null; ICreateDevEnum enumDev = null; UCOMIEnumMoniker enumMon = null; UCOMIMoniker[] mon = new UCOMIMoniker[1]; try { Type srvType = Type.GetTypeFromCLSID( Clsid.SystemDeviceEnum ); if( srvType == null ) throw new NotImplementedException( "System Device Enumerator" ); comObj = Activator.CreateInstance( srvType ); enumDev = (ICreateDevEnum) comObj; hr = enumDev.CreateClassEnumerator( ref cat, out enumMon, 0 ); if( hr != 0 ) throw new NotSupportedException( "No devices of the category" ); int f, count = 0; do { hr = enumMon.Next( 1, mon, out f ); if( (hr != 0) || (mon[0] == null) ) break; DsDevice dev = new DsDevice(); dev.Name = GetFriendlyName( mon[0] ); if( devs == null ) devs = new ArrayList(); dev.Mon = mon[0]; mon[0] = null; devs.Add( dev ); dev = null; count++; } while(true); return count > 0; } catch( Exception ) { if( devs != null ) { foreach( DsDevice d in devs ) d.Dispose(); devs = null; } return false; } 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; } }
private void okButton_Click(object sender, System.EventArgs e) { if( deviceListVw.SelectedItems.Count != 1 ) return; ListViewItem selitem = deviceListVw.SelectedItems[0]; SelectedDevice = selitem.Tag as DsDevice; Close(); }
private int width_; // リサイズ後の幅 #endregion Fields #region Constructors /// <summary> /// 各々のキャプチャデバイスを利用するためのクラス。 /// 幅、高さはデフォルト値が設定されます。 /// </summary> /// <param name="device">キャプチャデバイス</param> public CaptureDevice(DsDevice device) { device_ = device; name_ = device.Name; }
public static Image GetImage(DsDevice device) { Capture cam = new Capture(); try { cam.Init(device); cam.CaptureImage(); cam.CloseInterfaces(); return cam.image; } catch (Exception ex) { cam.CloseInterfaces(); Debug.WriteLine(ex); return null; } }
private void Init(DsDevice device) { // store it for clean up. capDevices = new ArrayList(); capDevices.Add(device); StartupVideo( device.Mon ); }
public static bool GetDevicesOfCat(Guid cat, out ArrayList devs) { bool flag; devs = null; object o = null; ICreateDevEnum enum2 = null; UCOMIEnumMoniker ppEnumMoniker = null; UCOMIMoniker[] rgelt = new UCOMIMoniker[1]; try { Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); if (typeFromCLSID == null) { throw new NotImplementedException("System Device Enumerator"); } o = Activator.CreateInstance(typeFromCLSID); enum2 = (ICreateDevEnum) o; if (enum2.CreateClassEnumerator(ref cat, out ppEnumMoniker, 0) != 0) { throw new NotSupportedException("No devices of the category"); } int num3 = 0; while (true) { int num2; if ((ppEnumMoniker.Next(1, rgelt, out num2) != 0) || (rgelt[0] == null)) { break; } DsDevice device = new DsDevice { Name = GetFriendlyName(rgelt[0]) }; if (devs == null) { devs = new ArrayList(); } device.Mon = rgelt[0]; rgelt[0] = null; devs.Add(device); device = null; num3++; } flag = num3 > 0; } catch (Exception) { if (devs != null) { foreach (DsDevice device2 in devs) { device2.Dispose(); } devs = null; } flag = false; } finally { enum2 = null; if (rgelt[0] != null) { Marshal.ReleaseComObject(rgelt[0]); } rgelt[0] = null; if (ppEnumMoniker != null) { Marshal.ReleaseComObject(ppEnumMoniker); } ppEnumMoniker = null; if (o != null) { Marshal.ReleaseComObject(o); } o = null; } return flag; }
public static bool GetDevicesOfCat(Guid cat, out ArrayList devs) { devs = null; int hr; object comObj = null; ICreateDevEnum enumDev = null; UCOMIEnumMoniker enumMon = null; UCOMIMoniker[] mon = new UCOMIMoniker[1]; try { Type srvType = Type.GetTypeFromCLSID(Clsid.SystemDeviceEnum); if (srvType == null) { throw new NotImplementedException("System Device Enumerator"); } comObj = Activator.CreateInstance(srvType); enumDev = (ICreateDevEnum)comObj; hr = enumDev.CreateClassEnumerator(ref cat, out enumMon, 0); if (hr != 0) { throw new NotSupportedException("No devices of the category"); } int f, count = 0; do { hr = enumMon.Next(1, mon, out f); if ((hr != 0) || (mon[0] == null)) { break; } DsDevice dev = new DsDevice(); dev.Name = GetFriendlyName(mon[0]); if (devs == null) { devs = new ArrayList(); } dev.Mon = mon[0]; mon[0] = null; devs.Add(dev); dev = null; count++; }while(true); return(count > 0); } catch (Exception) { if (devs != null) { foreach (DsDevice d in devs) { d.Dispose(); } devs = null; } return(false); } 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; } }
/// <summary> do cleanup and release DirectShow. </summary> void CloseInterfaces() { int hr; #if DEBUG if (rotCookie != 0) DsROT.RemoveGraphFromRot(ref rotCookie); #endif if (mediaCtrl != null) { hr = mediaCtrl.Stop(); Marshal.ReleaseComObject(mediaCtrl); mediaCtrl = null; } if (mediaEvt != null) { Marshal.ReleaseComObject(mediaEvt); mediaEvt = null; } if (baseGrabFlt != null) { Marshal.ReleaseComObject(baseGrabFlt); baseGrabFlt = null; } if (sampleGrabber != null) { Marshal.ReleaseComObject(sampleGrabber); sampleGrabber = null; } if (grabberConfig != null) { Marshal.ReleaseComObject(grabberConfig); grabberConfig = null; } if (capGraph != null) { Marshal.ReleaseComObject(capGraph); capGraph = null; } if (graphBuilder != null) { Marshal.ReleaseComObject(graphBuilder); graphBuilder = null; } if (dev != null) { dev.Dispose(); dev = null; } if (wmVideoDecoder != null) { Marshal.ReleaseComObject(wmVideoDecoder); wmVideoDecoder = null; } if (capFilter != null) { Marshal.ReleaseComObject(capFilter); capFilter = null; } if (capDevices != null) { foreach (DsDevice d in capDevices) d.Dispose(); capDevices = null; } if (atiCrossbar != null) { Marshal.ReleaseComObject(atiCrossbar); atiCrossbar = null; } if (motionVector != null) { Marshal.ReleaseComObject(motionVector); motionVector = null; } if (teeSplitter != null) { Marshal.ReleaseComObject(teeSplitter); teeSplitter = null; } if (videoRenderer != null) { Marshal.ReleaseComObject(videoRenderer); videoRenderer = null; } if (vectorGrabber != null) { //vectorGrabber.SetCallback(null); // FIXME: sometimes, this causes an exception Marshal.ReleaseComObject(vectorGrabber); vectorGrabber = null; } if (crossBar != null) { Marshal.ReleaseComObject(crossBar); crossBar = null; } }
/// <summary> detect first form appearance, start grabber. </summary> /// <fixme> There are three paths to activation: /// One opens a media file whose name is specified in the dsshost.exe.config file, /// another assumes that a particular video card is present, /// and the third asks the user to select a video input source. /// This module really only works for the first two paths. /// </fixme> public void Activate() { IMoniker moniker; IMoniker devmoniker; if (firstActive) return; firstActive = true; if (!DsUtils.IsCorrectDirectXVersion()) { LogInfo(LogGroups.Console, "DirectX 8.1 NOT installed!"); //this.Close(); return; } try { if (videoSource.Equals("File", StringComparison.CurrentCultureIgnoreCase)) { LogInfo(LogGroups.Console, "File to play : " + filePath); //capFilter = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.WM_ASF_Reader); } else if (videoSource.Equals("Analog", StringComparison.CurrentCultureIgnoreCase)) { atiCrossbar = (IBaseFilter)DsDev.CreateFromMoniker(ATICrossbar); capFilter = (IBaseFilter)DsDev.CreateFromMoniker(ATICapture); atiTVCardFound = true; } else // digital camera, may be a webcam { if (!DsDev.GetDevicesOfCat(FilterCategory.VideoInputDevice, out capDevices)) { LogInfo(LogGroups.Console, "No video capture devices found!"); return; } if (capDevices.Count == 1) dev = capDevices[0] as DsDevice; else { //DeviceSelector selector = new DeviceSelector(capDevices); //selector.ShowDialog(); //dev = selector.SelectedDevice; dev = capDevices[0] as DsDevice; } if (dev == null) { LogInfo(LogGroups.Console, "Cannot use first capture device found."); return; } CreateCaptureDevice(dev.Mon); } StartupVideo(); } catch (Exception ex) { LogInfo(LogGroups.Console, "Filter Graph can't start : " + ex.Message); } }