Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

354 lines
10 KiB

  1. //--------------------------------------------------------------------------;
  2. //
  3. // File: advaudio.cpp
  4. //
  5. // Copyright (c) 1997 Microsoft Corporation. All rights reserved
  6. //
  7. //--------------------------------------------------------------------------;
  8. #include "mmcpl.h"
  9. #include <windowsx.h>
  10. #ifdef DEBUG
  11. #undef DEBUG
  12. #include <mmsystem.h>
  13. #define DEBUG
  14. #else
  15. #include <mmsystem.h>
  16. #endif
  17. #include <commctrl.h>
  18. #include <prsht.h>
  19. #include <regstr.h>
  20. #include "utils.h"
  21. #include "medhelp.h"
  22. #include "gfxui.h"
  23. #include <dsound.h>
  24. #include "advaudio.h"
  25. #include "speakers.h"
  26. #include "perfpage.h"
  27. #include "dslevel.h"
  28. #include "drivers.h"
  29. ////////////
  30. // Globals
  31. ////////////
  32. AUDDATA gAudData;
  33. HINSTANCE ghInst;
  34. const TCHAR * gszHelpFile;
  35. ////////////
  36. // Functions
  37. ////////////
  38. extern INT_PTR CALLBACK SoundEffectsDlg(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  39. STDAPI_(void) ToggleApplyButton(HWND hWnd)
  40. {
  41. BOOL fChanged = FALSE;
  42. HWND hwndSheet;
  43. if (memcmp(&gAudData.stored,&gAudData.current,sizeof(CPLDATA)))
  44. {
  45. fChanged = TRUE;
  46. }
  47. hwndSheet = GetParent(hWnd);
  48. if (fChanged)
  49. {
  50. PropSheet_Changed(hwndSheet,hWnd);
  51. }
  52. else
  53. {
  54. PropSheet_UnChanged(hwndSheet,hWnd);
  55. }
  56. }
  57. void VerifyRanges(LPCPLDATA pData)
  58. {
  59. pData->dwHWLevel = min(pData->dwHWLevel,MAX_HW_LEVEL);
  60. pData->dwSRCLevel = min(pData->dwSRCLevel,MAX_SRC_LEVEL);
  61. pData->dwSpeakerType = min(pData->dwSpeakerType,MAX_SPEAKER_TYPE);
  62. }
  63. void GetCurrentSettings(LPAUDDATA pAD, DWORD dwWaveId, LPTSTR szDeviceName, BOOL fRecord)
  64. {
  65. HRESULT hr = E_FAIL;
  66. if (pAD)
  67. {
  68. CPLDATA cplData = { DEFAULT_HW_LEVEL, DEFAULT_SRC_LEVEL, SPEAKERS_DEFAULT_CONFIG, SPEAKERS_DEFAULT_TYPE };
  69. memset(pAD,0,sizeof(AUDDATA));
  70. pAD->dwDefaultHWLevel = MAX_HW_LEVEL;
  71. pAD->fRecord = fRecord;
  72. hr = DSGetGuidFromName(szDeviceName, fRecord, &pAD->devGuid);
  73. if (SUCCEEDED(hr))
  74. {
  75. hr = DSGetCplValues(pAD->devGuid, fRecord, &cplData);
  76. if (SUCCEEDED(hr))
  77. {
  78. VerifyRanges(&cplData);
  79. VerifySpeakerConfig(cplData.dwSpeakerConfig,&cplData.dwSpeakerType);
  80. }
  81. }
  82. pAD->waveId = dwWaveId;
  83. pAD->stored = cplData;
  84. pAD->current = cplData;
  85. pAD->fValid = SUCCEEDED(hr);
  86. }
  87. }
  88. STDAPI_(void) ApplyCurrentSettings(LPAUDDATA pAD)
  89. {
  90. HRESULT hr = S_OK;
  91. if (pAD && pAD->fValid) // Only apply changes if there are changes to be applied
  92. {
  93. if (memcmp(&pAD->stored,&pAD->current,sizeof(CPLDATA)))
  94. {
  95. hr = DSSetCplValues(pAD->devGuid, pAD->fRecord, &pAD->current);
  96. if (SUCCEEDED(hr))
  97. {
  98. pAD->stored = pAD->current;
  99. }
  100. }
  101. }
  102. }
  103. typedef BOOL (WINAPI* UPDATEDDDLG)(HWND,HINSTANCE,const TCHAR *,LPTSTR,BOOL);
  104. STDAPI_(BOOL) RunUpgradedDialog(HWND hwnd, HINSTANCE hInst, const TCHAR *szHelpFile, LPTSTR szDeviceName, BOOL fRecord)
  105. {
  106. BOOL fUsedUpgradedDLG = FALSE;
  107. TCHAR path[_MAX_PATH];
  108. UPDATEDDDLG UpdatedDialog;
  109. HMODULE hModule;
  110. GetSystemDirectory(path, sizeof(path)/sizeof(TCHAR));
  111. lstrcat(path, TEXT("\\DSNDDLG.DLL") );
  112. hModule = LoadLibrary(path);
  113. if (hModule)
  114. {
  115. UpdatedDialog = (UPDATEDDDLG) GetProcAddress( hModule,"DSAdvancedAudio");
  116. if (UpdatedDialog)
  117. {
  118. fUsedUpgradedDLG = UpdatedDialog(hwnd,hInst,szHelpFile,szDeviceName,fRecord);
  119. }
  120. FreeLibrary( hModule );
  121. }
  122. return fUsedUpgradedDLG;
  123. }
  124. HRESULT CheckDSAccelerationPriv(GUID guidDevice, BOOL fRecord, HRESULT *phrGet)
  125. {
  126. HRESULT hr;
  127. DWORD dwHWLevel = gAudData.dwDefaultHWLevel;
  128. hr = DSGetAcceleration(guidDevice, fRecord, &dwHWLevel);
  129. if (phrGet)
  130. {
  131. *phrGet = hr;
  132. }
  133. if (SUCCEEDED(hr))
  134. {
  135. hr = DSSetAcceleration(guidDevice, fRecord, dwHWLevel);
  136. } //end if Get is OK
  137. return (hr);
  138. }
  139. HRESULT CheckDSSrcQualityPriv(GUID guidDevice, BOOL fRecord, HRESULT *phrGet)
  140. {
  141. HRESULT hr;
  142. DWORD dwSRCLevel = DEFAULT_SRC_LEVEL;
  143. hr = DSGetSrcQuality(guidDevice, fRecord, &dwSRCLevel);
  144. if (phrGet)
  145. {
  146. *phrGet = hr;
  147. }
  148. if (SUCCEEDED(hr))
  149. {
  150. hr = DSSetSrcQuality(guidDevice, fRecord, dwSRCLevel);
  151. } //end if Get is OK
  152. return (hr);
  153. }
  154. HRESULT CheckDSSpeakerConfigPriv(GUID guidDevice, BOOL fRecord, HRESULT *phrGet)
  155. {
  156. HRESULT hr;
  157. DWORD dwSpeakerConfig = SPEAKERS_DEFAULT_CONFIG;
  158. DWORD dwSpeakerType = SPEAKERS_DEFAULT_TYPE;
  159. hr = DSGetSpeakerConfigType(guidDevice, fRecord, &dwSpeakerConfig, &dwSpeakerType);
  160. if (phrGet)
  161. {
  162. *phrGet = hr;
  163. }
  164. if (SUCCEEDED(hr))
  165. {
  166. hr = DSSetSpeakerConfigType(guidDevice, fRecord, dwSpeakerConfig, dwSpeakerType);
  167. } //end if Get is OK
  168. return (hr);
  169. }
  170. STDAPI_(void) AdvancedAudio(HWND hwnd, HINSTANCE hInst, const TCHAR *szHelpFile,
  171. DWORD dwWaveId, LPTSTR szDeviceName, BOOL fRecord)
  172. {
  173. PROPSHEETHEADER psh;
  174. PROPSHEETPAGE psp[3];
  175. int page;
  176. TCHAR str[255];
  177. HMODULE hModDirectSound = NULL;
  178. HRESULT hrAccelGet = E_FAIL;
  179. HRESULT hrQualityGet = E_FAIL;
  180. HRESULT hrSpeakerConfigGet = E_FAIL;
  181. bool fDisplayGFXTab = false;
  182. if (!RunUpgradedDialog(hwnd,hInst,szHelpFile,szDeviceName,fRecord))
  183. {
  184. //load DirectSound
  185. hModDirectSound = LoadLibrary(TEXT("dsound.dll"));
  186. if (hModDirectSound)
  187. {
  188. // Initialize gAudData
  189. memset(&gAudData,0,sizeof(AUDDATA));
  190. gAudData.dwDefaultHWLevel = MAX_HW_LEVEL;
  191. gAudData.fRecord = fRecord;
  192. // If not a Capture device, check if we can read any of the DirectSound device settings
  193. if (!fRecord && SUCCEEDED(DSGetGuidFromName(szDeviceName, fRecord, &gAudData.devGuid)))
  194. {
  195. CheckDSAccelerationPriv(gAudData.devGuid, fRecord, &hrAccelGet);
  196. CheckDSSrcQualityPriv(gAudData.devGuid, fRecord, &hrQualityGet);
  197. CheckDSSpeakerConfigPriv(gAudData.devGuid, fRecord, &hrSpeakerConfigGet);
  198. }
  199. // Check if we should show the GFX tab
  200. UINT uMixId;
  201. if( !fRecord )
  202. {
  203. if (!mixerGetID(HMIXEROBJ_INDEX(dwWaveId), &uMixId, MIXER_OBJECTF_WAVEOUT) &&
  204. GFXUI_CheckDevice(uMixId, GFXTYPE_RENDER))
  205. {
  206. fDisplayGFXTab = true;
  207. }
  208. }
  209. else
  210. {
  211. if (!mixerGetID(HMIXEROBJ_INDEX(dwWaveId), &uMixId, MIXER_OBJECTF_WAVEIN) &&
  212. GFXUI_CheckDevice(uMixId, GFXTYPE_CAPTURE))
  213. {
  214. fDisplayGFXTab = true;
  215. }
  216. }
  217. // If there's anything to display
  218. if (fDisplayGFXTab || SUCCEEDED(hrAccelGet) || SUCCEEDED(hrQualityGet) ||
  219. SUCCEEDED(hrSpeakerConfigGet))
  220. {
  221. ghInst = hInst;
  222. gszHelpFile = szHelpFile;
  223. // Get the current settings
  224. GetCurrentSettings(&gAudData, dwWaveId, szDeviceName, fRecord);
  225. // Now, add the property sheets
  226. page = 0;
  227. // Only add speaker configuration if we're not in record mode
  228. if (!fRecord)
  229. {
  230. if (SUCCEEDED(hrSpeakerConfigGet))
  231. {
  232. memset(&psp[page],0,sizeof(PROPSHEETPAGE));
  233. psp[page].dwSize = sizeof(PROPSHEETPAGE);
  234. psp[page].dwFlags = PSP_DEFAULT;
  235. psp[page].hInstance = ghInst;
  236. psp[page].pszTemplate = MAKEINTRESOURCE(IDD_SPEAKERS);
  237. psp[page].pfnDlgProc = SpeakerHandler;
  238. page++;
  239. }
  240. }
  241. // Always check to add performance sheet
  242. if (SUCCEEDED(hrAccelGet) || SUCCEEDED(hrQualityGet))
  243. {
  244. memset(&psp[page],0,sizeof(PROPSHEETPAGE));
  245. psp[page].dwSize = sizeof(PROPSHEETPAGE);
  246. psp[page].dwFlags = PSP_DEFAULT;
  247. psp[page].hInstance = ghInst;
  248. psp[page].pszTemplate = MAKEINTRESOURCE(IDD_PLAYBACKPERF);
  249. psp[page].pfnDlgProc = PerformanceHandler;
  250. page++;
  251. }
  252. // Always check to add GFX sheet
  253. if (fDisplayGFXTab)
  254. {
  255. memset(&psp[page],0,sizeof(PROPSHEETPAGE));
  256. psp[page].dwSize = sizeof(PROPSHEETPAGE);
  257. psp[page].dwFlags = PSP_DEFAULT;
  258. psp[page].hInstance = ghInst;
  259. psp[page].pszTemplate = MAKEINTRESOURCE(EFFECTSDLG);
  260. psp[page].pfnDlgProc = SoundEffectsDlg;
  261. page++;
  262. }
  263. LoadString( hInst, IDS_ADVAUDIOTITLE, str, sizeof( str )/sizeof(TCHAR) );
  264. memset(&psh,0,sizeof(psh));
  265. psh.dwSize = sizeof(psh);
  266. psh.dwFlags = PSH_DEFAULT | PSH_PROPSHEETPAGE;
  267. psh.hwndParent = hwnd;
  268. psh.hInstance = ghInst;
  269. psh.pszCaption = str;
  270. psh.nPages = page;
  271. psh.nStartPage = 0;
  272. psh.ppsp = psp;
  273. PropertySheet(&psh);
  274. }
  275. else
  276. {
  277. TCHAR szCaption[MAX_PATH];
  278. TCHAR szMessage[MAX_PATH];
  279. bool fAccessDenied;
  280. fAccessDenied = (hrAccelGet == DSERR_ACCESSDENIED) || (hrQualityGet == DSERR_ACCESSDENIED) ||
  281. (hrSpeakerConfigGet == DSERR_ACCESSDENIED);
  282. LoadString(hInst,IDS_ERROR,szCaption,sizeof(szCaption)/sizeof(TCHAR));
  283. LoadString(hInst,fAccessDenied ? IDS_ERROR_DSPRIVS : IDS_ERROR_DSGENERAL,szMessage,sizeof(szMessage)/sizeof(TCHAR));
  284. MessageBox(hwnd,szMessage,szCaption,MB_OK|MB_ICONERROR);
  285. }
  286. FreeLibrary(hModDirectSound);
  287. } //end if DS loaded
  288. }
  289. }