title: Unable to RenderStream when using SampleGrabber with Microsoft DTV-DVD Audio Decoder and Direct Sound Renederer
body: <p>I would like to play only audio from video file. For this I'm using directshow SampleGrabber with Major_type set to MEDIATYPE_Audio and DirectSound Audio Renderer. </p>
  
  <p>This works fine for .wmv files. However when I try to play .mp4 files. The RenderStream fails.</p>
  
  <p>I then tried creating filter in GrapStudioNext with following filtet</p>
  
  <p>File Source->LAV Splitter (Automatically load)->SampleGrabber->MS DTV-DVD Audio Decoder->Default DirectSoude Device</p>
  
  <p>The above filter works fine and I'm to listen to the audio.</p>
  
  <p>However when I create the same filter graph manually in vc++. The RenderStream calls fails while connecting source filter to SampleGrabber</p>
  
  <pre><code>HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                          IID_IGraphBuilder, (void **)&amp;m_pGraph);
  if(FAILED(hr))
  {
  ReleaseResource();
  return hr;
  }
  
  hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, 
          (void **)&amp;m_pBuilder);
      if (SUCCEEDED(hr))
      {
          m_pBuilder-&gt;SetFiltergraph(m_pGraph);
      }
  else
  {
  std::cout&lt;&lt;"Failed to Created Capture Graph"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  
  hr = m_pGraph-&gt;QueryInterface(IID_IMediaControl, (void**)&amp;m_pControl);
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Get Media Control Interface"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  
  hr = m_pGraph-&gt;QueryInterface(IID_IMediaEvent, (void**)&amp;m_pEvent);
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Get Media Event"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  
  hr = m_pGraph-&gt;QueryInterface(IID_IMediaSeeking, (void**)&amp;m_pMediaSeek);
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Get Media Seeking"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  
  hr = m_pGraph-&gt;QueryInterface(IID_IBasicAudio, (void**)&amp;m_pBasicAudio);
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Get Basic Audio"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  #if 0
  hr = CoCreateInstance(CLSID_AudioRender, NULL, CLSCTX_INPROC_SERVER, 
  IID_IBaseFilter, (void**)&amp;m_pBaseFilter);
  #endif
  
  hr = CoCreateInstance(CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, 
  IID_IBaseFilter, (void**)&amp;m_pBaseFilter);
  
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Create Audio Render"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  
  hr = m_pGraph-&gt;AddFilter(m_pBaseFilter, L"Audio Filter");
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Add Audio Render"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  
  hr = m_pGraph-&gt;AddSourceFilter((LPCWSTR)wxStr,L"SourceFlt", &amp;m_pSourceFilter);
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Add Source Filter"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  
  hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, 
  IID_IBaseFilter, (void**)&amp;m_pBaseFilterSG);
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Create Sample Grabber"&lt;&lt;std::endl;
  ReleaseResource();
  return 1;
  }
  
  hr = m_pGraph-&gt;AddFilter(m_pBaseFilterSG, L"Sample_Grabber");
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Add Sample Grabber"&lt;&lt;std::endl;
  ReleaseResource();
  return 1;
  }
  
  hr = m_pBaseFilterSG-&gt;QueryInterface(IID_ISampleGrabber, (void**)&amp;m_pSampleGrabber);
  
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Query Interface Failed for Sample Grabber"&lt;&lt;std::endl;
  ReleaseResource();
  return 1;
  }
  ZeroMemory(&amp;mt, sizeof(mt));
  mt.majortype = MEDIATYPE_Audio;
  mt.subtype = MEDIASUBTYPE_RAW_AAC1;
   hr = m_pSampleGrabber-&gt;SetMediaType(&amp;mt);
  
    if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Set Media Type"&lt;&lt;std::endl;
  ReleaseResource();
  return 1;
  }
  
  hr = CoCreateInstance(CLSID_CMPEG2AudDecoderDS , NULL, CLSCTX_INPROC_SERVER, 
  IID_IBaseFilter, (void**)&amp;m_pMSAduioDecoder);
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Create Sample Grabber"&lt;&lt;std::endl;
  ReleaseResource();
  return 1;
  }
  
  hr = m_pGraph-&gt;AddFilter(m_pMSAduioDecoder, L"Audio_Decoder");
  if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Add Adudio Decoder"&lt;&lt;std::endl;
  ReleaseResource();
  return 1;
  }
  
  hr = m_pBuilder-&gt;RenderStream( &amp;PIN_CATEGORY_CAPTURE, &amp;MEDIATYPE_Audio,m_pSourceFilter, m_pBaseFilterSG,m_pMSAduioDecoder);
   if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Render First Chain"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  
    hr = m_pBuilder-&gt;RenderStream(NULL, NULL,m_pMSAduioDecoder,NULL,  m_pBaseFilter);
   if(FAILED(hr))
  {
  std::cout&lt;&lt;"Failed to Render Second Chain"&lt;&lt;std::endl;
  ReleaseResource();
  return hr;
  }
  </code></pre>
  
  <p>Also when I SetMediaType to MEDIATYPE_Video the first chain connects properly. But seconds one fails even after using PIN_CATEOGARY_CAPTURE and MediaType_Audio.</p>
  
  <p>Also the error I'm getting in RenderStream invalid args.</p>
  
  <p>Please suggest what could be going wrong. Thanks in advance.</p>
  
  <p>Pradeep</p>