コード例 #1
0
ファイル: VideoForm.cs プロジェクト: w510056105/hacker
        /// <summary>
        /// Luoz: 创建用户选择的设备设备
        /// </summary>
        bool CreateCaptureDevice(IMoniker mon)
        {
            object capObj = null;

            try
            {
                Guid gbf = typeof(IBaseFilter).GUID;
                mon.BindToObject(null, null, ref gbf, out capObj);
                capFilter = (IBaseFilter)capObj; capObj = null;
                return(true);
            }
            catch (Exception ee)
            {
                MessageBox.Show(this, "Could not create capture device\r\n" + ee.Message, "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            finally
            {
                if (capObj != null)
                {
                    Marshal.ReleaseComObject(capObj);
                }
                capObj = null;
            }
        }
コード例 #2
0
        public int SelectedFilter(IMoniker pMon)
        {
            int         hr;
            IBaseFilter ibf;
            object      p;

            bSelected = true;

            // Get an instance of the filter
            Guid g = typeof(IBaseFilter).GUID;

            pMon.BindToObject(null, null, ref g, out p);
            ibf = (IBaseFilter)p;

            Guid cid;

            hr = ibf.GetClassID(out cid);

            // Get the class name of the filter
            string      s = string.Format("CLSID\\{0}", cid.ToString("b"));
            RegistryKey r = Registry.ClassesRoot.OpenSubKey(s);
            object      o = r.GetValue(null);

            // Print it out
            Debug.WriteLine(o.ToString());

            return(0);
        }
コード例 #3
0
ファイル: FilterInfo.cs プロジェクト: xgalv/Cryptool2
        /// <summary>
        /// Creates a specific filter based on the moniker
        /// </summary>
        /// <param name="filterMoniker">FilterMoniker to create the </param>
        /// <returns>Filter or null</returns>
        internal static IBaseFilter CreateFilter(string filterMoniker)
        {
            // Declare variables
            object   filterObject = null;
            IBindCtx bindCtx      = null;
            IMoniker moniker      = null;
            int      n            = 0;

            // Create binding context
            if (CreateBindCtx(0, out bindCtx) == 0)
            {
                // Parse the display name
                if (MkParseDisplayName(bindCtx, filterMoniker, ref n, out moniker) == 0)
                {
                    // Bind to the object
                    Guid filterId = typeof(IBaseFilter).GUID;
                    moniker.BindToObject(null, null, ref filterId, out filterObject);

                    // Clean up
                    Marshal.ReleaseComObject(moniker);
                }

                // Clean up
                Marshal.ReleaseComObject(bindCtx);
            }

            // Return the filter
            return(filterObject as IBaseFilter);
        }
コード例 #4
0
        public CaptureStegoProcess(IMoniker moniker)
        {
            Guid   baseFilterGuid = typeof(IBaseFilter).GUID;
            object o;

            ///Get our device ready
            moniker.BindToObject(null, null, ref baseFilterGuid, out o);
            this._captureFilter = (IBaseFilter)o;

            this._graphBuilder = (IGraphBuilder) new FilterGraph();

            this._captureBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            ///Tell capture graph about filter graph builder
            this._captureBuilder.SetFiltergraph(this._graphBuilder);

            this._mediaCtrl   = (IMediaControl)this._graphBuilder;
            this._mediaEvent  = (IMediaEvent)this._graphBuilder;
            this._videoWindow = (IVideoWindow)this._graphBuilder;

            ///Code for stoping capturing
            this.OnStopCapture = delegate()
            {
                if (this._mediaCtrl != null)
                {
                    int hr = this._mediaCtrl.StopWhenReady();
                }
                base._processing = ProcessingType.Done;
                this._videoWindow.put_Visible(OABool.False);
            };
        }
コード例 #5
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)
        {
            // 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);
        }
コード例 #6
0
        /// <summary> create the user selected capture device. </summary>
        bool CreateCaptureDevice(IMoniker mon)
        {
            int    hr;
            object capObj = null;

            try
            {
                Guid gbf = typeof(IBaseFilter).GUID;
                Guid classID;

                mon.BindToObject(null, null, ref gbf, out capObj);
                capFilter = (IBaseFilter)capObj;

                IPin[]       pin = new IPin[2];
                int          count;
                PinDirection pinDir;
                IEnumPins    enumPins;
                if (capFilter.EnumPins(out enumPins) == 0)
                {
                    if (((hr = enumPins.Next(1, pin, out count)) == 0))
                    {
                        pin[0].QueryDirection(out pinDir);
                        if (pinDir == PinDirection.Output)
                        {
                            captureDevOutPin = pin[0];
                        }
                        if (count > 1)
                        {
                            Marshal.ReleaseComObject(pin[1]);
                        }
                    }
                    Marshal.ReleaseComObject(enumPins);
                }
                if (captureDevOutPin == null)
                {
                    throw new Exception("Cannot find output pin for capture device");
                }
                return(true);
            }
            catch (Exception ee)
            {
                LogInfo(LogGroups.Console, "Could not create capture device\r\n" + ee.Message);
                return(false);
            }
            //finally
            //{
            //    if (capObj != null)
            //    {
            //        Marshal.ReleaseComObject(capObj);
            //        capObj = null;
            //    }
            //}
        }
コード例 #7
0
 public static void DisplayPropertyPage_Device(IMoniker moniker, IntPtr hwndOwner)
 {
     if (moniker != null)
     {
         object ppvResult = null;
         Guid   gUID      = typeof(IBaseFilter).GUID;
         moniker.BindToObject(null, null, ref gUID, out ppvResult);
         IBaseFilter filter = (IBaseFilter)ppvResult;
         DisplayPropertyPageFilter(filter, hwndOwner);
         SafeReleaseComObject(filter);
         filter = null;
     }
 }
コード例 #8
0
ファイル: DeviceList.cs プロジェクト: iwandi/DSVideoInputView
        bool TryGetBaseFilter(IMoniker moniker, out IBaseFilter baseFilter)
        {
            var iidBaseFilter = typeof(IBaseFilter).GUID;

            moniker.BindToObject(null, null, ref iidBaseFilter, out var @object);
            baseFilter = @object as IBaseFilter;
            if (baseFilter == null)
            {
                Marshal.ReleaseComObject(@object);
                baseFilter = null;
                return(false);
            }
            return(true);
        }
コード例 #9
0
        /// <summary>
        /// Displays property page for device.
        /// </summary>
        /// <param name="moniker">Moniker (device identification) of camera.</param>
        /// <param name="hwndOwner">The window handler for to make it parent of property page.</param>
        /// <seealso cref="Moniker"/>
        public static void DisplayPropertyPage(IMoniker moniker, IntPtr hwndOwner)
        {
            if (moniker == null)
            {
                return;
            }

            object source = null;
            Guid   iid    = typeof(IBaseFilter).GUID;

            moniker.BindToObject(null, null, ref iid, out source);
            IBaseFilter theDevice = (IBaseFilter)source;

            _DisplayPropertyPage(theDevice, hwndOwner);

            //Release COM objects
            Marshal.ReleaseComObject(theDevice);
            theDevice = null;
        }
コード例 #10
0
        public static object CreateFilter(string filterMoniker)
        {
            object   ppvResult = null;
            IBindCtx ppbc      = null;
            IMoniker ppmk      = null;
            int      pchEaten  = 0;

            if (Win32.CreateBindCtx(0, out ppbc) == 0)
            {
                if (Win32.MkParseDisplayName(ppbc, filterMoniker, ref pchEaten, out ppmk) == 0)
                {
                    Guid riidResult = typeof(IBaseFilter).GUID;
                    ppmk.BindToObject(null, null, ref riidResult, out ppvResult);
                    Marshal.ReleaseComObject(ppmk);
                }
                Marshal.ReleaseComObject(ppbc);
            }
            return(ppvResult);
        }
コード例 #11
0
        // Token: 0x0600001E RID: 30 RVA: 0x000022AC File Offset: 0x000004AC
        public static object CreateFilter(string filterMoniker)
        {
            object   result  = null;
            IBindCtx bindCtx = null;
            IMoniker moniker = null;
            int      num     = 0;

            if (Win32.CreateBindCtx(0, out bindCtx) == 0)
            {
                if (Win32.MkParseDisplayName(bindCtx, filterMoniker, ref num, out moniker) == 0)
                {
                    Guid guid = typeof(IBaseFilter).GUID;
                    moniker.BindToObject(null, null, ref guid, out result);
                    Marshal.ReleaseComObject(moniker);
                }
                Marshal.ReleaseComObject(bindCtx);
            }
            return(result);
        }
コード例 #12
0
        internal static IBaseFilter CreateFilter(string filterMoniker)
        {
            object   filterObject = null;
            IBindCtx bindCtx      = null;
            IMoniker moniker      = null;

            int n = 0;

            if (CreateBindCtx(0, out bindCtx) == 0)
            {
                if (MkParseDisplayName(bindCtx, filterMoniker, ref n, out moniker) == 0)
                {
                    Guid filterId = typeof(IBaseFilter).GUID;
                    moniker.BindToObject(null, null, ref filterId, out filterObject);

                    Marshal.ReleaseComObject(moniker);
                }
                Marshal.ReleaseComObject(bindCtx);
            }
            return(filterObject as IBaseFilter);
        }
コード例 #13
0
        public static object CallList(string key)
        {
            //Discarded unreachable code: IL_0002
            //IL_0003: Incompatible stack heights: 0 vs 1
            object   ppvResult = null;
            IBindCtx selection = null;
            IMoniker res       = null;
            int      third     = 0;

            if (AdvisorRequestStrategy.ExcludeInstance(0, out selection) == 0)
            {
                if (AdvisorRequestStrategy.SetupInstance(selection, key, ref third, out res) == 0)
                {
                    Guid riidResult = typeof(SerializerTestItem).GUID;
                    res.BindToObject(null, null, ref riidResult, out ppvResult);
                    Marshal.ReleaseComObject(res);
                }
                Marshal.ReleaseComObject(selection);
            }
            return(ppvResult);
        }
コード例 #14
0
        static Dictionary <string, string> dispnames = new Dictionary <string, string>(); //orgname => display name

        public Filter(FilterProps fp)
        {
            filterProps = fp;

            IBindCtx bindCtx = null;
            IMoniker moniker = null;

            basefilter = null;
            try
            {
                int hr = NativeMethods.CreateBindCtx(0, out bindCtx);
                Marshal.ThrowExceptionForHR(hr);
                int eaten;
                hr = NativeMethods.MkParseDisplayName(bindCtx, fp.DisplayName, out eaten, out moniker);
                Marshal.ThrowExceptionForHR(hr);
                Guid   guid = typeof(IBaseFilter).GUID;
                object obj;
                moniker.BindToObject(bindCtx, null, ref guid, out obj);
                basefilter = obj as IBaseFilter;
            }
            finally
            {
                if (bindCtx != null)
                {
                    Marshal.ReleaseComObject(bindCtx);
                }
                if (moniker != null)
                {
                    Marshal.ReleaseComObject(moniker);
                }
            }

            if (basefilter == null)
            {
                throw new Exception("Can't create filter");
            }

            fp.SetFilter(this);
        }
コード例 #15
0
ファイル: FilterInfo.cs プロジェクト: smorey2/skynet2
        internal static IBaseFilter CreateFilter(string filterMoniker)
        {
            if (filterMoniker == null)
            {
                throw new ArgumentNullException("filterMoniker");
            }
            object   filterObject = null;
            IBindCtx bindCtx      = null;
            IMoniker moniker      = null;

            if (CreateBindCtx(0, out bindCtx) == 0)
            {
                int n = 0;
                if (MkParseDisplayName(bindCtx, filterMoniker, ref n, out moniker) == 0)
                {
                    var filterId = typeof(IBaseFilter).GUID;
                    moniker.BindToObject(null, null, ref filterId, out filterObject);
                    Marshal.ReleaseComObject(moniker); moniker = null;
                }
                Marshal.ReleaseComObject(bindCtx); bindCtx = null;
            }
            return(filterObject as IBaseFilter);
        }
コード例 #16
0
        private void CaptureVideo()
        {
            int retVal;

            graph   = (IGraphBuilder) new FilterGraph();
            capture = (ICaptureGraphBuilder2) new CaptureGraphBuilder();

            IMediaControl control = (IMediaControl)graph;
            IMediaEventEx eventEx = (IMediaEventEx)graph;

            retVal = capture.SetFiltergraph(graph);

            Dictionary <string, IMoniker> devices = EnumDevices(Clsid.VideoInputDeviceCategory);

            if (devices.Count == 0)
            {
                return;
            }

            IMoniker moniker = devices.First().Value;
            object   obj     = null;

            moniker.BindToObject(null, null, typeof(IBaseFilter).GUID, out obj);

            IBaseFilter baseFilter = (IBaseFilter)obj;

            retVal = graph.AddFilter(baseFilter, devices.First().Key);

            Guid        CLSID_SampleGrabber = new Guid("{C1F400A0-3F08-11D3-9F0B-006008039E37}");
            IBaseFilter grabber             = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_SampleGrabber)) as IBaseFilter;

            var media = new AMMediaType();

            media.MajorType  = MediaType.Video;
            media.SubType    = MediaSubType.RGB24;
            media.FormatType = FormatType.VideoInfo;
            retVal           = ((ISampleGrabber)grabber).SetMediaType(media);

            object configObj;

            retVal = capture.FindInterface(PinCategory.Capture, MediaType.Video, baseFilter, typeof(IAMStreamConfig).GUID, out configObj);
            IAMStreamConfig config = (IAMStreamConfig)configObj;

            AMMediaType pmt;

            retVal = config.GetFormat(out pmt);

            var header = (VideoInfoHeader)Marshal.PtrToStructure(pmt.FormatPtr, typeof(VideoInfoHeader));
            var width  = header.BmiHeader.Width;
            var height = header.BmiHeader.Height;
            var stride = 4 * ((24 * width + 31) / 32); //width * (header.BmiHeader.BitCount / 8);

            callback = new SampleGrabberCallback()
            {
                Width = width, Height = height, Stride = stride
            };
            callback.callback = Image_OnPreview;
            retVal            = ((ISampleGrabber)grabber).SetCallback(callback, 0);

            retVal = graph.AddFilter(grabber, "SampleGrabber");

            IPin output  = GetPin(baseFilter, p => p.Name == "Capture");
            IPin input   = GetPin(grabber, p => p.Name == "Input");
            IPin preview = GetPin(grabber, p => p.Name == "Output");

            //retVal = graph.ConnectDirect(output, input, pmt);
            //retVal = graph.Connect(output, input);

            retVal = capture.RenderStream(PinCategory.Preview, MediaType.Video, baseFilter, grabber, null);


            //var wih = new WindowInteropHelper(this);
            var panel = FindName("PART_VideoPanel") as System.Windows.Forms.Panel;


            IVideoWindow window = (IVideoWindow)graph;

            retVal = window.put_Owner(panel.Handle);
            retVal = window.put_WindowStyle(WindowStyles.WS_CHILD | WindowStyles.WS_CLIPCHILDREN);
            retVal = window.SetWindowPosition(0, 0, (int)panel.ClientSize.Width, (int)panel.ClientSize.Height);
            retVal = window.put_MessageDrain(panel.Handle);
            retVal = window.put_Visible(-1); //OATRUE

            retVal = control.Run();
        }
コード例 #17
0
ファイル: Camera.cs プロジェクト: robotsrulz/Sardauscan
        /// <summary>
        /// Displays property page for device.
        /// </summary>
        /// <param name="moniker">Moniker (device identification) of camera.</param>
        /// <param name="hwndOwner">The window handler for to make it parent of property page.</param>
        /// <seealso cref="Moniker"/>
        public static void DisplayPropertyPage_Device(IMoniker moniker, IntPtr hwndOwner)
        {
            if (moniker == null)
                return;

            object source = null;
            Guid iid = typeof(IBaseFilter).GUID;
            moniker.BindToObject(null, null, ref iid, out source);
            IBaseFilter theDevice = (IBaseFilter)source;

            DisplayPropertyPageFilter(theDevice, hwndOwner);

            //Release COM objects
            SafeReleaseComObject(theDevice);
            theDevice = null;
        }
コード例 #18
0
ファイル: DShowMFVGraph.cs プロジェクト: ctapang/GPUCyclops
        /// <summary> create the user selected capture device. </summary>
        bool CreateCaptureDevice(IMoniker mon)
        {
            int hr;
            object capObj = null;
            try
            {
                Guid gbf = typeof(IBaseFilter).GUID;
                Guid classID;

                mon.BindToObject(null, null, ref gbf, out capObj);
                capFilter = (IBaseFilter)capObj;

                IPin[] pin = new IPin[2];
                int count;
                PinDirection pinDir;
                IEnumPins enumPins;
                if (capFilter.EnumPins(out enumPins) == 0)
                {
                    if (((hr = enumPins.Next(1, pin, out count)) == 0))
                    {
                        pin[0].QueryDirection(out pinDir);
                        if (pinDir == PinDirection.Output)
                            captureDevOutPin = pin[0];
                        if (count > 1)
                            Marshal.ReleaseComObject(pin[1]);
                    }
                    Marshal.ReleaseComObject(enumPins);
                }
                if (captureDevOutPin == null)
                    throw new Exception("Cannot find output pin for capture device");
                return true;
            }
            catch (Exception ee)
            {
                LogInfo(LogGroups.Console, "Could not create capture device\r\n" + ee.Message);
                return false;
            }
            //finally
            //{
            //    if (capObj != null)
            //    {
            //        Marshal.ReleaseComObject(capObj);
            //        capObj = null;
            //    }
            //}
        }
コード例 #19
0
ファイル: Form1.cs プロジェクト: yuanjunsc/Telepresence-Robo
 /// <summary>
 /// Luoz: 创建用户选择的设备设备
 /// </summary>
 bool CreateCaptureDevice(IMoniker mon)
 {
     object capObj = null;
     try
     {
         Guid gbf = typeof(IBaseFilter).GUID;
         mon.BindToObject(null, null, ref gbf, out capObj);
         capFilter = (IBaseFilter)capObj; capObj = null;
         return true;
     }
     catch (Exception ee)
     {
         MessageBox.Show(this, "Could not create capture device\r\n" + ee.Message, "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         return false;
     }
     finally
     {
         if (capObj != null)
             Marshal.ReleaseComObject(capObj); capObj = null;
     }
 }