[DSOUND]
[reactos.git] / reactos / dll / directx / dsound_new / dsound.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Configuration of network devices
4 * FILE: dll/directx/dsound_new/dsound.c
5 * PURPOSE: Handles DSound initialization
6 *
7 * PROGRAMMERS: Johannes Anderwald (janderwald@reactos.org)
8 */
9
10 #include "precomp.h"
11
12 HINSTANCE dsound_hInstance;
13 LPFILTERINFO RootInfo = NULL;
14
15 static INTERFACE_TABLE InterfaceTable[] =
16 {
17 {
18 &CLSID_DirectSoundPrivate,
19 NewKsPropertySet
20 },
21 {
22 &CLSID_DirectSoundCapture,
23 NewDirectSoundCapture
24 },
25 {
26 &CLSID_DirectSound,
27 NewDirectSound
28 },
29 {
30 NULL,
31 NULL
32 }
33 };
34
35
36 HRESULT
37 WINAPI
38 DllCanUnloadNow()
39 {
40 return S_FALSE;
41 }
42
43 HRESULT
44 WINAPI
45 GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
46 {
47 ULONG DeviceID = ULONG_MAX, Flags;
48 MMRESULT Result;
49 LPFILTERINFO Filter;
50
51 if (!pGuidSrc || !pGuidDest)
52 {
53 /* invalid param */
54 return DSERR_INVALIDPARAM;
55 }
56
57 /* sanity check */
58 ASSERT(!IsEqualGUID(pGuidSrc, &GUID_NULL));
59
60 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc) ||
61 IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc))
62 {
63 Result = waveOutMessage(UlongToHandle(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&DeviceID, (DWORD_PTR)&Flags);
64 if (Result != MMSYSERR_NOERROR || DeviceID == ULONG_MAX)
65 {
66 /* hack */
67 DPRINT1("Failed to get DRVM_MAPPER_PREFERRED_GET, using device 0\n");
68 DeviceID = 0;
69 }
70
71 if (!FindDeviceByMappedId(DeviceID, &Filter, TRUE))
72 {
73 /* device not found */
74 return DSERR_INVALIDPARAM;
75 }
76
77 /* copy device guid */
78 RtlMoveMemory(pGuidDest, &Filter->DeviceGuid[1], sizeof(GUID));
79 return DS_OK;
80 }
81 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc) ||
82 IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc))
83 {
84 Result = waveInMessage(UlongToHandle(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&DeviceID, (DWORD_PTR)&Flags);
85 if (Result != MMSYSERR_NOERROR || DeviceID == ULONG_MAX)
86 {
87 /* hack */
88 DPRINT1("Failed to get DRVM_MAPPER_PREFERRED_GET, for record using device 0\n");
89 DeviceID = 0;
90 }
91
92 if (!FindDeviceByMappedId(DeviceID, &Filter, FALSE))
93 {
94 /* device not found */
95 return DSERR_INVALIDPARAM;
96 }
97
98 /* copy device guid */
99 RtlMoveMemory(pGuidDest, &Filter->DeviceGuid[0], sizeof(GUID));
100 return DS_OK;
101 }
102
103 if (!FindDeviceByGuid(pGuidSrc, &Filter))
104 {
105 /* unknown guid */
106 return DSERR_INVALIDPARAM;
107 }
108
109 /* done */
110 return DS_OK;
111 }
112
113
114 HRESULT
115 WINAPI
116 DllGetClassObject(
117 REFCLSID rclsid,
118 REFIID riid,
119 LPVOID* ppv
120 )
121 {
122 LPOLESTR pStr, pStr2;
123 UINT i;
124 HRESULT hres = E_OUTOFMEMORY;
125 IClassFactory * pcf = NULL;
126
127 if (!ppv)
128 return E_INVALIDARG;
129
130 *ppv = NULL;
131
132 for (i = 0; InterfaceTable[i].riid; i++)
133 {
134 if (IsEqualIID(InterfaceTable[i].riid, rclsid))
135 {
136 pcf = IClassFactory_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
137 break;
138 }
139 }
140
141 if (!pcf)
142 {
143 StringFromIID(rclsid, &pStr);
144 StringFromIID(riid, &pStr2);
145 DPRINT("No Class Available for %ws IID %ws\n", pStr, pStr2);
146 CoTaskMemFree(pStr);
147 CoTaskMemFree(pStr2);
148 ASSERT(0);
149 return CLASS_E_CLASSNOTAVAILABLE;
150 }
151
152 hres = IClassFactory_QueryInterface(pcf, riid, ppv);
153 IClassFactory_Release(pcf);
154
155 return hres;
156 }
157
158
159
160 BOOL
161 WINAPI
162 DllMain(
163 HINSTANCE hInstDLL,
164 DWORD fdwReason,
165 LPVOID lpvReserved)
166 {
167 switch (fdwReason)
168 {
169 case DLL_PROCESS_ATTACH:
170 dsound_hInstance = hInstDLL;
171 #if 1
172 DPRINT("NumDevs %u\n", waveOutGetNumDevs());
173 if (EnumAudioDeviceInterfaces(&RootInfo) != S_OK)
174 {
175 DPRINT("EnumAudioDeviceInterfaces failed\n");
176 RootInfo = NULL;
177 }
178 DPRINT1("EnumAudioDeviceInterfaces %p %u\n", RootInfo, waveOutGetNumDevs());
179 #endif
180 DisableThreadLibraryCalls(dsound_hInstance);
181 break;
182 default:
183 break;
184 }
185
186 return TRUE;
187 }
188