- Update to r53061
[reactos.git] / base / applications / dxdiag / sound.c
1 /*
2 * PROJECT: ReactX Diagnosis Application
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/dxdiag/sound.c
5 * PURPOSE: ReactX diagnosis sound page
6 * COPYRIGHT: Copyright 2008 Johannes Anderwald
7 *
8 */
9
10 #include "precomp.h"
11 #include <dsound.h>
12
13 #if 0
14 BOOL
15 GetCatFileFromDriverPath(LPWSTR szFileName, LPWSTR szCatFileName)
16 {
17 GUID VerifyGuid = DRIVER_ACTION_VERIFY;
18 HANDLE hFile;
19 DWORD dwHash;
20 BYTE bHash[100];
21 HCATINFO hCatInfo;
22 HCATADMIN hActAdmin;
23 BOOL bRet = FALSE;
24 CATALOG_INFO CatInfo;
25
26 /* attempt to open file */
27 hFile = CreateFileW(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
28 if (hFile == INVALID_HANDLE_VALUE)
29 return FALSE;
30
31 /* calculate hash from file handle */
32 dwHash = sizeof(bHash);
33 if (!CryptCATAdminCalcHashFromFileHandle(hFile, &dwHash, bHash, 0))
34 {
35 CloseHandle(hFile);
36 return FALSE;
37 }
38
39 /* try open the CAT admin */
40 if (!CryptCATAdminAcquireContext(&hActAdmin, &VerifyGuid, 0))
41 {
42 CloseHandle(hFile);
43 return FALSE;
44 }
45
46 /* search catalog to find for catalog containing this hash */
47 hCatInfo = CryptCATAdminEnumCatalogFromHash(hActAdmin, bHash, dwHash, 0, NULL);
48 if (hCatInfo != NULL)
49 {
50 /* theres a catalog get the filename */
51 bRet = CryptCATCatalogInfoFromContext(hCatInfo, &CatInfo, 0);
52 if (bRet)
53 wcscpy(szCatFileName, CatInfo.wszCatalogFile);
54 CryptCATAdminReleaseCatalogContext(hActAdmin, hCatInfo, 0);
55 }
56
57 /* perform cleanup */
58 CloseHandle(hFile);
59 CryptCATAdminReleaseContext(hActAdmin, 0);
60 return bRet;
61 }
62
63 BOOL
64 IsDriverWHQL(LPWSTR szFileName)
65 {
66 WCHAR szCatFile[MAX_PATH];
67 HANDLE hCat;
68 BOOL bRet = FALSE;
69
70 /* get the driver's cat file */
71 if (!GetCatFileFromDriverPath(szFileName, szCatFile))
72 {
73 /* driver has no cat so its definately not WHQL signed */
74 return FALSE;
75 }
76
77 /* open the CAT file */
78 hCat = CryptCATOpen(szCatFile, CRYPTCAT_OPEN_EXISTING, 0, 0, 0);
79 if (hCat == INVALID_HANDLE_VALUE)
80 {
81 /* couldnt open cat */
82 return FALSE;
83 }
84
85 /* FIXME
86 * build certificate chain with CertGetCertificateChain
87 * verify certificate chain (WinVerifyTrust)
88 * retrieve signer (WTHelperGetProvSignerFromChain)
89 */
90
91
92 /* close CAT file */
93 CryptCATClose(hCat);
94 return bRet;
95 }
96 #endif
97
98 static
99 void
100 SetDeviceDetails(HWND hwndDlg, LPCGUID classGUID, LPCWSTR lpcstrDescription)
101 {
102 HDEVINFO hInfo;
103 DWORD dwIndex = 0;
104 SP_DEVINFO_DATA InfoData;
105 WCHAR szText[30];
106 HWND hDlgCtrls[3];
107 WAVEOUTCAPSW waveOut;
108 UINT numDev;
109 MMRESULT errCode;
110
111
112 /* enumerate waveout devices */
113 numDev = waveOutGetNumDevs();
114 if (numDev)
115 {
116 do
117 {
118 ZeroMemory(&waveOut, sizeof(waveOut));
119 errCode = waveOutGetDevCapsW(dwIndex++, &waveOut, sizeof(waveOut));
120 if (!wcsncmp(lpcstrDescription, waveOut.szPname, min(MAXPNAMELEN, wcslen(waveOut.szPname))))
121 {
122 /* set the product id */
123 SetDlgItemInt(hwndDlg, IDC_STATIC_DSOUND_PRODUCTID, waveOut.wPid, FALSE);
124 /* set the vendor id */
125 SetDlgItemInt(hwndDlg, IDC_STATIC_DSOUND_VENDORID, waveOut.wMid, FALSE);
126 /* check if its a wdm audio driver */
127 if (waveOut.wPid == MM_MSFT_WDMAUDIO_WAVEOUT)
128 SendDlgItemMessageW(hwndDlg, IDC_STATIC_DSOUND_TYPE, WM_SETTEXT, 0, (LPARAM)L"WDM");
129
130 /* check if device is default device */
131 szText[0] = L'\0';
132 if (dwIndex - 1 == 0) /* FIXME assume default playback device is device 0 */
133 LoadStringW(hInst, IDS_OPTION_YES, szText, sizeof(szText)/sizeof(WCHAR));
134 else
135 LoadStringW(hInst, IDS_OPTION_NO, szText, sizeof(szText)/sizeof(WCHAR));
136
137 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
138 /* set default device info */
139 SendDlgItemMessageW(hwndDlg, IDC_STATIC_DSOUND_STANDARD, WM_SETTEXT, 0, (LPARAM)szText);
140 break;
141 }
142 }while(errCode == MMSYSERR_NOERROR && dwIndex < numDev);
143 }
144
145 dwIndex = 0;
146 /* create the setup list */
147 hInfo = SetupDiGetClassDevsW(classGUID, NULL, NULL, DIGCF_PRESENT|DIGCF_PROFILE);
148 if (hInfo == INVALID_HANDLE_VALUE)
149 return;
150
151 do
152 {
153 ZeroMemory(&InfoData, sizeof(InfoData));
154 InfoData.cbSize = sizeof(InfoData);
155
156 if (SetupDiEnumDeviceInfo(hInfo, dwIndex, &InfoData))
157 {
158 /* set device name */
159 if (SetupDiGetDeviceInstanceId(hInfo, &InfoData, szText, sizeof(szText)/sizeof(WCHAR), NULL))
160 SendDlgItemMessageW(hwndDlg, IDC_STATIC_DSOUND_DEVICEID, WM_SETTEXT, 0, (LPARAM)szText);
161
162 /* set the manufacturer name */
163 if (SetupDiGetDeviceRegistryPropertyW(hInfo, &InfoData, SPDRP_MFG, NULL, (PBYTE)szText, sizeof(szText), NULL))
164 SendDlgItemMessageW(hwndDlg, IDC_STATIC_ADAPTER_PROVIDER, WM_SETTEXT, 0, (LPARAM)szText);
165
166 /* FIXME
167 * we currently enumerate only the first adapter
168 */
169 hDlgCtrls[0] = GetDlgItem(hwndDlg, IDC_STATIC_DSOUND_DRIVER);
170 hDlgCtrls[1] = GetDlgItem(hwndDlg, IDC_STATIC_DSOUND_VERSION);
171 hDlgCtrls[2] = GetDlgItem(hwndDlg, IDC_STATIC_DSOUND_DATE);
172 EnumerateDrivers(hDlgCtrls, hInfo, &InfoData);
173 break;
174 }
175
176 if (GetLastError() == ERROR_NO_MORE_ITEMS)
177 break;
178
179 dwIndex++;
180 }while(TRUE);
181
182 /* destroy the setup list */
183 SetupDiDestroyDeviceInfoList(hInfo);
184 }
185
186
187
188 BOOL CALLBACK DSEnumCallback(LPGUID lpGuid, LPCWSTR lpcstrDescription, LPCWSTR lpcstrModule, LPVOID lpContext)
189 {
190 PDXDIAG_CONTEXT pContext = (PDXDIAG_CONTEXT)lpContext;
191 HWND * hDlgs;
192 HWND hwndDlg;
193 WCHAR szSound[20];
194 WCHAR szText[30];
195 IDirectSound8 *pObj;
196 HRESULT hResult;
197 DWORD dwCertified;
198
199 if (!lpGuid)
200 return TRUE;
201
202 if (pContext->NumSoundAdapter)
203 hDlgs = HeapReAlloc(GetProcessHeap(), 0, pContext->hSoundWnd, (pContext->NumSoundAdapter + 1) * sizeof(HWND));
204 else
205 hDlgs = HeapAlloc(GetProcessHeap(), 0, (pContext->NumSoundAdapter + 1) * sizeof(HWND));
206
207 if (!hDlgs)
208 return FALSE;
209
210 pContext->hSoundWnd = hDlgs;
211 hwndDlg = CreateDialogParamW(hInst, MAKEINTRESOURCEW(IDD_SOUND_DIALOG), pContext->hMainDialog, SoundPageWndProc, (LPARAM)pContext);
212 if (!hwndDlg)
213 return FALSE;
214
215 hResult = DirectSoundCreate8(lpGuid, (LPDIRECTSOUND8*)&pObj, NULL);
216 if (hResult == DS_OK)
217 {
218 szText[0] = L'\0';
219 if (IDirectSound8_VerifyCertification(pObj, &dwCertified) == DS_OK)
220 {
221 if (dwCertified == DS_CERTIFIED)
222 LoadStringW(hInst, IDS_OPTION_YES, szText, sizeof(szText)/sizeof(WCHAR));
223 else if (dwCertified == DS_UNCERTIFIED)
224 LoadStringW(hInst, IDS_OPTION_NO, szText, sizeof(szText)/sizeof(WCHAR));
225 }
226 else
227 {
228 LoadStringW(hInst, IDS_OPTION_NO, szText, sizeof(szText)/sizeof(WCHAR));
229 }
230 szText[(sizeof(szText)/sizeof(WCHAR))-1] = L'\0';
231 SendDlgItemMessageW(hwndDlg, IDC_STATIC_DSOUND_LOGO, WM_SETTEXT, 0, (LPARAM)szText);
232 IDirectSound8_Release(pObj);
233 }
234
235 /* set device name */
236 SendDlgItemMessageW(hwndDlg, IDC_STATIC_DSOUND_NAME, WM_SETTEXT, 0, (LPARAM)lpcstrDescription);
237
238 /* set range for slider */
239 SendDlgItemMessageW(hwndDlg, IDC_SLIDER_DSOUND, TBM_SETRANGE, TRUE, MAKELONG(0, 3));
240
241 /* FIXME set correct position */
242 SendDlgItemMessageW(hwndDlg, IDC_SLIDER_DSOUND, TBM_SETSEL, FALSE, 0);
243
244 /* set further device details */
245 SetDeviceDetails(hwndDlg, &GUID_DEVCLASS_MEDIA, lpcstrDescription);
246
247
248
249 /* load sound resource string */
250 szSound[0] = L'\0';
251 LoadStringW(hInst, IDS_SOUND_DIALOG, szSound, sizeof(szSound)/sizeof(WCHAR));
252 szSound[(sizeof(szSound)/sizeof(WCHAR))-1] = L'\0';
253 /* output the device id */
254 wsprintfW (szText, L"%s %u", szSound, pContext->NumSoundAdapter + 1);
255 /* insert it into general tab */
256 InsertTabCtrlItem(pContext->hTabCtrl, pContext->NumDisplayAdapter + pContext->NumSoundAdapter + 1, szText);
257 /* store dialog window */
258 hDlgs[pContext->NumSoundAdapter] = hwndDlg;
259 pContext->NumSoundAdapter++;
260 return TRUE;
261 }
262
263
264 void InitializeDirectSoundPage(PDXDIAG_CONTEXT pContext)
265 {
266 HRESULT hResult;
267
268
269 /* create DSound object */
270
271 // if (hResult != DS_OK)
272 // return;
273 hResult = DirectSoundEnumerateW(DSEnumCallback, pContext);
274
275 /* release the DSound object */
276 // pObj->lpVtbl->Release(pObj);
277 (void)hResult;
278 }
279
280
281 INT_PTR CALLBACK
282 SoundPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
283 {
284 switch (message)
285 {
286 case WM_INITDIALOG:
287 {
288 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
289 return TRUE;
290 }
291 case WM_COMMAND:
292 {
293 if (LOWORD(wParam) == IDC_BUTTON_TESTDSOUND)
294 {
295 return FALSE;
296 }
297 break;
298 }
299 }
300
301 return FALSE;
302 }