private IEnumPins GetTestEnum() { IBaseFilter filter = new SmartTee() as IBaseFilter; int hr; IEnumPins ppEnum; hr = filter.EnumPins(out ppEnum); DsError.ThrowExceptionForHR(hr); return(ppEnum); }
private static IPin GetSmartTeeInputPin() { IBaseFilter filter = new SmartTee() as IBaseFilter; int hr; IntPtr ip = Marshal.AllocCoTaskMem(4); IEnumPins ppEnum; IPin pRet = null; IPin[] pPins = new IPin[1]; hr = filter.EnumPins(out ppEnum); Marshal.ThrowExceptionForHR(hr); while ((ppEnum.Next(1, pPins, ip) >= 0) && (Marshal.ReadInt32(ip) == 1)) { pRet = pPins[0]; break; } Marshal.FreeCoTaskMem(ip); Marshal.ReleaseComObject(ppEnum); return(pRet); }
/////////////////////////////////////////////////////////////////////////////// // Inherited methods // /////////////////////////////////////////////////////////////////////////////// #region OVERRIDES #endregion //OVERRIDES /////////////////////////////////////////////////////////////////////////////// // Eventhandler // /////////////////////////////////////////////////////////////////////////////// #region EVENTS /////////////////////////////////////////////////////////////////////////////// // Eventhandler for UI, Menu, Buttons, Toolbars etc. // /////////////////////////////////////////////////////////////////////////////// #region WINDOWSEVENTHANDLER #endregion //WINDOWSEVENTHANDLER /////////////////////////////////////////////////////////////////////////////// // Eventhandler for Custom Defined Events // /////////////////////////////////////////////////////////////////////////////// #region CUSTOMEVENTHANDLER #endregion //CUSTOMEVENTHANDLER #endregion //EVENTS /////////////////////////////////////////////////////////////////////////////// // Methods and Eventhandling for Background tasks // /////////////////////////////////////////////////////////////////////////////// #region BACKGROUNDWORKER #endregion //BACKGROUNDWORKER /////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region PRIVATEMETHODS /// <summary> /// Build the filter graph /// </summary> /// <returns>True if successful, otherwise false.</returns> private bool SetupGraph() { int hr; // Get the graphbuilder object this.filterGraph = new FilterGraph() as IFilterGraph2; // Get a ICaptureGraphBuilder2 to help build the graph ICaptureGraphBuilder2 captureGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); try { // Link the ICaptureGraphBuilder2 to the IFilterGraph2 hr = captureGraph.SetFiltergraph(this.filterGraph); DsError.ThrowExceptionForHR(hr); #if DEBUG // Allows you to view the graph with GraphEdit File/Connect this.dsRot = new DsROTEntry(this.filterGraph); #endif // Our data source one IBaseFilter bitmapSource = (IBaseFilter) new GenericSampleSourceFilter(); // Create a DMO Wrapper Filter IBaseFilter dmoFilter = (IBaseFilter) new DMOWrapperFilter(); IDMOWrapperFilter dmoWrapperFilter = (IDMOWrapperFilter)dmoFilter; Guid g = this.FindGuid("DmoMixer", DMOCategory.VideoEffect); hr = dmoWrapperFilter.Init(g, DMOCategory.VideoEffect); DMOError.ThrowExceptionForHR(hr); try { // Get the pin from the filter so we can configure it IPin ipin = DsFindPin.ByDirection(bitmapSource, PinDirection.Output, 0); try { // Configure the pin using the provided BitmapInfo this.ConfigurePusher((IGenericSampleConfig)ipin); } catch (Exception ex) { ExceptionMethods.HandleException(ex); return(false); } finally { Marshal.ReleaseComObject(ipin); } // Add the bitmap source to the graph hr = this.filterGraph.AddFilter(bitmapSource, "BitmapSourceFilter"); DsError.ThrowExceptionForHR(hr); IBaseFilter webcamSource = null; if (this.videoExportProperties.UserVideoProperties.IsStreamRendered) { hr = this.filterGraph.AddSourceFilter( this.videoExportProperties.UserVideoTempFile, "WebcamVideoSource", out webcamSource); DsError.ThrowExceptionForHR(hr); } // Add it to the Graph hr = this.filterGraph.AddFilter(dmoFilter, "DMO Filter"); DsError.ThrowExceptionForHR(hr); this.SetDMOParams(dmoFilter, this.videoExportProperties); // Add the Video compressor filter to the graph if (this.videoCompressor != null) { hr = this.filterGraph.AddFilter(this.videoCompressor, "video compressor filter"); DsError.ThrowExceptionForHR(hr); } // Create the file writer part of the graph. // SetOutputFileName does this for us, and returns the mux and sink IBaseFilter mux; IFileSinkFilter sink; hr = captureGraph.SetOutputFileName(MediaSubType.Avi, this.videoExportProperties.OutputVideoProperties.Filename, out mux, out sink); DsError.ThrowExceptionForHR(hr); // Connect the bitmap source to the dmo mixer filter hr = captureGraph.RenderStream( null, null, bitmapSource, null, dmoFilter); DsError.ThrowExceptionForHR(hr); // If there is a webcam source connect it to the second input of the dmo mixer if (webcamSource != null) { hr = captureGraph.RenderStream( null, null, webcamSource, null, dmoFilter); DsError.ThrowExceptionForHR(hr); } // Create a smart tee filter to enable preview and capture pins IBaseFilter smartTee = new SmartTee() as IBaseFilter; // Add the filter to the graph hr = this.filterGraph.AddFilter(smartTee, "Smart Tee"); DsError.ThrowExceptionForHR(hr); // Connect the dmo mixer output to the smart tee hr = captureGraph.RenderStream( null, null, dmoFilter, null, smartTee); DsError.ThrowExceptionForHR(hr); // Render the smart tee capture pin to the capture part including // compressor to the file muxer. hr = captureGraph.RenderStream( null, null, smartTee, this.videoCompressor, mux); DsError.ThrowExceptionForHR(hr); // Render the smart tee preview pin to the default video renderer hr = captureGraph.RenderStream( null, null, smartTee, null, null); DsError.ThrowExceptionForHR(hr); // Configure the Video Window this.videoWindow = this.filterGraph as IVideoWindow; this.ConfigureVideoWindow(this.videoWindow, this.previewWindow); } catch (Exception ex) { ExceptionMethods.HandleException(ex); return(false); } finally { Marshal.ReleaseComObject(bitmapSource); } // Grab some other interfaces this.mediaControl = this.filterGraph as IMediaControl; } catch (Exception ex) { ExceptionMethods.HandleException(ex); return(false); } finally { Marshal.ReleaseComObject(captureGraph); } return(true); }
/////////////////////////////////////////////////////////////////////////////// // Inherited methods // /////////////////////////////////////////////////////////////////////////////// #region OVERRIDES #endregion //OVERRIDES /////////////////////////////////////////////////////////////////////////////// // Eventhandler // /////////////////////////////////////////////////////////////////////////////// #region EVENTS /////////////////////////////////////////////////////////////////////////////// // Eventhandler for UI, Menu, Buttons, Toolbars etc. // /////////////////////////////////////////////////////////////////////////////// #region WINDOWSEVENTHANDLER #endregion //WINDOWSEVENTHANDLER /////////////////////////////////////////////////////////////////////////////// // Eventhandler for Custom Defined Events // /////////////////////////////////////////////////////////////////////////////// #region CUSTOMEVENTHANDLER #endregion //CUSTOMEVENTHANDLER #endregion //EVENTS /////////////////////////////////////////////////////////////////////////////// // Methods and Eventhandling for Background tasks // /////////////////////////////////////////////////////////////////////////////// #region BACKGROUNDWORKER #endregion //BACKGROUNDWORKER /////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region PRIVATEMETHODS /// <summary> /// Build the filter graph /// </summary> /// <returns>True if successful, otherwise false.</returns> private bool SetupGraph() { int hr; // Get the graphbuilder object this.filterGraph = new FilterGraph() as IFilterGraph2; // Get a ICaptureGraphBuilder2 to help build the graph ICaptureGraphBuilder2 captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2(); try { // Link the ICaptureGraphBuilder2 to the IFilterGraph2 hr = captureGraph.SetFiltergraph(this.filterGraph); DsError.ThrowExceptionForHR(hr); #if DEBUG // Allows you to view the graph with GraphEdit File/Connect this.dsRot = new DsROTEntry(this.filterGraph); #endif // Our data source one IBaseFilter bitmapSource = (IBaseFilter)new GenericSampleSourceFilter(); // Create a DMO Wrapper Filter IBaseFilter dmoFilter = (IBaseFilter)new DMOWrapperFilter(); IDMOWrapperFilter dmoWrapperFilter = (IDMOWrapperFilter)dmoFilter; Guid g = this.FindGuid("DmoMixer", DMOCategory.VideoEffect); hr = dmoWrapperFilter.Init(g, DMOCategory.VideoEffect); DMOError.ThrowExceptionForHR(hr); try { // Get the pin from the filter so we can configure it IPin ipin = DsFindPin.ByDirection(bitmapSource, PinDirection.Output, 0); try { // Configure the pin using the provided BitmapInfo this.ConfigurePusher((IGenericSampleConfig)ipin); } catch (Exception ex) { ExceptionMethods.HandleException(ex); return false; } finally { Marshal.ReleaseComObject(ipin); } // Add the bitmap source to the graph hr = this.filterGraph.AddFilter(bitmapSource, "BitmapSourceFilter"); DsError.ThrowExceptionForHR(hr); IBaseFilter webcamSource = null; if (this.videoExportProperties.UserVideoProperties.IsStreamRendered) { hr = this.filterGraph.AddSourceFilter( this.videoExportProperties.UserVideoTempFile, "WebcamVideoSource", out webcamSource); DsError.ThrowExceptionForHR(hr); } // Add it to the Graph hr = this.filterGraph.AddFilter(dmoFilter, "DMO Filter"); DsError.ThrowExceptionForHR(hr); this.SetDMOParams(dmoFilter, this.videoExportProperties); // Add the Video compressor filter to the graph if (this.videoCompressor != null) { hr = this.filterGraph.AddFilter(this.videoCompressor, "video compressor filter"); DsError.ThrowExceptionForHR(hr); } // Create the file writer part of the graph. // SetOutputFileName does this for us, and returns the mux and sink IBaseFilter mux; IFileSinkFilter sink; hr = captureGraph.SetOutputFileName(MediaSubType.Avi, this.videoExportProperties.OutputVideoProperties.Filename, out mux, out sink); DsError.ThrowExceptionForHR(hr); // Connect the bitmap source to the dmo mixer filter hr = captureGraph.RenderStream( null, null, bitmapSource, null, dmoFilter); DsError.ThrowExceptionForHR(hr); // If there is a webcam source connect it to the second input of the dmo mixer if (webcamSource != null) { hr = captureGraph.RenderStream( null, null, webcamSource, null, dmoFilter); DsError.ThrowExceptionForHR(hr); } // Create a smart tee filter to enable preview and capture pins IBaseFilter smartTee = new SmartTee() as IBaseFilter; // Add the filter to the graph hr = this.filterGraph.AddFilter(smartTee, "Smart Tee"); DsError.ThrowExceptionForHR(hr); // Connect the dmo mixer output to the smart tee hr = captureGraph.RenderStream( null, null, dmoFilter, null, smartTee); DsError.ThrowExceptionForHR(hr); // Render the smart tee capture pin to the capture part including // compressor to the file muxer. hr = captureGraph.RenderStream( null, null, smartTee, this.videoCompressor, mux); DsError.ThrowExceptionForHR(hr); // Render the smart tee preview pin to the default video renderer hr = captureGraph.RenderStream( null, null, smartTee, null, null); DsError.ThrowExceptionForHR(hr); // Configure the Video Window this.videoWindow = this.filterGraph as IVideoWindow; this.ConfigureVideoWindow(this.videoWindow, this.previewWindow); } catch (Exception ex) { ExceptionMethods.HandleException(ex); return false; } finally { Marshal.ReleaseComObject(bitmapSource); } // Grab some other interfaces this.mediaControl = this.filterGraph as IMediaControl; } catch (Exception ex) { ExceptionMethods.HandleException(ex); return false; } finally { Marshal.ReleaseComObject(captureGraph); } return true; }