- Download demo project - 295.9 KB
-
Introduction
DSGraphEdit is a library to easily add functionality similar to Microsoft's venerable GraphEdit to your .NET applications. Most of the functionality has been recreated, with a few new bells and whistles to aid in the debugging of DirectShow software.
Background
GraphEdit is a utility that comes with the DirectShow SDK (later moved to the Windows SDK) that is a visual tool for creating and testing filter graphs for media playback. One of the more powerful functions of GraphEdit is its ability to hook into a filter graph running in an external application via the ROT (Running Object Table). However, doing so tends to be frustrating as it frequently crashes, and only provides limited functionality while connected to a remote graph. Another drawback of GraphEdit is that it is closed source, and can't be freely redistributed with your own software. DSGraphEdit uses DirectShowLib, Media Foundation .NET (for the Enhanced Video Renderer) and DaggerLib. DaggerLib is a library that aids in the visual construction and execution of DAGs (Direct Acyclic Graphs) for flow-based programming. It will be covered in more detail in future articles.
Using the Code
To use DSGraphEdit in your own application, add a reference to DaggerLib.DSGraphEdit.dll found in the lib directory, and add the namespace to the form:
//add namespace
using DaggerLib.DSGraphEdit;DaggerLib.DSGraphedit provides three controls:
- DSGraphEditPanel: The workspace for viewing and manipulating a Filter Graph.ed
- DSFiltersPanel: A panel that maintains a tree of DirectShow filters registered on your system
- DSGraphEditForm: An all-in-one dialog of DSGraphEditPanel and DSFiltersPanel to make testing easier
DSGraphEditPanel
Constructing a DSGraphEditPanel
DSGraphEditPanel can be created in four different ways:
- // construct a DSGraphEditPanel with an empty IFilterGraph
DSGraphEditPanel dsGraphEditPanel = new DSGraphEditPanel(); - // construct a DSGraphEditPanel from an existing IFilterGraph
IFilterGraph myFilterGraph = (IFilterGraph)new FilterGraph();
...
// do something with myFilterGraph
...
DSGraphEditPanel dsGraphEditPanel = new DSGraphEditPanel(myFilterGraph); - // construct a DSGraphEditPanel from a *.grf file
// Grf files are files that are created by GraphEdit or from a call
// to DSGraphEditPanel.SaveFilterGraph(string filename).
// Also, constructing a DSGraphEditPanel from a grf file should
// always be enclosed in a try/catch block because
// it may want some filters that are not registered on your system.
DSGraphEditPanel dsGraphEditPanel = null;
try
{
dsGraphEditPanel = new DSGraphEditPanel("c:\\somegraphfile.grf");
}
catch (Exception ex)
{
// we failed, show the error
MessageBox.Show(ex.Message, "Error loading graph file");
} - // attempt connection to a remote graph on the ROT via
// the DSGraphEditPanel.ConnectToRemoteGraph static method
DSGraphEditPanel dsGraphEditPanel = null;
try
{
dsGraphEditPanel = DSGraphEditPanel.ConnectToRemoteGraph();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error connecting to remote graph");
}
...
// do something with your connected graph
...
// disconnect from the Remote Graph
dsGraphEditPanel.Dispose();
dsGraphEditPanel = null;
The DSGraphEditPanel.ConnectToRemoteGraph() static method will prompt the user with a dialog box containing a list of IFilterGraphs that are currently registered on ROT:
To disconnect from a Remote Graph, simply dispose of the DSGraphEditPanel with the Dispose() method. Also, similar to constructing from a *.grf file, the ConnectToRemoteGraph static method should always be enclosed in a try/catch block.
Working With a DSGraphEditPanel
A DSGraphEditPanel is comprised of three areas:
The Toolbar Buttons
- Runs the Filter Graph. The corresponding method is DSGraphEditPanel.Play()
- Pauses the Filter Graph. The corresponding method is DSGraphEditPanel.Pause()
- Stops the Filter Graph. The corresponding method is DSGraphEditPanel.Run()
- Skips forward one frame. The corresponding method is DSGraphEditPanel.StepOneFrame()
- Synchronizes the contents of the displayed graph with the Filter Graph. Use this if you think the contents of the canvas do not accurately reflect the current state of the Filter Graph. The corresponding method is DSGraphEditPanel.SyncGraphs()
- Auto arranges the filters in the displayed graph. The corresponding method is DSGraphEditPanel.ArrangeNodes()
- Disconnects all pins in the Filter Graph
- Saves the Filter Graph to a *.grf file. These are compatible with Microsoft's GraphEdit. The corresponding method is DSGraphEditPanel.SaveFilterGraph(string filename)
- Renders a media file into the Filter Graph. The corresponding method is DSGraphEditPanel.RenderMediaFile(string filename)
- Renders a URL (Uniform Resource Locator) into the Filter Graph. The corresponding method is DSGraphEditPanel.RenderURL(string URL)
-
Provides several styles for displaying connections between filters. The corresponding property is DSGraphEditPanel.NoodleStyle (yes, they're called Noodles):
- Bezier - A simple bezier curve
- Lines - A five segment line
- CircuitBoardCoarse - All right angles (uses AStar path finding)
- CircuitBoardFine - Same as CircuitBoardCoarse, but allows non-right angles
- Ramen - Same as CircuitBoardFine, but uses splines instead of line segments
-
Provides several operational and visual styles for the Filter Graph:
- Drop Shadow - Filters and Noodles cast a drop shadow on the canvas. The corresponding property is DSGraphEditPanel.DropShadow
- Pin Placement - Sets the pins on the Filters to be inside, outside, or indented. The corresponding property is DSGraphEditPanel.PinPlacement
- Show Pin Names - Draws the names for the pins onto the canvas. The corresponding property is DSGraphEditPanel.ShowPinNames
- Show/Hide Time Slider - Sets the Time Slider (in)visible. The corresponding property is DSGraphEditPanel.ShowTimeSlider
- Modal Properties - Sets if filters show their properties in a modal dialog, or directly on the canvas. The corresponding property is DSGraphEditPanel.ModalProperties
- Connect Intelligent - Sets if the Filter Graph adds intermediate filters when it connects two pins. The corresponding property is DSGraphEditPanel.ConnectIntelligent
- Use Clock - Enables or disables the reference clock of the Filter Graph. The corresponding property is DSGraphEditPanel.UseReferenceClock
The Time Slider
If the filterGraph has IMediaSeeking available, you can set the current playback of the graph with the Time Slider. Unlike Microsoft's GraphEdit, the Time Slider displays the current time (in hrs:min:secs:frame format) and allows you to set the start and end positions of the media.
The Canvas
The Canvas is where the filters are displayed as Nodes with interconnecting Noodles. Connecting pins is as easy as drag and drop, or point and click. In addition, depending on the type of filter that is represented, the Node can have several different attributes.
If the DSGraphEditPanel is set to ModalProprties = false, clicking the
button will show/hide the properties for the filter inside the node (this way, you can have multiple filter properties open at once on the canvas), otherwise the filter properties will be shown in a modal dialog box.
If the DSGraphEditPanel was created with the DSGraphEditPanel(), or the DSGraphEditPanel(string graphFileName) constructors, and the filter is a Video Renderer, the video will be displayed inside the node. To detach the video into its own window, click the Detach Video Window button
. Closing the detached video window will return to the video inside the node.
Unlike Microsoft's GraphEdit, DSGraphEditPanels allows you view and modify properties of DMOs (DirectX Media Objects):
DSFiltersPanel
The DSFiltersPanel provides a searchable TreeView of all the DirectShow filters registered on the system. After a DSFiltersPanel is constructed, set its AssociatedGraphPanel property to the current DSGraphEditPanel. Once a DSFilterPanel is created and associated with a DSGraphEditPanel, you can drag/drop filters onto a DSGraphEditPanel, double click them to add to the associated DSGraphEditPanel, or click the Insert Filter button
.
The DSFilterPanel also provides a property panel with all the FilterData information found in the registry:
DSGraphEditForm
DSGraphEditForm allows you to take a quick peek at a Filter Graph without having to hassle with setting up a DSGraphEditPanel/DSFiltersPanel pair, or using connect to a remote graph:
// create an arbitrary IFilterGraph
IFilterGraph myFilterGraph = (IFilterGraph)new FilterGraph();
...
// do something with myFilterGraph
...
// create and show the DSGraphEditForm as a modal dialog
DSGraphEditForm dsGraphEditForm = new DSGraphEditForm(myFilterGraph);
dsGraphEditForm.ShowDialog();
// dispose of it
dsGraphEditForm.Dispose();
dsGraphEditForm = null;No muss, no fuss.
Known Issues
In order for DSGraphEditPanel.ConnectToRemoteGraph() to work on Windows Vista, you actually need to have the version of GraphEdit from the Windows SDK for Windows Vista and register the proppage.dll that comes with it. If you have the older version of GraphEdit from the previous version of the Windows SDK, it still won't work. It has to be the one from the Windows SDK for Vista. The reason for this is that Microsoft (in their infinite wisdom) removed almost all the proxy/stub pairs from Quartz.dll in Vista, and moved them all into the proppage.dll. Without the proxy/stub pairs registered, Windows can't marshal proxies from one thread apartment to another. (Shame on you Microsoft)
History
- 10/30/07: Initial release of DSGraphEdit
About the Author
|
|
Other popular Audio and Video articles:
- Face Detection C++ Library with Skin and Motion Analysis
The article demonstrates face detection SSE optimized C++ library for color and gray scale data with skin detection, motion estimation for faster processing, small sized SVM and NN rough face prefiltering, PCA/LDA/ICA/any dimensionality reduction/projection and final NN classification - DSGraphEdit: A Reasonable Facsimile of Microsoft's GraphEdit in .NET
A library for adding DirectShow GraphEdit-like abilities to .NET applications. - Video Preview and Frames Capture to Memory with SampleGrabber in Buffered Mode.
The article demonstrating video preview and frames capture to memory from external video devices using ISampleGrabber interface in buffered mode. - DirectShow Filters (for beginners)
DirectShow Filters are described in an easy way - Webcamera, Multithreading and VFW
An article on webcamera frame-grabbing in a multi-thread environment
원본 위치 <http://www.codeproject.com/KB/audio-video/dsgraphedit.aspx>
'IT > UTIL' 카테고리의 다른 글
Vista Util 2007 06 (0) | 2007.12.12 |
---|---|
RTC Client API's and Windows Vista (0) | 2007.12.10 |
windows 2003 server 에서 photoshop cs3 설치방법 (0) | 2007.11.28 |
UltraVNC NAT2NAT connections (0) | 2007.11.09 |
IE7Pro 인터넷 익스플로러 7 Addin (0) | 2007.11.09 |