<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>6581 Useful Things</title>
	<atom:link href="http://sid6581.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sid6581.wordpress.com</link>
	<description>Random tech stuff</description>
	<lastBuildDate>Tue, 31 Oct 2006 21:37:52 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='sid6581.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/9eb25c4256e5593b28d885486f09bd87?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>6581 Useful Things</title>
		<link>http://sid6581.wordpress.com</link>
	</image>
			<item>
		<title>Instantiating Directshow filters by name</title>
		<link>http://sid6581.wordpress.com/2006/10/12/finding-directshow-filters-by-name/</link>
		<comments>http://sid6581.wordpress.com/2006/10/12/finding-directshow-filters-by-name/#comments</comments>
		<pubDate>Fri, 13 Oct 2006 03:43:10 +0000</pubDate>
		<dc:creator>sid6581</dc:creator>
				<category><![CDATA[DirectShow]]></category>

		<guid isPermaLink="false">http://sid6581.wordpress.com/2006/10/12/finding-directshow-filters-by-name/</guid>
		<description><![CDATA[One of the most basic things you need to do in a DirectShow application is add filters to a graph. If it is a basic stock filter you can usually find the CLSID in MSDN, and creating the filter is as easy instantiating it as a regular COM object from that CLSID.
If you fire up [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sid6581.wordpress.com&blog=463538&post=4&subd=sid6581&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>One of the most basic things you need to do in a DirectShow application is add filters to a graph. If it is a basic stock filter you can usually find the CLSID in MSDN, and creating the filter is as easy instantiating it as a regular COM object from that CLSID.</p>
<p>If you fire up GraphEdit on your system you&#8217;ll probably find a whole bunch of different filters that aren&#8217;t mentioned in MSDN. For instance, in the video compressor category there are several interesting filters:</p>
<p><span id="more-4"></span></p>
<p><img src="http://sid6581.files.wordpress.com/2006/10/ge_compressors_list.png" alt="GraphEdit Video Compressors List" /></p>
<p>It is important to remember that not all filters are supported by third party applications, and some filters may be unusable without having access to custom interfaces to configure and control them. Some filters (notably MPEG encoders and decoders) may have license restrictions preventing their use from your application without your paying license fees. Nevertheless, there are several cases where you will need to use a filter for which you don&#8217;t have a CLSID. Maybe you know the name of a filter that will work, or you&#8217;d like to give the user the choice of using third-party filters he has installed on his system.</p>
<p>One easy way to find such filters is to enumerate them and look for the specific filter you need. Below are a couple of helper functions that will assist you with that. They will show you how to enumerate filters by category and match them by name, and instantiate and add the matched filter to a filter graph.</p>
<p>As an example of how to use these functions, this code snippet instantiates the Microsoft MPEG4 V2 compressor and adds it to the filter graph:</p>
<pre>
   CComPtr compressor;
   AddFilter(filtergraph, L"Microsoft MPEG-4 Video Codec V2", &amp;compressor,
      CLSID_VideoCompressorCategory, L"VideoCompressor");
</pre>
<p>The category list can be found in MSDN under the topic <a href="http://windowssdk.msdn.microsoft.com/en-us/library/ms783347.aspx">Filter Categories</a>.</p>
<p>And here are the functions:</p>
<pre>
///
/// Create a filter by category and name, and add it to a filter
/// graph. Will enumerate all filters of the given category and
/// add the filter whose name matches, if any. If the filter could be
/// created but not added to the graph, the filter is destroyed.
///
/// @param Graph Filter graph.
/// @param Name of filter to create.
/// @param Filter Receives a pointer to the filter.
/// @param FilterCategory Filter category.
/// @param NameInGraph Name for the filter in the graph, or 0 for no
/// name.
///
/// @return true if successful.
bool AddFilter(IFilterGraph *Graph, const WCHAR *Name,
   IBaseFilter **Filter, REFCLSID FilterCategory,
   const WCHAR *NameInGraph)
{
   assert(Graph);
   assert(Name);
   assert(Filter);
   assert(!*Filter);   

   if (!CreateFilter(Name, Filter, FilterCategory))
      return false;   

   if (FAILED(Graph-&gt;AddFilter(*Filter, NameInGraph)))
   {
      (*Filter)-&gt;Release();
      *Filter = 0;
      return false;
   }   

   return true;
}   

///
/// Create a filter by category and name. Will enumerate all filters
/// of the given category and return the filter whose name matches,
/// if any.
///
/// @param Name of filter to create.
/// @param Filter Will receive the pointer to the interface
/// for the created filter.
/// @param FilterCategory Filter category.
///
/// @return true if successful.
bool CreateFilter(const WCHAR *Name, IBaseFilter **Filter,
   REFCLSID FilterCategory)
{
   assert(Name);
   assert(Filter);
   assert(!*Filter);    

   HRESULT hr;    

   // Create the system device enumerator.
   CComPtr&lt;ICreateDevEnum&gt; devenum;
   hr = devenum.CoCreateInstance(CLSID_SystemDeviceEnum);
   if (FAILED(hr))
      return false;    

   // Create an enumerator for this category.
   CComPtr&lt;IEnumMoniker&gt; classenum;
   hr = devenum-&gt;CreateClassEnumerator(FilterCategory, &amp;classenum, 0);
   if (hr != S_OK)
      return false;    

   // Find the filter that matches the name given.
   CComVariant name(Name);
   CComPtr&lt;IMoniker&gt; moniker;
   while (classenum-&gt;Next(1, &amp;moniker, 0) == S_OK)
   {
      CComPtr&lt;IPropertyBag&gt; properties;
      hr = moniker-&gt;BindToStorage(0, 0, IID_IPropertyBag, (void **)&amp;properties);
      if (FAILED(hr))
         return false;    

      CComVariant friendlyname;
      hr = properties-&gt;Read(L"FriendlyName", &amp;friendlyname, 0);
      if (FAILED(hr))
         return false;    

      if (name == friendlyname)
      {
         hr = moniker-&gt;BindToObject(0, 0, IID_IBaseFilter, (void **)Filter);
         return SUCCEEDED(hr);
      }    

      moniker.Release();
   }    

   // Couldn't find a matching filter.
   return false;
}</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sid6581.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sid6581.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sid6581.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sid6581.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sid6581.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sid6581.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sid6581.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sid6581.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sid6581.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sid6581.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sid6581.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sid6581.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sid6581.wordpress.com&blog=463538&post=4&subd=sid6581&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sid6581.wordpress.com/2006/10/12/finding-directshow-filters-by-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d9ffd10824eaa73bbe2fa7ab432af2f0?s=96&#38;d=identicon" medium="image">
			<media:title type="html">sid6581</media:title>
		</media:content>

		<media:content url="http://sid6581.files.wordpress.com/2006/10/ge_compressors_list.png" medium="image">
			<media:title type="html">GraphEdit Video Compressors List</media:title>
		</media:content>
	</item>
		<item>
		<title>Minimizing audio capture latency in DirectShow</title>
		<link>http://sid6581.wordpress.com/2006/10/09/minimizing-audio-capture-latency-in-directshow/</link>
		<comments>http://sid6581.wordpress.com/2006/10/09/minimizing-audio-capture-latency-in-directshow/#comments</comments>
		<pubDate>Tue, 10 Oct 2006 02:21:25 +0000</pubDate>
		<dc:creator>sid6581</dc:creator>
				<category><![CDATA[DirectShow]]></category>

		<guid isPermaLink="false">http://sid6581.wordpress.com/2006/10/09/minimizing-audio-capture-latency-in-directshow/</guid>
		<description><![CDATA[If you have used DirectShow for audio capture, you have probably noticed that audio that is being previewed by an audio renderer in your graph can significantly lag the audio capture source. This is especially obvious if you are capturing and previewing both audio and video, where this lag will make your preview look like a badly dubbed movie.
The cause of the lag can be hard [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sid6581.wordpress.com&blog=463538&post=3&subd=sid6581&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you have used DirectShow for audio capture, you have probably noticed that audio that is being previewed by an audio renderer in your graph can significantly lag the audio capture source. This is especially obvious if you are capturing and previewing both audio and video, where this lag will make your preview look like a badly dubbed movie.</p>
<p>The cause of the lag can be hard to track down if you don&#8217;t know where to look. It turns out that the reason is that the audio capture source in DirectShow defaults to using 500ms buffers. In other words, the capture source has to capture 500ms worth of audio before it can pass the buffer downstream. Since the audio renderer can&#8217;t render any audio until it gets the buffer from the source, there will be at least a 500ms latency between any audio being captured and any audio being played.<br />
<span id="more-3"></span><br />
So what can we do about it? There&#8217;s actually a fairly easy way to ask the capture source to use a smaller buffer: The IAMBufferNegotiation interface. You have to get this interface from the audio capture pin on your capture filter, not the filter itself. Using it is very simple, but you need to be careful when calculating the buffer size to take into account the current audio capture rate, the number of channels, and the number of bits in a sample.</p>
<p>Below is a quick example. Call this function with your audio capture pin and your desired latency in milliseconds (try 50ms), and your latency problems should hopefully be taken care of.</p>
<pre>
HRESULT SetAudioLatency(IPin *AudioCapturePin, int BufferSizeMilliSeconds)
{
   assert(AudioCapturePin);
   assert(BufferSizeMilliSeconds &gt; 0); 

   // Get the interfaces we need.
   CComQIPtr&lt;IAMStreamConfig&gt; streamconfig(AudioCapturePin);
   if (!streamconfig)
      return E_NOINTERFACE; 

   CComQIPtr&lt;IAMBufferNegotiation&gt; bufneg(AudioCapturePin);
   if (!bufneg)
      return E_NOINTERFACE; 

   // Get the current audio capture properties.
   CMediaType mt;
   HRESULT hr = streamconfig-&gt;GetFormat(&amp;mt);
   if (FAILED(hr))
      return hr; 

   assert(*mt-&gt;FormatType() == FORMAT_WaveFormatEx);
   assert(mt-&gt;FormatLength() &gt;= sizeof(WAVEFORMATEX));
   WAVEFORMATEX *wf = (WAVEFORMATEX *)MediaType-&gt;Format(); 

   // Set the desired buffer size.
   ALLOCATOR_PROPERTIES props;
   props.cBuffers = -1;
   props.cbBuffer = wf-&gt;nAvgBytesPerSec * BufferSizeMilliSeconds/1000;
   props.cbAlign = -1;
   props.cbPrefix = -1;
   return bufneg-&gt;SuggestAllocatorProperties(&amp;props);
}</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sid6581.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sid6581.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sid6581.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sid6581.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sid6581.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sid6581.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sid6581.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sid6581.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sid6581.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sid6581.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sid6581.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sid6581.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sid6581.wordpress.com&blog=463538&post=3&subd=sid6581&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sid6581.wordpress.com/2006/10/09/minimizing-audio-capture-latency-in-directshow/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d9ffd10824eaa73bbe2fa7ab432af2f0?s=96&#38;d=identicon" medium="image">
			<media:title type="html">sid6581</media:title>
		</media:content>
	</item>
	</channel>
</rss>