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.

637 lines
17 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 1995,1996 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dsprvobj.c
  6. * Content: DirectSound Private Object wrapper functions.
  7. * History:
  8. * Date By Reason
  9. * ==== == ======
  10. * 02/12/98 dereks Created.
  11. * 12/16/99 rodtoll Added support for new funcs from dsound team on private
  12. * interface for getting process dsound object list
  13. * 01/08/2001 rodtoll WINBUG #256541 Pseudo: Loss of functionality: Voice Wizrd can't be launched.
  14. * 02/28/2002 rodtoll WINBUG #550105 SECURITY: DPVOICE: Dead code
  15. * - Remove unused calls.
  16. * rodtoll Fix for regression caused by TCHAR conversion (Post DirectX 8.1 work)
  17. * - Source was updated to retrieve device information from DirectSound w/Unicode
  18. * but routines which wanted the information needed Unicode.
  19. *
  20. ***************************************************************************/
  21. #include "dxvutilspch.h"
  22. #define MAX_OBJECTS 20
  23. /***************************************************************************
  24. *
  25. * DirectSoundPrivateCreate
  26. *
  27. * Description:
  28. * Creates and initializes a DirectSoundPrivate object.
  29. *
  30. * Arguments:
  31. * LPKSPROPERTYSET * [out]: receives IKsPropertySet interface to the
  32. * object.
  33. *
  34. * Returns:
  35. * HRESULT: DirectSound/COM result code.
  36. *
  37. ***************************************************************************/
  38. HRESULT DirectSoundPrivateCreate
  39. (
  40. LPKSPROPERTYSET * ppKsPropertySet
  41. )
  42. {
  43. typedef HRESULT (STDAPICALLTYPE *LPFNDLLGETCLASSOBJECT)(REFCLSID, REFIID, LPVOID *);
  44. HINSTANCE hLibDsound = NULL;
  45. LPFNGETCLASSOBJECT pfnDllGetClassObject = NULL;
  46. LPCLASSFACTORY pClassFactory = NULL;
  47. LPKSPROPERTYSET pKsPropertySet = NULL;
  48. HRESULT hr = DS_OK;
  49. // Get dsound.dll's instance handle. The dll must already be loaded at this
  50. // point.
  51. hLibDsound =
  52. GetModuleHandle
  53. (
  54. TEXT("dsound.dll")
  55. );
  56. if(!hLibDsound)
  57. {
  58. hr = DSERR_GENERIC;
  59. }
  60. // Find DllGetClassObject
  61. if(SUCCEEDED(hr))
  62. {
  63. pfnDllGetClassObject = (LPFNDLLGETCLASSOBJECT)
  64. GetProcAddress
  65. (
  66. hLibDsound,
  67. "DllGetClassObject"
  68. );
  69. if(!pfnDllGetClassObject)
  70. {
  71. hr = DSERR_GENERIC;
  72. }
  73. }
  74. // Create a class factory object
  75. if(SUCCEEDED(hr))
  76. {
  77. hr =
  78. pfnDllGetClassObject
  79. (
  80. CLSID_DirectSoundPrivate,
  81. IID_IClassFactory,
  82. (LPVOID *)&pClassFactory
  83. );
  84. }
  85. // Create the DirectSoundPrivate object and query for an IKsPropertySet
  86. // interface
  87. if(SUCCEEDED(hr))
  88. {
  89. hr =
  90. pClassFactory->CreateInstance
  91. (
  92. NULL,
  93. IID_IKsPropertySet,
  94. (LPVOID *)&pKsPropertySet
  95. );
  96. }
  97. // Release the class factory
  98. if(pClassFactory)
  99. {
  100. pClassFactory->Release();
  101. }
  102. // Success
  103. if(SUCCEEDED(hr))
  104. {
  105. *ppKsPropertySet = pKsPropertySet;
  106. }
  107. return hr;
  108. }
  109. /***************************************************************************
  110. *
  111. * PrvGetMixerSrcQuality
  112. *
  113. * Description:
  114. * Gets the mixer SRC quality for a given DirectSound device.
  115. *
  116. * Arguments:
  117. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  118. * DirectSoundPrivate object.
  119. * REFGUID [in]: DirectSound device GUID.
  120. * DIRECTSOUNDMIXER_SRCQUALITY * [out]: receives mixer SRC quality.
  121. *
  122. * Returns:
  123. * HRESULT: DirectSound/COM result code.
  124. *
  125. ***************************************************************************/
  126. HRESULT PrvGetMixerSrcQuality
  127. (
  128. LPKSPROPERTYSET pKsPropertySet,
  129. REFGUID guidDeviceId,
  130. DIRECTSOUNDMIXER_SRCQUALITY * pSrcQuality
  131. )
  132. {
  133. DSPROPERTY_DIRECTSOUNDMIXER_SRCQUALITY_DATA Data;
  134. HRESULT hr;
  135. Data.DeviceId = guidDeviceId;
  136. hr =
  137. pKsPropertySet->Get
  138. (
  139. DSPROPSETID_DirectSoundMixer,
  140. DSPROPERTY_DIRECTSOUNDMIXER_SRCQUALITY,
  141. NULL,
  142. 0,
  143. &Data,
  144. sizeof(Data),
  145. NULL
  146. );
  147. if(SUCCEEDED(hr))
  148. {
  149. *pSrcQuality = Data.Quality;
  150. }
  151. return hr;
  152. }
  153. /***************************************************************************
  154. *
  155. * PrvSetMixerSrcQuality
  156. *
  157. * Description:
  158. * Sets the mixer SRC quality for a given DirectSound device.
  159. *
  160. * Arguments:
  161. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  162. * DirectSoundPrivate object.
  163. * REFGUID [in]: DirectSound device GUID.
  164. * DIRECTSOUNDMIXER_SRCQUALITY [in]: mixer SRC quality.
  165. *
  166. * Returns:
  167. * HRESULT: DirectSound/COM result code.
  168. *
  169. ***************************************************************************/
  170. HRESULT PrvSetMixerSrcQuality
  171. (
  172. LPKSPROPERTYSET pKsPropertySet,
  173. REFGUID guidDeviceId,
  174. DIRECTSOUNDMIXER_SRCQUALITY SrcQuality
  175. )
  176. {
  177. DSPROPERTY_DIRECTSOUNDMIXER_SRCQUALITY_DATA Data;
  178. HRESULT hr;
  179. Data.DeviceId = guidDeviceId;
  180. Data.Quality = SrcQuality;
  181. hr =
  182. pKsPropertySet->Set
  183. (
  184. DSPROPSETID_DirectSoundMixer,
  185. DSPROPERTY_DIRECTSOUNDMIXER_SRCQUALITY,
  186. NULL,
  187. 0,
  188. &Data,
  189. sizeof(Data)
  190. );
  191. return hr;
  192. }
  193. /***************************************************************************
  194. *
  195. * PrvGetWaveDeviceMapping
  196. *
  197. * Description:
  198. * Gets the DirectSound device id (if any) for a given waveIn or
  199. * waveOut device description. This is the description given by
  200. * waveIn/OutGetDevCaps (szPname).
  201. *
  202. * Arguments:
  203. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  204. * DirectSoundPrivate object.
  205. * LPCSTR [in]: wave device description.
  206. * BOOL [in]: TRUE if the device description refers to a waveIn device.
  207. * LPGUID [out]: receives DirectSound device GUID.
  208. *
  209. * Returns:
  210. * HRESULT: DirectSound/COM result code.
  211. *
  212. ***************************************************************************/
  213. HRESULT PrvGetWaveDeviceMapping
  214. (
  215. LPKSPROPERTYSET pKsPropertySet,
  216. LPCSTR pszWaveDevice,
  217. BOOL fCapture,
  218. LPGUID pguidDeviceId
  219. )
  220. {
  221. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_DATA Data;
  222. HRESULT hr;
  223. Data.DeviceName = (LPTSTR)pszWaveDevice;
  224. Data.DataFlow = fCapture ? DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE : DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
  225. hr =
  226. pKsPropertySet->Get
  227. (
  228. DSPROPSETID_DirectSoundDevice,
  229. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING,
  230. NULL,
  231. 0,
  232. &Data,
  233. sizeof(Data),
  234. NULL
  235. );
  236. if(SUCCEEDED(hr))
  237. {
  238. *pguidDeviceId = Data.DeviceId;
  239. }
  240. return hr;
  241. }
  242. /***************************************************************************
  243. *
  244. * PrvGetWaveDeviceMappingW (Unicode)
  245. *
  246. * Description:
  247. * Gets the DirectSound device id (if any) for a given waveIn or
  248. * waveOut device description. This is the description given by
  249. * waveIn/OutGetDevCaps (szPname).
  250. *
  251. * Arguments:
  252. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  253. * DirectSoundPrivate object.
  254. * LPWCSTR [in]: wave device description.
  255. * BOOL [in]: TRUE if the device description refers to a waveIn device.
  256. * LPGUID [out]: receives DirectSound device GUID.
  257. *
  258. * Returns:
  259. * HRESULT: DirectSound/COM result code.
  260. *
  261. ***************************************************************************/
  262. HRESULT PrvGetWaveDeviceMappingW
  263. (
  264. LPKSPROPERTYSET pKsPropertySet,
  265. LPWSTR pwszWaveDevice,
  266. BOOL fCapture,
  267. LPGUID pguidDeviceId
  268. )
  269. {
  270. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W_DATA Data;
  271. HRESULT hr;
  272. Data.DeviceName = (LPWSTR)pwszWaveDevice;
  273. Data.DataFlow = fCapture ? DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE : DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
  274. hr =
  275. pKsPropertySet->Get
  276. (
  277. DSPROPSETID_DirectSoundDevice,
  278. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W,
  279. NULL,
  280. 0,
  281. &Data,
  282. sizeof(Data),
  283. NULL
  284. );
  285. if(SUCCEEDED(hr))
  286. {
  287. *pguidDeviceId = Data.DeviceId;
  288. }
  289. return hr;
  290. }
  291. /***************************************************************************
  292. *
  293. * PrvGetDeviceDescription
  294. *
  295. * Description:
  296. * Gets the extended description for a given DirectSound device.
  297. *
  298. * Arguments:
  299. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  300. * DirectSoundPrivate object.
  301. * REFGUID [in]: DirectSound device id.
  302. * PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA [out]: receives
  303. * description.
  304. *
  305. * Returns:
  306. * HRESULT: DirectSound/COM result code.
  307. *
  308. ***************************************************************************/
  309. HRESULT PrvGetDeviceDescription
  310. (
  311. LPKSPROPERTYSET pKsPropertySet,
  312. REFGUID guidDeviceId,
  313. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA *ppData
  314. )
  315. {
  316. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA pData = NULL;
  317. ULONG cbData;
  318. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA Basic;
  319. HRESULT hr;
  320. Basic.DeviceId = guidDeviceId;
  321. hr =
  322. pKsPropertySet->Get
  323. (
  324. DSPROPSETID_DirectSoundDevice,
  325. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A,
  326. NULL,
  327. 0,
  328. &Basic,
  329. sizeof(Basic),
  330. &cbData
  331. );
  332. if(SUCCEEDED(hr))
  333. {
  334. pData = (PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA)new BYTE [cbData];
  335. if(!pData)
  336. {
  337. hr = DSERR_OUTOFMEMORY;
  338. }
  339. }
  340. if(SUCCEEDED(hr))
  341. {
  342. pData->DeviceId = guidDeviceId;
  343. hr =
  344. pKsPropertySet->Get
  345. (
  346. DSPROPSETID_DirectSoundDevice,
  347. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A,
  348. NULL,
  349. 0,
  350. pData,
  351. cbData,
  352. NULL
  353. );
  354. }
  355. if(SUCCEEDED(hr))
  356. {
  357. *ppData = pData;
  358. }
  359. else if(pData)
  360. {
  361. delete[] pData;
  362. }
  363. return hr;
  364. }
  365. /***************************************************************************
  366. *
  367. * PrvGetDirectSoundObjects
  368. *
  369. * Description:
  370. * Gets the list of DirectSound objects in the current process
  371. *
  372. * Arguments:
  373. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  374. * DirectSoundPrivate object.
  375. * GUID guiDevice [in]: Device to get list for, or GUID_NULL for all.
  376. * DSPROPERTY_DIRECTSOUND_OBJECTS_DATA [in/out]: Pointer to place
  377. * newly allocated memory containing list.
  378. * Free the memory with a delete []
  379. *
  380. * Returns:
  381. * HRESULT: DirectSound/COM result code.
  382. *
  383. ***************************************************************************/
  384. HRESULT PrvGetDirectSoundObjects
  385. (
  386. LPKSPROPERTYSET pKsPropertySet,
  387. const GUID& guidDevice,
  388. DSPROPERTY_DIRECTSOUND_OBJECTS_DATA **pDSObjects
  389. )
  390. {
  391. HRESULT hr;
  392. ULONG ulSize;
  393. DSPROPERTY_DIRECTSOUND_OBJECTS_DATA* pDsObjList;
  394. DWORD dwNumObjects;
  395. *pDSObjects = NULL;
  396. pDsObjList = (DSPROPERTY_DIRECTSOUND_OBJECTS_DATA *) new DSPROPERTY_DIRECTSOUND_OBJECTS_DATA;
  397. if( pDsObjList == NULL )
  398. {
  399. return E_OUTOFMEMORY;
  400. }
  401. memset( pDsObjList, 0x00, sizeof( DSPROPERTY_DIRECTSOUND_OBJECTS_DATA ) );
  402. pDsObjList->DeviceId = guidDevice;
  403. hr =
  404. pKsPropertySet->Get
  405. (
  406. DSPROPSETID_DirectSound,
  407. DSPROPERTY_DIRECTSOUND_OBJECTS,
  408. NULL,
  409. 0,
  410. pDsObjList,
  411. sizeof( DSPROPERTY_DIRECTSOUND_OBJECTS_DATA ),
  412. NULL
  413. );
  414. dwNumObjects = pDsObjList->Count;
  415. if(SUCCEEDED(hr))
  416. {
  417. if( dwNumObjects > 0 )
  418. {
  419. delete pDsObjList;
  420. pDsObjList = NULL;
  421. ulSize = sizeof(DSPROPERTY_DIRECTSOUND_OBJECTS_DATA) + (dwNumObjects * sizeof(DIRECTSOUND_INFO));
  422. pDsObjList = (DSPROPERTY_DIRECTSOUND_OBJECTS_DATA *) new BYTE[ulSize];
  423. if( pDsObjList == NULL )
  424. {
  425. return E_OUTOFMEMORY;
  426. }
  427. memset( pDsObjList, 0x00, sizeof( DSPROPERTY_DIRECTSOUND_OBJECTS_DATA ) );
  428. pDsObjList->DeviceId = guidDevice;
  429. hr =
  430. pKsPropertySet->Get
  431. (
  432. DSPROPSETID_DirectSound,
  433. DSPROPERTY_DIRECTSOUND_OBJECTS,
  434. NULL,
  435. 0,
  436. pDsObjList,
  437. ulSize,
  438. NULL
  439. );
  440. if( FAILED( hr ) )
  441. {
  442. delete [] pDsObjList;
  443. return hr;
  444. }
  445. }
  446. *pDSObjects = pDsObjList;
  447. }
  448. else
  449. {
  450. delete pDsObjList;
  451. pDsObjList = NULL;
  452. *pDSObjects = NULL;
  453. }
  454. return hr;
  455. }
  456. /***************************************************************************
  457. *
  458. * PrvGetDirectSoundCaptureObjects
  459. *
  460. * Description:
  461. * Gets the list of DirectSoundCapture objects in the current process
  462. *
  463. * Arguments:
  464. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  465. * DirectSoundPrivate object.
  466. * GUID guiDevice [in]: Device to get list for, or GUID_NULL for all.
  467. * DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA [in/out]: Pointer to place
  468. * newly allocated memory containing list.
  469. * Free the memory with a delete []
  470. *
  471. * Returns:
  472. * HRESULT: DirectSound/COM result code.
  473. *
  474. ***************************************************************************/
  475. HRESULT PrvGetDirectSoundCaptureObjects
  476. (
  477. LPKSPROPERTYSET pKsPropertySet,
  478. const GUID& guidDevice,
  479. DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA **pDSObjects
  480. )
  481. {
  482. HRESULT hr;
  483. ULONG ulSize;
  484. DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA* pDsObjList;
  485. DWORD dwNumObjects;
  486. *pDSObjects = NULL;
  487. pDsObjList = (DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA *) new DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA;
  488. if( pDsObjList == NULL )
  489. {
  490. return E_OUTOFMEMORY;
  491. }
  492. memset( pDsObjList, 0x00, sizeof( DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA ) );
  493. pDsObjList->DeviceId = guidDevice;
  494. hr =
  495. pKsPropertySet->Get
  496. (
  497. DSPROPSETID_DirectSound,
  498. DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS,
  499. NULL,
  500. 0,
  501. pDsObjList,
  502. sizeof( DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA ),
  503. NULL
  504. );
  505. dwNumObjects = pDsObjList->Count;
  506. if(SUCCEEDED(hr))
  507. {
  508. if( dwNumObjects > 0 )
  509. {
  510. delete [] pDsObjList;
  511. pDsObjList = NULL;
  512. ulSize = sizeof(DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA) + (dwNumObjects * sizeof(DIRECTSOUNDCAPTURE_INFO));
  513. pDsObjList = (DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA *) new BYTE[ulSize];
  514. if( pDsObjList == NULL )
  515. {
  516. return E_OUTOFMEMORY;
  517. }
  518. memset( pDsObjList, 0x00, sizeof( DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA ) );
  519. pDsObjList->DeviceId = guidDevice;
  520. hr =
  521. pKsPropertySet->Get
  522. (
  523. DSPROPSETID_DirectSound,
  524. DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS,
  525. NULL,
  526. 0,
  527. pDsObjList,
  528. ulSize,
  529. NULL
  530. );
  531. if( FAILED( hr ) )
  532. {
  533. delete [] pDsObjList;
  534. return hr;
  535. }
  536. }
  537. *pDSObjects = pDsObjList;
  538. }
  539. else
  540. {
  541. delete pDsObjList;
  542. *pDSObjects = NULL;
  543. }
  544. return hr;
  545. }