|
楼主 |
发表于 2020-7-3 23:00:01
|
显示全部楼层
//mpeg2dmx.ax
WCHAR szMPegTS[]=L"@device:sw:{083863F1-70DE-11D0-BD40-00A0C911CE86}\\{731B8592-4001-46D4-B1A5-33EC792B4501}";
// construct source filter
if (m_bInit)
{
CMediaType mt;
mt.majortype = MEDIATYPE_Stream;
mt.subtype = MEDIASUBTYPE_MPEG2_TRANSPORT;
mt.formattype =FORMAT_MPEGStreams;
m_pSourceStream = new CMemStream(m_pDataList);
m_pSourceStream->bStopFlag=0;
m_pSourceReader = new CMemReader(m_pSourceStream, &mt, &hr);
m_pSourceReader->AddRef();
// Add our source filter
hr = m_pGB->AddFilter(m_pSourceReader, NULL);
// find mpeg2 filter
hr=GetFilterByMoniker(szMPegTS, (IBaseFilter **)&m_pMpeg2tsFilter);
//add mpeg2 filter
hr=m_pMpeg2tsFilter->AddRef();
hr = m_pGB->AddFilter(m_pMpeg2tsFilter, NULL);
hr=m_pMpeg2VideoFilter->AddRef();
hr = m_pGB->AddFilter(m_pMpeg2VideoFilter, NULL);
if (FAILED(hr))
{
m_bInit = false;
}
//就是这里连接失败
hr=ConnectFilters(m_pGB,m_pSourceReader,m_pMpeg2tsFilter);
ConnectFilters函数是分别在两个filter中查找一个INPIN和一个OUTPIN并调用:hr = pGraph->Connect(pOut, pIn)进行连接,分别查找两个PIN都是成功了的。
HRESULT CFilterGraph::ConnectFilters(
IGraphBuilder *pGraph,
IBaseFilter *pSrc,
IBaseFilter *pDest)
{
if ((pGraph == NULL) || (pSrc == NULL) || (pDest == NULL))
{
return E_POINTER;
}
// Find an output pin on the first filter.
IPin *pOut = 0;
HRESULT hr = GetUnconnectedPin(pSrc, PINDIR_OUTPUT, &pOut);
if (FAILED(hr))
{
return hr;
}
hr = ConnectFilters(pGraph, pOut, pDest);
pOut->Release();
return hr;
}
HRESULT CFilterGraph::ConnectFilters(
IGraphBuilder *pGraph, // Filter Graph Manager.
IPin *pOut, // Output pin on the upstream filter.
IBaseFilter *pDest) // Downstream filter.
{
if ((pGraph == NULL) || (pOut == NULL) || (pDest == NULL))
{
return E_POINTER;
}
// Find an input pin on the downstream filter.
IPin *pIn = 0;
HRESULT hr = GetUnconnectedPin(pDest, PINDIR_INPUT, &pIn);
if (FAILED(hr))
{
return hr;
}
// Try to connect them.
hr = pGraph->Connect(pOut, pIn); //真正连接失败的地方是这里
pIn->Release();
return hr;
}
|
|