e8322ebbc316f31f62d4ffcb91834191b2b5ca06
[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_DirectSoundCapture8,
27 NewDirectSoundCapture
28 },
29 {
30 &CLSID_DirectSound,
31 NewDirectSound
32 },
33 {
34 &CLSID_DirectSound8,
35 NewDirectSound
36 },
37 {
38 NULL,
39 NULL
40 }
41 };
42
43
44 HRESULT
45 WINAPI
46 DllCanUnloadNow()
47 {
48 return S_FALSE;
49 }
50
51 HRESULT
52 WINAPI
53 GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest)
54 {
55 ULONG DeviceID = ULONG_MAX, Flags;
56 MMRESULT Result;
57 LPFILTERINFO Filter;
58
59 if (!pGuidSrc || !pGuidDest)
60 {
61 /* invalid param */
62 return DSERR_INVALIDPARAM;
63 }
64
65 /* sanity check */
66 ASSERT(!IsEqualGUID(pGuidSrc, &GUID_NULL));
67
68 if (IsEqualGUID(&DSDEVID_DefaultPlayback, pGuidSrc) ||
69 IsEqualGUID(&DSDEVID_DefaultVoicePlayback, pGuidSrc))
70 {
71 Result = waveOutMessage(UlongToHandle(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&DeviceID, (DWORD_PTR)&Flags);
72 if (Result != MMSYSERR_NOERROR || DeviceID == ULONG_MAX)
73 {
74 /* hack */
75 DPRINT1("Failed to get DRVM_MAPPER_PREFERRED_GET, using device 0\n");
76 DeviceID = 0;
77 }
78
79 if (!FindDeviceByMappedId(DeviceID, &Filter, TRUE))
80 {
81 /* device not found */
82 return DSERR_INVALIDPARAM;
83 }
84
85 /* copy device guid */
86 RtlMoveMemory(pGuidDest, &Filter->DeviceGuid[1], sizeof(GUID));
87 return DS_OK;
88 }
89 else if (IsEqualGUID(&DSDEVID_DefaultCapture, pGuidSrc) ||
90 IsEqualGUID(&DSDEVID_DefaultVoiceCapture, pGuidSrc))
91 {
92 Result = waveInMessage(UlongToHandle(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&DeviceID, (DWORD_PTR)&Flags);
93 if (Result != MMSYSERR_NOERROR || DeviceID == ULONG_MAX)
94 {
95 /* hack */
96 DPRINT1("Failed to get DRVM_MAPPER_PREFERRED_GET, for record using device 0\n");
97 DeviceID = 0;
98 }
99
100 if (!FindDeviceByMappedId(DeviceID, &Filter, FALSE))
101 {
102 /* device not found */
103 return DSERR_INVALIDPARAM;
104 }
105
106 /* copy device guid */
107 RtlMoveMemory(pGuidDest, &Filter->DeviceGuid[0], sizeof(GUID));
108 return DS_OK;
109 }
110
111 if (!FindDeviceByGuid(pGuidSrc, &Filter))
112 {
113 /* unknown guid */
114 return DSERR_INVALIDPARAM;
115 }
116
117 /* done */
118 return DS_OK;
119 }
120
121
122 HRESULT
123 WINAPI
124 DllGetClassObject(
125 REFCLSID rclsid,
126 REFIID riid,
127 LPVOID* ppv
128 )
129 {
130 LPOLESTR pStr, pStr2;
131 UINT i;
132 HRESULT hres = E_OUTOFMEMORY;
133 IClassFactory * pcf = NULL;
134
135 if (!ppv)
136 return E_INVALIDARG;
137
138 *ppv = NULL;
139
140 for (i = 0; InterfaceTable[i].riid; i++)
141 {
142 if (IsEqualIID(InterfaceTable[i].riid, rclsid))
143 {
144 pcf = IClassFactory_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
145 break;
146 }
147 }
148
149 if (!pcf)
150 {
151 StringFromIID(rclsid, &pStr);
152 StringFromIID(riid, &pStr2);
153 DPRINT("No Class Available for %ws IID %ws\n", pStr, pStr2);
154 CoTaskMemFree(pStr);
155 CoTaskMemFree(pStr2);
156 ASSERT(0);
157 return CLASS_E_CLASSNOTAVAILABLE;
158 }
159
160 hres = IClassFactory_QueryInterface(pcf, riid, ppv);
161 IClassFactory_Release(pcf);
162
163 return hres;
164 }
165
166
167
168 BOOL
169 WINAPI
170 DllMain(
171 HINSTANCE hInstDLL,
172 DWORD fdwReason,
173 LPVOID lpvReserved)
174 {
175 switch (fdwReason)
176 {
177 case DLL_PROCESS_ATTACH:
178 dsound_hInstance = hInstDLL;
179 #if 1
180 DPRINT("NumDevs %u\n", waveOutGetNumDevs());
181 if (EnumAudioDeviceInterfaces(&RootInfo) != S_OK)
182 {
183 DPRINT("EnumAudioDeviceInterfaces failed\n");
184 RootInfo = NULL;
185 }
186 DPRINT1("EnumAudioDeviceInterfaces %p %u\n", RootInfo, waveOutGetNumDevs());
187 #endif
188 DisableThreadLibraryCalls(dsound_hInstance);
189 break;
190 default:
191 break;
192 }
193
194 return TRUE;
195 }
196