private void GetInterface() { object o; int hr; m_pGraph = (IGraphBuilder)new FilterGraph(); IBaseFilter pSource; hr = m_pGraph.AddSourceFilter(@"C:\SourceForge\mflib\Test\Media\AspectRatio4x3.wmv", null, out pSource); DsError.ThrowExceptionForHR(hr); IBaseFilter pEVR = (IBaseFilter)new EnhancedVideoRenderer(); hr = m_pGraph.AddFilter(pEVR, "EVR"); DsError.ThrowExceptionForHR(hr); ICaptureGraphBuilder2 cgb; cgb = (ICaptureGraphBuilder2)new CaptureGraphBuilder2(); hr = cgb.SetFiltergraph(m_pGraph); DsError.ThrowExceptionForHR(hr); hr = cgb.RenderStream(null, MediaType.Video, pSource, null, pEVR); DsError.ThrowExceptionForHR(hr); IMFGetService gs = pEVR as IMFGetService; hr = gs.GetService(MFServices.MR_VIDEO_MIXER_SERVICE, typeof(IMFVideoMixerBitmap).GUID, out o); MFError.ThrowExceptionForHR(hr); m_vmb = o as IMFVideoMixerBitmap; }
private void CloseInterfaces() { int hr = 0; try { lock (this) { // Relinquish ownership (IMPORTANT!) after hiding video window //if (!this.isAudioOnly) //{ // hr = this.videoWindow.put_Visible(OABool.False); // DsError.ThrowExceptionForHR(hr); // hr = this.videoWindow.put_Owner(IntPtr.Zero); // DsError.ThrowExceptionForHR(hr); //} //#if DEBUG try { if (rot != null) { rot.Dispose(); rot = null; } } catch {} //#endif if (evrDisplay != null) { //evrDisplay.SetVideoWindow(IntPtr.Zero); Marshal.ReleaseComObject(evrDisplay); } evrDisplay = null; //if (rateSupport != null) //{ // //evrDisplay.SetVideoWindow(IntPtr.Zero); // Marshal.ReleaseComObject(rateSupport); //} //rateSupport = null; //if (stateSink != null) //{ // //evrDisplay.SetVideoWindow(IntPtr.Zero); // Marshal.ReleaseComObject(stateSink); //} //stateSink = null; if (mixBmp != null) Marshal.ReleaseComObject(mixBmp); mixBmp = null; if (this.evrRenderer != null) Marshal.ReleaseComObject(evrRenderer); evrRenderer = null; if (cpsett != null) Marshal.ReleaseComObject(cpsett); cpsett = null; if (dvdSubtitle != null) Marshal.ReleaseComObject(dvdSubtitle); dvdSubtitle = null; if (dvdCtrl != null) { hr = dvdCtrl.SetOption(DvdOptionFlag.ResetOnStop, true); } if (cmdOption != null) { Marshal.ReleaseComObject(cmdOption); cmdOption = null; } pendingCmd = false; dvdCtrl = null; if (dvdInfo != null) { Marshal.ReleaseComObject(dvdInfo); dvdInfo = null; } if (this.mediaEventEx != null) { if(dvdGraph != null) hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, WM.DVD_EVENT, IntPtr.Zero); else hr = this.mediaEventEx.SetNotifyWindow(IntPtr.Zero, WM.NULL, IntPtr.Zero); //DsError.ThrowExceptionForHR(hr); } if (audioRenderer != null) Marshal.ReleaseComObject(audioRenderer); audioRenderer = null; // Release and zero DirectShow interfaces if (this.mediaEventEx != null) this.mediaEventEx = null; 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.videoWindow != null) // this.videoWindow = null; if (this.frameStep != null) this.frameStep = null; if (this.graphBuilder != null) Marshal.ReleaseComObject(this.graphBuilder); this.graphBuilder = null; if (this.dvdGraph != null) Marshal.ReleaseComObject(dvdGraph); dvdGraph = null; GC.Collect(); } } catch { } }
private void SetupEvrDisplay() { int hr=0; //Guid presenterCLSID = new Guid(0xeb449d36, 0x4, 0x4ea8, 0x90, 0x74, 0x40, 0xc5, 0xf4, 0x94, 0xb5, 0xe4); //Guid presenterCLSID = new Guid(0x9707fc9c, 0x807b, 0x41e3, 0x98, 0xa8, 0x75, 0x17, 0x6f, 0x95, 0xa0, 0x62); //Guid presenterCLSID = new Guid("29FAB022-F7CC-4819-B2B8-D9B6BCFB6698"); IMFGetService mfgs = evrRenderer as IMFGetService; if (mfgs != null) { IMFVideoPresenter pPresenter = null; try { if (ps.CustomPresenterEnabled) { Guid presenterCLSID = new Guid(ps.CustomPresenter); IMFVideoRenderer pRenderer = evrRenderer as IMFVideoRenderer; Type type = Type.GetTypeFromCLSID(presenterCLSID); pPresenter = (IMFVideoPresenter)Activator.CreateInstance(type); if (pPresenter != null) { try { pRenderer.InitializeRenderer(null, pPresenter); cpsett = pPresenter as IEVRCPConfig; if (cpsett != null) { int range; float alpha; bool mftime; hr = cpsett.GetInt(EVRCPSetting.NOMINAL_RANGE, out range); hr = cpsett.SetInt(EVRCPSetting.NOMINAL_RANGE, range); hr = cpsett.GetFloat(EVRCPSetting.SUBTITLE_ALPHA, out alpha); hr = cpsett.SetFloat(EVRCPSetting.SUBTITLE_ALPHA, alpha); hr = cpsett.GetBool(EVRCPSetting.USE_MF_TIME_CALC, out mftime); hr = cpsett.SetBool(EVRCPSetting.USE_MF_TIME_CALC, mftime); hr = cpsett.GetInt(EVRCPSetting.FRAME_DROP_THRESHOLD, out range); hr = cpsett.SetInt(EVRCPSetting.FRAME_DROP_THRESHOLD, range+1); hr = cpsett.GetBool(EVRCPSetting.EVRCP_SETTING_REQUEST_OVERLAY, out mftime); hr = cpsett.SetBool(EVRCPSetting.EVRCP_SETTING_REQUEST_OVERLAY, false); } } finally { if (pPresenter != null && cpsett == null) Marshal.ReleaseComObject(pPresenter); } } } //object objStateSink = null; //mfgs.GetService(MFServices.MR_VIDEO_RENDER_SERVICE, // typeof(IMFClockStateSink).GUID, // out objStateSink); //stateSink = objStateSink as IMFClockStateSink; //object objRateSupp= null; //mfgs.GetService(MFServices.MR_VIDEO_RENDER_SERVICE, // typeof(IMFRateSupport).GUID, // out objRateSupp); //rateSupport = objRateSupp as IMFRateSupport; object objMixBmp = null; mfgs.GetService(MFServices.MR_VIDEO_MIXER_SERVICE, typeof(IMFVideoMixerBitmap).GUID, out objMixBmp); mixBmp = objMixBmp as IMFVideoMixerBitmap; object objDisplay = null; mfgs.GetService(MFServices.MR_VIDEO_RENDER_SERVICE, typeof(IMFVideoDisplayControl).GUID, out objDisplay ); FileLogger.Log("PlayMovieInWindow: MR_VIDEO_RENDER_SERVICE"); evrDisplay = objDisplay as IMFVideoDisplayControl; this.evrDisplay.SetVideoWindow(this.Handle); MediaFoundation.Misc.MFSize videoSize = new MediaFoundation.Misc.MFSize(); MediaFoundation.Misc.MFSize ar = new MediaFoundation.Misc.MFSize(); //evrDisplay.GetNativeVideoSize(videoSize, ar); if ((videoSize.cx == 0 && videoSize.cy == 0) || videoSize.cx <= 0) { IEVRFilterConfig evrConfig = evrRenderer as IEVRFilterConfig; int pdwMaxStreams; evrConfig.GetNumberOfStreams(out pdwMaxStreams); FileLogger.Log("NumberOfStreams: {0}", pdwMaxStreams); if (pdwMaxStreams < 1) { evrConfig.SetNumberOfStreams(1); FileLogger.Log("Set NumberOfStreams: {0}", 1); } } //object objMemConfig = null; //mfgs.GetService(MFServices.MR_VIDEO_ACCELERATION_SERVICE, typeof(IDirectXVideoMemoryConfiguration).GUID, out objMemConfig); } catch (InvalidCastException) { //do nothing } } }