Ejemplo n.º 1
0
        public void ZoomToRect(Rectangle zoomRect)
        {
            NormalizedRect rect = new NormalizedRect();

            if ((zoomRect.Height == 0) || (zoomRect.Width == 0))
            {
                throw new Exception("ZoomRect has zero size.");
            }
            IVMRMixerControl9 vMRenderer = (IVMRMixerControl9)this.DX.VMRenderer;

            if (vMRenderer == null)
            {
                throw new Exception("The Mixer control is not created.");
            }
            float num  = ((float)this._Resolution.Width) / ((float)zoomRect.Width);
            float num2 = ((float)this._Resolution.Height) / ((float)zoomRect.Height);

            rect = new NormalizedRect(-((float)zoomRect.Left) * num, -((float)zoomRect.Top) * num2, (-((float)zoomRect.Right) * num) + (this._Resolution.Width * (num + 1f)), (-((float)zoomRect.Bottom) * num2) + (this._Resolution.Height * (num2 + 1f)))
            {
                left   = rect.left / ((float)this._Resolution.Width),
                right  = rect.right / ((float)this._Resolution.Width),
                top    = rect.top / ((float)this._Resolution.Height),
                bottom = rect.bottom / ((float)this._Resolution.Height)
            };
            vMRenderer.SetOutputRect(0, ref rect);
        }
Ejemplo n.º 2
0
        public void InitVMR9(string filename)
        {
            int hr = 0;

            // Create a DirectShow FilterGraph
            graphBuilder = (IFilterGraph2) new FilterGraph();

            // Add it in ROT for debug purpose
            rot = new DsROTEntry(graphBuilder);

            // Add a notification handler (see WndProc)
            hr = (graphBuilder as IMediaEventEx).SetNotifyWindow(this.Handle, WM_GRAPHNOTIFY, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);

            // Create a VMR9 object
            vmr9 = (IBaseFilter) new VideoMixingRenderer9();

            IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)vmr9;

            // We want the Renderless mode!
            hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless);
            DsError.ThrowExceptionForHR(hr);

            // One stream is enough for this sample
            hr = filterConfig.SetNumberOfStreams(1);
            DsError.ThrowExceptionForHR(hr);

            // Create the Allocator / Presenter object
            allocator = new Allocator(device);

            IVMRSurfaceAllocatorNotify9 vmrSurfAllocNotify = (IVMRSurfaceAllocatorNotify9)vmr9;

            // Notify the VMR9 filter about our allocator
            hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(IntPtr.Zero, allocator);
            DsError.ThrowExceptionForHR(hr);

            // Notify our allocator about the VMR9 filter
            hr = allocator.AdviseNotify(vmrSurfAllocNotify);
            DsError.ThrowExceptionForHR(hr);

            IVMRMixerControl9 mixerControl = (IVMRMixerControl9)vmr9;

            // Select the mixer mode : YUV or RGB
            hr = mixerControl.SetMixingPrefs(VMR9MixerPrefs.RenderTargetYUV | VMR9MixerPrefs.NoDecimation | VMR9MixerPrefs.ARAdjustXorY | VMR9MixerPrefs.BiLinearFiltering);
            //hr = mixerControl.SetMixingPrefs(VMR9MixerPrefs.RenderTargetRGB | VMR9MixerPrefs.NoDecimation | VMR9MixerPrefs.ARAdjustXorY | VMR9MixerPrefs.BiLinearFiltering);
            DsError.ThrowExceptionForHR(hr);

            // Add the filter to the graph
            hr = graphBuilder.AddFilter(vmr9, "Video Mixing Renderer 9");
            DsError.ThrowExceptionForHR(hr);

            // Render the file
            hr = graphBuilder.RenderFile(filename, null);
            DsError.ThrowExceptionForHR(hr);

            // Run the graph
            hr = (graphBuilder as IMediaControl).Run();
            DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 3
0
        public void BuildGraph()
        {
            int hr = 0;

            graphBuilder = (IFilterGraph2) new FilterGraph();
            vmr9         = (IBaseFilter) new VideoMixingRenderer9();

            hr = (vmr9 as IVMRFilterConfig9).SetNumberOfStreams(4);
            DsError.ThrowExceptionForHR(hr);

            vmr9MixerControl = (IVMRMixerControl9)vmr9;

            hr = graphBuilder.AddFilter(vmr9, "VMR9");
            DsError.ThrowExceptionForHR(hr);
        }
Ejemplo n.º 4
0
        private void ConfigureVMR9InWindowlessMode()
        {
            int hr = 0;
            IVMRFilterConfig9 filterConfig = this.videoRenderer as IVMRFilterConfig9;

            // Configure VMR-9 in Windowsless mode
            hr = filterConfig.SetRenderingMode(VMR9Mode.Windowless);
            DsError.ThrowExceptionForHR(hr);

            // With 1 input stream
            hr = filterConfig.SetNumberOfStreams(1);
            DsError.ThrowExceptionForHR(hr);

            IVMRWindowlessControl9 windowlessControl = this.videoRenderer as IVMRWindowlessControl9;

            // The main form is hosting the VMR-9
            hr = windowlessControl.SetVideoClippingWindow(this.hostingControl.Handle);
            DsError.ThrowExceptionForHR(hr);

            // Keep the aspect-ratio OK
            hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.LetterBox);
            DsError.ThrowExceptionForHR(hr);

            IVMRMixerControl9 mixerControl = this.videoRenderer as IVMRMixerControl9;
            VMR9MixerPrefs    mixerPrefs;

            hr = mixerControl.GetMixingPrefs(out mixerPrefs);
            DsError.ThrowExceptionForHR(hr);

            // Configure the VMR9 filter to use YUV mixing
            mixerPrefs &= ~VMR9MixerPrefs.RenderTargetMask;
            mixerPrefs |= VMR9MixerPrefs.RenderTargetYUV;

            hr = mixerControl.SetMixingPrefs(mixerPrefs);
            DsError.ThrowExceptionForHR(hr);

            // Init the VMR-9 with default size values
            ResizeMoveHandler(null, null);

            // Add Windows Messages handlers
            AddHandlers();
        }
        public void BuildGraph()
        {
            int hr = 0;

            graphBuilder = (IFilterGraph2) new FilterGraph();

            rot = new DsROTEntry(graphBuilder);

            vmr9 = (IBaseFilter) new VideoMixingRenderer9();

            IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)vmr9;

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

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

            IVMRMixerControl9 mixerControl = (IVMRMixerControl9)vmr9;

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

            hr = graphBuilder.AddFilter(vmr9, "VMR9");
            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);
        }
Ejemplo n.º 6
0
        //public bool IsVMR9Connected

        #endregion

        #region public members

        /// <summary>
        /// Add VMR9 filter to graph and configure it
        /// </summary>
        /// <param name="graphBuilder"></param>
        public bool AddVMR9(IGraphBuilder graphBuilder)
        {
            if (!_useVmr9)
            {
                Log.Debug("VMR9: addvmr9 - vmr9 is deactivated");
                return(false);
            }
            if (_isVmr9Initialized)
            {
                Log.Debug("VMR9: addvmr9: vmr9 has already been initialized");
                return(false);
            }

            bool _useEvr = GUIGraphicsContext.IsEvr;

            if (_instanceCounter != 0)
            {
                Log.Error("VMR9: Multiple instances of VMR9 running!!!");
                throw new Exception("VMR9Helper: Multiple instances of VMR9 running!!!");
            }

            HResult hr;
            IntPtr  hMonitor = Manager.GetAdapterMonitor(GUIGraphicsContext.DX9Device.DeviceCaps.AdapterOrdinal);
            IntPtr  upDevice = DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device);

            _scene = new PlaneScene(this);
            _scene.Init();

            if (_useEvr)
            {
                EvrInit(_scene, (uint)upDevice.ToInt32(), ref _vmr9Filter, (uint)hMonitor.ToInt32());
                hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "Enhanced Video Renderer"));
                Log.Info("VMR9: added EVR Renderer to graph");
            }
            else
            {
                _vmr9Filter = (IBaseFilter) new VideoMixingRenderer9();
                Log.Info("VMR9: added Video Mixing Renderer 9 to graph");

                Vmr9Init(_scene, (uint)upDevice.ToInt32(), _vmr9Filter, (uint)hMonitor.ToInt32());
                hr = new HResult(graphBuilder.AddFilter(_vmr9Filter, "Video Mixing Renderer 9"));
            }

            if (_vmr9Filter == null)
            {
                Error.SetError("Unable to play movie", "Renderer could not be added");
                Log.Error("VMR9: Renderer not installed / cannot be used!");
                return(false);
            }

            if (hr != 0)
            {
                if (_useEvr)
                {
                    EvrDeinit();
                }
                else
                {
                    Vmr9Deinit();
                }
                _scene.Stop();
                _scene.Deinit();
                _scene = null;

                DirectShowUtil.ReleaseComObject(_vmr9Filter);
                _vmr9Filter = null;
                Error.SetError("Unable to play movie", "Unable to initialize Renderer");
                Log.Error("VMR9: Failed to add Renderer to filter graph");
                return(false);
            }

            _qualityInterface         = _vmr9Filter as IQualProp;
            _vmr9MixerBitmapInterface = _vmr9Filter as IVMRMixerBitmap9;
            _graphBuilderInterface    = graphBuilder;
            _instanceCounter++;
            _isVmr9Initialized = true;
            if (!_useEvr)
            {
                SetDeinterlacePrefs();

                IVMRMixerControl9 mixer = _vmr9Filter as IVMRMixerControl9;
                if (mixer != null)
                {
                    VMR9MixerPrefs dwPrefs;
                    mixer.GetMixingPrefs(out dwPrefs);
                    dwPrefs &= ~VMR9MixerPrefs.RenderTargetMask;

                    dwPrefs |= VMR9MixerPrefs.RenderTargetYUV;
                    // YUV saves graphics bandwith  http://msdn2.microsoft.com/en-us/library/ms788177(VS.85).aspx
                    hr.Set(mixer.SetMixingPrefs(dwPrefs));
                    Log.Debug("VMR9: Enabled YUV mixing - " + hr.ToDXString());

                    using (Settings xmlreader = new MPSettings())
                    {
                        //Enable nonsquaremixing
                        if (xmlreader.GetValueAsBool("general", "nonsquare", true))
                        {
                            mixer.GetMixingPrefs(out dwPrefs);
                            dwPrefs |= VMR9MixerPrefs.NonSquareMixing;
                            hr.Set(mixer.SetMixingPrefs(dwPrefs));
                            Log.Debug("VRM9: Turning on nonsquare mixing - " + hr.ToDXString());
                            hr.Set(mixer.SetMixingPrefs(dwPrefs));
                        }

                        // Enable DecimateMask - this will effectively use only half of the input width & length
                        if (xmlreader.GetValueAsBool("general", "dx9decimatemask", false))
                        {
                            mixer.GetMixingPrefs(out dwPrefs);
                            dwPrefs &= ~VMR9MixerPrefs.DecimateMask;
                            dwPrefs |= VMR9MixerPrefs.DecimateOutput;
                            hr.Set(mixer.SetMixingPrefs(dwPrefs));
                            Log.Debug("VRM9: Enable decimatemask - " + hr.ToDXString());
                            hr.Set(mixer.SetMixingPrefs(dwPrefs));
                        }

                        // see  D3DTEXTUREFILTERTYPE Enumerated Type documents for further information
                        // MixerPref9_PointFiltering
                        // MixerPref9_BiLinearFiltering
                        // MixerPref9_AnisotropicFiltering
                        // MixerPref9_PyramidalQuadFiltering
                        // MixerPref9_GaussianQuadFiltering

                        mixer.SetMixingPrefs(dwPrefs);
                        mixer.GetMixingPrefs(out dwPrefs);
                        dwPrefs &= ~VMR9MixerPrefs.FilteringMask;
                        string filtermode9 = xmlreader.GetValueAsString("general", "dx9filteringmode", "Gaussian Quad Filtering");
                        if (filtermode9 == "Point Filtering")
                        {
                            dwPrefs |= VMR9MixerPrefs.PointFiltering;
                        }
                        else if (filtermode9 == "Bilinear Filtering")
                        {
                            dwPrefs |= VMR9MixerPrefs.BiLinearFiltering;
                        }
                        else if (filtermode9 == "Anisotropic Filtering")
                        {
                            dwPrefs |= VMR9MixerPrefs.AnisotropicFiltering;
                        }
                        else if (filtermode9 == "Pyrimidal Quad Filtering")
                        {
                            dwPrefs |= VMR9MixerPrefs.PyramidalQuadFiltering;
                        }
                        else
                        {
                            dwPrefs |= VMR9MixerPrefs.GaussianQuadFiltering;
                        }

                        hr.Set(mixer.SetMixingPrefs(dwPrefs));
                        Log.Debug("VRM9: Set filter mode - " + filtermode9 + " " + hr.ToDXString());
                    }
                }
            }
            _threadId = Thread.CurrentThread.ManagedThreadId;
            GUIGraphicsContext.Vmr9Active = true;
            g_vmr9 = this;
            Log.Debug("VMR9: Renderer successfully added");
            return(true);
        }
Ejemplo n.º 7
0
        protected override HRESULT OnInitInterfaces()
        {
            m_Renderer             = new VMR9Renderer();
            m_Renderer.FilterGraph = m_GraphBuilder;
            IVMRFilterConfig9 _config = (IVMRFilterConfig9)m_Renderer.QueryInterface(typeof(IVMRFilterConfig9).GUID);
            HRESULT           hr;

            if (_config != null)
            {
                hr = (HRESULT)_config.SetRenderingMode(VMR9Mode.Renderless);
                hr.Assert();
                hr = (HRESULT)_config.SetNumberOfStreams(2);
                hr.Assert();
            }

            m_mixerControl = (IVMRMixerControl9)m_Renderer.QueryInterface(typeof(IVMRMixerControl9).GUID);

            m_mixerControl.SetBackgroundClr((int)0xbf7f2f);

            VMR9MixerPrefs mixerPrefs;

            m_mixerControl.GetMixingPrefs(out mixerPrefs);
            m_mixerControl.SetMixingPrefs(mixerPrefs);

            IVMRSurfaceAllocatorNotify9 _notify = (IVMRSurfaceAllocatorNotify9)m_Renderer.QueryInterface(typeof(IVMRSurfaceAllocatorNotify9).GUID);

            if (_notify != null)
            {
                hr = (HRESULT)_notify.AdviseSurfaceAllocator(new IntPtr(g_ciUsedID), this);
                hr.Assert();
                hr = (HRESULT)this.AdviseNotify(_notify);
                hr.Assert();
            }

            DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory();
            List <DSFilter>        capFilters      = new List <DSFilter>();

            foreach (var captureDevice in captureCategory.Objects)
            {
                if (captureDevice.DevicePath == m_leftEyeDevicePath)
                {
                    capFilters.Add(captureDevice.Filter);
                    break;
                }
            }

            foreach (var captureDevice in captureCategory.Objects)
            {
                if (captureDevice.DevicePath == m_rightEyeDevicePath)
                {
                    capFilters.Add(captureDevice.Filter);
                    break;
                }
            }

            if (capFilters.Count < 2)
            {
                MessageBox.Show("Not enough capture devices found (" + capFilters.Count.ToString() + " device(s))");
                throw new Exception();
            }


            for (int i = 0; i < 2; i++)
            {
                if (capFilters[i] == null)
                {
                    return(E_FAIL);
                }

                DSPin capturePin = null;

                foreach (var outputPin in capFilters[i].Output)
                {
                    if (outputPin.Name == "Capture")
                    {
                        capturePin = outputPin;
                        break;
                    }
                }

                AMMediaType mjpgMediaType = null;

                int maxPixels = -1;
                foreach (var mediaType in capturePin.MediaTypes)
                {
                    VideoInfoHeader videoInfo = new VideoInfoHeader();
                    videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.formatPtr, typeof(VideoInfoHeader));

                    // pick the highest res mode...
                    if ((videoInfo.BmiHeader.Width * videoInfo.BmiHeader.Height) > maxPixels)
                    {
                        maxPixels     = videoInfo.BmiHeader.Width * videoInfo.BmiHeader.Height;
                        mjpgMediaType = mediaType;
                        //break;
                    }
                }

                capFilters[i].OutputPin.Format = mjpgMediaType;

                capFilters[i].FilterGraph = m_GraphBuilder;
                capFilters[i].Connect(m_Renderer);
            }


            VMR9NormalizedRect r1 = new VMR9NormalizedRect(0, 0, 0.5f, 1f);
            VMR9NormalizedRect r2 = new VMR9NormalizedRect(0.5f, 0f, 1f, 1f);

            int rt0 = m_mixerControl.SetOutputRect(0, ref r1);
            int rt1 = m_mixerControl.SetOutputRect(1, ref r2);

            hr = base.OnInitInterfaces();

            return(hr);
        }
Ejemplo n.º 8
0
        void initGraph(Rectangle rect, IntPtr hwnd)
        {
            log.writeLog("Init Graph");
            pGB           = (IGraphBuilder) new FilterGraph();
            pVmr          = (IBaseFilter) new VideoMixingRenderer9();
            compressVideo = CreateFilter(FilterCategory.VideoCompressorCategory, lstCompressor[3]);
            pGB.AddFilter(pVmr, "Video");
            pGB.AddFilter(captureVideo, "VideoCapture");
            //pGB.AddFilter(compressVideo, "Encoder");

            pConfig = (IVMRFilterConfig9)pVmr;
            pConfig.SetRenderingMode(VMR9Mode.Windowless);
            pWC = (IVMRWindowlessControl9)pVmr;

            pWC.SetVideoPosition(null, DsRect.FromRectangle(rect));
            pWC.SetVideoClippingWindow(hwnd);

            pMix = (IVMRMixerControl9)pVmr;
            pMs  = (IMediaSeeking)pGB;
            pMC  = (IMediaControl)pGB;

            ICaptureGraphBuilder2 cc = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            cc.SetFiltergraph(pGB);
            pGB.AddFilter(devices[0], "Camera-1");
            if (devices[1] != null)
            {
                pGB.AddFilter(devices[1], "Camera-2");
            }
            pGB.AddFilter(audioCapture, "Audio Capture");

            Rectangle win = rect;
            float     _w  = win.Width;
            float     _H  = win.Height;

            NormalizedRect _0rect = new NormalizedRect();

            _0rect.top    = win.Top;
            _0rect.left   = win.Left;
            _0rect.right  = (win.Left + win.Width / 2) / _w;
            _0rect.bottom = (win.Bottom / _H);

            NormalizedRect _1rect = new NormalizedRect();

            _1rect.top    = win.Top;
            _1rect.left   = (win.Left + win.Width / 2) / _w;;
            _1rect.right  = win.Right / _w;
            _1rect.bottom = win.Bottom / _H;

            pMix.SetOutputRect(0, _0rect);
            pMix.SetOutputRect(1, _1rect);

            int             hr   = 0;
            IFileSinkFilter sink = null;

            log.writeLog("SetOutputFileName create");
            hr = cc.SetOutputFileName(MediaSubType.Avi, "VideoCaptured.avi", out captureVideo, out sink);
            DsError.ThrowExceptionForHR(hr);
            log.writeLog("SetOutputFileName success");
            log.writeLog("Start create cam-1 to preview");
            hr = cc.RenderStream(PinCategory.Preview, MediaType.Video, devices[0], null, pVmr);
            DsError.ThrowExceptionForHR(hr);
            log.writeLog("Start cam-1 to preview success");
            if (devices[1] != null)
            {
                log.writeLog("Start create cam-2 to preview");
                hr = cc.RenderStream(PinCategory.Preview, MediaType.Video, devices[1], null, pVmr);
                DsError.ThrowExceptionForHR(hr);
                log.writeLog("Create cam-2 to preview success");
            }
            log.writeLog("Start capture video from cam-1");
            hr = cc.RenderStream(PinCategory.Capture, MediaType.Video, devices[0], null, captureVideo);
            DsError.ThrowExceptionForHR(hr);
            log.writeLog("success create capture from cam-1");
            log.writeLog("Start capture audio");
            hr = cc.RenderStream(PinCategory.Capture, MediaType.Audio, audioCapture, null, captureVideo);
            DsError.ThrowExceptionForHR(hr);
            log.writeLog("Success to capture audio");

            Marshal.ReleaseComObject(cc);
        }
Ejemplo n.º 9
0
        protected override HRESULT OnInitInterfaces()
        {
            m_Renderer = new VMR9Renderer();
            m_Renderer.FilterGraph = m_GraphBuilder;
            IVMRFilterConfig9 _config = (IVMRFilterConfig9)m_Renderer.QueryInterface(typeof(IVMRFilterConfig9).GUID);
            HRESULT hr;
            if (_config != null)
            {
                hr = (HRESULT)_config.SetRenderingMode(VMR9Mode.Renderless);
                hr.Assert();
                hr = (HRESULT)_config.SetNumberOfStreams(2);
                hr.Assert();
            }

            m_mixerControl = (IVMRMixerControl9)m_Renderer.QueryInterface(typeof(IVMRMixerControl9).GUID);

            m_mixerControl.SetBackgroundClr((int)0xbf7f2f);

            VMR9MixerPrefs mixerPrefs;
            m_mixerControl.GetMixingPrefs(out mixerPrefs);
            m_mixerControl.SetMixingPrefs(mixerPrefs);

            IVMRSurfaceAllocatorNotify9 _notify = (IVMRSurfaceAllocatorNotify9)m_Renderer.QueryInterface(typeof(IVMRSurfaceAllocatorNotify9).GUID);
            if (_notify != null)
            {
                hr = (HRESULT)_notify.AdviseSurfaceAllocator(new IntPtr(g_ciUsedID), this);
                hr.Assert();
                hr = (HRESULT)this.AdviseNotify(_notify);
                hr.Assert();
            }

            DSVideoCaptureCategory captureCategory = new DSVideoCaptureCategory();
            List<DSFilter> capFilters = new List<DSFilter>();
            foreach (var captureDevice in captureCategory.Objects)
            {
                if (captureDevice.DevicePath == m_leftEyeDevicePath)
                {
                    capFilters.Add(captureDevice.Filter);
                    break;
                }
            }

            foreach (var captureDevice in captureCategory.Objects)
            {
                if (captureDevice.DevicePath == m_rightEyeDevicePath)
                {
                    capFilters.Add(captureDevice.Filter);
                    break;
                }
            }

            if (capFilters.Count < 2)
            {
                MessageBox.Show("Not enough capture devices found (" + capFilters.Count.ToString() + " device(s))");
                throw new Exception();
            }

            for (int i = 0; i < 2; i++)
            {
                if (capFilters[i] == null)
                {
                    return E_FAIL;
                }

                DSPin capturePin = null;

                foreach (var outputPin in capFilters[i].Output)
                {
                    if (outputPin.Name == "Capture")
                    {
                        capturePin = outputPin;
                        break;
                    }
                }

                AMMediaType mjpgMediaType = null;

                int maxPixels = -1;
                foreach (var mediaType in capturePin.MediaTypes)
                {
                    VideoInfoHeader videoInfo = new VideoInfoHeader();
                    videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.formatPtr, typeof(VideoInfoHeader));

                    // pick the highest res mode...
                    if ((videoInfo.BmiHeader.Width * videoInfo.BmiHeader.Height) > maxPixels)
                    {
                        maxPixels = videoInfo.BmiHeader.Width * videoInfo.BmiHeader.Height;
                        mjpgMediaType = mediaType;
                        //break;
                    }
                }

                capFilters[i].OutputPin.Format = mjpgMediaType;

                capFilters[i].FilterGraph = m_GraphBuilder;
                capFilters[i].Connect(m_Renderer);
            }

            VMR9NormalizedRect r1 = new VMR9NormalizedRect(0, 0, 0.5f, 1f);
            VMR9NormalizedRect r2 = new VMR9NormalizedRect(0.5f, 0f, 1f, 1f);

            int rt0 = m_mixerControl.SetOutputRect(0, ref r1);
            int rt1 = m_mixerControl.SetOutputRect(1, ref r2);

            hr = base.OnInitInterfaces();

            return hr;
        }
Ejemplo n.º 10
0
        private void BuildMosaicGraph(ITuningSpace tuningSpace, ArrayList programs)
        {
            this.graphBuilder = (IFilterGraph2) new FilterGraph();
            rot = new DsROTEntry(this.graphBuilder);

            // Method names should be self explanatory
            AddNetworkProviderFilter(tuningSpace);
            AddMPEG2DemuxFilter();

            AddAndConnectBDABoardFilters();
            AddTransportStreamFiltersToGraph();
            AddRenderers();

            //unsafe
            //{
            IntPtr formatPtr = Marshal.AllocHGlobal(g_Mpeg2ProgramVideo.Length);

            Marshal.Copy(g_Mpeg2ProgramVideo, 0, formatPtr, g_Mpeg2ProgramVideo.Length);

            IMpeg2Demultiplexer mpeg2Demultiplexer = this.mpeg2Demux as IMpeg2Demultiplexer;

            for (int p = 1; p < programs.Count; p++)
            {
                PSI.PSIPMT      pmt    = (PSI.PSIPMT)programs[p];
                PSI.PSIPMT.Data stream = (PSI.PSIPMT.Data)pmt.GetStreamByType(CodeTV.PSI.STREAM_TYPES.STREAMTYPE_13818_VIDEO);

                AMMediaType mediaType = new AMMediaType();
                mediaType.majorType           = MediaType.Video;
                mediaType.subType             = MediaSubType.Mpeg2Video;
                mediaType.fixedSizeSamples    = false;
                mediaType.temporalCompression = false;
                mediaType.sampleSize          = 0;
                mediaType.formatType          = FormatType.Mpeg2Video;
                mediaType.unkPtr = IntPtr.Zero;

                mediaType.formatSize = g_Mpeg2ProgramVideo.Length;
                mediaType.formatPtr  = formatPtr;

                //mediaType.formatType = FormatType.Mpeg2Video;
                //mediaType.formatSize = 0;
                //mediaType.formatPtr = IntPtr.Zero;

                string pinName = "video" + p;
                IPin   outputPin;
                int    hr = mpeg2Demultiplexer.CreateOutputPin(mediaType, pinName, out outputPin);
                if (outputPin != null)
                {
                    IMPEG2PIDMap mpeg2PIDMap = outputPin as IMPEG2PIDMap;
                    if (mpeg2PIDMap != null)
                    {
                        hr = mpeg2PIDMap.MapPID(1, new int[] { stream.Pid }, MediaSampleContent.ElementaryStream);
                    }
                    Marshal.ReleaseComObject(outputPin);
                }
            }
            Marshal.FreeHGlobal(formatPtr);
            //}

            ConfigureVMR9InWindowlessMode(programs.Count);
            ConnectAllOutputFilters();

            int   numberColumn  = 4;
            int   numberRow     = 4;
            float widthPadding  = 0.01f;
            float heightPadding = 0.01f;

            float width  = (1.0f / numberColumn) - 2.0f * widthPadding;
            float height = (1.0f / numberRow) - 2.0f * heightPadding;

            IVMRMixerControl9 vmrMixerControl9 = this.videoRenderer as IVMRMixerControl9;

            for (int p = 1; p < programs.Count; p++)
            {
                int            column, row = Math.DivRem(p - 1, numberColumn, out column);
                NormalizedRect rect = new NormalizedRect();
                rect.left   = (float)column / (float)numberColumn + widthPadding;
                rect.top    = (float)row / (float)numberRow + heightPadding;
                rect.right  = rect.left + width;
                rect.bottom = rect.top + height;
                vmrMixerControl9.SetOutputRect(p, ref rect);
            }
        }