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.

263 lines
7.2 KiB

  1. /**************************************************************************
  2. AVStream Simulated Hardware Sample
  3. Copyright (c) 2001, Microsoft Corporation.
  4. File:
  5. capture.h
  6. Abstract:
  7. This file contains header for the video capture pin on the capture
  8. filter. The capture sample performs "fake" DMA directly into
  9. the capture buffers. Common buffer DMA will work slightly differently.
  10. For common buffer DMA, the general technique would be DPC schedules
  11. processing with KsPinAttemptProcessing. The processing routine grabs
  12. the leading edge, copies data out of the common buffer and advances.
  13. Cloning would not be necessary with this technique. It would be
  14. similiar to the way "AVSSamp" works, but it would be pin-centric.
  15. History:
  16. created 3/8/2001
  17. **************************************************************************/
  18. //
  19. // STREAM_POINTER_CONTEXT:
  20. //
  21. // This is the context structure we associate with all clone stream pointers.
  22. // It allows the mapping code to rip apart the buffer into chunks the same
  23. // size as the scatter/gather mappings in order to fake scatter / gather
  24. // bus-master DMA.
  25. //
  26. typedef struct _STREAM_POINTER_CONTEXT {
  27. PUCHAR BufferVirtual;
  28. } STREAM_POINTER_CONTEXT, *PSTREAM_POINTER_CONTEXT;
  29. //
  30. // CCapturePin:
  31. //
  32. // The video capture pin class.
  33. //
  34. class CCapturePin :
  35. public ICaptureSink {
  36. private:
  37. //
  38. // The AVStream pin we're associated with.
  39. //
  40. PKSPIN m_Pin;
  41. //
  42. // Pointer to the internal device object for our capture device.
  43. // We access the "fake" hardware through this object.
  44. //
  45. CCaptureDevice *m_Device;
  46. //
  47. // The state we've put the hardware into. This allows us to keep track
  48. // of whether to do things like unpausing or restarting.
  49. //
  50. HARDWARE_STATE m_HardwareState;
  51. //
  52. // The clock we've been assigned. As with other capture filters, we do
  53. // not expose a clock. If one has been assigned, we will use it to
  54. // time stamp packets (plus a reasonable delta to work the capture stream
  55. // in a preview graph).
  56. //
  57. PIKSREFERENCECLOCK m_Clock;
  58. //
  59. // The transport information for this capture pin. The settings for "fake" hardware will be
  60. // programmed for this transport info.
  61. //
  62. PBDA_TRANSPORT_INFO m_TransportInfo;
  63. //
  64. // If we are unable to insert all of the mappings in a stream pointer into
  65. // the "fake" hardware's scatter / gather table, we set this to the
  66. // stream pointer that's incomplete. This is done both to make the
  67. // relasing easier and to make it easier to fake the scatter / gather
  68. // hardware.
  69. //
  70. PKSSTREAM_POINTER m_PreviousStreamPointer;
  71. //
  72. // An indication of whether or not we pended I/O for some reason. If this
  73. // is set, the DPC will resume I/O when any mappings are completed.
  74. //
  75. BOOLEAN m_PendIo;
  76. //
  77. // An indication of whether or not this pin has acquired the necessary
  78. // hardware resources to operate. When the pin reaches KSSTATE_ACQUIRE,
  79. // we attempt to acquire the hardware. This flag will be set based on
  80. // our success / failure.
  81. //
  82. BOOLEAN m_AcquiredResources;
  83. //
  84. // CleanupReferences():
  85. //
  86. // Clean up any references we hold on frames in the queue. This is called
  87. // when we abruptly stop the fake hardware.
  88. //
  89. NTSTATUS
  90. CleanupReferences (
  91. );
  92. //
  93. // SetState():
  94. //
  95. // This is the state transition handler for the capture pin. It attempts
  96. // to acquire resources for the capture pin (or releasing them if
  97. // necessary) and starts and stops the hardware as required.
  98. //
  99. NTSTATUS
  100. SetState (
  101. IN KSSTATE ToState,
  102. IN KSSTATE FromState
  103. );
  104. //
  105. // Process():
  106. //
  107. // This is the processing dispatch for the capture pin. It handles
  108. // programming the scatter / gather tables for the hardware as buffers
  109. // become available. This processing routine is designed for a direct
  110. // into the capture buffers kind of DMA as opposed to common-buffer
  111. // and copy strategies.
  112. //
  113. NTSTATUS
  114. Process (
  115. );
  116. //
  117. // CaptureBdaTransportInfo():
  118. //
  119. // This routine stashes the BDA Transport Info for the pin connection
  120. // in the CCapturePin object. This is used to base hardware settings.
  121. //
  122. PBDA_TRANSPORT_INFO
  123. CaptureBdaTransportInfo (
  124. );
  125. //
  126. // Cleanup():
  127. //
  128. // This is the free callback from the bagged item (CCapturePin). If we
  129. // do not provide a callback when we bag the CCapturePin, ExFreePool
  130. // would be called. This is not desirable for C++ constructed objects.
  131. // We merely delete the object here.
  132. //
  133. static
  134. void
  135. Cleanup (
  136. IN CCapturePin *Pin
  137. )
  138. {
  139. delete Pin;
  140. }
  141. public:
  142. //
  143. // CCapturePin():
  144. //
  145. // The capture pin's constructor. Initialize any non-0, non-NULL fields
  146. // (since new will have zero'ed the memory anyway) and set up our
  147. // device level pointers for access during capture routines.
  148. //
  149. CCapturePin (
  150. IN PKSPIN Pin
  151. );
  152. //
  153. // ~CCapturePin():
  154. //
  155. // The capture pin's destructor.
  156. //
  157. ~CCapturePin (
  158. )
  159. {
  160. }
  161. //
  162. // ICaptureSink::CompleteMappings()
  163. //
  164. // This is the capture sink notification mechanism for mapping completion.
  165. // When the device DPC detects that a given number of mappings have been
  166. // completed by the fake hardware, it signals the capture sink of this
  167. // through this method.
  168. //
  169. virtual
  170. void
  171. CompleteMappings (
  172. IN ULONG NumMappings
  173. );
  174. /*************************************************
  175. Dispatch Routines
  176. *************************************************/
  177. //
  178. // DispatchCreate():
  179. //
  180. // This is the creation dispatch for the capture pin. It creates
  181. // the CCapturePin object and associates it with the AVStream object
  182. // bagging it in the process.
  183. //
  184. static
  185. NTSTATUS
  186. DispatchCreate (
  187. IN PKSPIN Pin,
  188. IN PIRP Irp
  189. );
  190. //
  191. // DispatchSetState():
  192. //
  193. // This is the set device state dispatch for the pin. The routine bridges
  194. // to SetState() in the context of the CCapturePin.
  195. //
  196. static
  197. NTSTATUS
  198. DispatchSetState (
  199. IN PKSPIN Pin,
  200. IN KSSTATE ToState,
  201. IN KSSTATE FromState
  202. )
  203. {
  204. return
  205. (reinterpret_cast <CCapturePin *> (Pin -> Context)) ->
  206. SetState (ToState, FromState);
  207. }
  208. //
  209. // DispatchProcess():
  210. //
  211. // This is the processing dispatch for the capture pin. The routine
  212. // bridges to Process() in the context of the CCapturePin.
  213. //
  214. static
  215. NTSTATUS
  216. DispatchProcess (
  217. IN PKSPIN Pin
  218. )
  219. {
  220. return
  221. (reinterpret_cast <CCapturePin *> (Pin -> Context)) ->
  222. Process ();
  223. }
  224. };