Ejemplo n.º 1
2
        private void BuildGraph(string fileName)
        {
            int hr = 0;

             try
             {
                 graphBuilder = (IFilterGraph2)new FilterGraph();
                 mediaControl = (IMediaControl)graphBuilder;

                 mediaSeeking = (IMediaSeeking)graphBuilder;
                 mediaPosition = (IMediaPosition)graphBuilder;

                 vmr9 = (IBaseFilter)new VideoMixingRenderer9();

                 ConfigureVMR9InWindowlessMode();

                 hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
                 DsError.ThrowExceptionForHR(hr);

                 hr = graphBuilder.RenderFile(fileName, null);
                 DsError.ThrowExceptionForHR(hr);
             }
             catch (Exception e)
             {
                 CloseInterfaces();
                 MessageBox.Show("An error occured during the graph building : \r\n\r\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
        }
Ejemplo n.º 2
0
        int AddSourceFilter(Uri uri, IFilterGraph2 filterGraph, out IBaseFilter sourceFilter)
        {
            sourceFilter = null;
            string protocol = uri.Scheme.Substring(0, Math.Min(uri.Scheme.Length, 4));

            switch (protocol)
            {
            case "http":
            case "rtmp":
                sourceFilter = DShowNET.Helper.FilterFromFile.LoadFilterFromDll(@"MPUrlSourceSplitter\MPUrlSourceSplitter.ax", new Guid(OnlineVideos.MPUrlSourceFilter.Downloader.FilterCLSID), true);
                return(filterGraph.AddFilter(sourceFilter, OnlineVideos.MPUrlSourceFilter.Downloader.FilterName));

            case "sop":
                sourceFilter = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("{A895A82C-7335-4D6B-A811-82E9E3C4403E}"))) as IBaseFilter;
                return(filterGraph.AddFilter(sourceFilter, "SopCast ASF Splitter"));

            case "mms":
                sourceFilter = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("{187463A0-5BB7-11D3-ACBE-0080C75E246E}"))) as IBaseFilter;
                return(filterGraph.AddFilter(sourceFilter, "WM ASF Reader"));

            case "file":
                sourceFilter = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("{E436EBB5-524F-11CE-9F53-0020AF0BA770}"))) as IBaseFilter;
                return(filterGraph.AddFilter(sourceFilter, "File Source (Async.)"));
            }
            return(-1);
        }
Ejemplo n.º 3
0
        void BuildGraph()
        {
            int                   hr;
            IBaseFilter           ppbf, ppFilter;
            ICaptureGraphBuilder2 icgb2;

            DsDevice [] devs;

            IGraphBuilder graphBuilder = new FilterGraph() as IGraphBuilder;

            icgb2 = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            icgb2.SetFiltergraph(graphBuilder);

            DsROTEntry    ds   = new DsROTEntry(graphBuilder);
            IFilterGraph2 ifg2 = graphBuilder as IFilterGraph2;

            devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            DsDevice dev = devs[0];

            hr = ifg2.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out ppFilter);
            DsError.ThrowExceptionForHR(hr);

            // Use the ICaptureGraphBuilder2 to add the avi mux
            hr = icgb2.SetOutputFileName(MediaSubType.Avi, FileName, out ppbf, out m_ppsink);
            DsError.ThrowExceptionForHR(hr);

            hr = icgb2.RenderStream(PinCategory.Capture, MediaType.Video, ppFilter, null, ppbf);
            DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            int hr;

            if (tbFileName.Enabled)
            {
                BuildGraph(tbFileName.Text, rbLeft.Checked);

                // Run this graph
                hr = (graphBuilder as IMediaControl).Run();
                DsError.ThrowExceptionForHR(hr);
                tbFileName.Enabled = false;
                groupBox1.Enabled  = false;
                btnStart.Text      = "Stop";
            }
            else
            {
                hr = (graphBuilder as IMediaControl).Stop();
                groupBox1.Enabled  = true;
                tbFileName.Enabled = true;
                Marshal.ReleaseComObject(graphBuilder);
                graphBuilder  = null;
                btnStart.Text = "Start";
            }
        }
Ejemplo n.º 5
0
        // Shut down capture
        public void CloseInterfaces()
        {
            int hr;

            IsOnDeleting = true;
            lock (this)
            {
                if (m_State != GraphState.Exiting)
                {
                    m_State = GraphState.Exiting;

                    // Release the thread (if the thread was started)
                    if (m_mre != null)
                    {
                        m_mre.Set();
                    }
                }



                if (m_mediaCtrl != null)
                {
                    // Stop the graph
                    hr          = m_mediaCtrl.Stop();
                    m_mediaCtrl = null;
                }

                if (m_mediaSeeking != null)
                {
                    Marshal.ReleaseComObject(m_mediaSeeking);
                    m_mediaSeeking = null;
                }
                if (m_sampGrabber != null)
                {
                    Marshal.ReleaseComObject(m_sampGrabber);
                    m_sampGrabber = null;
                }

#if DEBUG
                if (m_DsRot != null)
                {
                    m_DsRot.Dispose();
                }
#endif

                if (m_FilterGraph != null)
                {
                    try
                    {
                        Marshal.ReleaseComObject(m_FilterGraph);
                    }
                    catch { }
                    finally
                    {
                        m_FilterGraph = null;
                    }
                }
            }
            GC.Collect();
        }
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if (m_FilterGraph != null)
                {
                    IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;
                    // Stop the graph
                    hr = mediaCtrl.Stop();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            if (m_FilterGraph != null)
            {
                Marshal.ReleaseComObject(m_FilterGraph);
                m_FilterGraph = null;
            }
            if (m_VidControl != null)
            {
                Marshal.ReleaseComObject(m_VidControl);
                m_VidControl = null;
            }
            if (m_pinStill != null)
            {
                Marshal.ReleaseComObject(m_pinStill);
                m_pinStill = null;
            }
        }
Ejemplo n.º 7
0
        public static void AddTransportStreamFiltersToGraph(IFilterGraph2 graphBuilder, out IBaseFilter bdaTIF, out IBaseFilter bdaSecTab)
        {
            int hr = 0;

            DsDevice[] devices;

            bdaTIF    = null;
            bdaSecTab = null;

            devices = DsDevice.GetDevicesOfCat(FilterCategory.BDATransportInformationRenderersCategory);
            for (int i = 0; i < devices.Length; i++)
            {
                if (devices[i].Name.Equals("BDA MPEG2 Transport Information Filter"))
                {
                    hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out bdaTIF);
                    DsError.ThrowExceptionForHR(hr);
                    continue;
                }

                if (devices[i].Name.Equals("MPEG-2 Sections and Tables"))
                {
                    hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out bdaSecTab);
                    DsError.ThrowExceptionForHR(hr);
                    continue;
                }
            }
        }
        public void BuildGraph()
        {
            int hr = 0;

            graphBuilder = (IFilterGraph2) new FilterGraph();

            rot = new DsROTEntry(graphBuilder);

            vmr9 = (IBaseFilter) new VideoMixingRenderer9();

            IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)vmr9;

            hr = filterConfig.SetNumberOfStreams(2);
            DsError.ThrowExceptionForHR(hr);

            // Put the VMR9 in Renderless mode
            hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            DsError.ThrowExceptionForHR(hr);

            surfaceAllocatorNotify = (IVMRSurfaceAllocatorNotify9)vmr9;

            // Advise to VMR9 of our custom Allocator / Presenter
            hr = surfaceAllocatorNotify.AdviseSurfaceAllocator(cookie, this);
            DsError.ThrowExceptionForHR(hr);

            // Advise our custom Allocator / Presenter of the VMR9
            hr = this.AdviseNotify(surfaceAllocatorNotify);
            DsError.ThrowExceptionForHR(hr);

            hr = graphBuilder.AddFilter(vmr9, "VMR9");
            DsError.ThrowExceptionForHR(hr);

            hr = graphBuilder.RenderFile(@"..\..\..\Resources\foo.avi", null);
            DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 9
0
        void BuildGraph()
        {
            int         hr;
            IBaseFilter ppFilter;

            DsDevice []   devs;
            IGraphBuilder graphBuilder = new FilterGraph() as IGraphBuilder;

            m_ROT = new DsROTEntry(graphBuilder);
            IFilterGraph2 ifg2 = graphBuilder as IFilterGraph2;

            devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            DsDevice dev = devs[0];

            hr = ifg2.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out ppFilter);
            DsError.ThrowExceptionForHR(hr);

            ICaptureGraphBuilder2 captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            hr = captureGraphBuilder.SetFiltergraph(graphBuilder);

            object o;

            hr = captureGraphBuilder.FindInterface(null, null, ppFilter, typeof(IAMStreamConfig).GUID, out o);
            DsError.ThrowExceptionForHR(hr);

            m_asc = o as IAMStreamConfig;

            //m_imc = graphBuilder as IMediaControl;
            //hr = m_imc.Run();
            //DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 10
0
        private void Shutdown()
        {
            int hr = 0;

            // Remove the ROT entry
            if (rot != null)
            {
                rot.Dispose();
            }

            if (graphBuilder != null)
            {
                // Stop DirectShow notifications
                hr = (graphBuilder as IMediaEventEx).SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);

                // Stop the graph
                hr = (graphBuilder as IMediaControl).StopWhenReady();
                hr = (graphBuilder as IMediaControl).Stop();

                // Dispose the allocator
                allocator.Dispose();

                // Release DirectShow objects
                Marshal.ReleaseComObject(vmr9);
                Marshal.ReleaseComObject(graphBuilder);
                graphBuilder = null;

                FreeResources();

                // Free the Managed Direct3D device
                device.Dispose();
            }
        }
Ejemplo n.º 11
0
        private void BuildGraph(string sFileName, out IFilterGraph2 graphBuilder, out IBaseFilter audioFilter)
        {
            int         hr           = 0;
            IBaseFilter sourceFilter = null;
            IPin        pinOut       = null;

            graphBuilder = new FilterGraph() as IFilterGraph2;
            audioFilter  = null;

            try
            {
                hr = graphBuilder.AddSourceFilter(sFileName, sFileName, out sourceFilter);
                Marshal.ThrowExceptionForHR(hr);

                audioFilter = (IBaseFilter) new DSoundRender();
                hr          = graphBuilder.AddFilter(audioFilter, "DirectSound Renderer");

                pinOut = DsFindPin.ByDirection(sourceFilter, PinDirection.Output, 0);

                hr = graphBuilder.RenderEx(pinOut, AMRenderExFlags.RenderToExistingRenderers, IntPtr.Zero);
                Marshal.ThrowExceptionForHR(hr);
            }
            catch
            {
                Marshal.ReleaseComObject(graphBuilder);
                throw;
            }
            finally
            {
                Marshal.ReleaseComObject(sourceFilter);
                Marshal.ReleaseComObject(pinOut);
            }
        }
        private void Configure2()
        {
            int         hr;
            IBaseFilter pFilter;
            IBaseFilter ibf;

            ICaptureGraphBuilder2 icgb        = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            IFilterGraph2         FilterGraph = (IFilterGraph2) new FilterGraph();
            DsROTEntry            ds          = new DsROTEntry(FilterGraph);

            hr = icgb.SetFiltergraph(FilterGraph);
            DsError.ThrowExceptionForHR(hr);

            hr = FilterGraph.AddSourceFilter(FileName, "foo", out pFilter);
            DsError.ThrowExceptionForHR(hr);

            hr = icgb.RenderStream(null, null, pFilter, null, null);
            DsError.ThrowExceptionForHR(hr);

            hr = FilterGraph.FindFilterByName("AVI Splitter", out ibf);
            DsError.ThrowExceptionForHR(hr);

            m_pPersist2 = (IPersistMediaPropertyBag)ibf;

            Marshal.ReleaseComObject(pFilter);
            Marshal.ReleaseComObject(icgb);
        }
Ejemplo n.º 13
0
        private void SetupGraph(Control hWin)
        {
            //streamSource = new UdpSource("127.0.0.1", 2001);
            streamSource = new UdpSource("224.0.0.1", 2002);
            //streamSource = new Core.Sources.FileSource("test.ts");

            streamSource.PacketLength = Constants.TSPacketSize;
            streamSource.SearchMethod = TSUtils.TSPacketSearch;

            streamSource.Configure();

            if (!streamSource.Require(10))
            {
                throw new Exception("Source is not ready. No data is received.");
            }

            Log.Info("Identify the A/V streams");
            var streamInfo = new TStreamInfo(streamSource);

            streamInfo.Configure();

            streamSource.Reset();

            filterGraph = new FilterGraph() as IFilterGraph2;
            Ensure.IsNotNull(Log, filterGraph, "graph is null");
            if (filterGraph == null)
            {
                return;
            }

            var pVideoRender = (IBaseFilter) new VideoRendererDefault();
            var hr           = filterGraph.AddFilter(pVideoRender, "Video Renderer");

            DsError.ThrowExceptionForHR(hr);

            var pAudioRender = (IBaseFilter) new DSoundRender();

            hr = filterGraph.AddFilter(pAudioRender, "Audio Render");
            DsError.ThrowExceptionForHR(hr);

            Log.Info("Configure the directshow graph.");
            configurator = new GraphConfigurator
            {
                Source       = streamSource,
                StreamInfo   = streamInfo,
                Graph        = filterGraph,
                VideoRender  = pVideoRender,
                AudioRender  = pAudioRender,
                VideoGrabber = null,
                AudioGrabber = null
            };

            configurator.Configure();

            var videoWindow = pVideoRender as IVideoWindow;

            ConfigureVideoWindow(videoWindow, hWin);

            this.mediaControl = this.filterGraph as IMediaControl;
        }
Ejemplo n.º 14
0
        private void Close()
        {
            lock (lockObject)
            {
                if (streamSource != null)
                {
                    streamSource.Dispose();
                    streamSource = null;
                }

                if (this.configurator != null)
                {
                    this.configurator.Dispose();
                    this.configurator = null;
                }

                if (this.mediaControl != null)
                {
                    this.mediaControl.Stop();
                    this.mediaControl = null;
                }

                if (this.filterGraph != null)
                {
                    ((IMediaEventSink)this.filterGraph).Notify(EventCode.UserAbort, IntPtr.Zero, IntPtr.Zero);

                    Marshal.ReleaseComObject(this.filterGraph);
                    this.filterGraph = null;
                }
            }

            GC.Collect();
        }
Ejemplo n.º 15
0
        private void BuildGraph(string fileName)
        {
            int hr = 0;

            try
            {
                graphBuilder = (IFilterGraph2) new FilterGraph();
                mediaControl = (IMediaControl)graphBuilder;

                mediaSeeking  = (IMediaSeeking)graphBuilder;
                mediaPosition = (IMediaPosition)graphBuilder;


                vmr9 = (IBaseFilter) new VideoMixingRenderer9();

                ConfigureVMR9InWindowlessMode();

                hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
                DsError.ThrowExceptionForHR(hr);

                hr = graphBuilder.RenderFile(fileName, null);
                DsError.ThrowExceptionForHR(hr);
            }
            catch (Exception e)
            {
                CloseInterfaces();
                MessageBox.Show("An error occured during the graph building : \r\n\r\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 16
0
        private void Configure()
        {
            int         hr;
            IBaseFilter pFilter;
            IBaseFilter pRender = (IBaseFilter) new VideoRendererDefault();

            ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            m_FilterGraph = (IFilterGraph2) new FilterGraph();
            DsROTEntry ds = new DsROTEntry(m_FilterGraph);

            hr = icgb.SetFiltergraph(m_FilterGraph);
            DsError.ThrowExceptionForHR(hr);

            DsDevice [] devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            hr = m_FilterGraph.AddSourceFilterForMoniker(devs[0].Mon, null, devs[0].Name, out pFilter);
            DsError.ThrowExceptionForHR(hr);

            hr = m_FilterGraph.AddFilter(pRender, "renderererer");
            DsError.ThrowExceptionForHR(hr);

            hr = icgb.RenderStream(null, null, pFilter, null, pRender);
            DsError.ThrowExceptionForHR(hr);

            m_fmf1 = (IAMFilterMiscFlags)pRender;
            m_fmf2 = (IAMFilterMiscFlags)pFilter;

            Marshal.ReleaseComObject(icgb);
        }
Ejemplo n.º 17
0
        private void Configure()
        {
            // In order to lock a profile, you have to have at least one stream
            // connected to the sink. I connect a video thru the DVVideoEnc into
            // the StreamBufferSink.
            int hr;

            m_pRender = (IBaseFilter) new VideoRendererDefault();

            ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            m_FilterGraph = (IFilterGraph2) new FilterGraph();
            DsROTEntry ds = new DsROTEntry(m_FilterGraph);

            hr = icgb.SetFiltergraph(m_FilterGraph);
            DsError.ThrowExceptionForHR(hr);

            DsDevice [] devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            hr = m_FilterGraph.AddSourceFilterForMoniker(devs[0].Mon, null, devs[0].Name, out m_pFilter);
            DsError.ThrowExceptionForHR(hr);

            hr = m_FilterGraph.AddFilter(m_pRender, "renderererer");
            DsError.ThrowExceptionForHR(hr);

            hr = icgb.RenderStream(null, null, m_pFilter, null, m_pRender);
            DsError.ThrowExceptionForHR(hr);

            m_fc = (IFilterChain)m_FilterGraph;

            Marshal.ReleaseComObject(icgb);
        }
Ejemplo n.º 18
0
        public void SetupVideoStream(IFilterGraph2 builder, IBaseFilter capfiler, IBaseFilter renderer, Control target)
        {
            //串接後面的Filters 的 Pins
            //目前不做畫面擷取所以也不需要用SmartTee來分流
            IPin pin_out = null;
            IPin pin_in  = null;

            //==== Streaming Circuit ====
            try
            {
                //Win7開始預設最好是使用 VideoMixingRenderer7,當然能用VideoMixingRenderer9更好
                //原始的VideoRenderer吃不到顯卡的特殊能力
                //renderer = (IBaseFilter)new VideoMixingRenderer9();
                SetupRenderWindow((IVMRFilterConfig9)renderer, target);
                builder.AddFilter(renderer, "Video Mixing Renderer 9");
                pin_in = DsFindPin.ByDirection(renderer, PinDirection.Input, 0);

                //裝好Filter以後,在Capture Device找出對應的pin腳然後接上去...
                //就像焊接電路一樣的觀念
                pin_out = DsFindPin.ByCategory(capfiler, PinCategory.Capture, 0);
                builder.Connect(pin_out, pin_in);
            }
            finally
            {
                //todo: 這邊應該弄Dispose不應該直接叫 Marshal
                if (null != pin_out)
                {
                    Marshal.ReleaseComObject(pin_out);
                }
                if (null != pin_in)
                {
                    Marshal.ReleaseComObject(pin_in);
                }
            }
        }
        private void BuildGraph()
        {
            int hr = 0;

            graphBuilder = (IFilterGraph2) new FilterGraph();
            vmr          = (IBaseFilter) new VideoMixingRenderer();

            hr = graphBuilder.AddFilter(vmr, "VMR");
            DsError.ThrowExceptionForHR(hr);

            hr = (vmr as IVMRFilterConfig).SetNumberOfStreams(1);
            DsError.ThrowExceptionForHR(hr);

            IPin pinIn = DsFindPin.ByDirection(vmr, PinDirection.Input, 0);

            streamControl = (IVMRVideoStreamControl)pinIn;

            hr = graphBuilder.RenderFile(@"..\..\..\Resources\foo.avi", null);
            DsError.ThrowExceptionForHR(hr);

            rot = new DsROTEntry(graphBuilder);

            // Run the graph to really connect VMR pins.
            // This sample doesn't work if the graph has not been run at least one time
            hr = (graphBuilder as IMediaControl).Run();
            DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 20
0
 private static bool ConnectFilter(IFilterGraph2 graphBuilder, IBaseFilter networkFilter, IBaseFilter tunerFilter)
 {
   IPin pinOut = DsFindPin.ByDirection(networkFilter, PinDirection.Output, 0);
   IPin pinIn = DsFindPin.ByDirection(tunerFilter, PinDirection.Input, 0);
   int hr = graphBuilder.Connect(pinOut, pinIn);
   return (hr == 0);
 }
Ejemplo n.º 21
0
        public static void AddNetworkFiltersToGraph(IFilterGraph2 graphBuilder, out IBaseFilter bdaMPE, out IBaseFilter bdaIPSink)
        {
            int hr = 0;

            DsDevice[] devices;

            bdaMPE    = null;
            bdaIPSink = null;

            devices = DsDevice.GetDevicesOfCat(FilterCategory.BDAReceiverComponentsCategory);
            foreach (DsDevice device in devices)
            {
                if (device.Name.IndexOf("BDA MPE") != -1)
                {
                    hr = graphBuilder.AddSourceFilterForMoniker(device.Mon, null, "BDA MPE Filter", out bdaMPE);
                    DsError.ThrowExceptionForHR(hr);
                    break;
                }
            }

            devices = DsDevice.GetDevicesOfCat(FilterCategory.BDARenderingFiltersCategory);
            foreach (DsDevice device in devices)
            {
                if (device.Name.Equals("BDA IP Sink"))
                {
                    hr = graphBuilder.AddSourceFilterForMoniker(device.Mon, null, "BDA IP Sink", out bdaIPSink);
                    DsError.ThrowExceptionForHR(hr);
                    break;
                }
            }
        }
Ejemplo n.º 22
0
        void BuildGraph()
        {
            int         hr;
            IBaseFilter ppFilter;

            DsDevice []   devs;
            IGraphBuilder graphBuilder = new FilterGraph() as IGraphBuilder;

            m_ROT = new DsROTEntry(graphBuilder);
            IFilterGraph2 ifg2 = graphBuilder as IFilterGraph2;

            devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            DsDevice dev = devs[0];

            hr = ifg2.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out ppFilter);
            DsError.ThrowExceptionForHR(hr);

            m_idf = ppFilter as IAMDroppedFrames;

            IPin IPinOut = DsFindPin.ByDirection(ppFilter, PinDirection.Output, 0);

            hr = ifg2.Render(IPinOut);
            DsError.ThrowExceptionForHR(hr);

            m_imc = graphBuilder as IMediaControl;
            hr    = m_imc.Run();
            DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 23
0
        public PlayerCore(string file)
        {
            graphBuilder = (new FilterGraph()) as IFilterGraph2;
            if (graphBuilder == null) return;
            mediaControl = graphBuilder as IMediaControl;
            mediaSeeking = graphBuilder as IMediaSeeking;
            audioControl = graphBuilder as IBasicAudio;
            if (mediaControl == null || mediaSeeking == null || audioControl == null) return;
            //int hr = mediaControl.RenderFile(file);
            FileInfo info = new FileInfo(file);
            ISupport support = Supports.Instance[info.Extension];
            int hr = -1;
            if (support != null)
                hr = support.RenderGraph(graphBuilder, file);
            else
                hr = mediaControl.RenderFile(file);

            fileName = file;
            if (hr != 0) errorStack.Push(hr);
            if (hr != 0) return;
            mediaSeeking.SetTimeFormat(TimeFormat.MediaTime);
            isValidate = true;
            window = graphBuilder as IVideoWindow;
            if (window != null)
            {
                int width = 0;
                int height = 0;
                window.get_Width(out width);
                window.get_Height(out height);
                nativeSize = new Size(width, height);
            }
        }
Ejemplo n.º 24
0
        public void CloseInterfaces()
        {
            if (mediaControl != null)
            {
                int hr = mediaControl.StopWhenReady();
                DsError.ThrowExceptionForHR(hr);
            }

            if (videoWindow != null)
            {
                videoWindow.put_Visible(OABool.False);
                videoWindow.put_Owner(IntPtr.Zero);
            }

            // Remove filter graph from the running object table.
            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }

            // Release DirectShow interfaces.
            Marshal.ReleaseComObject(this.mediaControl); this.mediaControl = null;
            Marshal.ReleaseComObject(this.videoWindow); this.videoWindow   = null;
            Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;
            Marshal.ReleaseComObject(this.captureGraphBuilder); this.captureGraphBuilder = null;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// This constructor internally build a DirectShow graph using the given file name parameter.
        /// </summary>
        /// <param name="filename">A media file.</param>
        /// <remarks>This constructor use the BlackListManager class to bane the use of the ffdshow Audio and Video decoders during the Intelligent Connect graph building.</remarks>
        public SimplePlayer(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            throw new ArgumentNullException("filename");

              if (!File.Exists(filename))
            throw new FileNotFoundException();

              this.graphBuilder = (IFilterGraph2)new FilterGraph();

            #if DEBUG
              this.rot = new DsROTEntry(this.graphBuilder);
            #endif

              this.blackListManager = new BlackListManager(this.graphBuilder);

              // blacklist the ffdshow Audio Decoder filter
              this.blackListManager.AddBlackListedFilter(new Guid("0F40E1E5-4F79-4988-B1A9-CC98794E6B55"));
              // blacklist the ffdshow Video Decoder filter
              this.blackListManager.AddBlackListedFilter(new Guid("04FE9017-F873-410E-871E-AB91661A4EF7"));

              int hr = this.graphBuilder.RenderFile(filename, null);
              DsError.ThrowExceptionForHR(hr);

              this.mediaControl = (IMediaControl)this.graphBuilder;
              this.mediaEvent = (IMediaEvent)this.graphBuilder;
        }
Ejemplo n.º 26
0
        private void BuildGraph(string sFileName, out IFilterGraph2 graphBuilder, out IBaseFilter vmr7Filter)
        {
            int         hr           = 0;
            IBaseFilter sourceFilter = null;

            graphBuilder = new FilterGraph() as IFilterGraph2;
            vmr7Filter   = null;

            try
            {
                hr = graphBuilder.AddSourceFilter(sFileName, sFileName, out sourceFilter);
                Marshal.ThrowExceptionForHR(hr);

                vmr7Filter = (IBaseFilter) new VideoMixingRenderer();
                hr         = graphBuilder.AddFilter(vmr7Filter, "VMR7");
            }
            catch
            {
                Marshal.ReleaseComObject(graphBuilder);
                throw;
            }
            finally
            {
                Marshal.ReleaseComObject(sourceFilter);
            }
        }
Ejemplo n.º 27
0
        private void Dispose(bool disposing)
        {
            if (this.disposed)
            {
                return;
            }

            if (disposing)
            {
                this.source       = null;
                this.streamInfo   = null;
                this.graph        = null;
                this.videoRender  = null;
                this.audioRender  = null;
                this.videoGrabber = null;
                this.audioGrabber = null;

                if (this.sampleHandler != null)
                {
                    this.sampleHandler.Dispose();
                    this.sampleHandler = null;
                }

                this.isConfigured = false;
            }

            this.disposed = true;
        }
Ejemplo n.º 28
0
        void BuildGraph()
        {
            int           hr;
            IGraphBuilder graphBuilder = new FilterGraph() as IGraphBuilder;

            m_ROT = new DsROTEntry(graphBuilder);
            IFilterGraph2 ifg2 = graphBuilder as IFilterGraph2;

            hr = graphBuilder.RenderFile("foo.avi", null);
            DsError.ThrowExceptionForHR(hr);

            // Get a ICaptureGraphBuilder2
            ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            hr = icgb.SetFiltergraph((IGraphBuilder)graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            m_mediaEventEx = graphBuilder as IMediaEventEx;
            hr             = m_mediaEventEx.SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            Thread.Sleep(500);

            m_imc = graphBuilder as IMediaControl;
            hr    = m_imc.Run();
            DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 29
0
        private void Config()
        {
            int                   hr;
            IBaseFilter           pFilter;
            ICaptureGraphBuilder2 icgb = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            m_fg = (IFilterGraph2) new FilterGraph();
            DsROTEntry rot = new DsROTEntry(m_fg);

            hr = icgb.SetFiltergraph(m_fg);
            DsError.ThrowExceptionForHR(hr);

            m_mo = (IMixerOCX) new OverlayMixer();
            TestAdvise();

            hr = m_fg.AddFilter((IBaseFilter)m_mo, null);
            DsError.ThrowExceptionForHR(hr);

            hr = m_fg.AddSourceFilter(@"foo.avi", null, out pFilter);
            DsError.ThrowExceptionForHR(hr);

            IPin iPin = DsFindPin.ByDirection(pFilter, PinDirection.Output, 0);

            hr = icgb.RenderStream(null, null, iPin, null, (IBaseFilter)m_mo);
            DsError.ThrowExceptionForHR(hr);

            hr = ((IMediaControl)m_fg).Run();
            DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 30
0
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if (m_FilterGraph != null)
                {
                    IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;

                    // Stop the graph
                    hr = mediaCtrl.Stop();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

#if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
            }
#endif

            if (m_FilterGraph != null)
            {
                Marshal.ReleaseComObject(m_FilterGraph);
                m_FilterGraph = null;
            }
            GC.Collect();
        }
Ejemplo n.º 31
0
        public void DoTests()
        {
            m_graphBuilder = BuildGraph(g_TestFile);
            m_ims          = m_graphBuilder as IMediaSeeking;

            try
            {
                TestCaps();
                TestFormats();
                TestRate();
                TestPosition();
                TestPreRoll();
                TestSetPosition();
                TestConvert();
            }
            finally
            {
                if (m_graphBuilder != null)
                {
                    Marshal.ReleaseComObject(m_graphBuilder);
                }

                m_graphBuilder = null;
                m_ims          = null;
            }
        }
Ejemplo n.º 32
0
 public void Stop()
 {
     if (_parentControl != null)
     {
         _parentControl.SizeChanged -= _parentControl_SizeChanged;
     }
     if (_videoWin != null)
     {
         _videoWin.put_Visible(OABool.False);
         _videoWin = null;
     }
     if (_mediaCtrl != null)
     {
         _mediaCtrl.Stop();
         _mediaCtrl = null;
     }
     if (_rotEntry != null)
     {
         _rotEntry.Dispose();
         _rotEntry = null;
     }
     if (_graphBuilder != null)
     {
         DirectShowUtil.ReleaseComObject(_graphBuilder, 2000);
         _graphBuilder = null;
     }
 }
Ejemplo n.º 33
0
        private void BuildGraph()
        {
            int hr = 0;

            DsDevice [] devs;

            graphBuilder = (IFilterGraph2) new FilterGraph();
            rot          = new DsROTEntry(graphBuilder);

            vmr9 = (IBaseFilter) new VideoMixingRenderer9();
            hr   = graphBuilder.AddFilter(vmr9, "VMR9");

            devs = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            DsDevice dev = devs[0];

            hr = graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out filter);
            DsError.ThrowExceptionForHR(hr);

            captureGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            hr           = captureGraph.SetFiltergraph(graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            hr = captureGraph.RenderStream(PinCategory.Capture, MediaType.Video, filter, null, vmr9);
            DsError.ThrowExceptionForHR(hr);

            object tmp;

            hr = captureGraph.FindInterface(null, null, filter, typeof(IAMTVTuner).GUID, out tmp);
            DsError.ThrowExceptionForHR(hr);
            tuner = (IAMTVTuner)tmp;

            mediaControl = (IMediaControl)graphBuilder;
            mediaControl.Run();
        }
        private void SetupGraphInternal(DsDevice dev, SystemCodecEntry compressor, VideoFormatHelper.SupportedVideoFormat selectedFormat, ref float iFrameRate, ref int iWidth, ref int iHeight, string fileName)
        {
            filterGraph = (IFilterGraph2) new FilterGraph();
            mediaCtrl   = filterGraph as IMediaControl;

            capBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            samplGrabber = (ISampleGrabber) new SampleGrabber();

            int hr = capBuilder.SetFiltergraph(filterGraph);

            DsError.ThrowExceptionForHR(hr);

            if (rot != null)
            {
                rot.Dispose();
                rot = null;
            }
            rot = new DsROTEntry(filterGraph);

            if (fileName != null)
            {
                deviceFilter = BuildFileCaptureGraph(dev, compressor.Device, selectedFormat, fileName, ref iFrameRate, ref iWidth, ref iHeight);
            }
            else
            {
                deviceFilter = BuildPreviewOnlyCaptureGraph(dev, selectedFormat, ref iFrameRate, ref iWidth, ref iHeight);
            }

            // Now that sizes are fixed/known, store the sizes
            SaveSizeInfo(samplGrabber);
        }
Ejemplo n.º 35
0
        public void BuildGraph(ITuningSpace tuningSpace)
        {
            this.graphBuilder = (IFilterGraph2) new FilterGraph();
              rot = new DsROTEntry(this.graphBuilder);

              // Method names should be self explanatory
              AddNetworkProviderFilter(tuningSpace);
              AddMPEG2DemuxFilter();
              AddAndConnectBDABoardFilters();
              AddTransportStreamFiltersToGraph();
              AddRenderers();
              ConfigureVMR9InWindowlessMode();
              ConnectFilters();
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            base.Dispose( disposing );

            if (m_rot != null)
            {
                m_rot.Dispose();
                m_rot = null;
            }
            if (graphBuilder != null)
            {
                (graphBuilder as IMediaControl).Stop();
                Marshal.ReleaseComObject(graphBuilder);
                graphBuilder = null;
            }
        }
Ejemplo n.º 37
0
    /// <summary>
    /// Initializes a new instance of the <see cref="HDPVRChannel"/> class.
    /// </summary>
    public HDPVRChannel(TvCardHDPVR card, String deviceType, Int32 subchannelId, IBaseFilter filterTsWriter, IFilterGraph2 graphBuilder)
    {
      _eventPMT = new ManualResetEvent(false);
      _graphState = GraphState.Created;
      _graphBuilder = graphBuilder;
      _channelInfo = new ChannelInfo();
      _pmtPid = -1;
      _subChannelIndex = -1;

      // Keep a reference to the card for quality control.
      _card = card;
      _deviceType = deviceType;

      _tsFilterInterface = (ITsFilter)filterTsWriter;
      _tsFilterInterface.AddChannel(ref _subChannelIndex);
      _subChannelId = subchannelId;
      _timeshiftFileName = "";
      _recordingFileName = "";
      _pmtData = null;
      _pmtLength = 0;

      _grabTeletext = false;
      _mdplugs = null;
    }
Ejemplo n.º 38
0
        public int RenderGraph(IFilterGraph2 graph, string fileName)
        {
            FileInfo info = new FileInfo(fileName);
            string ext = info.Extension;
            bool has = false;
            foreach (string s in exts)
            {
                if (s == ext)
                {
                    has = true;
                    break;
                }
            }

            if (!has)
                return -1;

            //just render file

            IMediaControl mediaControl = graph as IMediaControl;
            if( mediaControl == null ) return -1;

            return mediaControl.RenderFile(fileName);
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Closes and releases all used interfaces.
        /// </summary>
        public void CloseInterfaces()
        {
            if (VMRenderer != null)
            {
                Marshal.ReleaseComObject(VMRenderer);
                VMRenderer = null;
                WindowlessCtrl = null;
                MixerBitmap = null;
            }

            if (FilterGraph != null)
            {
                Marshal.ReleaseComObject(FilterGraph);
                FilterGraph = null;
                MediaControl = null;
            }

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

            if (SampleGrabber != null)
            {
                Marshal.ReleaseComObject(SampleGrabber);
                SampleGrabber = null;
                SampleGrabberFilter = null;
            }

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

            if (Crossbar != null)
            {
                Marshal.ReleaseComObject(Crossbar);
                Crossbar = null;
            }
        }
Ejemplo n.º 40
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
                return;

            if (disposing)
            {
                // Dispose managed resources.
            }

            if (filterGraph != null)
            {
                MediaControl.Stop();
                Marshal.ReleaseComObject(filterGraph);
                filterGraph = null;
            }

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

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

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

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

            disposed = true;
        }
Ejemplo n.º 41
0
 protected RadioBase()
 {
     filterGraph = (IFilterGraph2)new FilterGraph();
     AddSourceFilter();
 }
Ejemplo n.º 42
0
        // Shut down capture
        private void CloseInterfaces()
        {
            int hr;

            lock (this)
            {
                if (m_State != GraphState.Exiting)
                {
                    m_State = GraphState.Exiting;

                    // Release the thread (if the thread was started)
                    if (m_mre != null)
                    {
                        m_mre.Set();
                    }
                }

                if (m_mediaCtrl != null)
                {
                    // Stop the graph
                    hr = m_mediaCtrl.Stop();
                    m_mediaCtrl = null;
                }

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

                if (m_FilterGraph != null)
                {
                    Marshal.ReleaseComObject(m_FilterGraph);
                    m_FilterGraph = null;
                }
            }
            GC.Collect();
        }
Ejemplo n.º 43
0
        // Build the capture graph for grabber and renderer.</summary>
        // (Control to show video in, Filename to play)
        private void SetupGraph(string FileName)
        {
            int hr;

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

            // Get a ICaptureGraphBuilder2 to help build the graph
            ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            try
            {
                // Link the ICaptureGraphBuilder2 to the IFilterGraph2
                hr = icgb2.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

                // Add the filters necessary to render the file.  This function will
                // work with a number of different file types.
                IBaseFilter sourceFilter = null;
                hr = m_FilterGraph.AddSourceFilter(FileName, FileName, out sourceFilter);
                DsError.ThrowExceptionForHR(hr);

                // Get the SampleGrabber interface
                m_sampGrabber = (ISampleGrabber)new SampleGrabber();
                IBaseFilter baseGrabFlt = (IBaseFilter)m_sampGrabber;

                // Configure the Sample Grabber
                ConfigureSampleGrabber(m_sampGrabber);

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

                // Add the null renderer to the graph
                IBaseFilter nullrenderer = new NullRenderer() as IBaseFilter;
                hr = m_FilterGraph.AddFilter(nullrenderer, "Null renderer");
                DsError.ThrowExceptionForHR(hr);

                // Connect the pieces together, use the default renderer
                hr = icgb2.RenderStream(null, null, sourceFilter, baseGrabFlt, nullrenderer);
                DsError.ThrowExceptionForHR(hr);

                // Now that the graph is built, read the dimensions of the bitmaps we'll be getting
                SaveSizeInfo(m_sampGrabber);

                // Grab some other interfaces
                m_mediaEvent = m_FilterGraph as IMediaEvent;
                m_mediaCtrl = m_FilterGraph as IMediaControl;
            }
            finally
            {
                if (icgb2 != null)
                {
                    Marshal.ReleaseComObject(icgb2);
                    icgb2 = null;
                }
            }
            #if DEBUG
            // Double check to make sure we aren't releasing something
            // important.
            GC.Collect();
            GC.WaitForPendingFinalizers();
            #endif
        }
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if (m_mediaCtrl != null)
                {
                    // Stop the graph
                    hr = m_mediaCtrl.Stop();
                    m_mediaCtrl = null;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            #if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
            }
            #endif

            if (m_FilterGraph != null)
            {
                Marshal.ReleaseComObject(m_FilterGraph);
                m_FilterGraph = null;
            }
            GC.Collect();
        }
        /// <summary> build the capture graph for grabber. </summary>
        private void SetupGraph(string FileName)
        {
            int hr;

            ISampleGrabber sampGrabber = null;
            IBaseFilter baseGrabFlt = null;
            IBaseFilter capFilter = null;
            IBaseFilter nullrenderer = null;

            // Get the graphbuilder object
            m_FilterGraph = new FilterGraph() as IFilterGraph2;
            m_mediaCtrl = m_FilterGraph as IMediaControl;
            m_MediaEvent = m_FilterGraph as IMediaEvent;

            IMediaFilter mediaFilt = m_FilterGraph as IMediaFilter;

            try
            {
            #if DEBUG
                m_rot = new DsROTEntry(m_FilterGraph);
            #endif

                // Add the video source
                hr = m_FilterGraph.AddSourceFilter(FileName, "Ds.NET FileFilter", out capFilter);
                DsError.ThrowExceptionForHR(hr);

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

                ConfigureSampleGrabber(sampGrabber);

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

                // ---------------------------------
                // Connect the file filter to the sample grabber

                // Hopefully this will be the video pin, we could check by reading it's mediatype
                IPin iPinOut = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);

                // Get the input pin from the sample grabber
                IPin iPinIn = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);

                hr = m_FilterGraph.Connect(iPinOut, iPinIn);
                DsError.ThrowExceptionForHR(hr);

                // Add the null renderer to the graph
                nullrenderer = new NullRenderer() as IBaseFilter;
                hr = m_FilterGraph.AddFilter(nullrenderer, "Null renderer");
                DsError.ThrowExceptionForHR(hr);

                // ---------------------------------
                // Connect the sample grabber to the null renderer

                iPinOut = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Output, 0);
                iPinIn = DsFindPin.ByDirection(nullrenderer, PinDirection.Input, 0);

                hr = m_FilterGraph.Connect(iPinOut, iPinIn);
                DsError.ThrowExceptionForHR(hr);

                // Turn off the clock.  This causes the frames to be sent
                // thru the graph as fast as possible
                hr = mediaFilt.SetSyncSource(null);
                DsError.ThrowExceptionForHR(hr);

                // Read and cache the image sizes
                SaveSizeInfo(sampGrabber);
            }
            finally
            {
                if (capFilter != null)
                {
                    Marshal.ReleaseComObject(capFilter);
                    capFilter = null;
                }
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                    sampGrabber = null;
                }
                if (nullrenderer != null)
                {
                    Marshal.ReleaseComObject(nullrenderer);
                    nullrenderer = null;
                }
            }
        }
Ejemplo n.º 46
0
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            try
            {
                if (m_FilterGraph != null)
                {
                    IMediaControl mediaCtrl = (IMediaControl)m_FilterGraph;

                    // Stop the graph
                    mediaCtrl.Stop();
                }
            }
            catch
            {
            }

            if (m_FilterGraph != null)
            {
                Marshal.ReleaseComObject(m_FilterGraph);
                m_FilterGraph = null;
            }
        }
Ejemplo n.º 47
0
        /// <summary> build the capture graph for grabber. </summary>
        private void SetupGraph(DsDevice dev, int iWidth, int iHeight, short iBPP)
        {
            ISampleGrabber sampGrabber = null;
            IPin pCaptureOut = null;
            IPin pRenderIn = null;

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

            try
            {

                // add the video input device
                IBaseFilter capFilter;
                int hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
                DsError.ThrowExceptionForHR(hr);

                //if (iHeight + iWidth + iBPP > 0)
                //{
                //SetConfigParms(pRaw, iWidth, iHeight, iBPP);
                //}
                pCaptureOut = DsFindPin.ByCategory(capFilter, PinCategory.Capture, 0);

                // Get the SampleGrabber interface
                sampGrabber = new SampleGrabber() as ISampleGrabber;
                // Configure the sample grabber
                IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
                ConfigureSampleGrabber(sampGrabber);

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

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

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

                // Learn the video properties
                SaveSizeInfo(sampGrabber);

                // Start the graph
                IMediaControl mediaCtrl = (IMediaControl)m_FilterGraph;
                hr = mediaCtrl.Run();
                DsError.ThrowExceptionForHR(hr);
            }
            finally
            {
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                }
                if (pCaptureOut != null)
                {
                    Marshal.ReleaseComObject(pCaptureOut);
                }
                if (pRenderIn != null)
                {
                    Marshal.ReleaseComObject(pRenderIn);
                }
            }
        }
Ejemplo n.º 48
0
        private void CloseInterfaces()
        {
            if (mediaControl != null)
                mediaControl.Stop();

            if (handlersAdded)
                RemoveHandlers();

            if (vmr9 != null)
            {
                Marshal.ReleaseComObject(vmr9);
                vmr9 = null;
                windowlessCtrl = null;
                mixerBitmap = null;
            }

            if (graphBuilder != null)
            {
                Marshal.ReleaseComObject(graphBuilder);
                graphBuilder = null;
                mediaControl = null;
            }

            menuMixer.Enabled = false;
        }
Ejemplo n.º 49
0
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if (m_FilterGraph != null)
                {
                    IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;

                    // Stop the graph
                    hr = mediaCtrl.Stop();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

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

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

            if (m_pinStill != null)
            {
                Marshal.ReleaseComObject(m_pinStill);
                m_pinStill = null;
            }
        }
Ejemplo n.º 50
0
 /// <summary>
 /// Creates the filter by trying to detect it
 /// </summary>
 /// <param name="crossbar">The crossbar componen</param>
 /// <param name="tuner">The tuner component</param>
 /// <param name="graph">The stored graph</param>
 /// <param name="graphBuilder">The graphBuilder</param>
 /// <returns>true, if the graph building was successful</returns>
 private bool CreateAutomaticFilterInstance(Graph graph, Tuner tuner, Crossbar crossbar, IFilterGraph2 graphBuilder)
 {
   //get all tv audio tuner devices on this system
   DsDevice[] devices = null;
   try
   {
     devices = DsDevice.GetDevicesOfCat(FilterCategory.AMKSTVAudio);
     devices = DeviceSorter.Sort(devices, tuner.TunerName, crossbar.CrossBarName);
   }
   catch (Exception)
   {
     Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio devices found - Trying TvTuner filter");
   }
   if (devices != null && devices.Length > 0)
   {
     // try each tv audio tuner
     for (int i = 0; i < devices.Length; i++)
     {
       IBaseFilter tmp;
       Log.Log.WriteFile("analog: AddTvAudioFilter try:{0} {1}", devices[i].Name, i);
       //if tv audio tuner is currently in use we can skip it
       if (DevicesInUse.Instance.IsUsed(devices[i]))
         continue;
       int hr;
       try
       {
         //add tv audio tuner to graph
         hr = graphBuilder.AddSourceFilterForMoniker(devices[i].Mon, null, devices[i].Name, out tmp);
       }
       catch (Exception)
       {
         Log.Log.WriteFile("analog: cannot add filter to graph");
         continue;
       }
       if (hr != 0)
       {
         //failed to add tv audio tuner to graph, continue with the next one
         if (tmp != null)
         {
           graphBuilder.RemoveFilter(tmp);
           Release.ComObject("tvAudioFilter filter", tmp);
         }
         continue;
       }
       // try connecting the tv tuner-> tv audio tuner
       if (FilterGraphTools.ConnectPin(graphBuilder, tuner.AudioPin, tmp, 0))
       {
         // Got it !
         // Connect tv audio tuner to the crossbar
         IPin pin = DsFindPin.ByDirection(tmp, PinDirection.Output, 0);
         hr = graphBuilder.Connect(pin, crossbar.AudioTunerIn);
         if (hr < 0)
         {
           //failed
           graphBuilder.RemoveFilter(tmp);
           Release.ComObject("audiotuner pinin", pin);
           Release.ComObject("audiotuner filter", tmp);
         }
         else
         {
           //succeeded. we're done
           Log.Log.WriteFile("analog: AddTvAudioFilter succeeded:{0}", devices[i].Name);
           Release.ComObject("audiotuner pinin", pin);
           _filterTvAudioTuner = tmp;
           _audioDevice = devices[i];
           DevicesInUse.Instance.Add(_audioDevice);
           _tvAudioTunerInterface = tuner.Filter as IAMTVAudio;
           break;
         }
       }
       else
       {
         // cannot connect tv tuner-> tv audio tuner, try next one...
         graphBuilder.RemoveFilter(tmp);
         Release.ComObject("audiotuner filter", tmp);
       }
     }
   }
   if (_filterTvAudioTuner == null)
   {
     Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio devices found - Trying TvTuner filter");
     int hr = graphBuilder.Connect(tuner.AudioPin, crossbar.AudioTunerIn);
     if (hr != 0)
     {
       Log.Log.Error("analog: unable to add TvAudioTuner to graph - even TvTuner as TvAudio fails");
       mode = TvAudioVariant.Unavailable;
     }
     else
     {
       Log.Log.WriteFile("analog: AddTvAudioFilter connected TvTuner with Crossbar directly succeeded!");
       mode = TvAudioVariant.TvTunerConnection;
       _tvAudioTunerInterface = tuner.Filter as IAMTVAudio;
       if (_tvAudioTunerInterface != null)
       {
         Log.Log.WriteFile("analog: AddTvAudioFilter succeeded - TvTuner is also TvAudio");
         _filterTvAudioTuner = tuner.Filter;
         mode = TvAudioVariant.TvTuner;
       }
     }
     graph.TvAudio.Mode = mode;
   }
   else
   {
     mode = TvAudioVariant.Normal;
     graph.TvAudio.Name = _audioDevice.Name;
   }
   if (mode != TvAudioVariant.Unavailable && mode != TvAudioVariant.TvTunerConnection &&
       _tvAudioTunerInterface != null)
   {
     CheckCapabilities(graph);
   }
   return true;
 }
Ejemplo n.º 51
0
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if( m_mediaCtrl != null )
                {
                    // Stop the graph
                    hr = m_mediaCtrl.Stop();
                    m_bRunning = false;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            if (m_FilterGraph != null)
            {
                Marshal.ReleaseComObject(m_FilterGraph);
                m_FilterGraph = null;
            }
        }
Ejemplo n.º 52
0
        /// <summary> build the capture graph for grabber. </summary>
        private void SetupGraph(DsDevice dev, AMMediaType media)
        {
            int hr;

            ISampleGrabber sampGrabber = null;
            IBaseFilter capFilter = null;
            ICaptureGraphBuilder2 capGraph = null;

            // Get the graphbuilder object
            m_FilterGraph = (IFilterGraph2) new FilterGraph();
            m_mediaCtrl = m_FilterGraph as IMediaControl;
            try
            {
                // Get the ICaptureGraphBuilder2
                capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

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

                // Start building the graph
                hr = capGraph.SetFiltergraph( m_FilterGraph );
                DsError.ThrowExceptionForHR( hr );

                // Add the video device
                hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
                DsError.ThrowExceptionForHR( hr );

                // add video crossbar
                // thanks to Andrew Fernie - this is to get tv tuner cards working
                IAMCrossbar crossbar = null;
                object o;

                hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    crossbar = (IAMCrossbar)o;
                    int oPin, iPin;
                    int ovLink, ivLink;
                    ovLink = ivLink = 0;

                    crossbar.get_PinCounts(out oPin, out iPin);
                    int pIdxRel;
                    PhysicalConnectorType tp;
                    for (int i = 0; i < iPin; i++)
                    {
                        crossbar.get_CrossbarPinInfo(true, i, out pIdxRel, out tp);
                        if (tp == PhysicalConnectorType.Video_Composite) ivLink = i;
                    }

                    for (int i = 0; i < oPin; i++)
                    {
                        crossbar.get_CrossbarPinInfo(false, i, out pIdxRel, out tp);
                        if (tp == PhysicalConnectorType.Video_VideoDecoder) ovLink = i;
                    }

                    try
                    {
                        crossbar.Route(ovLink, ivLink);
                        o = null;
                    }

                    catch
                    {
                        throw new Exception("Failed to get IAMCrossbar");
                    }
                }

                //add AVI Decompressor
                IBaseFilter pAVIDecompressor = (IBaseFilter)new AVIDec();
                hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor");
                DsError.ThrowExceptionForHR(hr);

                //
                IBaseFilter baseGrabFlt = (IBaseFilter)	sampGrabber;
                ConfigureSampleGrabber(sampGrabber);

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

                SetConfigParms(capGraph, capFilter, media);

                hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, pAVIDecompressor, baseGrabFlt);
                if (hr < 0)
                {
                    hr = capGraph.RenderStream(PinCategory.Capture, MediaType.Video, capFilter, null, baseGrabFlt);
                }

                DsError.ThrowExceptionForHR( hr );

                SaveSizeInfo(sampGrabber);
            }
            finally
            {
                if (capFilter != null)
                {
                    Marshal.ReleaseComObject(capFilter);
                    capFilter = null;
                }
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                    sampGrabber = null;
                }
                if (capGraph != null)
                {
                    Marshal.ReleaseComObject(capGraph);
                    capGraph = null;
                }
            }
        }
Ejemplo n.º 53
0
        /// <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;

            // 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);
                }

                // 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 (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;
                }
            }
        }
Ejemplo n.º 54
0
        public void SetupGraph(DsDevice dev, bool runOCR, VideoFormatHelper.SupportedVideoFormat selectedFormat, ref float iFrameRate, ref int iWidth, ref int iHeight)
        {
            try
            {
                filterGraph = (IFilterGraph2)new FilterGraph();
                mediaCtrl = filterGraph as IMediaControl;

                capBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

                samplGrabber = (ISampleGrabber)new SampleGrabber();

                int hr = capBuilder.SetFiltergraph(filterGraph);
                DsError.ThrowExceptionForHR(hr);

                if (Settings.Default.VideoGraphDebugMode)
                {
                    if (rot != null)
                    {
                        rot.Dispose();
                        rot = null;
                    }
                    rot = new DsROTEntry(filterGraph);
                }

                SetupGraphInternal(dev, selectedFormat, ref iFrameRate, ref iWidth, ref iHeight);

                // Now that sizes are fixed/known, store the sizes
                SaveSizeInfo(samplGrabber);

                crossbar = CrossbarHelper.SetupTunerAndCrossbar(capBuilder, capFilter);

                latestBitmap = new Bitmap(iWidth, iHeight, PixelFormat.Format24bppRgb);
                fullRect = new Rectangle(0, 0, latestBitmap.Width, latestBitmap.Height);

                NativeHelpers.SetupCamera(
                    Settings.Default.CameraModel,
                    iWidth, iHeight,
                    Settings.Default.HorizontalFlip,
                    Settings.Default.VerticalFlip,
                    Settings.Default.IsIntegrating,
                    (float)Settings.Default.MinSignatureDiffRatio,
                    (float)Settings.Default.MinSignatureDiff,
                    Settings.Default.GammaDiff,
                    Settings.Default.ForceNewFrameOnLockedRate,
                    dev.Name,
                    selectedFormat.AsSerialized(),
                    selectedFormat.FrameRate);

                NativeHelpers.SetupAav(Settings.Default.RecordStatusSectionOnly ? AavImageLayout.StatusSectionOnly : Settings.Default.AavImageLayout, Settings.Default.AavCompression);

                ocrEnabled = false;
                string errorMessage;

                if (runOCR)
                {
                    OcrConfiguration ocrConfig = OcrSettings.Instance[Settings.Default.SelectedOcrConfiguration];

                    errorMessage = NativeHelpers.SetupBasicOcrMetrix(ocrConfig);
                    if (errorMessage != null && callbacksObject != null)
                        callbacksObject.OnError(-1, errorMessage);
                    else
                    {
                        NativeHelpers.SetupOcr(ocrConfig);
                        ocrEnabled = true;
                    }
                }
                else
                {
                    errorMessage = NativeHelpers.SetupTimestampPreservation(false, 0, 0);
                    if (errorMessage != null && callbacksObject != null)
                        callbacksObject.OnError(-1, errorMessage);
                }
            }
            catch
            {
                CloseResources();

                if (callbacksObject != null)
                    callbacksObject.OnError(-1, "Error initialising the camera. The selected video mode may not be supported by the camera.");

                throw;
            }
        }
Ejemplo n.º 55
0
        /// <summary> build the capture graph for grabber. </summary>
        private void SetupGraph(DsDevice dev, int iFrameRate, int iWidth, int iHeight)
        {
            int hr;

            ISampleGrabber sampGrabber = null;
            IBaseFilter capFilter = null;
            ICaptureGraphBuilder2 capGraph = null;

            // Get the graphbuilder object
            m_FilterGraph = (IFilterGraph2) new FilterGraph();
            m_mediaCtrl = m_FilterGraph as IMediaControl;
            try
            {
                // Get the ICaptureGraphBuilder2
                capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

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

                // Start building the graph
                hr = capGraph.SetFiltergraph( m_FilterGraph );
                DsError.ThrowExceptionForHR( hr );

                // Add the video device
                hr = m_FilterGraph.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter);
                DsError.ThrowExceptionForHR( hr );

                IBaseFilter baseGrabFlt = (IBaseFilter)	sampGrabber;
                ConfigureSampleGrabber(sampGrabber);

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

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

                hr = capGraph.RenderStream( PinCategory.Capture, MediaType.Video, capFilter, null, baseGrabFlt );
                DsError.ThrowExceptionForHR( hr );

                SaveSizeInfo(sampGrabber);
            }
            finally
            {
                if (capFilter != null)
                {
                    Marshal.ReleaseComObject(capFilter);
                    capFilter = null;
                }
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                    sampGrabber = null;
                }
                if (capGraph != null)
                {
                    Marshal.ReleaseComObject(capGraph);
                    capGraph = null;
                }
            }
        }
Ejemplo n.º 56
0
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;
            ConsoleLogger.logMessage("In CloseInterfaces");

            try
            {
                if (m_FilterGraph != null)
                {
                    IMediaControl mediaCtrl = m_FilterGraph as IMediaControl;

                    // Stop the graph
                    hr = mediaCtrl.Stop();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            #if DEBUG
            if (m_rot != null)
            {
                m_rot.Dispose();
            }
            #endif

            if (m_FilterGraph != null)
            {
                Marshal.ReleaseComObject(m_FilterGraph);
                m_FilterGraph = null;
            }
            GC.Collect();

            if(CaptureShutdownEvent != null)
                CaptureShutdownEvent(this, new EventArgs());

            mFrameOverlay.dispose();
        }
Ejemplo n.º 57
0
    /// <summary>
    /// Adds the tv audio tuner to the graph and connects it to the crossbar.
    /// At the end of this method the graph looks like:
    /// [          ] ------------------------->[           ]
    /// [ tvtuner  ]                           [ crossbar  ]
    /// [          ]----[            ]-------->[           ]
    ///                 [ tvaudio    ]
    ///                 [   tuner    ]
    /// </summary>
    /// <param name="crossbar">The crossbar componen</param>
    /// <param name="tuner">The tuner component</param>
    /// <param name="graph">The stored graph</param>
    /// <param name="graphBuilder">The graphBuilder</param>
    /// <returns>true, if the graph building was successful</returns>
    public bool CreateFilterInstance(Graph graph, IFilterGraph2 graphBuilder, Tuner tuner, Crossbar crossbar)
    {
      streams = new List<IAudioStream>();
      if (!string.IsNullOrEmpty(graph.TvAudio.Name) && graph.TvAudio.Mode != TvAudioVariant.Unavailable)
      {
        Log.Log.WriteFile("analog: Using TvAudio configuration from stored graph");

        if (CreateConfigurationBasedFilterInstance(graph, tuner, crossbar, graphBuilder))
        {
          Log.Log.WriteFile("analog: Using TvAudio configuration from stored graph succeeded");
          return true;
        }
      }
      if (tuner.AudioPin == null)
      {
        Log.Log.WriteFile("analog: AddTvAudioFilter no tv audio device needed!");
        mode = TvAudioVariant.Unavailable;
        return true;
      }
      Log.Log.WriteFile("analog: No stored graph for TvAudio component - Trying to detect");
      return CreateAutomaticFilterInstance(graph, tuner, crossbar, graphBuilder);
    }
Ejemplo n.º 58
0
        /// <summary> build the capture graph for grabber. </summary>
        private void SetupGraph(string FileName, Control hWin)
        {
            int hr;

            IBaseFilter ibfRenderer = null;
            ISampleGrabber sampGrabber = null;
            IBaseFilter capFilter = null;
            IPin iPinInFilter = null;
            IPin iPinOutFilter = null;
            IPin iPinInDest = null;
            IBasicAudio basicAudio = null;

            // Get the graphbuilder object
            m_FilterGraph = new FilterGraph() as IFilterGraph2;
            #if DEBUG
            m_rot = new DsROTEntry(m_FilterGraph);
            #endif

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

                // Add the video source
                hr = m_FilterGraph.AddSourceFilter(FileName, "Ds.NET FileFilter", out capFilter);
                DsError.ThrowExceptionForHR(hr);

                // Hopefully this will be the video pin
                IPin iPinOutSource = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);

                IBaseFilter baseGrabFlt = sampGrabber as IBaseFilter;
                ConfigureSampleGrabber(sampGrabber);

                iPinInFilter = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Input, 0);
                iPinOutFilter = DsFindPin.ByDirection(baseGrabFlt, PinDirection.Output, 0);

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

                hr = m_FilterGraph.Connect(iPinOutSource, iPinInFilter);
                DsError.ThrowExceptionForHR(hr);

                // Get the default video renderer
                ibfRenderer = (IBaseFilter)new VideoRendererDefault();

                // Add it to the graph
                hr = m_FilterGraph.AddFilter(ibfRenderer, "Ds.NET VideoRendererDefault");
                DsError.ThrowExceptionForHR(hr);
                iPinInDest = DsFindPin.ByDirection(ibfRenderer, PinDirection.Input, 0);

                // Connect the graph.  Many other filters automatically get added here
                hr = m_FilterGraph.Connect(iPinOutFilter, iPinInDest);
                DsError.ThrowExceptionForHR(hr);

                SaveSizeInfo(sampGrabber);

                // Set the output window

                IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
                hr = videoWindow.put_Owner(hWin.Handle);
                DsError.ThrowExceptionForHR(hr);

                hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings);
                DsError.ThrowExceptionForHR(hr);

                hr = videoWindow.put_Visible(OABool.True);
                DsError.ThrowExceptionForHR(hr);

                //TODO : Need a better way to hide the video in the parent Window
                Rectangle rc = hWin.ClientRectangle;
                if (mParentWindowDisplay)
                    hr = videoWindow.SetWindowPosition(0, 0, rc.Right, rc.Bottom);
                else
                    hr = videoWindow.SetWindowPosition(0, 0, 0, 0);
                DsError.ThrowExceptionForHR(hr);

                IGraphBuilder graphBuilder = m_FilterGraph as IGraphBuilder;
                ICaptureGraphBuilder2 captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

                // Attach the filter graph to the capture graph
                hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
                DsError.ThrowExceptionForHR(hr);

                hr = captureGraphBuilder.RenderStream(null, MediaType.Audio, capFilter, null, null);

            }
            finally
            {
                if (capFilter != null)
                {
                    Marshal.ReleaseComObject(capFilter);
                    capFilter = null;
                }
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                    sampGrabber = null;
                }
                if (ibfRenderer != null)
                {
                    Marshal.ReleaseComObject(ibfRenderer);
                    ibfRenderer = null;
                }
                if (iPinInFilter != null)
                {
                    Marshal.ReleaseComObject(iPinInFilter);
                    iPinInFilter = null;
                }
                if (iPinOutFilter != null)
                {
                    Marshal.ReleaseComObject(iPinOutFilter);
                    iPinOutFilter = null;
                }
                if (iPinInDest != null)
                {
                    Marshal.ReleaseComObject(iPinInDest);
                    iPinInDest = null;
                }
            }
        }
Ejemplo n.º 59
0
        private void StartCapture()
        {
            int hr;

            ISampleGrabber sampGrabber = null;
            IBaseFilter capFilter = null;
            ICaptureGraphBuilder2 capGraph = null;

            if (System.IO.File.Exists(txtAviFileName.Text))
            {
                // Get the graphbuilder object
                m_FilterGraph = (IFilterGraph2) new FilterGraph();
                m_mediaCtrl = m_FilterGraph as IMediaControl;

                // Get the ICaptureGraphBuilder2
                capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

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

                // Start building the graph
                hr = capGraph.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

                // Add the video source
                hr = m_FilterGraph.AddSourceFilter(txtAviFileName.Text, "File Source (Async.)", out capFilter);
                DsError.ThrowExceptionForHR(hr);

                //add AVI Decompressor
                IBaseFilter pAVIDecompressor = (IBaseFilter) new AVIDec();
                hr = m_FilterGraph.AddFilter(pAVIDecompressor, "AVI Decompressor");
                DsError.ThrowExceptionForHR(hr);

                IBaseFilter ffdshow;
                try
                {
                    // Create Decoder filter COM object (ffdshow video decoder)
                    Type comtype = Type.GetTypeFromCLSID(new Guid("{04FE9017-F873-410E-871E-AB91661A4EF7}"));
                    if (comtype == null)
                        throw new NotSupportedException("Creating ffdshow video decoder COM object fails.");
                    object comobj = Activator.CreateInstance(comtype);
                    ffdshow = (IBaseFilter) comobj; // error ocurrs! raised exception
                    comobj = null;
                }
                catch
                {
                    CustomMessageBox.Show("Please install/reinstall ffdshow");
                    return;
                }

                hr = m_FilterGraph.AddFilter(ffdshow, "ffdshow");
                DsError.ThrowExceptionForHR(hr);

                //
                IBaseFilter baseGrabFlt = (IBaseFilter) sampGrabber;
                ConfigureSampleGrabber(sampGrabber);

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


                IBaseFilter vidrender = (IBaseFilter) new VideoRenderer();
                hr = m_FilterGraph.AddFilter(vidrender, "Render");
                DsError.ThrowExceptionForHR(hr);


                IPin captpin = DsFindPin.ByDirection(capFilter, PinDirection.Output, 0);

                IPin ffdpinin = DsFindPin.ByName(ffdshow, "In");

                IPin ffdpinout = DsFindPin.ByName(ffdshow, "Out");

                IPin samppin = DsFindPin.ByName(baseGrabFlt, "Input");

                hr = m_FilterGraph.Connect(captpin, ffdpinin);
                DsError.ThrowExceptionForHR(hr);
                hr = m_FilterGraph.Connect(ffdpinout, samppin);
                DsError.ThrowExceptionForHR(hr);

                FileWriter filewritter = new FileWriter();
                IFileSinkFilter filemux = (IFileSinkFilter) filewritter;
                //filemux.SetFileName("test.avi",);

                //hr = capGraph.RenderStream(null, MediaType.Video, capFilter, null, vidrender);
                // DsError.ThrowExceptionForHR(hr); 

                SaveSizeInfo(sampGrabber);

                // setup buffer
                if (m_handle == IntPtr.Zero)
                    m_handle = Marshal.AllocCoTaskMem(m_stride*m_videoHeight);

                // tell the callback to ignore new images
                m_PictureReady = new ManualResetEvent(false);
                m_bGotOne = false;
                m_bRunning = false;

                timer1 = new Thread(timer);
                timer1.IsBackground = true;
                timer1.Start();

                m_mediaextseek = m_FilterGraph as IAMExtendedSeeking;
                m_mediapos = m_FilterGraph as IMediaPosition;
                m_mediaseek = m_FilterGraph as IMediaSeeking;
                double length = 0;
                m_mediapos.get_Duration(out length);
                trackBar_mediapos.Minimum = 0;
                trackBar_mediapos.Maximum = (int) length;

                Start();
            }
            else
            {
                MessageBox.Show("File does not exist");
            }
        }
Ejemplo n.º 60
0
        private void BuildGraph(string fileName)
        {
            int hr = 0;

            try
            {
                graphBuilder = (IFilterGraph2) new FilterGraph();
                mediaControl = (IMediaControl) graphBuilder;

                vmr9 = (IBaseFilter) new VideoMixingRenderer9();

                ConfigureVMR9InWindowlessMode();

                hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
                DsError.ThrowExceptionForHR(hr);

                hr = graphBuilder.RenderFile(fileName, null);
                DsError.ThrowExceptionForHR(hr);

                mixerBitmap = (IVMRMixerBitmap9) vmr9;

                menuMixer.Enabled = true;
                mixerEnabled = true;
                usingGDI = false;
                UpdateMixerMenu();
                SetMixerSettings();
            }
            catch(Exception e)
            {
                CloseInterfaces();
                MessageBox.Show("An error occured during the graph building : \r\n\r\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }