Пример #1
0
        private void AddVideoRenderer()
        {
            int hr;

            _videoRender = (IBaseFilter) new VideoMixingRenderer();
            Debug.Assert(_videoRender != null);
            hr = _graphBuilder.AddFilter(_videoRender, "VMR7");
            DsError.ThrowExceptionForHR(hr);

            // Configure the video renderer

            if (_hostControl != null)
            {
                IVMRFilterConfig vmrFilterConfig = (IVMRFilterConfig)_videoRender;
                hr = vmrFilterConfig.SetRenderingMode(VMRMode.Windowless);
                DsError.ThrowExceptionForHR(hr);
                _vmrWindowlessControl = (IVMRWindowlessControl)_videoRender;
                hr = _vmrWindowlessControl.SetAspectRatioMode(VMRAspectRatioMode.LetterBox);
                DsError.ThrowExceptionForHR(hr);
                hr = _vmrWindowlessControl.SetVideoClippingWindow(_hostControl.Handle);
                DsError.ThrowExceptionForHR(hr);
                ResizeMoveHandler(null, null);
                _hostControl.Paint  += new PaintEventHandler(PaintHandler);
                _hostControl.Resize += new EventHandler(ResizeMoveHandler);
                _hostControl.Move   += new EventHandler(ResizeMoveHandler);
            }
            else
            {
                throw new Exception("Host control not specified");
            }
        }
        protected override void CloseInterfaces()
        {
            _pVMRFilterConfig      = null;
            _pVMRWindowlessControl = null; // they will be released when pBaseFilter is released

            base.CloseInterfaces();        // release pBaseFilter
        }
Пример #3
0
        /// <summary>
        /// Add VMR7 filter to graph and configure it
        /// </summary>
        /// <param name="graphBuilder"></param>
        public void AddVMR7(IGraphBuilder graphBuilder)
        {
            Log.Info("VMR7Helper:AddVMR7");
            if (vmr7intialized)
            {
                return;
            }

            VMR7Filter = (IBaseFilter) new VideoMixingRenderer();
            if (VMR7Filter == null)
            {
                Error.SetError("Unable to play movie", "VMR7 is not installed");
                Log.Error("VMR7Helper:Failed to get instance of VMR7 ");
                return;
            }

            int hr;
            IVMRFilterConfig config = VMR7Filter as IVMRFilterConfig;

            if (config != null)
            {
                hr = config.SetNumberOfStreams(1);
                if (hr != 0)
                {
                    Log.Error("VMR7Helper:Failed to set number of streams:0x{0:X}", hr);
                    DirectShowUtil.ReleaseComObject(VMR7Filter);
                    VMR7Filter = null;
                    return;
                }
            }

            hr = graphBuilder.AddFilter(VMR7Filter, "Video Mixing Renderer");
            if (hr != 0)
            {
                Error.SetError("Unable to play movie", "Unable to initialize VMR7");
                Log.Error("VMR7Helper:Failed to add VMR7 to filtergraph");
                DirectShowUtil.ReleaseComObject(VMR7Filter);
                VMR7Filter = null;
                return;
            }
            m_graphBuilder = graphBuilder;
            m_mixerBitmap  = VMR7Filter as IVMRMixerBitmap;
            quality        = VMR7Filter as IQualProp;
            g_vmr7         = this;
            vmr7intialized = true;
        }
        protected override void Initialize(IGraphBuilder pGraphBuilder, IntPtr hMediaWindow)
        {
            // QUERY the VMR interfaces
            try
            {
                _pVMRFilterConfig = (IVMRFilterConfig)BaseFilter;
                _pVMRFilterConfig.SetRenderingMode(VMRMode.VMRMode_Windowless);
                _pVMRWindowlessControl = (IVMRWindowlessControl)BaseFilter;
                _pVMRWindowlessControl.SetVideoClippingWindow(hMediaWindow);

                _pVMRWindowlessControl.SetAspectRatioMode(VMR_ASPECT_RATIO_MODE.VMR_ARMODE_NONE);
            }
            catch (Exception e)
            {
                throw new FilterGraphBuilderException(GraphBuilderError.ConfigureVMR, e);
            }
        }
Пример #5
0
        public void DoTests()
        {
            try
            {
                BuildGraph(testFile, out this.graphBuilder, out this.vmr7Filter);
                this.vmrConfig = this.vmr7Filter as IVMRFilterConfig;

                TestNumberOfStreams();
                TestRenderingMode();
                TestRenderingPrefs();
                TestSetImageCompositor();
            }
            finally
            {
                Marshal.ReleaseComObject(this.vmr7Filter);
                Marshal.ReleaseComObject(this.graphBuilder);
            }
        }
Пример #6
0
        protected void AddVideoRender()
        {
            int hr;

            _videoRender = (IBaseFilter) new VideoMixingRenderer();
            hr           = _graphBuilder.AddFilter(_videoRender, "VMR");
            DsError.ThrowExceptionForHR(hr);

            // Configure the video renderer

            IVMRFilterConfig vmrFilterConfig = (IVMRFilterConfig)_videoRender;

            hr = vmrFilterConfig.SetRenderingMode(VMRMode.Windowless);
            DsError.ThrowExceptionForHR(hr);
            _windowlessControl = (IVMRWindowlessControl)_videoRender;
            hr = _windowlessControl.SetAspectRatioMode(VMRAspectRatioMode.LetterBox);
            DsError.ThrowExceptionForHR(hr);
            NotifyPropertyChanged("VideoRender");
        }
Пример #7
0
        public void BuildGraph()
        {
            int hr = 0;

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

            vmr = (IBaseFilter) new VideoMixingRenderer();

            IVMRFilterConfig filterConfig = (IVMRFilterConfig)vmr;

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

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

            surfaceAllocatorNotify = (IVMRSurfaceAllocatorNotify)vmr;

            hr = surfaceAllocatorNotify.AdviseSurfaceAllocator(cookie, this);
            DsError.ThrowExceptionForHR(hr);

            defaultAllocatorPresenter = (IVMRSurfaceAllocator)Activator.CreateInstance(Type.GetTypeFromCLSID(VMRClsId.AllocPresenter));

            form = new Form();
            form.Show();

            hr = (defaultAllocatorPresenter as IVMRWindowlessControl).SetVideoClippingWindow(form.Handle);
            DsError.ThrowExceptionForHR(hr);

            hr = this.AdviseNotify(surfaceAllocatorNotify);
            DsError.ThrowExceptionForHR(hr);

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

            hr = graphBuilder.RenderFile(@"..\..\..\Resources\foo.avi", null);
            DsError.ThrowExceptionForHR(hr);
        }
        public void BuildGraph()
        {
            int hr = 0;

            graphBuilder = (IFilterGraph2) new FilterGraph();

            rot = new DsROTEntry(graphBuilder);

            vmr = (IBaseFilter) new VideoMixingRenderer();

            IVMRFilterConfig filterConfig = (IVMRFilterConfig)vmr;

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

            // Set the custom compositor
            hr = filterConfig.SetImageCompositor(this);
            DsError.ThrowExceptionForHR(hr);

            IVMRMixerControl mixerControl = (IVMRMixerControl)vmr;

            // In COLORREF, colors are coded in ABGR format
            hr = mixerControl.SetBackgroundClr(backgroundColorABGR);
            DsError.ThrowExceptionForHR(hr);

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

            // The 2 VMR pins must be connected...
            hr = graphBuilder.RenderFile(@"..\..\..\Resources\foo.avi", null);
            DsError.ThrowExceptionForHR(hr);

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

            hr = (graphBuilder as IMediaControl).Run();
            DsError.ThrowExceptionForHR(hr);
        }
Пример #9
0
        public void DoTests()
        {
            int hr = 0;
            IVMRFilterConfig vmrConfig = null;
            DsROTEntry       ROT       = null;

            this.Show();

            try
            {
                // Just build the graph with unconnected source filter and VMR7
                BuildGraph(testFile, out this.graphBuilder, out this.sourceFilter, out this.vmr7Filter);

                // VMR7 need to be placed in Windowless mode before connecting it to the rest of the graph
                vmrConfig = this.vmr7Filter as IVMRFilterConfig;
                hr        = vmrConfig.SetRenderingMode(VMRMode.Windowless);
                Marshal.ThrowExceptionForHR(hr);

                this.vmrWndConfig = this.vmr7Filter as IVMRWindowlessControl;

                TestSetVideoClippingWindow();
                TestAspectRatioMode();
                TestBorderColor();
                TestColorKey();
                TestGetMaxIdealVideoSize();
                TestGetMinIdealVideoSize();

                // Connect source filter with the VMR7
                ConnectGraph(ref this.graphBuilder, ref this.sourceFilter, ref this.vmr7Filter);
                ROT = new DsROTEntry(this.graphBuilder);

                // Run the graph to test other methods
                this.mediaControl = this.graphBuilder as IMediaControl;
                hr = this.mediaControl.Run();
                Marshal.ThrowExceptionForHR(hr);

                this.timer          = new System.Windows.Forms.Timer();
                this.timer.Interval = 2000;
                this.timer.Enabled  = true;
                this.timer.Tick    += new EventHandler(DoTestsPart2);
                this.timer.Start();

                this.isPlaying = true;
                TestVideoPosition();

                Application.Run(this);
            }
            finally
            {
                if (ROT != null)
                {
                    ROT.Dispose();
                }
                if (this.mediaControl != null)
                {
                    this.mediaControl.Stop();
                }
                Marshal.ReleaseComObject(this.vmr7Filter);
                Marshal.ReleaseComObject(this.sourceFilter);
                Marshal.ReleaseComObject(this.graphBuilder);
            }
        }