示例#1
0
        protected void CalcRunningObjName(UCOMIRunningObjectTable rot,
                                          UCOMIBindCtx bc,
                                          UCOMIMoniker moniker,
                                          String monikerName)
        {
            _moniker     = moniker;
            _monikerName = monikerName;
            // FIXME - Does not work because IsRunning is defined
            // incorrectly in the IRunningObjectTable mapping
            //IsRunning = rot.IsRunning(Moniker);

            // Get the object from the table
            _isRunningObjectTable = true;
            // Persist Guid is probably not used for anything, but
            // let's get it anyway
            Guid persistGuid = new Guid();

            _moniker.GetClassID(out persistGuid);
            _persistGuid = persistGuid;
            // GUID is the *real* CLSID for the object
            String rotProgId = null;

            if (_monikerName.StartsWith("!{"))
            {
                int guidStart = _monikerName.IndexOf('{');
                int guidEnd   = _monikerName.IndexOf('}');
                if (guidStart != -1 && guidEnd != -1)
                {
                    _CLSID =
                        _monikerName.Substring(guidStart, guidEnd);
                    _classIdKey = Windows.KeyCLSID.OpenSubKey(_CLSID);
                    if (_classIdKey != null)
                    {
                        String progId = (String)
                                        _classIdKey.OpenSubKey("ProgID").
                                        GetValue(null);
                        _classNameKey =
                            Windows.KeyClassRoot.OpenSubKey(progId);
                        rotProgId = progId
                                    + _monikerName.Substring(guidEnd + 1);
                    }
                }
                // Use the translated progId if available
                if (rotProgId != null)
                {
                    _monikerDisplayName = rotProgId;
                }
                else
                {
                    _monikerDisplayName = _monikerName;
                }
            }
            else
            {
                // The moniker is something else, just use that
                _monikerDisplayName = _monikerName;
            }
        }
示例#2
0
        public static IBaseFilter AddFilterByDevicePath(IGraphBuilder graphBuilder, string devicePath, string name)
        {
            int         hr     = 0;
            IBaseFilter filter = null;

#if USING_NET11
            UCOMIBindCtx bindCtx = null;
            UCOMIMoniker moniker = null;
#else
            IBindCtx bindCtx = null;
            IMoniker moniker = null;
#endif
            int eaten;

            if (graphBuilder == null)
            {
                throw new ArgumentNullException("graphBuilder");
            }

            try
            {
                hr = NativeMethods.CreateBindCtx(0, out bindCtx);
                Marshal.ThrowExceptionForHR(hr);

                hr = NativeMethods.MkParseDisplayName(bindCtx, devicePath, out eaten, out moniker);
                Marshal.ThrowExceptionForHR(hr);

                hr = (graphBuilder as IFilterGraph2).AddSourceFilterForMoniker(moniker, bindCtx, name, out filter);
                DsError.ThrowExceptionForHR(hr);
            }
            catch
            {
                // An error occur. Just returning null...
            }
            finally
            {
                if (bindCtx != null)
                {
                    Marshal.ReleaseComObject(bindCtx);
                }
                if (moniker != null)
                {
                    Marshal.ReleaseComObject(moniker);
                }
            }

            return(filter);
        }
示例#3
0
        // Get filter name represented by the moniker string
        private string GetName(string monikerString)
        {
            UCOMIBindCtx bindCtx = null;
            UCOMIMoniker moniker = null;
            String       name    = "";
            int          n       = 0;

            // create bind context
            if (Win32.CreateBindCtx(0, out bindCtx) == 0)
            {
                // convert moniker`s string to a moniker
                if (Win32.MkParseDisplayName(bindCtx, monikerString, ref n, out moniker) == 0)
                {
                    // get device name
                    name = GetName(moniker);

                    Marshal.ReleaseComObject(moniker);
                    moniker = null;
                }
                Marshal.ReleaseComObject(bindCtx);
                bindCtx = null;
            }
            return(name);
        }
示例#4
0
文件: Win32.cs 项目: tdhieu/openvss
		int MkParseDisplayName(
			UCOMIBindCtx pbc,
			string szUserName,
			ref int pchEaten,
			out UCOMIMoniker ppmk);
示例#5
0
文件: Win32.cs 项目: tdhieu/openvss
		int CreateBindCtx(
			int reserved,
			out UCOMIBindCtx ppbc);
 public static extern uint CreateBindCtx(uint res, out UCOMIBindCtx ctx);
示例#7
0
 public static extern uint CreateBindCtx(uint res, out UCOMIBindCtx ctx);
示例#8
0
 public int MonikerBindToObject(UCOMIMoniker pMk, UCOMIBindCtx pBC, IntPtr pBSC, Guid riid, out object ppvObj)
 {
     // TODO:  Add IAMFilterGraphCallbackTest.MonikerBindToObject implementation
     ppvObj = null;
     return(0);
 }
示例#9
0
        // Thread entry point
        public void WorkerThread()
        {
            // grabber
            Grabber grabber = new Grabber(this);

            // objects
            object graphObj   = null;
            object sourceObj  = null;
            object grabberObj = null;

            // interfaces
            IGraphBuilder  graph       = null;
            IBaseFilter    sourceBase  = null;
            IBaseFilter    grabberBase = null;
            ISampleGrabber sg          = null;
            IMediaControl  mc          = null;

            try
            {
                // Get type for filter graph
                Type srvType = Type.GetTypeFromCLSID(Clsid.FilterGraph);
                if (srvType == null)
                {
                    throw new ApplicationException("Failed creating filter graph");
                }

                // create filter graph
                graphObj = Activator.CreateInstance(srvType);
                graph    = (IGraphBuilder)graphObj;

                // ----
                UCOMIBindCtx bindCtx = null;
                UCOMIMoniker 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, source, ref n, out moniker) == 0)
                    {
                        // get device base filter
                        Guid filterId = typeof(IBaseFilter).GUID;
                        moniker.BindToObject(null, null, ref filterId, out sourceObj);

                        Marshal.ReleaseComObject(moniker);
                        moniker = null;
                    }
                    Marshal.ReleaseComObject(bindCtx);
                    bindCtx = null;
                }
                // ----

                if (sourceObj == null)
                {
                    throw new ApplicationException("Failed creating device object for moniker");
                }

                sourceBase = (IBaseFilter)sourceObj;

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

                // create sample grabber
                grabberObj  = Activator.CreateInstance(srvType);
                sg          = (ISampleGrabber)grabberObj;
                grabberBase = (IBaseFilter)grabberObj;

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

                // set media type
                AMMediaType mt = new AMMediaType();
                mt.majorType = MediaType.Video;
                mt.subType   = MediaSubType.RGB24;
                sg.SetMediaType(mt);

                // connect pins
                if (graph.Connect(DSTools.GetOutPin(sourceBase, 0), DSTools.GetInPin(grabberBase, 0)) < 0)
                {
                    throw new ApplicationException("Failed connecting filters");
                }

                // get media type
                if (sg.GetConnectedMediaType(mt) == 0)
                {
                    VideoInfoHeader vih = (VideoInfoHeader)Marshal.PtrToStructure(mt.formatPtr, typeof(VideoInfoHeader));

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

                // render
                graph.Render(DSTools.GetOutPin(grabberBase, 0));

                //
                sg.SetBufferSamples(false);
                sg.SetOneShot(false);
                sg.SetCallback(grabber, 1);

                // window
                IVideoWindow win = (IVideoWindow)graphObj;
                win.put_AutoShow(false);
                win = null;


                // get media control
                mc = (IMediaControl)graphObj;

                // run
                mc.Run();

                while (!stopEvent.WaitOne(0, true))
                {
                    Thread.Sleep(100);
                }
                mc.StopWhenReady();
            }
            // catch any exceptions
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("----: " + e.Message);
            }
            // finalization block
            finally
            {
                // release all objects
                mc          = null;
                graph       = null;
                sourceBase  = null;
                grabberBase = null;
                sg          = null;

                if (graphObj != null)
                {
                    Marshal.ReleaseComObject(graphObj);
                    graphObj = null;
                }
                if (sourceObj != null)
                {
                    Marshal.ReleaseComObject(sourceObj);
                    sourceObj = null;
                }
                if (grabberObj != null)
                {
                    Marshal.ReleaseComObject(grabberObj);
                    grabberObj = null;
                }
            }
        }
		public static extern int MkParseDisplayName(UCOMIBindCtx pcb, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out int pchEaten, out UCOMIMoniker ppmk);
示例#11
0
 int MkParseDisplayName(
     UCOMIBindCtx pbc,
     string szUserName,
     ref int pchEaten,
     out UCOMIMoniker ppmk);
示例#12
0
 int CreateBindCtx(
     int reserved,
     out UCOMIBindCtx ppbc);
示例#13
0
        public void WorkerThread()
        {
            Grabber        pCallback = new Grabber(this);
            object         o         = null;
            object         ppvResult = null;
            object         obj4      = null;
            IGraphBuilder  builder   = null;
            IBaseFilter    pFilter   = null;
            IBaseFilter    filter2   = null;
            ISampleGrabber grabber2  = null;
            IMediaControl  control   = null;

            try
            {
                Type typeFromCLSID = Type.GetTypeFromCLSID(Clsid.FilterGraph);
                if (typeFromCLSID == null)
                {
                    throw new ApplicationException("Failed creating filter graph");
                }
                o       = Activator.CreateInstance(typeFromCLSID);
                builder = (IGraphBuilder)o;
                UCOMIBindCtx ppbc     = null;
                UCOMIMoniker ppmk     = null;
                int          pchEaten = 0;
                if (Win32.CreateBindCtx(0, out ppbc) == 0)
                {
                    if (Win32.MkParseDisplayName(ppbc, this.source, ref pchEaten, out ppmk) == 0)
                    {
                        Guid gUID = typeof(IBaseFilter).GUID;
                        ppmk.BindToObject(null, null, ref gUID, out ppvResult);
                        Marshal.ReleaseComObject(ppmk);
                        ppmk = null;
                    }
                    Marshal.ReleaseComObject(ppbc);
                    ppbc = null;
                }
                if (ppvResult == null)
                {
                    throw new ApplicationException("Failed creating device object for moniker");
                }
                pFilter       = (IBaseFilter)ppvResult;
                typeFromCLSID = Type.GetTypeFromCLSID(Clsid.SampleGrabber);
                if (typeFromCLSID == null)
                {
                    throw new ApplicationException("Failed creating sample grabber");
                }
                obj4     = Activator.CreateInstance(typeFromCLSID);
                grabber2 = (ISampleGrabber)obj4;
                filter2  = (IBaseFilter)obj4;
                builder.AddFilter(pFilter, "source");
                builder.AddFilter(filter2, "grabber");
                AMMediaType pmt = new AMMediaType {
                    majorType = MediaType.Video,
                    subType   = MediaSubType.RGB24
                };
                grabber2.SetMediaType(pmt);
                if (builder.Connect(DSTools.GetOutPin(pFilter, 0), DSTools.GetInPin(filter2, 0)) < 0)
                {
                    throw new ApplicationException("Failed connecting filters");
                }
                if (grabber2.GetConnectedMediaType(pmt) == 0)
                {
                    VideoInfoHeader header = (VideoInfoHeader)Marshal.PtrToStructure(pmt.formatPtr, typeof(VideoInfoHeader));
                    pCallback.Width  = header.BmiHeader.Width;
                    pCallback.Height = header.BmiHeader.Height;
                    pmt.Dispose();
                }
                builder.Render(DSTools.GetOutPin(filter2, 0));
                grabber2.SetBufferSamples(false);
                grabber2.SetOneShot(false);
                grabber2.SetCallback(pCallback, 1);
                ((IVideoWindow)o).put_AutoShow(false);
                control = (IMediaControl)o;
                control.Run();
                while (!this.stopEvent.WaitOne(0, true))
                {
                    Thread.Sleep(100);
                }
                control.StopWhenReady();
            }
            catch (Exception)
            {
            }
            finally
            {
                control  = null;
                builder  = null;
                pFilter  = null;
                filter2  = null;
                grabber2 = null;
                if (o != null)
                {
                    Marshal.ReleaseComObject(o);
                    o = null;
                }
                if (ppvResult != null)
                {
                    Marshal.ReleaseComObject(ppvResult);
                    ppvResult = null;
                }
                if (obj4 != null)
                {
                    Marshal.ReleaseComObject(obj4);
                    obj4 = null;
                }
            }
        }
示例#14
0
		protected void CalcRunningObjName(UCOMIRunningObjectTable rot,
										  UCOMIBindCtx bc, 
										  UCOMIMoniker moniker,
										  String monikerName)
		{
			_moniker = moniker;
			_monikerName = monikerName;
			// FIXME - Does not work because IsRunning is defined
			// incorrectly in the IRunningObjectTable mapping
			//IsRunning = rot.IsRunning(Moniker);
				
			// Get the object from the table
			_isRunningObjectTable = true;
			// Persist Guid is probably not used for anything, but
			// let's get it anyway
			Guid persistGuid = new Guid();
			_moniker.GetClassID(out persistGuid);
			_persistGuid = persistGuid;
			// GUID is the *real* CLSID for the object
			String rotProgId = null;
			if (_monikerName.StartsWith("!{"))
			{
				int guidStart = _monikerName.IndexOf('{');
				int guidEnd = _monikerName.IndexOf('}');
				if (guidStart != -1 && guidEnd != -1)
				{
					_CLSID = 
						_monikerName.Substring(guidStart, guidEnd);
					_classIdKey = Windows.KeyCLSID.OpenSubKey(_CLSID);
					if (_classIdKey != null)
					{
						String progId = (String)
							_classIdKey.OpenSubKey("ProgID").
							GetValue(null);
						_classNameKey = 
							Windows.KeyClassRoot.OpenSubKey(progId);
						rotProgId = progId
							+ _monikerName.Substring(guidEnd + 1);
					}
				}
				// Use the translated progId if available
				if (rotProgId != null)
					_monikerDisplayName = rotProgId;
				else
					_monikerDisplayName = _monikerName;
			}
			else
			{
				// The moniker is something else, just use that
				_monikerDisplayName = _monikerName;
			}
		}
示例#15
0
 public static extern int MkParseDisplayName(UCOMIBindCtx pcb, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out int pchEaten, out UCOMIMoniker ppmk);
 public static extern int  CreateBindCtx(int reserved, out UCOMIBindCtx ppbc);
示例#17
0
		private static extern int CreateBindCtx(int res, out UCOMIBindCtx ctx);
示例#18
0
			CreateBindCtx(uint reserved, 
						  out UCOMIBindCtx bc);
示例#19
0
 CreateBindCtx(uint reserved,
               out UCOMIBindCtx bc);
 public static extern int CreateBindCtx(int reserved,
                               out UCOMIBindCtx ppbc);
示例#21
0
 public int CreateMoniker(string szName, UCOMIBindCtx pBC, out UCOMIMoniker ppmk, int dwReserved)
 {
     // TODO:  Add IAMFilterGraphCallbackTest.CreateMoniker implementation
     ppmk = null;
     return(0);
 }