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.

306 lines
13 KiB

  1. // Copyright (c) 1998-1999 Microsoft Corporation
  2. // DMSStObj.h : Declaration of the CSegState
  3. #ifndef __AUDIOPATH_H_
  4. #define __AUDIOPATH_H_
  5. #include "dmusici.h"
  6. #include "dmusicf.h"
  7. #include "TrkList.h"
  8. #include "alist.h"
  9. #include "..\shared\dmstrm.h"
  10. #include "dmscriptautguids.h"
  11. #include "..\shared\dmusiccp.h"
  12. class CPerformance;
  13. class CSegState;
  14. class CGraph;
  15. class CAudioPathConfig;
  16. class CBufferConfig;
  17. struct IDirectSoundConnect;
  18. class CBufferNode : public AListItem
  19. {
  20. friend class CBufferManager;
  21. friend class CAudioPath;
  22. public:
  23. CBufferNode();
  24. ~CBufferNode();
  25. ULONG AddRef();
  26. ULONG Release();
  27. IDirectSoundBuffer *GetBuffer() { if (m_pBuffer) m_pBuffer->AddRef(); return m_pBuffer;}
  28. HRESULT Activate(BOOL fActivate);
  29. private:
  30. void FinalDeactivate();
  31. CBufferNode* GetNext() { return (CBufferNode*)AListItem::GetNext();}
  32. IDirectSoundBuffer * m_pBuffer; // DSound buffer that this manages.
  33. DMUS_IO_BUFFER_ATTRIBUTES_HEADER m_BufferHeader; // GUID that identifies this buffer and flags (can it be shared?).
  34. CBufferManager * m_pManager; // Pointer to parent list.
  35. long m_lActivateCount; // How many times this has been activated.
  36. long m_cRef; // How many objects point at this.
  37. };
  38. class CBufferManager : public AList
  39. {
  40. public:
  41. CBufferManager();
  42. ~CBufferManager() ;
  43. HRESULT Init(CPerformance *pPerf, DMUS_AUDIOPARAMS *pAudioParams) ;
  44. HRESULT InitSink();
  45. void AddHead(CBufferNode* pBufferNode) { AList::AddHead((AListItem*)pBufferNode);}
  46. CBufferNode* GetHead(){return (CBufferNode*)AList::GetHead();}
  47. CBufferNode* RemoveHead() {return (CBufferNode *) AList::RemoveHead();}
  48. void Remove(CBufferNode* pBufferNode){AList::Remove((AListItem*)pBufferNode);}
  49. void AddTail(CBufferNode* pBufferNode){AList::AddTail((AListItem*)pBufferNode);}
  50. void Clear();
  51. void FinalDeactivate();
  52. CBufferNode * GetBufferNode(REFGUID guidBufferID);
  53. HRESULT CreateBuffer(CBufferConfig *pConfig, CBufferConfig **pNew);
  54. private:
  55. CPerformance *m_pPerf; // Pointer to parent performance.
  56. CBufferConfig *m_pFirstBuffer; // Actual buffer created by config.
  57. public:
  58. IDirectSoundConnect* m_pSinkConnect; // The sink object which manages creation of buffers in dsound.
  59. IDirectSoundSynthSink *m_pSynthSink; // Used to activate sink.
  60. DMUS_AUDIOPARAMS m_AudioParams;
  61. };
  62. #define BUFFER_REVERB 1
  63. #define BUFFER_ENVREVERB 2
  64. #define BUFFER_3D 3
  65. #define BUFFER_3D_DRY 4
  66. #define BUFFER_MONO 6
  67. #define BUFFER_STEREO 7
  68. #define BUFFER_MUSIC 8
  69. DEFINE_GUID(GUID_Buffer_Primary,0x186cc544, 0xdb29, 0x11d3, 0x9b, 0xd1, 0x0, 0x80, 0xc7, 0x15, 0xa, 0x74);
  70. #define DMUS_BUFFERF_PRIMARY 4 // This buffer flag is a private definition.
  71. #define DMUS_STANDARD_PATH_DX7 20 // This is for internal use only.
  72. #define MAX_CONNECTIONS 32 // Maximum of 32 buffers connected to one PChannel.
  73. class CBufferConfig : public AListItem
  74. {
  75. public:
  76. CBufferConfig(DWORD dwType) ;
  77. ~CBufferConfig();
  78. void DecideType(); // Looks at embedded GUID and infers default type, if one exists.
  79. HRESULT Load(IStream *pStream);
  80. CBufferConfig* GetNext() { return (CBufferConfig*)AListItem::GetNext();}
  81. IUnknown * m_pBufferConfig; // Buffer definition.
  82. CBufferNode * m_pBufferNode; // Manages the DSound buffer.
  83. DMUS_IO_BUFFER_ATTRIBUTES_HEADER m_BufferHeader; // GUID that identifies this buffer and flags.
  84. DWORD m_dwStandardBufferID;// Optionally, one of the standard buffer types.
  85. HRESULT Activate(BOOL fActivate);
  86. };
  87. class CBufferConfigList : public AList
  88. {
  89. public:
  90. void AddHead(CBufferConfig* pBufferConfig) { AList::AddHead((AListItem*)pBufferConfig);}
  91. CBufferConfig* GetHead(){return (CBufferConfig*)AList::GetHead();}
  92. CBufferConfig* RemoveHead() {return (CBufferConfig *) AList::RemoveHead();}
  93. void Remove(CBufferConfig* pBufferConfig){AList::Remove((AListItem*)pBufferConfig);}
  94. void AddTail(CBufferConfig* pBufferConfig){AList::AddTail((AListItem*)pBufferConfig);}
  95. void Clear();
  96. CBufferNode * GetBufferNode(REFGUID guidBufferID);
  97. HRESULT CreateRunTimeVersion(CBufferConfigList *pCopy, CBufferManager *pManager);
  98. HRESULT Activate(BOOL fActivate);
  99. };
  100. class CPortConfig;
  101. class CBufferConnect : public AListItem
  102. {
  103. public:
  104. CBufferConnect() ;
  105. ~CBufferConnect();
  106. CBufferConnect *CreateRunTimeVersion(CPortConfig *pParent);
  107. HRESULT Load(CRiffParser *pParser);
  108. CBufferConnect* GetNext() { return (CBufferConnect*)AListItem::GetNext();}
  109. DMUS_IO_PCHANNELTOBUFFER_HEADER m_ConnectHeader;
  110. GUID * m_pguidBufferIDs;// Set of guids identifying buffers to connect to.
  111. CBufferNode ** m_ppBufferNodes; // Array of equivalent Buffer nodes.
  112. };
  113. class CBufferConnectList : public AList
  114. {
  115. public:
  116. void AddHead(CBufferConnect* pBufferConnect) { AList::AddHead((AListItem*)pBufferConnect);}
  117. CBufferConnect* GetHead(){return (CBufferConnect*)AList::GetHead();}
  118. CBufferConnect* RemoveHead() {return (CBufferConnect *) AList::RemoveHead();}
  119. void Remove(CBufferConnect* pBufferConnect){AList::Remove((AListItem*)pBufferConnect);}
  120. void AddTail(CBufferConnect* pBufferConnect){AList::AddTail((AListItem*)pBufferConnect);}
  121. HRESULT CreateRunTimeVersion(CBufferConnectList *pDestination, CPortConfig *pParent);
  122. void Clear();
  123. };
  124. class CAudioPath;
  125. class CPortConfig : public AListItem
  126. {
  127. public:
  128. CPortConfig() ;
  129. ~CPortConfig();
  130. HRESULT CreateRunTimeVersion(CPortConfig ** ppCopy, CAudioPath *pParent,CBufferManager *pManager);
  131. CPortConfig* GetNext() { return (CPortConfig*)AListItem::GetNext();}
  132. CBufferNode * GetBufferNode(REFGUID guidBuffer);
  133. HRESULT Activate(BOOL fActivate);
  134. HRESULT CPortConfig::Load(CRiffParser *pParser);
  135. DMUS_IO_PORTCONFIG_HEADER m_PortHeader; // Port configuration header, from file.
  136. DMUS_PORTPARAMS8 m_PortParams; // Port params for opening the port, also from file.
  137. DWORD m_dwPortID; // Used to track the index of a created port, once connecting.
  138. CBufferConnectList m_BufferConnectList; // Pchannel to buffer mappings.
  139. CBufferConfigList m_BufferConfigList; // List of dsound buffer configurations.
  140. CAudioPath * m_pParent; // Parent audio path.
  141. IDirectMusicPort * m_pPort; // Pointer to port, if run time version.
  142. BOOL m_fAlreadyHere; // Check for recursive case looking for buffer nodes.
  143. };
  144. class CPortConfigList : public AList
  145. {
  146. public:
  147. void AddHead(CPortConfig* pPortConfig) { AList::AddHead((AListItem*)pPortConfig);}
  148. CPortConfig* GetHead(){return (CPortConfig*)AList::GetHead();}
  149. CPortConfig* RemoveHead() {return (CPortConfig *) AList::RemoveHead();}
  150. void Remove(CPortConfig* pPortConfig){AList::Remove((AListItem*)pPortConfig);}
  151. void AddTail(CPortConfig* pPortConfig){AList::AddTail((AListItem*)pPortConfig);}
  152. HRESULT CreateRunTimeVersion(CPortConfigList *pDestination,CAudioPath *pParent,CBufferManager *pManager);
  153. void Clear();
  154. HRESULT Activate(BOOL fActivate);
  155. BOOL UsesPort(IDirectMusicPort *pPort);
  156. };
  157. class CAudioPath;
  158. DEFINE_GUID(IID_CAudioPath,0xb06c0c23, 0xd3c7, 0x11d3, 0x9b, 0xd1, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);
  159. /* The AudioPath represents a configuration of pchannels, ports, and buffers to play
  160. segments. The performance creates CAudioPath objects from CAudioPathConfig file
  161. objects and stores them in a linked list, which it uses to keep track of them.
  162. */
  163. class CAudioPath :
  164. public IDirectMusicAudioPath,
  165. public IDirectMusicGraph,
  166. public AListItem
  167. {
  168. public:
  169. CAudioPath();
  170. ~CAudioPath();
  171. CAudioPath* GetNext() { return (CAudioPath*)AListItem::GetNext();}
  172. // IUnknown
  173. STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  174. STDMETHODIMP_(ULONG) AddRef();
  175. STDMETHODIMP_(ULONG) Release();
  176. // IDirectMusicAudioPath
  177. STDMETHODIMP GetObjectInPath( DWORD dwPChannel,DWORD dwStage,DWORD dwBuffer, REFGUID guidObject,
  178. DWORD dwIndex,REFGUID iidInterface, void ** ppObject);
  179. STDMETHODIMP Activate(BOOL fActivate) ;
  180. STDMETHODIMP SetVolume(long lVolume,DWORD dwDuration) ;
  181. STDMETHODIMP ConvertPChannel( DWORD dwPChannelIn,DWORD *pdwPChannelOut) ;
  182. // IDirectMusicGraph
  183. STDMETHODIMP Shutdown();
  184. STDMETHODIMP InsertTool(IDirectMusicTool *pTool,DWORD *pdwPChannels,DWORD cPChannels,LONG lIndex);
  185. STDMETHODIMP GetTool(DWORD,IDirectMusicTool**);
  186. STDMETHODIMP RemoveTool(IDirectMusicTool*);
  187. STDMETHODIMP StampPMsg(DMUS_PMSG* pEvent);
  188. HRESULT Init(IUnknown *pSourceConfig,CPerformance *pPerf);
  189. HRESULT ConnectToPorts(CPerformance *pPerf,DWORD dwSampleRate);
  190. CBufferNode * GetBufferNode(REFGUID guidBuffer);
  191. void SetGraph(CGraph *pGraph);
  192. CGraph *GetGraph();
  193. void Deactivate();
  194. BOOL IsActive() { return m_fActive; }
  195. BOOL NoPorts() { return m_PortConfigList.IsEmpty(); }
  196. BOOL UsesPort(IDirectMusicPort *pPort) { return m_PortConfigList.UsesPort(pPort); }
  197. private:
  198. BOOL m_fDeactivating; // State variable.
  199. BYTE m_bLastVol; // Last volume change.
  200. CRITICAL_SECTION m_CriticalSection;
  201. BOOL m_fActive; // Indicates that the audio path is active.
  202. long m_cRef; // Reference counter.
  203. DWORD * m_pdwVChannels; // Array of source VChannels.
  204. DWORD * m_pdwPChannels; // Array of destination PChannels.
  205. DWORD m_dwChannelCount; // Size of arrays.
  206. CGraph * m_pGraph; // Route tool graph.
  207. CPerformance * m_pPerformance; // Pointer to performance, needed to release PChannels.
  208. CAudioPathConfig * m_pConfig; // Source configuration.
  209. CPortConfigList m_PortConfigList; // List of port definitions (copied from source.)
  210. CBufferConfigList m_BufferConfigList; // List of DSound buffers connected to the ports.
  211. IUnknown * m_pUnkDispatch; // holds the controlling unknown of the scripting object that implements IDispatch
  212. };
  213. class CAudioPathList : public AList
  214. {
  215. public:
  216. void Clear();
  217. void AddHead(CAudioPath* pAudioPath) { AList::AddHead((AListItem*)pAudioPath);}
  218. CAudioPath* GetHead(){return (CAudioPath*)AList::GetHead();}
  219. CAudioPath* RemoveHead() {return (CAudioPath *) AList::RemoveHead();}
  220. void Remove(CAudioPath* pAudioPath){AList::Remove((AListItem*)pAudioPath);}
  221. void AddTail(CAudioPath* pAudioPath){AList::AddTail((AListItem*)pAudioPath);}
  222. BOOL IsMember(CAudioPath* pAudioPath){return AList::IsMember((AListItem*)pAudioPath);}
  223. BOOL UsesPort(IDirectMusicPort *pPort);
  224. CBufferNode * GetBufferNode(REFGUID guidBufferID);
  225. };
  226. DEFINE_GUID(IID_CAudioPathConfig,0xe9874261, 0xab52, 0x11d3, 0x9b, 0xd1, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0);
  227. class CAudioPathConfig :
  228. public IPersistStream,
  229. public IDirectMusicObject
  230. {
  231. friend class CAudioPath;
  232. public:
  233. CAudioPathConfig();
  234. ~CAudioPathConfig();
  235. static CAudioPathConfig *CreateStandardConfig(DWORD dwType,DWORD dwPChannelCount,DWORD dwSampleRate);
  236. // IUnknown
  237. STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  238. STDMETHODIMP_(ULONG) AddRef();
  239. STDMETHODIMP_(ULONG) Release();
  240. // IPersist functions
  241. STDMETHODIMP GetClassID( CLSID* pClsId );
  242. // IPersistStream functions
  243. STDMETHODIMP IsDirty();
  244. STDMETHODIMP Load( IStream* pIStream );
  245. STDMETHODIMP Save( IStream* pIStream, BOOL fClearDirty );
  246. STDMETHODIMP GetSizeMax( ULARGE_INTEGER FAR* pcbSize );
  247. // IDirectMusicObject
  248. STDMETHODIMP GetDescriptor(LPDMUS_OBJECTDESC pDesc);
  249. STDMETHODIMP SetDescriptor(LPDMUS_OBJECTDESC pDesc);
  250. STDMETHODIMP ParseDescriptor(LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc);
  251. HRESULT Load( CRiffParser *pParser);
  252. protected:
  253. CGraph * m_pGraph; // Audio path tool graph.
  254. CPortConfigList m_PortConfigList; // List of port definitions.
  255. CBufferConfigList m_BufferConfigList; // List of global dsound buffer configurations.
  256. CRITICAL_SECTION m_CriticalSection;
  257. long m_cRef;
  258. DWORD m_fPartialLoad;
  259. // IDirectMusicObject variables
  260. DWORD m_dwValidData;
  261. GUID m_guidObject;
  262. FILETIME m_ftDate; /* Last edited date of object. */
  263. DMUS_VERSION m_vVersion; /* Version. */
  264. WCHAR m_wszName[DMUS_MAX_NAME]; /* Name of object. */
  265. WCHAR m_wszCategory[DMUS_MAX_CATEGORY]; /* Category for object */
  266. WCHAR m_wszFileName[DMUS_MAX_FILENAME]; /* File path. */
  267. IUnknown * m_pUnkDispatch; // holds the controlling unknown of the scripting object that implements IDispatch
  268. };
  269. #endif // __AUDIOPATH_H_