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.

691 lines
15 KiB

  1. /****************************************************************************
  2. *
  3. * wdmdrv.h
  4. *
  5. * Function declarations, etc. for WDMAUD.DRV
  6. *
  7. * Copyright (C) Microsoft Corporation, 1997 - 1999 All Rights Reserved.
  8. *
  9. * History
  10. * 5-12-97 - Noel Cross (NoelC)
  11. *
  12. ***************************************************************************/
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <windows.h>
  19. #include <windowsx.h>
  20. #include <mmsystem.h>
  21. #include <mmddk.h>
  22. #include <ks.h>
  23. #include <ksmedia.h>
  24. #include <setupapi.h>
  25. #ifdef UNDER_NT
  26. #if (DBG)
  27. #define DEBUG
  28. #endif
  29. #endif
  30. #include <wdmaud.h>
  31. #include <midi.h>
  32. /***************************************************************************
  33. DEBUGGING SUPPORT
  34. ***************************************************************************/
  35. #ifdef DEBUG
  36. extern VOID FAR __cdecl wdmaudDbgOut(LPSTR lpszFormat, ...);
  37. extern UINT uiDebugLevel; // debug level
  38. extern char szReturningErrorStr[];
  39. extern char *MsgToAscii(ULONG ulMsg);
  40. //
  41. // Debug message levels:
  42. //
  43. #define DL_ERROR 0x00000000
  44. #define DL_WARNING 0x00000001
  45. #define DL_TRACE 0x00000002
  46. #define DL_MAX 0x00000004
  47. #define DL_MASK 0x000000FF
  48. //
  49. // 20 bits reserved for functional areas. If we find that this bit is set
  50. // in the DebugLevel variable, we will display every message of this type.
  51. //
  52. #define FA_AUX 0x80000000
  53. #define FA_DEVICEIO 0x40000000
  54. #define FA_SETUP 0x20000000
  55. #define FA_MIDI 0x10000000
  56. #define FA_WAVE 0x08000000
  57. #define FA_RECORD 0x04000000
  58. #define FA_EVENT 0x02000000
  59. #define FA_MIXER 0x01000000
  60. #define FA_DRV 0x00800000
  61. #define FA_ASSERT 0x00400000
  62. #define FA_RETURN 0x00200000
  63. #define FA_SYNC 0x00100000
  64. #define FA_MASK 0xFFFFF000
  65. #define FA_ALL 0x00001000
  66. extern VOID
  67. wdmaudDbgBreakPoint(
  68. );
  69. extern UINT
  70. wdmaudDbgPreCheckLevel(
  71. UINT uiMsgLevel,
  72. char *pFunction,
  73. int iLine
  74. );
  75. extern UINT
  76. wdmaudDbgPostCheckLevel(
  77. UINT uiMsgLevel
  78. );
  79. extern char *
  80. wdmaudReturnString(
  81. ULONG ulMsg
  82. );
  83. extern char szReturningErrorStr[];
  84. //----------------------------------------------------------------------------
  85. //
  86. // This debug macro is used like this:
  87. //
  88. // DPF(DL_WARNING|FA_MIXER,("Message %X %X %X ...",x,y,z,...) );
  89. //
  90. // The output for this message will look like:
  91. //
  92. // WDMAUD.DRV FooFunction Warning Message 5 6 7 - Set BP on 64003452 to DBG
  93. //
  94. // The only difference between this code and the code in wdmaud.sys is that
  95. // to break in the debugger, you call DbgBreak() and to display a string you
  96. // call OutputDebugString(...).
  97. //
  98. // The call to wdmaudDbgPreCheckLevel displays:
  99. //
  100. // "WDMAUD.DRV FooFunction Warning "
  101. //
  102. // The call to wdmaudDbgOut displays the actual message
  103. //
  104. // "Message 5 6 7 ..."
  105. //
  106. // and the call to wdmaudDbgPostCheckLevel finishs the line
  107. //
  108. // " - Set BP on 64003452 to DBG"
  109. //
  110. //----------------------------------------------------------------------------
  111. #define DPF(_x_,_y_) {if( wdmaudDbgPreCheckLevel(_x_,__FUNCTION__,__LINE__) ) { wdmaudDbgOut _y_; \
  112. wdmaudDbgPostCheckLevel( _x_ ); }}
  113. //
  114. // Warning: Do not rap function calls in this return macro! Notice that
  115. // _mmr_ is used more then once, thus the function call would be made more
  116. // than once!
  117. //
  118. #define MMRRETURN( _mmr_ ) {if ( _mmr_ != MMSYSERR_NOERROR) \
  119. { DPF(DL_WARNING|FA_RETURN, (szReturningErrorStr, _mmr_,MsgToAscii(_mmr_)) ); } \
  120. return _mmr_;}
  121. //
  122. // It's bad form to put more then one expression in an assert macro. Why? because
  123. // you will not know exactly what expression failed the assert!
  124. //
  125. // dDbgAssert should be:
  126. //
  127. #define DPFASSERT(_exp_) {if( !(_exp_) ) {DPF(DL_ERROR|FA_ASSERT,("'%s'",#_exp_) );}}
  128. // #define WinAssert(exp) ((exp) ? (VOID)0 : dDbgAssert(#exp, __FILE__, __LINE__))
  129. #define DbgBreak() DebugBreak()
  130. // The path trap macro ...
  131. #define DPFBTRAP() DPF(DL_ERROR|FA_ASSERT,("Path Trap, Please report") );
  132. //
  133. // There are a number of internal structures that we want to keep tabs on. In
  134. // every case, there will be a signature in the structure that we can use when
  135. // verifying the content.
  136. //
  137. #define WAVEPREPAREDATA_SIGNATURE 'DPPW' //WPPD as seen in memory
  138. #define MIXERINSTANCE_SIGNATURE 'IMAW' // WAMI as seen in memory
  139. #else
  140. #define DPF( _x_,_y_ )
  141. #define MMRRETURN( _mmr_ ) return (_mmr_)
  142. #define DPFASSERT(x) 0
  143. #define DbgBreak()
  144. #endif
  145. #ifdef DEBUG
  146. //
  147. // Here are a couple of defines used to look for corruption paths
  148. //
  149. #define FOURTYTHREE 0x43434343
  150. #define FOURTYTWO 0x42424242
  151. #define FOURTYEIGHT 0x48484848
  152. #else
  153. #define FOURTYTHREE NULL
  154. #define FOURTYTWO NULL
  155. #define FOURTYEIGHT NULL
  156. #endif
  157. /***************************************************************************
  158. UNICODE SUPPORT
  159. ***************************************************************************/
  160. //
  161. // Taken from winnt.h
  162. //
  163. // Neutral ANSI/UNICODE types and macros
  164. //
  165. #ifdef UNICODE
  166. #ifndef _TCHAR_DEFINED
  167. typedef WCHAR TCHAR, *PTCHAR;
  168. #define _TCHAR_DEFINED
  169. #define TEXT(quote) L##quote
  170. #endif /* !_TCHAR_DEFINED */
  171. #else /* UNICODE */
  172. #ifndef _TCHAR_DEFINED
  173. typedef char TCHAR, *PTCHAR;
  174. #define _TCHAR_DEFINED
  175. #define TEXT(quote) quote
  176. #endif /* !_TCHAR_DEFINED */
  177. #endif /* UNICODE */
  178. /****************************************************************************
  179. Random defines and global variables
  180. ***************************************************************************/
  181. #define WDMAUD_MAX_DEVICES 100
  182. extern LPDEVICEINFO pWaveDeviceList;
  183. extern LPDEVICEINFO pMidiDeviceList;
  184. extern CRITICAL_SECTION wdmaudCritSec;
  185. #ifdef UNDER_NT
  186. #define CRITENTER EnterCriticalSection( (LPCRITICAL_SECTION)DeviceInfo->DeviceState->csQueue )
  187. #define CRITLEAVE LeaveCriticalSection( (LPCRITICAL_SECTION)DeviceInfo->DeviceState->csQueue )
  188. #else
  189. extern WORD gwCritLevel ; // critical section counter
  190. #define CRITENTER if (!(gwCritLevel++)) _asm { cli }
  191. #define CRITLEAVE if (!(--gwCritLevel)) _asm { sti }
  192. #endif
  193. #ifdef UNDER_NT
  194. #define CALLBACKARRAYSIZE 128
  195. typedef struct {
  196. DWORD dwID;
  197. DWORD dwCallbackType;
  198. } CBINFO;
  199. typedef struct {
  200. ULONG GlobalIndex;
  201. CBINFO Callbacks[CALLBACKARRAYSIZE];
  202. } CALLBACKS, *PCALLBACKS;
  203. #endif
  204. //
  205. // These two macros are for validating error return codes from wdmaud.sys.
  206. //
  207. // This first one sets the input and output buffer for a DeviceIoControl call to
  208. // a known bad value.
  209. //
  210. #define PRESETERROR(_di) _di->mmr=0xDEADBEEF
  211. //
  212. // This macro reads: if the return value from wdmaudIoControl is SUCCESS THEN
  213. // check to see if there was an error code placed in the device info structure.
  214. // If so (we don't find DEADBEEF there), that is the real error value to return.
  215. // But, if during the call the value didn't get set, we'll find DEADBEEF in the
  216. // error location! Thus,the check for DEADBEEF that simply restores the device
  217. // info mmr entry to SUCCESS.
  218. //
  219. #define POSTEXTRACTERROR(r, _di) if( r == MMSYSERR_NOERROR ) { \
  220. if( _di->mmr != 0xDEADBEEF ) { \
  221. r = _di->mmr; \
  222. } else { \
  223. DPF(DL_TRACE|FA_DEVICEIO, ("wdmaudIoControl didn't set mmr %X:%s", r, MsgToAscii(r)) ); \
  224. _di->mmr = MMSYSERR_NOERROR; } }
  225. #define EXTRACTERROR(r, _di) if( r == MMSYSERR_NOERROR ) { r = _di->mmr; }
  226. /****************************************************************************
  227. Struture definitions
  228. ***************************************************************************/
  229. typedef struct _WAVEPREPAREDATA
  230. {
  231. struct _DEVICEINFO FAR *pdi;
  232. LPOVERLAPPED pOverlapped; // Overlapped structure
  233. // for completion
  234. #ifdef DEBUG
  235. DWORD dwSig; // WPPD
  236. #endif
  237. } WAVEPREPAREDATA, FAR *PWAVEPREPAREDATA;
  238. /****************************************************************************
  239. Driver entry points
  240. ***************************************************************************/
  241. BOOL FAR PASCAL LibMain
  242. (
  243. HANDLE hInstance,
  244. WORD wHeapSize,
  245. LPSTR lpszCmdLine
  246. );
  247. BOOL WINAPI DllEntryPoint
  248. (
  249. HINSTANCE hinstDLL,
  250. DWORD fdwReason,
  251. LPVOID lpvReserved
  252. );
  253. LRESULT _loadds CALLBACK DriverProc
  254. (
  255. DWORD id,
  256. HDRVR hDriver,
  257. WORD msg,
  258. LPARAM lParam1,
  259. LPARAM lParam2
  260. );
  261. DWORD FAR PASCAL _loadds wodMessage
  262. (
  263. UINT id,
  264. UINT msg,
  265. DWORD_PTR dwUser,
  266. DWORD_PTR dwParam1,
  267. DWORD_PTR dwParam2
  268. );
  269. DWORD FAR PASCAL _loadds widMessage
  270. (
  271. UINT id,
  272. UINT msg,
  273. DWORD_PTR dwUser,
  274. DWORD_PTR dwParam1,
  275. DWORD_PTR dwParam2
  276. );
  277. DWORD FAR PASCAL _loadds modMessage
  278. (
  279. UINT id,
  280. UINT msg,
  281. DWORD_PTR dwUser,
  282. DWORD_PTR dwParam1,
  283. DWORD_PTR dwParam2
  284. );
  285. DWORD FAR PASCAL _loadds midMessage
  286. (
  287. UINT id,
  288. UINT msg,
  289. DWORD_PTR dwUser,
  290. DWORD_PTR dwParam1,
  291. DWORD_PTR dwParam2
  292. );
  293. DWORD FAR PASCAL _loadds mxdMessage
  294. (
  295. UINT id,
  296. UINT msg,
  297. DWORD_PTR dwUser,
  298. DWORD_PTR dwParam1,
  299. DWORD_PTR dwParam2
  300. );
  301. /****************************************************************************
  302. Local routines
  303. ***************************************************************************/
  304. BOOL DrvInit();
  305. HANDLE wdmaOpenKernelDevice();
  306. VOID DrvEnd();
  307. LPDEVICEINFO GlobalAllocDeviceInfo(LPCWSTR DeviceInterface);
  308. VOID GlobalFreeDeviceInfo(LPDEVICEINFO lpdi);
  309. MMRESULT wdmaudOpenDev
  310. (
  311. LPDEVICEINFO DeviceInfo,
  312. LPWAVEFORMATEX lpWaveFormat
  313. );
  314. MMRESULT FAR wdmaudCloseDev
  315. (
  316. LPDEVICEINFO DeviceInfo
  317. );
  318. MMRESULT FAR wdmaudGetDevCaps
  319. (
  320. LPDEVICEINFO DeviceInfo,
  321. MDEVICECAPSEX FAR *MediaDeviceCapsEx
  322. );
  323. DWORD FAR wdmaudGetNumDevs
  324. (
  325. UINT DeviceType,
  326. LPCWSTR DeviceInterface
  327. );
  328. DWORD FAR wdmaudAddRemoveDevNode
  329. (
  330. UINT DeviceType,
  331. LPCWSTR DeviceInterface,
  332. BOOL fAdd
  333. );
  334. DWORD FAR wdmaudSetPreferredDevice
  335. (
  336. UINT DeviceType,
  337. UINT DeviceNumber,
  338. DWORD_PTR dwParam1,
  339. DWORD_PTR dwParam2
  340. );
  341. MMRESULT FAR wdmaudIoControl
  342. (
  343. LPDEVICEINFO DeviceInfo,
  344. DWORD dwSize,
  345. LPVOID pData,
  346. ULONG IoCode
  347. );
  348. MMRESULT wdmaudSetDeviceState
  349. (
  350. LPDEVICEINFO DeviceInfo,
  351. ULONG IoCode
  352. );
  353. MMRESULT wdmaudGetPos
  354. (
  355. LPDEVICEINFO pClient,
  356. LPMMTIME lpmmt,
  357. DWORD dwSize,
  358. UINT DeviceType
  359. );
  360. VOID FAR midiCallback
  361. (
  362. LPDEVICEINFO pMidi,
  363. UINT msg,
  364. DWORD_PTR dw1,
  365. DWORD_PTR dw2
  366. );
  367. MMRESULT FAR midiOpen
  368. (
  369. LPDEVICEINFO DeviceInfo,
  370. DWORD_PTR dwUser,
  371. LPMIDIOPENDESC pmod,
  372. DWORD dwParam2
  373. );
  374. VOID FAR midiCleanUp
  375. (
  376. LPDEVICEINFO pClient
  377. );
  378. MMRESULT midiInRead
  379. (
  380. LPDEVICEINFO pClient,
  381. LPMIDIHDR pHdr
  382. );
  383. MMRESULT FAR midiOutWrite
  384. (
  385. LPDEVICEINFO pClient,
  386. DWORD ulEvent
  387. );
  388. VOID FAR midiOutAllNotesOff
  389. (
  390. LPDEVICEINFO pClient
  391. );
  392. VOID FAR waveCallback
  393. (
  394. LPDEVICEINFO pWave,
  395. UINT msg,
  396. DWORD_PTR dw1
  397. );
  398. MMRESULT waveOpen
  399. (
  400. LPDEVICEINFO DeviceInfo,
  401. DWORD_PTR dwUser,
  402. LPWAVEOPENDESC pwod,
  403. DWORD dwParam2
  404. );
  405. VOID waveCleanUp
  406. (
  407. LPDEVICEINFO pClient
  408. );
  409. MMRESULT waveWrite
  410. (
  411. LPDEVICEINFO pClient,
  412. LPWAVEHDR pHdr
  413. );
  414. MMRESULT wdmaudSubmitWaveHeader
  415. (
  416. LPDEVICEINFO DeviceInfo,
  417. LPWAVEHDR pHdr
  418. );
  419. MMRESULT FAR wdmaudSubmitMidiOutHeader
  420. (
  421. LPDEVICEINFO DeviceInfo,
  422. LPMIDIHDR pHdr
  423. );
  424. MMRESULT wdmaudSubmitMidiInHeader
  425. (
  426. LPDEVICEINFO DeviceInfo,
  427. LPMIDIHDR pHdrex
  428. );
  429. VOID waveCompleteHeader
  430. (
  431. LPDEVICEINFO DeviceInfo
  432. );
  433. VOID midiInCompleteHeader
  434. (
  435. LPDEVICEINFO DeviceInfo,
  436. DWORD dwTimeStamp,
  437. WORD wDataType
  438. );
  439. VOID midiInEventCallback
  440. (
  441. HANDLE MidiHandle,
  442. DWORD dwEvent
  443. );
  444. #ifdef UNDER_NT
  445. PSECURITY_DESCRIPTOR BuildSecurityDescriptor
  446. (
  447. DWORD AccessMask
  448. );
  449. void DestroySecurityDescriptor
  450. (
  451. PSECURITY_DESCRIPTOR pSd
  452. );
  453. MMRESULT wdmaudPrepareWaveHeader
  454. (
  455. LPDEVICEINFO DeviceInfo,
  456. LPWAVEHDR pHdr
  457. );
  458. MMRESULT wdmaudUnprepareWaveHeader
  459. (
  460. LPDEVICEINFO DeviceInfo,
  461. LPWAVEHDR pHdr
  462. );
  463. MMRESULT wdmaudGetMidiData
  464. (
  465. LPDEVICEINFO DeviceInfo,
  466. LPMIDIDATALISTENTRY pOldMidiDataListEntry
  467. );
  468. void wdmaudParseMidiData
  469. (
  470. LPDEVICEINFO DeviceInfo,
  471. LPMIDIDATALISTENTRY pMidiData
  472. );
  473. void wdmaudFreeMidiData
  474. (
  475. LPDEVICEINFO DeviceInfo,
  476. LPMIDIDATALISTENTRY pMidiData
  477. );
  478. MMRESULT wdmaudFreeMidiQ
  479. (
  480. LPDEVICEINFO DeviceInfo
  481. );
  482. MMRESULT wdmaudCreateCompletionThread
  483. (
  484. LPDEVICEINFO DeviceInfo
  485. );
  486. MMRESULT wdmaudDestroyCompletionThread
  487. (
  488. LPDEVICEINFO DeviceInfo
  489. );
  490. #endif
  491. MMRESULT
  492. IsValidDeviceInfo(
  493. LPDEVICEINFO lpDeviceInfo
  494. );
  495. MMRESULT
  496. IsValidDeviceState(
  497. LPDEVICESTATE lpDeviceState,
  498. BOOL bFullyConfigured
  499. );
  500. MMRESULT
  501. IsValidWaveHeader(
  502. LPWAVEHDR pWaveHdr
  503. );
  504. MMRESULT
  505. IsValidMidiHeader(
  506. LPMIDIHDR pMidiHdr
  507. );
  508. MMRESULT
  509. IsValidPrepareWaveHeader(
  510. PWAVEPREPAREDATA pPrepare
  511. );
  512. BOOL
  513. IsValidDeviceInterface(
  514. LPCWSTR DeviceInterface
  515. );
  516. MMRESULT
  517. IsValidOverLapped(
  518. LPOVERLAPPED lpol
  519. );
  520. MMRESULT
  521. IsValidMidiDataListEntry(
  522. LPMIDIDATALISTENTRY pMidiDataListEntry
  523. );
  524. MMRESULT
  525. IsValidWaveOpenDesc(
  526. LPWAVEOPENDESC pwod
  527. );
  528. #ifdef DEBUG
  529. #define ISVALIDDEVICEINFO(x) IsValidDeviceInfo(x)
  530. #define ISVALIDDEVICESTATE(x,y) IsValidDeviceState(x,y)
  531. #define ISVALIDWAVEHEADER(x) IsValidWaveHeader(x)
  532. #define ISVALIDMIDIHEADER(x) IsValidMidiHeader(x)
  533. #define ISVALIDPREPAREWAVEHEADER(x) IsValidPrepareWaveHeader(x)
  534. #define ISVALIDDEVICEINTERFACE(x) IsValidDeviceInterface(x)
  535. #define ISVALIDOVERLAPPED(x) IsValidOverLapped(x)
  536. #define ISVALIDMIDIDATALISTENTRY(x) IsValidMidiDataListEntry(x)
  537. #define ISVALIDWAVEOPENDESC(x) IsValidWaveOpenDesc(x)
  538. #else
  539. #define ISVALIDDEVICEINFO(x)
  540. #define ISVALIDDEVICESTATE(x,y)
  541. #define ISVALIDWAVEHEADER(x)
  542. #define ISVALIDMIDIHEADER(x)
  543. #define ISVALIDPREPAREWAVEHEADER(x)
  544. #define ISVALIDDEVICEINTERFACE(x)
  545. #define ISVALIDOVERLAPPED(x)
  546. #define ISVALIDMIDIDATALISTENTRY(x)
  547. #define ISVALIDWAVEOPENDESC(x)
  548. #endif
  549. #ifndef UNDER_NT
  550. VOID WaveDeviceCallback();
  551. VOID MidiInDeviceCallback();
  552. VOID MidiEventDeviceCallback();
  553. VOID MixerDeviceCallback();
  554. #endif
  555. PCALLBACKS wdmaGetCallbacks();
  556. PCALLBACKS wdmaCreateCallbacks();
  557. #ifdef __cplusplus
  558. }
  559. #endif