public void TestAspectRatioMode() { int hr = 0; VMRAspectRatioMode ar; hr = arControl.SetAspectRatioMode(VMRAspectRatioMode.LetterBox); DsError.ThrowExceptionForHR(hr); hr = arControl.GetAspectRatioMode(out ar); DsError.ThrowExceptionForHR(hr); Debug.Assert(ar == VMRAspectRatioMode.LetterBox, "IVMRAspectRatioControl9.GetAspectRatioMode"); hr = arControl.SetAspectRatioMode(VMRAspectRatioMode.None); DsError.ThrowExceptionForHR(hr); hr = arControl.GetAspectRatioMode(out ar); DsError.ThrowExceptionForHR(hr); Debug.Assert(ar == VMRAspectRatioMode.None, "IVMRAspectRatioControl9.GetAspectRatioMode"); }
// TODO : Implment Strech // TODO : Implement Mute void ApplySettings(SourceSettings sourceSettings, AudioSettings audioSettings) { VMRAspectRatioMode aspectRatioMode = sourceSettings.SourceAspectFit == SourceAspectFit.LetterBox ? VMRAspectRatioMode.LetterBox : VMRAspectRatioMode.None; if (aspectRatioControl != null) { aspectRatioControl.SetAspectRatioMode(aspectRatioMode); } if (aspectRatioControl9 != null) { aspectRatioControl9.SetAspectRatioMode(aspectRatioMode); } }
protected override void Initialize(IGraphBuilder pGraphBuilder, IntPtr hMediaWindow) { if (_initialized) { base.Initialize(pGraphBuilder, hMediaWindow); } else { IVMRFilterConfig9 pVMRFilterConfig9 = (IVMRFilterConfig9)BaseFilter; // will be released when pBaseFilter is released pVMRFilterConfig9.SetNumberOfStreams(NUMBER_OF_STREAMS); IVMRAspectRatioControl9 pVMRAspectRatioControl9 = (IVMRAspectRatioControl9)BaseFilter; pVMRAspectRatioControl9.SetAspectRatioMode(VMR9AspectRatioMode.VMR9ARMode_None); _initialized = true; } }
//The following is called for building the PREVIEW graph #region PREVIEW ONLY public void Init() { Debug.WriteLine("VIDEO FOR PREVIEW"); pGraph = graph; int hr = 0; hr = pGraphBuilder.SetFiltergraph(pGraph); DsError.ThrowExceptionForHR(hr); pUSB = FindCaptureDevice(); hr = pGraph.AddFilter(pUSB, "WebCamControl Video"); DsError.ThrowExceptionForHR(hr); hr = pGraph.AddFilter(pSampleGrabber as IBaseFilter, "SampleGrabber"); checkHR(hr, "Can't add SampleGrabber to graph"); i_grabber = (ISampleGrabber)pSampleGrabber; i_grabber.SetBufferSamples(true); IVMRAspectRatioControl9 ratioControl9 = (IVMRAspectRatioControl9)renderFilter; hr = ratioControl9.SetAspectRatioMode(VMRAspectRatioMode.LetterBox); DsError.ThrowExceptionForHR(hr); hr = pGraph.AddFilter(renderFilter, "My Render Filter"); DsError.ThrowExceptionForHR(hr); //SetFormat(); hr = pGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, pUSB, (IBaseFilter)pSampleGrabber, renderFilter); DsError.ThrowExceptionForHR(hr); Debug.WriteLine(DsError.GetErrorText(hr) + " is error in rendering"); IEnumFilters enumFilters = null; IBaseFilter[] baseFilters = { null }; IntPtr fetched = IntPtr.Zero; hr = pGraph.EnumFilters(out enumFilters); int r = 0; while (r == 0) { try { r = enumFilters.Next(baseFilters.Length, baseFilters, fetched); DsError.ThrowExceptionForHR(hr); baseFilters[0].QueryFilterInfo(out FilterInfo filterInfo); Debug.WriteLine(filterInfo.achName + " -filtername"); } catch { r = 1; continue; } } SafeReleaseComObject(pUSB); SafeReleaseComObject(pAVIMux); SafeReleaseComObject(pGraph); SafeReleaseComObject(pGraphBuilder); SafeReleaseComObject(pSampleGrabber); //SafeReleaseComObject(sampleGrabber); SafeReleaseComObject(pSmartTee); SafeReleaseComObject(renderFilter); SafeReleaseComObject(nullRender); SafeReleaseComObject(mediaEventEx); SafeReleaseComObject(ratioControl9); SafeReleaseComObject(streamConfig); SafeReleaseComObject(mediaControl); //SafeReleaseComObject(format); //SafeReleaseComObject(i_grabber); SafeReleaseComObject(graph); SetupVideoWindow(); }