多线程时Filter的怪异问题
gaofg 2006-03-15 05:11:03 相关代码如下:
UINT CFilterGraph::WaitingThrd(void * pParam)
{
CFilterGraph * pGraph = (CFilterGraph *) pParam;
if (pGraph != NULL && pGraph->m_pDataList != NULL)
{
::WaitForSingleObject(pGraph->m_pDataList->m_hBufEnough, INFINITE);
if (!pGraph->IsRunning())
{
pGraph->Run();
/*
long evCode = 0;
pGraph->m_pME->WaitForCompletion(INFINITE, &evCode);
*/
}
}
return 1;
}
bool CFilterGraph::StartGraph(void)
{
...
// Waiting for event to start filter graph,等待一定的数据后才开始run filter
::AfxBeginThread((AFX_THREADPROC)CFilterGraph::WaitingThrd, this);
...
}
UINT GraphThread( LPVOID pParam )
{
AfxOleInit();
CFilterGraph *pthrd = (CFilterGraph *)pParam;
if(!pthrd->BuildGraph())
{
AfxMessageBox("Build Filter Graph Manager Failed!");
return FALSE;
}
if(!pthrd->StartGraph())
{
AfxMessageBox("Filter Graph Manager Was not Started!");
return FALSE;
}
// Sleep(60000); //如果没有则没有图像显示
return 0;
}
对话框通过如下方式来创建线程:
m_pGraph = new CFilterGraph();
m_pGraph->SetVideoWndOwner(GetDlgItem(IDC_PICTURE)->GetSafeHwnd()); // 窗口句柄
AfxBeginThread(GraphThread, (LPVOID)m_pGraph);
问题是:如果没有上面的Sleep语句,则没有图像播放出,但Filter已经创建了。加上Sleep后则在
指定的时间后停止播放。但是这种方式显然不是解决问题的办法。而且即使如上注释中使用WaitForCompletion也还是不行。而以前对Filter不采用单独线程即在对话框中直接创建并运行则是正常的。
请指教,谢谢了!