Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 4-Apr-12 4:02am
lanhxg467
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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".
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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]
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This is a solution from graph edit plus.
 
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:
 
 
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");
  Permalink  
v3

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 472
1 sanket saxena 355
2 CPallini 205
3 thatraja 200
4 OriginalGriff 195
0 Sergey Alexandrovich Kryukov 8,784
1 OriginalGriff 5,025
2 Peter Leow 3,839
3 Maciej Los 3,535
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 15 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid