protected virtual void ConfigureVMR9InWindowlessMode(int numberOfStream) { int hr; if (useEVR) { object o; IMFGetService pGetService = null; pGetService = (IMFGetService)this.videoRenderer; hr = pGetService.GetService(MFServices.MR_VIDEO_RENDER_SERVICE, typeof(CodeTV.IMFVideoDisplayControl).GUID, out o); try { evrVideoDisplayControl = (CodeTV.IMFVideoDisplayControl)o; } catch { Marshal.ReleaseComObject(o); throw; } try { // Set the number of streams. hr = evrVideoDisplayControl.SetVideoWindow(this.hostingControl.Handle); if (numberOfStream > 1) { IEVRFilterConfig evrFilterConfig; evrFilterConfig = (IEVRFilterConfig)this.videoRenderer; hr = evrFilterConfig.SetNumberOfStreams(numberOfStream); } // Keep the aspect-ratio OK hr = evrVideoDisplayControl.SetAspectRatioMode(MFVideoAspectRatioMode.None); // VMR9AspectRatioMode.None); ThrowExceptionForHR("Setting the EVR AspectRatioMode: ", hr); //http://msdn.microsoft.com/en-us/library/windows/desktop/ms701834(v=vs.85).aspx //MFVideoRenderPrefs videoRenderPrefs; //hr = evrVideoDisplayControl.GetRenderingPrefs(out videoRenderPrefs); ////videoRenderPrefs = MFVideoRenderPrefs.DoNotRenderBorder | MFVideoRenderPrefs.DoNotRepaintOnStop; ////videoRenderPrefs = MFVideoRenderPrefs.AllowBatching; //videoRenderPrefs = MFVideoRenderPrefs.ForceBatching; ////videoRenderPrefs = MFVideoRenderPrefs.ForceBatching | MFVideoRenderPrefs.AllowBatching; //hr = evrVideoDisplayControl.SetRenderingPrefs(videoRenderPrefs); //MFVideoAspectRatioMode pdwAspectRatioMode; //hr = evrVideoDisplayControl.GetAspectRatioMode(out pdwAspectRatioMode); //pdwAspectRatioMode = MFVideoAspectRatioMode.None; //hr = evrVideoDisplayControl.SetAspectRatioMode(pdwAspectRatioMode); //int color = 0; //hr = evrVideoDisplayControl.GetBorderColor(out color); // VMR9AspectRatioMode.None); //hr = evrVideoDisplayControl.SetBorderColor(0xff0FF0); // VMR9AspectRatioMode.None); //ThrowExceptionForHR("Setting the EVR AspectRatioMode: ", hr); //EVR Clipping Window bug!!!!!!!!!!!!!!!!!!!http://social.msdn.microsoft.com/Forums/en/windowsdirectshowdevelopment/thread/579b6a6b-bdba-4d3b-a0b6-4de72114232b } finally { //Marshal.ReleaseComObject(pDisplay); } //hr = pGetService.GetService(MFServices.MR_VIDEO_RENDER_SERVICE, typeof(IMFVideoMixerControl).GUID, out o); //try //{ // //IMFVideoMixerControl videoMixerControl = (IMFVideoMixerControl)o; // //videoMixerControl.SetStreamOutputRect( //} //catch //{ // Marshal.ReleaseComObject(o); // throw; //} //hr = pGetService.GetService(MFServices.MR_VIDEO_ACCELERATION_SERVICE, typeof(IDirectXVideoMemoryConfiguration).GUID, out o); //try //{ // //IDirectXVideoMemoryConfiguration videoMixerControl = (IDirectXVideoMemoryConfiguration)o; // //videoMixerControl.SetStreamOutputRect( //} //catch //{ // Marshal.ReleaseComObject(o); // throw; //} } else { IVMRFilterConfig9 filterConfig = this.videoRenderer as IVMRFilterConfig9; if (filterConfig != null) { // Configure VMR-9 in Windowsless mode hr = filterConfig.SetRenderingMode(VMR9Mode.Windowless); //hr = filterConfig.SetRenderingMode(VMR9Mode.Windowed); ThrowExceptionForHR("Setting the VMR9 RenderingMode: ", hr); // With 1 input stream hr = filterConfig.SetNumberOfStreams(numberOfStream); ThrowExceptionForHR("Setting the VMR9 NumberOfStreams: ", hr); } IVMRWindowlessControl9 windowlessControl = this.videoRenderer as IVMRWindowlessControl9; if (windowlessControl != null) { // The main form is hosting the VMR-9 hr = windowlessControl.SetVideoClippingWindow(this.hostingControl.Handle); ThrowExceptionForHR("Setting the VMR9 VideoClippingWindow: ", hr); // Keep the aspect-ratio OK //hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.LetterBox); hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.None); ThrowExceptionForHR("Setting the VMR9 AspectRatioMode: ", hr); } //IVMRMixerControl9 vmrMixerControl9 = this.videoRenderer as IVMRMixerControl9; //if (vmrMixerControl9 != null) //{ // VMR9MixerPrefs dwMixerPrefs; // hr = vmrMixerControl9.GetMixingPrefs(out dwMixerPrefs); // //dwMixerPrefs = DirectShowLib.VMR9MixerPrefs.NoDecimation | DirectShowLib.VMR9MixerPrefs.ARAdjustXorY | DirectShowLib.VMR9MixerPrefs.GaussianQuadFiltering | DirectShowLib.VMR9MixerPrefs.RenderTargetRGB; // //dwMixerPrefs = DirectShowLib.VMR9MixerPrefs.NoDecimation | DirectShowLib.VMR9MixerPrefs.ARAdjustXorY | DirectShowLib.VMR9MixerPrefs.GaussianQuadFiltering | DirectShowLib.VMR9MixerPrefs.RenderTargetRGB; // dwMixerPrefs &= ~DirectShowLib.VMR9MixerPrefs.DecimateMask; // dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.NoDecimation; //Default // //dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.DecimateOutput; // dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.ARAdjustXorY; //Default // //dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.NonSquareMixing; // dwMixerPrefs &= ~DirectShowLib.VMR9MixerPrefs.FilteringMask; // dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.BiLinearFiltering; //Default // //dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.PointFiltering; // //dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.AnisotropicFiltering; // //dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.PyramidalQuadFiltering; // //dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.GaussianQuadFiltering; // dwMixerPrefs &= ~DirectShowLib.VMR9MixerPrefs.RenderTargetMask; // //dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.RenderTargetRGB; //Default // dwMixerPrefs |= DirectShowLib.VMR9MixerPrefs.RenderTargetYUV; // hr = vmrMixerControl9.SetMixingPrefs(dwMixerPrefs); //} } // Init the VMR-9 with default size values OnResizeMoveHandler(null, null); // Add Windows Messages handlers AddHandlers(); }
protected virtual void Decompose() { if (this.graphBuilder != null) { int hr = 0; OnGraphEnded(); // Decompose the graph try { hr = (this.graphBuilder as IMediaControl).StopWhenReady(); } catch { } try { hr = (this.graphBuilder as IMediaControl).Stop(); } catch { } RemoveHandlers(); FilterGraphTools.RemoveAllFilters(this.graphBuilder); if (this.evrVideoDisplayControl != null) Marshal.ReleaseComObject(this.evrVideoDisplayControl); this.evrVideoDisplayControl = null; if (this.audioRenderer != null) Marshal.ReleaseComObject(this.audioRenderer); this.audioRenderer = null; if (this.videoRenderer != null) Marshal.ReleaseComObject(this.videoRenderer); this.videoRenderer = null; try { rot.Dispose(); } catch { } try { Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null; } catch { } } }