public static void SetFormat(ref AMMediaType mt, ref VideoInfoHeader vih) { if (vih != null) { int cb = Marshal.SizeOf(vih); IntPtr _ptr = Marshal.AllocCoTaskMem(cb); try { Marshal.StructureToPtr(vih, _ptr, true); SetFormat(ref mt, _ptr, cb); if (mt != null) { mt.formatType = FormatType.VideoInfo; } } finally { Marshal.FreeCoTaskMem(_ptr); } } }
public void SetFormat(VideoInfoHeader vih) { if (vih != null) { int cb = Marshal.SizeOf(vih); IntPtr _ptr = Marshal.AllocCoTaskMem(cb); try { Marshal.StructureToPtr(vih, _ptr, true); SetFormat(_ptr, cb); formatType = FormatType.VideoInfo; } finally { Marshal.FreeCoTaskMem(_ptr); } } }
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; }
/* public override int OnReceive(ref IMediaSampleImpl _sample) { Console.WriteLine("OnReceive "); Output.Deliver(ref _sample); return S_OK; } */ public override int GetMediaType(int iPosition, ref AMMediaType pMediaType) { Console.WriteLine("GetMediaType"); if (iPosition > 0) return VFW_S_NO_MORE_ITEMS; if (pMediaType == null) return E_INVALIDARG; if (!Input.IsConnected) return VFW_E_NOT_CONNECTED; AMMediaType.Copy(Input.CurrentMediaType, ref pMediaType); VideoInfoHeader vhi = new VideoInfoHeader(); Marshal.PtrToStructure(pMediaType.formatPtr, vhi); vhi.BmiHeader.Compression = 0; vhi.BmiHeader.BitCount = 24; vhi.BmiHeader.ImageSize = vhi.BmiHeader.Width * vhi.BmiHeader.Height * 3; pMediaType.formatPtr = Marshal.AllocCoTaskMem(pMediaType.formatSize); Marshal.StructureToPtr(vhi, pMediaType.formatPtr, false); pMediaType.majorType = MediaType.Video; pMediaType.subType = MediaSubType.RGB24; pMediaType.formatType = FormatType.VideoInfo; pMediaType.sampleSize = vhi.BmiHeader.ImageSize; return NOERROR; }
public int GetMediaType(int iPosition, ref AMMediaType pMediaType) { if (iPosition < 0) return E_INVALIDARG; VideoStreamConfigCaps _caps; GetDefaultCaps(0, out _caps); int nWidth = 0; int nHeight = 0; if (iPosition == 0) { if (Pins.Count > 0 && Pins[0].CurrentMediaType.majorType == MediaType.Video) { pMediaType.Set(Pins[0].CurrentMediaType); return NOERROR; } nWidth = _caps.InputSize.Width; nHeight = _caps.InputSize.Height; } else { iPosition--; nWidth = _caps.MinOutputSize.Width + _caps.OutputGranularityX * iPosition; nHeight = _caps.MinOutputSize.Height + _caps.OutputGranularityY * iPosition; if (nWidth > _caps.MaxOutputSize.Width || nHeight > _caps.MaxOutputSize.Height) { return VFW_S_NO_MORE_ITEMS; } } pMediaType.majorType = DirectShow.MediaType.Video; pMediaType.formatType = DirectShow.FormatType.VideoInfo; VideoInfoHeader vih = new VideoInfoHeader(); vih.AvgTimePerFrame = m_nAvgTimePerFrame; vih.BmiHeader.Compression = BI_RGB; vih.BmiHeader.BitCount = (short)m_nBitCount; vih.BmiHeader.Width = nWidth; vih.BmiHeader.Height = nHeight; vih.BmiHeader.Planes = 1; vih.BmiHeader.ImageSize = vih.BmiHeader.Width * Math.Abs(vih.BmiHeader.Height) * vih.BmiHeader.BitCount / 8; if (vih.BmiHeader.BitCount == 32) { pMediaType.subType = DirectShow.MediaSubType.RGB32; } if (vih.BmiHeader.BitCount == 24) { pMediaType.subType = DirectShow.MediaSubType.RGB24; } AMMediaType.SetFormat(ref pMediaType, ref vih); pMediaType.fixedSizeSamples = true; pMediaType.sampleSize = vih.BmiHeader.ImageSize; return NOERROR; }