Dowitchers Tutorial 1 PDF Print E-mail
Written by Daniel P   
Friday, 03 August 2007

This is an introduction to programming Dowitchers applications. We just wrote the shortest program to display a video. I suppose there is a need for "Tutorial 0" which would explain the basic concepts of programming audio and video on Microsoft with DirectShow: things like media types and samples, pins and filters, and the graph of filters for an application. Maybe I'll just paste in the Introduction to my tutorials "Programming DirectShow application in C#".

The support files (including all the source code) can be found here.

Assuming you have a basic understanding of the previous concepts, we start our program with a declaration of the Dowitchers namespaces:

  1. // we'll be using these
  2. using Dowitchers;
  3. using Dowitchers.Graph;
  4. using Dowitchers.Filters;
 

Then we create a form, a panel and a VideoControl objects that will be used to display the video:

  1. // create a form to display the video
  2. Form form = new Form();
  3. form.Visible = false;
  4.  
  5. // use a panel to fill the form
  6. Panel panel = new Panel();
  7. panel.Parent = form;
  8. panel.Dock = DockStyle.Fill;
  9.  
  10. // the VideoControl handles the repaint event
  11. VideoControl videoControl = new VideoControl();
  12. videoControl.Parent = panel;
  13. videoControl.Dock = DockStyle.Fill;
 


Now, we are reading for some real Dowitchers code:

  1. // create a graph object
  2. Graph graph = new Graph();
  3. try
  4. {
  5. // the MDX object that will be used to display the video
  6. // if your vid card supports ps_2 then can use Direct3DPresenter instead
  7. IPresenter presenter = new DirectDraw7Presenter(graph, form, videoControl);
  8.  
  9. // the source filter created from the uri
  10. IFilter filter;
  11.  
  12. if (graph.AddSource(new Uri("file:///" + args[0]), out filter))
  13. {
  14. // if we recognize the format, render it
  15. graph.Render(filter);
  16. // start the graph running
  17. graph.State = MediaState.Running;
  18. }
  19. }
 

We create a Graph object, then a presenter object that wraps the Managed DirectX device used for the application. We are now ready to call the Graph AddSource method to try to identify the media format used and setup the appropriate internal data structures. If this succeeds, we call the Render method with filter object returned by the AddSource method. Then we get the graph running.

We are now ready to display the result and we make sure that when the user closes the window, we stopped all worker threads:

  1. Application.Run(form);
  2. // make sure all worker threads are done executing
  3. graph.State = MediaState.Stopped;
 

That's it. If you're familiar with DirectShow, you should feel right at home with Dowitchers.

With the Vfw wrapper, you should be able to play most avi files if you have ffshow installed on your machine.




Bookmark it...
Digg!Reddit!Del.icio.us!Google!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!
 
Who said filters can't be written in managed code? PDF Print E-mail
Written by Daniel P   
Saturday, 21 July 2007

If you didn't believe that filters could be written in managed code, I'd suggest you have a look at the collection of filters that Gabest has already written for Dowitchers.

Admittedly most are splitters/demux/parsers, but AFAIK, the real "numbers cruncher" of video processing is the motion estimation of delta frames when encoding. And if you're not interested in encoding, the hotspots of decoding are the variable-length decoding of coefficients and the iDct. If you can't get hardware support for these operations, the difference between C/C++ and C# is negligible.

As I pointed out before, if you are worried about performance, you can check the assembly code executed in VS Disassembly window (if you're happy with what you see, you're done. If not, before going further and, in case you didn't already know, start the "release version" and use the debugger to "Attach to process..." to break into your code and see the actual optimized jitted code that your application is actually running).

If that's not good enough then SIMD (ie. SSE?, shaders & al) is the way to go. But there is a good chance that you can find good critical routines in existing open-source code.

 




Bookmark it...
Digg!Reddit!Del.icio.us!Google!Facebook!Slashdot!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!
 
<< Start < Prev 1 2 3 4 5 6 7 8 9 10 Next > End >>

Results 13 - 16 of 81
Joomla Template by Joomlashack
Joomla Templates by JoomlaShack Joomla Templates by Compass Design