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.

466 lines
17 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1992 - 1999 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //==========================================================================;
  11. #ifndef __CAPMAIN_H__
  12. #define __CAPMAIN_H__
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif // __cplusplus
  16. // ------------------------------------------------------------------------
  17. // The master list of all streams supported by this driver
  18. // ------------------------------------------------------------------------
  19. // Warning: The stream numbers below MUST be the same as its position
  20. // in the Streams[] array in the capstrm.h file.
  21. typedef enum {
  22. STREAM_Capture = 0,
  23. STREAM_Preview,
  24. STREAM_VBI,
  25. STREAM_CC,
  26. STREAM_NABTS,
  27. STREAM_AnalogVideoInput,
  28. MAX_TESTCAP_STREAMS // This entry MUST be last; it's the size
  29. };
  30. // ------------------------------------------------------------------------
  31. // Other misc stuff
  32. // ------------------------------------------------------------------------
  33. #ifndef FIELDOFFSET
  34. #define FIELDOFFSET(type, field) ((LONG_PTR)(&((type *)1)->field)-1)
  35. #endif
  36. #ifndef mmioFOURCC
  37. #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
  38. ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) | \
  39. ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
  40. #endif
  41. #define FOURCC_YUV422 mmioFOURCC('U', 'Y', 'V', 'Y')
  42. typedef struct _STREAMX;
  43. typedef struct _STREAMX *PSTREAMX;
  44. typedef struct _COMPRESSION_SETTINGS {
  45. LONG CompressionKeyFrameRate;
  46. LONG CompressionPFramesPerKeyFrame;
  47. LONG CompressionQuality;
  48. } COMPRESSION_SETTINGS, *PCOMPRESSION_SETTINGS;
  49. //
  50. // definition of the full HW device extension structure This is the structure
  51. // that will be allocated in HW_INITIALIZATION by the stream class driver
  52. // Any information that is used in processing a device request (as opposed to
  53. // a STREAM based request) should be in this structure. A pointer to this
  54. // structure will be passed in all requests to the minidriver. (See
  55. // HW_STREAM_REQUEST_BLOCK in STRMINI.H)
  56. //
  57. typedef struct _HW_DEVICE_EXTENSION {
  58. PULONG ioBaseLocal; // board base address
  59. USHORT Irq; // IRQ level
  60. BOOLEAN IRQExpected; // IRQ expected
  61. PSTREAMX pStrmEx [MAX_TESTCAP_STREAMS]; // Pointers to each stream
  62. UINT ActualInstances [MAX_TESTCAP_STREAMS]; // Counter of instances per stream
  63. PDEVICE_OBJECT PDO; // Physical Device Object
  64. DEVICE_POWER_STATE DeviceState; // D0 ... D3
  65. // Spinlock and Queue for the Adapter
  66. BOOL AdapterQueueInitialized; // Stays TRUE after first init
  67. KSPIN_LOCK AdapterSpinLock; // Multiprocessor safe access to AdapterSRBList
  68. LIST_ENTRY AdapterSRBList; // List of pending adapter commands
  69. BOOL ProcessingAdapterSRB; // Master flag which prevents reentry
  70. // Spinlocks and Queues for each data stream
  71. LIST_ENTRY StreamSRBList[MAX_TESTCAP_STREAMS]; // List of pending read requests
  72. KSPIN_LOCK StreamSRBSpinLock[MAX_TESTCAP_STREAMS];// Multiprocessor safe access to StreamSRBList
  73. int StreamSRBListSize[MAX_TESTCAP_STREAMS];// Number of entries in the list
  74. // Control Queues for each data stream
  75. LIST_ENTRY StreamControlSRBList[MAX_TESTCAP_STREAMS];
  76. BOOL ProcessingControlSRB[MAX_TESTCAP_STREAMS];
  77. // Unique identifier for the analog video input pin
  78. KSPIN_MEDIUM AnalogVideoInputMedium;
  79. UINT DriverMediumInstanceCount; // Unique Medium.Id for multiple cards
  80. // Crossbar settings
  81. LONG VideoInputConnected; // which input is the video out connected to?
  82. LONG AudioInputConnected; // which input is the audio out connected to?
  83. // TV Tuner settings
  84. ULONG TunerMode; // TV, FM, AM, ATSC
  85. ULONG Frequency;
  86. ULONG VideoStandard;
  87. ULONG TuningQuality;
  88. ULONG TunerInput;
  89. ULONG Country;
  90. ULONG Channel;
  91. ULONG Busy;
  92. // TV Audio settings
  93. ULONG TVAudioMode;
  94. // VideoProcAmp settings
  95. LONG Brightness;
  96. LONG BrightnessFlags;
  97. LONG Contrast;
  98. LONG ContrastFlags;
  99. LONG ColorEnable;
  100. LONG ColorEnableFlags;
  101. // CameraControl settings
  102. LONG Focus;
  103. LONG FocusFlags;
  104. LONG Zoom;
  105. LONG ZoomFlags;
  106. // AnalogVideoDecoder settings
  107. LONG VideoDecoderVideoStandard;
  108. LONG VideoDecoderOutputEnable;
  109. LONG VideoDecoderVCRTiming;
  110. // VideoControl settings (these are set if a pin is not opened,
  111. // otherwise, the STREAMEX values are used.
  112. LONG VideoControlMode;
  113. // Compressor settings (these are set if a pin is not opened,
  114. // otherwise, the STREAMEX values are used.
  115. COMPRESSION_SETTINGS CompressionSettings;
  116. // Channel Change information
  117. KS_TVTUNER_CHANGE_INFO TVTunerChangeInfo;
  118. // Bits indicating protection status; eg, has Macrovision been detected?
  119. ULONG ProtectionStatus;
  120. } HW_DEVICE_EXTENSION, *PHW_DEVICE_EXTENSION;
  121. //
  122. // this structure is our per stream extension structure. This stores
  123. // information that is relevant on a per stream basis. Whenever a new stream
  124. // is opened, the stream class driver will allocate whatever extension size
  125. // is specified in the HwInitData.PerStreamExtensionSize.
  126. //
  127. typedef struct _STREAMEX {
  128. PHW_DEVICE_EXTENSION pHwDevExt; // For timer use
  129. PHW_STREAM_OBJECT pStreamObject; // For timer use
  130. KS_VIDEOINFOHEADER *pVideoInfoHeader; // format (variable size!)
  131. KSPIN_LOCK lockVideoInfoHeader;// lock the access to pVideoInfoHeader
  132. DWORD biSizeImage; // a copy from InfoHdr to avoid lock
  133. KS_DATARANGE_VIDEO_VBI *pVBIStreamFormat;
  134. KS_FRAME_INFO FrameInfo; // PictureNumber, etc.
  135. KS_VBI_FRAME_INFO VBIFrameInfo; // PictureNumber, etc.
  136. ULONG fDiscontinuity; // Discontinuity since last valid
  137. KSSTATE KSState; // Run, Stop, Pause
  138. UCHAR LineBuffer[720 * 3];// working buffer (RGB24)
  139. // Clock
  140. HANDLE hMasterClock; // Master clock to use
  141. REFERENCE_TIME QST_Now; // KeQuerySystemTime currently
  142. REFERENCE_TIME QST_NextFrame; // When to capture the next frame
  143. REFERENCE_TIME QST_StreamTime; // Stream time reported by master clock
  144. REFERENCE_TIME AvgTimePerFrame; // Extracted from pVideoInfoHeader
  145. // Compressor settings (note these are duplicated in the
  146. // HW_DEVICE_EXTENSION to allow setting these before a pin is created)
  147. COMPRESSION_SETTINGS CompressionSettings;
  148. // VideoControl settings (note these are duplicated in the
  149. // HW_DEVICE_EXTENSION to allow setting these before a pin is created)
  150. LONG VideoControlMode;
  151. // Kernel DDraw interface
  152. BOOL KernelDirectDrawRegistered;
  153. HANDLE UserDirectDrawHandle; // DD itself
  154. HANDLE KernelDirectDrawHandle;
  155. BOOL PreEventOccurred;
  156. BOOL PostEventOccurred;
  157. BOOL SentVBIInfoHeader;
  158. } STREAMEX, *PSTREAMEX;
  159. //
  160. // this structure defines the per request extension. It defines any storage
  161. // space that the mini driver may need in each request packet.
  162. //
  163. typedef struct _SRB_EXTENSION {
  164. LIST_ENTRY ListEntry;
  165. PHW_STREAM_REQUEST_BLOCK pSrb;
  166. HANDLE UserSurfaceHandle; // DDraw
  167. HANDLE KernelSurfaceHandle; // DDraw
  168. } SRB_EXTENSION, * PSRB_EXTENSION;
  169. // -------------------------------------------------------------------
  170. //
  171. // Adapter level prototypes
  172. //
  173. // These functions affect the device as a whole, as opposed to
  174. // affecting individual streams.
  175. //
  176. // -------------------------------------------------------------------
  177. //
  178. // DriverEntry:
  179. //
  180. // This routine is called when the mini driver is first loaded. The driver
  181. // should then call the StreamClassRegisterAdapter function to register with
  182. // the stream class driver
  183. //
  184. ULONG DriverEntry (PVOID Context1, PVOID Context2);
  185. //
  186. // This routine is called by the stream class driver with configuration
  187. // information for an adapter that the mini driver should load on. The mini
  188. // driver should still perform a small verification to determine that the
  189. // adapter is present at the specified addresses, but should not attempt to
  190. // find an adapter as it would have with previous NT miniports.
  191. //
  192. // All initialization of the adapter should also be performed at this time.
  193. //
  194. BOOLEAN STREAMAPI HwInitialize (IN OUT PHW_STREAM_REQUEST_BLOCK pSrb);
  195. //
  196. // This routine is called when the system is going to remove or disable the
  197. // device.
  198. //
  199. // The mini-driver should free any system resources that it allocated at this
  200. // time. Note that system resources allocated for the mini-driver by the
  201. // stream class driver will be free'd by the stream driver, and should not be
  202. // free'd in this routine. (Such as the HW_DEVICE_EXTENSION)
  203. //
  204. BOOLEAN STREAMAPI HwUnInitialize ( PHW_STREAM_REQUEST_BLOCK pSrb);
  205. //
  206. // This is the prototype for the Hardware Interrupt Handler. This routine
  207. // will be called whenever the minidriver receives an interrupt
  208. //
  209. BOOLEAN HwInterrupt ( IN PHW_DEVICE_EXTENSION pDeviceExtension );
  210. //
  211. // This is the prototype for the stream enumeration function. This routine
  212. // provides the stream class driver with the information on data stream types
  213. // supported
  214. //
  215. VOID STREAMAPI AdapterStreamInfo(PHW_STREAM_REQUEST_BLOCK pSrb);
  216. //
  217. // This is the prototype for the stream open function
  218. //
  219. VOID STREAMAPI AdapterOpenStream(PHW_STREAM_REQUEST_BLOCK pSrb);
  220. //
  221. // This is the prototype for the stream close function
  222. //
  223. VOID STREAMAPI AdapterCloseStream(PHW_STREAM_REQUEST_BLOCK pSrb);
  224. //
  225. // This is the prototype for the AdapterReceivePacket routine. This is the
  226. // entry point for command packets that are sent to the adapter (not to a
  227. // specific open stream)
  228. //
  229. VOID STREAMAPI AdapterReceivePacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  230. //
  231. // This is the protoype for the cancel packet routine. This routine enables
  232. // the stream class driver to cancel an outstanding packet.
  233. //
  234. VOID STREAMAPI AdapterCancelPacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  235. //
  236. // This is the packet timeout function. The adapter may choose to ignore a
  237. // packet timeout, or rest the adapter and cancel the requests, as required.
  238. //
  239. VOID STREAMAPI AdapterTimeoutPacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  240. //
  241. // Adapter level property set handling
  242. //
  243. VOID STREAMAPI AdapterGetCrossbarProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  244. VOID STREAMAPI AdapterSetCrossbarProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  245. VOID STREAMAPI AdapterSetTunerProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  246. VOID STREAMAPI AdapterGetTunerProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  247. VOID STREAMAPI AdapterSetVideoProcAmpProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  248. VOID STREAMAPI AdapterGetVideoProcAmpProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  249. VOID STREAMAPI AdapterSetCameraControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  250. VOID STREAMAPI AdapterGetCameraControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  251. VOID STREAMAPI AdapterSetTVAudioProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  252. VOID STREAMAPI AdapterGetTVAudioProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  253. VOID STREAMAPI AdapterSetAnalogVideoDecoderProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  254. VOID STREAMAPI AdapterGetAnalogVideoDecoderProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  255. VOID STREAMAPI AdapterSetVideoControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  256. VOID STREAMAPI AdapterGetVideoControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  257. VOID STREAMAPI AdapterGetVideoCompressionProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  258. VOID STREAMAPI AdapterSetVideoCompressionProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  259. VOID STREAMAPI AdapterSetProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  260. VOID STREAMAPI AdapterGetProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  261. BOOL
  262. STREAMAPI
  263. AdapterVerifyFormat(
  264. PKSDATAFORMAT pKSDataFormatToVerify,
  265. int StreamNumber);
  266. BOOL
  267. STREAMAPI
  268. AdapterFormatFromRange(
  269. IN PHW_STREAM_REQUEST_BLOCK pSrb);
  270. VOID
  271. STREAMAPI
  272. CompleteDeviceSRB (
  273. IN PHW_STREAM_REQUEST_BLOCK pSrb
  274. );
  275. VOID
  276. STREAMAPI
  277. AdapterSetInstance (
  278. PHW_STREAM_REQUEST_BLOCK pSrb
  279. );
  280. //
  281. // prototypes for general queue management using a busy flag
  282. //
  283. BOOL
  284. STREAMAPI
  285. AddToListIfBusy (
  286. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  287. IN KSPIN_LOCK *SpinLock,
  288. IN OUT BOOL *BusyFlag,
  289. IN LIST_ENTRY *ListHead
  290. );
  291. BOOL
  292. STREAMAPI
  293. RemoveFromListIfAvailable (
  294. IN OUT PHW_STREAM_REQUEST_BLOCK *pSrb,
  295. IN KSPIN_LOCK *SpinLock,
  296. IN OUT BOOL *BusyFlag,
  297. IN LIST_ENTRY *ListHead
  298. );
  299. // -------------------------------------------------------------------
  300. //
  301. // Stream level prototypes
  302. //
  303. // These functions affect individual streams, as opposed to
  304. // affecting the device as a whole.
  305. //
  306. // -------------------------------------------------------------------
  307. //
  308. // Routines to manage the SRB queue on a per stream basis
  309. //
  310. VOID
  311. STREAMAPI
  312. VideoQueueAddSRB (
  313. IN PHW_STREAM_REQUEST_BLOCK pSrb
  314. );
  315. PHW_STREAM_REQUEST_BLOCK
  316. STREAMAPI
  317. VideoQueueRemoveSRB (
  318. PHW_DEVICE_EXTENSION pHwDevExt,
  319. int StreamNumber
  320. );
  321. VOID
  322. STREAMAPI
  323. VideoQueueCancelAllSRBs (
  324. PSTREAMEX pStrmEx
  325. );
  326. BOOL
  327. STREAMAPI
  328. VideoQueueCancelOneSRB (
  329. PSTREAMEX pStrmEx,
  330. PHW_STREAM_REQUEST_BLOCK pSrbToCancel
  331. );
  332. //
  333. // StreamFormat declarations
  334. //
  335. extern KS_DATARANGE_VIDEO_VBI StreamFormatVBI;
  336. extern KSDATARANGE StreamFormatNABTS;
  337. extern KSDATARANGE StreamFormatCC;
  338. //
  339. // Data packet handlers
  340. //
  341. //
  342. // prototypes for data handling routines
  343. //
  344. VOID STREAMAPI CompleteStreamSRB (IN PHW_STREAM_REQUEST_BLOCK pSrb);
  345. BOOL STREAMAPI VideoSetFormat(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  346. VOID STREAMAPI VideoReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  347. VOID STREAMAPI VideoReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  348. VOID STREAMAPI AnalogVideoReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  349. VOID STREAMAPI AnalogVideoReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  350. VOID STREAMAPI VBIReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  351. VOID STREAMAPI VBIReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  352. VOID STREAMAPI EnableIRQ(PHW_STREAM_OBJECT pstrm);
  353. VOID STREAMAPI DisableIRQ(PHW_STREAM_OBJECT pstrm);
  354. //
  355. // prototypes for properties and states
  356. //
  357. VOID STREAMAPI VideoSetState(PHW_STREAM_REQUEST_BLOCK pSrb);
  358. VOID STREAMAPI VideoGetState(PHW_STREAM_REQUEST_BLOCK pSrb);
  359. VOID STREAMAPI VideoSetProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  360. VOID STREAMAPI VideoGetProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  361. VOID STREAMAPI VideoStreamGetConnectionProperty (PHW_STREAM_REQUEST_BLOCK pSrb);
  362. VOID STREAMAPI VideoStreamGetDroppedFramesProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  363. //
  364. // stream clock functions
  365. //
  366. VOID
  367. STREAMAPI
  368. VideoIndicateMasterClock (PHW_STREAM_REQUEST_BLOCK pSrb);
  369. //
  370. // The point of it all
  371. //
  372. VOID
  373. STREAMAPI
  374. VideoCaptureRoutine(
  375. IN PSTREAMEX pStrmEx
  376. );
  377. #ifdef __cplusplus
  378. }
  379. #endif // __cplusplus
  380. #endif //__CAPMAIN_H__