Mobile上 Directshow開發Camera問題
我們利用DirectShow開發Camera
平常都能正常開啟關閉
但連續開啟關閉數十次後,Camera會開始出現全黑畫面,
發現問題在於Transform filter 跟Render filter連接時失敗
ConnectFilters( pGraphBuilder, m_pTransformFilter, m_pRender );
HRESULT ConnectFilters(IGraphBuilder *pGraph,IBaseFilter *pSrc,IBaseFilter *pDest){ if(( !pGraph ) || ( !pSrc ) || ( !pDest )) return E_POINTER; // Find an output pin on the first filter. HRESULT hr = E_FAIL; CComPtr<IPin> pOut = NULL; CHK( GetUnconnectedPin( pSrc, PINDIR_OUTPUT, &pOut )); CHK( ConnectFilters( pGraph, pOut, pDest )); Cleanup: if( FAILED( hr )) RETAILMSG( 1, ( L"CAMERA >>> Connect Filters Failed...\r\n" )); if( pOut ) pOut.Release(); return hr;}//=============================================================================HRESULT ConnectFilters(IGraphBuilder *pGraph, IPin *pOut, IBaseFilter *pDest){ if( (!pGraph) || (!pOut) || (!pDest) ) return E_POINTER; // Find an input pin on the downstream filter. HRESULT hr = E_FAIL; CComPtr<IPin> pIn = NULL; CHK( GetUnconnectedPin( pDest, PINDIR_INPUT, &pIn )); PIN_INFO pinInfo_OUT, pinInfo_IN; memset( &pinInfo_OUT, 0, sizeof( PIN_INFO )); memset( &pinInfo_IN, 0, sizeof( PIN_INFO )); hr = pOut->QueryPinInfo( &pinInfo_OUT ); hr = pIn->QueryPinInfo( &pinInfo_IN ); // Try to connect them. CHK( pGraph->Connect( pOut, pIn )); Cleanup: if( FAILED( hr )) RETAILMSG( 1, ( L"CAMERA >>> Connect Pins Failed...\r\n" )); if( pIn ) pIn.Release(); return hr;}//=============================================================================HRESULT GetUnconnectedPin(IBaseFilter *pFilter,PIN_DIRECTION PinDir,IPin **ppPin){ HRESULT hr = E_FAIL; *ppPin = 0; CComPtr<IEnumPins> pEnum = NULL; IPin *pPin = 0; CHK( pFilter->EnumPins( &pEnum )); while( pEnum->Next(1, &pPin, NULL) == S_OK ) { PIN_DIRECTION ThisPinDir; hr = pPin->QueryDirection( &ThisPinDir ); if( ThisPinDir == PinDir ) { CComPtr<IPin> pTmp = NULL; hr = pPin->ConnectedTo(&pTmp); if( SUCCEEDED( hr )) // Already connected, not the pin we want. { pTmp.Release(); } else // Unconnected, this is the pin we want. { *ppPin = pPin; hr = S_OK; break; } } pPin->Release(); }Cleanup: if( FAILED( hr )) RETAILMSG( 1, ( L"CAMERA >>> Get Unconnected Pin Failed...\r\n" )); if( pEnum ) pEnum.Release(); return hr; }