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.

323 lines
7.9 KiB

  1. /**************************************************************************
  2. AVStream Simulated Hardware Sample
  3. Copyright (c) 2001, Microsoft Corporation.
  4. File:
  5. device.h
  6. Abstract:
  7. The header for the device level of the simulated hardware. This is
  8. not actually the hardware simulation itself. The hardware simulation
  9. is contained in hwsim.*, image.*.
  10. History:
  11. created 3/9/2001
  12. **************************************************************************/
  13. class CCaptureDevice :
  14. public IHardwareSink {
  15. private:
  16. //
  17. // The AVStream device we're associated with.
  18. //
  19. PKSDEVICE m_Device;
  20. //
  21. // Number of pins with resources acquired. This is used as a locking
  22. // mechanism for resource acquisition on the device.
  23. //
  24. LONG m_PinsWithResources;
  25. //
  26. // Since we don't have physical hardware, this provides the hardware
  27. // simulation. m_HardwareSimulation provides the fake ISR, fake DPC,
  28. // etc... m_TsSynth provides a place to put transport stream synthesis
  29. // in software.
  30. //
  31. CHardwareSimulation *m_HardwareSimulation;
  32. CTsSynthesizer *m_TsSynth;
  33. //
  34. // The number of ISR's that have occurred since capture started.
  35. //
  36. ULONG m_InterruptTime;
  37. //
  38. // The last reading of mappings completed.
  39. //
  40. ULONG m_LastMappingsCompleted;
  41. //
  42. // The Dma adapter object we acquired through IoGetDmaAdapter() during
  43. // Pnp start. This must be initialized with AVStream in order to perform
  44. // Dma directly into the capture buffers.
  45. //
  46. PADAPTER_OBJECT m_DmaAdapterObject;
  47. //
  48. // The number of map registers returned from IoGetDmaAdapter().
  49. //
  50. ULONG m_NumberOfMapRegisters;
  51. //
  52. // The capture sink. When we complete scatter / gather mappings, we
  53. // notify the capture sink.
  54. //
  55. ICaptureSink *m_CaptureSink;
  56. //
  57. // The video info header we're basing hardware settings on. The pin
  58. // provides this to us when acquiring resources and must guarantee its
  59. // stability until resources are released.
  60. //
  61. PBDA_TRANSPORT_INFO m_TransportInfo;
  62. //
  63. // Cleanup():
  64. //
  65. // This is the free callback for the bagged capture device. Not providing
  66. // one will call ExFreePool, which is not what we want for a constructed
  67. // C++ object. This simply deletes the capture device.
  68. //
  69. static
  70. void
  71. Cleanup (
  72. IN CCaptureDevice *CapDevice
  73. )
  74. {
  75. delete CapDevice;
  76. }
  77. // CleanupHW()
  78. //
  79. // Cleanup the hwsimulation object associated with this device. This is the
  80. // free callback for the bagged hwsim.
  81. //
  82. static
  83. void
  84. CleanupHW(
  85. IN CHardwareSimulation *hwSim
  86. )
  87. {
  88. delete hwSim;
  89. }
  90. //
  91. // CleanupSynth():
  92. //
  93. // Cleanup the image synth associated with this device. This is the
  94. // free callback for the bagged image synth.
  95. //
  96. static
  97. void
  98. CleanupSynth (
  99. IN CTsSynthesizer *TsSynth
  100. )
  101. {
  102. delete TsSynth;
  103. }
  104. //
  105. // PnpStart():
  106. //
  107. // This is the Pnp start routine for our simulated hardware. Note that
  108. // DispatchStart bridges to here in the context of the CCaptureDevice.
  109. //
  110. NTSTATUS
  111. PnpStart (
  112. IN PCM_RESOURCE_LIST TranslatedResourceList,
  113. IN PCM_RESOURCE_LIST UntranslatedResourceList
  114. );
  115. //
  116. // PnpStop():
  117. //
  118. // This is the Pnp stop routine for our simulated hardware. Note that
  119. // DispatchStop bridges to here in the context of the CCaptureDevice.
  120. //
  121. void
  122. PnpStop (
  123. );
  124. public:
  125. //
  126. // CCaptureDevice():
  127. //
  128. // The capture device class constructor. Since everything should have
  129. // been zero'ed by the new operator, don't bother setting anything to
  130. // zero or NULL. Only initialize non-NULL, non-0 fields.
  131. //
  132. CCaptureDevice (
  133. IN PKSDEVICE Device
  134. ) :
  135. m_Device (Device)
  136. {
  137. }
  138. //
  139. // ~CCaptureDevice():
  140. //
  141. // The capture device destructor.
  142. //
  143. ~CCaptureDevice (
  144. )
  145. {
  146. }
  147. //
  148. // DispatchCreate():
  149. //
  150. // This is the Add Device dispatch for the capture device. It creates
  151. // the CCaptureDevice and associates it with the device via the bag.
  152. //
  153. static
  154. NTSTATUS
  155. DispatchCreate (
  156. IN PKSDEVICE Device
  157. );
  158. //
  159. // DispatchPnpStart():
  160. //
  161. // This is the Pnp Start dispatch for the capture device. It simply
  162. // bridges to PnpStart() in the context of the CCaptureDevice.
  163. //
  164. static
  165. NTSTATUS
  166. DispatchPnpStart (
  167. IN PKSDEVICE Device,
  168. IN PIRP Irp,
  169. IN PCM_RESOURCE_LIST TranslatedResourceList,
  170. IN PCM_RESOURCE_LIST UntranslatedResourceList
  171. )
  172. {
  173. return
  174. (reinterpret_cast <CCaptureDevice *> (Device -> Context)) ->
  175. PnpStart (
  176. TranslatedResourceList,
  177. UntranslatedResourceList
  178. );
  179. }
  180. //
  181. // DispatchPnpStop():
  182. //
  183. // This is the Pnp stop dispatch for the capture device. It simply
  184. // bridges to PnpStop() in the context of the CCaptureDevice.
  185. //
  186. static
  187. void
  188. DispatchPnpStop (
  189. IN PKSDEVICE Device,
  190. IN PIRP Irp
  191. )
  192. {
  193. return
  194. (reinterpret_cast <CCaptureDevice *> (Device -> Context)) ->
  195. PnpStop (
  196. );
  197. }
  198. //
  199. // AcquireHardwareResources():
  200. //
  201. // Called to acquire hardware resources for the device based on a given
  202. // video info header. This will fail if another object has already
  203. // acquired hardware resources since we emulate a single capture
  204. // device.
  205. //
  206. NTSTATUS
  207. AcquireHardwareResources (
  208. IN ICaptureSink *CaptureSink,
  209. IN PBDA_TRANSPORT_INFO TransportInfo
  210. );
  211. //
  212. // ReleaseHardwareResources():
  213. //
  214. // Called to release hardware resources for the device.
  215. //
  216. void
  217. ReleaseHardwareResources (
  218. );
  219. //
  220. // Start():
  221. //
  222. // Called to start the hardware simulation. This causes us to simulate
  223. // interrupts, simulate filling buffers with synthesized data, etc...
  224. //
  225. NTSTATUS
  226. Start (
  227. );
  228. //
  229. // Pause():
  230. //
  231. // Called to pause or unpause the hardware simulation. This will be
  232. // indentical to a start or stop but it will not reset formats and
  233. // counters.
  234. //
  235. NTSTATUS
  236. Pause (
  237. IN BOOLEAN Pausing
  238. );
  239. //
  240. // Stop():
  241. //
  242. // Called to stop the hardware simulation. This causes interrupts to
  243. // stop issuing. When this call returns, the "fake" hardware has
  244. // stopped accessing all s/g buffers, etc...
  245. //
  246. NTSTATUS
  247. Stop (
  248. );
  249. //
  250. // ProgramScatterGatherMappings():
  251. //
  252. // Called to program the hardware simulation's scatter / gather table.
  253. // This synchronizes with the "fake" ISR and hardware simulation via
  254. // a spinlock.
  255. //
  256. ULONG
  257. ProgramScatterGatherMappings (
  258. IN PUCHAR *Buffer,
  259. IN PKSMAPPING Mappings,
  260. IN ULONG MappingsCount
  261. );
  262. //
  263. // QueryInterruptTime():
  264. //
  265. // Determine the frame number that this frame corresponds to.
  266. //
  267. ULONG
  268. QueryInterruptTime (
  269. );
  270. //
  271. // IHardwareSink::Interrupt():
  272. //
  273. // The interrupt service routine as called through the hardware sink
  274. // interface. The "fake" hardware uses this method to inform the device
  275. // of a "fake" ISR. The routine is called at dispatch level and must
  276. // be in locked code.
  277. //
  278. virtual
  279. void
  280. Interrupt (
  281. );
  282. };