コード例 #1
0
        //
        //Method to start to play a media file
        //
        private void LoadFile(string fName)
        {
            try
            {
                //get the graph filter ready to render
                graphBuilder.RenderFile(fName, null);

                //set the trackbar
                OABool bCsf, bCsb;
                mediaPos.CanSeekBackward(out bCsb);
                mediaPos.CanSeekForward(out bCsf);
                isSeeking = (bCsb == OABool.True) && (bCsf == OABool.True);
                if (isSeeking)
                {
                    trackBar1.Enabled = true;
                }
                else
                {
                    trackBar1.Enabled = false;
                }
                trackBar1.Minimum = 0;

                double duration;
                mediaPos.get_Duration(out duration);
                trackBar1.Maximum = (int)(duration * 100.0);
                Text = fName;

                //check for the ability to step
                frameStep = graphBuilder as IVideoFrameStep;
                if (frameStep.CanStep(1, null) == 0)
                {
                    canStep = true;
                    buttonFramestep.Enabled = true;
                }

                //prepare and set the video window
                videoWin = graphBuilder as IVideoWindow;
                videoWin.put_Owner((IntPtr)panel1.Handle);
                videoWin.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
                Rectangle rc = panel1.ClientRectangle;
                videoWin.SetWindowPosition(0, 0, rc.Right, rc.Bottom);
                mediaEvt.SetNotifyWindow((IntPtr)this.Handle, WM_GRAPHNOTIFY, (IntPtr)0);

                //set the different values for controls
                trackBar1.Value           = 0;
                minutes                   = (int)duration / 60;
                seconds                   = (int)duration % 60;
                statusBar1.Panels[0].Text = "Duration: " + minutes.ToString("D2")
                                            + ":m" + seconds.ToString("D2") + ":s";
                graphState = State.Playing;

                this.buttonPlay.Text = "Pause";
                //start the playback
                mediaCtrl.Run();
            }
            catch (Exception) { Text = "Error loading file"; }
        }
コード例 #2
0
ファイル: VideoPlayer.cs プロジェクト: fabianhick/viana
        /// <summary>
        ///   The dispose.
        /// </summary>
        public override void Dispose()
        {
            this.ReleaseEventThread();

            //// Release and zero DirectShow interfaces
            if (this.mediaSeeking != null)
            {
                this.mediaSeeking = null;
            }

            if (this.mediaPosition != null)
            {
                this.mediaPosition = null;
            }

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

            if (this.basicAudio != null)
            {
                this.basicAudio = null;
            }

            if (this.basicVideo != null)
            {
                this.basicVideo = null;
            }

            if (this.mediaEvent != null)
            {
                this.mediaEvent = null;
            }

            if (this.videoWindow != null)
            {
                this.videoWindow = null;
            }

            if (this.frameStep != null)
            {
                this.frameStep = null;
            }

            // Release DirectShow interfaces
            base.Dispose();

            // Clear file name to allow selection of new file with open dialog
            this.VideoFilename = string.Empty;
        }
コード例 #3
0
ファイル: DShowPlayer.cs プロジェクト: gmorkvenas/pimaker
        public void Step(int dwFrames)
        {
            if (m_pGraph == null)
            {
                throw new COMException("Graph in wrong state", DsResults.E_WrongState);
            }

            IVideoFrameStep pStep = (IVideoFrameStep)m_pGraph;

            int hr = pStep.Step(dwFrames, null);

            DsError.ThrowExceptionForHR(hr);

            // To step, the Filter Graph Manager first runs the graph. When
            // the step is complete, it pauses the graph. For the application,
            // we can just report our new state as paused.
            m_state = PlaybackState.Paused;
        }
コード例 #4
0
        public void DoTests()
        {
            BuildGraph();

            this.videoFrameStep = (IVideoFrameStep)this.graphBuilder;

            try
            {
                TestCanStep();
                TestStep();
                TestCancelStep();
            }
            finally
            {
                Marshal.ReleaseComObject(this.vmr9);
                Marshal.ReleaseComObject(this.graphBuilder);
            }
        }
コード例 #5
0
ファイル: VideoPlayer.cs プロジェクト: fabianhick/viana
        /// <summary>
        /// The get frame step interface.
        /// Some video renderers support stepping media frame by frame with the
        /// IVideoFrameStep interface.  See the interface documentation for more
        /// details on frame stepping.
        /// </summary>
        /// <returns> True, if frame step interface is available, otherwise false </returns>
        private bool GetFrameStepInterface()
        {
            int hr = 0;

            IVideoFrameStep frameStepTest = null;

            // Get the frame step interface, if supported
            frameStepTest = (IVideoFrameStep)this.filterGraph;

            // Check if this decoder can step
            hr = frameStepTest.CanStep(0, null);
            if (hr == 0)
            {
                this.frameStep = frameStepTest;
                return(true);
            }

            this.frameStep = null;
            return(false);
        }
コード例 #6
0
        // Some video renderers support stepping media frame by frame with the
        // IVideoFrameStep interface.  See the interface documentation for more
        // details on frame stepping.
        private bool GetFrameStepInterface()
        {
            int hr = 0;

            // Get the frame step interface, if supported
            IVideoFrameStep frameStepTest = this.graphBuilder as IVideoFrameStep;

            // Check if this decoder can step
            hr = frameStepTest.CanStep(0, null);
            if (hr == 0)
            {
                this.frameStep = frameStepTest;
                return(true);
            }
            else
            {
                this.frameStep = null;
                return(false);
            }
        }
コード例 #7
0
        /// Some video renderers support stepping media frame by frame with the
        /// IVideoFrameStep interface.  See the interface documentation for more
        /// details on frame stepping.
        public bool GetFrameStepInterface()
        {
            int             hr            = 0;
            IVideoFrameStep frameStepTest = null;

            // Get the frame step interface, if supported
            frameStepTest = (IVideoFrameStep)graphBuilder;

            // Check if this decoder can step
            hr = frameStepTest.CanStep(0, null);
            if (hr == 0)
            {
                frameStep = frameStepTest;
                return(true);
            }
            else
            {
                frameStep = null;
                return(false);
            }
        }
コード例 #8
0
 //
 //This method stop the filter graph and ensures that we stop
 //sending messages to our window
 //
 private void CloseInterfaces()
 {
     if (mediaCtrl != null)
     {
         mediaCtrl.StopWhenReady();
         mediaEvt.SetNotifyWindow((IntPtr)0, WM_GRAPHNOTIFY, (IntPtr)0);
     }
     mediaCtrl = null;
     mediaEvt  = null;
     mediaPos  = null;
     if (canStep)
     {
         frameStep = null;
     }
     videoWin = null;
     if (graphBuilder != null)
     {
         Marshal.ReleaseComObject(this.graphBuilder);
     }
     graphBuilder = null;
 }
コード例 #9
0
        private void open()
        {
            int hr;

            if (this.GraphBuilder == null)
            {
                this.GraphBuilder = (IGraphBuilder) new FilterGraph();

                hr = GraphBuilder.RenderFile(file, null);//读取文件
                DsError.ThrowExceptionForHR(hr);
                this.MediaControl = (IMediaControl)this.GraphBuilder;
                this.MediaEventEx = (IMediaEventEx)this.GraphBuilder;
                MediaSeeking      = (IMediaSeeking)this.GraphBuilder;
                MediaSeeking.SetTimeFormat(TIME_FORMAT_FRAME);
                MediaSeeking.SetRate(0.3);
                this.VideoFrameStep = (IVideoFrameStep)this.GraphBuilder;
                // MediaPosition= (IMediaPosition)this.GraphBuilder;
                this.VideoWindow = this.GraphBuilder as IVideoWindow;
                this.BasicVideo  = this.GraphBuilder as IBasicVideo;
                this.BasicAudio  = this.GraphBuilder as IBasicAudio;

                hr = this.MediaEventEx.SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
                DsError.ThrowExceptionForHR(hr);


                hr = this.VideoWindow.put_Owner(this.Handle);
                DsError.ThrowExceptionForHR(hr);
                hr = this.VideoWindow.put_WindowStyle(WindowStyle.Child |
                                                      WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
                DsError.ThrowExceptionForHR(hr);
                this.Focus();
                hr = InitVideoWindow(1, 1);
                DsError.ThrowExceptionForHR(hr);
                long time;
                MediaSeeking.GetDuration(out time);
                label20.Text = time.ToString();
                trackBar1.SetRange(0, (int)time);
                t = new Thread(new ThreadStart(updateTimeBarThread));
            }
        }
コード例 #10
0
        protected virtual HRESULT PreparePlayback()
        {
            m_MediaControl  = (IMediaControl)m_GraphBuilder;
            m_BasicVideo    = (IBasicVideo)m_GraphBuilder;
            m_MediaSeeking  = (IMediaSeeking)m_GraphBuilder;
            m_VideoWindow   = (IVideoWindow)m_GraphBuilder;
            m_MediaEventEx  = (IMediaEventEx)m_GraphBuilder;
            m_FrameStep     = (IVideoFrameStep)m_GraphBuilder;
            m_MediaPosition = (IMediaPosition)m_GraphBuilder;
            SettingUpVideoWindow();
            int hr = m_MediaEventEx.SetNotifyWindow(m_EventControl.Handle, WM_GRAPHNOTIFY, Marshal.GetIUnknownForObject(this));

            Debug.Assert(hr == 0);
            SetVolume(m_bMute ? -10000 : m_iVolume);
            if (m_dRate != 1.0)
            {
                m_MediaSeeking.SetRate(m_dRate);
                m_MediaSeeking.GetRate(out m_dRate);
            }
            OnPlaybackReady?.Invoke(this, EventArgs.Empty);
            return((HRESULT)hr);
        }
コード例 #11
0
ファイル: AVPlayer.cs プロジェクト: zhjh-stack/ogama
        //
        // Some video renderers support stepping media frame by frame with the
        // IVideoFrameStep interface.  See the interface documentation for more
        // details on frame stepping.
        //
        private bool GetFrameStepInterface()
        {
            int hr = 0;

            IVideoFrameStep frameStepTest = null;

            // Get the frame step interface, if supported
            frameStepTest = (IVideoFrameStep)this.graphBuilder;

            // Check if this decoder can step
            hr = frameStepTest.CanStep(0, null);
            if (hr == 0)
            {
                this.frameStep = frameStepTest;
                return(true);
            }
            else
            {
                // BUG 1560263 found by husakm (thanks)...
                // Marshal.ReleaseComObject(frameStepTest);
                this.frameStep = null;
                return(false);
            }
        }
コード例 #12
0
ファイル: RadPlayer.cs プロジェクト: configare/hispeed
        //
        // Some video renderers support stepping media frame by frame with the
        // IVideoFrameStep interface.  See the interface documentation for more
        // details on frame stepping.
        //
        private bool GetFrameStepInterface()
        {
            // Get the frame step interface, if supported
            IVideoFrameStep frameStepTest = this.graphBuilder as IVideoFrameStep;

            if (frameStepTest == null)
            {
                SetLastError("Frame Step interface could be get");
                return(false);
            }

            // Check if this decoder can step
            if (Check(frameStepTest.CanStep(0, null)))
            {
                this.frameStep = frameStepTest;
                return(true);
            }
            else
            {
                Marshal.ReleaseComObject(frameStepTest);
                frameStepTest = null;
                return(false);
            }
        }
コード例 #13
0
ファイル: AVPlayer.cs プロジェクト: zhjh-stack/ogama
        private void CloseInterfaces()
        {
            //int hr = 0;

            try
            {
                lock (this)
                {
                    //// Relinquish ownership (IMPORTANT!) after hiding video window
                    //if (!this.isAudioOnly && this.videoWindow != null)
                    //{
                    //  hr = this.videoWindow.put_Visible(OABool.False);
                    //  DsError.ThrowExceptionForHR(hr);
                    //  hr = this.videoWindow.put_Owner(IntPtr.Zero);
                    //  DsError.ThrowExceptionForHR(hr);
                    //}

                    //if (this.mediaEventEx != null)
                    //{
                    //  hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                    //  DsError.ThrowExceptionForHR(hr);
                    //}

#if DEBUG
                    if (rot != null)
                    {
                        rot.Dispose();
                        rot = null;
                    }
#endif
                    // Release and zero DirectShow interfaces
                    //if (this.mediaEventEx != null)
                    //  this.mediaEventEx = null;
                    if (this.mediaSeeking != null)
                    {
                        this.mediaSeeking = null;
                    }
                    if (this.mediaPosition != null)
                    {
                        this.mediaPosition = null;
                    }
                    if (this.mediaControl != null)
                    {
                        this.mediaControl = null;
                    }
                    if (this.basicAudio != null)
                    {
                        this.basicAudio = null;
                    }
                    if (this.basicVideo != null)
                    {
                        this.basicVideo = null;
                    }
                    //if (this.videoWindow != null)
                    //  this.videoWindow = null;
                    if (this.frameStep != null)
                    {
                        this.frameStep = null;
                    }
                    if (this.graphBuilder != null)
                    {
                        Marshal.ReleaseComObject(this.graphBuilder);
                    }
                    this.graphBuilder = null;

                    GC.Collect();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }
コード例 #14
0
ファイル: Grabber.cs プロジェクト: RoChess/mvcentral
        /// <summary> create the used COM components and get the interfaces. </summary>
        protected virtual bool GetDVDInterfaces(string path)
        {
            int hr;
            //Type	            comtype = null;
            object comobj = null;

            _freeNavigator = true;
            _dvdInfo       = null;
            _dvdCtrl       = null;
            bool   useAC3Filter    = false;
            string dvdNavigator    = "";
            string aspectRatioMode = "";
            string displayMode     = "";

            _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
            using (MediaPortal.Profile.Settings xmlreader = new MPSettings())
            {
                dvdNavigator    = xmlreader.GetValueAsString("dvdplayer", "navigator", "DVD Navigator");
                aspectRatioMode = xmlreader.GetValueAsString("dvdplayer", "armode", "").ToLower();

                dvdNavigator = "dslibdvdnav";

                if (aspectRatioMode == "crop")
                {
                    arMode = AspectRatioMode.Crop;
                }
                if (aspectRatioMode == "letterbox")
                {
                    arMode = AspectRatioMode.LetterBox;
                }
                if (aspectRatioMode == "stretch")
                {
                    arMode = AspectRatioMode.Stretched;
                }
                //if ( aspectRatioMode == "stretch" ) arMode = AspectRatioMode.zoom14to9;
                if (aspectRatioMode == "follow stream")
                {
                    arMode = AspectRatioMode.StretchedAsPrimary;
                }
                useAC3Filter = xmlreader.GetValueAsBool("dvdplayer", "ac3", false);
                displayMode  = xmlreader.GetValueAsString("dvdplayer", "displaymode", "").ToLower();
                if (displayMode == "default")
                {
                    _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
                }
                if (displayMode == "16:9")
                {
                    _videoPref = DvdPreferredDisplayMode.Display16x9;
                }
                if (displayMode == "4:3 pan scan")
                {
                    _videoPref = DvdPreferredDisplayMode.Display4x3PanScanPreferred;
                }
                if (displayMode == "4:3 letterbox")
                {
                    _videoPref = DvdPreferredDisplayMode.Display4x3LetterBoxPreferred;
                }
            }
            try
            {
                _dvdGraph = (IDvdGraphBuilder) new DvdGraphBuilder();

                hr = _dvdGraph.GetFiltergraph(out _graphBuilder);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                _rotEntry = new DsROTEntry((IFilterGraph)_graphBuilder);

                _vmr9Filter = (IBaseFilter) new VideoMixingRenderer9();
                IVMRFilterConfig9 config = _vmr9Filter as IVMRFilterConfig9;
                hr             = config.SetNumberOfStreams(1);
                hr             = config.SetRenderingMode(VMR9Mode.Windowless);
                windowlessCtrl = (IVMRWindowlessControl9)_vmr9Filter;
                windowlessCtrl.SetVideoClippingWindow(this.panVideoWin.Handle);


                //                config.SetRenderingPrefs(VMR9RenderPrefs.

                _graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Renderer 9");

                //               _vmr7 = new VMR7Util();
                //               _vmr7.AddVMR7(_graphBuilder);

                try
                {
                    _dvdbasefilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, dvdNavigator);
                    if (_dvdbasefilter != null)
                    {
                        IDvdControl2 cntl = (IDvdControl2)_dvdbasefilter;
                        if (cntl != null)
                        {
                            _dvdInfo = (IDvdInfo2)cntl;
                            _dvdCtrl = (IDvdControl2)cntl;
                            if (path != null)
                            {
                                if (path.Length != 0)
                                {
                                    cntl.SetDVDDirectory(path);
                                }
                            }
                            _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
                            _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);

                            AddPreferedCodecs(_graphBuilder);
                            DirectShowUtil.RenderOutputPins(_graphBuilder, _dvdbasefilter);


//                            _videoWin = _graphBuilder as IVideoWindow;
                            _freeNavigator = false;
                        }

                        //DirectShowUtil.ReleaseComObject( _dvdbasefilter); _dvdbasefilter = null;
                    }
                }
                catch (Exception ex)
                {
                    string strEx = ex.Message;
                }

                Guid riid;

                if (_dvdInfo == null)
                {
                    riid = typeof(IDvdInfo2).GUID;
                    hr   = _dvdGraph.GetDvdInterface(riid, out comobj);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    _dvdInfo = (IDvdInfo2)comobj;
                    comobj   = null;
                }

                if (_dvdCtrl == null)
                {
                    riid = typeof(IDvdControl2).GUID;
                    hr   = _dvdGraph.GetDvdInterface(riid, out comobj);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    _dvdCtrl = (IDvdControl2)comobj;
                    comobj   = null;
                }

                _mediaCtrl  = (IMediaControl)_graphBuilder;
                _mediaEvt   = (IMediaEventEx)_graphBuilder;
                _basicAudio = _graphBuilder as IBasicAudio;
                _mediaPos   = (IMediaPosition)_graphBuilder;
                _mediaSeek  = (IMediaSeeking)_graphBuilder;
                _mediaStep  = (IVideoFrameStep)_graphBuilder;
                _basicVideo = _graphBuilder as IBasicVideo2;
                _videoWin   = _graphBuilder as IVideoWindow;

                // disable Closed Captions!
                IBaseFilter baseFilter;
                _graphBuilder.FindFilterByName("Line 21 Decoder", out baseFilter);
                if (baseFilter == null)
                {
                    _graphBuilder.FindFilterByName("Line21 Decoder", out baseFilter);
                }
                if (baseFilter != null)
                {
                    _line21Decoder = (IAMLine21Decoder)baseFilter;
                    if (_line21Decoder != null)
                    {
                        AMLine21CCState state = AMLine21CCState.Off;
                        hr = _line21Decoder.SetServiceState(state);
                        if (hr == 0)
                        {
                            logger.Info("DVDPlayer:Closed Captions disabled");
                        }
                        else
                        {
                            logger.Info("DVDPlayer:failed 2 disable Closed Captions");
                        }
                    }
                }

                /*
                 *      // get video window
                 *      if (_videoWin==null)
                 *      {
                 *        riid = typeof( IVideoWindow ).GUID;
                 *        hr = _dvdGraph.GetDvdInterface( ref riid, out comobj );
                 *        if( hr < 0 )
                 *          Marshal.ThrowExceptionForHR( hr );
                 *        _videoWin = (IVideoWindow) comobj; comobj = null;
                 *      }
                 */
                // GetFrameStepInterface();

                DirectShowUtil.SetARMode(_graphBuilder, arMode);
                DirectShowUtil.EnableDeInterlace(_graphBuilder);
                //m_ovMgr = new OVTOOLLib.OvMgrClass();
                //m_ovMgr.SetGraph(_graphBuilder);

                return(true);
            }
            catch (Exception)
            {
                //MessageBox.Show( this, "Could not get interfaces\r\n" + ee.Message, "DVDPlayer.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
                CloseDVDInterfaces();
                return(false);
            }
            finally
            {
                if (comobj != null)
                {
                    DirectShowUtil.ReleaseComObject(comobj);
                }
                comobj = null;
            }
        }
コード例 #15
0
ファイル: Player.cs プロジェクト: babgvant/EVRPlay
        private void CloseInterfaces()
        {
            int hr = 0;

            try
            {
                lock (this)
                {
                    // Relinquish ownership (IMPORTANT!) after hiding video window
                    //if (!this.isAudioOnly)
                    //{
                    //    hr = this.videoWindow.put_Visible(OABool.False);
                    //    DsError.ThrowExceptionForHR(hr);
                    //    hr = this.videoWindow.put_Owner(IntPtr.Zero);
                    //    DsError.ThrowExceptionForHR(hr);
                    //}

                    //#if DEBUG
                    try
                    {
                        if (rot != null)
                        {
                            rot.Dispose();
                            rot = null;
                        }
                    }
                    catch { }
                    //#endif

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

                    if (dvdCtrl != null)
                    {
                        hr = dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, true);
                    }

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

                    pendingCmd = false;

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

                    if (this.mediaEventEx != null)
                    {
                        if (dvdGraph != null)
                            hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, WM.DVD_EVENT, IntPtr.Zero);
                        else
                            hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, WM.NULL, IntPtr.Zero);
                        //DsError.ThrowExceptionForHR(hr);
                    }

                    if (evrDisplay != null)
                    {
                        //evrDisplay.SetVideoWindow(IntPtr.Zero);
                        Marshal.ReleaseComObject(evrDisplay);
                    }
                    evrDisplay = null;
                    if (this.evrRenderer != null)
                        Marshal.ReleaseComObject(evrRenderer);
                    evrRenderer = null;

                    // Release and zero DirectShow interfaces
                    if (this.mediaEventEx != null)
                        this.mediaEventEx = null;
                    if (this.mediaSeeking != null)
                        this.mediaSeeking = null;
                    if (this.mediaPosition != null)
                        this.mediaPosition = null;
                    if (this.mediaControl != null)
                        this.mediaControl = null;
                    if (this.basicAudio != null)
                        this.basicAudio = null;
                    if (this.basicVideo != null)
                        this.basicVideo = null;
                    //if (this.videoWindow != null)
                    //    this.videoWindow = null;
                    if (this.frameStep != null)
                        this.frameStep = null;
                    if (this.graphBuilder != null)
                        Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;
                    if (this.dvdGraph != null)
                        Marshal.ReleaseComObject(dvdGraph); dvdGraph = null;

                    GC.Collect();
                }
            }
            catch
            {
            }
        }
コード例 #16
0
ファイル: GUI.cs プロジェクト: mguthrie777/demo-newstuff
        private void ClosePlayback()
        {
            int hr = 0;

            try
            {
                if (this.mediaEventEx != null)
                {
                    hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                    DsError.ThrowExceptionForHR(hr);
                }

            #if DEBUG
                if (rot != null)
                {
                    rot.Dispose();
                    rot = null;
                }
            #endif
                // Release and zero DirectShow interfaces
                if (this.mediaEventEx != null) this.mediaEventEx = null;
                if (this.mediaSeeking != null) this.mediaSeeking = null;
                if (this.mediaPosition != null) this.mediaPosition = null;
                if (this.mediaControl != null) this.mediaControl = null;
                if (this.basicAudio != null) this.basicAudio = null;
                if (this.basicVideo != null) this.basicVideo = null;
                if (this.videoWindow != null) this.videoWindow = null;
                if (this.frameStep != null) this.frameStep = null;
                if (this.graphBuilder != null) Marshal.ReleaseComObject(this.graphBuilder);
                this.graphBuilder = null;

                //GC.Collect();
            }
            catch
            {
            }
        }
コード例 #17
0
        /// <summary> do cleanup and release DirectShow. </summary>
        void CloseInterfaces()
        {
            int hr;
            try
            {
                if( dvdCtrl != null )
                {
                    hr = dvdCtrl.SetOption( DvdOptionFlag.ResetOnStop, true );
                }

                if( mediaCtrl != null )
                {
                    hr = mediaCtrl.Stop();
                    mediaCtrl = null;
                }
                playState = PlayState.Stopped;

                if( mediaEvt != null )
                {
                    hr = mediaEvt.SetNotifyWindow( IntPtr.Zero, WM_DVD_EVENT, IntPtr.Zero );
                    mediaEvt = null;
                }

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

                videoStep	= null;

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

                pendingCmd = false;

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

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

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

                playState = PlayState.Init;
            }
            catch( Exception )
            {}
        }
コード例 #18
0
        /// <summary>
        /// Close the currently open video feed.
        /// </summary>
        public void Close()
        {
            m_bConnected = false;
            m_lDuration  = 0;

            if (m_mediaControl != null)
            {
                m_mediaControl.Stop();
            }

            if (m_mediaEventEx != null)
            {
                m_mediaEventEx.SetNotifyWindow(IntPtr.Zero, WM_GRAPHNOTIFY, IntPtr.Zero);
            }

            if (m_videoWindow != null)
            {
                m_videoWindow.put_Visible(DsHlp.OAFALSE);
                m_videoWindow.put_Owner(IntPtr.Zero);
            }

            // Release all interfaces.

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

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

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

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

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

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

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

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

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

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

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

            if (m_videoFilter != null)
            {
                Marshal.ReleaseComObject(m_videoFilter);
                m_videoFilter = null;
            }
        }
コード例 #19
0
ファイル: VideoFramePusher.cs プロジェクト: DeSciL/Ogama
    /// <summary> Shut down capture </summary>
    private void CloseInterfaces()
    {
      int hr;
      try
      {
        if (m_handle != IntPtr.Zero)
        {
          Marshal.FreeCoTaskMem(m_handle);
          m_handle = IntPtr.Zero;
        }
      }
      catch (Exception)
      {
      }

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

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

      if (this.mediaSeeking != null)
        this.mediaSeeking = null;
      if (this.frameStep != null)
        this.frameStep = null;

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

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

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

      GC.Collect();
    }
コード例 #20
0
ファイル: RadPlayer.cs プロジェクト: configare/hispeed
        private bool CloseInterfaces(bool disposing)
        {
            this.lastError = 0;

            try
            {
                lock (this)
                {
                    if (disposing)
                    {
                        // Stop media playback (could be disposing while playing...)
                        if (this.mediaControl != null)
                        {
                            Check(this.mediaControl.Stop());
                        }
                    }

                    // Relinquish ownership (IMPORTANT!) after hiding video window
                    if (this.hasVideo)
                    {
                        Check(this.videoWindow.put_Visible(OABool.False));
                        Check(this.videoWindow.put_Owner(IntPtr.Zero));
                    }

                    if (this.mediaEventEx != null)
                    {
                        Check(this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero));
                    }

#if DEBUG
                    if (rot != null)
                    {
                        rot.Dispose();
                        rot = null;
                    }
#endif
                    // Release and zero DirectShow interfaces
                    if (this.mediaEventEx != null)
                    {
                        this.mediaEventEx = null;
                    }
                    if (this.mediaSeeking != null)
                    {
                        this.mediaSeeking = null;
                    }
                    if (this.mediaPosition != null)
                    {
                        this.mediaPosition = null;
                    }
                    if (this.mediaControl != null)
                    {
                        this.mediaControl = null;
                    }
                    if (this.basicAudio != null)
                    {
                        this.basicAudio = null;
                    }
                    if (this.basicVideo != null)
                    {
                        this.basicVideo = null;
                    }
                    if (this.videoWindow != null)
                    {
                        this.videoWindow = null;
                    }
                    if (this.frameStep != null)
                    {
                        this.frameStep = null;
                    }

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

                    GC.Collect();

                    if (deleteTempFile && this.tempFileName != null && File.Exists(this.tempFileName))
                    {
                        File.Delete(this.tempFileName);
                        this.tempFileName = null;
                    }
                }
            }
            catch
            {
                if (this.lastError >= 0)
                {
                    SetLastError("Error closing DirectShow interfaces");
                }
            }

            return(this.lastError >= 0 && this.errorMessage == null);
        }
コード例 #21
0
ファイル: MediaPlayer.cs プロジェクト: jamecook/projects
        /// <summary>
        /// Close all interfaces.
        /// </summary>
        private void CloseInterfaces()
        {
            int hr = 0;

            try
            {
                lock (this)
                {
                    // Remove the dvd control.
                    if (_dvdControl != null)
                    {
                        hr = _dvdControl.SetOption(DvdOptionFlag.ResetOnStop, true);
                    }

                    // Free the preview window (ignore errors)
                    if (_videoWindow != null)
                    {
                        _videoWindow.put_Visible(OABool.False);
                        _videoWindow.put_Owner(IntPtr.Zero);
                    }

                    // Remove the Resize event handler
                    if (_playWindow != null)
                    {
                        _playWindow.Resize -= new EventHandler(onPlayerWindowResize);
                    }

                    if (_mediaEventEx != null)
                    {
                        hr = _mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }

                    // Release and zero DirectShow interfaces
                    if (_mediaEventEx != null)
                    {
                        _mediaEventEx = null;
                    }

                    if (_mediaSeeking != null)
                    {
                        _mediaSeeking = null;
                    }

                    if (_mediaPosition != null)
                    {
                        _mediaPosition = null;
                    }

                    if (_mediaControl != null)
                    {
                        _mediaControl = null;
                    }

                    if (_basicAudio != null)
                    {
                        _basicAudio = null;
                    }

                    if (_basicVideo != null)
                    {
                        _basicVideo = null;
                    }

                    if (_videoWindow != null)
                    {
                        _videoWindow = null;
                    }

                    if (_frameStep != null)
                    {
                        _frameStep = null;
                    }

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

                    GC.Collect();
                }
            }
            catch
            {
            }
        }
コード例 #22
0
        private void closeInterfaces()
        {
            int hr = 0;

            try
            {
                lock (this)
                {
                    //relinquish ownership (IMPORTANT!) after hiding video window
                    hr = this.VideoWindow.put_Visible(OABool.False);
                    DsError.ThrowExceptionForHR(hr);
                    hr = this.VideoWindow.put_Owner(IntPtr.Zero);
                    DsError.ThrowExceptionForHR(hr);

                    if (this.MediaEventEx != null)
                    {
                        hr = this.MediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }
                    //release and zero DirectShow interfaces
                    if (this.MediaEventEx != null)
                    {
                        this.MediaEventEx = null;
                    }
                    if (this.MediaSeeking != null)
                    {
                        this.MediaSeeking = null;
                    }
                    if (this.MediaPosition != null)
                    {
                        this.MediaPosition = null;
                    }
                    if (this.MediaControl != null)
                    {
                        this.MediaControl = null;
                    }
                    if (this.BasicAudio != null)
                    {
                        this.BasicAudio = null;
                    }
                    if (this.BasicVideo != null)
                    {
                        this.BasicVideo = null;
                    }
                    if (this.VideoWindow != null)
                    {
                        this.VideoWindow = null;
                    }
                    if (this.VideoFrameStep != null)
                    {
                        this.VideoFrameStep = null;
                    }
                    if (this.GraphBuilder != null)
                    {
                        this.GraphBuilder = null;
                    }
                    GC.Collect();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #23
0
ファイル: Grabber.cs プロジェクト: andrewjswan/mvcentral
        /// <summary> create the used COM components and get the interfaces. </summary>
        protected virtual bool GetDVDInterfaces(string path)
        {
            int hr;
            //Type	            comtype = null;
            object comobj = null;
            _freeNavigator = true;
            _dvdInfo = null;
            _dvdCtrl = null;
            bool useAC3Filter = false;
            string dvdNavigator = "";
            string aspectRatioMode = "";
            string displayMode = "";
            _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
            using (MediaPortal.Profile.Settings xmlreader = new MPSettings())
            {
                dvdNavigator = xmlreader.GetValueAsString("dvdplayer", "navigator", "DVD Navigator");
                aspectRatioMode = xmlreader.GetValueAsString("dvdplayer", "armode", "").ToLower();

                dvdNavigator = "dslibdvdnav";

                if (aspectRatioMode == "crop")
                {
                    arMode = AspectRatioMode.Crop;
                }
                if (aspectRatioMode == "letterbox")
                {
                    arMode = AspectRatioMode.LetterBox;
                }
                if (aspectRatioMode == "stretch")
                {
                    arMode = AspectRatioMode.Stretched;
                }
                //if ( aspectRatioMode == "stretch" ) arMode = AspectRatioMode.zoom14to9;
                if (aspectRatioMode == "follow stream")
                {
                    arMode = AspectRatioMode.StretchedAsPrimary;
                }
                useAC3Filter = xmlreader.GetValueAsBool("dvdplayer", "ac3", false);
                displayMode = xmlreader.GetValueAsString("dvdplayer", "displaymode", "").ToLower();
                if (displayMode == "default")
                {
                    _videoPref = DvdPreferredDisplayMode.DisplayContentDefault;
                }
                if (displayMode == "16:9")
                {
                    _videoPref = DvdPreferredDisplayMode.Display16x9;
                }
                if (displayMode == "4:3 pan scan")
                {
                    _videoPref = DvdPreferredDisplayMode.Display4x3PanScanPreferred;
                }
                if (displayMode == "4:3 letterbox")
                {
                    _videoPref = DvdPreferredDisplayMode.Display4x3LetterBoxPreferred;
                }
            }
            try
            {
                _dvdGraph = (IDvdGraphBuilder)new DvdGraphBuilder();

                hr = _dvdGraph.GetFiltergraph(out _graphBuilder);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
                _rotEntry = new DsROTEntry((IFilterGraph)_graphBuilder);

                _vmr9Filter = (IBaseFilter)new VideoMixingRenderer9();
                IVMRFilterConfig9 config = _vmr9Filter as IVMRFilterConfig9;
                hr = config.SetNumberOfStreams(1);
                hr = config.SetRenderingMode(VMR9Mode.Windowless);
                windowlessCtrl = (IVMRWindowlessControl9)_vmr9Filter;
                windowlessCtrl.SetVideoClippingWindow(this.panVideoWin.Handle);

                //                config.SetRenderingPrefs(VMR9RenderPrefs.

                _graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Renderer 9");

             //               _vmr7 = new VMR7Util();
             //               _vmr7.AddVMR7(_graphBuilder);

                try
                {
                    _dvdbasefilter = DirectShowUtil.AddFilterToGraph(_graphBuilder, dvdNavigator);
                    if (_dvdbasefilter != null)
                    {
                        IDvdControl2 cntl = (IDvdControl2)_dvdbasefilter;
                        if (cntl != null)
                        {
                            _dvdInfo = (IDvdInfo2)cntl;
                            _dvdCtrl = (IDvdControl2)cntl;
                            if (path != null)
                            {
                                if (path.Length != 0)
                                {
                                    cntl.SetDVDDirectory(path);
                                }
                            }
                            _dvdCtrl.SetOption(DvdOptionFlag.HMSFTimeCodeEvents, true); // use new HMSF timecode format
                            _dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, false);

                            AddPreferedCodecs(_graphBuilder);
                            DirectShowUtil.RenderOutputPins(_graphBuilder, _dvdbasefilter);

            //                            _videoWin = _graphBuilder as IVideoWindow;
                            _freeNavigator = false;
                        }

                        //DirectShowUtil.ReleaseComObject( _dvdbasefilter); _dvdbasefilter = null;
                    }
                }
                catch (Exception ex)
                {
                    string strEx = ex.Message;
                }

                Guid riid;

                if (_dvdInfo == null)
                {
                    riid = typeof(IDvdInfo2).GUID;
                    hr = _dvdGraph.GetDvdInterface(riid, out comobj);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    _dvdInfo = (IDvdInfo2)comobj;
                    comobj = null;
                }

                if (_dvdCtrl == null)
                {
                    riid = typeof(IDvdControl2).GUID;
                    hr = _dvdGraph.GetDvdInterface(riid, out comobj);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                    _dvdCtrl = (IDvdControl2)comobj;
                    comobj = null;
                }

                _mediaCtrl = (IMediaControl)_graphBuilder;
                _mediaEvt = (IMediaEventEx)_graphBuilder;
                _basicAudio = _graphBuilder as IBasicAudio;
                _mediaPos = (IMediaPosition)_graphBuilder;
                _mediaSeek = (IMediaSeeking)_graphBuilder;
                _mediaStep = (IVideoFrameStep)_graphBuilder;
                _basicVideo = _graphBuilder as IBasicVideo2;
                _videoWin = _graphBuilder as IVideoWindow;

                // disable Closed Captions!
                IBaseFilter baseFilter;
                _graphBuilder.FindFilterByName("Line 21 Decoder", out baseFilter);
                if (baseFilter == null)
                {
                    _graphBuilder.FindFilterByName("Line21 Decoder", out baseFilter);
                }
                if (baseFilter != null)
                {
                    _line21Decoder = (IAMLine21Decoder)baseFilter;
                    if (_line21Decoder != null)
                    {
                        AMLine21CCState state = AMLine21CCState.Off;
                        hr = _line21Decoder.SetServiceState(state);
                        if (hr == 0)
                        {
                            logger.Info("DVDPlayer:Closed Captions disabled");
                        }
                        else
                        {
                            logger.Info("DVDPlayer:failed 2 disable Closed Captions");
                        }
                    }
                }
                /*
                        // get video window
                        if (_videoWin==null)
                        {
                          riid = typeof( IVideoWindow ).GUID;
                          hr = _dvdGraph.GetDvdInterface( ref riid, out comobj );
                          if( hr < 0 )
                            Marshal.ThrowExceptionForHR( hr );
                          _videoWin = (IVideoWindow) comobj; comobj = null;
                        }
                  */
                // GetFrameStepInterface();

                DirectShowUtil.SetARMode(_graphBuilder, arMode);
                DirectShowUtil.EnableDeInterlace(_graphBuilder);
                //m_ovMgr = new OVTOOLLib.OvMgrClass();
                //m_ovMgr.SetGraph(_graphBuilder);

                return true;
            }
            catch (Exception)
            {

                //MessageBox.Show( this, "Could not get interfaces\r\n" + ee.Message, "DVDPlayer.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop );
                CloseDVDInterfaces();
                return false;
            }
            finally
            {
                if (comobj != null)
                {
                    DirectShowUtil.ReleaseComObject(comobj);
                }
                comobj = null;
            }
        }
コード例 #24
0
        /// <summary> Shut down capture </summary>
        private void CloseInterfaces()
        {
            int hr;

            try
            {
                if (m_handle != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(m_handle);
                    m_handle = IntPtr.Zero;
                }
            }
            catch (Exception)
            {
            }

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

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

            if (this.mediaSeeking != null)
            {
                this.mediaSeeking = null;
            }
            if (this.frameStep != null)
            {
                this.frameStep = null;
            }

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

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

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

            GC.Collect();
        }
コード例 #25
0
ファイル: MainForm.cs プロジェクト: coolsula/vidplaycorder
        private void CloseInterfaces()
        {
            int hr = 0;

              try
              {
            lock(this)
            {
              // Relinquish ownership (IMPORTANT!) after hiding video window
              if (!this.isAudioOnly)
              {
            hr = this.videoWindow.put_Visible(OABool.False);
            DsError.ThrowExceptionForHR(hr);
            hr = this.videoWindow.put_Owner(IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);
              }

              if (this.mediaEventEx != null)
              {
            hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);
              }

            #if DEBUG
              if (rot != null)
              {
            rot.Dispose();
            rot = null;
              }
            #endif
              // Release and zero DirectShow interfaces
              if (this.mediaEventEx != null)
            this.mediaEventEx = null;
              if (this.mediaSeeking != null)
            this.mediaSeeking = null;
              if (this.mediaPosition != null)
            this.mediaPosition = null;
              if (this.mediaControl != null)
            this.mediaControl = null;
              if (this.basicAudio != null)
            this.basicAudio = null;
              if (this.basicVideo != null)
            this.basicVideo = null;
              if (this.videoWindow != null)
            this.videoWindow = null;
              if (this.frameStep != null)
            this.frameStep = null;
              if (this.graphBuilder != null)
            Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null;

              GC.Collect();
            }
              }
              catch
              {
              }
        }
コード例 #26
0
        /// <summary> detect if we can single step. </summary>
        bool GetFrameStepInterface()
        {
            videoStep = graphBuilder as IVideoFrameStep;
            if( videoStep == null )
            {
                return false;
            }

            // Check if this decoder can step
            int hr = videoStep.CanStep( 0, null );
            if( hr != 0 )
            {
                videoStep = null;
                return false;
            }
            return true;
        }
コード例 #27
0
        public void CloseFile()
        {
            int hr = 0;

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

            // Free DirectShow interfaces
            try
            {
                lock (this)
                {
                    // Relinquish ownership after hiding video window
                    if (this.MediaType == MediaType.AudioVideo)
                    {
                        hr = this.videoWindow.put_Visible(OABool.False);
                        DsError.ThrowExceptionForHR(hr);

                        hr = this.videoWindow.put_Owner(IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }

                    if (this.mediaEventEx != null)
                    {
                        hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }

                    // Release and zero DirectShow interfaces
                    if (this.mediaEventEx != null)
                    {
                        this.mediaEventEx = null;
                    }
                    if (this.mediaSeeking != null)
                    {
                        this.mediaSeeking = null;
                    }
                    if (this.mediaPosition != null)
                    {
                        this.mediaPosition = null;
                    }
                    if (this.mediaControl != null)
                    {
                        this.mediaControl = null;
                    }
                    if (this.basicAudio != null)
                    {
                        this.basicAudio = null;
                    }
                    if (this.basicVideo != null)
                    {
                        this.basicVideo = null;
                    }
                    if (this.videoWindow != null)
                    {
                        this.videoWindow = null;
                    }
                    if (this.frameStep != null)
                    {
                        this.frameStep = null;
                    }

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

                    GC.Collect();
                }
            }
            catch { }

            // Reset properties
            this.MediaFile      = null;
            this.MediaType      = MediaType.Unknown;
            this.Length         = null;
            this.Resolution     = null;
            this.PlaybackStatus = PlayState.Closed;
        }
コード例 #28
0
ファイル: VideoFramePusher.cs プロジェクト: DeSciL/Ogama
    // Some video renderers support stepping media frame by frame with the
    // IVideoFrameStep interface.  See the interface documentation for more
    // details on frame stepping.
    private bool GetFrameStepInterface()
    {
      int hr = 0;

      // Get the frame step interface, if supported
      IVideoFrameStep frameStepTest = this.graphBuilder as IVideoFrameStep;

      // Check if this decoder can step
      hr = frameStepTest.CanStep(0, null);
      if (hr == 0)
      {
        this.frameStep = frameStepTest;
        return true;
      }
      else
      {
        this.frameStep = null;
        return false;
      }
    }
コード例 #29
0
        private void CloseInterfaces()
        {
            int hr = 0;

            try
            {
                lock (this)
                {
                    // Relinquish ownership (IMPORTANT!) after hiding video window
                    hr = this.videoWindow.put_Visible(OABool.False);
                    DsError.ThrowExceptionForHR(hr);
                    hr = this.videoWindow.put_Owner(IntPtr.Zero);
                    DsError.ThrowExceptionForHR(hr);
                    if (this.mediaEventEx != null)
                    {
                        hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }
                    // Release and zero DirectShow interfaces
                    if (this.mediaEventEx != null)
                    {
                        this.mediaEventEx = null;
                    }
                    if (this.mediaSeeking != null)
                    {
                        this.mediaSeeking = null;
                    }
                    if (this.mediaPosition != null)
                    {
                        this.mediaPosition = null;
                    }
                    if (this.mediaControl != null)
                    {
                        this.mediaControl = null;
                    }
                    if (this.basicAudio != null)
                    {
                        this.basicAudio = null;
                    }
                    if (this.basicVideo != null)
                    {
                        this.basicVideo = null;
                    }
                    if (this.videoWindow != null)
                    {
                        this.videoWindow = null;
                    }
                    if (this.frameStep != null)
                    {
                        this.frameStep = null;
                    }
                    if (this.graphBuilder != null)
                    {
                        Marshal.ReleaseComObject(this.graphBuilder);
                    }
                    this.graphBuilder = null;
                    GC.Collect();
                }
            }
            catch
            {
                //what to do?
            }
        }
コード例 #30
0
        /// <summary>
        /// Open a new video feed (either web-cam or video file).
        /// </summary>
        /// <param name="filter">Specifies the web-cam filter to use, or <i>null</i> when opening a video file.</param>
        /// <param name="pb">Specifies the output window, or <i>null</i> when running headless and only receiving snapshots.</param>
        /// <param name="strFile">Specifies the video file to use, or <i>null</i> when opening a web-cam feed.</param>
        /// <param name="vidCap">Optionally specifies the video capabilities to use, or <i>null</i> to ignore and use the default video capabilities.</param>
        /// <returns>The duration (if any) is returned, or 0.</returns>
        /// <remarks>To get the video capabilities see the GetVideoCapatiblities method.</remarks>
        public long Open(Filter filter, PictureBox pb, string strFile, VideoCapability vidCap = null)
        {
            int hr;

            if (filter != null && strFile != null)
            {
                throw new ArgumentException("Both the filter and file are non NULL - only one of these can be used at a time; The filter is used with the web-cam and the file is used with a video file.");
            }

            m_selectedFilter = filter;
            m_graphBuilder   = (IFilterGraph2)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.FilterGraph, true));

            // When using a web-cam, create the moniker for the filter and add the filter to the graph.
            if (strFile == null)
            {
                IMoniker moniker = m_selectedFilter.CreateMoniker();
                m_graphBuilder.AddSourceFilterForMoniker(moniker, null, m_selectedFilter.Name, out m_camFilter);
                Marshal.ReleaseComObject(moniker);
                m_camControl = m_camFilter as IAMCameraControl;

                // Create the capture builder used to build the web-cam filter graph.
                m_captureGraphBuilder = (ICaptureGraphBuilder2)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.CaptureGraphBuilder2, true));
                hr = m_captureGraphBuilder.SetFiltergraph(m_graphBuilder as IGraphBuilder);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Add the web-cam filter to the graph.
                hr = m_graphBuilder.AddFilter(m_camFilter, m_selectedFilter.Name);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Set the desired video capabilities.
                if (vidCap != null)
                {
                    setVideoCapabilities(m_captureGraphBuilder, m_camFilter, vidCap);
                }
            }
            else
            {
                // Build the graph with the video file.
                hr = m_graphBuilder.RenderFile(strFile, null);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                m_mediaSeek = m_graphBuilder as IMediaSeeking;

                if (pb != null)
                {
                    m_videoFrameStep = m_graphBuilder as IVideoFrameStep;
                }
            }

            // Create the sample grabber used to get snapshots.
            m_sampleGrabber  = (ISampleGrabber)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.SampleGrabber, true));
            m_baseGrabFilter = m_sampleGrabber as IBaseFilter;
            m_mediaControl   = m_graphBuilder as IMediaControl;

            // When using a target window, get the video window used with the target output window
            if (pb != null)
            {
                m_mediaEventEx = m_graphBuilder as IMediaEventEx;
                m_videoWindow  = m_graphBuilder as IVideoWindow;
            }
            // Otherwise create the null renderer for no video output is needed (only snapshots).
            else
            {
                m_nullRenderer = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(Clsid.NullRenderer, true));
            }

            // Add the sample grabber to the filter graph.
            hr = m_graphBuilder.AddFilter(m_baseGrabFilter, "Ds.Lib Grabber");
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // Turn off the sample grabber buffers.
            hr = m_sampleGrabber.SetBufferSamples(false);
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // Turn off the sample grabber one-shot.
            hr = m_sampleGrabber.SetOneShot(false);
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // Turn ON the sample grabber callback where video data is to be received.
            hr = m_sampleGrabber.SetCallback(this, 1);
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // Set the media format used by the sample grabber.
            AMMediaType media = new AMMediaType();

            media.majorType  = MediaType.Video;
            media.subType    = MediaSubType.RGB24;
            media.formatType = FormatType.VideoInfo;

            hr = m_sampleGrabber.SetMediaType(media);
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // Connect the WebCam Filters and Frame Grabber.
            if (m_selectedFilter != null)
            {
                Guid cat;
                Guid med;

                cat = PinCategory.Preview;
                med = MediaType.Video;
                hr  = m_captureGraphBuilder.RenderStream(ref cat, ref med, m_camFilter, null, null);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                cat = PinCategory.Capture;
                med = MediaType.Video;
                hr  = m_captureGraphBuilder.RenderStream(ref cat, ref med, m_camFilter, null, m_baseGrabFilter);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }
            // Connect the Frame Grabber and (optionally the Null Renderer)
            else
            {
                // Get the video decoder and its pins.
                m_videoFilter = Utility.GetFilter(m_graphBuilder as IGraphBuilder, "Video Decoder", false);

                IPin pOutput;
                hr = Utility.GetPin(m_videoFilter, PinDirection.Output, out pOutput);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                IPin pInput;
                hr = pOutput.ConnectedTo(out pInput);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                PinInfo pinInfo;
                hr = pInput.QueryPinInfo(out pinInfo);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Get the sample grabber pins.
                IPin pGrabInput;
                hr = Utility.GetPin(m_baseGrabFilter, PinDirection.Input, out pGrabInput);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                IPin pGrabOutput;
                hr = Utility.GetPin(m_baseGrabFilter, PinDirection.Output, out pGrabOutput);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Disconnect the source filter output and the input it is connected to.
                hr = pOutput.Disconnect();
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                hr = pInput.Disconnect();
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Connect the source output to the Grabber input.
                hr = m_graphBuilder.Connect(pOutput, pGrabInput);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // When rendering video output, connect the Grabber output to the original downstream input that the source was connected to.
                if (m_nullRenderer == null)
                {
                    hr = m_graphBuilder.Connect(pGrabOutput, pInput);
                    if (hr < 0)
                    {
                        Marshal.ThrowExceptionForHR(hr);
                    }
                }

                Marshal.ReleaseComObject(pOutput);
                Marshal.ReleaseComObject(pInput);
                Marshal.ReleaseComObject(pGrabInput);
                Marshal.ReleaseComObject(pGrabOutput);
            }

            // Remove sound filters.
            IBaseFilter soundFilter = Utility.GetFilter(m_graphBuilder as IGraphBuilder, "Audio Decoder", false);

            if (soundFilter != null)
            {
                hr = m_graphBuilder.RemoveFilter(soundFilter);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                Marshal.ReleaseComObject(soundFilter);
            }

            soundFilter = Utility.GetFilter(m_graphBuilder as IGraphBuilder, "Sound", false);
            if (soundFilter != null)
            {
                hr = m_graphBuilder.RemoveFilter(soundFilter);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                Marshal.ReleaseComObject(soundFilter);
            }

            // When using a headless (no video rendering) setup, connect the null renderer to the Sample Grabber.
            if (m_nullRenderer != null)
            {
                // Add the null renderer.
                hr = m_graphBuilder.AddFilter(m_nullRenderer, "Null Renderer");
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Get the sample grabber output pin.
                IPin pGrabOutput;
                hr = Utility.GetPin(m_baseGrabFilter, PinDirection.Output, out pGrabOutput);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Get the null renderer input pin.
                IPin pInput;
                hr = Utility.GetPin(m_nullRenderer, PinDirection.Input, out pInput);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Disconnect the sample grabber pin.
                hr = pGrabOutput.Disconnect();
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Connect the Grabber output to the null renderer.
                hr = m_graphBuilder.Connect(pGrabOutput, pInput);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                Marshal.ReleaseComObject(pInput);
                Marshal.ReleaseComObject(pGrabOutput);

                // Remove the Video Renderer for it is no longer needed.
                IBaseFilter ivideorender = Utility.GetFilter(m_graphBuilder as IGraphBuilder, "Video Renderer");
                if (ivideorender != null)
                {
                    m_graphBuilder.RemoveFilter(ivideorender);
                    Marshal.ReleaseComObject(ivideorender);
                }
            }

            // Get the sample grabber media settings and video header.
            media = new AMMediaType();
            hr    = m_sampleGrabber.GetConnectedMediaType(media);
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            if ((media.formatType != FormatType.VideoInfo &&
                 media.formatType != FormatType.WaveEx &&
                 media.formatType != FormatType.MpegVideo) ||
                media.formatPtr == IntPtr.Zero)
            {
                throw new Exception("Media grabber format is unknown.");
            }

            // Get the video header with frame sizing information.
            m_videoInfoHeader = Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader)) as VideoInfoHeader;
            Marshal.FreeCoTaskMem(media.formatPtr);
            media.formatPtr = IntPtr.Zero;

            // If we are rendering video output, setup the video window (which requires a message pump).
            if (m_videoWindow != null)
            {
                // setup the video window
                hr = m_videoWindow.put_Owner(pb.Handle);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                hr = m_videoWindow.put_WindowStyle(WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }


                // resize the window
                hr = m_videoWindow.SetWindowPosition(0, 0, pb.Width, pb.Height);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                hr = m_videoWindow.put_Visible(DsHlp.OATRUE);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                // Subscribe to the picturebox size changed event.
                pb.SizeChanged += Pb_SizeChanged;
            }


            // start the capturing
            hr = m_mediaControl.Run();
            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            // When using a video file, immediately stop at the start.
            if (strFile != null)
            {
                hr = m_mediaControl.Pause();
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            // When using a media file, we need to save the video file's duration.
            if (m_mediaSeek != null)
            {
                hr = m_mediaSeek.GetDuration(out m_lDuration);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }
            }

            m_bConnected = true;

            return(m_lDuration);
        }
コード例 #31
0
        public void CloseInterfaces()
        {
            int hr = 0;

            try
            {
                lock (this)
                {
                    // Relinquish ownership (IMPORTANT!) after hiding video window
                    if (!isAudioOnly)
                    {
                        hr = videoWindow.put_Visible(OABool.False);
                        DsError.ThrowExceptionForHR(hr);
                        hr = videoWindow.put_Owner(IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }

                    if (mediaEventEx != null)
                    {
                        hr = mediaEventEx.SetNotifyWindow(IntPtr.Zero, 0, IntPtr.Zero);
                        DsError.ThrowExceptionForHR(hr);
                    }

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

                    // Release and zero DirectShow interfaces
                    if (mediaEventEx != null)
                    {
                        mediaEventEx = null;
                    }
                    if (mediaSeeking != null)
                    {
                        mediaSeeking = null;
                    }
                    if (mediaPosition != null)
                    {
                        mediaPosition = null;
                    }
                    if (mediaControl != null)
                    {
                        mediaControl = null;
                    }
                    if (basicAudio != null)
                    {
                        basicAudio = null;
                    }
                    if (basicVideo != null)
                    {
                        basicVideo = null;
                    }
                    if (videoWindow != null)
                    {
                        videoWindow = null;
                    }
                    if (frameStep != null)
                    {
                        frameStep = null;
                    }
                    if (graphBuilder != null)
                    {
                        Marshal.ReleaseComObject(graphBuilder);
                    }
                    graphBuilder = null;

                    // Tuner stuff
                    if (captureGraphBuilder != null)
                    {
                        Marshal.ReleaseComObject(captureGraphBuilder);
                    }
                    captureGraphBuilder = null;

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

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

                    //temp
                    if (sourceFilter != null)
                    {
                        Marshal.ReleaseComObject(sourceFilter);
                        sourceFilter = null;
                    }
                    GC.Collect();
                }
            }
            catch
            {
            }
        }
コード例 #32
0
ファイル: Grabber.cs プロジェクト: andrewjswan/mvcentral
        /// <summary> do cleanup and release DirectShow. </summary>
        protected virtual void CloseDVDInterfaces()
        {
            if (_graphBuilder == null)
            {
                return;
            }
            int hr;
            try
            {
                logger.Info("DVDPlayer:cleanup DShow graph");

                if (_mediaCtrl != null)
                {
                    hr = _mediaCtrl.Stop();
                    _mediaCtrl = null;
                }
                _state = PlayState.Stopped;

                _mediaEvt = null;
                _visible = false;
                _videoWin = null;
                //				videoStep	= null;
                _dvdCtrl = null;
                _dvdInfo = null;
                _basicVideo = null;
                _basicAudio = null;
                _mediaPos = null;
                _mediaSeek = null;
                _mediaStep = null;

                //if (_vmr7 != null)
                //{
                //    _vmr7.RemoveVMR7();
                //}
                //_vmr7 = null;

                if (_vmr9Filter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_vmr9Filter)) > 0)
                    {
                        ;
                    }
                    _vmr9Filter = null;
                }

                if (_dvdbasefilter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_dvdbasefilter)) > 0)
                    {
                        ;
                    }
                    _dvdbasefilter = null;
                }

                if (_cmdOption != null)
                {
                    DirectShowUtil.ReleaseComObject(_cmdOption);
                }
                _cmdOption = null;
                _pendingCmd = false;
                if (_line21Decoder != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_line21Decoder)) > 0)
                    {
                        ;
                    }
                    _line21Decoder = null;
                }

                if (_graphBuilder != null)
                {
                    DirectShowUtil.RemoveFilters(_graphBuilder);
                    if (_rotEntry != null)
                    {
                        _rotEntry.Dispose();
                        _rotEntry = null;
                    }
                    while ((hr = DirectShowUtil.ReleaseComObject(_graphBuilder)) > 0)
                    {
                        ;
                    }
                    _graphBuilder = null;
                }

                if (_dvdGraph != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_dvdGraph)) > 0)
                    {
                        ;
                    }
                    _dvdGraph = null;
                }
                _state = PlayState.Init;

            }
            catch (Exception ex)
            {
                logger.Error("DVDPlayer:exception while cleanuping DShow graph {0} {1}", ex.Message, ex.StackTrace);
            }
        }
コード例 #33
0
ファイル: Grabber.cs プロジェクト: RoChess/mvcentral
        private void BuildGraph()
        {
            int hr;

            try
            {
                lblTotalTime.Text = mvs.PlayTime.ToString();
                TimeSpan tt = TimeSpan.Parse(mvs.PlayTime);
                DateTime dt = new DateTime(tt.Ticks);
                lblTotalTime.Text = String.Format("{0:HH:mm:ss}", dt);

                if (mvs.LocalMedia[0].IsDVD)
                {
                    mediaToPlay = mvs.LocalMedia[0];
                    MediaState mediaState = mediaToPlay.State;
                    if (mediaState == MediaState.NotMounted)
                    {
                        MountResult result = mediaToPlay.Mount();
                    }



                    string videoPath = mediaToPlay.GetVideoPath();

                    if (videoPath != null)
                    {
                        FirstPlayDvd(videoPath);
                    }
                    else
                    {
                        FirstPlayDvd(mvs.LocalMedia[0].File.FullName);
                    }
                    // Add delegates for Windowless operations
                    AddHandlers();
                    MainForm_ResizeMove(null, null);
                }
                else
                {
                    _graphBuilder = (IFilterGraph2) new FilterGraph();
                    _rotEntry     = new DsROTEntry((IFilterGraph)_graphBuilder);
                    _mediaCtrl    = (IMediaControl)_graphBuilder;
                    _mediaSeek    = (IMediaSeeking)_graphBuilder;
                    _mediaPos     = (IMediaPosition)_graphBuilder;
                    _mediaStep    = (IVideoFrameStep)_graphBuilder;
                    _vmr9Filter   = (IBaseFilter) new VideoMixingRenderer9();
                    ConfigureVMR9InWindowlessMode();
                    AddHandlers();
                    MainForm_ResizeMove(null, null);
                    hr = _graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Render 9");
                    AddPreferedCodecs(_graphBuilder);
                    DsError.ThrowExceptionForHR(hr);
                    hr = _graphBuilder.RenderFile(mvs.LocalMedia[0].File.FullName, null);
                    DsError.ThrowExceptionForHR(hr);
                }
            }
            catch (Exception e)
            {
                CloseDVDInterfaces();
                logger.ErrorException("An error occured during the graph building : \r\n\r\n", e);
            }
        }
コード例 #34
0
ファイル: Grabber.cs プロジェクト: andrewjswan/mvcentral
        private void BuildGraph()
        {
            int hr;
            try
            {
                lblTotalTime.Text = mvs.PlayTime.ToString();
                TimeSpan tt = TimeSpan.Parse(mvs.PlayTime);
                DateTime dt = new DateTime(tt.Ticks);
                lblTotalTime.Text = String.Format("{0:HH:mm:ss}", dt);

                if (mvs.LocalMedia[0].IsDVD)
                {

                    mediaToPlay = mvs.LocalMedia[0];
                    MediaState mediaState = mediaToPlay.State;
                    if (mediaState == MediaState.NotMounted)
                    {
                        MountResult result = mediaToPlay.Mount();
                    }

                    string videoPath = mediaToPlay.GetVideoPath();

                    if (videoPath != null)
                        FirstPlayDvd(videoPath);
                    else
                      FirstPlayDvd(mvs.LocalMedia[0].File.FullName);
                    // Add delegates for Windowless operations
                    AddHandlers();
                    MainForm_ResizeMove(null, null);

                }
                else
                {
                    _graphBuilder = (IFilterGraph2)new FilterGraph();
                    _rotEntry = new DsROTEntry((IFilterGraph)_graphBuilder);
                    _mediaCtrl = (IMediaControl)_graphBuilder;
                    _mediaSeek = (IMediaSeeking)_graphBuilder;
                    _mediaPos = (IMediaPosition)_graphBuilder;
                    _mediaStep = (IVideoFrameStep)_graphBuilder;
                    _vmr9Filter = (IBaseFilter)new VideoMixingRenderer9();
                    ConfigureVMR9InWindowlessMode();
                    AddHandlers();
                    MainForm_ResizeMove(null, null);
                    hr = _graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Render 9");
                    AddPreferedCodecs(_graphBuilder);
                    DsError.ThrowExceptionForHR(hr);
                    hr = _graphBuilder.RenderFile(mvs.LocalMedia[0].File.FullName, null);
                    DsError.ThrowExceptionForHR(hr);
                }

            }
            catch (Exception e)
            {
                CloseDVDInterfaces();
                logger.ErrorException("An error occured during the graph building : \r\n\r\n",e);
            }
        }
コード例 #35
0
ファイル: Grabber.cs プロジェクト: RoChess/mvcentral
        /// <summary> do cleanup and release DirectShow. </summary>
        protected virtual void CloseDVDInterfaces()
        {
            if (_graphBuilder == null)
            {
                return;
            }
            int hr;

            try
            {
                logger.Info("DVDPlayer:cleanup DShow graph");

                if (_mediaCtrl != null)
                {
                    hr         = _mediaCtrl.Stop();
                    _mediaCtrl = null;
                }
                _state = PlayState.Stopped;

                _mediaEvt = null;
                _visible  = false;
                _videoWin = null;
                //				videoStep	= null;
                _dvdCtrl    = null;
                _dvdInfo    = null;
                _basicVideo = null;
                _basicAudio = null;
                _mediaPos   = null;
                _mediaSeek  = null;
                _mediaStep  = null;

                //if (_vmr7 != null)
                //{
                //    _vmr7.RemoveVMR7();
                //}
                //_vmr7 = null;



                if (_vmr9Filter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_vmr9Filter)) > 0)
                    {
                        ;
                    }
                    _vmr9Filter = null;
                }

                if (_dvdbasefilter != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_dvdbasefilter)) > 0)
                    {
                        ;
                    }
                    _dvdbasefilter = null;
                }

                if (_cmdOption != null)
                {
                    DirectShowUtil.ReleaseComObject(_cmdOption);
                }
                _cmdOption  = null;
                _pendingCmd = false;
                if (_line21Decoder != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_line21Decoder)) > 0)
                    {
                        ;
                    }
                    _line21Decoder = null;
                }


                if (_graphBuilder != null)
                {
                    DirectShowUtil.RemoveFilters(_graphBuilder);
                    if (_rotEntry != null)
                    {
                        _rotEntry.Dispose();
                        _rotEntry = null;
                    }
                    while ((hr = DirectShowUtil.ReleaseComObject(_graphBuilder)) > 0)
                    {
                        ;
                    }
                    _graphBuilder = null;
                }

                if (_dvdGraph != null)
                {
                    while ((hr = DirectShowUtil.ReleaseComObject(_dvdGraph)) > 0)
                    {
                        ;
                    }
                    _dvdGraph = null;
                }
                _state = PlayState.Init;
            }
            catch (Exception ex)
            {
                logger.Error("DVDPlayer:exception while cleanuping DShow graph {0} {1}", ex.Message, ex.StackTrace);
            }
        }
コード例 #36
0
ファイル: MainForm.cs プロジェクト: coolsula/vidplaycorder
        //
        // Some video renderers support stepping media frame by frame with the
        // IVideoFrameStep interface.  See the interface documentation for more
        // details on frame stepping.
        //
        private bool GetFrameStepInterface()
        {
            int hr = 0;

              IVideoFrameStep frameStepTest = null;

              // Get the frame step interface, if supported
              frameStepTest = (IVideoFrameStep) this.graphBuilder;

              // Check if this decoder can step
              hr = frameStepTest.CanStep(0, null);
              if (hr == 0)
              {
            this.frameStep = frameStepTest;
            return true;
              }
              else
              {
            // BUG 1560263 found by husakm (thanks)...
            // Marshal.ReleaseComObject(frameStepTest);
            this.frameStep = null;
            return false;
              }
        }
コード例 #37
0
 protected virtual HRESULT PreparePlayback()
 {
     m_MediaControl = (IMediaControl)m_GraphBuilder;
     m_BasicVideo = (IBasicVideo)m_GraphBuilder;
     m_MediaSeeking = (IMediaSeeking)m_GraphBuilder;
     m_VideoWindow = (IVideoWindow)m_GraphBuilder;
     m_MediaEventEx = (IMediaEventEx)m_GraphBuilder;
     m_FrameStep = (IVideoFrameStep)m_GraphBuilder;
     SettingUpVideoWindow();
     int hr = m_MediaEventEx.SetNotifyWindow(m_EventControl.Handle, WM_GRAPHNOTIFY, Marshal.GetIUnknownForObject(this));
     Debug.Assert(hr == 0);
     SetVolume(m_bMute ? -10000 : m_iVolume);
     if (m_dRate != 1.0)
     {
         m_MediaSeeking.SetRate(m_dRate);
         m_MediaSeeking.GetRate(out m_dRate);
     }
     if (OnPlaybackReady != null) OnPlaybackReady(this, EventArgs.Empty);
     return (HRESULT)hr;
 }