0
votes

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.

This works fine for .wmv files. However when I try to play .mp4 files. The RenderStream fails.

I then tried creating filter in GrapStudioNext with following filtet

File Source->LAV Splitter (Automatically load)->SampleGrabber->MS DTV-DVD Audio Decoder->Default DirectSoude Device

The above filter works fine and I'm to listen to the audio.

However when I create the same filter graph manually in vc++. The RenderStream calls fails while connecting source filter to SampleGrabber

HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, 
                        IID_IGraphBuilder, (void **)&m_pGraph);
if(FAILED(hr))
{
ReleaseResource();
return hr;
}

hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, 
        (void **)&m_pBuilder);
    if (SUCCEEDED(hr))
    {
        m_pBuilder->SetFiltergraph(m_pGraph);
    }
else
{
std::cout<<"Failed to Created Capture Graph"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->QueryInterface(IID_IMediaControl, (void**)&m_pControl);
if(FAILED(hr))
{
std::cout<<"Failed to Get Media Control Interface"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->QueryInterface(IID_IMediaEvent, (void**)&m_pEvent);
if(FAILED(hr))
{
std::cout<<"Failed to Get Media Event"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->QueryInterface(IID_IMediaSeeking, (void**)&m_pMediaSeek);
if(FAILED(hr))
{
std::cout<<"Failed to Get Media Seeking"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->QueryInterface(IID_IBasicAudio, (void**)&m_pBasicAudio);
if(FAILED(hr))
{
std::cout<<"Failed to Get Basic Audio"<<std::endl;
ReleaseResource();
return hr;
}
#if 0
hr = CoCreateInstance(CLSID_AudioRender, NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (void**)&m_pBaseFilter);
#endif

hr = CoCreateInstance(CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (void**)&m_pBaseFilter);

if(FAILED(hr))
{
std::cout<<"Failed to Create Audio Render"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->AddFilter(m_pBaseFilter, L"Audio Filter");
if(FAILED(hr))
{
std::cout<<"Failed to Add Audio Render"<<std::endl;
ReleaseResource();
return hr;
}

hr = m_pGraph->AddSourceFilter((LPCWSTR)wxStr,L"SourceFlt", &m_pSourceFilter);
if(FAILED(hr))
{
std::cout<<"Failed to Add Source Filter"<<std::endl;
ReleaseResource();
return hr;
}

hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (void**)&m_pBaseFilterSG);
if(FAILED(hr))
{
std::cout<<"Failed to Create Sample Grabber"<<std::endl;
ReleaseResource();
return 1;
}

hr = m_pGraph->AddFilter(m_pBaseFilterSG, L"Sample_Grabber");
if(FAILED(hr))
{
std::cout<<"Failed to Add Sample Grabber"<<std::endl;
ReleaseResource();
return 1;
}

hr = m_pBaseFilterSG->QueryInterface(IID_ISampleGrabber, (void**)&m_pSampleGrabber);

if(FAILED(hr))
{
std::cout<<"Query Interface Failed for Sample Grabber"<<std::endl;
ReleaseResource();
return 1;
}
ZeroMemory(&mt, sizeof(mt));
mt.majortype = MEDIATYPE_Audio;
mt.subtype = MEDIASUBTYPE_RAW_AAC1;
 hr = m_pSampleGrabber->SetMediaType(&mt);

  if(FAILED(hr))
{
std::cout<<"Failed to Set Media Type"<<std::endl;
ReleaseResource();
return 1;
}

hr = CoCreateInstance(CLSID_CMPEG2AudDecoderDS , NULL, CLSCTX_INPROC_SERVER, 
IID_IBaseFilter, (void**)&m_pMSAduioDecoder);
if(FAILED(hr))
{
std::cout<<"Failed to Create Sample Grabber"<<std::endl;
ReleaseResource();
return 1;
}

hr = m_pGraph->AddFilter(m_pMSAduioDecoder, L"Audio_Decoder");
if(FAILED(hr))
{
std::cout<<"Failed to Add Adudio Decoder"<<std::endl;
ReleaseResource();
return 1;
}

hr = m_pBuilder->RenderStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Audio,m_pSourceFilter, m_pBaseFilterSG,m_pMSAduioDecoder);
 if(FAILED(hr))
{
std::cout<<"Failed to Render First Chain"<<std::endl;
ReleaseResource();
return hr;
}

  hr = m_pBuilder->RenderStream(NULL, NULL,m_pMSAduioDecoder,NULL,  m_pBaseFilter);
 if(FAILED(hr))
{
std::cout<<"Failed to Render Second Chain"<<std::endl;
ReleaseResource();
return hr;
}

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.

Also the error I'm getting in RenderStream invalid args.

Please suggest what could be going wrong. Thanks in advance.

Pradeep

1

1 Answers

0
votes

This is totally wrong. You don't have capture sources at all, so trying to leverage Capture Graph Builder is weak in first place. You don't have a single pin in your graph which is PIN_CATEGORY_CAPTURE and so it fails.

You know all the filters you need to use, CoCreateInstance, IGraphBuilder::AddFilter and IPin::Connect are sufficient for graph building, you don't need capture graph builder here at all.