Source code of Windows XP (NT5)
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.

1388 lines
36 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. *
  15. ***************************************************************************/
  16. #include "dxvutilspch.h"
  17. #define MAX_OBJECTS 20
  18. /***************************************************************************
  19. *
  20. * DirectSoundPrivateCreate
  21. *
  22. * Description:
  23. * Creates and initializes a DirectSoundPrivate object.
  24. *
  25. * Arguments:
  26. * LPKSPROPERTYSET * [out]: receives IKsPropertySet interface to the
  27. * object.
  28. *
  29. * Returns:
  30. * HRESULT: DirectSound/COM result code.
  31. *
  32. ***************************************************************************/
  33. HRESULT DirectSoundPrivateCreate
  34. (
  35. LPKSPROPERTYSET * ppKsPropertySet
  36. )
  37. {
  38. typedef HRESULT (STDAPICALLTYPE *LPFNDLLGETCLASSOBJECT)(REFCLSID, REFIID, LPVOID *);
  39. HINSTANCE hLibDsound = NULL;
  40. LPFNGETCLASSOBJECT pfnDllGetClassObject = NULL;
  41. LPCLASSFACTORY pClassFactory = NULL;
  42. LPKSPROPERTYSET pKsPropertySet = NULL;
  43. HRESULT hr = DS_OK;
  44. // Get dsound.dll's instance handle. The dll must already be loaded at this
  45. // point.
  46. hLibDsound =
  47. GetModuleHandle
  48. (
  49. TEXT("dsound.dll")
  50. );
  51. if(!hLibDsound)
  52. {
  53. hr = DSERR_GENERIC;
  54. }
  55. // Find DllGetClassObject
  56. if(SUCCEEDED(hr))
  57. {
  58. pfnDllGetClassObject = (LPFNDLLGETCLASSOBJECT)
  59. GetProcAddress
  60. (
  61. hLibDsound,
  62. "DllGetClassObject"
  63. );
  64. if(!pfnDllGetClassObject)
  65. {
  66. hr = DSERR_GENERIC;
  67. }
  68. }
  69. // Create a class factory object
  70. if(SUCCEEDED(hr))
  71. {
  72. hr =
  73. pfnDllGetClassObject
  74. (
  75. CLSID_DirectSoundPrivate,
  76. IID_IClassFactory,
  77. (LPVOID *)&pClassFactory
  78. );
  79. }
  80. // Create the DirectSoundPrivate object and query for an IKsPropertySet
  81. // interface
  82. if(SUCCEEDED(hr))
  83. {
  84. hr =
  85. pClassFactory->CreateInstance
  86. (
  87. NULL,
  88. IID_IKsPropertySet,
  89. (LPVOID *)&pKsPropertySet
  90. );
  91. }
  92. // Release the class factory
  93. if(pClassFactory)
  94. {
  95. pClassFactory->Release();
  96. }
  97. // Success
  98. if(SUCCEEDED(hr))
  99. {
  100. *ppKsPropertySet = pKsPropertySet;
  101. }
  102. return hr;
  103. }
  104. /***************************************************************************
  105. *
  106. * PrvGetMixerSrcQuality
  107. *
  108. * Description:
  109. * Gets the mixer SRC quality for a given DirectSound device.
  110. *
  111. * Arguments:
  112. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  113. * DirectSoundPrivate object.
  114. * REFGUID [in]: DirectSound device GUID.
  115. * DIRECTSOUNDMIXER_SRCQUALITY * [out]: receives mixer SRC quality.
  116. *
  117. * Returns:
  118. * HRESULT: DirectSound/COM result code.
  119. *
  120. ***************************************************************************/
  121. HRESULT PrvGetMixerSrcQuality
  122. (
  123. LPKSPROPERTYSET pKsPropertySet,
  124. REFGUID guidDeviceId,
  125. DIRECTSOUNDMIXER_SRCQUALITY * pSrcQuality
  126. )
  127. {
  128. DSPROPERTY_DIRECTSOUNDMIXER_SRCQUALITY_DATA Data;
  129. HRESULT hr;
  130. Data.DeviceId = guidDeviceId;
  131. hr =
  132. pKsPropertySet->Get
  133. (
  134. DSPROPSETID_DirectSoundMixer,
  135. DSPROPERTY_DIRECTSOUNDMIXER_SRCQUALITY,
  136. NULL,
  137. 0,
  138. &Data,
  139. sizeof(Data),
  140. NULL
  141. );
  142. if(SUCCEEDED(hr))
  143. {
  144. *pSrcQuality = Data.Quality;
  145. }
  146. return hr;
  147. }
  148. /***************************************************************************
  149. *
  150. * PrvSetMixerSrcQuality
  151. *
  152. * Description:
  153. * Sets the mixer SRC quality for a given DirectSound device.
  154. *
  155. * Arguments:
  156. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  157. * DirectSoundPrivate object.
  158. * REFGUID [in]: DirectSound device GUID.
  159. * DIRECTSOUNDMIXER_SRCQUALITY [in]: mixer SRC quality.
  160. *
  161. * Returns:
  162. * HRESULT: DirectSound/COM result code.
  163. *
  164. ***************************************************************************/
  165. HRESULT PrvSetMixerSrcQuality
  166. (
  167. LPKSPROPERTYSET pKsPropertySet,
  168. REFGUID guidDeviceId,
  169. DIRECTSOUNDMIXER_SRCQUALITY SrcQuality
  170. )
  171. {
  172. DSPROPERTY_DIRECTSOUNDMIXER_SRCQUALITY_DATA Data;
  173. HRESULT hr;
  174. Data.DeviceId = guidDeviceId;
  175. Data.Quality = SrcQuality;
  176. hr =
  177. pKsPropertySet->Set
  178. (
  179. DSPROPSETID_DirectSoundMixer,
  180. DSPROPERTY_DIRECTSOUNDMIXER_SRCQUALITY,
  181. NULL,
  182. 0,
  183. &Data,
  184. sizeof(Data)
  185. );
  186. return hr;
  187. }
  188. /***************************************************************************
  189. *
  190. * PrvGetMixerAcceleration
  191. *
  192. * Description:
  193. * Gets the mixer acceleration flags for a given DirectSound device.
  194. *
  195. * Arguments:
  196. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  197. * DirectSoundPrivate object.
  198. * REFGUID [in]: DirectSound device GUID.
  199. * LPDWORD [out]: receives acceleration flags.
  200. *
  201. * Returns:
  202. * HRESULT: DirectSound/COM result code.
  203. *
  204. ***************************************************************************/
  205. HRESULT PrvGetMixerAcceleration
  206. (
  207. LPKSPROPERTYSET pKsPropertySet,
  208. REFGUID guidDeviceId,
  209. LPDWORD pdwAcceleration
  210. )
  211. {
  212. DSPROPERTY_DIRECTSOUNDMIXER_ACCELERATION_DATA Data;
  213. HRESULT hr;
  214. Data.DeviceId = guidDeviceId;
  215. hr =
  216. pKsPropertySet->Get
  217. (
  218. DSPROPSETID_DirectSoundMixer,
  219. DSPROPERTY_DIRECTSOUNDMIXER_ACCELERATION,
  220. NULL,
  221. 0,
  222. &Data,
  223. sizeof(Data),
  224. NULL
  225. );
  226. if(SUCCEEDED(hr))
  227. {
  228. *pdwAcceleration = Data.Flags;
  229. }
  230. return hr;
  231. }
  232. /***************************************************************************
  233. *
  234. * PrvSetMixerAcceleration
  235. *
  236. * Description:
  237. * Sets the mixer acceleration flags for a given DirectSound device.
  238. *
  239. * Arguments:
  240. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  241. * DirectSoundPrivate object.
  242. * REFGUID [in]: DirectSound device GUID.
  243. * DWORD [in]: acceleration flags.
  244. *
  245. * Returns:
  246. * HRESULT: DirectSound/COM result code.
  247. *
  248. ***************************************************************************/
  249. HRESULT PrvSetMixerAcceleration
  250. (
  251. LPKSPROPERTYSET pKsPropertySet,
  252. REFGUID guidDeviceId,
  253. DWORD dwAcceleration
  254. )
  255. {
  256. DSPROPERTY_DIRECTSOUNDMIXER_ACCELERATION_DATA Data;
  257. HRESULT hr;
  258. Data.DeviceId = guidDeviceId;
  259. Data.Flags = dwAcceleration;
  260. hr =
  261. pKsPropertySet->Set
  262. (
  263. DSPROPSETID_DirectSoundMixer,
  264. DSPROPERTY_DIRECTSOUNDMIXER_ACCELERATION,
  265. NULL,
  266. 0,
  267. &Data,
  268. sizeof(Data)
  269. );
  270. return hr;
  271. }
  272. /***************************************************************************
  273. *
  274. * PrvGetDevicePresence
  275. *
  276. * Description:
  277. * Determines whether a device is enabled.
  278. *
  279. * Arguments:
  280. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  281. * DirectSoundPrivate object.
  282. * REFGUID [in]: DirectSound device GUID.
  283. * LPBOOL [out]: receives TRUE if the device is enabled.
  284. *
  285. * Returns:
  286. * HRESULT: DirectSound/COM result code.
  287. *
  288. ***************************************************************************/
  289. HRESULT PrvGetDevicePresence
  290. (
  291. LPKSPROPERTYSET pKsPropertySet,
  292. REFGUID guidDeviceId,
  293. LPBOOL pfEnabled
  294. )
  295. {
  296. DSPROPERTY_DIRECTSOUNDDEVICE_PRESENCE_DATA Data;
  297. HRESULT hr;
  298. Data.DeviceId = guidDeviceId;
  299. hr =
  300. pKsPropertySet->Get
  301. (
  302. DSPROPSETID_DirectSoundDevice,
  303. DSPROPERTY_DIRECTSOUNDDEVICE_PRESENCE,
  304. NULL,
  305. 0,
  306. &Data,
  307. sizeof(Data),
  308. NULL
  309. );
  310. if(SUCCEEDED(hr))
  311. {
  312. *pfEnabled = Data.Present;
  313. }
  314. return hr;
  315. }
  316. /***************************************************************************
  317. *
  318. * PrvSetDevicePresence
  319. *
  320. * Description:
  321. * Sets whether a device is enabled.
  322. *
  323. * Arguments:
  324. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  325. * DirectSoundPrivate object.
  326. * REFGUID [in]: DirectSound device GUID.
  327. * BOOL [in]: TRUE if the device is enabled.
  328. *
  329. * Returns:
  330. * HRESULT: DirectSound/COM result code.
  331. *
  332. ***************************************************************************/
  333. HRESULT PrvSetDevicePresence
  334. (
  335. LPKSPROPERTYSET pKsPropertySet,
  336. REFGUID guidDeviceId,
  337. BOOL fEnabled
  338. )
  339. {
  340. DSPROPERTY_DIRECTSOUNDDEVICE_PRESENCE_DATA Data;
  341. HRESULT hr;
  342. Data.DeviceId = guidDeviceId;
  343. Data.Present = fEnabled;
  344. hr =
  345. pKsPropertySet->Set
  346. (
  347. DSPROPSETID_DirectSoundDevice,
  348. DSPROPERTY_DIRECTSOUNDDEVICE_PRESENCE,
  349. NULL,
  350. 0,
  351. &Data,
  352. sizeof(Data)
  353. );
  354. return hr;
  355. }
  356. /***************************************************************************
  357. *
  358. * PrvGetWaveDeviceMapping
  359. *
  360. * Description:
  361. * Gets the DirectSound device id (if any) for a given waveIn or
  362. * waveOut device description. This is the description given by
  363. * waveIn/OutGetDevCaps (szPname).
  364. *
  365. * Arguments:
  366. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  367. * DirectSoundPrivate object.
  368. * LPCSTR [in]: wave device description.
  369. * BOOL [in]: TRUE if the device description refers to a waveIn device.
  370. * LPGUID [out]: receives DirectSound device GUID.
  371. *
  372. * Returns:
  373. * HRESULT: DirectSound/COM result code.
  374. *
  375. ***************************************************************************/
  376. HRESULT PrvGetWaveDeviceMapping
  377. (
  378. LPKSPROPERTYSET pKsPropertySet,
  379. LPCTSTR pszWaveDevice,
  380. BOOL fCapture,
  381. LPGUID pguidDeviceId
  382. )
  383. {
  384. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_DATA Data;
  385. HRESULT hr;
  386. Data.DeviceName = (LPTSTR)pszWaveDevice;
  387. Data.DataFlow = fCapture ? DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE : DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
  388. hr =
  389. pKsPropertySet->Get
  390. (
  391. DSPROPSETID_DirectSoundDevice,
  392. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING,
  393. NULL,
  394. 0,
  395. &Data,
  396. sizeof(Data),
  397. NULL
  398. );
  399. if(SUCCEEDED(hr))
  400. {
  401. *pguidDeviceId = Data.DeviceId;
  402. }
  403. return hr;
  404. }
  405. /***************************************************************************
  406. *
  407. * PrvGetWaveDeviceMappingW (Unicode)
  408. *
  409. * Description:
  410. * Gets the DirectSound device id (if any) for a given waveIn or
  411. * waveOut device description. This is the description given by
  412. * waveIn/OutGetDevCaps (szPname).
  413. *
  414. * Arguments:
  415. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  416. * DirectSoundPrivate object.
  417. * LPWCSTR [in]: wave device description.
  418. * BOOL [in]: TRUE if the device description refers to a waveIn device.
  419. * LPGUID [out]: receives DirectSound device GUID.
  420. *
  421. * Returns:
  422. * HRESULT: DirectSound/COM result code.
  423. *
  424. ***************************************************************************/
  425. HRESULT PrvGetWaveDeviceMappingW
  426. (
  427. LPKSPROPERTYSET pKsPropertySet,
  428. LPWSTR pwszWaveDevice,
  429. BOOL fCapture,
  430. LPGUID pguidDeviceId
  431. )
  432. {
  433. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W_DATA Data;
  434. HRESULT hr;
  435. Data.DeviceName = (LPWSTR)pwszWaveDevice;
  436. Data.DataFlow = fCapture ? DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE : DIRECTSOUNDDEVICE_DATAFLOW_RENDER;
  437. hr =
  438. pKsPropertySet->Get
  439. (
  440. DSPROPSETID_DirectSoundDevice,
  441. DSPROPERTY_DIRECTSOUNDDEVICE_WAVEDEVICEMAPPING_W,
  442. NULL,
  443. 0,
  444. &Data,
  445. sizeof(Data),
  446. NULL
  447. );
  448. if(SUCCEEDED(hr))
  449. {
  450. *pguidDeviceId = Data.DeviceId;
  451. }
  452. return hr;
  453. }
  454. /***************************************************************************
  455. *
  456. * PrvGetDeviceDescription
  457. *
  458. * Description:
  459. * Gets the extended description for a given DirectSound device.
  460. *
  461. * Arguments:
  462. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  463. * DirectSoundPrivate object.
  464. * REFGUID [in]: DirectSound device id.
  465. * PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA [out]: receives
  466. * description.
  467. *
  468. * Returns:
  469. * HRESULT: DirectSound/COM result code.
  470. *
  471. ***************************************************************************/
  472. HRESULT PrvGetDeviceDescription
  473. (
  474. LPKSPROPERTYSET pKsPropertySet,
  475. REFGUID guidDeviceId,
  476. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA *ppData
  477. )
  478. {
  479. PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA pData = NULL;
  480. ULONG cbData;
  481. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA Basic;
  482. HRESULT hr;
  483. Basic.DeviceId = guidDeviceId;
  484. hr =
  485. pKsPropertySet->Get
  486. (
  487. DSPROPSETID_DirectSoundDevice,
  488. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION,
  489. NULL,
  490. 0,
  491. &Basic,
  492. sizeof(Basic),
  493. &cbData
  494. );
  495. if(SUCCEEDED(hr))
  496. {
  497. pData = (PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_DATA)new BYTE [cbData];
  498. if(!pData)
  499. {
  500. hr = DSERR_OUTOFMEMORY;
  501. }
  502. }
  503. if(SUCCEEDED(hr))
  504. {
  505. pData->DeviceId = guidDeviceId;
  506. hr =
  507. pKsPropertySet->Get
  508. (
  509. DSPROPSETID_DirectSoundDevice,
  510. DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION,
  511. NULL,
  512. 0,
  513. pData,
  514. cbData,
  515. NULL
  516. );
  517. }
  518. if(SUCCEEDED(hr))
  519. {
  520. *ppData = pData;
  521. }
  522. else if(pData)
  523. {
  524. delete[] pData;
  525. }
  526. return hr;
  527. }
  528. /***************************************************************************
  529. *
  530. * PrvEnumerateDevices
  531. *
  532. * Description:
  533. * Enumerates all DirectSound devices.
  534. *
  535. * Arguments:
  536. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  537. * DirectSoundPrivate object.
  538. * LPFNDIRECTSOUNDDEVICEENUMERATECALLBACK [in]: pointer to the callback
  539. * function.
  540. * LPVOID [in]: context argument to pass to the callback function.
  541. *
  542. * Returns:
  543. * HRESULT: DirectSound/COM result code.
  544. *
  545. ***************************************************************************/
  546. HRESULT PrvEnumerateDevices
  547. (
  548. LPKSPROPERTYSET pKsPropertySet,
  549. LPFNDIRECTSOUNDDEVICEENUMERATECALLBACK pfnCallback,
  550. LPVOID pvContext
  551. )
  552. {
  553. DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE_DATA Data;
  554. HRESULT hr;
  555. Data.Callback = pfnCallback;
  556. Data.Context = pvContext;
  557. hr =
  558. pKsPropertySet->Get
  559. (
  560. DSPROPSETID_DirectSoundDevice,
  561. DSPROPERTY_DIRECTSOUNDDEVICE_ENUMERATE,
  562. NULL,
  563. 0,
  564. &Data,
  565. sizeof(Data),
  566. NULL
  567. );
  568. return hr;
  569. }
  570. /***************************************************************************
  571. *
  572. * PrvGetBasicAcceleration
  573. *
  574. * Description:
  575. * Gets basic acceleration flags for a given DirectSound device. This
  576. * is the accleration level that the multimedia control panel uses.
  577. *
  578. * Arguments:
  579. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  580. * DirectSoundPrivate object.
  581. * REFGUID [in]: DirectSound device GUID.
  582. * DIRECTSOUNDBASICACCELERATION_LEVEL * [out]: receives basic
  583. * acceleration level.
  584. *
  585. * Returns:
  586. * HRESULT: DirectSound/COM result code.
  587. *
  588. ***************************************************************************/
  589. HRESULT PrvGetBasicAcceleration
  590. (
  591. LPKSPROPERTYSET pKsPropertySet,
  592. REFGUID guidDeviceId,
  593. DIRECTSOUNDBASICACCELERATION_LEVEL * pLevel
  594. )
  595. {
  596. DSPROPERTY_DIRECTSOUNDBASICACCELERATION_ACCELERATION_DATA Data;
  597. HRESULT hr;
  598. Data.DeviceId = guidDeviceId;
  599. hr =
  600. pKsPropertySet->Get
  601. (
  602. DSPROPSETID_DirectSoundBasicAcceleration,
  603. DSPROPERTY_DIRECTSOUNDBASICACCELERATION_ACCELERATION,
  604. NULL,
  605. 0,
  606. &Data,
  607. sizeof(Data),
  608. NULL
  609. );
  610. if(SUCCEEDED(hr))
  611. {
  612. *pLevel = Data.Level;
  613. }
  614. return hr;
  615. }
  616. /***************************************************************************
  617. *
  618. * PrvSetBasicAcceleration
  619. *
  620. * Description:
  621. * Sets basic acceleration flags for a given DirectSound device. This
  622. * is the accleration level that the multimedia control panel uses.
  623. *
  624. * Arguments:
  625. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  626. * DirectSoundPrivate object.
  627. * REFGUID [in]: DirectSound device GUID.
  628. * DIRECTSOUNDBASICACCELERATION_LEVEL [in]: basic acceleration level.
  629. *
  630. * Returns:
  631. * HRESULT: DirectSound/COM result code.
  632. *
  633. ***************************************************************************/
  634. HRESULT PrvSetBasicAcceleration
  635. (
  636. LPKSPROPERTYSET pKsPropertySet,
  637. REFGUID guidDeviceId,
  638. DIRECTSOUNDBASICACCELERATION_LEVEL Level
  639. )
  640. {
  641. DSPROPERTY_DIRECTSOUNDBASICACCELERATION_ACCELERATION_DATA Data;
  642. HRESULT hr;
  643. Data.DeviceId = guidDeviceId;
  644. Data.Level = Level;
  645. hr =
  646. pKsPropertySet->Set
  647. (
  648. DSPROPSETID_DirectSoundBasicAcceleration,
  649. DSPROPERTY_DIRECTSOUNDBASICACCELERATION_ACCELERATION,
  650. NULL,
  651. 0,
  652. &Data,
  653. sizeof(Data)
  654. );
  655. return hr;
  656. }
  657. /***************************************************************************
  658. *
  659. * PrvGetDebugInformation
  660. *
  661. * Description:
  662. * Gets the current DirectSound debug settings.
  663. *
  664. * Arguments:
  665. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  666. * DirectSoundPrivate object.
  667. * LPDWORD [in]: receives DPF flags.
  668. * PULONG [out]: receives DPF level.
  669. * PULONG [out]: receives break level.
  670. * LPSTR [out]: receives log file name.
  671. *
  672. * Returns:
  673. * HRESULT: DirectSound/COM result code.
  674. *
  675. ***************************************************************************/
  676. HRESULT PrvGetDebugInformation
  677. (
  678. LPKSPROPERTYSET pKsPropertySet,
  679. LPDWORD pdwFlags,
  680. PULONG pulDpfLevel,
  681. PULONG pulBreakLevel,
  682. LPTSTR pszLogFile
  683. )
  684. {
  685. DSPROPERTY_DIRECTSOUNDDEBUG_DPFINFO_DATA Data;
  686. HRESULT hr;
  687. hr =
  688. pKsPropertySet->Get
  689. (
  690. DSPROPSETID_DirectSoundDebug,
  691. DSPROPERTY_DIRECTSOUNDDEBUG_DPFINFO,
  692. NULL,
  693. 0,
  694. &Data,
  695. sizeof(Data),
  696. NULL
  697. );
  698. if(SUCCEEDED(hr) && pdwFlags)
  699. {
  700. *pdwFlags = Data.Flags;
  701. }
  702. if(SUCCEEDED(hr) && pulDpfLevel)
  703. {
  704. *pulDpfLevel = Data.DpfLevel;
  705. }
  706. if(SUCCEEDED(hr) && pulBreakLevel)
  707. {
  708. *pulBreakLevel = Data.BreakLevel;
  709. }
  710. if(SUCCEEDED(hr) && pszLogFile)
  711. {
  712. lstrcpy
  713. (
  714. pszLogFile,
  715. Data.LogFile
  716. );
  717. }
  718. return hr;
  719. }
  720. /***************************************************************************
  721. *
  722. * PrvSetDebugInformation
  723. *
  724. * Description:
  725. * Sets the current DirectSound debug settings.
  726. *
  727. * Arguments:
  728. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  729. * DirectSoundPrivate object.
  730. * DWORD [in]: DPF flags.
  731. * ULONG [in]: DPF level.
  732. * ULONG [in]: break level.
  733. * LPCSTR [in]: log file name.
  734. *
  735. * Returns:
  736. * HRESULT: DirectSound/COM result code.
  737. *
  738. ***************************************************************************/
  739. HRESULT PrvSetDebugInformation
  740. (
  741. LPKSPROPERTYSET pKsPropertySet,
  742. DWORD dwFlags,
  743. ULONG ulDpfLevel,
  744. ULONG ulBreakLevel,
  745. LPCTSTR pszLogFile
  746. )
  747. {
  748. DSPROPERTY_DIRECTSOUNDDEBUG_DPFINFO_DATA Data;
  749. HRESULT hr;
  750. Data.Flags = dwFlags;
  751. Data.DpfLevel = ulDpfLevel;
  752. Data.BreakLevel = ulBreakLevel;
  753. lstrcpy
  754. (
  755. Data.LogFile,
  756. pszLogFile
  757. );
  758. hr =
  759. pKsPropertySet->Set
  760. (
  761. DSPROPSETID_DirectSoundDebug,
  762. DSPROPERTY_DIRECTSOUNDDEBUG_DPFINFO,
  763. NULL,
  764. 0,
  765. &Data,
  766. sizeof(Data)
  767. );
  768. return hr;
  769. }
  770. /***************************************************************************
  771. *
  772. * PrvGetPersistentData
  773. *
  774. * Description:
  775. * Gets a registry value stored under the DirectSound subkey of a
  776. * specific hardware device.
  777. *
  778. * Arguments:
  779. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  780. * DirectSoundPrivate object.
  781. * REFGUID [in]: DirectSound device id.
  782. * LPCSTR [in]: subkey path.
  783. * LPCSTR [in]: value name.
  784. * LPDWORD [in/out]: receives registry data type.
  785. * LPVOID [out]: data buffer.
  786. * LPDWORD [in/out]: size of above buffer. On entry, this argument is
  787. * filled with the maximum size of the data buffer.
  788. * On exit, this argument is filled with the required
  789. * size.
  790. *
  791. * Returns:
  792. * HRESULT: DirectSound/COM result code.
  793. *
  794. ***************************************************************************/
  795. HRESULT PrvGetPersistentData
  796. (
  797. LPKSPROPERTYSET pKsPropertySet,
  798. REFGUID guidDeviceId,
  799. LPCTSTR pszSubkey,
  800. LPCTSTR pszValue,
  801. LPDWORD pdwRegType,
  802. LPVOID pvData,
  803. LPDWORD pcbData
  804. )
  805. {
  806. PDSPROPERTY_DIRECTSOUNDPERSISTENTDATA_PERSISTDATA_DATA pPersist;
  807. ULONG cbPersist;
  808. HRESULT hr;
  809. cbPersist = sizeof(*pPersist) + *pcbData;
  810. pPersist = (PDSPROPERTY_DIRECTSOUNDPERSISTENTDATA_PERSISTDATA_DATA)
  811. LocalAlloc
  812. (
  813. LPTR,
  814. cbPersist
  815. );
  816. if(pPersist)
  817. {
  818. pPersist->DeviceId = guidDeviceId;
  819. pPersist->SubKeyName = (LPTSTR)pszSubkey;
  820. pPersist->ValueName = (LPTSTR)pszValue;
  821. if(pdwRegType)
  822. {
  823. pPersist->RegistryDataType = *pdwRegType;
  824. }
  825. hr =
  826. pKsPropertySet->Get
  827. (
  828. DSPROPSETID_DirectSoundPersistentData,
  829. DSPROPERTY_DIRECTSOUNDPERSISTENTDATA_PERSISTDATA,
  830. NULL,
  831. 0,
  832. pPersist,
  833. cbPersist,
  834. &cbPersist
  835. );
  836. }
  837. else
  838. {
  839. hr = DSERR_OUTOFMEMORY;
  840. }
  841. if(SUCCEEDED(hr))
  842. {
  843. CopyMemory
  844. (
  845. pvData,
  846. pPersist + 1,
  847. *pcbData
  848. );
  849. }
  850. *pcbData = cbPersist - sizeof(*pPersist);
  851. if(pPersist && pdwRegType)
  852. {
  853. *pdwRegType = pPersist->RegistryDataType;
  854. }
  855. if(pPersist)
  856. {
  857. LocalFree(pPersist);
  858. }
  859. return hr;
  860. }
  861. /***************************************************************************
  862. *
  863. * PrvSetPersistentData
  864. *
  865. * Description:
  866. * Sets a registry value stored under the DirectSound subkey of a
  867. * specific hardware device.
  868. *
  869. * Arguments:
  870. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  871. * DirectSoundPrivate object.
  872. * REFGUID [in]: DirectSound device id.
  873. * LPCSTR [in]: subkey path.
  874. * LPCSTR [in]: value name.
  875. * DWORD [in]: registry data type.
  876. * LPVOID [out]: data buffer.
  877. * DWORD [in]: size of above buffer.
  878. *
  879. * Returns:
  880. * HRESULT: DirectSound/COM result code.
  881. *
  882. ***************************************************************************/
  883. HRESULT PrvSetPersistentData
  884. (
  885. LPKSPROPERTYSET pKsPropertySet,
  886. REFGUID guidDeviceId,
  887. LPCTSTR pszSubkey,
  888. LPCTSTR pszValue,
  889. DWORD dwRegType,
  890. LPVOID pvData,
  891. DWORD cbData
  892. )
  893. {
  894. PDSPROPERTY_DIRECTSOUNDPERSISTENTDATA_PERSISTDATA_DATA pPersist;
  895. ULONG cbPersist;
  896. HRESULT hr;
  897. cbPersist = sizeof(*pPersist) + cbData;
  898. pPersist = (PDSPROPERTY_DIRECTSOUNDPERSISTENTDATA_PERSISTDATA_DATA)
  899. LocalAlloc
  900. (
  901. LPTR,
  902. cbPersist
  903. );
  904. if(pPersist)
  905. {
  906. pPersist->DeviceId = guidDeviceId;
  907. pPersist->SubKeyName = (LPTSTR)pszSubkey;
  908. pPersist->ValueName = (LPTSTR)pszValue;
  909. pPersist->RegistryDataType = dwRegType;
  910. CopyMemory
  911. (
  912. pPersist + 1,
  913. pvData,
  914. cbData
  915. );
  916. hr =
  917. pKsPropertySet->Set
  918. (
  919. DSPROPSETID_DirectSoundPersistentData,
  920. DSPROPERTY_DIRECTSOUNDPERSISTENTDATA_PERSISTDATA,
  921. NULL,
  922. 0,
  923. pPersist,
  924. cbPersist
  925. );
  926. }
  927. else
  928. {
  929. hr = DSERR_OUTOFMEMORY;
  930. }
  931. if(pPersist)
  932. {
  933. LocalFree(pPersist);
  934. }
  935. return hr;
  936. }
  937. /***************************************************************************
  938. *
  939. * PrvTranslateErrorCode
  940. *
  941. * Description:
  942. * Translates an error code to a string representation.
  943. *
  944. * Arguments:
  945. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  946. * DirectSoundPrivate object.
  947. * HRESULT [in]: result code.
  948. * PDSPROPERTY_DIRECTSOUNDDEBUG_TRANSLATEERRORCODE_DATA * [out]:
  949. * receives error code data. The caller is responsible for freeing
  950. * this buffer.
  951. *
  952. * Returns:
  953. * HRESULT: DirectSound/COM result code.
  954. *
  955. ***************************************************************************/
  956. HRESULT PrvTranslateResultCode
  957. (
  958. LPKSPROPERTYSET pKsPropertySet,
  959. HRESULT hrResult,
  960. PDSPROPERTY_DIRECTSOUNDDEBUG_TRANSLATERESULTCODE_DATA * ppData
  961. )
  962. {
  963. PDSPROPERTY_DIRECTSOUNDDEBUG_TRANSLATERESULTCODE_DATA pData = NULL;
  964. DSPROPERTY_DIRECTSOUNDDEBUG_TRANSLATERESULTCODE_DATA Basic;
  965. ULONG cbData;
  966. HRESULT hr;
  967. Basic.ResultCode = hrResult;
  968. hr =
  969. pKsPropertySet->Get
  970. (
  971. DSPROPSETID_DirectSoundDebug,
  972. DSPROPERTY_DIRECTSOUNDDEBUG_TRANSLATERESULTCODE,
  973. NULL,
  974. 0,
  975. &Basic,
  976. sizeof(Basic),
  977. &cbData
  978. );
  979. if(SUCCEEDED(hr))
  980. {
  981. pData = (PDSPROPERTY_DIRECTSOUNDDEBUG_TRANSLATERESULTCODE_DATA)
  982. LocalAlloc
  983. (
  984. LPTR,
  985. cbData
  986. );
  987. if(!pData)
  988. {
  989. hr = DSERR_OUTOFMEMORY;
  990. }
  991. }
  992. if(SUCCEEDED(hr))
  993. {
  994. pData->ResultCode = hrResult;
  995. hr =
  996. pKsPropertySet->Get
  997. (
  998. DSPROPSETID_DirectSoundDebug,
  999. DSPROPERTY_DIRECTSOUNDDEBUG_TRANSLATERESULTCODE,
  1000. NULL,
  1001. 0,
  1002. pData,
  1003. cbData,
  1004. NULL
  1005. );
  1006. }
  1007. if(SUCCEEDED(hr))
  1008. {
  1009. *ppData = pData;
  1010. }
  1011. else if(pData)
  1012. {
  1013. LocalFree
  1014. (
  1015. pData
  1016. );
  1017. }
  1018. return hr;
  1019. }
  1020. /***************************************************************************
  1021. *
  1022. * PrvGetDirectSoundObjects
  1023. *
  1024. * Description:
  1025. * Gets the list of DirectSound objects in the current process
  1026. *
  1027. * Arguments:
  1028. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  1029. * DirectSoundPrivate object.
  1030. * GUID guiDevice [in]: Device to get list for, or GUID_NULL for all.
  1031. * DSPROPERTY_DIRECTSOUND_OBJECTS_DATA [in/out]: Pointer to place
  1032. * newly allocated memory containing list.
  1033. * Free the memory with a delete []
  1034. *
  1035. * Returns:
  1036. * HRESULT: DirectSound/COM result code.
  1037. *
  1038. ***************************************************************************/
  1039. HRESULT PrvGetDirectSoundObjects
  1040. (
  1041. LPKSPROPERTYSET pKsPropertySet,
  1042. GUID guidDevice,
  1043. DSPROPERTY_DIRECTSOUND_OBJECTS_DATA **pDSObjects
  1044. )
  1045. {
  1046. HRESULT hr;
  1047. ULONG ulSize;
  1048. DSPROPERTY_DIRECTSOUND_OBJECTS_DATA* pDsObjList;
  1049. DWORD dwNumObjects;
  1050. *pDSObjects = NULL;
  1051. pDsObjList = (DSPROPERTY_DIRECTSOUND_OBJECTS_DATA *) new DSPROPERTY_DIRECTSOUND_OBJECTS_DATA;
  1052. if( pDsObjList == NULL )
  1053. {
  1054. return E_OUTOFMEMORY;
  1055. }
  1056. memset( pDsObjList, 0x00, sizeof( DSPROPERTY_DIRECTSOUND_OBJECTS_DATA ) );
  1057. pDsObjList->DeviceId = guidDevice;
  1058. hr =
  1059. pKsPropertySet->Get
  1060. (
  1061. DSPROPSETID_DirectSound,
  1062. DSPROPERTY_DIRECTSOUND_OBJECTS,
  1063. NULL,
  1064. 0,
  1065. pDsObjList,
  1066. sizeof( DSPROPERTY_DIRECTSOUND_OBJECTS_DATA ),
  1067. NULL
  1068. );
  1069. dwNumObjects = pDsObjList->Count;
  1070. if(SUCCEEDED(hr))
  1071. {
  1072. if( dwNumObjects > 0 )
  1073. {
  1074. delete pDsObjList;
  1075. pDsObjList = NULL;
  1076. ulSize = sizeof(DSPROPERTY_DIRECTSOUND_OBJECTS_DATA) + (dwNumObjects * sizeof(DIRECTSOUND_INFO));
  1077. pDsObjList = (DSPROPERTY_DIRECTSOUND_OBJECTS_DATA *) new BYTE[ulSize];
  1078. if( pDsObjList == NULL )
  1079. {
  1080. return E_OUTOFMEMORY;
  1081. }
  1082. memset( pDsObjList, 0x00, sizeof( DSPROPERTY_DIRECTSOUND_OBJECTS_DATA ) );
  1083. pDsObjList->DeviceId = guidDevice;
  1084. hr =
  1085. pKsPropertySet->Get
  1086. (
  1087. DSPROPSETID_DirectSound,
  1088. DSPROPERTY_DIRECTSOUND_OBJECTS,
  1089. NULL,
  1090. 0,
  1091. pDsObjList,
  1092. ulSize,
  1093. NULL
  1094. );
  1095. if( FAILED( hr ) )
  1096. {
  1097. delete [] pDsObjList;
  1098. return hr;
  1099. }
  1100. }
  1101. *pDSObjects = pDsObjList;
  1102. }
  1103. else
  1104. {
  1105. delete pDsObjList;
  1106. pDsObjList = NULL;
  1107. *pDSObjects = NULL;
  1108. }
  1109. return hr;
  1110. }
  1111. /***************************************************************************
  1112. *
  1113. * PrvGetDirectSoundCaptureObjects
  1114. *
  1115. * Description:
  1116. * Gets the list of DirectSoundCapture objects in the current process
  1117. *
  1118. * Arguments:
  1119. * LPKSPROPERTYSET [in]: IKsPropertySet interface to the
  1120. * DirectSoundPrivate object.
  1121. * GUID guiDevice [in]: Device to get list for, or GUID_NULL for all.
  1122. * DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA [in/out]: Pointer to place
  1123. * newly allocated memory containing list.
  1124. * Free the memory with a delete []
  1125. *
  1126. * Returns:
  1127. * HRESULT: DirectSound/COM result code.
  1128. *
  1129. ***************************************************************************/
  1130. HRESULT PrvGetDirectSoundCaptureObjects
  1131. (
  1132. LPKSPROPERTYSET pKsPropertySet,
  1133. GUID guidDevice,
  1134. DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA **pDSObjects
  1135. )
  1136. {
  1137. HRESULT hr;
  1138. ULONG ulSize;
  1139. DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA* pDsObjList;
  1140. DWORD dwNumObjects;
  1141. *pDSObjects = NULL;
  1142. pDsObjList = (DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA *) new DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA;
  1143. if( pDsObjList == NULL )
  1144. {
  1145. return E_OUTOFMEMORY;
  1146. }
  1147. memset( pDsObjList, 0x00, sizeof( DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA ) );
  1148. pDsObjList->DeviceId = guidDevice;
  1149. hr =
  1150. pKsPropertySet->Get
  1151. (
  1152. DSPROPSETID_DirectSound,
  1153. DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS,
  1154. NULL,
  1155. 0,
  1156. pDsObjList,
  1157. sizeof( DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA ),
  1158. NULL
  1159. );
  1160. dwNumObjects = pDsObjList->Count;
  1161. if(SUCCEEDED(hr))
  1162. {
  1163. if( dwNumObjects > 0 )
  1164. {
  1165. delete [] pDsObjList;
  1166. pDsObjList = NULL;
  1167. ulSize = sizeof(DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA) + (dwNumObjects * sizeof(DIRECTSOUNDCAPTURE_INFO));
  1168. pDsObjList = (DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA *) new BYTE[ulSize];
  1169. if( pDsObjList == NULL )
  1170. {
  1171. return E_OUTOFMEMORY;
  1172. }
  1173. memset( pDsObjList, 0x00, sizeof( DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS_DATA ) );
  1174. pDsObjList->DeviceId = guidDevice;
  1175. hr =
  1176. pKsPropertySet->Get
  1177. (
  1178. DSPROPSETID_DirectSound,
  1179. DSPROPERTY_DIRECTSOUNDCAPTURE_OBJECTS,
  1180. NULL,
  1181. 0,
  1182. pDsObjList,
  1183. ulSize,
  1184. NULL
  1185. );
  1186. if( FAILED( hr ) )
  1187. {
  1188. delete [] pDsObjList;
  1189. return hr;
  1190. }
  1191. }
  1192. *pDSObjects = pDsObjList;
  1193. }
  1194. else
  1195. {
  1196. delete pDsObjList;
  1197. *pDSObjects = NULL;
  1198. }
  1199. return hr;
  1200. }