aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Output/out_ds/DevEnum.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Src/Plugins/Output/out_ds/DevEnum.cpp')
-rw-r--r--Src/Plugins/Output/out_ds/DevEnum.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/Src/Plugins/Output/out_ds/DevEnum.cpp b/Src/Plugins/Output/out_ds/DevEnum.cpp
new file mode 100644
index 00000000..2c35db49
--- /dev/null
+++ b/Src/Plugins/Output/out_ds/DevEnum.cpp
@@ -0,0 +1,132 @@
+#include "DevEnum.h"
+#include "ds2.h"
+#include "strsafe.h"
+
+static int device_count=0;
+static const GUID NULL_GUID;
+
+
+BOOL WINAPI DsDevEnum::DSEnumCallback(LPGUID guid,LPCTSTR desc,LPCTSTR,DS_DEV *** var)
+{
+ DS_DEV * dev=new DS_DEV;
+
+ size_t length=lstrlen(desc);
+ length+=4; // "##: "
+ length+=1; // null terminator
+
+ dev->name = (TCHAR *)calloc(sizeof(TCHAR),length);
+
+ StringCchPrintf(dev->name,length, TEXT("%02d: %s"), device_count++, desc);
+
+ dev->guid=guid ? *guid : NULL_GUID;
+
+ **var = dev;
+ *var=&dev->next;
+
+ return 1;
+}
+
+DsDevEnum::DsDevEnum()
+{
+ DS2::InitDLL();
+ ds_devs=0;
+
+ DS_DEV ** dev_ptr=&ds_devs;
+ device_count = 1;
+ if (DS2::pDirectSoundEnumerate)
+ DS2::pDirectSoundEnumerate((LPDSENUMCALLBACK)DSEnumCallback,&dev_ptr);
+
+ *dev_ptr=0;
+ pDev=ds_devs;
+}
+
+DsDevEnum::~DsDevEnum()
+{
+ DS_DEV* dev=ds_devs;
+ while(dev)
+ {
+ DS_DEV * next=dev->next;
+ free(dev->name);
+ delete dev;
+ dev=next;
+ }
+// ds_devs=0;
+}
+
+bool DsDevEnum::FindGuid(const GUID & guid)
+{
+ pDev=ds_devs;
+ while(pDev)
+ {
+ if (pDev->guid== guid) return true;
+ pDev=pDev->next;
+ }
+ return false;
+}
+
+bool DsDevEnum::FindDefault()
+{
+ return FindGuid(NULL_GUID);
+}
+
+bool DsDevEnum::FindName(const TCHAR *deviceToFind)
+{
+ pDev=ds_devs;
+ if (!deviceToFind) return true;
+ while(pDev)
+ {
+ if (!lstrcmpi(pDev->name,deviceToFind)) return true;
+ pDev=pDev->next;
+ }
+ return false;
+}
+/*
+const GUID DsDevEnum::GuidFromName(const char* name)
+{
+ return FindName(name) ? GetGuid() : NULL_GUID;
+}
+
+const char * DsDevEnum::NameFromGuid(const GUID & g, char * def)
+{
+ return FindGuid(g) ? GetName() : def;
+}
+*/
+const GUID DsDevEnum::GetGuid()
+{
+ return pDev ? pDev->guid : NULL_GUID;
+}
+
+
+static bool _getcaps(IDirectSound * pDS,LPDSCAPS pCaps,DWORD * speakercfg)
+{
+ bool rv = true;
+ if (pCaps)
+ {
+ memset(pCaps,0,sizeof(*pCaps));
+ pCaps->dwSize=sizeof(*pCaps);
+ if (FAILED(pDS->GetCaps(pCaps))) rv = false;
+ }
+ if (speakercfg)
+ {
+ if (FAILED(pDS->GetSpeakerConfig(speakercfg))) rv = false;
+ }
+ return rv;
+}
+
+bool DsDevEnum::GetCapsFromGuid(const GUID *dev,LPDSCAPS pCaps,DWORD * speakercfg)
+{
+ bool rv=false;
+ if (!dev) dev=&NULL_GUID;
+
+ if (DS2::TryGetDevCaps(dev,pCaps,speakercfg)) rv=true;
+ else
+ {
+ IDirectSound * l_pDS=0;
+ if (SUCCEEDED(DS2::myDirectSoundCreate(dev,&l_pDS)) && l_pDS)
+ {
+ rv=_getcaps(l_pDS,pCaps,speakercfg);
+ l_pDS->Release();
+ }
+ }
+ return rv;
+}