遍历 source filter 的每一个 pin,尝试找到一个到 audio renderer 的成功连接,这个过程是 DShow 自动完成的,在 source 和 renderer 中间可能会添加一些 filter 如 demuxer、decoder 和 resampler 等等。
HRESULT _renderStreams(IBaseFilter *pSource){
HRESULT hr = S_OK;
BOOL bRenderedAnyPin = FALSE;
CComPtr<IFilterGraph2> pGraph2 =NULL;
CComPtr<IEnumPins> pEnum =NULL;
CComPtr<IBaseFilter> pAudioRenderer =NULL;
hr = m_pGraph->QueryInterface(IID_IFilterGraph2,(void**)&pGraph2);RETURN_IF_FAILED(hr);
hr =AddFilterByCLSID(m_pGraph, CLSID_DSoundRender,&pAudioRenderer,_T("Audio Renderer"));RETURN_IF_FAILED(hr);
hr = pSource->EnumPins(&pEnum);RETURN_IF_FAILED(hr);
IPin *pPin =NULL;while(S_OK == pEnum->Next(1,&pPin,NULL)){// Try to render this pin. It's OK if we fail some pins, if at least one pin renders.
hr = pGraph2->RenderEx(pPin, AM_RENDEREX_RENDERTOEXISTINGRENDERERS,NULL);
pPin->Release();if(SUCCEEDED(hr))
bRenderedAnyPin = TRUE;}RETURN_IF_FALSE_EX(bRenderedAnyPin, VFW_E_CANNOT_RENDER);return S_OK;}
DSAudioPlayer::_updateVolume 函数
Very simple,在播放过程中也可以调节。
HRESULT _updateVolume(){
HRESULT hr = E_FAIL;if(m_bMute)// If the audio is muted, set the minimum volume.
hr = m_pAudio->put_Volume(MIN_VOLUME);else// Restore previous volume setting
hr = m_pAudio->put_Volume(m_lVolume);RETURN_IF_FAILED(hr);return hr;}