/////////////////////////////////////////////////////////////////////////////// // Public methods // /////////////////////////////////////////////////////////////////////////////// #region PUBLICMETHODS #endregion //PUBLICMETHODS /////////////////////////////////////////////////////////////////////////////// // Inherited methods // /////////////////////////////////////////////////////////////////////////////// #region OVERRIDES /// <summary> /// Initialize custom elements /// </summary> protected override void InitializeCustomElements() { base.InitializeCustomElements(); this.slideshow = new Slideshow(); this.toolTip = new ToolTip(); this.toolTip.ShowAlways = true; if (SecondaryScreen.SystemHasSecondaryScreen()) { if (Settings.Default.PresentationScreenMonitor == "Primary") { this.btnPrimary.Checked = true; this.btnSecondary.Checked = false; } else { this.btnPrimary.Checked = false; this.btnSecondary.Checked = true; } } else { this.btnPrimary.Visible = false; this.btnSecondary.Visible = false; } // Hide PropertyGrid this.spcPropertiesPreview.Panel1Collapsed = true; this.btnHelp.Click += new EventHandler(this.btnHelp_Click); this.pnlCanvas.Resize += new EventHandler(this.pnlCanvas_Resize); }
/////////////////////////////////////////////////////////////////////////////// // 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> /// Create a new filter graph and add filters (devices, compressors, /// misc), but leave the filters unconnected. Call renderGraph() /// to connect the filters. /// </summary> /// <returns>True if successful created the graph.</returns> protected bool createGraph() { int hr; try { // Garbage collect, ensure that previous filters are released GC.Collect(); // Get the graphbuilder object this.graphBuilder = new FilterGraph() as IFilterGraph2; // Get a ICaptureGraphBuilder2 to help build the graph this.captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2; // Link the CaptureGraphBuilder to the filter graph hr = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder); DsError.ThrowExceptionForHR(hr); #if DEBUG this.rotCookie = new DsROTEntry(this.graphBuilder); #endif // this.screenCaptureFilter = (IBaseFilter)new OgamaScreenCaptureFilter(); // Get the ogama screen capture device and add it to the filter graph this.screenCaptureFilter = DirectShowUtils.CreateFilter(FilterCategory.VideoInputDevice, "OgamaCapture"); hr = this.graphBuilder.AddFilter(this.screenCaptureFilter, "OgamaCapture"); DsError.ThrowExceptionForHR(hr); // Query the interface for the screen capture Filter var ogamaFilter = this.screenCaptureFilter as IOgamaScreenCapture; hr = ogamaFilter.set_Monitor(this.monitorIndex); DsError.ThrowExceptionForHR(hr); hr = ogamaFilter.set_Framerate(this.frameRate); DsError.ThrowExceptionForHR(hr); //// Get the IAMStreamConfig from the filter so we can configure it //var videoStreamConfig = this.screenCaptureFilter as IAMStreamConfig; var resolution = PresentationScreen.GetPresentationResolution(); //hr = videoStreamConfig.SetFormat(this.CreateVideoMediaType(24, resolution.Width, resolution.Height)); //DsError.ThrowExceptionForHR(hr); this.smartTeeFilter = new SmartTee() as IBaseFilter; hr = this.graphBuilder.AddFilter(this.smartTeeFilter, "Smart Tee"); DsError.ThrowExceptionForHR(hr); if (SecondaryScreen.SystemHasSecondaryScreen()) { // Add a DMO Wrapper Filter this.dmoFilter = (IBaseFilter) new DMOWrapperFilter(); this.dmoWrapperFilter = (IDMOWrapperFilter)this.dmoFilter; // But it is more useful to show how to scan for the DMO var g = this.FindGuid("DmoOverlay", DMOCategory.VideoEffect); hr = this.dmoWrapperFilter.Init(g, DMOCategory.VideoEffect); DMOError.ThrowExceptionForHR(hr); this.SetDMOParams(this.dmoFilter); // Add it to the Graph hr = this.graphBuilder.AddFilter(this.dmoFilter, "DMO Filter"); DsError.ThrowExceptionForHR(hr); var dmo = (IMediaObject)this.dmoFilter; hr = dmo.SetInputType(0, this.CreateVideoMediaType(24, resolution.Width, resolution.Height), DMOSetType.None); DsError.ThrowExceptionForHR(hr); hr = dmo.SetOutputType(0, this.CreateVideoMediaType(24, resolution.Width, resolution.Height), DMOSetType.None); DsError.ThrowExceptionForHR(hr); } // Get the video compressor and add it to the filter graph // Create the filter for the selected video compressor this.videoCompressorFilter = DirectShowUtils.CreateFilter( FilterCategory.VideoCompressorCategory, this.videoCompressorName); hr = this.graphBuilder.AddFilter(this.videoCompressorFilter, "Video Compressor"); DsError.ThrowExceptionForHR(hr); // Render the file writer portion of graph (mux -> file) hr = this.captureGraphBuilder.SetOutputFileName( MediaSubType.Avi, this.tempFilename, out this.muxFilter, out this.fileWriterFilter); DsError.ThrowExceptionForHR(hr); //// Disable overwrite //// hr = this.fileWriterFilter.SetMode(AMFileSinkFlags.None); //// DsError.ThrowExceptionForHR(hr); hr = this.captureGraphBuilder.AllocCapFile(this.tempFilename, 10000000); DsError.ThrowExceptionForHR(hr); if (SecondaryScreen.SystemHasSecondaryScreen()) { hr = this.captureGraphBuilder.RenderStream(null, null, this.screenCaptureFilter, null, this.smartTeeFilter); DsError.ThrowExceptionForHR(hr); hr = this.captureGraphBuilder.RenderStream( null, null, this.smartTeeFilter, this.videoCompressorFilter, this.muxFilter); DsError.ThrowExceptionForHR(hr); hr = this.captureGraphBuilder.RenderStream(null, null, this.smartTeeFilter, null, this.dmoFilter); DsError.ThrowExceptionForHR(hr); hr = this.captureGraphBuilder.RenderStream(null, null, this.dmoFilter, null, null); DsError.ThrowExceptionForHR(hr); } else { hr = this.captureGraphBuilder.RenderStream( null, null, this.screenCaptureFilter, this.videoCompressorFilter, this.muxFilter); DsError.ThrowExceptionForHR(hr); } // IMediaFilter filter = this.graphBuilder as IMediaFilter; // IReferenceClock clock; // filter.GetSyncSource(out clock); hr = this.graphBuilder.SetDefaultSyncSource(); DsError.ThrowExceptionForHR(hr); // Retreive the media control interface (for starting/stopping graph) this.mediaControl = (IMediaControl)this.graphBuilder; } catch (Exception ex) { ExceptionMethods.HandleException(ex); return(false); } return(true); }