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.

934 lines
18 KiB

  1. #include "precomp.h"
  2. extern HANDLE g_hEventHalfDuplex;
  3. ///////////////////////////////////////////////////////
  4. //
  5. // Public methods
  6. //
  7. MediaControl::MediaControl ( void )
  8. {
  9. _Construct ();
  10. }
  11. MediaControl::~MediaControl ( void )
  12. {
  13. _Destruct ();
  14. }
  15. HRESULT MediaControl::Initialize ( MEDIACTRLINIT * p )
  16. {
  17. HRESULT hr = DPR_SUCCESS;
  18. DEBUGMSG (ZONE_VERBOSE, ("MediaControl::Initialize: enter.\r\n"));
  19. m_dwFlags = p->dwFlags;
  20. m_hEvent = NULL;
  21. m_uDuration = MC_DEF_DURATION;
  22. DEBUGMSG (ZONE_VERBOSE, ("MediaControl::Initialize: exit, hr=0x%lX\r\n", hr));
  23. m_hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  24. if (m_hEvent == NULL)
  25. {
  26. hr = DPR_CANT_CREATE_EVENT;
  27. }
  28. return hr;
  29. }
  30. HRESULT MediaControl::RegisterData ( PVOID pDataPtrArray, ULONG cElements )
  31. {
  32. HRESULT hr;
  33. if (pDataPtrArray == NULL) return DPR_INVALID_PARAMETER;
  34. m_ppMediaPkt = (MediaPacket **) pDataPtrArray;
  35. m_cMediaPkt = cElements;
  36. hr = DPR_SUCCESS;
  37. return hr;
  38. }
  39. HRESULT MediaControl::FillMediaPacketInit ( MEDIAPACKETINIT * p )
  40. {
  41. if (p == NULL) return DPR_INVALID_PARAMETER;
  42. p->pDevFmt = m_pDevFmt;
  43. p->cbSizeDevData = m_cbSizeDevData;
  44. p->cbOffsetDevData = 0;
  45. return DPR_SUCCESS;
  46. }
  47. HRESULT MediaControl::SetProp ( DWORD dwPropId, DWORD_PTR dwPropVal )
  48. {
  49. HRESULT hr = DPR_SUCCESS;
  50. MMRESULT mmr;
  51. switch (dwPropId)
  52. {
  53. case MC_PROP_MEDIA_STREAM:
  54. m_hStrm = (DPHANDLE) dwPropVal;
  55. break;
  56. case MC_PROP_MEDIA_DEV_HANDLE:
  57. m_hDev = (DPHANDLE) dwPropVal;
  58. break;
  59. case MC_PROP_MEDIA_DEV_ID:
  60. m_uDevId = (UINT) dwPropVal;
  61. break;
  62. case MC_PROP_MEDIA_FORMAT:
  63. m_pDevFmt = (PVOID) dwPropVal;
  64. break;
  65. case MC_PROP_SIZE:
  66. m_cbSizeDevData = (DWORD)dwPropVal;
  67. break;
  68. case MC_PROP_PLATFORM:
  69. m_dwFlags = (DWORD)((m_dwFlags & ~DP_MASK_PLATFORM) | (dwPropVal & DP_MASK_PLATFORM));
  70. break;
  71. case MC_PROP_DURATION:
  72. m_uDuration = (DWORD)dwPropVal;
  73. break;
  74. case MC_PROP_DUPLEX_TYPE:
  75. m_dwFlags = (DWORD)((m_dwFlags & ~DP_MASK_DUPLEX) | (dwPropVal & DP_MASK_DUPLEX));
  76. break;
  77. case MC_PROP_STATE:
  78. hr = DPR_IMPOSSIBLE_SET_PROP;
  79. break;
  80. case MC_PROP_AUDIO_JAMMED:
  81. m_fJammed = (DWORD)dwPropVal;
  82. break;
  83. default:
  84. hr = DPR_INVALID_PROP_ID;
  85. break;
  86. }
  87. return hr;
  88. }
  89. HRESULT MediaControl::GetProp ( DWORD dwPropId, PDWORD_PTR pdwPropVal )
  90. {
  91. HRESULT hr = DPR_SUCCESS;
  92. if (pdwPropVal)
  93. {
  94. switch (dwPropId)
  95. {
  96. case MC_PROP_MEDIA_STREAM:
  97. *pdwPropVal = (DWORD_PTR) m_hStrm;
  98. break;
  99. case MC_PROP_MEDIA_DEV_HANDLE:
  100. *pdwPropVal = (DWORD_PTR) m_hDev;
  101. break;
  102. case MC_PROP_MEDIA_DEV_ID:
  103. *pdwPropVal = (DWORD) m_uDevId;
  104. break;
  105. case MC_PROP_MEDIA_FORMAT:
  106. *pdwPropVal = (DWORD_PTR) m_pDevFmt;
  107. break;
  108. case MC_PROP_SIZE:
  109. *pdwPropVal = (DWORD) m_cbSizeDevData;
  110. break;
  111. case MC_PROP_PLATFORM:
  112. *pdwPropVal = m_dwFlags & DP_MASK_PLATFORM;
  113. break;
  114. case MC_PROP_STATE:
  115. *pdwPropVal = m_uState;
  116. break;
  117. case MC_PROP_DURATION:
  118. *pdwPropVal = m_uDuration;
  119. break;
  120. case MC_PROP_DUPLEX_TYPE:
  121. *pdwPropVal = m_dwFlags & DP_MASK_DUPLEX;
  122. break;
  123. case MC_PROP_EVENT_HANDLE:
  124. *pdwPropVal = (DWORD_PTR) m_hEvent;
  125. break;
  126. case MC_PROP_AUDIO_JAMMED:
  127. *pdwPropVal = (DWORD)(m_fJammed ? TRUE : FALSE);
  128. break;
  129. default:
  130. hr = DPR_INVALID_PROP_ID;
  131. break;
  132. }
  133. }
  134. else
  135. {
  136. hr = DPR_INVALID_PARAMETER;
  137. }
  138. return hr;
  139. }
  140. HRESULT MediaControl::PrepareHeaders ( void )
  141. {
  142. HRESULT hr = DPR_SUCCESS;
  143. MediaPacket **pp;
  144. ULONG uc;
  145. if (m_hDev)
  146. {
  147. if (m_ppMediaPkt == NULL)
  148. {
  149. hr = DPR_INVALID_PARAMETER;
  150. goto MyExit;
  151. }
  152. for (uc = m_cMediaPkt, pp = m_ppMediaPkt; uc--; pp++)
  153. {
  154. if (*pp)
  155. {
  156. hr = (*pp)->Open (MP_TYPE_DEV, m_hDev);
  157. if (hr != DPR_SUCCESS)
  158. {
  159. goto MyExit;
  160. }
  161. }
  162. }
  163. }
  164. MyExit:
  165. return hr;
  166. }
  167. HRESULT MediaControl::UnprepareHeaders ( void )
  168. {
  169. HRESULT hr = DPR_SUCCESS;
  170. MediaPacket **pp;
  171. ULONG uc;
  172. if (m_hDev)
  173. {
  174. if (m_ppMediaPkt == NULL)
  175. {
  176. hr = DPR_INVALID_PARAMETER;
  177. goto MyExit;
  178. }
  179. for (uc = m_cMediaPkt, pp = m_ppMediaPkt; uc--; pp++)
  180. {
  181. if (*pp)
  182. {
  183. hr = (*pp)->Close (MP_TYPE_DEV);
  184. if (hr != DPR_SUCCESS)
  185. {
  186. goto MyExit;
  187. }
  188. }
  189. }
  190. //
  191. // LAURABU 11/24/99
  192. // Messes up pausing/unpausing audio
  193. // Had added this to fix faults pausing/unpausing video
  194. //
  195. // m_cMediaPkt = 0;
  196. // m_ppMediaPkt = NULL;
  197. //
  198. }
  199. MyExit:
  200. return hr;
  201. }
  202. HRESULT MediaControl::Release ( void )
  203. {
  204. _Destruct ();
  205. return DPR_SUCCESS;
  206. }
  207. ///////////////////////////////////////////////////////
  208. //
  209. // Private methods
  210. //
  211. void MediaControl::_Construct ( void )
  212. {
  213. m_dwFlags = 0;
  214. m_hStrm = NULL;
  215. m_uDevId = 0;
  216. m_hDev = NULL;
  217. m_pDevFmt = NULL;
  218. m_uDuration = 0;
  219. m_cbSizeDevData = 0;
  220. m_uState = 0;
  221. m_hEvent = NULL;
  222. m_ppMediaPkt = NULL;
  223. m_cMediaPkt = 0;
  224. m_fJammed = FALSE;
  225. }
  226. void MediaControl::_Destruct ( void )
  227. {
  228. if (m_hDev) {
  229. // waveInOut/UnprepareHeaders() and waveIn/OutClose() can fail if the
  230. // device is still playing. Need to Reset() first!
  231. Reset();
  232. UnprepareHeaders ();
  233. Close ();
  234. }
  235. if (m_hEvent)
  236. {
  237. CloseHandle (m_hEvent);
  238. m_hEvent = NULL;
  239. }
  240. }
  241. WaveInControl::WaveInControl()
  242. {
  243. }
  244. WaveInControl::~WaveInControl()
  245. {
  246. }
  247. WaveOutControl::WaveOutControl()
  248. {
  249. m_uPosition = 0;
  250. m_uVolume = 0;
  251. }
  252. WaveOutControl::~WaveOutControl()
  253. {
  254. }
  255. HRESULT WaveInControl::Initialize ( MEDIACTRLINIT * p )
  256. {
  257. HRESULT hr = DPR_SUCCESS;
  258. DEBUGMSG (ZONE_VERBOSE, ("WaveInControl::Initialize: enter.\r\n"));
  259. if ((hr =MediaControl::Initialize( p)) != DPR_SUCCESS)
  260. return hr;
  261. m_uTimeout = MC_DEF_RECORD_TIMEOUT;
  262. m_uPrefeed = MC_DEF_RECORD_BUFS;
  263. m_uSilenceDuration = MC_DEF_SILENCE_DURATION;
  264. DEBUGMSG (ZONE_VERBOSE, ("WaveInControl::Initialize: exit, hr=0x%lX\r\n", hr));
  265. return hr;
  266. }
  267. HRESULT WaveOutControl::Initialize ( MEDIACTRLINIT * p )
  268. {
  269. HRESULT hr = DPR_SUCCESS;
  270. DEBUGMSG (ZONE_VERBOSE, ("WaveOutControl::Initialize: enter.\r\n"));
  271. if ((hr =MediaControl::Initialize( p)) != DPR_SUCCESS)
  272. return hr;
  273. m_uTimeout = MC_DEF_PLAY_TIMEOUT;
  274. m_uPrefeed = MC_DEF_PLAY_BUFS;
  275. m_uVolume = MC_DEF_VOLUME;
  276. DEBUGMSG (ZONE_VERBOSE, ("WaveOutControl::Initialize: exit, hr=0x%lX\r\n", hr));
  277. return hr;
  278. }
  279. HRESULT WaveInControl::Configure ( MEDIACTRLCONFIG * p )
  280. {
  281. HRESULT hr = DPR_SUCCESS;
  282. UINT uBlockAlign;
  283. DEBUGMSG (ZONE_VERBOSE, ("WaveInControl::Configure: enter.\r\n"));
  284. m_hStrm = p->hStrm;
  285. m_uDevId = p->uDevId;
  286. m_pDevFmt = p->pDevFmt;
  287. if (m_pDevFmt == NULL) return DPR_INVALID_PARAMETER;
  288. if ((m_uDuration = p->uDuration) == MC_USING_DEFAULT)
  289. {
  290. m_cbSizeDevData = ((WAVEFORMAT *) m_pDevFmt)->nAvgBytesPerSec * p->cbSamplesPerPkt
  291. /((WAVEFORMAT *) m_pDevFmt)->nSamplesPerSec;
  292. m_uDuration = p->cbSamplesPerPkt*1000 /((WAVEFORMAT *) m_pDevFmt)->nSamplesPerSec;
  293. } else {
  294. // roughly calculate the buffer size based on 20ms
  295. m_cbSizeDevData = ((WAVEFORMAT *) m_pDevFmt)->nAvgBytesPerSec
  296. * m_uDuration / 1000;
  297. // need to be on the block alignment boundary
  298. uBlockAlign = ((WAVEFORMAT *) m_pDevFmt)->nBlockAlign;
  299. m_cbSizeDevData = ((m_cbSizeDevData + uBlockAlign - 1) / uBlockAlign)
  300. * uBlockAlign;
  301. }
  302. DEBUGMSG (ZONE_VERBOSE, ("WaveInControl::Configure: exit, hr=0x%lX\r\n", hr));
  303. return hr;
  304. }
  305. HRESULT WaveOutControl::Configure ( MEDIACTRLCONFIG * p )
  306. {
  307. HRESULT hr = DPR_SUCCESS;
  308. UINT uBlockAlign;
  309. DEBUGMSG (ZONE_VERBOSE, ("WaveOutControl::Configure: enter.\r\n"));
  310. m_hStrm = p->hStrm;
  311. m_uDevId = p->uDevId;
  312. m_pDevFmt = p->pDevFmt;
  313. if (m_pDevFmt == NULL) return DPR_INVALID_PARAMETER;
  314. if ((m_uDuration = p->uDuration) == MC_USING_DEFAULT)
  315. {
  316. m_cbSizeDevData = ((WAVEFORMAT *) m_pDevFmt)->nAvgBytesPerSec * p->cbSamplesPerPkt
  317. /((WAVEFORMAT *) m_pDevFmt)->nSamplesPerSec;
  318. m_uDuration = p->cbSamplesPerPkt*1000 /((WAVEFORMAT *) m_pDevFmt)->nSamplesPerSec;
  319. } else {
  320. // roughly calculate the buffer size based on 20ms
  321. m_cbSizeDevData = ((WAVEFORMAT *) m_pDevFmt)->nAvgBytesPerSec
  322. * m_uDuration / 1000;
  323. // need to be on the block alignment boundary
  324. uBlockAlign = ((WAVEFORMAT *) m_pDevFmt)->nBlockAlign;
  325. m_cbSizeDevData = ((m_cbSizeDevData + uBlockAlign - 1) / uBlockAlign)
  326. * uBlockAlign;
  327. }
  328. DEBUGMSG (ZONE_VERBOSE, ("MediaControl::Configure: exit, hr=0x%lX\r\n", hr));
  329. return hr;
  330. }
  331. HRESULT WaveInControl::Open ( void )
  332. {
  333. HRESULT hr = DPR_INVALID_PLATFORM;
  334. MMRESULT mmr;
  335. DWORD dwfOpen;
  336. UINT uDevId;
  337. m_hDev = NULL;
  338. dwfOpen = CALLBACK_EVENT;
  339. uDevId = (m_uDevId == (UINT) -1) ? WAVE_MAPPER : m_uDevId;
  340. mmr = waveInOpen ((HWAVEIN *) &m_hDev, uDevId,
  341. (WAVEFORMATEX *) m_pDevFmt,
  342. (DWORD_PTR) m_hEvent, 0, dwfOpen);
  343. // begin hack
  344. if (mmr == WAVERR_BADFORMAT && uDevId != WAVE_MAPPER) {
  345. // the sound card probably doesnt support our sample size or sample rate
  346. // (16 bit, 8Khz)
  347. // Try using the WAVE_MAPPER. The WAVE_MAPPER may end up using
  348. // a different device than the one we wanted !!
  349. DEBUGMSG (1, ("MediaControl::Open: bad format, trying WAVE_MAPPER\r\n" ));
  350. mmr = waveInOpen ((HWAVEIN *) &m_hDev, WAVE_MAPPER,
  351. (WAVEFORMATEX *) m_pDevFmt,
  352. (DWORD_PTR) m_hEvent, 0, dwfOpen);
  353. if (mmr == MMSYSERR_NOERROR)
  354. m_uDevId = (UINT) -1; // use WAVE_MAPPER next time
  355. }
  356. // end hack
  357. if (mmr != MMSYSERR_NOERROR)
  358. {
  359. DEBUGMSG (1, ("MediaControl::Open: waveInOpen failed, mmr=%ld\r\n", (ULONG) mmr));
  360. hr = DPR_CANT_OPEN_WAVE_DEV;
  361. goto MyExit;
  362. }
  363. else
  364. {
  365. hr = DPR_SUCCESS;
  366. }
  367. MyExit:
  368. return hr;
  369. }
  370. HRESULT WaveOutControl::Open ( void )
  371. {
  372. HRESULT hr = DPR_INVALID_PLATFORM;
  373. MMRESULT mmr;
  374. DWORD dwfOpen;
  375. UINT uDevId;
  376. m_hDev = NULL;
  377. dwfOpen = CALLBACK_EVENT;
  378. uDevId = (m_uDevId == (UINT) -1) ? WAVE_MAPPER : m_uDevId;
  379. mmr = waveOutOpen ((HWAVEOUT *) &m_hDev, uDevId,
  380. (WAVEFORMATEX *) m_pDevFmt,
  381. (DWORD_PTR) m_hEvent, 0, dwfOpen);
  382. // begin hack
  383. if (mmr == WAVERR_BADFORMAT && uDevId != WAVE_MAPPER) {
  384. // the sound card probably doesnt support our sample size or sample rate
  385. // (16 bit, 8Khz)
  386. // Try using the WAVE_MAPPER. The WAVE_MAPPER may end up using
  387. // a different device than the one we wanted !!
  388. DEBUGMSG (1, ("MediaControl::Open: bad format, trying WAVE_MAPPER\r\n" ));
  389. mmr = waveOutOpen((HWAVEOUT *) &m_hDev, WAVE_MAPPER,
  390. (WAVEFORMATEX *) m_pDevFmt,
  391. (DWORD_PTR) m_hEvent, 0, dwfOpen);
  392. if (mmr == MMSYSERR_NOERROR)
  393. m_uDevId = (UINT) -1; // use WAVE_MAPPER next time
  394. }
  395. // end hack
  396. if (mmr != MMSYSERR_NOERROR)
  397. {
  398. DEBUGMSG (1, ("MediaControl::Open: waveOutOpen failed, mmr=%ld\r\n", (ULONG) mmr));
  399. hr = DPR_CANT_OPEN_WAVE_DEV;
  400. goto MyExit;
  401. }
  402. else
  403. {
  404. hr = DPR_SUCCESS;
  405. }
  406. MyExit:
  407. return hr;
  408. }
  409. HRESULT WaveInControl::Close ( void )
  410. {
  411. HRESULT hr = DPR_INVALID_PLATFORM;
  412. MMRESULT mmr;
  413. if (m_hDev)
  414. {
  415. mmr = waveInClose ((HWAVEIN) m_hDev);
  416. if (mmr != MMSYSERR_NOERROR)
  417. {
  418. DEBUGMSG (1, ("MediaControl::CloseAudioDev: waveInClose failed, mmr=%ld\r\n", (ULONG) mmr));
  419. hr = DPR_CANT_CLOSE_WAVE_DEV;
  420. }
  421. else
  422. {
  423. hr = DPR_SUCCESS;
  424. }
  425. }
  426. else
  427. {
  428. hr = DPR_INVALID_HANDLE;
  429. }
  430. m_hDev = NULL;
  431. return hr;
  432. }
  433. HRESULT WaveOutControl::Close ( void )
  434. {
  435. HRESULT hr = DPR_INVALID_PLATFORM;
  436. MMRESULT mmr;
  437. if (m_hDev)
  438. {
  439. mmr = waveOutClose ((HWAVEOUT) m_hDev);
  440. if (mmr != MMSYSERR_NOERROR)
  441. {
  442. DEBUGMSG (1, ("MediaControl::CloseAudioDev: waveOutClose failed, mmr=%ld\r\n", (ULONG) mmr));
  443. hr = DPR_CANT_CLOSE_WAVE_DEV;
  444. }
  445. else
  446. {
  447. hr = DPR_SUCCESS;
  448. }
  449. }
  450. else
  451. {
  452. hr = DPR_INVALID_HANDLE;
  453. }
  454. m_hDev = NULL;
  455. return hr;
  456. }
  457. HRESULT WaveInControl::Start ( void )
  458. {
  459. HRESULT hr = DPR_INVALID_PLATFORM;
  460. MMRESULT mmr;
  461. if (m_hDev)
  462. {
  463. mmr = waveInStart ((HWAVEIN) m_hDev);
  464. if (mmr != MMSYSERR_NOERROR)
  465. {
  466. DEBUGMSG (1, ("MediaControl::StartAudioDev: waveInStart failed, mmr=%ld\r\n", (ULONG) mmr));
  467. hr = DPR_CANT_START_WAVE_DEV;
  468. }
  469. else
  470. {
  471. hr = DPR_SUCCESS;
  472. }
  473. }
  474. else
  475. {
  476. hr = DPR_INVALID_HANDLE;
  477. }
  478. return hr;
  479. }
  480. HRESULT WaveOutControl::Start ( void )
  481. {
  482. return DPR_SUCCESS;
  483. }
  484. HRESULT WaveOutControl::Stop( void )
  485. {
  486. return DPR_INVALID_PARAMETER;
  487. }
  488. HRESULT WaveInControl::Stop ( void )
  489. {
  490. HRESULT hr = DPR_INVALID_PLATFORM;
  491. MMRESULT mmr;
  492. if (m_hDev)
  493. {
  494. mmr = waveInStop ((HWAVEIN) m_hDev);
  495. if (mmr != MMSYSERR_NOERROR)
  496. {
  497. DEBUGMSG (1, ("MediaControl::StopAudioDev: waveInStop failed, mmr=%ld\r\n", (ULONG) mmr));
  498. hr = DPR_CANT_STOP_WAVE_DEV;
  499. }
  500. else
  501. {
  502. hr = DPR_SUCCESS;
  503. }
  504. }
  505. else
  506. {
  507. hr = DPR_INVALID_HANDLE;
  508. }
  509. return hr;
  510. }
  511. HRESULT WaveInControl::Reset ( void )
  512. {
  513. HRESULT hr;
  514. MMRESULT mmr;
  515. if (m_hDev)
  516. {
  517. mmr = waveInReset ((HWAVEIN) m_hDev);
  518. if (mmr != MMSYSERR_NOERROR)
  519. {
  520. DEBUGMSG (1, ("MediaControl::ResetAudioDev: waveInReset failed, mmr=%ld\r\n", (ULONG) mmr));
  521. hr = DPR_CANT_RESET_WAVE_DEV;
  522. }
  523. else
  524. {
  525. hr = DPR_SUCCESS;
  526. }
  527. }
  528. else
  529. {
  530. hr = DPR_INVALID_HANDLE;
  531. }
  532. return hr;
  533. }
  534. HRESULT WaveOutControl::Reset ( void )
  535. {
  536. HRESULT hr;
  537. MMRESULT mmr;
  538. if (m_hDev)
  539. {
  540. mmr = waveOutReset ((HWAVEOUT) m_hDev);
  541. if (mmr != MMSYSERR_NOERROR)
  542. {
  543. DEBUGMSG (1, ("MediaControl::ResetAudioDev: waveOutReset failed, mmr=%ld\r\n", (ULONG) mmr));
  544. hr = DPR_CANT_RESET_WAVE_DEV;
  545. }
  546. else
  547. {
  548. hr = DPR_SUCCESS;
  549. }
  550. }
  551. else
  552. {
  553. hr = DPR_INVALID_HANDLE;
  554. }
  555. return hr;
  556. }
  557. HRESULT WaveInControl::SetProp ( DWORD dwPropId, DWORD_PTR dwPropVal )
  558. {
  559. HRESULT hr = DPR_SUCCESS;
  560. MMRESULT mmr;
  561. switch (dwPropId)
  562. {
  563. case MC_PROP_VOICE_SWITCH:
  564. m_dwFlags = (DWORD)((m_dwFlags & ~DP_MASK_VOICESWITCH) | (dwPropVal & DP_MASK_VOICESWITCH));
  565. break;
  566. case MC_PROP_SILENCE_DURATION:
  567. if (dwPropVal == MC_USING_DEFAULT)
  568. m_uSilenceDuration = MC_DEF_SILENCE_DURATION;
  569. else
  570. m_uSilenceDuration = (DWORD)dwPropVal; //ms
  571. break;
  572. case MC_PROP_TIMEOUT:
  573. m_uTimeout = (DWORD)dwPropVal;
  574. break;
  575. case MC_PROP_PREFEED:
  576. m_uPrefeed = (DWORD)dwPropVal;
  577. break;
  578. default:
  579. hr = MediaControl::SetProp(dwPropId, dwPropVal );
  580. break;
  581. }
  582. return hr;
  583. }
  584. HRESULT WaveOutControl::SetProp ( DWORD dwPropId, DWORD_PTR dwPropVal )
  585. {
  586. HRESULT hr = DPR_SUCCESS;
  587. MMRESULT mmr;
  588. switch (dwPropId)
  589. {
  590. case MC_PROP_VOICE_SWITCH:
  591. m_dwFlags = (DWORD)((m_dwFlags & ~DP_MASK_VOICESWITCH) | (dwPropVal & DP_MASK_VOICESWITCH));
  592. break;
  593. case MC_PROP_VOLUME:
  594. if (m_dwFlags & DP_FLAG_SEND)
  595. {
  596. hr = DPR_INVALID_PARAMETER;
  597. goto MyExit;
  598. }
  599. if (dwPropVal == MC_USING_DEFAULT) // dont change the volume
  600. break;
  601. // this is in units of % of maximum. Scale it to mmsystem.
  602. dwPropVal = min(dwPropVal, 100);
  603. dwPropVal *= 655;
  604. dwPropVal |= (dwPropVal << 16);
  605. mmr = waveOutSetVolume ((HWAVEOUT) m_hDev, (DWORD)dwPropVal);
  606. if (mmr != MMSYSERR_NOERROR)
  607. {
  608. hr = DPR_CANT_SET_VOLUME;
  609. goto MyExit;
  610. }
  611. m_uVolume = (DWORD)dwPropVal;
  612. break;
  613. case MC_PROP_TIMEOUT:
  614. m_uTimeout = (DWORD)dwPropVal;
  615. break;
  616. case MC_PROP_PREFEED:
  617. m_uPrefeed = (DWORD)dwPropVal;
  618. break;
  619. default:
  620. hr = MediaControl::SetProp(dwPropId, dwPropVal );
  621. break;
  622. }
  623. MyExit:
  624. return hr;
  625. }
  626. char LogScale[] = {0, 3, 6, 9, 11, 13, 15,
  627. 17, 19, 21, 23, 24, 26, 27, 28, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
  628. 42, 43, 43, 44, 45, 46, 46, 47, 48, 48, 49, 50, 50, 51, 51, 52, 52, 53, 54, 54,
  629. 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 59, 60, 60, 61, 61, 62, 62, 62, 63, 63,
  630. 64, 64, 64, 65, 65, 65, 66, 66, 66, 67, 67, 67, 68, 68, 68, 69, 69, 69, 70, 70,
  631. 70, 71, 71, 71, 71, 72, 72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 75,
  632. 76, 76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 79, 79, 80, 80, 80,
  633. 80, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 83, 83, 83, 83, 83, 84, 84, 84, 84,
  634. 84, 84, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 88,
  635. 88, 88, 88, 88, 88, 89, 89, 89, 89, 89, 89, 89, 90, 90, 90, 90, 90, 90, 91, 91,
  636. 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93,
  637. 94, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96,
  638. 96, 96, 96, 97, 97, 97, 97, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98,
  639. 99, 99, 99, 99, 99, 99, 99, 99, 100};
  640. HRESULT WaveInControl::GetProp ( DWORD dwPropId, PDWORD_PTR pdwPropVal )
  641. {
  642. HRESULT hr = DPR_SUCCESS;
  643. if (pdwPropVal)
  644. {
  645. switch (dwPropId)
  646. {
  647. case MC_PROP_SILENCE_DURATION:
  648. *pdwPropVal = m_uSilenceDuration;
  649. break;
  650. case MC_PROP_TIMEOUT:
  651. *pdwPropVal = m_uTimeout;
  652. break;
  653. case MC_PROP_PREFEED:
  654. *pdwPropVal = m_uPrefeed;
  655. break;
  656. case MC_PROP_VOICE_SWITCH:
  657. *pdwPropVal = m_dwFlags & DP_MASK_VOICESWITCH;
  658. break;
  659. case MC_PROP_SPP:
  660. // *pdwPropVal = (DWORD) ((WAVEFORMATEX *) m_pDevFmt)->nSamplesPerSec
  661. // * m_uDuration / 100UL;
  662. *pdwPropVal = m_cbSizeDevData * (DWORD) ((WAVEFORMATEX *) m_pDevFmt)->nSamplesPerSec
  663. /(DWORD) ((WAVEFORMATEX *) m_pDevFmt)->nAvgBytesPerSec;
  664. break;
  665. case MC_PROP_SPS:
  666. *pdwPropVal = (DWORD) ((WAVEFORMATEX *) m_pDevFmt)->nSamplesPerSec;
  667. break;
  668. default:
  669. hr = MediaControl::GetProp( dwPropId, pdwPropVal );
  670. break;
  671. }
  672. }
  673. else
  674. {
  675. hr = DPR_INVALID_PARAMETER;
  676. }
  677. return hr;
  678. }
  679. HRESULT WaveOutControl::GetProp ( DWORD dwPropId, PDWORD_PTR pdwPropVal )
  680. {
  681. HRESULT hr = DPR_SUCCESS;
  682. if (pdwPropVal)
  683. {
  684. switch (dwPropId)
  685. {
  686. case MC_PROP_VOLUME:
  687. *pdwPropVal = m_uVolume;
  688. break;
  689. case MC_PROP_TIMEOUT:
  690. *pdwPropVal = m_uTimeout;
  691. break;
  692. case MC_PROP_PREFEED:
  693. *pdwPropVal = m_uPrefeed;
  694. break;
  695. case MC_PROP_VOICE_SWITCH:
  696. *pdwPropVal = m_dwFlags & DP_MASK_VOICESWITCH;
  697. break;
  698. case MC_PROP_SPP:
  699. // *pdwPropVal = (DWORD) ((WAVEFORMATEX *) m_pDevFmt)->nSamplesPerSec
  700. // * m_uDuration / 100UL;
  701. *pdwPropVal = m_cbSizeDevData * (DWORD) ((WAVEFORMATEX *) m_pDevFmt)->nSamplesPerSec
  702. /(DWORD) ((WAVEFORMATEX *) m_pDevFmt)->nAvgBytesPerSec;
  703. break;
  704. case MC_PROP_SPS:
  705. *pdwPropVal = (DWORD) ((WAVEFORMATEX *) m_pDevFmt)->nSamplesPerSec;
  706. break;
  707. default:
  708. hr = MediaControl::GetProp( dwPropId, pdwPropVal );
  709. break;
  710. }
  711. }
  712. else
  713. {
  714. hr = DPR_INVALID_PARAMETER;
  715. }
  716. return hr;
  717. }