Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi guys:
i'm a little puzzle about "Default Directsound Device".< graphedit / Audio Rederers/ Default Directsound Device>
how can i add a Default Directsound Device to my filter graph so that my player can work correctly.
Anyone got any ideas or links for adding the Default DirectSound Device to filter graph just help me!
Posted

C
HRESULT CPlayer::AddDefaultDirectSoundDevice (	IFilterGraph *pfG,IBaseFilter ** ppF,
											  LPCWSTR wszName)
{
	HRESULT hr ;
	ICreateDevEnum *pSysDevEnum = NULL;
	hr = CoCreateInstance(CLSID_SystemDeviceEnum,NULL,CLSCTX_INPROC_SERVER,
		IID_ICreateDevEnum,(void**)&pSysDevEnum);

	if(FAILED(hr))
	{
		return hr; 
	}
	IEnumMoniker *pEnumCat = NULL;
	hr = pSysDevEnum->CreateClassEnumerator(CLSID_AudioRendererCategory, &pEnumCat, 0);

	if(hr ==S_OK)
	{
		IMoniker *pMoniker = NULL;
		ULONG cFetched;
		CString temp ;

		while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
		{
			IPropertyBag *pPropBag;
			hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, 
				(void **)&pPropBag);
			if (SUCCEEDED(hr))
			{
				// To retrieve the filter's friendly name, do the following:
				VARIANT varName;
				VariantInit(&varName);
				hr = pPropBag->Read(L"FriendlyName", &varName, 0);
	
				if (SUCCEEDED(hr))
				{
					// Display the name in your UI somehow.
					temp.Format(TEXT("%s"),varName.bstrVal);
					if(temp.Compare(wszName)==0)
					{
						// To create an instance of the filter, do the following:
						IBaseFilter *pFilter;
						hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
							(void**)&pFilter);
						// Now add the filter to the graph. 
						hr = pfG->AddFilter(pFilter,wszName);
						if(SUCCEEDED(hr))
							*ppF=pFilter ;
						else
							pFilter->Release();
					}
				}
				VariantClear(&varName);		
				pPropBag->Release();
			}
			pMoniker->Release();
		}
		pEnumCat->Release();
	}
	pSysDevEnum->Release();
}


[EDIT] Added <pre> tags for better readability - Code-o-mat [/EDIT]
 
Share this answer
 
v3
This is a solution from graph edit plus.

C++
CComPtr<ibasefilter> CreateFilterByName(const WCHAR* filterName, const GUID& category)
{
	HRESULT hr = S_OK;
	CComPtr<icreatedevenum> pSysDevEnum;
	hr = pSysDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum);
	if (hrcheck(hr, "Can't create System Device Enumerator"))
	{
		return NULL;
	}
	
	CComPtr<ienummoniker> pEnumCat;
	hr = pSysDevEnum->CreateClassEnumerator(category, &pEnumCat, 0);
	if (hr == S_OK)
	{
		CComPtr<imoniker> pMoniker;
		ULONG cFetched;
		while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
		{
			CComPtr<ipropertybag> pPropBag;
			hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void * *)&pPropBag);
			if (SUCCEEDED(hr))
			{
				VARIANT varName;
				VariantInit(&varName);
				hr = pPropBag->Read(L"FriendlyName", &varName, 0);
				if (SUCCEEDED(hr))
				{
					if (wcscmp(filterName, varName.bstrVal)==0)
					{
						CComPtr<ibasefilter> pFilter;
						hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter);
						if (hrcheck(hr, "Can't bind moniker to filter object"))
							return NULL;
						return pFilter;
					}
				}
				VariantClear(&varName);
			}
			pMoniker.Release();
		}
	}
	return NULL;
}


And using:

C++
DEFINE_GUID(CLSID_AudioRenderers,
0xE0F158E1, 0xCB04, 0x11D0, 0xBD, 0x4E, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86);

//add Default DirectSound Device
	CComPtr<IBaseFilter> pDefaultDirectSoundDevice = CreateFilterByName(L"Default DirectSound Device", CLSID_AudioRenderers);
	hr = pGraph->AddFilter(pDefaultDirectSoundDevice, L"Default DirectSound Device");
	CHECK_HR(hr, "Can't add Default DirectSound Device to graph");
 
Share this answer
 
v3
As stated here[^]:

The audio renderer category contains two additional filter instances, named "Default DirectSound Device" and "Default WaveOut Device." These correspond to the default sound device, as chosen by the user through the Control Panel.

So i'd say, enumerate the filters and look for one that is called "Default DirectSound Device".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900