HRESULT CSampleCGB::FindEncoder( IEnumMoniker *pEncoders, REGPINMEDIUM pinMedium, IBaseFilter **ppEncoder ) { if( ! pEncoders ) { return E_INVALIDARG; } if(IsEqualGUID(pinMedium.clsMedium,GUID_NULL) || IsEqualGUID(pinMedium.clsMedium,KSMEDIUMSETID_Standard)) { return E_INVALIDARG; } HRESULT hr; SmartPtr<IBaseFilter> pFilter; SmartPtr<IMoniker> pMoniker; ULONG cFetched; SmartPtr<IPin> pPin; while(pFilter.Release(),pMoniker.Release(),S_OK == pEncoders->Next(1,&pMoniker,&cFetched)) { hr = pMoniker->BindToObject(0,0,IID_IBaseFilter,(void**)&pFilter); if(FAILED(hr))continue; hr = FindPin(pFilter,pinMedium,PINDIR_INPUT,TRUE,&pPin); if(SUCCEEDED(hr)) { *ppEncoder = pFilter.Detach(); return hr; } } return E_FAIL; }
HRESULT ISampleCaptureGraphBuilder::FindAudioPin( IBaseFilter *pFilter, IPin **ppPin ) { if( !pFilter ) { return E_POINTER; } SmartPtr<IEnumPins> pEnumPins; HRESULT hr = pFilter->EnumPins( &pEnumPins ); if( FAILED( hr ) ) { return hr; } SmartPtr<IPin> pTempPin; ULONG fetched; hr = pEnumPins->Reset( ); while( pTempPin.Release(), S_OK == pEnumPins->Next( 1, &pTempPin, &fetched ) ) { if( IsAudioPin( pTempPin ) ) { (*ppPin) = pTempPin.Detach(); return S_OK; } } return E_FAIL; }
HRESULT CSampleCGB::FindMPEG2Pin( IBaseFilter *pFilter, IPin** ppPin ) { if(!pFilter)return E_INVALIDARG; SmartPtr<IEnumPins> pEnumPins; HRESULT hr = pFilter->EnumPins(&pEnumPins); if(FAILED(hr))return hr; SmartPtr<IPin> pTempPin; ULONG fetched; PIN_DIRECTION dir; hr = pEnumPins->Reset(); while(pTempPin.Release(),S_OK == pEnumPins->Next(1,&pTempPin,&fetched)) { hr = pTempPin->QueryDirection(&dir); if(FAILED(hr) || PINDIR_INPUT == dir) { continue; } if(IsMPEG2Pin(pTempPin)) { (*ppPin) = pTempPin.Detach(); return S_OK; } } return E_FAIL; }
// // search the encoder that has this special medium // video == TRUE -- look for a video pin // video == FALSE -- look for a audio pin // HRESULT ISampleCaptureGraphBuilder::FindPin( IBaseFilter *pFilter, const REGPINMEDIUM& regPinMedium, PIN_DIRECTION direction, BOOL video, IPin **ppPin) { if( !pFilter ) { return E_POINTER; } SmartPtr<IEnumPins> pEnumPins; HRESULT hr = pFilter->EnumPins( &pEnumPins ); if( FAILED( hr ) ) { return hr; } SmartPtr<IPin> pTempPin; ULONG fetched; REGPINMEDIUM regPinMediumTemp; PIN_DIRECTION dir; hr = pEnumPins->Reset( ); while( pTempPin.Release(), S_OK == pEnumPins->Next( 1, &pTempPin, &fetched ) ) { ASSERT( pTempPin ); hr = pTempPin->QueryDirection( &dir ); if( FAILED( hr ) || dir != direction ) { continue; } hr = GetMedium( pTempPin, regPinMediumTemp ); if( FAILED( hr ) ) { continue; } if( !IsVideoPin( pTempPin ) ) { continue; } if( ::IsEqualGUID( regPinMediumTemp.clsMedium, regPinMedium.clsMedium ) && regPinMediumTemp.dw1 == regPinMedium.dw1 ) { (*ppPin) = pTempPin.Detach(); return S_OK; } } return E_FAIL; }
HRESULT CSampleCGB::FindAudioPin( IBaseFilter *pFilter, IPin **ppPin ) { if(!pFilter)return E_POINTER; SmartPtr<IEnumPins> pEnumPins; HRESULT hr = pFilter->EnumPins(&pEnumPins); if(FAILED(hr))return hr; SmartPtr<IPin> pTempPin; ULONG cFetched; hr = pEnumPins->Reset(); if(FAILED(hr))return hr; while(pTempPin.Release(),pEnumPins->Next(1,&pTempPin,&cFetched)) { if(IsAudioPin(pTempPin)) { *ppPin = pTempPin.Detach(); return S_OK; } } return E_FAIL; }