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.

464 lines
16 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. KS_DATARANGE_VIDEO_VBI *pVBIStreamFormat;
  132. KS_FRAME_INFO FrameInfo; // PictureNumber, etc.
  133. KS_VBI_FRAME_INFO VBIFrameInfo; // PictureNumber, etc.
  134. ULONG fDiscontinuity; // Discontinuity since last valid
  135. KSSTATE KSState; // Run, Stop, Pause
  136. UCHAR LineBuffer[720 * 3];// working buffer (RGB24)
  137. // Clock
  138. HANDLE hMasterClock; // Master clock to use
  139. REFERENCE_TIME QST_Now; // KeQuerySystemTime currently
  140. REFERENCE_TIME QST_NextFrame; // When to capture the next frame
  141. REFERENCE_TIME QST_StreamTime; // Stream time reported by master clock
  142. REFERENCE_TIME AvgTimePerFrame; // Extracted from pVideoInfoHeader
  143. // Compressor settings (note these are duplicated in the
  144. // HW_DEVICE_EXTENSION to allow setting these before a pin is created)
  145. COMPRESSION_SETTINGS CompressionSettings;
  146. // VideoControl settings (note these are duplicated in the
  147. // HW_DEVICE_EXTENSION to allow setting these before a pin is created)
  148. LONG VideoControlMode;
  149. // Kernel DDraw interface
  150. BOOL KernelDirectDrawRegistered;
  151. HANDLE UserDirectDrawHandle; // DD itself
  152. HANDLE KernelDirectDrawHandle;
  153. BOOL PreEventOccurred;
  154. BOOL PostEventOccurred;
  155. BOOL SentVBIInfoHeader;
  156. } STREAMEX, *PSTREAMEX;
  157. //
  158. // this structure defines the per request extension. It defines any storage
  159. // space that the mini driver may need in each request packet.
  160. //
  161. typedef struct _SRB_EXTENSION {
  162. LIST_ENTRY ListEntry;
  163. PHW_STREAM_REQUEST_BLOCK pSrb;
  164. HANDLE UserSurfaceHandle; // DDraw
  165. HANDLE KernelSurfaceHandle; // DDraw
  166. } SRB_EXTENSION, * PSRB_EXTENSION;
  167. // -------------------------------------------------------------------
  168. //
  169. // Adapter level prototypes
  170. //
  171. // These functions affect the device as a whole, as opposed to
  172. // affecting individual streams.
  173. //
  174. // -------------------------------------------------------------------
  175. //
  176. // DriverEntry:
  177. //
  178. // This routine is called when the mini driver is first loaded. The driver
  179. // should then call the StreamClassRegisterAdapter function to register with
  180. // the stream class driver
  181. //
  182. ULONG DriverEntry (PVOID Context1, PVOID Context2);
  183. //
  184. // This routine is called by the stream class driver with configuration
  185. // information for an adapter that the mini driver should load on. The mini
  186. // driver should still perform a small verification to determine that the
  187. // adapter is present at the specified addresses, but should not attempt to
  188. // find an adapter as it would have with previous NT miniports.
  189. //
  190. // All initialization of the adapter should also be performed at this time.
  191. //
  192. BOOLEAN STREAMAPI HwInitialize (IN OUT PHW_STREAM_REQUEST_BLOCK pSrb);
  193. //
  194. // This routine is called when the system is going to remove or disable the
  195. // device.
  196. //
  197. // The mini-driver should free any system resources that it allocated at this
  198. // time. Note that system resources allocated for the mini-driver by the
  199. // stream class driver will be free'd by the stream driver, and should not be
  200. // free'd in this routine. (Such as the HW_DEVICE_EXTENSION)
  201. //
  202. BOOLEAN STREAMAPI HwUnInitialize ( PHW_STREAM_REQUEST_BLOCK pSrb);
  203. //
  204. // This is the prototype for the Hardware Interrupt Handler. This routine
  205. // will be called whenever the minidriver receives an interrupt
  206. //
  207. BOOLEAN HwInterrupt ( IN PHW_DEVICE_EXTENSION pDeviceExtension );
  208. //
  209. // This is the prototype for the stream enumeration function. This routine
  210. // provides the stream class driver with the information on data stream types
  211. // supported
  212. //
  213. VOID STREAMAPI AdapterStreamInfo(PHW_STREAM_REQUEST_BLOCK pSrb);
  214. //
  215. // This is the prototype for the stream open function
  216. //
  217. VOID STREAMAPI AdapterOpenStream(PHW_STREAM_REQUEST_BLOCK pSrb);
  218. //
  219. // This is the prototype for the stream close function
  220. //
  221. VOID STREAMAPI AdapterCloseStream(PHW_STREAM_REQUEST_BLOCK pSrb);
  222. //
  223. // This is the prototype for the AdapterReceivePacket routine. This is the
  224. // entry point for command packets that are sent to the adapter (not to a
  225. // specific open stream)
  226. //
  227. VOID STREAMAPI AdapterReceivePacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  228. //
  229. // This is the protoype for the cancel packet routine. This routine enables
  230. // the stream class driver to cancel an outstanding packet.
  231. //
  232. VOID STREAMAPI AdapterCancelPacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  233. //
  234. // This is the packet timeout function. The adapter may choose to ignore a
  235. // packet timeout, or rest the adapter and cancel the requests, as required.
  236. //
  237. VOID STREAMAPI AdapterTimeoutPacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  238. //
  239. // Adapter level property set handling
  240. //
  241. VOID STREAMAPI AdapterGetCrossbarProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  242. VOID STREAMAPI AdapterSetCrossbarProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  243. VOID STREAMAPI AdapterSetTunerProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  244. VOID STREAMAPI AdapterGetTunerProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  245. VOID STREAMAPI AdapterSetVideoProcAmpProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  246. VOID STREAMAPI AdapterGetVideoProcAmpProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  247. VOID STREAMAPI AdapterSetCameraControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  248. VOID STREAMAPI AdapterGetCameraControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  249. VOID STREAMAPI AdapterSetTVAudioProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  250. VOID STREAMAPI AdapterGetTVAudioProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  251. VOID STREAMAPI AdapterSetAnalogVideoDecoderProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  252. VOID STREAMAPI AdapterGetAnalogVideoDecoderProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  253. VOID STREAMAPI AdapterSetVideoControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  254. VOID STREAMAPI AdapterGetVideoControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  255. VOID STREAMAPI AdapterGetVideoCompressionProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  256. VOID STREAMAPI AdapterSetVideoCompressionProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  257. VOID STREAMAPI AdapterSetProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  258. VOID STREAMAPI AdapterGetProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  259. BOOL
  260. STREAMAPI
  261. AdapterVerifyFormat(
  262. PKSDATAFORMAT pKSDataFormatToVerify,
  263. int StreamNumber);
  264. BOOL
  265. STREAMAPI
  266. AdapterFormatFromRange(
  267. IN PHW_STREAM_REQUEST_BLOCK pSrb);
  268. VOID
  269. STREAMAPI
  270. CompleteDeviceSRB (
  271. IN PHW_STREAM_REQUEST_BLOCK pSrb
  272. );
  273. VOID
  274. STREAMAPI
  275. AdapterSetInstance (
  276. PHW_STREAM_REQUEST_BLOCK pSrb
  277. );
  278. //
  279. // prototypes for general queue management using a busy flag
  280. //
  281. BOOL
  282. STREAMAPI
  283. AddToListIfBusy (
  284. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  285. IN KSPIN_LOCK *SpinLock,
  286. IN OUT BOOL *BusyFlag,
  287. IN LIST_ENTRY *ListHead
  288. );
  289. BOOL
  290. STREAMAPI
  291. RemoveFromListIfAvailable (
  292. IN OUT PHW_STREAM_REQUEST_BLOCK *pSrb,
  293. IN KSPIN_LOCK *SpinLock,
  294. IN OUT BOOL *BusyFlag,
  295. IN LIST_ENTRY *ListHead
  296. );
  297. // -------------------------------------------------------------------
  298. //
  299. // Stream level prototypes
  300. //
  301. // These functions affect individual streams, as opposed to
  302. // affecting the device as a whole.
  303. //
  304. // -------------------------------------------------------------------
  305. //
  306. // Routines to manage the SRB queue on a per stream basis
  307. //
  308. VOID
  309. STREAMAPI
  310. VideoQueueAddSRB (
  311. IN PHW_STREAM_REQUEST_BLOCK pSrb
  312. );
  313. PHW_STREAM_REQUEST_BLOCK
  314. STREAMAPI
  315. VideoQueueRemoveSRB (
  316. PHW_DEVICE_EXTENSION pHwDevExt,
  317. int StreamNumber
  318. );
  319. VOID
  320. STREAMAPI
  321. VideoQueueCancelAllSRBs (
  322. PSTREAMEX pStrmEx
  323. );
  324. BOOL
  325. STREAMAPI
  326. VideoQueueCancelOneSRB (
  327. PSTREAMEX pStrmEx,
  328. PHW_STREAM_REQUEST_BLOCK pSrbToCancel
  329. );
  330. //
  331. // StreamFormat declarations
  332. //
  333. extern KS_DATARANGE_VIDEO_VBI StreamFormatVBI;
  334. extern KSDATARANGE StreamFormatNABTS;
  335. extern KSDATARANGE StreamFormatCC;
  336. //
  337. // Data packet handlers
  338. //
  339. //
  340. // prototypes for data handling routines
  341. //
  342. VOID STREAMAPI CompleteStreamSRB (IN PHW_STREAM_REQUEST_BLOCK pSrb);
  343. BOOL STREAMAPI VideoSetFormat(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  344. VOID STREAMAPI VideoReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  345. VOID STREAMAPI VideoReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  346. VOID STREAMAPI AnalogVideoReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  347. VOID STREAMAPI AnalogVideoReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  348. VOID STREAMAPI VBIReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  349. VOID STREAMAPI VBIReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  350. VOID STREAMAPI EnableIRQ(PHW_STREAM_OBJECT pstrm);
  351. VOID STREAMAPI DisableIRQ(PHW_STREAM_OBJECT pstrm);
  352. //
  353. // prototypes for properties and states
  354. //
  355. VOID STREAMAPI VideoSetState(PHW_STREAM_REQUEST_BLOCK pSrb);
  356. VOID STREAMAPI VideoGetState(PHW_STREAM_REQUEST_BLOCK pSrb);
  357. VOID STREAMAPI VideoSetProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  358. VOID STREAMAPI VideoGetProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  359. VOID STREAMAPI VideoStreamGetConnectionProperty (PHW_STREAM_REQUEST_BLOCK pSrb);
  360. VOID STREAMAPI VideoStreamGetDroppedFramesProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  361. //
  362. // stream clock functions
  363. //
  364. VOID
  365. STREAMAPI
  366. VideoIndicateMasterClock (PHW_STREAM_REQUEST_BLOCK pSrb);
  367. //
  368. // The point of it all
  369. //
  370. VOID
  371. STREAMAPI
  372. VideoCaptureRoutine(
  373. IN PSTREAMEX pStrmEx
  374. );
  375. #ifdef __cplusplus
  376. }
  377. #endif // __cplusplus
  378. #endif //__CAPMAIN_H__