예제 #1
0
        /// <summary>
        /// Creates a new VMR9 renderer and configures it with an allocator
        /// </summary>
        /// <returns>An initialized DirectShow VMR9 renderer</returns>
        private IBaseFilter CreateVideoMixingRenderer9(IGraphBuilder graph, int streamCount)
        {
            IBaseFilter vmr9;

            try
            {
                vmr9 = new VideoMixingRenderer9() as IBaseFilter;
            }
            catch (COMException ex)
            {
                throw new WPFMediaKitException("Could not create VMR9, do you have the grahics driver and DirectX properly installed?", ex);
            }

            var filterConfig = vmr9 as IVMRFilterConfig9;

            if (filterConfig == null)
            {
                throw new WPFMediaKitException("Could not query VMR9 filter configuration.");
            }

            /* We will only have one video stream connected to the filter */
            int hr = filterConfig.SetNumberOfStreams(streamCount);

            DsError.ThrowExceptionForHR(hr);

            /* Setting the renderer to "Renderless" mode
             * sounds counter productive, but its what we
             * need to do for setting up a custom allocator */
            hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            DsError.ThrowExceptionForHR(hr);

            /* Query the allocator interface */
            var vmrSurfAllocNotify = vmr9 as IVMRSurfaceAllocatorNotify9;

            if (vmrSurfAllocNotify == null)
            {
                throw new WPFMediaKitException("Could not query the VMR surface allocator.");
            }

            var allocator = new Vmr9Allocator();

            /* We supply our custom allocator to the renderer */
            hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(m_userId, allocator);
            DsError.ThrowExceptionForHR(hr);

            hr = allocator.AdviseNotify(vmrSurfAllocNotify);
            DsError.ThrowExceptionForHR(hr);

            RegisterCustomAllocator(allocator);

            hr = graph.AddFilter(vmr9,
                                 string.Format("Renderer: {0}", VideoRendererType.VideoMixingRenderer9));
            DsError.ThrowExceptionForHR(hr);

            return(vmr9);
        }
예제 #2
0
        private IBaseFilter GetRendererFilter(EVideoRendererType videoRendererType)
        {
            switch (videoRendererType)
            {
            case EVideoRendererType.EnhancedVideoRenderer:
                var evr       = new EnhancedVideoRenderer();
                var evrFilter = (IBaseFilter)evr;

                // Initialize the EVR renderer with our custom video presenter
                var evrPresenter = EVRPresenter.Create();
                ((IMFVideoRenderer)evr).InitializeRenderer(null, evrPresenter.VideoPresenter);

                // Configure the presenter with our hWnd
                var displayControl = (IMFVideoDisplayControl)evrPresenter.VideoPresenter;
                displayControl.SetVideoWindow(_hwnd);

                _customPresenter = evrPresenter;
                _customPresenter.NewSurfaceEvent += _player.NewSurface;
                _customPresenter.NewFrameEvent   += _player.NewFrame;

                return(evrFilter);

            case EVideoRendererType.VideoMixingRenderer:
                var vmr       = new VideoMixingRenderer9();
                var vmrFilter = (IBaseFilter)vmr;

                var vmrPresenter = VMR9Presenter.Create();

                // Initialize the VMR renderer with out custom video presenter
                var filterConfig = (IVMRFilterConfig9)vmr;
                filterConfig.SetRenderingMode(VMR9Mode.Renderless);
                filterConfig.SetNumberOfStreams(1);

                var surfaceAllocatorNotify = (IVMRSurfaceAllocatorNotify9)vmr;

                surfaceAllocatorNotify.AdviseSurfaceAllocator(IntPtr.Zero, vmrPresenter.SurfaceAllocator);
                vmrPresenter.SurfaceAllocator.AdviseNotify(surfaceAllocatorNotify);

                _customPresenter = vmrPresenter;
                _customPresenter.NewSurfaceEvent += _player.NewSurface;
                _customPresenter.NewFrameEvent   += _player.NewFrame;

                return(vmrFilter);
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Creates a new VMR9 renderer and configures it with an allocator
        /// </summary>
        /// <returns>An initialized DirectShow VMR9 renderer</returns>
        private IBaseFilter CreateVideoMixingRenderer9(IGraphBuilder graph)
        {
            var vmr9 = new VideoMixingRenderer9() as IBaseFilter;

            var filterConfig = vmr9 as IVMRFilterConfig9;

            if (filterConfig == null)
                throw new Exception("Could not query filter configuration.");

            /* We will only have one video stream connected to the filter */
            int hr = filterConfig.SetNumberOfStreams(4);
            DsError.ThrowExceptionForHR(hr);

            /* Setting the renderer to "Renderless" mode
             * sounds counter productive, but its what we
             * need to do for setting up a custom allocator */
            hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            DsError.ThrowExceptionForHR(hr);

            /* Query the allocator interface */
            var vmrSurfAllocNotify = vmr9 as IVMRSurfaceAllocatorNotify9;

            if (vmrSurfAllocNotify == null)
                throw new Exception("Could not query the VMR surface allocator.");

            /* We supply an hWnd so Direct3D can initialize */
            var allocator = new Vmr9Allocator(HwndHelper.Handle);

            /* We supply our custom allocator to the renderer */
            hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(userId, allocator);
            DsError.ThrowExceptionForHR(hr);

            hr = allocator.AdviseNotify(vmrSurfAllocNotify);
            DsError.ThrowExceptionForHR(hr);

            RegisterCustomAllocator(allocator);

            hr = graph.AddFilter(vmr9, //"Renderer: 1");
                                 string.Format("Renderer: {0}",
                                 VideoRendererType.VideoMixingRenderer9));

            DsError.ThrowExceptionForHR(hr);

            return vmr9;
        }
예제 #4
0
        private void LoadMovieInWindow(string filename)
        {
            int hr = 0;

            if (filename == string.Empty)
            {
                return;
            }

            this.graphBuilder        = (IGraphBuilder) new FilterGraph();
            this.captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
            this.vmr9      = new VideoMixingRenderer9();
            this.vmrConfig = this.vmr9 as IVMRFilterConfig9;

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

            hr = this.graphBuilder.AddFilter(vmr9 as IBaseFilter, "VideoMixingRenderer9");
            DsError.ThrowExceptionForHR(hr);

            hr = this.vmrConfig.SetRenderingMode(VMR9Mode.Windowless);
            DsError.ThrowExceptionForHR(hr);
            this.windowLessControl = this.vmr9 as IVMRWindowlessControl9;
            this.windowLessControl.SetVideoClippingWindow(this.Handle);
            this.windowLessControl.SetVideoPosition(null, new DsRect(0, 0, this.ClientSize.Width, this.ClientSize.Height));

            IBaseFilter fileSourceFilter;

            hr = this.graphBuilder.AddSourceFilter(filename, "WebCamSource", out fileSourceFilter);
            DsError.ThrowExceptionForHR(hr);

            hr = this.captureGraphBuilder.RenderStream(null, null, fileSourceFilter, null, vmr9 as IBaseFilter);
            DsError.ThrowExceptionForHR(hr);

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

            // QueryInterface for DirectShow interfaces
            this.mediaControl = (IMediaControl)this.graphBuilder;
            //this.mediaEventEx = (IMediaEventEx)this.graphBuilder;
            this.mediaSeeking = (IMediaSeeking)this.graphBuilder;
            //this.mediaPosition = (IMediaPosition)this.graphBuilder;

            // Query for video interfaces, which may not be relevant for audio files
            ////this.videoWindow = this.graphBuilder as IVideoWindow;
            this.basicVideo = this.graphBuilder as IBasicVideo;

            // Query for audio interfaces, which may not be relevant for video-only files
            this.basicAudio = this.graphBuilder as IBasicAudio;

            // Is this an audio-only file (no video component)?
            CheckVisibility();

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

            if (!this.isAudioOnly)
            {
                this.windowLessControl = this.vmr9 as IVMRWindowlessControl9;
                this.windowLessControl.SetVideoClippingWindow(this.Handle);
                this.windowLessControl.SetVideoPosition(null, new DsRect(0, 0, this.ClientSize.Width, this.ClientSize.Height));

                //hr = InitVideoWindow();
                //DsError.ThrowExceptionForHR(hr);

                GetFrameStepInterface();
            }

            // Complete window initialization
            //this.isFullScreen = false;
            this.currentPlaybackRate = 1.0;
            //UpdateToolTip();

#if DEBUG
            rot = new DsROTEntry(this.graphBuilder);
#endif
        }
예제 #5
0
파일: AVPlayer.cs 프로젝트: DeSciL/Ogama
    private void LoadMovieInWindow(string filename)
    {
      int hr = 0;

      if (filename == string.Empty)
        return;

      this.graphBuilder = (IGraphBuilder)new FilterGraph();
      this.captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
      this.vmr9 = new VideoMixingRenderer9();
      this.vmrConfig = this.vmr9 as IVMRFilterConfig9;

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

      hr = this.graphBuilder.AddFilter(vmr9 as IBaseFilter, "VideoMixingRenderer9");
      DsError.ThrowExceptionForHR(hr);

      hr = this.vmrConfig.SetRenderingMode(VMR9Mode.Windowless);
      DsError.ThrowExceptionForHR(hr);
      this.windowLessControl = this.vmr9 as IVMRWindowlessControl9;
      this.windowLessControl.SetVideoClippingWindow(this.Handle);
      this.windowLessControl.SetVideoPosition(null, new DsRect(0, 0, this.ClientSize.Width, this.ClientSize.Height));

      IBaseFilter fileSourceFilter;
      hr = this.graphBuilder.AddSourceFilter(filename, "WebCamSource", out fileSourceFilter);
      DsError.ThrowExceptionForHR(hr);

      hr = this.captureGraphBuilder.RenderStream(null, null, fileSourceFilter, null, vmr9 as IBaseFilter);
      DsError.ThrowExceptionForHR(hr);

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

      // QueryInterface for DirectShow interfaces
      this.mediaControl = (IMediaControl)this.graphBuilder;
      //this.mediaEventEx = (IMediaEventEx)this.graphBuilder;
      this.mediaSeeking = (IMediaSeeking)this.graphBuilder;
      //this.mediaPosition = (IMediaPosition)this.graphBuilder;

      // Query for video interfaces, which may not be relevant for audio files
      ////this.videoWindow = this.graphBuilder as IVideoWindow;
      this.basicVideo = this.graphBuilder as IBasicVideo;

      // Query for audio interfaces, which may not be relevant for video-only files
      this.basicAudio = this.graphBuilder as IBasicAudio;

      // Is this an audio-only file (no video component)?
      CheckVisibility();

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

      if (!this.isAudioOnly)
      {
        this.windowLessControl = this.vmr9 as IVMRWindowlessControl9;
        this.windowLessControl.SetVideoClippingWindow(this.Handle);
        this.windowLessControl.SetVideoPosition(null, new DsRect(0, 0, this.ClientSize.Width, this.ClientSize.Height));

        //hr = InitVideoWindow();
        //DsError.ThrowExceptionForHR(hr);

        GetFrameStepInterface();
      }

      // Complete window initialization
      //this.isFullScreen = false;
      this.currentPlaybackRate = 1.0;
      //UpdateToolTip();

#if DEBUG
      rot = new DsROTEntry(this.graphBuilder);
#endif
    }
예제 #6
0
        /// <summary>
        /// Creates a new VMR9 renderer and configures it with an allocator
        /// </summary>
        /// <returns>An initialized DirectShow VMR9 renderer</returns>
        private IBaseFilter CreateVideoMixingRenderer9(IGraphBuilder graph, int streamCount)
        {
            var vmr9 = new VideoMixingRenderer9() as IBaseFilter;

            var filterConfig = vmr9 as IVMRFilterConfig9;

            if (filterConfig == null)
                throw new Exception("Could not query filter configuration.");

            /* We will only have one video stream connected to the filter */
            int hr = filterConfig.SetNumberOfStreams(streamCount);
            DsError.ThrowExceptionForHR(hr);

            /* Setting the renderer to "Renderless" mode
             * sounds counter productive, but its what we
             * need to do for setting up a custom allocator */
            hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            DsError.ThrowExceptionForHR(hr);

            /* Query the allocator interface */
            var vmrSurfAllocNotify = vmr9 as IVMRSurfaceAllocatorNotify9;

            if (vmrSurfAllocNotify == null)
                throw new Exception("Could not query the VMR surface allocator.");

            var allocator = new Vmr9Allocator();

            IntPtr userId = new IntPtr(unchecked((int) 0xDEADBEEF));

            /* We supply our custom allocator to the renderer */
            hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(userId, allocator);
            DsError.ThrowExceptionForHR(hr);

            hr = allocator.AdviseNotify(vmrSurfAllocNotify);
            DsError.ThrowExceptionForHR(hr);

            allocator.NewAllocatorSurface += OnNewAllocatorSurfaceCallback;
            hr = graph.AddFilter(vmr9, string.Format("Renderer: {0}", "VideoMixingRenderer9"));

            DsError.ThrowExceptionForHR(hr);

            return vmr9;
        }
예제 #7
0
        private IBaseFilter GetRendererFilter(EVideoRendererType videoRendererType)
        {
            switch (videoRendererType)
            {
                case EVideoRendererType.EnhancedVideoRenderer:
                    var evr = new EnhancedVideoRenderer();
                    var evrFilter = (IBaseFilter)evr;

                    // Initialize the EVR renderer with our custom video presenter
                    var evrPresenter = EVRPresenter.Create();
                    ((IMFVideoRenderer)evr).InitializeRenderer(null, evrPresenter.VideoPresenter);

                    // Configure the presenter with our hWnd
                    var displayControl = (IMFVideoDisplayControl)evrPresenter.VideoPresenter;
                    displayControl.SetVideoWindow(_hwnd);

                    _customPresenter = evrPresenter;
                    _customPresenter.NewSurfaceEvent += _player.NewSurface;
                    _customPresenter.NewFrameEvent += _player.NewFrame;

                    return evrFilter;

                case EVideoRendererType.VideoMixingRenderer:
                    var vmr = new VideoMixingRenderer9();
                    var vmrFilter = (IBaseFilter)vmr;

                    var vmrPresenter = VMR9Presenter.Create();

                    // Initialize the VMR renderer with out custom video presenter
                    var filterConfig = (IVMRFilterConfig9)vmr;
                    filterConfig.SetRenderingMode(VMR9Mode.Renderless);
                    filterConfig.SetNumberOfStreams(1);

                    var surfaceAllocatorNotify = (IVMRSurfaceAllocatorNotify9)vmr;

                    surfaceAllocatorNotify.AdviseSurfaceAllocator(IntPtr.Zero, vmrPresenter.SurfaceAllocator);
                    vmrPresenter.SurfaceAllocator.AdviseNotify(surfaceAllocatorNotify);

                    _customPresenter = vmrPresenter;
                    _customPresenter.NewSurfaceEvent += _player.NewSurface;
                    _customPresenter.NewFrameEvent += _player.NewFrame;

                    return vmrFilter;
            }

            return null;
        }