Current version

v1.10.4 (stable)

Navigation

Main page
Archived news
Downloads
Documentation
   Capture
   Compiling
   Processing
   Crashes
Features
Filters
Plugin SDK
Knowledge base
Donate
Contact info
Forum
 
Other projects
   Altirra

Search

Archives

01 Dec - 31 Dec 2013
01 Oct - 31 Oct 2013
01 Aug - 31 Aug 2013
01 May - 31 May 2013
01 Mar - 31 Mar 2013
01 Feb - 29 Feb 2013
01 Dec - 31 Dec 2012
01 Nov - 30 Nov 2012
01 Oct - 31 Oct 2012
01 Sep - 30 Sep 2012
01 Aug - 31 Aug 2012
01 June - 30 June 2012
01 May - 31 May 2012
01 Apr - 30 Apr 2012
01 Dec - 31 Dec 2011
01 Nov - 30 Nov 2011
01 Oct - 31 Oct 2011
01 Sep - 30 Sep 2011
01 Aug - 31 Aug 2011
01 Jul - 31 Jul 2011
01 June - 30 June 2011
01 May - 31 May 2011
01 Apr - 30 Apr 2011
01 Mar - 31 Mar 2011
01 Feb - 29 Feb 2011
01 Jan - 31 Jan 2011
01 Dec - 31 Dec 2010
01 Nov - 30 Nov 2010
01 Oct - 31 Oct 2010
01 Sep - 30 Sep 2010
01 Aug - 31 Aug 2010
01 Jul - 31 Jul 2010
01 June - 30 June 2010
01 May - 31 May 2010
01 Apr - 30 Apr 2010
01 Mar - 31 Mar 2010
01 Feb - 29 Feb 2010
01 Jan - 31 Jan 2010
01 Dec - 31 Dec 2009
01 Nov - 30 Nov 2009
01 Oct - 31 Oct 2009
01 Sep - 30 Sep 2009
01 Aug - 31 Aug 2009
01 Jul - 31 Jul 2009
01 June - 30 June 2009
01 May - 31 May 2009
01 Apr - 30 Apr 2009
01 Mar - 31 Mar 2009
01 Feb - 29 Feb 2009
01 Jan - 31 Jan 2009
01 Dec - 31 Dec 2008
01 Nov - 30 Nov 2008
01 Oct - 31 Oct 2008
01 Sep - 30 Sep 2008
01 Aug - 31 Aug 2008
01 Jul - 31 Jul 2008
01 June - 30 June 2008
01 May - 31 May 2008
01 Apr - 30 Apr 2008
01 Mar - 31 Mar 2008
01 Feb - 29 Feb 2008
01 Jan - 31 Jan 2008
01 Dec - 31 Dec 2007
01 Nov - 30 Nov 2007
01 Oct - 31 Oct 2007
01 Sep - 30 Sep 2007
01 Aug - 31 Aug 2007
01 Jul - 31 Jul 2007
01 June - 30 June 2007
01 May - 31 May 2007
01 Apr - 30 Apr 2007
01 Mar - 31 Mar 2007
01 Feb - 29 Feb 2007
01 Jan - 31 Jan 2007
01 Dec - 31 Dec 2006
01 Nov - 30 Nov 2006
01 Oct - 31 Oct 2006
01 Sep - 30 Sep 2006
01 Aug - 31 Aug 2006
01 Jul - 31 Jul 2006
01 June - 30 June 2006
01 May - 31 May 2006
01 Apr - 30 Apr 2006
01 Mar - 31 Mar 2006
01 Feb - 29 Feb 2006
01 Jan - 31 Jan 2006
01 Dec - 31 Dec 2005
01 Nov - 30 Nov 2005
01 Oct - 31 Oct 2005
01 Sep - 30 Sep 2005
01 Aug - 31 Aug 2005
01 Jul - 31 Jul 2005
01 June - 30 June 2005
01 May - 31 May 2005
01 Apr - 30 Apr 2005
01 Mar - 31 Mar 2005
01 Feb - 29 Feb 2005
01 Jan - 31 Jan 2005
01 Dec - 31 Dec 2004
01 Nov - 30 Nov 2004
01 Oct - 31 Oct 2004
01 Sep - 30 Sep 2004
01 Aug - 31 Aug 2004

Stuff

Powered by Pivot  
XML: RSS feed 
XML: Atom feed 

§ DirectShow gone awry

A few days ago I discovered that some prototype DirectShow-based code I had was suddenly taking a lot longer to open files. By a lot longer, I mean up to a minute -- at full CPU. As you might imagine, this was pretty irritating, especially since not only was it running at full CPU, but it was doing something that made the entire system performance especially suck during that time. Great.

A bit of digging with the mighty F12 profiler -- actually, I guess it was Ctrl+Break, since I was using CDB -- revealed it to be the DirectShow filter graph "intelligent connect" code. Specifically, it was taking an abnormally long time to connect the audio sample grabber. "Intelligent connect" in DirectShow refers to the way in which the filter graph manager will automatically find a sequence of intermediate filters to connect two filters together whenever a direct connection isn't possible. For instance, trying to connect a renderer that wants uncompressed video to a compressed video source will result in a video decoder being stuck in between. As you might imagine, this is both handy and hazardous, the latter coming into play when the filter graph comes up with some horror like MJPEG Compressor + MJPEG Decompressor to do a color conversion. I had suspected that at first, but inspection of the resulting filter graph via GraphEdit's remote connect function didn't show anything unusual.

Some more investigation with the debugger revealed that a lot of time was being spent in creating and destroying DirectDraw surfaces, which some filter was using as part of its media type check -- not a great idea, considering how expensive it is and how often media type queries happen. For a moment, I had thought maybe some application I had installed recently had added a ton of slow or broken filters, which I'd have to hunt down and then uninstall. The situation was pretty bad too, because the filter graph manager was recursing a lot and trying some pretty deep chains of filters. Then it dawned on me... why was the filter graph manager trying so many video filters to connect an audio filter? Shouldn't it know that it already had an audio stream, and that only audio filters should be checked? Unless....

I checked the connection code again, and it turned out that I wasn't trying to connect an audio pin, but rather a source type pin. That meant that the intelligent connect code had to figure out both the demultiplex and decoder filters for the intermediate connections. Then, after checking the sample grabber code, I had a light bulb moment. It turns out that I hadn't reimplemented the EnumMediaTypes() code on the sample grabber's input pin, so it was returning no media type structures. That meant that the filter graph manager was trying to establish a connection with the following media type information:

The sample grabber did check the media type in the query function, so it only accepted audio connections. However, the filter graph manager had no way to know this since EnumMediaTypes() returned nothing, so the only way it found a connection was to do a brute force search through all possible combinations of filters that would make Dijkstra proud. And when you have M filters that can be combined up to a chain N long, the result unsurprisingly is a whole lot of CPU time spent trying connections. So I reimplemented EnumMediaTypes() to return a single entry with the media type set properly, and suddenly load time dropped to sub-second range.

Moral of the story? Make sure your filter isn't being too ambiguous with its reported connection requirements.

Comments

No comments yet:

Comment form


Please keep comments on-topic for this entry. If you have unrelated comments about VirtualDub, the forum is a better place to post them.
Name:  
Remember personal info?

Email (Optional):
Your email address is only revealed to the blog owner and is not shown to the public.
URL (Optional):
Comment: /

An authentication dialog may appear when you click Post Comment. Simply type in "post" as the user and "now" as the password. I have had to do this to stop automated comment spam.



Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.