Ejemplo n.º 1
0
    /// <summary>
    /// Shut down graph
    /// </summary>
    private void CloseInterfaces()
    {
      int hr;

      lock (this)
      {
        // Stop the graph
        if (this.mediaControl != null)
        {
          //// Stop the graph
          //hr = this.mediaControl.Stop();
        }

        // Free the preview window (ignore errors)
        if (this.videoWindow != null)
        {
          this.videoWindow.put_Visible(OABool.False);
          this.videoWindow.put_Owner(IntPtr.Zero);
          this.videoWindow = null;
        }

        if (this.imageHandler != null)
        {
          this.imageHandler.Dispose();
          this.imageHandler = null;
        }

        // Release the graph
        if (this.filterGraph != null)
        {
          hr = ((IMediaEventSink)this.filterGraph).Notify(EventCode.UserAbort, IntPtr.Zero, IntPtr.Zero);

          Marshal.ReleaseComObject(this.filterGraph);
          this.filterGraph = null;
          this.mediaControl = null;
        }
      }

#if DEBUG
      if (this.dsRot != null)
      {
        this.dsRot.Dispose();
        this.dsRot = null;
      }
#endif

      GC.Collect();
    }
Ejemplo n.º 2
0
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the DSRecordWithDMO class.
    /// </summary>
    /// <param name="newImageHandler">An <see cref="ImageFromVectorGraphics"/>
    /// with the callback.</param>
    /// <param name="newVideoExportProperties">A <see cref="VideoExportProperties"/> with 
    /// the video export properties.</param>
    /// <param name="newPreviewWindow">A <see cref="Control"/> with 
    /// the preview panel.</param>
    public DSRecordWithDMO(
      ImageFromVectorGraphics newImageHandler,
      VideoExportProperties newVideoExportProperties,
      Control newPreviewWindow)
    {
      try
      {
        // set the image provider
        this.imageHandler = newImageHandler;

        // set the video properties
        this.videoExportProperties = newVideoExportProperties;

        if (this.videoExportProperties.OutputVideoProperties.VideoCompressor != string.Empty)
        {
          // Create the filter for the selected video compressor
          this.videoCompressor = DirectShowUtils.CreateFilter(
            FilterCategory.VideoCompressorCategory,
            this.videoExportProperties.OutputVideoProperties.VideoCompressor);
        }

        if (this.videoExportProperties.OutputVideoProperties.AudioCompressor != string.Empty)
        {
          // Create the filter for the selected video compressor
          this.audioCompressor = DirectShowUtils.CreateFilter(
            FilterCategory.AudioCompressorCategory,
            this.videoExportProperties.OutputVideoProperties.AudioCompressor);
        }

        // Set up preview window
        this.previewWindow = newPreviewWindow;

        // Set up the graph
        if (!this.SetupGraph())
        {
          throw new OperationCanceledException("The DirectShow graph could not be created,"
            + " try to use another video or audio compressor.");
        }
      }
      catch
      {
        this.Dispose();
        throw;
      }
    }