Example #1
0
        public void Run()
        {
            media_control = GraphBuilder as IMediaControl;

            media_event = GraphBuilder as IMediaEvent;

            Console.WriteLine("Started filter graph");
            media_control.Run();

            bool stop = false;

            while (!stop)
            {
                System.Threading.Thread.Sleep(500);
                Console.Write(".");
                EventCode ev;
                IntPtr    p1, p2;
                if (media_event.GetEvent(out ev, out p1, out p2, 0) == 0)
                {
                    if (ev == EventCode.Complete || ev == EventCode.UserAbort)
                    {
                        Console.WriteLine("Done");
                        stop = true;
                        media_control.Stop();
                    }
                    else if (ev == EventCode.ErrorAbort)
                    {
                        Console.WriteLine("An Error occurred: HRESULT={0:X}", p1);
                        media_control.Stop();
                        stop = true;
                    }
                    media_event.FreeEventParams(ev, p1, p2);
                }
            }
        }
Example #2
0
        /// <summary>
        /// This constructor internally build a DirectShow graph using the given file name parameter.
        /// </summary>
        /// <param name="filename">A media file.</param>
        /// <remarks>This constructor use the BlackListManager class to bane the use of the ffdshow Audio and Video decoders during the Intelligent Connect graph building.</remarks>
        public SimplePlayer(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentNullException("filename");
            }

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

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

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

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

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

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

            this.mediaControl = (IMediaControl)this.graphBuilder;
            this.mediaEvent   = (IMediaEvent)this.graphBuilder;
        }
Example #3
0
        /// <summary>
        /// This constructor internally build a DirectShow graph using the given file name parameter.
        /// </summary>
        /// <param name="filename">A media file.</param>
        /// <remarks>This constructor use the BlackListManager class to bane the use of the ffdshow Audio and Video decoders during the Intelligent Connect graph building.</remarks>
        public SimplePlayer(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            throw new ArgumentNullException("filename");

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

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

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

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

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

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

              this.mediaControl = (IMediaControl)this.graphBuilder;
              this.mediaEvent = (IMediaEvent)this.graphBuilder;
        }
Example #4
0
        private bool PlayVideo(string path)
        {
            CleanUp();

            FilterGraph = new FilgraphManager();
            FilterGraph.RenderFile(path);

            BasicAudio = FilterGraph as IBasicAudio;

            try
            {
                VideoWindow             = FilterGraph as IVideoWindow;
                VideoWindow.Owner       = (int)panel1.Handle;
                VideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                VideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                                              panel1.ClientRectangle.Top,
                                              panel1.ClientRectangle.Width,
                                              panel1.ClientRectangle.Height);
            }
            catch (Exception)
            {
                VideoWindow = null;
                return(false);
            }

            MediaEvent   = FilterGraph as IMediaEvent;
            MediaEventEx = FilterGraph as IMediaEventEx;

            MediaPosition = FilterGraph as IMediaPosition;
            MediaControl  = FilterGraph as IMediaControl;

            MediaControl.Run();
            return(true);
        }
Example #5
0
        private void TestCalibrate()
        {
            //No hardware
            IMediaEventSink mes;
            IFilterGraph2   FilterGraph;
            int             hr;

            FilterGraph = (IFilterGraph2) new FilterGraph();

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

            mes = (IMediaEventSink)FilterGraph;
            IMediaEvent pEvent = (IMediaEvent)FilterGraph;


            int ret = 0;

            IntPtr eventHandle = IntPtr.Zero;

            hr = pEvent.GetEventHandle(out eventHandle);
            DsError.ThrowExceptionForHR(hr);

            hr = _extDevice.Calibrate(eventHandle, ExtTransportEdit.Active, out ret);
            //DsError.ThrowExceptionForHR(hr); //E_NOTIMPL , but atleast it's called.

            hr = _extDevice.Calibrate(eventHandle, 0, out ret);
            //DsError.ThrowExceptionForHR(hr); //E_NOTIMPL , but atleast it's called.
        }
Example #6
0
        public CaptureStegoProcess(IMoniker moniker)
        {
            Guid   baseFilterGuid = typeof(IBaseFilter).GUID;
            object o;

            ///Get our device ready
            moniker.BindToObject(null, null, ref baseFilterGuid, out o);
            this._captureFilter = (IBaseFilter)o;

            this._graphBuilder = (IGraphBuilder) new FilterGraph();

            this._captureBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            ///Tell capture graph about filter graph builder
            this._captureBuilder.SetFiltergraph(this._graphBuilder);

            this._mediaCtrl   = (IMediaControl)this._graphBuilder;
            this._mediaEvent  = (IMediaEvent)this._graphBuilder;
            this._videoWindow = (IVideoWindow)this._graphBuilder;

            ///Code for stoping capturing
            this.OnStopCapture = delegate()
            {
                if (this._mediaCtrl != null)
                {
                    int hr = this._mediaCtrl.StopWhenReady();
                }
                base._processing = ProcessingType.Done;
                this._videoWindow.put_Visible(OABool.False);
            };
        }
        private void TestLogError()
        {
            int           hr;
            IGraphBuilder fg;
            IRenderEngine ire = new RenderEngine() as IRenderEngine;

            hr = ire.SetTimelineObject(m_pTimeline);
            DESError.ThrowExceptionForHR(hr);

            hr = ire.ConnectFrontEnd();
            DESError.ThrowExceptionForHR(hr);

            hr = ire.RenderOutputPins();
            DESError.ThrowExceptionForHR(hr);

            hr = ire.GetFilterGraph(out fg);
            DESError.ThrowExceptionForHR(hr);

            hr = ((IMediaControl)fg).Run();
            DESError.ThrowExceptionForHR(hr);

            IMediaEvent ime = fg as IMediaEvent;
            EventCode   evCode;
            const int   E_Abort = unchecked ((int)0x80004004);

            do
            {
                System.Windows.Forms.Application.DoEvents();
                System.Threading.Thread.Sleep(100);
                hr = ime.WaitForCompletion(1000, out evCode);
            } while (evCode == (EventCode)E_Abort);

            Debug.Assert(m_Called == true, "LogError");
        }
Example #8
0
        private void CloseInterfaces()
        {
            while (!m_WaitUntilDoneIsDone)
            {
                Thread.Sleep(1);
            }

            if (!m_WaitUntilDoneIsDone)
            {
                MessageBox.Show("wait not done");
            }

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

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

                if (handlersAdded)
                {
                    RemoveHandlers();
                }

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

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

                if (graphBuilder != null)
                {
                    Marshal.ReleaseComObject(graphBuilder);
                    graphBuilder = null;
                    mediaControl = null;
                }
            }
            catch { }
        }
Example #9
0
        public void Run()
        {
            if (!string.IsNullOrWhiteSpace(this.Source))
            {
                if (this.State == MediaStatus.Stopped)
                {
                    try
                    {
                        filterGraph = new FilgraphManager();

                        this.filterGraph.RenderFile(this.Source);
                        basicAudio = filterGraph as IBasicAudio;

                        try
                        {
                            videoWindow             = filterGraph as IVideoWindow;
                            videoWindow.Owner       = (int)this.Handle;
                            videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                            videoWindow.SetWindowPosition(this.ClientRectangle.Left, this.ClientRectangle.Top, this.ClientRectangle.Width, this.ClientRectangle.Height);
                        }
                        catch (Exception)
                        {
                            videoWindow = null;
                        }

                        mediaEvent = filterGraph as IMediaEvent;

                        mediaEventEx = filterGraph as IMediaEventEx;
                        mediaEventEx.SetNotifyWindow((int)base.Handle, WM_GRAPHNOTIFY, 0);

                        mediaPosition = filterGraph as IMediaPosition;

                        mediaControl = filterGraph as IMediaControl;
                    }
                    catch
                    {
                        try
                        {
                            mediaControl.StopWhenReady();
                        }
                        catch
                        {
                            mediaControl.Stop();
                        }

                        this.CleanUp();
                        this.State = MediaStatus.Stopped;
                        throw;
                    }
                }

                if (this.State != MediaStatus.Running)
                {
                    this.mediaControl.Run();
                    this.State = MediaStatus.Running;
                }
            }
        }
Example #10
0
        /// <summary>
        /// Called on a new thread to process events from the graph.  The thread
        /// exits when the graph finishes.
        /// </summary>
        private void EventWait()
        {
            // Returned when GetEvent is called but there are no events
            const int E_ABORT = unchecked ((int)0x80004004);

            int       hr;
            IntPtr    p1, p2;
            EventCode ec;
            EventCode exitCode = 0;

            IMediaEvent mediaEvent = (IMediaEvent)this.filterGraph;

            do
            {
                // Read the event
                for (hr = mediaEvent.GetEvent(out ec, out p1, out p2, 100);
                     hr >= 0;
                     hr = mediaEvent.GetEvent(out ec, out p1, out p2, 100))
                {
                    switch (ec)
                    {
                    // If the clip is finished playing
                    case EventCode.EndOfSegment:
                    case EventCode.StreamControlStopped:
                    case EventCode.Complete:
                    case EventCode.ErrorAbort:
                    case EventCode.UserAbort:
                        exitCode = ec;

                        // Release any resources the message allocated
                        hr = mediaEvent.FreeEventParams(ec, p1, p2);
                        DsError.ThrowExceptionForHR(hr);
                        break;

                    default:
                        // Release any resources the message allocated
                        hr = mediaEvent.FreeEventParams(ec, p1, p2);
                        DsError.ThrowExceptionForHR(hr);
                        break;
                    }
                }

                // If the error that exited the loop wasn't due to running out of events
                if (hr != E_ABORT)
                {
                    DsError.ThrowExceptionForHR(hr);
                }
            }while (exitCode == 0);

            // Send an event saying we are complete
            if (this.Completed != null)
            {
                var ca = new DESCompletedArgs(exitCode);
                this.Completed(this, ca);
            }

            // Exit the thread
        }
Example #11
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        bool GetInterfaces()
        {
            Type   comType = null;
            object comObj  = null;

            try
            {
                graphBuilder = (IGraphBuilder)DsDev.CreateFromCLSID(Clsid.FilterGraph);
                mediaEvt     = (IMediaEvent)graphBuilder;
                AssignTaskToWaitForCompletion(mediaEvt);

                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid riid  = typeof(ICaptureGraphBuilder2).GUID;
                capGraph = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref clsid, ref riid);

                if (atiTVCardFound)
                {
                    wmVideoDecoder = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.AVI_Decompressor);
                }

                stretchVideo   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.Stretch_Video);
                colorConverter = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.ColorSpaceConverter);
                modFrameRate   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.ModifyFrameRate);

                motionVector = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.MotionVector);
                // Vector Grabber
                vectorGrabber = (IVectorGrabber)DsDev.CreateFromCLSID(Clsid.FlowVectorGrabber);

                sampleGrabber = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.SampleGrabber);
                grabberConfig = sampleGrabber as ISampleGrabber;

                mediaCtrl = (IMediaControl)graphBuilder;

                if (videoPreview)
                {
                    teeSplitter   = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.SmartTee);      //.CreateFromMoniker(TeeSplitter);
                    videoRenderer = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.VideoRenderer); // (Clsid.VMR9);
                }

                // Attemp to use VMR9 abandoned for now
                //vmrAllocator = (IVMRSurfaceAllocator9)DsDev.CreateFromCLSID(Clsid.VMR9Allocator);
                baseGrabFlt = (IBaseFilter)vectorGrabber;
                return(true);
            }
            catch (Exception ee)
            {
                LogInfo(LogGroups.Console, "Could not get interfaces\r\n" + ee.Message);
                return(false);
            }
            finally
            {
                if (comObj != null)
                {
                    Marshal.ReleaseComObject(comObj);
                }
                comObj = null;
            }
        }
Example #12
0
        /// <summary>
        /// 열기 메뉴 항목 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void openMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "미디어 파일|*.mpg;*.avi;*.wma;*.wmv;*.mov;*.wav;*.mp2;*.mp3|모든 파일|*.*";

            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                ReleaseResource();

                this.filterGraphManager = new FilgraphManager();

                this.filterGraphManager.RenderFile(openFileDialog.FileName);

                this.basicAudio = this.filterGraphManager as IBasicAudio;

                try
                {
                    this.videoWindow = this.filterGraphManager as IVideoWindow;

                    this.videoWindow.Owner       = (int)this.canvasPanel.Handle;
                    this.videoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;

                    this.videoWindow.SetWindowPosition
                    (
                        this.canvasPanel.ClientRectangle.Left,
                        this.canvasPanel.ClientRectangle.Top,
                        this.canvasPanel.ClientRectangle.Width,
                        this.canvasPanel.ClientRectangle.Height
                    );
                }
                catch (Exception)
                {
                    this.videoWindow = null;
                }

                this.mediaEvent = this.filterGraphManager as IMediaEvent;

                this.mediaEventEX = this.filterGraphManager as IMediaEventEx;

                this.mediaEventEX.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);

                this.mediaPosition = this.filterGraphManager as IMediaPosition;

                this.mediaControl = this.filterGraphManager as IMediaControl;

                this.Text = "DirectShow를 사용해 동영상 재생하기 - [" + openFileDialog.FileName + "]";

                this.mediaControl.Run();

                mediaStatus = MediaStatus.RUNNING;

                UpdateToolBar();
                UpdateStatusBar();
            }
        }
Example #13
0
        private void SetupGraph3(Control hWin, string FileName)
        {
            int hr;

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

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

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

                IBaseFilter pAudioRenderer = (IBaseFilter) new DSoundRender();
                hr = m_FilterGraph.AddFilter(pAudioRenderer, "Audio Renderer");
                DsError.ThrowExceptionForHR(hr);

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

                hr = icgb2.RenderStream(null, MediaType.Audio, sourceFilter, null, pAudioRenderer);
                DsError.ThrowExceptionForHR(hr);

                // Configure the Video Window
                IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
                ConfigureVideoWindow(videoWindow, hWin);

                // Grab some other interfaces
                m_mediaEvent   = m_FilterGraph as IMediaEvent;
                m_mediaCtrl    = m_FilterGraph as IMediaControl;
                m_mediaSeeking = m_FilterGraph as IMediaSeeking;
                m_basicAudio   = m_FilterGraph as IBasicAudio;
            }
            finally
            {
                if (icgb2 != null)
                {
                    Marshal.ReleaseComObject(icgb2);
                    icgb2 = null;
                }
            }
#if DEBUG
            // Double check to make sure we aren't releasing something
            // important.
            GC.Collect();
            GC.WaitForPendingFinalizers();
#endif
        }
Example #14
0
 public Graph(GraphForm gf, IGraphBuilder gb) //for remote graphs
 {
     myform       = gf;
     graphBuilder = gb;
     isFromRot    = true;
     mediaControl = (IMediaControl)graphBuilder;
     mediaSeeking = (IMediaSeeking)graphBuilder;
     mediaEvent   = (IMediaEvent)graphBuilder;
     ReloadGraph();
 }
Example #15
0
 public Graph(GraphForm gf)
 {
     myform       = gf;
     isFromRot    = false;
     graphBuilder = (IGraphBuilder) new FilterGraph();
     rot_entry    = new DsROTEntry(graphBuilder);
     mediaControl = (IMediaControl)graphBuilder;
     mediaSeeking = (IMediaSeeking)graphBuilder;
     mediaEvent   = (IMediaEvent)graphBuilder;
 }
Example #16
0
            /// <summary>
            /// Constructor - provides the fgm to monitor
            /// </summary>
            public FgmEventMonitor(IMediaEvent iME)
            {
                this.iME = iME;

                // Kick off a thread to monitor events in the filtergraph
                eventThread = new Thread(new ThreadStart(Monitor));
                eventThread.IsBackground = true;
                eventThread.Name         = "Fgm Event Monitor";
                eventThread.Start();
            }
Example #17
0
        public LTNetSource(Config.Graph sourceConfig, Control hostControl)
            : base(sourceConfig, hostControl)
        {
            this.Connected = ConnectionState.Disconnected;

            _mediaEvent                 = (IMediaEvent)_graphBuilder;
            dmxMsgReceiveTimer          = new System.Timers.Timer();
            dmxMsgReceiveTimer.Elapsed += new ElapsedEventHandler(dmxMsgReceiveTimer_Elapsed);
            dmxMsgReceiveTimer.Interval = 1000;
        }
Example #18
0
        //////////////////////////////////////////////////////////////////////////////// Function

        #region 리소스 해제하기 - ReleaseResource()

        /// <summary>
        /// 리소스 해제하기
        /// </summary>
        private void ReleaseResource()
        {
            if (this.mediaControl != null)
            {
                this.mediaControl.Stop();
            }

            this.mediaStatus = MediaStatus.STOPPED;

            if (this.mediaEventEX != null)
            {
                this.mediaEventEX.SetNotifyWindow(0, 0, 0);
            }

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

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

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

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

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

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

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

            if (this.filterGraphManager != null)
            {
                this.filterGraphManager = null;
            }
        }
Example #19
0
/*
 * int AddToRot(object UnkGraph)
 * {
 *  IMoniker pMoniker = null;
 *  IRunningObjectTable pROT = null;
 *
 *  GetRunningObjectTable(0, pROT);
 *
 *  CreateItemMoniker("!", "MyMoniker", pMoniker);
 *  {
 *      //pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, pUnkGraph,
 *      //    pMoniker, pdwRegister);
 *      //pMoniker->Release();
 *  }
 *  pROT.Release();
 *
 *  return 0;
 * }
 */
        private void menuItem2_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";

            if (DialogResult.OK == openFileDialog.ShowDialog())
            {
                CleanUp();
                //object Unk;
                m_objFilterGraph = new FilgraphManager();

/*                m_objFilterGraph.AddFilter(
 *                  "D:\\Expert\\onvif\\axis\\RTSP_source.090603\\RTSP_source.ax",
 *                  //"D:\\Expert\\onvif\\axis\\RTSP_source.090603\\RTSP_source.ax",
 *                  out Unk);
 */             m_objFilterGraph.RenderFile(openFileDialog.FileName);

                m_objBasicAudio = m_objFilterGraph as IBasicAudio;

                try
                {
                    m_objVideoWindow             = m_objFilterGraph as IVideoWindow;
                    m_objVideoWindow.Owner       = (int)panel1.Handle;
                    m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                    m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                                                       panel1.ClientRectangle.Top,
                                                       panel1.ClientRectangle.Width,
                                                       panel1.ClientRectangle.Height);
                }
                catch (Exception)
                {
                    m_objVideoWindow = null;
                }

                m_objMediaEvent = m_objFilterGraph as IMediaEvent;

                m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
                m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);

                m_objMediaPosition = m_objFilterGraph as IMediaPosition;

                m_objMediaControl = m_objFilterGraph as IMediaControl;

                this.Text = "DirectShow - [" + openFileDialog.FileName + "]";

                m_objMediaControl.Run();
                m_CurrentStatus = MediaStatus.Running;

                UpdateStatusBar();
                UpdateToolBar();
            }
        }
Example #20
0
        /// <summary>
        /// Called on a new thread to process events from the graph.  The thread
        /// exits when the graph finishes.
        /// </summary>
        private void EventWait()
        {
            // Returned when GetEvent is called but there are no events
            const int E_ABORT = unchecked ((int)0x80004004);

            int       hr;
            IntPtr    p1, p2;
            EventCode ec;
            EventCode exitCode = 0;

            IMediaEvent pEvent = (IMediaEvent)m_FilterGraph;

            do
            {
                // Read the event
                for (
                    hr = pEvent.GetEvent(out ec, out p1, out p2, 100);
                    hr >= 0;
                    hr = pEvent.GetEvent(out ec, out p1, out p2, 100)
                    )
                {
                    Debug.WriteLine(ec);
                    switch (ec)
                    {
                    // If the clip is finished playing
                    case EventCode.Complete:
                    case EventCode.ErrorAbort:
                    case EventCode.UserAbort:
                        exitCode = ec;

                        // Release any resources the message allocated
                        hr = pEvent.FreeEventParams(ec, p1, p2);
                        DsError.ThrowExceptionForHR(hr);
                        break;

                    default:
                        // Release any resources the message allocated
                        hr = pEvent.FreeEventParams(ec, p1, p2);
                        DsError.ThrowExceptionForHR(hr);
                        break;
                    }
                }

                // If the error that exited the loop wasn't due to running out of events
                if (hr != E_ABORT)
                {
                    DsError.ThrowExceptionForHR(hr);
                }
            } while (exitCode == 0);

            // Send an event saying we are complete
            IsCompleted = true;
        } // Exit the thread
Example #21
0
        /// <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;
        }
Example #22
0
    /// <summary> build the capture graph for grabber. </summary>
    private void SetupGraph(string destFilename, string encoderName)
    {
        int hr;

        // Get the graphbuilder object
        captureGraphBuilder = new DirectShowLib.CaptureGraphBuilder2() as DirectShowLib.ICaptureGraphBuilder2;
        IFilterGraph2 filterGraph = new DirectShowLib.FilterGraph() as DirectShowLib.IFilterGraph2;

        mediaCtrl = filterGraph as DirectShowLib.IMediaControl;
        IMediaFilter mediaFilt = filterGraph as IMediaFilter;

        mediaEvent = filterGraph as IMediaEvent;
        captureGraphBuilder.SetFiltergraph(filterGraph);
        IBaseFilter     aviMux;
        IFileSinkFilter fileSink = null;

        hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, destFilename, out aviMux, out fileSink);
        DsError.ThrowExceptionForHR(hr);
        DirectShowLib.IBaseFilter compressor = DirectShowUtils.GetVideoCompressor(encoderName);
        if (compressor == null)
        {
            throw new InvalidCodecException(encoderName);
        }
        hr = filterGraph.AddFilter(compressor, "compressor");
        DsError.ThrowExceptionForHR(hr);
        // Our data source
        IBaseFilter source = (IBaseFilter) new GenericSampleSourceFilter();
        // Get the pin from the filter so we can configure it
        IPin ipin = DsFindPin.ByDirection(source, PinDirection.Output, 0);

        try
        {
            // Configure the pin using the provided BitmapInfo
            ConfigurePusher((IGenericSampleConfig)ipin);
        }
        finally
        {
            Marshal.ReleaseComObject(ipin);
        }
        // Add the filter to the graph
        hr = filterGraph.AddFilter(source, "GenericSampleSourceFilter");
        Marshal.ThrowExceptionForHR(hr);
        hr = filterGraph.AddFilter(source, "source");
        DsError.ThrowExceptionForHR(hr);
        hr = captureGraphBuilder.RenderStream(null, null, source, compressor, aviMux);
        DsError.ThrowExceptionForHR(hr);
        IMediaPosition mediaPos = filterGraph as IMediaPosition;

        hr = mediaCtrl.Run();
        DsError.ThrowExceptionForHR(hr);
    }
Example #23
0
        static void Main(string[] args)
        {
            try
            {
                IGraphBuilder pGraph = (IGraphBuilder) new FilterGraph();
                Console.WriteLine("Building graph...");

                BuildGraph(pGraph, @"bbb_360p_10sec.mp4");
                Console.WriteLine("Running...");

                IMediaControl pMediaControl = (IMediaControl)pGraph;
                IMediaEvent   pMediaEvent   = (IMediaEvent)pGraph;

                int hr = pMediaControl.Run();
                checkHR(hr, "Can't run the graph");

                bool stop = false;
                while (!stop)
                {
                    System.Threading.Thread.Sleep(50);
                    Console.Write(".");
                    EventCode ev;
                    IntPtr    p1, p2;
                    System.Windows.Forms.Application.DoEvents();
                    while (pMediaEvent.GetEvent(out ev, out p1, out p2, 0) == 0)
                    {
                        if (ev == EventCode.Complete || ev == EventCode.UserAbort)
                        {
                            Console.WriteLine("Done!");
                            stop = true;
                        }
                        else if (ev == EventCode.ErrorAbort)
                        {
                            Console.WriteLine("An error occured: HRESULT={0:X}", p1);
                            pMediaControl.Stop();
                            stop = true;
                        }
                        pMediaEvent.FreeEventParams(ev, p1, p2);
                    }
                }
            }
            catch (COMException ex)
            {
                Console.WriteLine("COM error: " + ex.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.ToString());
            }
        }
Example #24
0
        protected virtual void SetPlayerCollaborators()
        {
            basicAudio = filgraphManager as IBasicAudio;

            mediaPosition = filgraphManager as IMediaPosition;

            mediaControl = filgraphManager as IMediaControl;

            mediaEvent = filgraphManager as IMediaEvent;

            mediaEventEx = filgraphManager as IMediaEventEx;

            messageHandler.MediaEventEx = mediaEventEx;
        }
        private void CleanUp()
        {
            if (m_objMediaControl != null)
            {
                m_objMediaControl.Stop();
            }

            m_CurrentStatus = MediaStatus.Stopped;

            if (m_objMediaEventEx != null)
            {
                m_objMediaEventEx.SetNotifyWindow(0, 0, 0);
            }

            if (m_objVideoWindow != null)
            {
                m_objVideoWindow.Visible = 0;
                m_objVideoWindow.Owner   = 0;
            }

            if (m_objMediaControl != null)
            {
                m_objMediaControl = null;
            }
            if (m_objMediaPosition != null)
            {
                m_objMediaPosition = null;
            }
            if (m_objMediaEventEx != null)
            {
                m_objMediaEventEx = null;
            }
            if (m_objMediaEvent != null)
            {
                m_objMediaEvent = null;
            }
            if (m_objVideoWindow != null)
            {
                m_objVideoWindow = null;
            }
            if (m_objBasicAudio != null)
            {
                m_objBasicAudio = null;
            }
            if (m_objFilterGraph != null)
            {
                m_objFilterGraph = null;
            }
        }
Example #26
0
        // Build the capture graph for grabber and renderer.</summary>
        // (Control to show video in, Filename to play)
        private void SetupGraph(Control hWin, string FileName)
        {
            int hr;

            m_FilterGraph = new FilterGraph() as IFilterGraph2;

            ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            try
            {
                hr = icgb2.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

                IBaseFilter sourceFilter = null;
                hr = m_FilterGraph.AddSourceFilter(FileName, FileName, out sourceFilter);
                DsError.ThrowExceptionForHR(hr);

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

                // Configure the Sample Grabber
                ConfigureSampleGrabber(m_sampGrabber);

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

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

                // Configure the Video Window
                IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
                ConfigureVideoWindow(videoWindow, hWin);

                // Grab some other interfaces
                m_mediaEvent = m_FilterGraph as IMediaEvent;
                m_mediaCtrl  = m_FilterGraph as IMediaControl;
            }
            finally
            {
                if (icgb2 != null)
                {
                    Marshal.ReleaseComObject(icgb2);
                    icgb2 = null;
                }
            }
        }
Example #27
0
        private static void playAudioFile(object fileName)
        {
            try {
                IFilterGraph2 filterGraph = (IFilterGraph2) new FilterGraph();
                if (0 == filterGraph.RenderFile(fileName as string, IntPtr.Zero))
                {
                    IMediaControl mediaControl = (IMediaControl)filterGraph;
                    mediaControl.Run();

                    IMediaEvent mediaEvent = (IMediaEvent)filterGraph;
                    int         eventCode;
                    mediaEvent.WaitForCompletion(6000, out eventCode);
                }
            } catch (Exception) { }
        }
Example #28
0
            static void Main(string[] args)
            {
                try
                {
                    IGraphBuilder graph = (IGraphBuilder) new FilterGraph();
                    Console.WriteLine("Building graph...");
                    BuildGraph(graph, @"J:\TORRENT\1. Фильмы\Mult.RU.320x240\03 Ежи и Петруччо\01 Когда-то.mp4");
                    Console.WriteLine("Running...");
                    IMediaControl mediaControl = (IMediaControl)graph;
                    IMediaEvent   mediaEvent   = (IMediaEvent)graph;
                    int           hr           = mediaControl.Run();
                    checkHR(hr, "Can't run the graph");
                    bool stop = false;
                    while (!stop)
                    {
                        System.Threading.Thread.Sleep(500);
                        Console.Write(".");
                        EventCode ev;
                        IntPtr    p1, p2;

                        System.Windows.Forms.Application.DoEvents();
                        while (mediaEvent.GetEvent(out ev, out p1, out p2, 0) == 0)
                        {
                            if (ev == EventCode.Complete || ev == EventCode.UserAbort)
                            {
                                Console.WriteLine("Done!");
                                stop = true;
                            }
                            else
                            if (ev == EventCode.ErrorAbort)
                            {
                                Console.WriteLine("An error occured: HRESULT={0:X}", p1);
                                mediaControl.Stop();
                                stop = true;
                            }
                            mediaEvent.FreeEventParams(ev, p1, p2);
                        }
                    }
                }
                catch (COMException ex)
                {
                    Console.WriteLine("COM error: " + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.ToString());
                }
            }
Example #29
0
        //setzt alle DirectShow Sachen auf null
        private void CleanUp()
        {
            if (MediaControl != null)
            {
                MediaControl.Stop();
            }

            if (MediaEventEx != null)
            {
                MediaEventEx.SetNotifyWindow(0, 0, 0);
            }

            if (VideoWindow != null)
            {
                VideoWindow.Visible = 0;
                VideoWindow.Owner   = 0;
            }

            if (MediaControl != null)
            {
                MediaControl = null;
            }
            if (MediaPosition != null)
            {
                MediaPosition = null;
            }
            if (MediaEventEx != null)
            {
                MediaEventEx = null;
            }
            if (MediaEvent != null)
            {
                MediaEvent = null;
            }
            if (VideoWindow != null)
            {
                VideoWindow = null;
            }
            if (BasicAudio != null)
            {
                BasicAudio = null;
            }
            if (FilterGraph != null)
            {
                FilterGraph = null;
            }
        }
Example #30
0
        private void init(string s)        //³õʼ²¥·ÅÆ÷
        {
            try
            {
                m_objFilterGraph = new FilgraphManager();
                m_objFilterGraph.RenderFile(s);

                m_objBasicAudio = m_objFilterGraph as IBasicAudio;

                m_objMediaEvent = m_objFilterGraph as IMediaEvent;

                m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;

                m_objMediaControl = m_objFilterGraph as IMediaControl;
            }
            catch {}
        }
Example #31
0
        /// <summary>
        /// Release any resource used and reset settings for next operation
        /// </summary>
        private void Cleanup()
        {
            this._mediaEvnt = null;

            if (this._mediaCtrl != null)
            {
                this._mediaCtrl.StopWhenReady();
                this._mediaCtrl = null;
            }

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

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

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

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

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

            if (this._graphBuilder != null)
            {
                Marshal.ReleaseComObject(this._graphBuilder);
                this._graphBuilder = null;
            }
        }
Example #32
0
        //Метод CleanUp (Зачистка графов)
        public void CleanUp()
        {
            if (mediaControl != null) mediaControl.Stop();
            CurrentStatus = mStatus.Stop;

            if (videoWindow != null)
            {
                videoWindow.put_Visible(0);
                videoWindow.put_Owner(new IntPtr(0));
            }
            if (mediaControl != null)  mediaControl  = null;
            if (mediaPosition != null) mediaPosition = null;
            if (mediaEventEx != null)  mediaEventEx  = null;
            if (mediaEvent != null)    mediaEvent    = null;
            if (videoWindow != null)   videoWindow   = null;
            if (basicAudio != null)    basicAudio    = null;
            if (graphBuilder != null)  graphBuilder  = null;
        }
Example #33
0
 // Methods
 internal AudioAnimate(string prefix, string localname, string ns, SvgDocument doc)
     : base(prefix, localname, ns, doc)
 {
     this.m_objFilterGraph = null;
     this.m_objBasicAudio = null;
     this.m_objMediaEvent = null;
     this.m_objMediaEventEx = null;
     this.m_objMediaPosition = null;
     this.m_objMediaControl = null;
     this.fillColor = Color.Khaki;
     this.fileName = string.Empty;
     this.m_CurrentStatus = MediaStatus.None;
     this.timer = new Timer();
     this.oldtime = 0f;
     this.timertime = 0f;
     this.timer.Interval = 100;
     this.timer.Tick += new EventHandler(this.TimerTick);
 }
Example #34
0
        /// <summary>
        /// Plays the given mediafile in the internal mediaplayer
        /// </summary>
        /// <param name="FilePath">File to play</param>
        public void ShowMedia(string FilePath)
        {
            StopMedia();
            Lbl_CurrentMedia.Text = Path.GetFileName(FilePath);
            m_objFilterGraph = new FilgraphManager();
            m_objFilterGraph.RenderFile(FilePath);

            m_objBasicAudio = m_objFilterGraph as IBasicAudio;

            try
            {
                m_objVideoWindow = m_objFilterGraph as IVideoWindow;
                m_objVideoWindow.Owner = (int)panel2.Handle;
                //m_objVideoWindow.Owner = (int)panel1.Handle;

                m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                m_objVideoWindow.SetWindowPosition(panel2.ClientRectangle.Left,
                   panel2.ClientRectangle.Top,
                    panel2.ClientRectangle.Width,
                    panel2.ClientRectangle.Height);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                m_objVideoWindow = null;
            }

            m_objMediaEvent = m_objFilterGraph as IMediaEvent;

            m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
            m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);

            m_objMediaPosition = m_objFilterGraph as IMediaPosition;

            m_objMediaControl = m_objFilterGraph as IMediaControl;

            m_objMediaControl.Run();
            m_CurrentStatus = MediaStatus.Running;
            UpdateMediaButtons();

            //UpdateStatusBar();
            //UpdateToolBar();
        }
Example #35
0
        /**
         * To clean up the FilterGraph and other Objects
         * */
        public void CleanUp()
        {
            if (m_objMediaControl != null)
                m_objMediaControl.Stop();

            if (m_objMediaEventEx != null)
                m_objMediaEventEx.SetNotifyWindow(0, 0, 0);

            if (m_objVideoWindow != null)
            {
                m_objVideoWindow.Visible = 0;
                m_objVideoWindow.Owner = 0;
            }

            if (m_objMediaControl != null) m_objMediaControl = null;
            if (m_objMediaPosition != null) m_objMediaPosition = null;
            if (m_objMediaEventEx != null) m_objMediaEventEx = null;
            if (m_objMediaEvent != null) m_objMediaEvent = null;
            if (m_objVideoWindow != null) m_objVideoWindow = null;
            if (m_objBasicAudio != null) m_objBasicAudio = null;
            if (m_objFilterGraph != null) m_objFilterGraph = null;
        }
Example #36
0
        /// <summary>
        /// 清理资源
        /// </summary>
        public void Dispose()
        {
            if (m_objMediaControl != null)
                m_objMediaControl.Stop();

            m_currentStatus = MediaStatus.Stopped;

            if (m_objMediaEventEx != null)
                m_objMediaEventEx.SetNotifyWindow(0, 0, 0);

            if (m_objMediaControl != null) m_objMediaControl = null;
            if (m_objMediaPosition != null) m_objMediaPosition = null;
            if (m_objMediaEventEx != null) m_objMediaEventEx = null;
            if (m_objMediaEvent != null) m_objMediaEvent = null;
            if (m_objBasicAudio != null) m_objBasicAudio = null;

            //System.Runtime.InteropServices.Marshal.ReleaseComObject(m_objFilterGraph);

            if (m_objFilterGraph != null) m_objFilterGraph = null;

            //System.Runtime.InteropServices.Marshal.ReleaseComObject
            //QuartzTypeLib.FilgraphManagerClass fm = new FilgraphManagerClass();
        }
        public void OpenFileFunc(int filedex)
        {
            fileIndex = filedex;
            listoffilenames.SelectedIndex = fileIndex;
            object sender = new object();
            EventArgs er = new EventArgs();
            listoffilenames_SelectedIndexChanged(sender, er);
            ReLoad();
            itemList.Refresh();
            string openedfile = this.listoffilenames.Items[fileIndex].ToString();
            m_obj_FilterGraph = new FilgraphManager();
            try
            {
                m_obj_FilterGraph.RenderFile(openedfile);
            }
            catch (Exception)
            {
                MessageBox.Show("Please choose a valid file.\n Check the file path.\n File path could be changed.");
                return;
            }
            try
            {
                m_obj_BasicAudio = m_obj_FilterGraph as IBasicAudio;
                trackBar1.Value = volumeValue;
                m_obj_BasicAudio.Volume = trackBar1.Value;
                if (mute)
                {
                    volumeValue = -10000;
                    trackBar1.Value = volumeValue;
                    m_obj_BasicAudio.Volume = trackBar1.Value;
                }
            }
            catch { }

            try
            {
                if (!newPlayerIsCreated)
                {
                    playerform = new player(itemList, listoffilenames, fileIndex, filename);
                    newPlayerIsCreated = true;
                    playerform.Location = new Point(playerformLocationX, playerformLocationY);
                }
                m_obj_VideoWindow = m_obj_FilterGraph as IVideoWindow;
                m_obj_VideoWindow.Owner = (int)playerform.Handle;
                m_obj_VideoWindow.WindowStyle = WS_CHILD;
                videoplaying = true;
                m_obj_VideoWindow.SetWindowPosition(playerform.ClientRectangle.Left,
                    playerform.ClientRectangle.Top,
                    playerform.ClientRectangle.Right,
                    playerform.ClientRectangle.Bottom);
            }
            catch (Exception)
            {
                m_obj_VideoWindow = null;
                videoplaying = false;
            }

            if (videoplaying)
            {
                trackBar2.Enabled = true;
                trackBar1.Enabled = true;
                if (fullscreen)
                {
                    if (playerformactivatedonce == 0)
                        playerform.Show();
                    fullscreen = false;
                    fullscreenfunc();
                }
                else
                {
                    if (playerformactivatedonce == 0)
                        playerform.Show();
                }
                playerform.Activate();
            }
            else
            {
                trackBar2.Enabled = true;
                trackBar1.Enabled = true;
                playerformHeight = playerform.Height;
                playerformWidth = playerform.Width;
                playerformLocationX = playerform.Location.X;
                playerformLocationY = playerform.Location.Y;
                playerform.Dispose();
                newPlayerIsCreated = false;
            }
            running = true;
            m_obj_MediaEvent = m_obj_FilterGraph as IMediaEvent;
            m_obj_MediaEventEx = m_obj_FilterGraph as IMediaEventEx;
            m_obj_MediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);
            m_obj_MediaPosition = m_obj_FilterGraph as IMediaPosition;
            m_obj_MediaControl = m_obj_FilterGraph as IMediaControl;
            trackBar2.Maximum = (int)m_obj_MediaPosition.Duration;
            trackBar2.Minimum = 0;
            trackBar2.Value = (int)m_obj_MediaPosition.CurrentPosition;
            m_obj_MediaControl.Run();
            m_CurrentStatus = MediaStatus.Running;
            try
            {
                if (searchform != null)
                    searchform.listBox1.SelectedIndex = itemList.SelectedIndex;
            }
            catch { }
            if (isHidden)
                openModifyWindow();
            string[] newfilenamearray = listoffilenames.Items[fileIndex].ToString().Split('\\');
            string newfilename = newfilenamearray[newfilenamearray.Length - 1].ToString();
            if(newfilename.Length>30)
                filename.Text = newfilename.Substring(0,29) + "  ";
            else
                filename.Text = newfilename+ "  ";
            this.Refresh();
            UpdateToolStrip();
        }
        /// <summary> build the capture graph for grabber. </summary>
        private void SetupGraph(string FileName)
        {
            int hr;

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

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

            IMediaFilter mediaFilt = m_FilterGraph as IMediaFilter;

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

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

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

                ConfigureSampleGrabber(sampGrabber);

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

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

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

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

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

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

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

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

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

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

                // Read and cache the image sizes
                SaveSizeInfo(sampGrabber);
            }
            finally
            {
                if (capFilter != null)
                {
                    Marshal.ReleaseComObject(capFilter);
                    capFilter = null;
                }
                if (sampGrabber != null)
                {
                    Marshal.ReleaseComObject(sampGrabber);
                    sampGrabber = null;
                }
                if (nullrenderer != null)
                {
                    Marshal.ReleaseComObject(nullrenderer);
                    nullrenderer = null;
                }
            }
        }
Example #39
0
        private void Init()
        {
            graphBuilder = (IGraphBuilder)new FilterGraph();

            //Create the media control for controlling the graph
            mediaControl = (IMediaControl)graphBuilder;

            mediaEvent = (IMediaEvent)graphBuilder;
            volume = 100;
            captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
            // initialize the Capture Graph Builder
            int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
            DsError.ThrowExceptionForHR(hr);

            DeinterlaceLayoutList = new DeinterlaceList();
            DeinterlaceLayoutList.Add(new DeInterlaceAlparyLayout(this));
            DeinterlaceLayoutList.Add(new DeInterlaceDscalerLayout(this));
            DeinterlaceLayoutList.Add(new DeInterlaceFFDShowLayout(this));
            aspectRatio = 4.0f / 3.0f;
        }
Example #40
0
        /// <summary>
        /// 初始化播放
        /// </summary>
        /// <param name="fileName">文件名称(全路径)</param>
        public void Open(string fileName)
        {
            m_objFilterGraph = new FilgraphManager();
            m_objFilterGraph.RenderFile(fileName);

            m_objBasicAudio = m_objFilterGraph as IBasicAudio;
            m_objMediaEvent = m_objFilterGraph as IMediaEvent;
            m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
            m_objMediaPosition = m_objFilterGraph as IMediaPosition;
            m_objMediaControl = m_objFilterGraph as IMediaControl;
        }
Example #41
0
        /// <summary> create the used COM components and get the interfaces. </summary>
        bool GetInterfaces()
        {
            Type comType = null;
            object comObj = null;
            try
            {
                graphBuilder = (IGraphBuilder)DsDev.CreateFromCLSID(Clsid.FilterGraph);
                mediaEvt = (IMediaEvent)graphBuilder;
                AssignTaskToWaitForCompletion(mediaEvt);

                Guid clsid = Clsid.CaptureGraphBuilder2;
                Guid riid = typeof(ICaptureGraphBuilder2).GUID;
                capGraph = (ICaptureGraphBuilder2)DsBugWO.CreateDsInstance(ref clsid, ref riid);

                if (atiTVCardFound)
                {
                    wmVideoDecoder = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.AVI_Decompressor);
                }

                stretchVideo = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.Stretch_Video);
                colorConverter = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.ColorSpaceConverter);
                modFrameRate = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.ModifyFrameRate);

                motionVector = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.MotionVector);
                // Vector Grabber
                vectorGrabber = (IVectorGrabber)DsDev.CreateFromCLSID(Clsid.FlowVectorGrabber);

                sampleGrabber = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.SampleGrabber);
                grabberConfig = sampleGrabber as ISampleGrabber;

                mediaCtrl = (IMediaControl)graphBuilder;

                if (videoPreview)
                {
                    teeSplitter = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.SmartTee); //.CreateFromMoniker(TeeSplitter);
                    videoRenderer = (IBaseFilter)DsDev.CreateFromCLSID(Clsid.VideoRenderer); // (Clsid.VMR9);
                }

                // Attemp to use VMR9 abandoned for now
                //vmrAllocator = (IVMRSurfaceAllocator9)DsDev.CreateFromCLSID(Clsid.VMR9Allocator);
                baseGrabFlt = (IBaseFilter)vectorGrabber;
                return true;
            }
            catch (Exception ee)
            {
                LogInfo(LogGroups.Console, "Could not get interfaces\r\n" + ee.Message);
                return false;
            }
            finally
            {
                if (comObj != null)
                    Marshal.ReleaseComObject(comObj); comObj = null;
            }
        }
Example #42
0
        // Build the capture graph for grabber and renderer.</summary>
        // (Control to show video in, Filename to play)
        private void SetupGraph(Control hWin, string FileName)
        {
            int hr;

            IBaseFilter ibfRenderer = null;
            IPin iPinInFilter = null;
            IPin iPinOutFilter = null;
            IPin iPinInDest = null;

            m_FilterGraph = new FilterGraph() as IFilterGraph2;

            ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            try
            {
                hr = icgb2.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

                IBaseFilter sourceFilter = null;
                hr = m_FilterGraph.AddSourceFilter(FileName, "Ds.NET FileFilter", out sourceFilter);
                DsError.ThrowExceptionForHR(hr);

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

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

                // Configure the Sample Grabber
                ConfigureSampleGrabber(m_sampGrabber);

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

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

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

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

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

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

                // Configure the Video Window
                IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
                ConfigureVideoWindow(videoWindow, hWin);

                // Grab some other interfaces
                m_mediaEvent = m_FilterGraph as IMediaEvent;
                m_mediaCtrl = m_FilterGraph as IMediaControl;
                m_mediaPosition = m_FilterGraph as IMediaPosition;
            }
            finally
            {
                if (icgb2 != null)
                {
                    Marshal.ReleaseComObject(icgb2);
                    icgb2 = null;
                }
            }
        }
        public void PlayeMusic(string url)
        {
            try
            {
                if (myMediaControl != null)
                {
                    myMediaControl.Stop();
                }

                //InitPlayer();

                myFilterGraph = new FilgraphManager();
                //PublicInterFace.LogErro(url);
                myFilterGraph.RenderFile(url);
                myBasicAudio = myFilterGraph as IBasicAudio;
                myMediaEvent = myFilterGraph as IMediaEvent;
                myMediaPosition = myFilterGraph as IMediaPosition;
                myMediaControl = myFilterGraph as IMediaControl;

                myBasicAudio.Volume = 100;

                //int ai = myBasicAudio.Volume;

                myMediaControl.Run();

                //IsPlay = true;
                //BaseInovke(new MethodInvoker(delegate()
                //{
                //    playerControl.StratAnti();
                //    playTimer.Start();
                //}));
            }
            catch (Exception ex)
            {
                //PublicInterFace.LogErro("发生异常:\r\n" + ex.Message + "\r\n" + ex.StackTrace);
                //BaseInovke(new MethodInvoker(delegate()
                //{
                //    playTimer.Stop();
                //    playerControl.StopAnti();
                //    IsPlay = false;
                //    nowPlayMusic.Text = "播放失败!请尝试换个链接或者下载!";
                //}));
            }
        }
        private void MediaPreviewer_Load(object sender, EventArgs e)
        {
            statusBarPanel1.Text = "Buffering !! Please  Wait";
                CleanUp();
                Console.WriteLine("download finished");
                m_objFilterGraph = new FilgraphManager();

                try
                {
                        m_objFilterGraph.RenderFile(fileName);
                }
                catch (Exception ex)
                {
                        return;
                }

                m_objBasicAudio = m_objFilterGraph as IBasicAudio;

                try
                {
                    m_objVideoWindow = m_objFilterGraph as IVideoWindow;
                    m_objVideoWindow.Owner = (int) panel1.Handle;
                    m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                    m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                        panel1.ClientRectangle.Top,
                        panel1.ClientRectangle.Width,
                        panel1.ClientRectangle.Height);
                }
                catch (Exception)
                {
                    m_objVideoWindow = null;
                }

                m_objMediaEvent = m_objFilterGraph as IMediaEvent;

                m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
                m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0);

                m_objMediaPosition = m_objFilterGraph as IMediaPosition;

                m_objMediaControl = m_objFilterGraph as IMediaControl;

                this.Text = "SMART MediaPreviewer";

                m_objMediaControl.Run();
                m_CurrentStatus = MediaStatus.Running;

                UpdateStatusBar();
                UpdateToolBar();
        }
Example #45
0
            /// <summary>
            /// Constructor - provides the fgm to monitor
            /// </summary>
            public FgmEventMonitor(IMediaEvent iME)
            {
                this.iME = iME;

                // Kick off a thread to monitor events in the filtergraph
                eventThread = new Thread(new ThreadStart(Monitor));
                eventThread.IsBackground = true;
                eventThread.Name = "Fgm Event Monitor";
                eventThread.Start();
            }
Example #46
0
        // Build the capture graph for grabber and renderer.</summary>
        // (Control to show video in, Filename to play)
        private void SetupGraph(Control hWin, string FileName)
        {
            int hr;

            m_FilterGraph = new FilterGraph() as IFilterGraph2;

            ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

            try
            {
                hr = icgb2.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

                IBaseFilter sourceFilter = null;
                hr = m_FilterGraph.AddSourceFilter(FileName, FileName, out sourceFilter);
                DsError.ThrowExceptionForHR( hr );

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

                // Configure the Sample Grabber
                ConfigureSampleGrabber(m_sampGrabber);

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

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

                // Configure the Video Window
                IVideoWindow videoWindow = m_FilterGraph as IVideoWindow;
                ConfigureVideoWindow(videoWindow, hWin);

                // Grab some other interfaces
                m_mediaEvent = m_FilterGraph as IMediaEvent;
                m_mediaCtrl = m_FilterGraph as IMediaControl;
            }
            finally
            {
                if (icgb2 != null)
                {
                    Marshal.ReleaseComObject(icgb2);
                    icgb2 = null;
                }
            }
        }
        //PLAYER ý yeniden yükleme iþlemi....
        public void ReLoad()
        {
            if (m_obj_MediaControl != null)
            {
                m_obj_MediaControl.Stop();
                m_CurrentStatus = MediaStatus.Stopped;
            }

            if (m_obj_MediaEventEx != null)
                m_obj_MediaEventEx.SetNotifyWindow(0, 0, 0);

            if (m_obj_VideoWindow != null)
            {
                m_obj_VideoWindow.Visible = 0;
                m_obj_VideoWindow.Owner = 0;
            }

            if (m_obj_MediaControl != null) m_obj_MediaControl = null;
            if (m_obj_MediaPosition != null) m_obj_MediaPosition = null;
            if (m_obj_MediaEventEx != null) m_obj_MediaEventEx = null;
            if (m_obj_MediaEvent != null) m_obj_MediaEvent = null;
            if (m_obj_VideoWindow != null) m_obj_VideoWindow = null;
            if (m_obj_BasicAudio != null) m_obj_BasicAudio = null;
            if (m_obj_FilterGraph != null) m_obj_FilterGraph = null;
            if (itemList.Items.Count == 0)
            {
                m_CurrentStatus = MediaStatus.None;
                trackBar2.Enabled = false;
                trackBar1.Enabled = false;
                if (videoplaying)
                    playerform.Dispose();
                videoplaying = false;
                m_CurrentStatus = MediaStatus.None;
            }
            UpdateToolStrip();
        }
Example #48
0
        private void openMedia()
        {
            openFileDialog1.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";
            if (DialogResult.OK == openFileDialog1.ShowDialog()) {
                CleanUp();
                m_objFilterGraph = new FilgraphManager();
                m_objFilterGraph.RenderFile(openFileDialog1.FileName);
                m_objBasicAudio = m_objFilterGraph as IBasicAudio;

                try
                {
                    m_objVideoWindow = m_objFilterGraph as IVideoWindow;
                    m_objVideoWindow.Owner = (int)panel1.Handle;
                    m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                    m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                        panel1.ClientRectangle.Top,
                        panel1.ClientRectangle.Width,
                        panel1.ClientRectangle.Height);
                }
                catch(Exception) {
                    m_objVideoWindow = null;
                }

                m_objMediaEvent = m_objFilterGraph as IMediaEvent;
                m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
                m_objMediaEventEx.SetNotifyWindow((int) this.Handle, WM_GRAPHNOTIFY, 0);
                m_objMediaPosition = m_objFilterGraph as IMediaPosition;
                m_objMediaControl = m_objFilterGraph as IMediaControl;
                this.Text = "Whistle- " + openFileDialog1.FileName + "]";
                m_objMediaControl.Run();
                m_CurrentStatus = MediaStatus.Running;

            }
        }
Example #49
0
        private void CleanUp()
        {
            if (m_objMediaControl != null) {
                m_objMediaControl.Stop();
            }

            m_CurrentStatus = MediaStatus.Stopped;

            if (m_objMediaEventEx != null) {
                m_objMediaEventEx.SetNotifyWindow(0, 0, 0);
            }

            if (m_objVideoWindow != null) {
                m_objVideoWindow.Visible = 0;
                m_objVideoWindow.Owner = 0;
            }

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

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

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

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

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

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

            if (m_objFilterGraph != null) {
                m_objFilterGraph = null;
            }
        }
Example #50
0
        private void CloseInterfaces()
        {
            while (!m_WaitUntilDoneIsDone)
                Thread.Sleep(1);

            if (!m_WaitUntilDoneIsDone)
            {
                MessageBox.Show("wait not done");

            }

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

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

                if (handlersAdded)
                    RemoveHandlers();

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

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

                if (graphBuilder != null)
                {
                    Marshal.ReleaseComObject(graphBuilder);
                    graphBuilder = null;
                    mediaControl = null;
                }
            }
            catch { }
        }
Example #51
0
    /// <summary> build the capture graph for grabber. </summary>
    private void SetupGraph(string FileName)
    {
      int hr;

      // Get the graphbuilder object
      this.graphBuilder = new FilterGraph() as IGraphBuilder;
      this.mediaControl = this.graphBuilder as IMediaControl;
      this.mediaSeeking = this.graphBuilder as IMediaSeeking;
      this.mediaEvent = this.graphBuilder as IMediaEvent;

      try
      {
        // Get the SampleGrabber interface
        this.sampleGrabber = new SampleGrabber() as ISampleGrabber;
        this.sampleGrabberFilter = sampleGrabber as IBaseFilter;

        ConfigureSampleGrabber(sampleGrabber);

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

        IBaseFilter aviSplitter = new AviSplitter() as IBaseFilter;

        // Add the aviSplitter to the graph
        hr = graphBuilder.AddFilter(aviSplitter, "Splitter");
        DsError.ThrowExceptionForHR(hr);

        // Have the graph builder construct its appropriate graph automatically
        hr = this.graphBuilder.RenderFile(FileName, null);
        DsError.ThrowExceptionForHR(hr);

#if DEBUG
        m_rot = new DsROTEntry(graphBuilder);
#endif

        // Remove the video renderer filter
        IBaseFilter defaultVideoRenderer = null;
        graphBuilder.FindFilterByName("Video Renderer", out defaultVideoRenderer);
        graphBuilder.RemoveFilter(defaultVideoRenderer);

        // Disconnect anything that is connected
        // to the output of the sample grabber
        IPin iPinSampleGrabberOut = DsFindPin.ByDirection(sampleGrabberFilter, PinDirection.Output, 0);
        IPin iPinVideoIn;
        hr = iPinSampleGrabberOut.ConnectedTo(out iPinVideoIn);

        if (hr == 0)
        {
          // Disconnect the sample grabber output from the attached filters
          hr = iPinVideoIn.Disconnect();
          DsError.ThrowExceptionForHR(hr);

          hr = iPinSampleGrabberOut.Disconnect();
          DsError.ThrowExceptionForHR(hr);
        }
        else
        {
          // Try other way round because automatic renderer could not build
          // graph including the sample grabber
          IPin iPinAVISplitterOut = DsFindPin.ByDirection(aviSplitter, PinDirection.Output, 0);
          IPin iPinAVISplitterIn;
          hr = iPinAVISplitterOut.ConnectedTo(out iPinAVISplitterIn);
          DsError.ThrowExceptionForHR(hr);

          hr = iPinAVISplitterOut.Disconnect();
          DsError.ThrowExceptionForHR(hr);

          hr = iPinAVISplitterIn.Disconnect();
          DsError.ThrowExceptionForHR(hr);

          // Connect the avi splitter output to sample grabber
          IPin iPinSampleGrabberIn = DsFindPin.ByDirection(sampleGrabberFilter, PinDirection.Input, 0);
          hr = graphBuilder.Connect(iPinAVISplitterOut, iPinSampleGrabberIn);
          DsError.ThrowExceptionForHR(hr);
        }

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

        // Get the input pin of the null renderer
        IPin iPinNullRendererIn = DsFindPin.ByDirection(nullrenderer, PinDirection.Input, 0);

        // Connect the sample grabber to the null renderer
        hr = graphBuilder.Connect(iPinSampleGrabberOut, iPinNullRendererIn);
        DsError.ThrowExceptionForHR(hr);

        // Read and cache the image sizes
        SaveSizeInfo(sampleGrabber);

        this.GetFrameStepInterface();
      }
      finally
      {
      }
    }
Example #52
0
        private void BuildGraph(string fileName)
        {
            int hr = 0;

            try
            {
                graphBuilder = (IFilterGraph2)new FilterGraph();
                mediaControl = (IMediaControl)graphBuilder;
                ISampleGrabber sampGrabber = null;
                IBaseFilter baseGrabFlt = null;

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

                vmr9 = (IBaseFilter)new VideoMixingRenderer9();

                ConfigureVMR9InWindowlessMode();

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

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

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

                mediaPosition = (IMediaPosition)graphBuilder;
                m_MediaEvent = graphBuilder as IMediaEvent;

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

                SaveSizeInfo(sampGrabber);

            }
            catch (Exception e)
            {
                CloseInterfaces();
                MessageBox.Show("An error occured during the graph building : \r\n\r\n" + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #53
0
        private void DeInit()
        {
            DeinterlaceLayoutList = null;
            rOT = null;
            mediaEvent = null;
            mediaControl = null;

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

            if (captureGraphBuilder != null)
                Marshal.ReleaseComObject(captureGraphBuilder);
            captureGraphBuilder = null;
              //  GC.Collect();
        }
Example #54
0
        /// <summary> do cleanup and release DirectShow. </summary>
        void CloseInterfaces()
        {
            int hr;
            #if DEBUG
            if (rotCookie != 0)
                DsROT.RemoveGraphFromRot(ref rotCookie);
            #endif

            if (mediaCtrl != null)
            {
                hr = mediaCtrl.Stop();
                Marshal.ReleaseComObject(mediaCtrl);
                mediaCtrl = null;
            }

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

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

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

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

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

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

            if (dev != null)
            {
                dev.Dispose();
                dev = null;
            }

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

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

            if (capDevices != null)
            {
                foreach (DsDevice d in capDevices)
                    d.Dispose();
                capDevices = null;
            }

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

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

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

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

            if (vectorGrabber != null)
            {
                //vectorGrabber.SetCallback(null); // FIXME: sometimes, this causes an exception
                Marshal.ReleaseComObject(vectorGrabber);
                vectorGrabber = null;
            }

            if (crossBar != null)
            {
                Marshal.ReleaseComObject(crossBar);
                crossBar = null;
            }
        }
Example #55
0
        public void Run()
        {
            media_control = GraphBuilder as IMediaControl;

            media_event = GraphBuilder as IMediaEvent;

            Console.WriteLine("Started filter graph");
            media_control.Run();

            bool stop = false;

            while (!stop)
            {
                System.Threading.Thread.Sleep(500);
                Console.Write(".");
                EventCode ev;
                IntPtr p1, p2;
                if (media_event.GetEvent(out ev, out p1, out p2, 0) == 0)
                {
                    if (ev == EventCode.Complete || ev == EventCode.UserAbort)
                    {
                        Console.WriteLine("Done");
                        stop = true;
                        media_control.Stop();
                    }
                    else if (ev == EventCode.ErrorAbort)
                    {
                        Console.WriteLine("An Error occurred: HRESULT={0:X}", p1);
                        media_control.Stop();
                        stop = true;
                    }
                    media_event.FreeEventParams(ev, p1, p2);
                }
            }
        }
Example #56
0
 // FIXME: complete this routine to catch the end of video properly.
 // Use CCR to assign the task.
 void AssignTaskToWaitForCompletion(IMediaEvent mediaEvent)
 {
 }
Example #57
0
        public void openFile(string filename)
        {
            CleanUp();

            m_objFilterGraph = new FilgraphManager();
            m_objFilterGraph.RenderFile(filename);

           
            try
            {
                m_objVideoWindow = m_objFilterGraph as IVideoWindow;
                m_objVideoWindow.Owner = (int)panel1.Handle;
                m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                    panel1.ClientRectangle.Top,
                    panel1.ClientRectangle.Width,
                    panel1.ClientRectangle.Height);
            }
            catch (Exception)
            {
                m_objVideoWindow = null;
            }
            
        
            m_objMediaEvent = m_objFilterGraph as IMediaEvent;

            m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
            m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);

            m_objMediaPosition = m_objFilterGraph as IMediaPosition;

            m_objMediaControl = m_objFilterGraph as IMediaControl;

            this.Text = "Preview - [" + filename + "]";
            m_objMediaControl.Run();
            m_objMediaControl.Pause();
            

            UpdateStatusBar();
            UpdateToolBar();
        }
Example #58
0
        private bool PlayVideo(string path)
        {
            CleanUp();

            FilterGraph = new FilgraphManager();
            FilterGraph.RenderFile(path);

            BasicAudio = FilterGraph as IBasicAudio;

            try
            {
                VideoWindow = FilterGraph as IVideoWindow;
                VideoWindow.Owner = (int)panel1.Handle;
                VideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                VideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                        panel1.ClientRectangle.Top,
                        panel1.ClientRectangle.Width,
                        panel1.ClientRectangle.Height);
            }
            catch (Exception)
            {
                VideoWindow = null;
                return false;
            }

            MediaEvent = FilterGraph as IMediaEvent;
            MediaEventEx = FilterGraph as IMediaEventEx;

            MediaPosition = FilterGraph as IMediaPosition;
            MediaControl = FilterGraph as IMediaControl;

            MediaControl.Run();
            return true;
        }
Example #59
0
        // Build the capture graph for grabber and renderer.</summary>
        // (Control to show video in, Filename to play)
        private void SetupGraph(string FileName)
        {
            int hr;

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

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

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

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

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

                // Configure the Sample Grabber
                ConfigureSampleGrabber(m_sampGrabber);

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

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

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

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

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

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

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

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

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

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

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

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