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 (johannes.anderwald@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 LPOLESTR pStr, pStr2; 130 UINT i; 131 HRESULT hres = E_OUTOFMEMORY; 132 IClassFactory * pcf = NULL; 133 134 if (!ppv) 135 return E_INVALIDARG; 136 137 *ppv = NULL; 138 139 for (i = 0; InterfaceTable[i].riid; i++) 140 { 141 if (IsEqualIID(InterfaceTable[i].riid, rclsid)) 142 { 143 pcf = IClassFactory_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL); 144 break; 145 } 146 } 147 148 if (!pcf) 149 { 150 StringFromIID(rclsid, &pStr); 151 StringFromIID(riid, &pStr2); 152 DPRINT("No Class Available for %ws IID %ws\n", pStr, pStr2); 153 CoTaskMemFree(pStr); 154 CoTaskMemFree(pStr2); 155 //ASSERT(0); 156 return CLASS_E_CLASSNOTAVAILABLE; 157 } 158 159 hres = IClassFactory_QueryInterface(pcf, riid, ppv); 160 IClassFactory_Release(pcf); 161 162 return hres; 163 } 164 165 166 167 BOOL 168 WINAPI 169 DllMain( 170 HINSTANCE hInstDLL, 171 DWORD fdwReason, 172 LPVOID lpvReserved) 173 { 174 switch (fdwReason) 175 { 176 case DLL_PROCESS_ATTACH: 177 dsound_hInstance = hInstDLL; 178 #if 1 179 DPRINT("NumDevs %u\n", waveOutGetNumDevs()); 180 if (EnumAudioDeviceInterfaces(&RootInfo) != S_OK) 181 { 182 DPRINT("EnumAudioDeviceInterfaces failed\n"); 183 RootInfo = NULL; 184 } 185 DPRINT1("EnumAudioDeviceInterfaces %p %u\n", RootInfo, waveOutGetNumDevs()); 186 #endif 187 DisableThreadLibraryCalls(dsound_hInstance); 188 break; 189 default: 190 break; 191 } 192 193 return TRUE; 194 } 195 196