예제 #1
0
        private void Config()
        {
            int hr;
            IFilterGraph gb = (IFilterGraph)new FilterGraph();
            int iDeviceIndex = 0;

            ICaptureGraphBuilder2 cgb = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
            IMediaControl m_imc1 = gb as IMediaControl;
            hr = cgb.SetFiltergraph((IGraphBuilder)gb);

            DsDevice[] dev = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            IBaseFilter theDevice;
            hr = ((IFilterGraph2)gb).AddSourceFilterForMoniker(dev[iDeviceIndex].Mon, null, dev[iDeviceIndex].Name, out theDevice);

            IStreamBufferSink sbs = new SBE2Sink() as IStreamBufferSink;
            hr = gb.AddFilter((IBaseFilter)sbs, "StreamBufferSink");
            DsError.ThrowExceptionForHR(hr);

            hr = cgb.RenderStream(null, null, theDevice, null, sbs as IBaseFilter);
            DsError.ThrowExceptionForHR(hr);

            hr = sbs.LockProfile(Environment.ExpandEnvironmentVariables(FILENAME));
            DsError.ThrowExceptionForHR(hr);
            SetupGraph2();

            Marshal.ReleaseComObject(cgb);
            Marshal.ReleaseComObject(theDevice);

            m_imc1.Run();
            System.Threading.Thread.Sleep(1000);
            m_imc2.Run();
            System.Threading.Thread.Sleep(1000);
        }
예제 #2
0
        private void Configure()
        {
            int          hr;
            IFilterGraph gb      = (IFilterGraph) new FilterGraph();
            DsROTEntry   rot     = new DsROTEntry(gb);
            IBaseFilter  pFilter = (IBaseFilter) new MPEG2Demultiplexer();
            AMMediaType  amt     = new AMMediaType();

            amt.majorType = MediaType.Video;
            IPin pPin;

            int [] pid = new int[1];
            pid[0] = 123;

            hr = gb.AddFilter(pFilter, "fdsa");
            DsError.ThrowExceptionForHR(hr);

            IMpeg2Demultiplexer ism = (IMpeg2Demultiplexer)pFilter;

            hr = ism.CreateOutputPin(amt, "Pin1", out pPin);
            DsError.ThrowExceptionForHR(hr);

            IMPEG2PIDMap pmap = pPin as IMPEG2PIDMap;

            //hr = pmap.MapPID(1, pid, MediaSampleContent.ElementaryStream);
            //DsError.ThrowExceptionForHR(hr);
            //hr = pmap.EnumPIDMap(out m_pm);
            DsError.ThrowExceptionForHR(hr);
        }
예제 #3
0
        public int JoinFilterGraph(IFilterGraph pGraph, string pName)
        {
            _Graph = pGraph;
            _Name  = pName;

            return(OnJoinFilterGraph());
        }
        private void HookupGraphEventService(IFilterGraph pGraph)
        {
            object o;
            int    hr;

            DirectShowLib.IServiceProvider spServiceProvider = (DirectShowLib.IServiceProvider)pGraph;

            hr = spServiceProvider.QueryService(typeof(BroadcastEventService).GUID,
                                                typeof(IBroadcastEventEx).GUID,
                                                out o);

            spBroadcastEvent = o as IBroadcastEventEx;

            if (hr < 0 || spBroadcastEvent == null)
            {
                // Create the Broadcast Event Service object.
                spBroadcastEvent = new BroadcastEventService() as IBroadcastEventEx;

                IRegisterServiceProvider spRegService = (IRegisterServiceProvider)pGraph;

                // Register the Broadcast Event Service object as a service.
                hr = spRegService.RegisterService(
                    typeof(BroadcastEventService).GUID,
                    spBroadcastEvent);
            }

            DsError.ThrowExceptionForHR(hr);
        }
예제 #5
0
        protected CaptureGraph(FilterInfo fiSource)
        {
            try
            {
                // Fgm initialization
                fgm   = new FilgraphManagerClass();
                iFG   = (IFilterGraph)fgm;
                iGB   = (IGraphBuilder)fgm;
                rotID = FilterGraph.AddToRot(iGB);

                // Create source filter and initialize it
                source = (SourceFilter)Filter.CreateFilter(fiSource);
                iGB.AddFilter(source.BaseFilter, source.FriendlyName);
                source.AddedToGraph(fgm);

                // Pass flags to the RtpRenderer filter from the config file.
                this.rtpRendererFlags = 0;
                string setting = ConfigurationManager.AppSettings[AppConfig.MDS_RtpRendererFlags];
                if (!String.IsNullOrEmpty(setting))
                {
                    if (!byte.TryParse(setting, out rtpRendererFlags))
                    {
                        rtpRendererFlags = 0;
                    }
                }
            }
            catch (Exception)
            {
                Cleanup();
                throw;
            }
        }
예제 #6
0
        public DsROTEntry(IFilterGraph graph)
        {
            IRunningObjectTable pprot = null;
            IMoniker            ppmk  = null;

            try
            {
                DsError.ThrowExceptionForHR(GetRunningObjectTable(0, out pprot));
                int    id = Process.GetCurrentProcess().Id;
                IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(graph);
                int    num3 = (int)iUnknownForObject;
                Marshal.Release(iUnknownForObject);
                string item = string.Format("FilterGraph {0} pid {1}", num3.ToString("x8"), id.ToString("x8"));
                DsError.ThrowExceptionForHR(CreateItemMoniker("!", item, out ppmk));
                this.m_cookie = pprot.Register(1, graph, ppmk);
            }
            finally
            {
                if (ppmk != null)
                {
                    Marshal.ReleaseComObject(ppmk);
                    ppmk = null;
                }
                if (pprot != null)
                {
                    Marshal.ReleaseComObject(pprot);
                    pprot = null;
                }
            }
        }
예제 #7
0
        public FilterControl(IFilterGraph fg)
        {
            filterGraph = fg;
            Filters = new ArrayList { };

            getFilters();
        }
예제 #8
0
 protected override void SetupFilterGraph(IFilterGraph graph)
 {
     _audioEngine = new X3DAudioEngine();
     _graph       = graph as IGraphBuilder;
     base.SetupFilterGraph(graph);
     SetupAudio();
 }
예제 #9
0
        /// <summary>
        /// Default Constructor
        /// </summary>
        public DSGraphEditPanel()
        {
            InitializeComponent();
            int hr = 0;

            // create filter graph
            _graph = (IFilterGraph) new FilterGraph();

            _filterGraphCreated = true;

            // give the filter graph to the DaggerUIGraph
            dsDaggerUIGraph1._Graph = _graph;

            // mark it as having been created internally
            dsDaggerUIGraph1._filterGraphCreated = true;

#if DEBUG
            rot = new DsROTEntry(_graph);
#endif

            // Initialize items common to all constructors
            Init();

            // get the state
            _mediaControl.GetState(100, out _mediaState);

            // Have the graph signal event via window callbacks for performance
            _mediaEventEx = _graph as IMediaEventEx;
            if (_mediaEventEx != null)
            {
                hr = _mediaEventEx.SetNotifyWindow(this.Handle, WMGraphNotify, IntPtr.Zero);
                DsError.ThrowExceptionForHR(hr);
            }
        }
예제 #10
0
        /// <summary>
        /// Static method to connect to a IFilterGraph on the ROT and create a DSGraphEditPanel for it
        /// </summary>
        /// <returns></returns>
        public static DSGraphEditPanel ConnectToRemoteGraph()
        {
            DSGraphEditPanel ret = null;
            ROTEntriesDialog rd  = new ROTEntriesDialog();

            if (rd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    // Connect to the FilterGraph selected in ROTEntriesDialog and create
                    // a new GraphEditPanel for it
                    IFilterGraph fg = rd.FilterGraph;
                    ret = new DSGraphEditPanel(fg);
                    ret._isRemoteGraph  = true;
                    ret._rotEntryString = rd.SelectedROTEntry;
                }
                finally
                {
                    // always dispose of ROTEntriesDialog when you're done with it
                    rd.Dispose();
                    rd = null;
                }
            }
            return(ret);
        }
예제 #11
0
        /// <summary>
        /// Get a List of all DirectShow IBasefilters in the FilterGraph
        /// </summary>
        /// <returns>List of filters</returns>
        internal List <IBaseFilter> GetFilters(IFilterGraph graph)
        {
            if (graph == null)
            {
                return(null);
            }

            int                hr = 0;
            IEnumFilters       enumFilters;
            List <IBaseFilter> filtersArray = new List <IBaseFilter>();

            hr = graph.EnumFilters(out enumFilters);
            DsError.ThrowExceptionForHR(hr);

            IntPtr fetched = Marshal.AllocCoTaskMem(4);

            try
            {
                IBaseFilter[] filters = new IBaseFilter[1];
                while (enumFilters.Next(filters.Length, filters, fetched) == 0)
                {
                    filtersArray.Add(filters[0]);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(enumFilters);
                Marshal.FreeCoTaskMem(fetched);
            }
            return(filtersArray);
        }
예제 #12
0
 protected override void SetupFilterGraph(IFilterGraph graph)
 {
     _audioEngine = new X3DAudioEngine();
     _graph = graph as IGraphBuilder;
     base.SetupFilterGraph(graph);
     SetupAudio();
 }
예제 #13
0
        private static IBaseFilter tオーディオレンダラを探して返す(IFilterGraph graph)
        {
            int         hr            = 0;
            IBaseFilter audioRenderer = null;

            IEnumFilters eFilters;

            hr = graph.EnumFilters(out eFilters);
            DsError.ThrowExceptionForHR(hr);
            try
            {
                var filters = new IBaseFilter[1];
                while (eFilters.Next(1, filters, IntPtr.Zero) == CWin32.S_OK)
                {
                    if ((filters[0] as IAMAudioRendererStats) != null)
                    {
                        audioRenderer = filters[0];
                        break;
                    }

                    CCommon.tReleaseComObject(ref filters[0]);
                }
            }
            finally
            {
                CCommon.tReleaseComObject(ref eFilters);
            }
            return(audioRenderer);
        }
예제 #14
0
        private void Config()
        {
            m_ixd       = (IXml2Dex) new Xml2Dex();
            m_pTimeline = (IAMTimeline) new AMTimeline();
            IRenderEngine ire = (IRenderEngine) new RenderEngine();

            m_ifg = (IFilterGraph) new FilterGraph();
            ire.SetFilterGraph((IGraphBuilder)m_ifg);
        }
예제 #15
0
        private void TestGraph()
        {
            int hr;

            m_pGraph = new FilterGraph() as IFilterGraph;

            hr = m_aStream.JoinFilterGraph(m_pGraph);
            DsError.ThrowExceptionForHR(hr);
        }
예제 #16
0
        // Constructor
        public DSTranscoderBase()
        {
            // Create a new filter graph to work with, and ensure it's disposed when this object is
            dc = new DisposalCleanup();
            currentFilterGraph = (IFilterGraph)new FilterGraph();
            dc.Add(currentFilterGraph);

            CreationDate = DateTime.Now;
        }
예제 #17
0
        protected DisposalCleanup dc;              // A class written by Stephen Toub to aid in cleanup / release of COM objects

        // Constructor
        public DSTranscoderBase()
        {
            // Create a new filter graph to work with, and ensure it's disposed when this object is
            dc = new DisposalCleanup();
            currentFilterGraph = (IFilterGraph) new FilterGraph();
            dc.Add(currentFilterGraph);

            CreationDate = DateTime.Now;
        }
예제 #18
0
        /// <summary>
        /// Configures all general DirectShow interfaces that the
        /// FilterGraph supplies.
        /// </summary>
        /// <param name="graph">The FilterGraph to setup</param>
        protected virtual void SetupFilterGraph(IFilterGraph graph)
        {
            m_graph = graph;

            /* Setup the interfaces and query basic information
             * on the graph that is passed */
            SetBasicAudioInterface(m_graph as IBasicAudio);
            SetMediaControlInterface(m_graph as IMediaControl);
            SetMediaEventExInterface(m_graph as IMediaEventEx);
        }
예제 #19
0
파일: ClipPlayer.cs 프로젝트: d3x0r/xperdex
 public ClipEntry(ClipEntry r)
 {
     m_tOffset     = r.m_tOffset;
     m_pGraph      = r.m_pGraph;
     m_pSinkFilter = r.m_pSinkFilter;
     m_strName     = r.m_strName;
     m_tStart      = r.m_tStart;
     m_tStop       = r.m_tStop;
     m_bPrimed     = r.m_bPrimed;
 }
예제 #20
0
        /// <summary>
        /// Disposed event handler to release interfaces AFTER the UIGraph is disposed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void DSDaggerUIGraph_Disposed(object sender, EventArgs e)
        {
            // clean up all interfaces and references
            _Graph = null;

            // release all the com interfaces in the Nodes
            foreach (DaggerUINode uinode in AllNodes)
            {
                (uinode.Node as DSFilterNode).CloseInterfaces();
            }
        }
예제 #21
0
        public static string Debug(IFilterGraph iFG)
        {
            string ret = "\nFilters in graph\n";

            foreach(IBaseFilter iBF in FiltersInGraph(iFG))
            {
                ret += string.Format(CultureInfo.CurrentCulture, "     {0}\n", Filter.Name(iBF));
            }

            return ret;
        }
예제 #22
0
        /// <summary>
        /// Contruct a DSGrapheditForm from an existing FilterGraph
        /// </summary>
        public DSGrapheditForm(IFilterGraph filtergraph)
        {
            InitializeComponent();
            DSGraphEditPanel _grapheditPanel = new DSGraphEditPanel(filtergraph);

            _grapheditPanel.Dock = DockStyle.Fill;
            splitContainer1.Panel2.Controls.Add(_grapheditPanel);
            this.Disposed += new EventHandler(DSGrapheditForm_Disposed);

            _filtersPanel.AssociatedGraphPanel = _grapheditPanel;
        }
예제 #23
0
        public void ResetGraph()
        {
            if (_filterGraph != null)
            {
                _mediaWindow.SetRendererInterfaces(null, null, null);
                _filterGraph.Dispose();
                _filterGraph = null;

                CleanUpMediaWindow();
            }
        }
예제 #24
0
파일: Graphs.cs 프로젝트: cucacutexice/AIGA
        public static string Debug(IFilterGraph iFG)
        {
            string ret = "\r\nFilters in graph\r\n";

            foreach (IBaseFilter iBF in FiltersInGraph(iFG))
            {
                ret += string.Format("\t{0}\r\n", Filter.Name(iBF));
            }

            return(ret);
        }
예제 #25
0
        public static string Debug(IFilterGraph iFG)
        {
            string ret = "\nFilters in graph\n";

            foreach (IBaseFilter iBF in FiltersInGraph(iFG))
            {
                ret += string.Format(CultureInfo.CurrentCulture, "     {0}\n", Filter.Name(iBF));
            }

            return(ret);
        }
예제 #26
0
 int IBaseFilter.JoinFilterGraph(IFilterGraph pGraph, string pName)
 {
     if ((filterGraph = pGraph) == null)
     {
         name = "Stream Source Filter";
     }
     else
     {
         name = pName;
     }
     return(S_OK);
 }
예제 #27
0
        public static void Disconnect(IFilterGraph pFilterGraph, IPin pPin)
        {
            IPin pInputPin = null;

            if (pPin.ConnectedTo(out pInputPin) == DsHlp.S_OK)
            {
                pFilterGraph.Disconnect(pInputPin);
                Marshal.ReleaseComObject(pInputPin);
            }

            pFilterGraph.Disconnect(pPin);
        }
예제 #28
0
파일: ClipPlayer.cs 프로젝트: d3x0r/xperdex
    ClipEntry Copy(ClipEntry r)
    {
        m_tOffset     = r.m_tOffset;
        m_pGraph      = r.m_pGraph;
        m_pSinkFilter = r.m_pSinkFilter;
        m_strName     = r.m_strName;
        m_tStart      = r.m_tStart;
        m_tStop       = r.m_tStop;
        m_bPrimed     = r.m_bPrimed;

        return(this);
    }
예제 #29
0
        CodecConfiguration.Codec?GetCodecInfo(IFilterGraph graph, string filterName)
        {
            IBaseFilter filter;
            int         hr = graph.FindFilterByName(filterName, out filter);

            CodecConfiguration.Codec?result = null;
            if (hr == 0 && filter != null)
            {
                result = GetCodecInfo(filter, filterName);
                DirectShowUtil.ReleaseComObject(filter, 2000);
            }
            return(result);
        }
예제 #30
0
        /// <summary>
        /// Disable DirectX Video Acceleration.
        /// </summary>
        /// <param name="fgm"></param>
        public static void DisableDXVA(FilgraphManagerClass fgm)
        {
            // Retrieve WM decoder so we can turn off DXVA
            IBaseFilter decoder = Filter.FindBaseFilterByName(fgm, "WMVideo Decoder DMO");

            if (decoder == null)
            {
                return;
            }

            // Remove the renderer and everything back to the decoder
            IFilterGraph iFG = (IFilterGraph)fgm;
            IEnumFilters iEnum;

            iFG.EnumFilters(out iEnum);

            uint        fetched;
            IBaseFilter iBF;

            iEnum.Next(1, out iBF, out fetched);
            List <IBaseFilter> toRemove = new List <IBaseFilter>();

            /// A base assumption is that the first items returned by the enumerator
            /// are the video renderer and other filters upstream to the video decoder.
            /// This should be true if these filters were the most recently added.
            /// Otherwise it would break in some contexts, including that of graphs with multiple branches.
            while (fetched == 1 && (Filter.Name(iBF) != Filter.Name(decoder)))
            {
                toRemove.Add(iBF);
                iEnum.Next(1, out iBF, out fetched);
            }

            foreach (IBaseFilter ibf in toRemove)
            {
                iFG.RemoveFilter(ibf);
            }

            // Try turning off DXVA
            try
            {
                IPropertyBag iPB = (IPropertyBag)decoder;
                object       o   = false;
                iPB.Write(WM9PropList.g_wszWMVCDXVAEnabled, ref o);
            }
            catch (Exception e) { Console.WriteLine(e.ToString()); } // Might be WM7 instead of WM9

            // Render again
            ((IGraphBuilder)fgm).Render(Filter.GetPin(decoder, _PinDirection.PINDIR_OUTPUT,
                                                      Guid.Empty, Guid.Empty, false, 0));
        }
예제 #31
0
        public DsROTEntry(IFilterGraph graph)
        {
            int hr = 0;
            IRunningObjectTable rot = null;
            IMoniker            mk  = null;

            try
            {
                // First, get a pointer to the running object table
                hr = GetRunningObjectTable(0, out rot);
                new HRESULT(hr).Throw();

                // Build up the object to add to the table
                int    id    = System.Diagnostics.Process.GetCurrentProcess().Id;
                IntPtr iuPtr = Marshal.GetIUnknownForObject(graph);
                string s;
                try
                {
                    s = iuPtr.ToString("x");
                }
                catch
                {
                    s = "";
                }
                finally
                {
                    Marshal.Release(iuPtr);
                }
                string item = string.Format("FilterGraph {0} pid {1}", s, id.ToString("x8"));
                hr = CreateItemMoniker("!", item, out mk);
                new HRESULT(hr).Throw();

                // Add the object to the table
                m_cookie = rot.Register((int)ROTFlags.RegistrationKeepsAlive, graph, mk);
            }
            finally
            {
                if (mk != null)
                {
                    Marshal.ReleaseComObject(mk);
                    mk = null;
                }
                if (rot != null)
                {
                    Marshal.ReleaseComObject(rot);
                    rot = null;
                }
            }
        }
예제 #32
0
    public DsROTEntry(IFilterGraph graph)
    {
      int hr = 0;
      IRunningObjectTable rot = null;
      IMoniker mk = null;
      try
      {
        // First, get a pointer to the running object table
        hr = GetRunningObjectTable(0, out rot);
        new HRESULT(hr).Throw();

        // Build up the object to add to the table
        int id = System.Diagnostics.Process.GetCurrentProcess().Id;
        IntPtr iuPtr = Marshal.GetIUnknownForObject(graph);
        string s;
        try
        {
          s = iuPtr.ToString("x");
        }
        catch
        {
          s = "";
        }
        finally
        {
          Marshal.Release(iuPtr);
        }
        string item = string.Format("FilterGraph {0} pid {1}", s, id.ToString("x8"));
        hr = CreateItemMoniker("!", item, out mk);
        new HRESULT(hr).Throw();

        // Add the object to the table
        m_cookie = rot.Register((int)ROTFlags.RegistrationKeepsAlive, graph, mk);
      }
      finally
      {
        if (mk != null)
        {
          Marshal.ReleaseComObject(mk);
          mk = null;
        }
        if (rot != null)
        {
          Marshal.ReleaseComObject(rot);
          rot = null;
        }
      }
    }
예제 #33
0
        /// <summary>
        /// Connect to existing filtergraph
        /// </summary>
        public DSGraphEditPanel(IFilterGraph filterGraph)
        {
            InitializeComponent();

            // create filter graph
            _graph = filterGraph;

            // give the filter graph to the DaggerUIGraph
            dsDaggerUIGraph1._Graph = _graph;

            // Initialize items common to all constructors
            Init();

            // get the state
            _mediaControl.GetState(100, out _mediaState);

            // match our state to the existing state
            switch (_mediaState)
            {
            case FilterState.Paused:
                Pause();
                break;

            case FilterState.Running:
                Play();
                break;

            case FilterState.Stopped:
                Stop();
                break;

            default:
                break;
            }

            dsDaggerUIGraph1.SyncGraphs(null);
            dsDaggerUIGraph1.ArrangeNodes(AutoArrangeStyle.All);

            // see if this graph has a reference clock
            IReferenceClock rc = null;

            (filterGraph as IMediaFilter).GetSyncSource(out rc);
            if (rc == null)
            {
                _useReferenceClock = false;
            }
        }
예제 #34
0
        /// <summary>
        /// Constructor from a Graph file
        /// </summary>
        /// <param name="graphFileName">Path of Graph File to load</param>
        public DSGraphEditPanel(string graphFileName)
        {
            InitializeComponent();
            int hr = 0;

            // create filter graph
            _graph = (IFilterGraph) new FilterGraph();
            _filterGraphCreated = true;

            // give the filter graph to the DaggerUIGraph
            dsDaggerUIGraph1._Graph = _graph;

            // mark it as having been created internally
            dsDaggerUIGraph1._filterGraphCreated = true;

#if DEBUG
            rot = new DsROTEntry(_graph);
#endif
            // Initialize items common to all constructors
            Init();

            // try to load the graph from IStorage
            try
            {
                hr = FilterGraphTools.LoadGraphFile(_graphBuilder, graphFileName);
                Marshal.ThrowExceptionForHR(hr);
            }
            catch (Exception ex)
            {
                // release the filtergraph and rethrow the exception
                Marshal.ReleaseComObject(_graph);
                throw ex;
            }

            // get the state
            _mediaControl.GetState(100, out _mediaState);

            // Have the graph signal event via window callbacks for performance
            _mediaEventEx = (IMediaEventEx)_graph;
            hr            = _mediaEventEx.SetNotifyWindow(this.Handle, WMGraphNotify, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            // sync the loaded graph and arrange the nodes
            dsDaggerUIGraph1.SyncGraphs(null);
            dsDaggerUIGraph1.ArrangeNodes(AutoArrangeStyle.All);
        }
예제 #35
0
        private void Cleanup()
        {
            if (fgm != null)
            {
                fgm.Stop();
                FilterGraph.RemoveAllFilters(fgm);
                FilterGraph.RemoveFromRot(rotID);

                iGB = null;
                iFG = null;
                fgm = null;
            }

            DisposeSource();
            DisposeCompressor();
            DisposeRenderer();
        }
예제 #36
0
        public static ArrayList FiltersInGraph(IFilterGraph iFG)
        {
            ArrayList ret = new ArrayList();

            IEnumFilters iEnum;
            iFG.EnumFilters(out iEnum);

            uint fetched;
            IBaseFilter iBF;
            iEnum.Next(1, out iBF, out fetched);

            while(fetched == 1)
            {
                ret.Add(iBF);
                iEnum.Next(1, out iBF, out fetched);
            }

            return ret;
        }
예제 #37
0
        protected CaptureGraph(FilterInfo fiSource)
        {
            try
            {
                // Fgm initialization
                fgm = new FilgraphManagerClass();
                iFG = (IFilterGraph)fgm;
                iGB = (IGraphBuilder)fgm;
                rotID = FilterGraph.AddToRot(iGB);

                // Create source filter and initialize it
                source = (SourceFilter)Filter.CreateFilter(fiSource);
                iGB.AddFilter(source.BaseFilter, source.FriendlyName);
                source.AddedToGraph(fgm);
            }
            catch(Exception)
            {
                Cleanup();
                throw;
            }
        }
예제 #38
0
 // Methods
 public DsROTEntry(IFilterGraph graph)
 {
     IRunningObjectTable pprot = null;
     IMoniker ppmk = null;
     try
     {
         string str;
         DsError.ThrowExceptionForHR(GetRunningObjectTable(0, out pprot));
         int id = Process.GetCurrentProcess().Id;
         IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(graph);
         try
         {
             str = iUnknownForObject.ToString("x");
         }
         catch
         {
             str = "";
         }
         finally
         {
             Marshal.Release(iUnknownForObject);
         }
         string item = string.Format("FilterGraph {0} pid {1}", str, id.ToString("x8"));
         DsError.ThrowExceptionForHR(CreateItemMoniker("!", item, out ppmk));
         this.m_cookie = pprot.Register(1, graph, ppmk);
     }
     finally
     {
         if (ppmk != null)
         {
             Marshal.ReleaseComObject(ppmk);
             ppmk = null;
         }
         if (pprot != null)
         {
             Marshal.ReleaseComObject(pprot);
             pprot = null;
         }
     }
 }
예제 #39
0
        private void CloseClip()
        {
            try
            {
                //Останавливаем таймер обновления позиции
                if (timer != null) timer.Stop();

                if (this.graphBuilder != null && this.VideoElement.Source == null)
                {
                    int hr = 0;

                    // Stop media playback
                    if (this.mediaControl != null)
                        hr = this.mediaControl.Stop();

                    // Clear global flags
                    this.currentState = PlayState.Stopped;

                    // Free DirectShow interfaces
                    CloseInterfaces();

                    this.isAudioOnly = true; //Перенесено сюда

                    if (VHost != null)
                    {
                        VHost.Dispose();
                        VHost = null;
                        VHandle = IntPtr.Zero;
                        VHostElement.Child = null;
                    }

                    // No current media state
                    this.currentState = PlayState.Init;
                }
                else if (this.VideoElement.Source != null)
                {
                    VideoElement.Stop();
                    VideoElement.Source = null;
                    this.currentState = PlayState.Init;

                    if (this.graphBuilder != null)
                    {
                        while (Marshal.ReleaseComObject(this.graphBuilder) > 0) ;
                        this.graphBuilder = null;
                        if (this.graph != null)
                        {
                            while (Marshal.ReleaseComObject(this.graph) > 0) ;
                            this.graph = null;
                        }
                        //Marshal.ReleaseComObject(this.graphBuilder);
                        //this.graphBuilder = null;
                        //Marshal.ReleaseComObject(this.graph);
                        //this.graph = null;
                        GC.Collect();
                    }

                    Thread.Sleep(100);
                    string url = "MediaBridge://MyDataString";
                    MediaBridge.MediaBridgeManager.UnregisterCallback(url);
                }
            }
            catch (Exception ex)
            {
                ErrorException("CloseClip: " + ex.Message, ex.StackTrace);
            }

            //update titles
            textbox_time.Text = "00:00:00";
            progress_top.Width = 0.0;
            slider_pos.Value = 0.0;
            in_ar = 0;
        }
예제 #40
0
		public int JoinFilterGraph(IFilterGraph graph, string name)
		{
			Console.WriteLine("JoinFilterGraph({0}, {1})", graph, name);
			//throw new NotImplementedException();
			return 0;
		}
예제 #41
0
    public int RebuildPin(IFilterGraph pGraph, IPin pPin)
    {
      //Set codec bool to false
      ResetCodecBool();

      IPin pinTo;
      if (pPin != null)
      {
        int hr = pPin.ConnectedTo(out pinTo);
        if (hr >= 0 && pinTo != null)
        {
          PinInfo pInfo;
          pinTo.QueryPinInfo(out pInfo);
          FilterInfo fInfo;
          pInfo.filter.QueryFilterInfo(out fInfo);
          if (pPin != null)
          {
            RebuildMediaType(pPin);
            Log.Debug("VideoPlayer9: Rebuild LAV Delegate Info filter Name - {0}", fInfo.achName);

            if (MediatypeVideo)
            {
              //Video Part
              if (h264Codec)
              {
                if (fInfo.achName == filterConfig.VideoH264)
                {
                  RebuildRelease(pInfo, fInfo, pinTo, pPin);
                  return 1;
                }
              }
              else if (vc1Codec)
              {
                if (fInfo.achName == filterConfig.VideoVC1)
                {
                  RebuildRelease(pInfo, fInfo, pinTo, pPin);
                  return 1;
                }
              }
              else if (vc1ICodec)
              {
                if (fInfo.achName == filterConfig.VideoVC1I)
                {
                  RebuildRelease(pInfo, fInfo, pinTo, pPin);
                  return 1;
                }
              }
              else if (xvidCodec)
              {
                if (fInfo.achName == filterConfig.VideoXVID)
                {
                  RebuildRelease(pInfo, fInfo, pinTo, pPin);
                  return 1;
                }
              }
              else if (fInfo.achName == filterConfig.Video)
              {
                RebuildRelease(pInfo, fInfo, pinTo, pPin);
                return 1;
              }
              iChangedMediaTypes = 2;
              DoGraphRebuild();
              Log.Debug("VideoPlayer9: Rebuild LAV Delegate filter Video");
              RebuildRelease(pInfo, fInfo, pinTo, pPin);
              return 1;
            }
            else if (MediatypeAudio)
            {
              //Audio Part 
              if (aacCodec)
              {
                if (fInfo.achName == filterConfig.AudioAAC)
                {
                  RebuildRelease(pInfo, fInfo, pinTo, pPin);
                  return 1;
                }
              }
              if (aacCodecLav && fInfo.achName == LAV_AUDIO)
              {
                if (fInfo.achName == filterConfig.AudioAAC)
                {
                  RebuildRelease(pInfo, fInfo, pinTo, pPin);
                  return 1;
                }
              }
              else if ((!aacCodecLav || !aacCodec) && fInfo.achName == filterConfig.Audio)
              {
                RebuildRelease(pInfo, fInfo, pinTo, pPin);
                return 1;
              }
              iChangedMediaTypes = 1;
              DoGraphRebuild();
              Log.Debug("VideoPlayer9: Rebuild LAV Delegate filter Audio");
              RebuildRelease(pInfo, fInfo, pinTo, pPin);
              return 1;
            }
            else if (MediatypeSubtitle)
            {
              RebuildRelease(pInfo, fInfo, pinTo, pPin);
              return -1;
            }
          }
          DsUtils.FreePinInfo(pInfo);
          DirectShowUtil.ReleaseComObject(fInfo.pGraph);
          DirectShowUtil.ReleaseComObject(pinTo);
          pinTo = null;
        }
        DirectShowUtil.ReleaseComObject(pPin);
        pPin = null;
      }
      Log.Debug("VideoPlayer9: Rebuild LAV Delegate (No Rebuild from MP, LAV Will doing the job)");
      return -1;
    }
 CodecConfiguration.Codec? GetCodecInfo(IFilterGraph graph, string filterName)
 {
     IBaseFilter filter;
     int hr = graph.FindFilterByName(filterName, out filter);
     CodecConfiguration.Codec? result = null;
     if (hr == 0 && filter != null)
     {
         result = GetCodecInfo(filter, filterName);
         DirectShowUtil.ReleaseComObject(filter, 2000);
     }
     return result;
 }
예제 #43
0
 private void StopAnimation()
 {
     if (isPlaying)
     {
         master.Stop();
         if (master.form != null)
         {
             master.form.Invoke((MethodInvoker)delegate()
             {
                 master.form.M_PrevSize.Enabled = true;
             });
         }
         media.Stop();
         if (eventEx != null)
         {
             eventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
             eventEx = null;
         }
         if (window != null)
         {
             window.put_Visible(OABool.False);
             window.put_Owner(IntPtr.Zero);
             window = null;
         }
         iba = null;
         imp = null;
         igb = null;
         render = null;
         media = null;
         graph = null;
         master.Stop();
         isPlaying = false;
     }
 }
예제 #44
0
        public override void Init()
        {
            if (!isPlaying)
            {
                string Filename = "";
                float size = 0;
                double Max = 0;
                int volume = 0;

                graph = new FilterGraph() as IFilterGraph;
                media = graph as IMediaControl;
                eventEx = media as IMediaEventEx;
                igb = media as IGraphBuilder;
                imp = igb as IMediaPosition;
                master.form.Invoke((MethodInvoker)delegate()
                {
                    Filename = master.form.M_Filename.Text;
                    media.RenderFile(Filename);
                    size = (float)master.form.M_PrevSize.Value;
                    master.form.M_PrevSize.Enabled = false;
                    imp.get_Duration(out Max);
                    master.form.M_Seek.Maximum = (int)(Max);
                    master.form.M_Seek.Value = 0;
                    volume = master.form.M_Volume.Value;
                    span = (uint)(1000000.0f / master.form.M_CollectFPS);
                });
                graph.FindFilterByName("Video Renderer", out render);
                if (render != null)
                {
                    window = render as IVideoWindow;
                    window.put_WindowStyle(
                        WindowStyle.Caption | WindowStyle.Child
                        );
                    window.put_WindowStyleEx(
                        WindowStyleEx.ToolWindow
                        );
                    window.put_Caption("ElectronicBoard - VideoPrev -");

                    int Width, Height, Left, Top;
                    window.get_Width(out Width);
                    window.get_Height(out Height);
                    window.get_Left(out Left);
                    window.get_Top(out Top);
                    renderSize.Width = (int)(Width * size);
                    renderSize.Height = (int)(Height * size);
                    Aspect = (float)renderSize.Height / (float)renderSize.Width;
                    window.SetWindowPosition(Left, Top, renderSize.Width, renderSize.Height);

                    eventEx = media as IMediaEventEx;
                    eventEx.SetNotifyWindow(master.form.Handle, WM_DirectShow, IntPtr.Zero);
                    media.Run();
                    foreach (Process p in Process.GetProcesses())
                    {
                        if (p.MainWindowTitle == "ElectronicBoard - VideoPrev -")
                        {
                            renderwindow = p.MainWindowHandle;
                            break;
                        }
                    }
                    isPlaying = true;
                    iba = media as IBasicAudio;
                    iba.put_Volume(volume);

                    //master.form.checkBox3_CheckedChanged(null, null);
                    master.Start();
                }
            }
        }
예제 #45
0
    ClipEntry Copy(ClipEntry r)
    {
        m_tOffset = r.m_tOffset;
        m_pGraph = r.m_pGraph;
        m_pSinkFilter = r.m_pSinkFilter;
        m_strName = r.m_strName;
        m_tStart = r.m_tStart;
        m_tStop = r.m_tStop;
        m_bPrimed = r.m_bPrimed;

        return this;
    }
예제 #46
0
        protected CaptureGraph(FilterInfo fiSource)
        {
            try
            {
                // Fgm initialization
                fgm = new FilgraphManagerClass();
                iFG = (IFilterGraph)fgm;
                iGB = (IGraphBuilder)fgm;
                rotID = FilterGraph.AddToRot(iGB);

                // Create source filter and initialize it
                source = (SourceFilter)Filter.CreateFilter(fiSource);
                iGB.AddFilter(source.BaseFilter, source.FriendlyName);
                source.AddedToGraph(fgm);

                // Pass flags to the RtpRenderer filter from the config file.
                this.rtpRendererFlags = 0;
                string setting = ConfigurationManager.AppSettings[AppConfig.MDS_RtpRendererFlags];
                if (!String.IsNullOrEmpty(setting)) {
                    if (!byte.TryParse(setting,out rtpRendererFlags)) {
                        rtpRendererFlags = 0;
                    }
                }
            }
            catch(Exception)
            {
                Cleanup();
                throw;
            }
        }
예제 #47
0
        private void BridgeCallback(MediaBridgeGraphInfo GraphInfo)
        {
            try
            {
                this.graph = (IFilterGraph) Marshal.GetObjectForIUnknown(GraphInfo.FilterGraph);
                this.graphBuilder = (IGraphBuilder) this.graph;
                DsError.ThrowExceptionForHR(this.graphBuilder.RenderFile(this.filepath, null));

                AddFiltersToMenu();
            }
            catch (Exception ex)
            {
                this.CloseClip();
                this.filepath = string.Empty;
                Win7Taskbar.SetProgressTaskComplete(this.Handle, TBPF.ERROR);
                System.Windows.MessageBox.Show("BridgeCallback: " + ex.Message, Languages.Translate("Error"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
예제 #48
0
        private void BridgeCallback(MediaBridge.MediaBridgeGraphInfo GraphInfo)
        {
            try
            {
                int hr = 0;

                //Convert pointer of filter graph to an object we can use
                graph = (IFilterGraph)Marshal.GetObjectForIUnknown(GraphInfo.FilterGraph);
                graphBuilder = (IGraphBuilder)graph;

                hr = graphBuilder.RenderFile(filepath, null);
                DsError.ThrowExceptionForHR(hr);
            }
            catch (Exception ex)
            {
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)delegate()
                {
                    ErrorException("BridgeCallback: " + ex.Message, ex.StackTrace);
                    PreviewError(Languages.Translate("Error") + "...", Brushes.Red);
                });
            }
        }
예제 #49
0
        private void CloseClip()
        {
            try
            {
                //Останавливаем таймер обновления позиции
                if (timer != null) timer.Stop();

                //DirectShow
                if (this.graphBuilder != null && this.VideoElement.Source == null)
                {
                    int hr = 0;

                    // Stop media playback
                    if (this.mediaControl != null)
                        hr = this.mediaControl.Stop();

                    // Free DirectShow interfaces
                    CloseInterfaces();

                    //EVR
                    if (VHost != null)
                    {
                        VHost.Dispose();
                        VHost = null;
                        VHandle = IntPtr.Zero;
                        VHostElement.Child = null;
                        VHostElement.Visibility = Visibility.Collapsed;
                        VHostElement.Width = VHostElement.Height = 0;
                        VHostElement.Margin = new Thickness(0);
                    }

                    // No current media state
                    if (mediaload != MediaLoad.update)
                        this.currentState = PlayState.Init;
                }

                //MediaBridge
                if (this.VideoElement.Source != null)
                {
                    VideoElement.Stop();
                    VideoElement.Close();
                    VideoElement.Source = null;
                    VideoElement.Visibility = Visibility.Collapsed;
                    VideoElement.Width = VideoElement.Height = 0;
                    VideoElement.Margin = new Thickness(0);

                    if (mediaload != MediaLoad.update)
                        this.currentState = PlayState.Init;

                    if (this.graphBuilder != null)
                    {
                        while (Marshal.ReleaseComObject(this.graphBuilder) > 0) ;
                        this.graphBuilder = null;
                        if (this.graph != null)
                        {
                            while (Marshal.ReleaseComObject(this.graph) > 0) ;
                            this.graph = null;
                        }
                        //Marshal.ReleaseComObject(this.graphBuilder);
                        //this.graphBuilder = null;
                        //Marshal.ReleaseComObject(this.graph);
                        //this.graph = null;
                        GC.Collect();
                    }

                    Thread.Sleep(100);
                    string url = "MediaBridge://MyDataString";
                    MediaBridge.MediaBridgeManager.UnregisterCallback(url);
                }

                //ScriptView
                if (script_box.Visibility != Visibility.Collapsed)
                {
                    script_box.Clear();
                    script_box.Visibility = Visibility.Collapsed;
                    this.currentState = PlayState.Init;
                }

                //AviSynthPlayer (PictureView)
                if (avsPlayer != null)
                {
                    avsPlayer.Abort();
                    avsPlayer.Close();
                    avsPlayer = null;

                    Pic.Source = null;
                    Pic.Visibility = Visibility.Collapsed;
                    Pic.Margin = new Thickness(0);
                    Pic.Width = Pic.Height = 0;

                    if (mediaload != MediaLoad.update)
                        this.currentState = PlayState.Init;
                }

                //Окно ошибок
                if (ErrBox.Visibility != Visibility.Collapsed)
                {
                    ErrBox.Child = null;
                    ErrBox.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                ErrorException("CloseClip: " + ex.Message, ex.StackTrace);
            }

            //update titles
            textbox_name.Text = textbox_frame.Text = "";
            textbox_time.Text = textbox_duration.Text = "00:00:00";
            progress_top.Width = slider_pos.Value = 0.0;

            SetPlayIcon();
        }
예제 #50
0
        public static string Debug(IFilterGraph iFG)
        {
            string ret = "\r\nFilters in graph\r\n";

            foreach(IBaseFilter iBF in FiltersInGraph(iFG))
            {
                ret += string.Format("\t{0}\r\n", Filter.Name(iBF));
            }

            return ret;
        }
예제 #51
0
    public int Create(IGMFBridgeController pController, string path)
    {
        m_bPrimed = false;

        m_pGraph = new FilterGraph() as IGraphBuilder;
        int hr = pController.CreateSourceGraph(path, m_pGraph, out m_pSinkFilter);

        m_strName = path.Substring(path.LastIndexOf('\\')+1);

        if (hr < 0)
        {
            if (m_pGraph != null)
            {
                Marshal.ReleaseComObject(m_pGraph);
                m_pGraph = null;
            }
        }

        return hr;
    }
예제 #52
0
 int IBaseFilter.JoinFilterGraph(IFilterGraph pGraph, string pName)
 {
     if ((filterGraph = pGraph) == null)
         name = "Stream Source Filter";
     else
         name = pName;
     return S_OK;
 }
예제 #53
0
        private void CloseClip()
        {
            if (!Application.Current.Dispatcher.CheckAccess())
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new CloseClipDelegate(CloseClip));
            else
            {
                try
                {
                    //Останавливаем таймер обновления позиции
                    if (timer != null) timer.Stop();

                    if ((this.graphBuilder != null) && (this.VideoElement.Source == null))
                    {
                        if (this.mediaControl != null)
                            this.mediaControl.Stop();

                        this.CloseInterfaces();
                        this.isAudioOnly = true;

                        if (VHost != null)
                        {
                            VHost.Dispose();
                            VHost = null;
                            VHandle = IntPtr.Zero;
                            VHostElement.Child = null;
                            VHostElement.Visibility = Visibility.Collapsed;
                        }
                    }
                    if (this.VideoElement.Source != null)
                    {
                        VideoElement.Stop();
                        VideoElement.Close();
                        VideoElement.Source = null;
                        VideoElement.Visibility = Visibility.Collapsed;
                        if (this.graphBuilder != null)
                        {
                            while (Marshal.ReleaseComObject(this.graphBuilder) > 0) ;
                            this.graphBuilder = null;

                            if (this.graph != null)
                            {
                                while (Marshal.ReleaseComObject(this.graph) > 0) ;
                                this.graph = null;
                            }
                            GC.Collect();
                        }
                        string mediaUrl = "MediaBridge://MyDataString";
                        MediaBridgeManager.UnregisterCallback(mediaUrl);
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.MessageBox.Show("CloseClip: " + ex.Message, Languages.Translate("Error"), MessageBoxButton.OK, MessageBoxImage.Error);
                }

                SetPlayIcon();
                ClearFiltersMenu();

                this.Title = "WPF Video Player";
                this.currentState = PlayState.Init;
                this.textbox_time.Text = textbox_duration.Text = "00:00:00";
                this.slider_pos.Value = 0.0;

                Win7Taskbar.SetProgressState(this.Handle, TBPF.NOPROGRESS);
            }
        }
예제 #54
0
파일: BaseClasses.cs 프로젝트: ORRNY66/GS
        /// <summary>
        /// Resets the local graph resources to their
        /// default settings
        /// </summary>
        private void ResetLocalGraphResources()
        {
            m_graph = null;

            if (m_basicAudio != null)
                Marshal.ReleaseComObject(m_basicAudio);
            m_basicAudio = null;

            if (m_mediaControl != null)
                Marshal.ReleaseComObject(m_mediaControl);
            m_mediaControl = null;

            if(m_mediaEvent != null)
                Marshal.ReleaseComObject(m_mediaEvent);
            m_mediaEvent = null;
        }
예제 #55
0
        private void Cleanup()
        {
            if(fgm != null)
            {
                fgm.Stop();
                FilterGraph.RemoveAllFilters(fgm);
                FilterGraph.RemoveFromRot(rotID);

                iGB = null;
                iFG = null;
                fgm = null;
            }

            DisposeSource();
            DisposeCompressor();
            DisposeRenderer();
        }
예제 #56
0
        private void BridgeCallback(MediaBridge.MediaBridgeGraphInfo GraphInfo)
        {
            try
            {
                int hr = 0;

                //Convert pointer of filter graph to an object we can use
                graph = (IFilterGraph)Marshal.GetObjectForIUnknown(GraphInfo.FilterGraph);
                graphBuilder = (IGraphBuilder)graph;

                hr = graphBuilder.RenderFile(filepath, null);
                DsError.ThrowExceptionForHR(hr);
            }
            catch (Exception ex)
            {
                ErrorException("BridgeCallback: " + ex.Message, ex.StackTrace);
            }
        }
예제 #57
0
        /// <summary>
        /// Configures all general DirectShow interfaces that the
        /// FilterGraph supplies.
        /// </summary>
        /// <param name="graph">The FilterGraph to setup</param>
        protected virtual void SetupFilterGraph(IFilterGraph graph)
        {
            m_graph = graph;

            /* Setup the interfaces and query basic information
             * on the graph that is passed */
            SetVideoDimensions(m_graph as IBasicVideo);
            SetBasicAudioInterface(m_graph as IBasicAudio);
            SetMediaControlInterface(m_graph as IMediaControl);
            SetMediaEventExInterface(m_graph as IMediaEventEx);
        }
예제 #58
0
    public void Dispose()
    {
        GC.SuppressFinalize(this);

        if (m_pGraph != null)
        {
            IMediaControl pMC = m_pGraph as IMediaControl;
            pMC.Stop();

            Marshal.ReleaseComObject(m_pGraph);
            m_pGraph = null;
        }

        if (m_pSinkFilter != null)
        {
            Marshal.ReleaseComObject(m_pSinkFilter);
            m_pSinkFilter = null;
        }
    }
 /// <summary>
 /// This method is overriden to get out the seeking
 /// interfaces from the DirectShow graph
 /// </summary>
 protected override void SetupFilterGraph(IFilterGraph graph)
 {
     SetMediaSeekingInterface(graph as IMediaSeeking);
     base.SetupFilterGraph(graph);
 }
예제 #60
0
 public ClipEntry(ClipEntry r)
 {
     m_tOffset = r.m_tOffset;
     m_pGraph = r.m_pGraph;
     m_pSinkFilter = r.m_pSinkFilter;
     m_strName = r.m_strName;
     m_tStart = r.m_tStart;
     m_tStop = r.m_tStop;
     m_bPrimed = r.m_bPrimed;
 }