使用SampleGrabber与Microsoft DTV-DVD音频解码器和Direct Sound Renederer时无法使用RenderStream

时间:2013-02-20 13:06:56

标签: directshow

我想只播放视频文件中的音频。为此,我使用directshow SampleGrabber,将Major_type设置为MEDIATYPE_Audio和DirectSound Audio Renderer。

这适用于.wmv文件。但是当我尝试播放.mp4文件时。 RenderStream失败。

然后我尝试使用以下filtet

在GrapStudioNext中创建过滤器

文件来源 - > LAV分离器(自动加载) - > SampleGrabber-> MS DTV-DVD音频解码器 - >默认DirectSoude设备

上面的过滤器工作正常,我要听音频。

然而,当我在vc ++中手动创建相同的过滤器图形时。将源过滤器连接到SampleGrabber

时,RenderStream调用失败
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;
}

当我将SetMediaType设置为MEDIATYPE_Video时,第一个链正确连接。但是,即使在使用PIN_CATEOGARY_CAPTURE和MediaType_Audio之后,秒数也会失败。

我在RenderStream中遇到的错误也是无效的args。

请提出可能出现的问题。提前谢谢。

与Pradeep

1 个答案:

答案 0 :(得分:0)

这是完全错误的。您根本没有捕获源,因此首先尝试利用Capture Graph Builder很弱。您的图表中没有PIN_CATEGORY_CAPTURE的单个图钉,因此失败。

您知道需要使用的所有过滤器,CoCreateInstanceIGraphBuilder::AddFilterIPin::Connect足以进行图形构建,您根本不需要捕获图构建器。