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.

299 lines
8.7 KiB

  1. // Copyright (c) 1998-1999 Microsoft Corporation
  2. /*
  3. * Internal function prototypes for DMusic32.dll
  4. */
  5. #ifndef _DM32P_
  6. #define _DM32P_
  7. #include "..\shared\dmusiccp.h"
  8. #include "tpool.h"
  9. #define THREAD_KILL_TIMEOUT 5000
  10. #define THREAD_WORK_BUFFER_SIZE 4096
  11. #define QWORD_ALIGN(x) (((x) + 7) & ~7)
  12. #define MIDI_CHANNELS 16
  13. /* DevIoctl.c - MMDEVLDR hooks we use
  14. */
  15. extern BOOL WINAPI OpenMMDEVLDR(void);
  16. extern VOID WINAPI CloseMMDEVLDR(void);
  17. extern VOID WINAPI CloseVxDHandle(DWORD hVxDHandle);
  18. /* From Win32 kernel
  19. */
  20. extern "C" DWORD WINAPI OpenVxDHandle(HANDLE hEvent);
  21. // 10 ms in 100ns units
  22. //
  23. #define FIXED_LEGACY_LATENCY_OFFSET (10L * 10L * 1000L)
  24. class CEmulateLatencyClock : public IReferenceClock
  25. {
  26. public:
  27. // IUnknown
  28. //
  29. STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  30. STDMETHODIMP_(ULONG) AddRef();
  31. STDMETHODIMP_(ULONG) Release();
  32. // IReferenceClock
  33. //
  34. STDMETHODIMP GetTime(REFERENCE_TIME *pTime);
  35. STDMETHODIMP AdviseTime(REFERENCE_TIME baseTime,
  36. REFERENCE_TIME streamTime,
  37. HANDLE hEvent,
  38. DWORD * pdwAdviseCookie);
  39. STDMETHODIMP AdvisePeriodic(REFERENCE_TIME startTime,
  40. REFERENCE_TIME periodTime,
  41. HANDLE hSemaphore,
  42. DWORD * pdwAdviseCookie);
  43. STDMETHODIMP Unadvise(DWORD dwAdviseCookie);
  44. // Class
  45. //
  46. CEmulateLatencyClock(IReferenceClock *pMasterClock);
  47. ~CEmulateLatencyClock();
  48. void Close();
  49. private:
  50. long m_cRef;
  51. IReferenceClock *m_pMasterClock;
  52. };
  53. // Struct for holding a property item supported by the synth
  54. //
  55. class CDirectMusicEmulatePort;
  56. typedef HRESULT (CDirectMusicEmulatePort::*GENPROPHANDLER)(ULONG ulId, BOOL fSet, LPVOID pbBuffer, PULONG cbBuffer);
  57. #define GENPROP_F_STATIC 0x00000000
  58. #define GENPROP_F_FNHANDLER 0x00000001
  59. struct GENERICPROPERTY
  60. {
  61. const GUID *pguidPropertySet; // What property set?
  62. ULONG ulId; // What item?
  63. ULONG ulSupported; // Get/Set flags for QuerySupported
  64. ULONG ulFlags; // GENPROP_F_xxx
  65. LPVOID pPropertyData; // Data to be returned
  66. ULONG cbPropertyData; // and its size
  67. GENPROPHANDLER pfnHandler; // Handler fn iff GENPROP_F_FNHANDLER
  68. };
  69. class CDirectMusicEmulatePort :
  70. public IDirectMusicPort,
  71. public IDirectMusicPortP,
  72. public IDirectMusicThru,
  73. public IDirectMusicPortPrivate,
  74. public IKsControl
  75. {
  76. public:
  77. // IUnknown
  78. //
  79. STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  80. STDMETHODIMP_(ULONG) AddRef();
  81. STDMETHODIMP_(ULONG) Release();
  82. // IDirectMusicPort
  83. //
  84. STDMETHODIMP PlayBuffer(LPDIRECTMUSICBUFFER pBuffer);
  85. STDMETHODIMP SetReadNotificationHandle(HANDLE hEvent);
  86. STDMETHODIMP Read(LPDIRECTMUSICBUFFER pBuffer);
  87. STDMETHODIMP DownloadInstrument(IDirectMusicInstrument*,
  88. IDirectMusicDownloadedInstrument**,
  89. DMUS_NOTERANGE*,
  90. DWORD);
  91. STDMETHODIMP UnloadInstrument(IDirectMusicDownloadedInstrument*);
  92. STDMETHODIMP GetLatencyClock(IReferenceClock **ppClock);
  93. STDMETHODIMP GetRunningStats(LPDMUS_SYNTHSTATS pStats);
  94. STDMETHODIMP Compact();
  95. STDMETHODIMP GetCaps(LPDMUS_PORTCAPS pPortCaps);
  96. STDMETHODIMP DeviceIoControl(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
  97. LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped);
  98. STDMETHODIMP SetNumChannelGroups(DWORD dwNumChannelGroups);
  99. STDMETHODIMP GetNumChannelGroups(LPDWORD pdwNumChannelGroups);
  100. STDMETHODIMP Activate(BOOL fActivate);
  101. STDMETHODIMP SetChannelPriority(DWORD dwChannelGroup, DWORD dwChannel, DWORD dwPriority);
  102. STDMETHODIMP GetChannelPriority(DWORD dwChannelGroup, DWORD dwChannel, LPDWORD pdwPriority);
  103. STDMETHODIMP SetDirectSound(LPDIRECTSOUND pDirectSound, LPDIRECTSOUNDBUFFER pDirectSoundBuffer);
  104. STDMETHODIMP GetFormat(LPWAVEFORMATEX pWaveFormatEx, LPDWORD pdwWaveFormatExSize, LPDWORD pdwBufferSize);
  105. // IDirectMusicThru
  106. STDMETHODIMP ThruChannel(DWORD dwSourceChannelGroup,
  107. DWORD dwSourceChannel,
  108. DWORD dwDestinationChannelGroup,
  109. DWORD dwDestinationChannel,
  110. LPDIRECTMUSICPORT pDestinationPort);
  111. // IDirectMusicPortP
  112. //
  113. STDMETHODIMP DownloadWave(
  114. IN IDirectSoundWave *pWave,
  115. OUT IDirectSoundDownloadedWaveP **ppWave,
  116. IN REFERENCE_TIME rtStartHint
  117. );
  118. STDMETHODIMP UnloadWave(
  119. IN IDirectSoundDownloadedWaveP *pWave
  120. );
  121. STDMETHODIMP AllocVoice(
  122. IN IDirectSoundDownloadedWaveP *pWave,
  123. IN DWORD dwChannel,
  124. IN DWORD dwChannelGroup,
  125. IN REFERENCE_TIME rtStart,
  126. IN SAMPLE_TIME stLoopStart,
  127. IN SAMPLE_TIME stLoopEnd,
  128. OUT IDirectMusicVoiceP **ppVoice
  129. );
  130. STDMETHODIMP AssignChannelToBuses(
  131. IN DWORD dwChannelGroup,
  132. IN DWORD dwChannel,
  133. IN LPDWORD pdwBuses,
  134. IN DWORD cBusCount
  135. );
  136. STDMETHODIMP SetSink(
  137. IN IDirectSoundConnect *pSinkConnect
  138. );
  139. STDMETHODIMP GetSink(
  140. IN IDirectSoundConnect **ppSinkConnect
  141. );
  142. // IKsControl
  143. STDMETHODIMP KsProperty(
  144. IN PKSPROPERTY Property,
  145. IN ULONG PropertyLength,
  146. IN OUT LPVOID PropertyData,
  147. IN ULONG DataLength,
  148. OUT PULONG BytesReturned
  149. );
  150. STDMETHODIMP KsMethod(
  151. IN PKSMETHOD Method,
  152. IN ULONG MethodLength,
  153. IN OUT LPVOID MethodData,
  154. IN ULONG DataLength,
  155. OUT PULONG BytesReturned
  156. );
  157. STDMETHODIMP KsEvent(
  158. IN PKSEVENT Event,
  159. IN ULONG EventLength,
  160. IN OUT LPVOID EventData,
  161. IN ULONG DataLength,
  162. OUT PULONG BytesReturned
  163. );
  164. // IDirectMusicPortPrivate
  165. STDMETHODIMP Close();
  166. STDMETHODIMP Report();
  167. STDMETHODIMP StartVoice(
  168. DWORD dwVoiceId,
  169. DWORD dwChannel,
  170. DWORD dwChannelGroup,
  171. REFERENCE_TIME rtStart,
  172. DWORD dwDLId,
  173. LONG prPitch,
  174. LONG veVolume,
  175. SAMPLE_TIME stVoiceStart,
  176. SAMPLE_TIME stLoopStart,
  177. SAMPLE_TIME stLoopEnd
  178. );
  179. STDMETHODIMP StopVoice(
  180. DWORD dwVoiceID,
  181. REFERENCE_TIME rtStop
  182. );
  183. STDMETHODIMP GetVoiceState(
  184. DWORD dwVoice[],
  185. DWORD cbVoice,
  186. DMUS_VOICE_STATE VoiceState[]
  187. );
  188. STDMETHODIMP Refresh(
  189. DWORD dwDownloadID,
  190. DWORD dwFlags
  191. );
  192. // Class
  193. //
  194. CDirectMusicEmulatePort(PORTENTRY *pPE, CDirectMusic *pDM);
  195. ~CDirectMusicEmulatePort();
  196. HRESULT Init(LPDMUS_PORTPARAMS pPortParams);
  197. HRESULT LegacyCaps(ULONG ulId, BOOL fSet, LPVOID pbBuffer, PULONG cbBuffer);
  198. DWORD InputWorker();
  199. DWORD TimerWorker();
  200. private:
  201. long m_cRef;
  202. UINT m_id;
  203. BOOL m_fIsOutput;
  204. HANDLE m_hDevice;
  205. CDirectMusic *m_pDM;
  206. DWORD m_hVxDEvent;
  207. DMUS_PORTCAPS dmpc;
  208. IReferenceClock *m_pMasterClock;
  209. CEmulateLatencyClock *m_pLatencyClock;
  210. IDirectMusicPortNotify *m_pNotify;
  211. HANDLE m_hAppEvent;
  212. HANDLE m_hDataReady;
  213. HANDLE m_hKillThreads;
  214. HANDLE m_hCaptureThread;
  215. BYTE m_WorkBuffer[THREAD_WORK_BUFFER_SIZE];
  216. DWORD m_dwWorkBufferTileInfo;
  217. DWORD m_p1616WorkBuffer;
  218. EVENT_POOL m_FreeEvents;
  219. EVENT_QUEUE m_ReadEvents;
  220. CRITICAL_SECTION m_csEventQueues;
  221. BOOL m_fCSInitialized;
  222. IDirectMusicBuffer *m_pThruBuffer;
  223. LPDMUS_THRU_CHANNEL m_pThruMap;
  224. long m_lActivated;
  225. BOOL m_fSyncToMaster;
  226. LONGLONG m_lTimeOffset;
  227. private:
  228. static GENERICPROPERTY m_aProperty[];
  229. static const int m_nProperty;
  230. static GENERICPROPERTY *FindPropertyItem(REFGUID rguid, ULONG ulId);
  231. private:
  232. HRESULT InitializeClock();
  233. HRESULT InitializeCapture();
  234. void InputWorkerDataReady();
  235. void ThruEvent(DMEVENT *pEvent);
  236. void MasterToSlave(REFERENCE_TIME *prt);
  237. void SlaveToMaster(REFERENCE_TIME *prt);
  238. void SyncClocks();
  239. };
  240. #endif