コード例 #1
0
        protected bool addIfSupported(object o, string name)
        {
            ISpecifyPropertyPages specifyPropertyPages = null;
            DsCAUUID pPages = new DsCAUUID();
            bool     flag   = false;

            try
            {
                specifyPropertyPages = o as ISpecifyPropertyPages;
                if ((specifyPropertyPages != null) && ((specifyPropertyPages.GetPages(out pPages) != 0) || (pPages.cElems <= 0)))
                {
                    specifyPropertyPages = null;
                }
            }
            finally
            {
                if (pPages.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pPages.pElems);
                }
            }
            if (specifyPropertyPages != null)
            {
                DirectShowPropertyPage page = new DirectShowPropertyPage(name, specifyPropertyPages);
                base.InnerList.Add(page);
                flag = true;
            }
            return(flag);
        }
コード例 #2
0
        private void ShowPropPages(object obj)
        {
            ISpecifyPropertyPages specPropPages = null;

            try
            {
                specPropPages = obj as ISpecifyPropertyPages;
                if (null == specPropPages)
                {
                    MessageBox.Show("Property pages not available");
                    return;
                }

                DsCAUUID cauuid;
                int      hr = specPropPages.GetPages(out cauuid);
                DsError.ThrowExceptionForHR(hr);

                if (hr == 0 && cauuid.cElems > 0)
                {
                    // show property pages
                    hr = WinAPI.OleCreatePropertyFrame(this.Handle,
                                                       30, 30, null, 1,
                                                       ref obj, cauuid.cElems,
                                                       cauuid.pElems, 0, 0, IntPtr.Zero);

                    Marshal.FreeCoTaskMem(cauuid.pElems);
                }
            }
            catch (COMException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            //do not release interfaces obtained with a cast (as), the primary interface is also released
        }
コード例 #3
0
        // Token: 0x06000350 RID: 848 RVA: 0x00013FF8 File Offset: 0x000121F8
        protected bool addIfSupported(object o, string name)
        {
            ISpecifyPropertyPages specifyPropertyPages = null;
            DsCAUUID dsCAUUID = default(DsCAUUID);
            bool     result   = false;

            try
            {
                specifyPropertyPages = (o as ISpecifyPropertyPages);
                if (specifyPropertyPages != null)
                {
                    int pages = specifyPropertyPages.GetPages(ref dsCAUUID);
                    if (pages != 0 || dsCAUUID.cElems <= 0)
                    {
                        specifyPropertyPages = null;
                    }
                }
            }
            finally
            {
                if (dsCAUUID.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(dsCAUUID.pElems);
                }
            }
            if (specifyPropertyPages != null)
            {
                DirectShowPropertyPage value = new DirectShowPropertyPage(name, specifyPropertyPages);
                this.InnerList.Add(value);
                result = true;
            }
            return(result);
        }
コード例 #4
0
        // ---------------- Public Methods --------------------

        /// <summary>
        ///  Show the property page. Some property pages cannot be displayed
        ///  while previewing and/or capturing.
        /// </summary>
        public override void Show(Control owner)
        {
            DsCAUUID cauuid = new DsCAUUID();

            try
            {
                int hr = specifyPropertyPages.GetPages(out cauuid);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                object o = specifyPropertyPages;
                hr = OleCreatePropertyFrame(owner.Handle, 30, 30, null, 1,
                                            ref o, cauuid.cElems, cauuid.pElems, 0, 0, IntPtr.Zero);
                DsError.ThrowExceptionForHR(hr);
            }
            catch (Exception)
            {
                MessageBox.Show("This filter has no property page!");
            }
            finally
            {
                if (cauuid.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(cauuid.pElems);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 视频属性页设置
        /// 原生方式
        /// </summary>
        public void changeCameraSetting(IntPtr Handle)
        {
            DsCAUUID cauuid = new DsCAUUID();

            try
            {
                specifyPropertyPages = theDevice as ISpecifyPropertyPages;
                if (specifyPropertyPages == null)
                {
                    MessageBox.Show("请先打开视频设备!");
                    return;
                }
                //返回filter所支持的属性页的CLSID
                int hr = specifyPropertyPages.GetPages(out cauuid);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                object o = specifyPropertyPages;
                //获取属性页
                hr = OleCreatePropertyFrame(Handle, 30, 30, null, 1,
                                            ref o, cauuid.cElems, cauuid.pElems, 0, 0, IntPtr.Zero);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable display property page. Please submit a bug report.\n\n" + ex.Message + "\n\n" + ex.ToString());
            }
        }
コード例 #6
0
        /// <summary>
        /// Display property window for the video capture device providing its configuration
        /// capabilities.
        /// </summary>
        ///
        /// <param name="parentWindow">Handle of parent window.</param>
        ///
        /// <remarks><para><note>If you pass parent window's handle to this method, then the
        /// displayed property page will become modal window and none of the controls from the
        /// parent window will be accessible. In order to make it modeless it is required
        /// to pass <see cref="IntPtr.Zero"/> as parent window's handle.
        /// </note></para>
        /// </remarks>
        ///
        /// <exception cref="NotSupportedException">The video source does not support configuration property page.</exception>
        ///
        public void DisplayPropertyPage(IntPtr parentWindow)
        {
            // check source
            if ((deviceMoniker == null) || (deviceMoniker == string.Empty))
            {
                throw new ArgumentException("Video source is not specified");
            }

            lock (this)
            {
                if (IsRunning)
                {
                    // pass the request to backgroud thread if video source is running
                    parentWindowForPropertyPage = parentWindow;
                    needToDisplayPropertyPage   = true;
                    return;
                }

                object tempSourceObject = null;

                // create source device's object
                try
                {
                    tempSourceObject = FilterInfo.CreateFilter(deviceMoniker);
                }
                catch
                {
                    throw new ApplicationException("Failed creating device object for moniker.");
                }

                if (!(tempSourceObject is ISpecifyPropertyPages))
                {
                    throw new NotSupportedException("The video source does not support configuration property page.");
                }

                // retrieve ISpecifyPropertyPages interface of the device
                ISpecifyPropertyPages pPropPages = (ISpecifyPropertyPages)tempSourceObject;

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

                // get filter info
                FilterInfo filterInfo = new FilterInfo(deviceMoniker);

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

                // release COM objects
                Marshal.FreeCoTaskMem(caGUID.pElems);
                Marshal.ReleaseComObject(tempSourceObject);
            }
        }
コード例 #7
0
ファイル: DsUtils.cs プロジェクト: w510056105/hacker
        public static bool ShowCapPinDialog(ICaptureGraphBuilder2 bld, IBaseFilter flt, IntPtr hwnd)
        {
            int    hr;
            object comObj = null;
            ISpecifyPropertyPages spec = null;
            DsCAUUID cauuid            = new DsCAUUID();

            try
            {
                Guid cat  = PinCategory.Capture;
                Guid type = MediaType.Interleaved;
                Guid iid  = typeof(IAMStreamConfig).GUID;
                hr = bld.FindInterface(ref cat, ref type, flt, ref iid, out comObj);
                if (hr != 0)
                {
                    type = MediaType.Video;
                    hr   = bld.FindInterface(ref cat, ref type, flt, ref iid, out comObj);
                    if (hr != 0)
                    {
                        return(false);
                    }
                }
                spec = comObj as ISpecifyPropertyPages;
                if (spec == null)
                {
                    return(false);
                }

                hr = spec.GetPages(out cauuid);
                hr = OleCreatePropertyFrame(hwnd, 30, 30, null, 1,
                                            ref comObj, cauuid.cElems, cauuid.pElems, 0, 0, IntPtr.Zero);
                return(true);
            }
            catch (Exception ee)
            {
                Trace.WriteLine("!Ds.NET: ShowCapPinDialog " + ee.Message);
                return(false);
            }
            finally
            {
                if (cauuid.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(cauuid.pElems);
                }

                spec = null;
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;
            }
        }
コード例 #8
0
        /// <summary>
        /// Displays a property page for a filter
        /// </summary>
        /// <param name="dev">The filter for which to display a property page</param>
        public static void DisplayPropertyPage(IBaseFilter dev, IntPtr hwndOwner)
        {
            Trace.WriteLine("Tangra.DirectShowVideoBase: Showing properties page on managed thread " + Thread.CurrentThread.ManagedThreadId);

            //Get the ISpecifyPropertyPages for the filter
            ISpecifyPropertyPages pProp = dev as ISpecifyPropertyPages;
            int hr = 0;

            if (pProp == null)
            {
                //If the filter doesn't implement ISpecifyPropertyPages, try displaying IAMVfwCompressDialogs instead!
                IAMVfwCompressDialogs compressDialog = dev as IAMVfwCompressDialogs;
                if (compressDialog != null)
                {
                    try
                    {
                        compressDialog.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.ToString());
                    }
                }
                return;
            }

            //Get the name of the filter from the FilterInfo struct
            FilterInfo filterInfo;

            hr = dev.QueryFilterInfo(out filterInfo);
            DsError.ThrowExceptionForHR(hr);

            // Get the propertypages from the property bag
            DsCAUUID caGUID;

            hr = pProp.GetPages(out caGUID);
            DsError.ThrowExceptionForHR(hr);

            // Create and display the OlePropertyFrame
            object oDevice = (object)dev;

            hr = OleCreatePropertyFrame(hwndOwner, 0, 0, filterInfo.achName, 1, ref oDevice, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            // Release COM objects
            Marshal.FreeCoTaskMem(caGUID.pElems);
            Marshal.ReleaseComObject(pProp);
            if (filterInfo.pGraph != null)
            {
                Marshal.ReleaseComObject(filterInfo.pGraph);
            }
        }
コード例 #9
0
        // Token: 0x060002F4 RID: 756 RVA: 0x00012B14 File Offset: 0x00010D14
        public static bool ShowTunerPinDialog(ICaptureGraphBuilder2 bld, IBaseFilter flt, IntPtr hwnd)
        {
            object   obj      = null;
            DsCAUUID dsCAUUID = default(DsCAUUID);
            bool     result;

            try
            {
                Guid capture = PinCategory.Capture;
                Guid guid    = MediaType.Interleaved;
                Guid guid2   = typeof(IAMTVTuner).GUID;
                int  num     = bld.FindInterface(ref capture, ref guid, flt, ref guid2, out obj);
                if (num != 0)
                {
                    guid = MediaType.Video;
                    num  = bld.FindInterface(ref capture, ref guid, flt, ref guid2, out obj);
                    if (num != 0)
                    {
                        return(false);
                    }
                }
                ISpecifyPropertyPages specifyPropertyPages = obj as ISpecifyPropertyPages;
                if (specifyPropertyPages == null)
                {
                    result = false;
                }
                else
                {
                    num    = specifyPropertyPages.GetPages(ref dsCAUUID);
                    num    = DsUtils.OleCreatePropertyFrame(hwnd, 30, 30, null, 1, ref obj, dsCAUUID.cElems, dsCAUUID.pElems, 0, 0, IntPtr.Zero);
                    result = true;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("!Ds.NET: ShowCapPinDialog " + ex.Message);
                result = false;
            }
            finally
            {
                if (dsCAUUID.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(dsCAUUID.pElems);
                }
                if (obj != null)
                {
                    Marshal.ReleaseComObject(RuntimeHelpers.GetObjectValue(obj));
                }
                obj = null;
            }
            return(result);
        }
コード例 #10
0
        public void Show(IntPtr hwnd)
        {
            CAUUID ca;
            int    hr = iSPP.GetPages(out ca);

            if (hr == 0) // S_OK
            {
                object o = iSPP;
                OleCreatePropertyFrame(hwnd, 0, 0, name, 1, ref o,
                                       ca.ElementCount, ca.Elements, 0, 0, IntPtr.Zero);

                Marshal.FreeCoTaskMem(ca.Elements);
            }
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: ewin66/DirectShow.NET
        /// <summary>
        /// Displays a property page for a filter
        /// </summary>
        /// <param name="dev">The filter for which to display a property page</param>
        private void DisplayPropertyPage(IBaseFilter dev)
        {
            //Get the ISpecifyPropertyPages for the filter
            ISpecifyPropertyPages pProp = dev as ISpecifyPropertyPages;
            int hr = 0;

            if (pProp == null)
            {
                //If the filter doesn't implement ISpecifyPropertyPages, try displaying IAMVfwCompressDialogs instead!
                IAMVfwCompressDialogs compressDialog = dev as IAMVfwCompressDialogs;
                if (compressDialog != null)
                {
                    hr = compressDialog.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
                    DsError.ThrowExceptionForHR(hr);
                }
                else
                {
                    MessageBox.Show("Item has no property page", "No Property Page", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                return;
            }

            //Get the name of the filter from the FilterInfo struct
            FilterInfo filterInfo;

            hr = dev.QueryFilterInfo(out filterInfo);
            DsError.ThrowExceptionForHR(hr);

            // Get the propertypages from the property bag
            DsCAUUID caGUID;

            hr = pProp.GetPages(out caGUID);
            DsError.ThrowExceptionForHR(hr);

            //Create and display the OlePropertyFrame
            object oDevice = (object)dev;

            hr = OleCreatePropertyFrame(this.Handle, 0, 0, filterInfo.achName, 1, ref oDevice, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            Marshal.ReleaseComObject(oDevice);

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

            // Release COM objects
            Marshal.FreeCoTaskMem(caGUID.pElems);
        }
コード例 #12
0
ファイル: DsUtils.cs プロジェクト: AreebaAroosh/DesktopClient
        public static bool ShowCapPinDialog(ICaptureGraphBuilder2 bld, IBaseFilter flt, IntPtr hwnd)
        {
            object ppint = null;
            ISpecifyPropertyPages pages = null;
            bool     flag;
            DsCAUUID pPages = new DsCAUUID();

            try
            {
                Guid capture     = PinCategory.Capture;
                Guid interleaved = MediaType.Interleaved;
                Guid gUID        = typeof(IAMStreamConfig).GUID;
                if (bld.FindInterface(ref capture, ref interleaved, flt, ref gUID, out ppint) != 0)
                {
                    interleaved = MediaType.Video;
                    if (bld.FindInterface(ref capture, ref interleaved, flt, ref gUID, out ppint) != 0)
                    {
                        return(false);
                    }
                }
                pages = ppint as ISpecifyPropertyPages;
                if (pages == null)
                {
                    return(false);
                }
                int num = pages.GetPages(out pPages);
                num  = OleCreatePropertyFrame(hwnd, 30, 30, null, 1, ref ppint, pPages.cElems, pPages.pElems, 0, 0, IntPtr.Zero);
                flag = true;
            }
            catch (Exception exception)
            {
                Trace.WriteLine("!Ds.NET: ShowCapPinDialog " + exception.Message);
                flag = false;
            }
            finally
            {
                if (pPages.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pPages.pElems);
                }
                pages = null;
                if (ppint != null)
                {
                    Marshal.ReleaseComObject(ppint);
                }
                ppint = null;
            }
            return(flag);
        }
コード例 #13
0
        public void TestGetPages()
        {
            int        hr = 0;
            FilterInfo filterInfo;
            DsCAUUID   pages = new DsCAUUID();

            try
            {
                // Just to retrieve the name of the filter
                hr = this.filter.QueryFilterInfo(out filterInfo);
                DsError.ThrowExceptionForHR(hr);

                // An exception is thrown if the cast is imposible
                ISpecifyPropertyPages propertyPages = (ISpecifyPropertyPages)this.filter;

                // Query PerperyPages Guid
                hr = propertyPages.GetPages(out pages);
                DsError.ThrowExceptionForHR(hr);

                object obj = (object)this.filter;

                // Display the property window
                hr = OleCreatePropertyFrame(
                    IntPtr.Zero,
                    0,
                    0,
                    filterInfo.achName,
                    1,
                    ref obj,
                    pages.cElems,
                    pages.pElems,
                    0,
                    0,
                    IntPtr.Zero
                    );
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                // pElems memory must be freed
                if (pages.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(pages.pElems);
                }
            }
        }
コード例 #14
0
        private void pbImage_DoubleClick(object sender, EventArgs e)
        {
            if (active_config == null)
            {
                return;
            }

            ISpecifyPropertyPages property_pages = (ISpecifyPropertyPages)active_config.Filter;
            DsCAUUID pages_uuid;

            property_pages.GetPages(out pages_uuid);
            OleHelper.OleCreatePropertyFrame(
                IntPtr.Zero,
                0, 0,
                "",
                1, new object[] { active_config.Filter },
                pages_uuid.cElems, pages_uuid.pElems,
                0, 0, IntPtr.Zero);
        }
コード例 #15
0
        /// <summary>
        ///  Show the property page. Some property pages cannot be displayed
        ///  while previewing and/or capturing.
        /// </summary>
        public override void Show(Control owner)
        {
            DsCAUUID cauuid = new DsCAUUID();

            try
            {
                int hr = specifyPropertyPages.GetPages(out cauuid);
                Marshal.ThrowExceptionForHR(hr);

                object o = specifyPropertyPages;
                hr = OleCreatePropertyFrame(owner.Handle, 30, 30, null, 1, ref o, cauuid.cElems, cauuid.pElems, 0, 0, IntPtr.Zero);
            }
            finally
            {
                if (cauuid.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(cauuid.pElems);
                }
            }
        }
コード例 #16
0
        public void Show(IntPtr hWnd)
        {
            var cauuid = new DsCAUUID();

            try
            {
                int hr = m_specifyPropertyPages.GetPages(out cauuid);
                if (hr != 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                object objRef = m_specifyPropertyPages;
                hr = OleCreatePropertyFrame(hWnd,
                                            30,
                                            30,
                                            null,
                                            1,
                                            ref objRef,
                                            cauuid.cElems,
                                            cauuid.pElems,
                                            0,
                                            0,
                                            IntPtr.Zero);

                DsError.ThrowExceptionForHR(hr);
            }
            catch (Exception)
            {
                MessageBox.Show(NO_PROPERTY_PAGE_FOUND);
            }
            finally
            {
                if (cauuid.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(cauuid.pElems);
                }
            }
        }
コード例 #17
0
        private void DisplayPropertyPage(IntPtr parentWindow, object sourceObject)
        {
            try
            {
                ISpecifyPropertyPages pPropPages = (ISpecifyPropertyPages)sourceObject;


                CAUUID caGUID;
                pPropPages.GetPages(out caGUID);


                FilterInfo filterInfo = new FilterInfo(deviceMoniker);


                Win32.OleCreatePropertyFrame(parentWindow, 0, 0, filterInfo.Name, 1, ref sourceObject, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero);


                Marshal.FreeCoTaskMem(caGUID.pElems);
            }
            catch
            {
            }
        }
コード例 #18
0
        /// <summary>
        ///  Returns the object as an ISpecificPropertyPage
        ///  if the object supports the ISpecificPropertyPage
        ///  interface and has at least one property page.
        /// </summary>
        protected bool addIfSupported(object o, string name)
        {
            ISpecifyPropertyPages specifyPropertyPages = null;
            DsCAUUID cauuid   = new DsCAUUID();
            bool     wasAdded = false;

            // Determine if the object supports the interface
            // and has at least 1 property page
            try
            {
                specifyPropertyPages = o as ISpecifyPropertyPages;
                if (specifyPropertyPages != null)
                {
                    int hr = specifyPropertyPages.GetPages(out cauuid);
                    if ((hr != 0) || (cauuid.cElems <= 0))
                    {
                        specifyPropertyPages = null;
                    }
                }
            }
            finally
            {
                if (cauuid.pElems != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(cauuid.pElems);
                }
            }

            // Add the page to the internal collection
            if (specifyPropertyPages != null)
            {
                DirectShowPropertyPage p = new DirectShowPropertyPage(name, specifyPropertyPages);
                InnerList.Add(p);
                wasAdded = true;
            }
            return(wasAdded);
        }
コード例 #19
0
        private void WorkerThread(bool runGraph)
        {
            VideoSourceFinishedReasonType reasonToStop = VideoSourceFinishedReasonType.StoppedByUser;
            bool isSapshotSupported = false;

            // grabber
            Grabber videoGrabber    = new Grabber(this, false);
            Grabber snapshotGrabber = new Grabber(this, true);

            // objects
            object captureGraphObject    = null;
            object graphObject           = null;
            object videoGrabberObject    = null;
            object snapshotGrabberObject = null;

            // interfaces
            ICaptureGraphBuilder2 captureGraph          = null;
            IFilterGraph2         graph                 = null;
            IBaseFilter           sourceBase            = null;
            IBaseFilter           videoGrabberBase      = null;
            IBaseFilter           snapshotGrabberBase   = null;
            ISampleGrabber        videoSampleGrabber    = null;
            ISampleGrabber        snapshotSampleGrabber = null;
            IMediaControl         mediaControl          = null;
            IAMVideoControl       videoControl          = null;
            IMediaEventEx         mediaEvent            = null;
            IPin pinStillImage = null;

            try
            {
                // get type of capture graph builder
                Type type = Type.GetTypeFromCLSID(Clsid.CaptureGraphBuilder2);
                if (type == null)
                {
                    throw new ApplicationException("Failed creating capture graph builder");
                }

                // create capture graph builder
                captureGraphObject = Activator.CreateInstance(type);
                captureGraph       = (ICaptureGraphBuilder2)captureGraphObject;

                // get type of filter graph
                type = Type.GetTypeFromCLSID(Clsid.FilterGraph);
                if (type == null)
                {
                    throw new ApplicationException("Failed creating filter graph");
                }

                // create filter graph
                graphObject = Activator.CreateInstance(type);
                graph       = (IFilterGraph2)graphObject;

                // set filter graph to the capture graph builder
                captureGraph.SetFiltergraph((IGraphBuilder)graph);

                // create source device's object
                sourceObject = FilterInfo.CreateFilter(deviceMoniker);
                if (sourceObject == null)
                {
                    throw new ApplicationException("Failed creating device object for moniker");
                }

                // get base filter interface of source device
                sourceBase = (IBaseFilter)sourceObject;

                // get video control interface of the device
                try
                {
                    videoControl = (IAMVideoControl)sourceObject;
                }
                catch
                {
                    // some camera drivers may not support IAMVideoControl interface
                }

                // get type of sample grabber
                type = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
                if (type == null)
                {
                    throw new ApplicationException("Failed creating sample grabber");
                }

                // create sample grabber used for video capture
                videoGrabberObject = Activator.CreateInstance(type);
                videoSampleGrabber = (ISampleGrabber)videoGrabberObject;
                videoGrabberBase   = (IBaseFilter)videoGrabberObject;
                // create sample grabber used for snapshot capture
                snapshotGrabberObject = Activator.CreateInstance(type);
                snapshotSampleGrabber = (ISampleGrabber)snapshotGrabberObject;
                snapshotGrabberBase   = (IBaseFilter)snapshotGrabberObject;

                // add source and grabber filters to graph
                graph.AddFilter(sourceBase, "source");
                graph.AddFilter(videoGrabberBase, "grabber_video");
                graph.AddFilter(snapshotGrabberBase, "grabber_snapshot");

                // set media type
                AMMediaType mediaType = new AMMediaType();
                mediaType.MajorType = MediaType.Video;
                mediaType.SubType   = MediaSubType.RGB24;

                videoSampleGrabber.SetMediaType(mediaType);
                snapshotSampleGrabber.SetMediaType(mediaType);

                if (videoControl != null)
                {
                    // find Still Image output pin of the vedio device
                    captureGraph.FindPin(sourceObject, PinDirection.Output,
                                         PinCategory.StillImage, MediaType.Video, false, 0, out pinStillImage);
                    // check if it support trigger mode
                    if (pinStillImage != null)
                    {
                        VideoControlFlags caps;
                        videoControl.GetCaps(pinStillImage, out caps);
                        isSapshotSupported = ((caps & VideoControlFlags.ExternalTriggerEnable) != 0);
                    }
                }

                // configure video sample grabber
                videoSampleGrabber.SetBufferSamples(false);
                videoSampleGrabber.SetOneShot(false);
                videoSampleGrabber.SetCallback(videoGrabber, 1);

                // configure snapshot sample grabber
                snapshotSampleGrabber.SetBufferSamples(true);
                snapshotSampleGrabber.SetOneShot(false);
                snapshotSampleGrabber.SetCallback(snapshotGrabber, 1);

                // configure pins
                GetPinCapabilitiesAndConfigureSizeAndRate(captureGraph, sourceBase,
                                                          PinCategory.Capture, desiredFrameSize, desiredFrameRate, ref videoCapabilities);
                if (isSapshotSupported)
                {
                    GetPinCapabilitiesAndConfigureSizeAndRate(captureGraph, sourceBase,
                                                              PinCategory.StillImage, desiredSnapshotSize, 0, ref snapshotCapabilities);
                }
                else
                {
                    snapshotCapabilities = new VideoCapabilities[0];
                }

                if (runGraph)
                {
                    // render capture pin
                    captureGraph.RenderStream(PinCategory.Capture, MediaType.Video, sourceBase, null, videoGrabberBase);

                    if (videoSampleGrabber.GetConnectedMediaType(mediaType) == 0)
                    {
                        VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader));

                        videoGrabber.Width  = vih.BmiHeader.Width;
                        videoGrabber.Height = vih.BmiHeader.Height;

                        mediaType.Dispose();
                    }

                    if ((isSapshotSupported) && (provideSnapshots))
                    {
                        // render snapshot pin
                        captureGraph.RenderStream(PinCategory.StillImage, MediaType.Video, sourceBase, null, snapshotGrabberBase);

                        if (snapshotSampleGrabber.GetConnectedMediaType(mediaType) == 0)
                        {
                            VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader));

                            snapshotGrabber.Width  = vih.BmiHeader.Width;
                            snapshotGrabber.Height = vih.BmiHeader.Height;

                            mediaType.Dispose();
                        }
                    }

                    // get media control
                    mediaControl = (IMediaControl)graphObject;

                    // get media events' interface
                    mediaEvent = (IMediaEventEx)graphObject;
                    IntPtr   p1, p2;
                    DsEvCode code;

                    // run
                    mediaControl.Run();

                    if ((isSapshotSupported) && (provideSnapshots))
                    {
                        startTime = DateTime.Now;
                        videoControl.SetMode(pinStillImage, VideoControlFlags.ExternalTriggerEnable);
                    }

                    while (!stopEvent.WaitOne(0, false))
                    {
                        Thread.Sleep(100);

                        if (mediaEvent != null)
                        {
                            if (mediaEvent.GetEvent(out code, out p1, out p2, 0) >= 0)
                            {
                                mediaEvent.FreeEventParams(code, p1, p2);

                                if (code == DsEvCode.DeviceLost)
                                {
                                    reasonToStop = VideoSourceFinishedReasonType.DeviceLost;
                                    break;
                                }
                            }
                        }

                        if (needToSimulateTrigger)
                        {
                            needToSimulateTrigger = false;

                            if ((isSapshotSupported) && (provideSnapshots))
                            {
                                videoControl.SetMode(pinStillImage, VideoControlFlags.Trigger);
                            }
                        }

                        if (needToDisplayPropertyPage)
                        {
                            needToDisplayPropertyPage = false;

                            try
                            {
                                // retrieve ISpecifyPropertyPages interface of the device
                                ISpecifyPropertyPages pPropPages = (ISpecifyPropertyPages)sourceObject;

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

                                // get filter info
                                FilterInfo filterInfo = new FilterInfo(deviceMoniker);

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

                                // release COM objects
                                Marshal.FreeCoTaskMem(caGUID.pElems);
                            }
                            catch
                            {
                            }
                        }
                    }
                    mediaControl.Stop();
                }
            }
            catch (Exception exception)
            {
                // provide information to clients
                if (VideoSourceException != null)
                {
                    VideoSourceException(this, new VideoSourceExceptionEventArgs(exception.Message));
                }
            }
            finally
            {
                // release all objects
                captureGraph  = null;
                graph         = null;
                sourceBase    = null;
                mediaControl  = null;
                videoControl  = null;
                mediaEvent    = null;
                pinStillImage = null;

                videoGrabberBase      = null;
                snapshotGrabberBase   = null;
                videoSampleGrabber    = null;
                snapshotSampleGrabber = null;

                if (graphObject != null)
                {
                    Marshal.ReleaseComObject(graphObject);
                    graphObject = null;
                }
                if (sourceObject != null)
                {
                    Marshal.ReleaseComObject(sourceObject);
                    sourceObject = null;
                }
                if (videoGrabberObject != null)
                {
                    Marshal.ReleaseComObject(videoGrabberObject);
                    videoGrabberObject = null;
                }
                if (snapshotGrabberObject != null)
                {
                    Marshal.ReleaseComObject(snapshotGrabberObject);
                    snapshotGrabberObject = null;
                }
                if (captureGraphObject != null)
                {
                    Marshal.ReleaseComObject(captureGraphObject);
                    captureGraphObject = null;
                }
            }

            if (VideoSourceFinished != null)
            {
                VideoSourceFinished(this, new VideoSourceFinishedEventArgs(reasonToStop));
            }
        }
コード例 #20
0
ファイル: DirectShowUtils.cs プロジェクト: odins1970/Ogama
        /// <summary>
        /// Displays a property page for a filter
        /// </summary>
        /// <param name="parentHandle">An <see cref="IntPtr"/> with the handle for the parent window of the dialog.</param>
        /// <param name="dev">The <see cref="IBaseFilter"/> for which to display a property page.</param>
        public static void DisplayPropertyPage(IntPtr parentHandle, IBaseFilter dev)
        {
            // Get the ISpecifyPropertyPages for the filter
            ISpecifyPropertyPages properties = dev as ISpecifyPropertyPages;
            int hr = 0;

            if (properties == null)
            {
                // If the filter doesn't implement ISpecifyPropertyPages, try displaying IAMVfwCompressDialogs instead!
                IAMVfwCompressDialogs compressDialog = dev as IAMVfwCompressDialogs;
                if (compressDialog != null)
                {
                    hr = compressDialog.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
                    DsError.ThrowExceptionForHR(hr);
                }

                return;
            }

            // Get the name of the filter from the FilterInfo struct
            FilterInfo filterInfo;

            hr = dev.QueryFilterInfo(out filterInfo);
            DsError.ThrowExceptionForHR(hr);

            // Get the propertypages from the property bag
            DsCAUUID captureGUID;

            hr = properties.GetPages(out captureGUID);
            DsError.ThrowExceptionForHR(hr);

            // Check for property pages on the output pin
            IPin pin = DsFindPin.ByDirection(dev, PinDirection.Output, 0);
            ISpecifyPropertyPages properties2 = pin as ISpecifyPropertyPages;

            if (properties2 != null)
            {
                DsCAUUID captureGUID2;
                hr = properties2.GetPages(out captureGUID2);
                DsError.ThrowExceptionForHR(hr);

                if (captureGUID2.cElems > 0)
                {
                    int guidSize = Marshal.SizeOf(typeof(Guid));

                    // Create a new buffer to hold all the GUIDs
                    IntPtr p1 = Marshal.AllocCoTaskMem((captureGUID.cElems + captureGUID2.cElems) * guidSize);

                    // Copy over the pages from the Filter
                    for (int x = 0; x < captureGUID.cElems * guidSize; x++)
                    {
                        Marshal.WriteByte(p1, x, Marshal.ReadByte(captureGUID.pElems, x));
                    }

                    // Add the pages from the pin
                    for (int x = 0; x < captureGUID2.cElems * guidSize; x++)
                    {
                        Marshal.WriteByte(p1, x + (captureGUID.cElems * guidSize), Marshal.ReadByte(captureGUID2.pElems, x));
                    }

                    // Release the old memory
                    Marshal.FreeCoTaskMem(captureGUID.pElems);
                    Marshal.FreeCoTaskMem(captureGUID2.pElems);

                    // Reset caGUID to include both
                    captureGUID.pElems  = p1;
                    captureGUID.cElems += captureGUID2.cElems;
                }
            }

            // Create and display the OlePropertyFrame
            object device = (object)dev;

            hr = Oleaut32.OleCreatePropertyFrame(parentHandle, 0, 0, filterInfo.achName, 1, ref device, captureGUID.cElems, captureGUID.pElems, 0, 0, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            // Release COM objects
            Marshal.FreeCoTaskMem(captureGUID.pElems);
            Marshal.ReleaseComObject(properties);
            if (filterInfo.pGraph != null)
            {
                Marshal.ReleaseComObject(filterInfo.pGraph);
            }
        }
コード例 #21
0
        public PropertyPagePanel(bool OkCloseButtons, IBaseFilter filter)
        {
            _filter = filter;

            base.BackColor = SystemColors.Control;

            _tabs           = new TabControl();
            _tabs.Dock      = DockStyle.Fill;
            this.Dock       = DockStyle.Fill;
            _tabs.Multiline = false;
            Controls.Add(_tabs);

            _buttonsPanel      = new Panel();
            _buttonsPanel.Dock = DockStyle.Bottom;

            _interfacesButton           = new Button();
            _interfacesButton.Text      = "Scan Interfaces";
            _interfacesButton.Width     = 100;
            _interfacesButton.Dock      = DockStyle.Left;
            _interfacesButton.BackColor = SystemColors.Control;
            _interfacesButton.Click    += new EventHandler(_interfacesButton_Click);
            _buttonsPanel.Controls.Add(_interfacesButton);

            _applyButton           = new Button();
            _applyButton.Text      = "Apply";
            _applyButton.Dock      = DockStyle.Left;
            _applyButton.BackColor = SystemColors.Control;
            _applyButton.Enabled   = false;
            _applyButton.Click    += new EventHandler(_applyButton_Click);
            _buttonsPanel.Controls.Add(_applyButton);

            if (OkCloseButtons)
            {
                _closeButton           = new Button();
                _closeButton.Text      = "Close";
                _closeButton.Dock      = DockStyle.Left;
                _closeButton.BackColor = SystemColors.Control;
                _buttonsPanel.Controls.Add(_closeButton);

                _okButton           = new Button();
                _okButton.Text      = "Ok";
                _okButton.Dock      = DockStyle.Left;
                _okButton.BackColor = SystemColors.Control;
                _okButton.Click    += new EventHandler(_applyButton_Click);
                _buttonsPanel.Controls.Add(_okButton);
            }

            _buttonsPanel.Height = 23;
            Controls.Add(_buttonsPanel);
            int hr = 0;

            ISpecifyPropertyPages pProp = filter as ISpecifyPropertyPages;

            if (pProp != null)
            {
                // Get the propertypages from the property bag
                DsCAUUID caGUID;
                hr = pProp.GetPages(out caGUID);
                if (hr != 0 || caGUID.cElems == 0)
                {
                    // could not get property sheets or got 0 property sheets
                    return;
                }

                // convert caGUID to a managed array of Guids
                Guid[] propertyPages = caGUID.ToGuidArray();

                for (int i = 0; i < propertyPages.Length; i++)
                {
                    try
                    {
                        Type   type = Type.GetTypeFromCLSID(propertyPages[i]);
                        object o    = Activator.CreateInstance(type);

                        IPropertyPage pp = o as IPropertyPage;
                        PROPPAGEINFO  pi = new PROPPAGEINFO();
                        pp.GetPageInfo(ref pi);

                        // get the page size, adjusting for button panel and padding
                        _pageSize.Width  = Math.Max(_pageSize.Width, pi.size.Width + 10);
                        _pageSize.Height = Math.Max(_pageSize.Height, pi.size.Height + 33);

                        // we want to inc the refcount so the property page won't vanish on us
                        _iunk.Add(Marshal.GetIUnknownForObject(o));

                        object[] obs = { filter };
                        pp.SetObjects(1, obs);
                        pp.SetPageSite(this);
                        Rectangle rect = new Rectangle(0, 0, pi.size.Width, pi.size.Height);

                        TabPage tp = new TabPage(Marshal.PtrToStringAuto(pi.szTitle));
                        _tabs.Controls.Add(tp);
                        _pages.Add(pp);
                        pp.Activate(tp.Handle, ref rect, false);

                        // some PropertyPages aren't visible by default
                        IntPtr childwindow = GetWindow(tp.Handle, 5);
                        if (childwindow != IntPtr.Zero)
                        {
                            ShowWindow(childwindow, 5);
                        }
                    }
                    catch
                    {
                        // some property pages don't abide by the rules of COM
                    }
                }
            }
        }
コード例 #22
0
ファイル: Capture.cs プロジェクト: sengithub/SenSourcecode
        /// <summary> build the capture graph for grabber. </summary>
        private void SetupGraph(DsDevice dev, int iWidth, int iHeight, short iBPP, Control hControl)
        {
            int hr;

            ISampleGrabber  sampGrabber = null;
            IBaseFilter     capFilter   = null;
            IPin            pCaptureOut = null;
            IPin            pSampleIn   = null;
            IPin            pRenderIn   = null;
            IAMVideoProcAmp vpa         = null;

            // Get the graphbuilder object
            m_FilterGraph = new FilterGraph() as IFilterGraph2;

            try
            {
#if DEBUG
                m_rot = new DsROTEntry(m_FilterGraph);
#endif
                // add the video input device
                hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
                DsError.ThrowExceptionForHR(hr);

                // Find the still pin
                m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Still, 0);

                // Didn't find one.  Is there a preview pin?
                if (m_pinStill == null)
                {
                    m_pinStill = DsFindPin.ByCategory(capFilter, PinCategory.Preview, 0);
                }

                //test
                ISpecifyPropertyPages pProp = capFilter as ISpecifyPropertyPages;

                DsCAUUID caGUID;
                hr = pProp.GetPages(out caGUID);
                DsError.ThrowExceptionForHR(hr);

                // Still haven't found one.  Need to put a splitter in so we have
                // one stream to capture the bitmap from, and one to display.  Ok, we
                // don't *have* to do it that way, but we are going to anyway.
                if (m_pinStill == null)
                {
                    IPin pRaw   = null;
                    IPin pSmart = null;

                    // There is no still pin
                    m_VidControl = null;

                    // Add a splitter
                    IBaseFilter iSmartTee = (IBaseFilter) new SmartTee();

                    try
                    {
                        hr = m_FilterGraph.AddFilter(iSmartTee, "SmartTee");
                        DsError.ThrowExceptionForHR(hr);

                        // Find the find the capture pin from the video device and the
                        // input pin for the splitter, and connnect them
                        pRaw   = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);
                        pSmart = DsFindPin.ByDirection(iSmartTee, PinDirection.Input, 0);

                        hr = m_FilterGraph.Connect(pRaw, pSmart);
                        DsError.ThrowExceptionForHR(hr);

                        // Now set the capture and still pins (from the splitter)
                        m_pinStill  = DsFindPin.ByName(iSmartTee, "Preview");
                        pCaptureOut = DsFindPin.ByName(iSmartTee, "Capture");

                        // If any of the default config items are set, perform the config
                        // on the actual video device (rather than the splitter)
                        if (iHeight + iWidth + iBPP > 0)
                        {
                            SetConfigParms(pRaw, iWidth, iHeight, iBPP);
                        }
                    }
                    finally
                    {
                        if (pRaw != null)
                        {
                            Marshal.ReleaseComObject(pRaw);
                        }
                        if (pRaw != pSmart)
                        {
                            Marshal.ReleaseComObject(pSmart);
                        }
                        if (pRaw != iSmartTee)
                        {
                            Marshal.ReleaseComObject(iSmartTee);
                        }
                    }
                }
                else
                {
                    // Get a control pointer (used in Click())
                    m_VidControl = capFilter as IAMVideoControl;

                    pCaptureOut = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);

                    // If any of the default config items are set
                    if (iHeight + iWidth + iBPP > 0)
                    {
                        SetConfigParms(m_pinStill, iWidth, iHeight, iBPP);
                    }
                }

                // Get the SampleGrabber interface
                sampGrabber = new SampleGrabber() as ISampleGrabber;

                // Configure the sample grabber
                IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
                ConfigureSampleGrabber(sampGrabber);
                pSampleIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);

                // Get the default video renderer
                IBaseFilter pRenderer = new VideoRendererDefault() as IBaseFilter;
                hr = m_FilterGraph.AddFilter(pRenderer, "Renderer");
                DsError.ThrowExceptionForHR(hr);

                pRenderIn = DsFindPin.ByDirection(pRenderer, PinDirection.Input, 0);

                // Add the sample grabber to the graph
                hr = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
                DsError.ThrowExceptionForHR(hr);

                if (m_VidControl == null)
                {
                    // Connect the Still pin to the sample grabber
                    hr = m_FilterGraph.Connect(m_pinStill, pSampleIn);
                    DsError.ThrowExceptionForHR(hr);

                    // Connect the capture pin to the renderer
                    hr = m_FilterGraph.Connect(pCaptureOut, pRenderIn);
                    DsError.ThrowExceptionForHR(hr);
                }
                else
                {
                    // Connect the capture pin to the renderer
                    hr = m_FilterGraph.Connect(pCaptureOut, pRenderIn);
                    DsError.ThrowExceptionForHR(hr);

                    // Connect the Still pin to the sample grabber
                    hr = m_FilterGraph.Connect(m_pinStill, pSampleIn);
                    DsError.ThrowExceptionForHR(hr);
                }
                // Learn the video properties
                SaveSizeInfo(sampGrabber);
                ConfigVideoWindow(hControl);

                // Start the graph
                IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;
                hr = mediaCtrl.Run();
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (vpa != null)
                {
                    Marshal.ReleaseComObject(vpa);
                    vpa = null;
                }
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                    sampGrabber = null;
                }
                if (pCaptureOut != null)
                {
                    Marshal.ReleaseComObject(pCaptureOut);
                    pCaptureOut = null;
                }
                if (pRenderIn != null)
                {
                    Marshal.ReleaseComObject(pRenderIn);
                    pRenderIn = null;
                }
                if (pSampleIn != null)
                {
                    Marshal.ReleaseComObject(pSampleIn);
                    pSampleIn = null;
                }
            }
        }
コード例 #23
0
        private void WorkerThread(bool runGraph)
        {
            // grabber
            Grabber grabber = new Grabber(this);

            // objects
            object captureGraphObject = null;
            object graphObject        = null;
            object grabberObject      = null;

            // interfaces
            ICaptureGraphBuilder2 captureGraph  = null;
            IFilterGraph2         graph         = null;
            IBaseFilter           sourceBase    = null;
            IBaseFilter           grabberBase   = null;
            ISampleGrabber        sampleGrabber = null;
            IMediaControl         mediaControl  = null;

            try
            {
                // get type of capture graph builder
                Type type = Type.GetTypeFromCLSID(Clsid.CaptureGraphBuilder2);
                if (type == null)
                {
                    throw new ApplicationException("Failed creating capture graph builder");
                }

                // create capture graph builder
                captureGraphObject = Activator.CreateInstance(type);
                captureGraph       = (ICaptureGraphBuilder2)captureGraphObject;

                // get type of filter graph
                type = Type.GetTypeFromCLSID(Clsid.FilterGraph);
                if (type == null)
                {
                    throw new ApplicationException("Failed creating filter graph");
                }

                // create filter graph
                graphObject = Activator.CreateInstance(type);
                graph       = (IFilterGraph2)graphObject;

                // set filter graph to the capture graph builder
                captureGraph.SetFiltergraph((IGraphBuilder)graph);

                // create source device's object
                sourceObject = FilterInfo.CreateFilter(deviceMoniker);
                if (sourceObject == null)
                {
                    throw new ApplicationException("Failed creating device object for moniker");
                }

                // get base filter interface of source device
                sourceBase = (IBaseFilter)sourceObject;

                // get type of sample grabber
                type = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
                if (type == null)
                {
                    throw new ApplicationException("Failed creating sample grabber");
                }

                // create sample grabber
                grabberObject = Activator.CreateInstance(type);
                sampleGrabber = (ISampleGrabber)grabberObject;
                grabberBase   = (IBaseFilter)grabberObject;

                // add source and grabber filters to graph
                graph.AddFilter(sourceBase, "source");
                graph.AddFilter(grabberBase, "grabber");

                // set media type
                AMMediaType mediaType = new AMMediaType( );
                mediaType.MajorType = MediaType.Video;
                mediaType.SubType   = MediaSubType.RGB24;

                sampleGrabber.SetMediaType(mediaType);

                // configure sample grabber
                sampleGrabber.SetBufferSamples(false);
                sampleGrabber.SetOneShot(false);
                sampleGrabber.SetCallback(grabber, 1);

                // check if it is required to change capture settings
                if ((desiredFrameRate != 0) || ((desiredFrameSize.Width != 0) && (desiredFrameSize.Height != 0)))
                {
                    object streamConfigObject;
                    // get stream configuration object
                    captureGraph.FindInterface(PinCategory.Capture, MediaType.Video, sourceBase, typeof(IAMStreamConfig).GUID, out streamConfigObject);

                    if (streamConfigObject != null)
                    {
                        IAMStreamConfig streamConfig = (IAMStreamConfig)streamConfigObject;

                        if (videoCapabilities == null)
                        {
                            // get all video capabilities
                            try
                            {
                                videoCapabilities = AForge.Video.DirectShow.VideoCapabilities.FromStreamConfig(streamConfig);
                            }
                            catch
                            {
                            }
                        }

                        // get current format
                        streamConfig.GetFormat(out mediaType);
                        VideoInfoHeader infoHeader = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader));

                        // change frame size if required
                        if ((desiredFrameSize.Width != 0) && (desiredFrameSize.Height != 0))
                        {
                            infoHeader.BmiHeader.Width  = desiredFrameSize.Width;
                            infoHeader.BmiHeader.Height = desiredFrameSize.Height;
                        }
                        // change frame rate if required
                        if (desiredFrameRate != 0)
                        {
                            infoHeader.AverageTimePerFrame = 10000000 / desiredFrameRate;
                        }

                        // copy the media structure back
                        Marshal.StructureToPtr(infoHeader, mediaType.FormatPtr, false);

                        // set the new format
                        streamConfig.SetFormat(mediaType);

                        mediaType.Dispose( );
                    }
                }
                else
                {
                    if (videoCapabilities == null)
                    {
                        object streamConfigObject;
                        // get stream configuration object
                        captureGraph.FindInterface(PinCategory.Capture, MediaType.Video, sourceBase, typeof(IAMStreamConfig).GUID, out streamConfigObject);

                        if (streamConfigObject != null)
                        {
                            IAMStreamConfig streamConfig = (IAMStreamConfig)streamConfigObject;
                            // get all video capabilities
                            try
                            {
                                videoCapabilities = AForge.Video.DirectShow.VideoCapabilities.FromStreamConfig(streamConfig);
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                if (runGraph)
                {
                    // render source device on sample grabber
                    captureGraph.RenderStream(PinCategory.Capture, MediaType.Video, sourceBase, null, grabberBase);

                    // get media type
                    if (sampleGrabber.GetConnectedMediaType(mediaType) == 0)
                    {
                        VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.FormatPtr, typeof(VideoInfoHeader));

                        grabber.Width  = vih.BmiHeader.Width;
                        grabber.Height = vih.BmiHeader.Height;
                        mediaType.Dispose( );
                    }

                    // get media control
                    mediaControl = (IMediaControl)graphObject;

                    // run
                    mediaControl.Run( );

                    while (!stopEvent.WaitOne(0, true))
                    {
                        Thread.Sleep(100);

                        if (needToDisplayPropertyPage)
                        {
                            needToDisplayPropertyPage = false;

                            try
                            {
                                // retrieve ISpecifyPropertyPages interface of the device
                                ISpecifyPropertyPages pPropPages = (ISpecifyPropertyPages)sourceObject;

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

                                // get filter info
                                FilterInfo filterInfo = new FilterInfo(deviceMoniker);

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

                                // release COM objects
                                Marshal.FreeCoTaskMem(caGUID.pElems);
                            }
                            catch
                            {
                            }
                        }
                    }
                    mediaControl.StopWhenReady( );
                }
            }
            catch (Exception exception)
            {
                // provide information to clients
                if (VideoSourceError != null)
                {
                    VideoSourceError(this, new VideoSourceErrorEventArgs(exception.Message));
                }
            }
            finally
            {
                // release all objects
                captureGraph  = null;
                graph         = null;
                sourceBase    = null;
                grabberBase   = null;
                sampleGrabber = null;
                mediaControl  = null;

                if (graphObject != null)
                {
                    Marshal.ReleaseComObject(graphObject);
                    graphObject = null;
                }
                if (sourceObject != null)
                {
                    Marshal.ReleaseComObject(sourceObject);
                    sourceObject = null;
                }
                if (grabberObject != null)
                {
                    Marshal.ReleaseComObject(grabberObject);
                    grabberObject = null;
                }
                if (captureGraphObject != null)
                {
                    Marshal.ReleaseComObject(captureGraphObject);
                    captureGraphObject = null;
                }
            }

            if (PlayingFinished != null)
            {
                PlayingFinished(this, ReasonToFinishPlaying.StoppedByUser);
            }
        }
コード例 #24
0
        public void DisplayPropertyPage()
        {
            if (theDevice != null)
            {
                Marshal.ReleaseComObject(theDevice);
                theDevice = null;
            }
            //Create the filter for the selected video input device
            string devicepath = _filter.Name; // cd.VideoSource;   //comboBox1.SelectedItem.ToString();

            theDevice = CreateFilter(FilterCategory.VideoInputDevice, devicepath);

            IBaseFilter dev = theDevice;

            //Get the ISpecifyPropertyPages for the filter
            ISpecifyPropertyPages pProp = dev as ISpecifyPropertyPages;
            int hr = 0;

            if (pProp == null)
            {
                //If the filter doesn't implement ISpecifyPropertyPages, try displaying IAMVfwCompressDialogs instead!
                IAMVfwCompressDialogs compressDialog = dev as IAMVfwCompressDialogs;
                if (compressDialog != null)
                {
                    hr = compressDialog.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
                    DsError.ThrowExceptionForHR(hr);
                }
                return;
            }

            //Get the name of the filter from the FilterInfo struct
            FilterInfo filterInfo;

            hr = dev.QueryFilterInfo(out filterInfo);
            DsError.ThrowExceptionForHR(hr);

            // Get the propertypages from the property bag
            DsCAUUID caGUID;

            hr = pProp.GetPages(out caGUID);
            DsError.ThrowExceptionForHR(hr);

            // Check for property pages on the output pin
            IPin pPin = DsFindPin.ByDirection(dev, PinDirection.Output, 0);
            ISpecifyPropertyPages pProp2 = pPin as ISpecifyPropertyPages;

            if (pProp2 != null)
            {
                DsCAUUID caGUID2;
                hr = pProp2.GetPages(out caGUID2);
                DsError.ThrowExceptionForHR(hr);

                if (caGUID2.cElems > 0)
                {
                    int soGuid = Marshal.SizeOf(typeof(Guid));

                    // Create a new buffer to hold all the GUIDs
                    IntPtr p1 = Marshal.AllocCoTaskMem((caGUID.cElems + caGUID2.cElems) * soGuid);

                    // Copy over the pages from the Filter
                    for (int x = 0; x < caGUID.cElems * soGuid; x++)
                    {
                        Marshal.WriteByte(p1, x, Marshal.ReadByte(caGUID.pElems, x));
                    }

                    // Add the pages from the pin
                    for (int x = 0; x < caGUID2.cElems * soGuid; x++)
                    {
                        Marshal.WriteByte(p1, x + (caGUID.cElems * soGuid), Marshal.ReadByte(caGUID2.pElems, x));
                    }

                    // Release the old memory
                    Marshal.FreeCoTaskMem(caGUID.pElems);
                    Marshal.FreeCoTaskMem(caGUID2.pElems);

                    // Reset caGUID to include both
                    caGUID.pElems  = p1;
                    caGUID.cElems += caGUID2.cElems;
                }
            }

            // Create and display the OlePropertyFrame
            try
            {
                object oDevice = (object)dev;
                hr = OleCreatePropertyFrame(_parent.Handle, 10, 10, filterInfo.achName, 1, ref oDevice, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero);
            }
            catch (Exception E)
            {
                //  DsError.ThrowExceptionForHR(hr);
            }

            // Release COM objects
            Marshal.FreeCoTaskMem(caGUID.pElems);
            Marshal.ReleaseComObject(pProp);
            if (filterInfo.pGraph != null)
            {
                Marshal.ReleaseComObject(filterInfo.pGraph);
            }
        }
コード例 #25
0
        internal static void _DisplayPropertyPage(object filter_or_pin, IntPtr hwndOwner)
        {
            if (filter_or_pin == null)
            {
                return;
            }

            //Get the ISpecifyPropertyPages for the filter
            ISpecifyPropertyPages pProp = filter_or_pin as ISpecifyPropertyPages;
            int hr = 0;

            if (pProp == null)
            {
                //If the filter doesn't implement ISpecifyPropertyPages, try displaying IAMVfwCompressDialogs instead!
                IAMVfwCompressDialogs compressDialog = filter_or_pin as IAMVfwCompressDialogs;
                if (compressDialog != null)
                {
                    hr = compressDialog.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
                    DsError.ThrowExceptionForHR(hr);
                }
                return;
            }

            string caption = string.Empty;

            if (filter_or_pin is IBaseFilter)
            {
                //Get the name of the filter from the FilterInfo struct
                IBaseFilter as_filter = filter_or_pin as IBaseFilter;
                FilterInfo  filterInfo;
                hr = as_filter.QueryFilterInfo(out filterInfo);
                DsError.ThrowExceptionForHR(hr);

                caption = filterInfo.achName;

                if (filterInfo.pGraph != null)
                {
                    Marshal.ReleaseComObject(filterInfo.pGraph);
                }
            }
            else
            if (filter_or_pin is IPin)
            {
                //Get the name of the filter from the FilterInfo struct
                IPin    as_pin = filter_or_pin as IPin;
                PinInfo pinInfo;
                hr = as_pin.QueryPinInfo(out pinInfo);
                DsError.ThrowExceptionForHR(hr);

                caption = pinInfo.name;
            }


            // Get the propertypages from the property bag
            DsCAUUID caGUID;

            hr = pProp.GetPages(out caGUID);
            DsError.ThrowExceptionForHR(hr);

            // Create and display the OlePropertyFrame
            object oDevice = (object)filter_or_pin;

            hr = NativeMethodes.OleCreatePropertyFrame(hwndOwner, 0, 0, caption, 1, ref oDevice, caGUID.cElems, caGUID.pElems, 0, 0, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            // Release COM objects
            Marshal.FreeCoTaskMem(caGUID.pElems);
            Marshal.ReleaseComObject(pProp);
        }
コード例 #26
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                //search for the weatherLayer first
                ILayer layer = null;
                RSSWeatherLayerClass RSSLayer = null;

                if (m_pHookHelper.FocusMap.LayerCount == 0)
                {
                    return;
                }

                IEnumLayer layers = m_pHookHelper.FocusMap.get_Layers(null, false);
                layers.Reset();
                layer = layers.Next();
                while (layer != null)
                {
                    if (layer is RSSWeatherLayerClass)
                    {
                        RSSLayer = (RSSWeatherLayerClass)layer;
                        break;
                    }
                    layer = layers.Next();
                }

                //In case that the weather layer wasn't found,just return
                if (null == RSSLayer)
                {
                    return;
                }


                //Launch the layer's properties
                Type   typ;
                object obj;
                Guid[] g;

                // METHOD 1: Instantiating a COM object and displaying its property pages
                // ONLY WORKS ON TRUE COM OBJECTS!  .NET objects that have rolled their own
                // ISpecifyPropertyPages implementation will error out when you try to cast
                // the instantiated object to your own ISpecifyPropertyPages implementation.

                // Get the typeinfo for the ActiveX common dialog control
                typ = Type.GetTypeFromProgID("MSComDlg.CommonDialog");

                // Create an instance of the control.  We pass it to the property frame function
                // so the property pages have an object from which to get current settings and apply
                // new settings.
                obj = Activator.CreateInstance(typ);
                // This handy function calls IPersistStreamInit->New on COM objects to initialize them
                ActiveXMessageFormatter.InitStreamedObject(obj);

                // Get the property pages for the control using the direct CAUUID method
                // This only works for true COM objects and I demonstrate it here only
                // to show how it is done.  Use the static method
                // PropertyPage.GetPagesForType() method for real-world use.
                ISpecifyPropertyPages pag = (ISpecifyPropertyPages)obj;
                CAUUID cau = new CAUUID(0);
                pag.GetPages(ref cau);
                g = cau.GetPages();

                // Instantiating a .NET object and displaying its property pages
                // WORKS ON ALL OBJECTS, .NET or COM

                // Create an instance of the .NET control, MyUserControl
                typ = Type.GetTypeFromProgID("RSSWeatherLayer.PropertySheet");

                // Retrieve the pages for the control
                g = PropertyPage.GetPagesForType(typ);

                // Create an instance of the control that we can give to the property pages
                obj = Activator.CreateInstance(typ);

                //add the RSS layer to the property-sheet control
                ((PropertySheet)obj).RSSWatherLayer = RSSLayer;

                // Display the OLE Property page for the control
                object[] items = new object[] { obj };

                PropertyPage.CreatePropertyFrame(IntPtr.Zero, 500, 500, "RSS Layer properties", items, g);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }