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.

338 lines
11 KiB

  1. /********************************************************************************
  2. ** Copyright (c) 1998-2000 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** Portions Copyright (c) 1998-1999 Intel Corporation
  5. **
  6. ********************************************************************************/
  7. #ifndef _MINTOPO_H_
  8. #define _MINTOPO_H_
  9. #include "shared.h"
  10. #include "guids.h"
  11. #ifdef INCLUDE_PRIVATE_PROPERTY
  12. #include "prvprop.h"
  13. #endif
  14. /*****************************************************************************
  15. * Structures and Definitions
  16. */
  17. // This structure is used to translate the TopoPins member to a (registered)
  18. // system pin member or vice versa.
  19. typedef struct
  20. {
  21. TopoPins PinDef;
  22. int PinNr;
  23. } tPinTranslationTable;
  24. // This structure is used to translate the TopoNodes member to a (registered)
  25. // system node member or vice versa.
  26. typedef struct
  27. {
  28. TopoNodes NodeDef;
  29. int NodeNr;
  30. } tNodeTranslationTable;
  31. // max. number of connections
  32. const int TOPO_MAX_CONNECTIONS = 0x80;
  33. // Looking at the structure stMapNodeToReg, it defines a mask for a node.
  34. // A volume node for instance could be used to prg. the left or right channel,
  35. // so we have to mask the mask in stMapNodeToReg with a "left channel mask"
  36. // or a "right channel mask" to only prg. the left or right channel.
  37. const WORD AC97REG_MASK_LEFT = 0x3F00;
  38. const WORD AC97REG_MASK_RIGHT = 0x003F;
  39. const WORD AC97REG_MASK_MUTE = 0x8000;
  40. // When the user moves the fader of a volume control to the bottom, the
  41. // system calls the property handler with a -MAXIMUM dB value. That's not
  42. // what you returned at a basic support "data range", but the most negative
  43. // value you can represent with a long.
  44. const long PROP_MOST_NEGATIVE = (long)0x80000000;
  45. // We must cache the values for the volume and tone controls. If we don't,
  46. // the controls will "jump".
  47. // We have around 50% volume controls in the nodes. One way would be to
  48. // create a separate structure for the node cache and a second array for
  49. // the mapping. But we just use one big array (that could cache mute controls
  50. // too) and in that way simplify the code a little.
  51. // We use the bLeftValid and bRightValid to indicate whether the values stored
  52. // in lLeft and lRight are true - remember at startup we only write and
  53. // initialize the AC97 registers and not this structure. But as soon as there
  54. // is a property get or a property set, this element (node) will be stored here
  55. // and marked valid.
  56. // We don't have to save/restore the virtual controls for WaveIn and MonoOut
  57. // in the registry, cause WDMAUD will do this for every node that is exposed
  58. // in the topology. We can also be sure that this structure gets initialized at
  59. // startup because WDMAUD will query every node that it finds.
  60. typedef struct
  61. {
  62. long lLeft;
  63. long lRight;
  64. BYTE bLeftValid;
  65. BYTE bRightValid;
  66. } tNodeCache;
  67. /*****************************************************************************
  68. * Classes
  69. */
  70. /*****************************************************************************
  71. * CMiniportTopologyICH
  72. *****************************************************************************
  73. * ICH topology miniport. This object is associated with the device and is
  74. * created when the device is started. The class inherits IMiniportTopology
  75. * so it can expose this interface and CUnknown so it automatically gets
  76. * reference counting and aggregation support.
  77. */
  78. class CMiniportTopologyICH : public IMiniportTopologyICH,
  79. public CUnknown
  80. {
  81. private:
  82. PADAPTERCOMMON AdapterCommon; // Adapter common object
  83. PPCFILTER_DESCRIPTOR FilterDescriptor; // Filter Descriptor
  84. PPCPIN_DESCRIPTOR PinDescriptors; // Pin Descriptors
  85. PPCNODE_DESCRIPTOR NodeDescriptors; // Node Descriptors
  86. PPCCONNECTION_DESCRIPTOR ConnectionDescriptors; // Connection Descriptors
  87. tPinTranslationTable stPinTrans[PIN_TOP_ELEMENT]; // pin translation table
  88. tNodeTranslationTable stNodeTrans[NODE_TOP_ELEMENT]; // node translation table
  89. tNodeCache stNodeCache[NODE_TOP_ELEMENT]; // cache for nodes.
  90. BOOL m_bCopyProtectFlag; // Copy protect flag for DRM.
  91. /*************************************************************************
  92. * CMiniportTopologyICH methods
  93. *
  94. * These are private member functions used internally by the object. See
  95. * MINIPORT.CPP for specific descriptions.
  96. */
  97. // builds the topology.
  98. NTSTATUS BuildTopology (void);
  99. // registers (builds) the pins
  100. NTSTATUS BuildPinDescriptors (void);
  101. // registers (builds) the nodes
  102. NTSTATUS BuildNodeDescriptors (void);
  103. // registers (builds) the connection between the pin, nodes.
  104. NTSTATUS BuildConnectionDescriptors (void);
  105. #if (DBG)
  106. // dumps the topology. you can specify if you want to dump pins, nodes,
  107. // connections (see debug.h).
  108. void DumpTopology (void);
  109. #endif
  110. // translates the system node id to a TopoNode.
  111. TopoNodes TransNodeNrToNodeDef (IN int Node)
  112. {
  113. #if (DBG)
  114. TopoNodes n;
  115. n = stNodeTrans[Node].NodeDef;
  116. // check for invalid translation. could be caused by a connection
  117. // to a not registered node or wrong use of nodes.
  118. if (n == NODE_INVALID)
  119. DOUT (DBG_ERROR, ("Invalid node nr %u.", Node));
  120. return n;
  121. #else
  122. return stNodeTrans[Node].NodeDef;
  123. #endif
  124. };
  125. // translates a TopoNode to a system node id.
  126. int TransNodeDefToNodeNr (IN TopoNodes Node)
  127. {
  128. #if (DBG)
  129. int n;
  130. // check for invalid translation. could be caused by a connection
  131. // to a not registered node or wrong use of nodes.
  132. n = stNodeTrans[Node].NodeNr;
  133. if (n == -1)
  134. DOUT (DBG_ERROR, ("Invalid TopoNode %u.", Node));
  135. return n;
  136. #else
  137. return stNodeTrans[Node].NodeNr;
  138. #endif
  139. };
  140. // translates a system pin id to a TopoPin.
  141. TopoPins TransPinNrToPinDef (IN int Pin)
  142. {
  143. #if (DBG)
  144. TopoPins p;
  145. p = stPinTrans[Pin].PinDef;
  146. // check for invalid translation. could be caused by a connection
  147. // to a not registered pin or wrong use of pins.
  148. if (p == PIN_INVALID)
  149. DOUT (DBG_ERROR, ("Invalid pin nr %u.", Pin));
  150. return p;
  151. #else
  152. return stPinTrans[Pin].PinDef;
  153. #endif
  154. };
  155. // translates a TopoPin to a system pin id.
  156. int TransPinDefToPinNr (IN TopoPins Pin)
  157. {
  158. #if (DBG)
  159. int p;
  160. p = stPinTrans[Pin].PinNr;
  161. // check for invalid translation. could be caused by a connection
  162. // to a not registered pin or wrong use of pins.
  163. if (p == -1)
  164. DOUT (DBG_ERROR, ("Invalid TopoPin %u.", Pin));
  165. return p;
  166. #else
  167. return stPinTrans[Pin].PinNr;
  168. #endif
  169. };
  170. // sets one table entry for translation.
  171. void SetNodeTranslation (IN int NodeNr, IN TopoNodes NodeDef)
  172. {
  173. stNodeTrans[NodeNr].NodeDef = NodeDef;
  174. stNodeTrans[NodeDef].NodeNr = NodeNr;
  175. };
  176. // sets one table entry for translation.
  177. void SetPinTranslation (IN int PinNr, IN TopoPins PinDef)
  178. {
  179. stPinTrans[PinNr].PinDef = PinDef;
  180. stPinTrans[PinDef].PinNr = PinNr;
  181. };
  182. // Updates the record mute - used for DRM.
  183. void UpdateRecordMute (void);
  184. public:
  185. /*************************************************************************
  186. * The following two macros are from STDUNK.H. DECLARE_STD_UNKNOWN()
  187. * defines inline IUnknown implementations that use CUnknown's aggregation
  188. * support. NonDelegatingQueryInterface() is declared, but it cannot be
  189. * implemented generically. Its definition appears in MINIPORT.CPP.
  190. * DEFINE_STD_CONSTRUCTOR() defines inline a constructor which accepts
  191. * only the outer unknown, which is used for aggregation. The standard
  192. * create macro (in MINIPORT.CPP) uses this constructor.
  193. */
  194. DECLARE_STD_UNKNOWN ();
  195. DEFINE_STD_CONSTRUCTOR (CMiniportTopologyICH);
  196. ~CMiniportTopologyICH ();
  197. /*************************************************************************
  198. * include IMiniportTopology (public/exported) methods
  199. */
  200. IMP_IMiniportTopology;
  201. /*************************************************************************
  202. * IMiniportTopologyICH methods
  203. */
  204. // returns the system pin id's for wave out, wave in and mic in.
  205. STDMETHODIMP_(NTSTATUS) GetPhysicalConnectionPins
  206. (
  207. OUT PULONG WaveOutSource,
  208. OUT PULONG WaveInDest,
  209. OUT PULONG MicInDest
  210. );
  211. // sets the copy protect flag.
  212. STDMETHODIMP_(void) SetCopyProtectFlag (BOOL flag)
  213. {
  214. if (m_bCopyProtectFlag != flag)
  215. {
  216. m_bCopyProtectFlag = flag;
  217. UpdateRecordMute ();
  218. }
  219. };
  220. /*************************************************************************
  221. * static functions for the property handler.
  222. * They are not part of an COM interface and are called directly.
  223. */
  224. // Get the data range of volume or tone controls in dB.
  225. // Called by the property handler.
  226. static NTSTATUS GetDBValues
  227. (
  228. IN PADAPTERCOMMON,
  229. IN TopoNodes Node,
  230. OUT LONG *plMinimum,
  231. OUT LONG *plMaximum,
  232. OUT ULONG *puStep
  233. );
  234. // Calculates the speaker mute with respect to master mono.
  235. // Called by the property handler.
  236. static NTSTATUS SetMultichannelMute
  237. (
  238. IN CMiniportTopologyICH *that,
  239. IN TopoNodes Mute
  240. );
  241. // Calculates the speaker volume with respect to master mono.
  242. // Called by the property handler.
  243. static NTSTATUS SetMultichannelVolume
  244. (
  245. IN CMiniportTopologyICH *that,
  246. IN TopoNodes Volume
  247. );
  248. // property handler for mute controls of checkboxes like Loudness.
  249. static NTSTATUS PropertyHandler_OnOff
  250. (
  251. IN PPCPROPERTY_REQUEST PropertyRequest
  252. );
  253. // This routine is the basic support handler for volume or tone controls.
  254. static NTSTATUS BasicSupportHandler
  255. (
  256. IN PPCPROPERTY_REQUEST PropertyRequest
  257. );
  258. // property handler for all volume controls.
  259. static NTSTATUS PropertyHandler_Level
  260. (
  261. IN PPCPROPERTY_REQUEST PropertyRequest
  262. );
  263. // property handler for tone controls.
  264. static NTSTATUS PropertyHandler_Tone
  265. (
  266. IN PPCPROPERTY_REQUEST PropertyRequest
  267. );
  268. // property handler for muxer. we have just two muxer, one for recording
  269. // and one for mono out.
  270. static NTSTATUS PropertyHandler_Ulong
  271. (
  272. IN PPCPROPERTY_REQUEST PropertyRequest
  273. );
  274. // this says that audio is played and processed without CPU resources.
  275. static NTSTATUS PropertyHandler_CpuResources
  276. (
  277. IN PPCPROPERTY_REQUEST PropertyRequest
  278. );
  279. #ifdef INCLUDE_PRIVATE_PROPERTY
  280. // property handler for private properties. we currently have only
  281. // one request defined (KSPROPERTY_AC97_FEATURES).
  282. static NTSTATUS PropertyHandler_Private
  283. (
  284. IN PPCPROPERTY_REQUEST PropertyRequest
  285. );
  286. #endif
  287. };
  288. #endif // _MINTOPO_H_