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.

368 lines
14 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 - 1998 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //==========================================================================;
  11. #ifndef __CODMAIN_H__
  12. #define __CODMAIN_H__
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif // __cplusplus
  16. #include "ccdecode.h"
  17. #include "defaults.h"
  18. #define ENTRIES(a) (sizeof(a)/sizeof(*(a)))
  19. /**************************************************************/
  20. /* Driver Name - Change this to reflect your executable name! */
  21. /**************************************************************/
  22. #define CODECNAME "CCDecode"
  23. // ------------------------------------------------------------------------
  24. // The master list of all streams supported by this driver
  25. // ------------------------------------------------------------------------
  26. typedef enum {
  27. STREAM_VBI = 0, // VBI samples in
  28. STREAM_CC, // Decoded VBI out (Should be less "generic")
  29. #ifdef CCINPUTPIN
  30. STREAM_CCINPUT, // H/W decoded CC in
  31. #endif // CCINPUTPIN
  32. MAX_STREAM_COUNT
  33. };
  34. // The MAX_STREAM_COUNT value must be equal to DRIVER_STREAM_COUNT
  35. // This particular value must be defined here to avoid circular references
  36. // We manage multiple instances of each pin up to this limit
  37. #define MAX_PIN_INSTANCES 8
  38. #define BIT(n) (((unsigned long)1)<<(n))
  39. #define BITSIZE(v) (sizeof(v)*8)
  40. #define SETBIT(array,n) (array[(n)/BITSIZE(*array)] |= BIT((n)%BITSIZE(*array)))
  41. #define CLEARBIT(array,n) (array[(n)/BITSIZE(*array)] &= ~BIT((n)%BITSIZE(*array)))
  42. #define TESTBIT(array,n) (BIT((n)%BITSIZE(*array)) == (array[(n)/BITSIZE(*array)] & BIT(n%BITSIZE(*array))))
  43. /*****************************************************************************
  44. *
  45. * The following structures are samples of information that could be used in
  46. * a device extension structure
  47. *
  48. *****************************************************************************/
  49. //
  50. // Result of DSP operation
  51. //
  52. typedef struct _DSPRESULT
  53. {
  54. CHAR Decoded[2];
  55. int Confidence;
  56. }DSPRESULT, *PDSPRESULT;
  57. //
  58. // definition of the full HW device extension structure This is the structure
  59. // that will be allocated in HW_INITIALIZATION by the stream class driver
  60. // Any information that is used in processing a device request (as opposed to
  61. // a STREAM based request) should be in this structure. A pointer to this
  62. // structure will be passed in all requests to the minidriver. (See
  63. // HW_STREAM_REQUEST_BLOCK in STRMINI.H)
  64. //
  65. typedef struct _HW_DEVICE_EXTENSION {
  66. struct _STREAMEX * pStrmEx[MAX_STREAM_COUNT][MAX_PIN_INSTANCES]; // Pointers to each stream
  67. UINT ActualInstances[MAX_STREAM_COUNT]; // Counter of instances per stream
  68. // Clock
  69. REFERENCE_TIME QST_Start; // KeQuerySystemTime at run
  70. REFERENCE_TIME QST_Now; // KeQuerySystemTime currently
  71. REFERENCE_TIME WallTime100ns; // elapsed time based on KeQueryPerformanceCounter
  72. // The following VBICODECFILTERING_* fields are defaults for newly created output pins(copied)
  73. VBICODECFILTERING_SCANLINES ScanlinesRequested; // Bitmask of requested scanlines
  74. VBICODECFILTERING_SCANLINES ScanlinesDiscovered;// Bitmask of discovered scanlines
  75. VBICODECFILTERING_CC_SUBSTREAMS SubstreamsRequested;// Bitmask of requested substream IDs
  76. VBICODECFILTERING_CC_SUBSTREAMS SubstreamsDiscovered;// Bitmask of discovered substream IDs
  77. // This is the global version of the STATISTICS property
  78. VBICODECFILTERING_STATISTICS_CC Statistics;
  79. PDSPRESULT DSPResult; // Pointer to result array
  80. ULONG DSPResultStartLine;
  81. ULONG DSPResultEndLine;
  82. ULONG SubStreamState[CC_MAX_HW_DECODE_LINES][2];
  83. ALL_STREAM_INFO * Streams;
  84. ULONG fTunerChange; // TV Tuner channel change in progress
  85. LIST_ENTRY AdapterSRBQueue;
  86. KSPIN_LOCK AdapterSRBSpinLock;
  87. BOOL bAdapterQueueInitialized;
  88. #ifdef CCINPUTPIN
  89. // Last pictureNumber that decoded VBI data was processed
  90. // (used for coordination of multiple input pins)
  91. FAST_MUTEX LastPictureMutex;
  92. LONGLONG LastPictureNumber;
  93. #endif // CCINPUTPIN
  94. } HW_DEVICE_EXTENSION, *PHW_DEVICE_EXTENSION;
  95. //
  96. // this structure is our per stream extension structure. This stores
  97. // information that is relevant on a per stream basis. Whenever a new stream
  98. // is opened, the stream class driver will allocate whatever extension size
  99. // is specified in the HwInitData.PerStreamExtensionSize.
  100. //
  101. typedef struct _STREAMEX
  102. {
  103. PHW_DEVICE_EXTENSION pHwDevExt; // For timer use
  104. PHW_STREAM_OBJECT pStreamObject; // For timer use
  105. KS_VBI_FRAME_INFO FrameInfo; // PictureNumber, etc.
  106. ULONG fDiscontinuity; // Discontinuity since last valid
  107. ULONG StreamInstance; // 0..NumberOfPossibleInstances-1
  108. LONGLONG LastPictureNumber; // Last received picture number
  109. KSSTATE KSState; // Run, Stop, Pause
  110. REFERENCE_TIME FrameTime100ns; // elapsed time based on frames captured
  111. HANDLE hMasterClock;
  112. HANDLE hClock;
  113. KSDATAFORMAT OpenedFormat; // Based on the actual open request.
  114. KSDATAFORMAT MatchedFormat; // Format that matched the open format.
  115. VBICODECFILTERING_SCANLINES ScanlinesRequested; // Bitmask of requested scanlines
  116. VBICODECFILTERING_SCANLINES ScanlinesDiscovered; // Bitmask of discovered scanlines
  117. VBICODECFILTERING_SCANLINES LastOddScanlinesDiscovered; // Bitmask of scanlines last discovered
  118. VBICODECFILTERING_SCANLINES LastEvenScanlinesDiscovered; // Bitmask of scanlines last discovered
  119. VBICODECFILTERING_CC_SUBSTREAMS SubstreamsRequested; // Bitmask of requested substream IDs
  120. VBICODECFILTERING_CC_SUBSTREAMS SubstreamsDiscovered; // Bitmask of discovered substream IDs
  121. VBICODECFILTERING_STATISTICS_CC_PIN PinStats; // CC Pin version of statistics property
  122. CCState State; // State variable for DSP
  123. KS_VBIINFOHEADER CurrentVBIInfoHeader;
  124. KSPIN_LOCK StreamControlSpinLock, // Command queue spin lock
  125. StreamDataSpinLock; // Data queue spin lock
  126. LIST_ENTRY StreamDataQueue, // Stream data queue
  127. StreamControlQueue; // Stream command queue
  128. #ifdef CCINPUTPIN
  129. // For when the VBI input pin is waiting for the HWCC input pin to catch up
  130. PHW_STREAM_REQUEST_BLOCK pVBISrbOnHold;
  131. KSPIN_LOCK VBIOnHoldSpinLock;
  132. #endif // CCINPUTPIN
  133. } STREAMEX, *PSTREAMEX;
  134. //
  135. // This structure is our per SRB extension, and carries the forward and backward
  136. // links for the pending SRB queue.
  137. //
  138. typedef struct _SRB_EXTENSION
  139. {
  140. LIST_ENTRY ListEntry;
  141. PHW_STREAM_REQUEST_BLOCK pSrb;
  142. }SRB_EXTENSION, *PSRB_EXTENSION;
  143. /*****************************************************************************
  144. *
  145. * the following section defines prototypes for the minidriver initialization
  146. * routines
  147. *
  148. ******************************************************************************/
  149. //
  150. // DriverEntry:
  151. //
  152. // This routine is called when the mini driver is first loaded. The driver
  153. // should then call the StreamClassRegisterAdapter function to register with
  154. // the stream class driver
  155. //
  156. ULONG DriverEntry (PVOID Context1, PVOID Context2);
  157. //
  158. // This routine is called by the stream class driver with configuration
  159. // information for an adapter that the mini driver should load on. The mini
  160. // driver should still perform a small verification to determine that the
  161. // adapter is present at the specified addresses, but should not attempt to
  162. // find an adapter as it would have with previous NT miniports.
  163. //
  164. // All initialization of the codec should also be performed at this time.
  165. //
  166. BOOLEAN CodecInitialize (IN OUT PHW_STREAM_REQUEST_BLOCK pSrb);
  167. //
  168. // This routine is called when the system is going to remove or disable the
  169. // device.
  170. //
  171. // The mini-driver should free any system resources that it allocated at this
  172. // time. Note that system resources allocated for the mini-driver by the
  173. // stream class driver will be free'd by the stream driver, and should not be
  174. // free'd in this routine. (Such as the HW_DEVICE_EXTENSION)
  175. //
  176. BOOLEAN CodecUnInitialize( PHW_STREAM_REQUEST_BLOCK pSrb);
  177. BOOLEAN CodecQueryUnload ( PHW_STREAM_REQUEST_BLOCK pSrb); // Not implemented currently
  178. //
  179. // This is the prototype for the Hardware Interrupt Handler. This routine
  180. // will be called if the minidriver registers for and receives an interrupt
  181. //
  182. BOOLEAN HwInterrupt ( IN PHW_DEVICE_EXTENSION pDeviceExtension );
  183. //
  184. // This is the prototype for the stream enumeration function. This routine
  185. // provides the stream class driver with the information on data stream types
  186. // supported
  187. //
  188. VOID CodecStreamInfo(PHW_STREAM_REQUEST_BLOCK pSrb);
  189. //
  190. // This is the prototype for the stream open function
  191. //
  192. VOID CodecOpenStream(PHW_STREAM_REQUEST_BLOCK pSrb);
  193. //
  194. // This is the prototype for the stream close function
  195. //
  196. VOID CodecCloseStream(PHW_STREAM_REQUEST_BLOCK pSrb);
  197. //
  198. // This is the prototype for the CodecReceivePacket routine. This is the
  199. // entry point for command packets that are sent to the codec (not to a
  200. // specific open stream)
  201. //
  202. VOID STREAMAPI CodecReceivePacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  203. //
  204. // This is the protoype for the cancel packet routine. This routine enables
  205. // the stream class driver to cancel an outstanding packet.
  206. //
  207. VOID STREAMAPI CodecCancelPacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  208. //
  209. // This is the packet timeout function. The codec may choose to ignore a
  210. // packet timeout, or reset the codec and cancel the requests, as required.
  211. //
  212. VOID STREAMAPI CodecTimeoutPacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  213. VOID STREAMAPI CodecGetProperty(IN PHW_STREAM_REQUEST_BLOCK Srb);
  214. VOID STREAMAPI CodecSetProperty(IN PHW_STREAM_REQUEST_BLOCK Srb);
  215. BOOL
  216. CodecCompareGUIDsAndFormatSize( IN PKSDATARANGE DataRange1,
  217. IN PKSDATARANGE DataRange2,
  218. BOOLEAN bCheckSize );
  219. BOOL
  220. CodecVerifyFormat(IN KSDATAFORMAT *pKSDataFormat,
  221. IN UINT StreamNumber,
  222. IN PKSDATARANGE pMatchedFormat );
  223. BOOL
  224. CodecVBIFormatFromRange(
  225. IN PHW_STREAM_REQUEST_BLOCK pSrb);
  226. BOOL
  227. CodecCCFormatFromRange(
  228. IN PHW_STREAM_REQUEST_BLOCK pSrb );
  229. void
  230. CompleteStreamSRB (
  231. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  232. STREAM_MINIDRIVER_STREAM_NOTIFICATION_TYPE NotificationType1,
  233. BOOL fUseNotification2,
  234. STREAM_MINIDRIVER_STREAM_NOTIFICATION_TYPE NotificationType2
  235. );
  236. void
  237. CompleteDeviceSRB (
  238. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  239. IN STREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE NotificationType,
  240. BOOL fReadyForNext
  241. );
  242. //
  243. // prototypes for data handling routines
  244. //
  245. void CompleteStreamIRP (IN PHW_STREAM_REQUEST_BLOCK pSrb, BOOLEAN ReadyForNext);
  246. VOID STREAMAPI VBIReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  247. VOID STREAMAPI VBIReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  248. void EnableIRQ(PHW_STREAM_OBJECT pstrm);
  249. void DisableIRQ(PHW_STREAM_OBJECT pstrm);
  250. //
  251. // prototypes for properties and states
  252. //
  253. VOID VideoSetState(PHW_STREAM_REQUEST_BLOCK pSrb);
  254. VOID VideoGetState(PHW_STREAM_REQUEST_BLOCK pSrb);
  255. VOID VideoSetProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  256. VOID VideoGetProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  257. //VOID VideoStreamSetConnectionProperty (PHW_STREAM_REQUEST_BLOCK pSrb); // Not implemented
  258. VOID VideoStreamGetConnectionProperty (PHW_STREAM_REQUEST_BLOCK pSrb);
  259. VOID VideoStreamSetVBIFilteringProperty (PHW_STREAM_REQUEST_BLOCK pSrb);
  260. VOID VideoStreamGetVBIFilteringProperty (PHW_STREAM_REQUEST_BLOCK pSrb);
  261. //
  262. // system time functions
  263. //
  264. ULONGLONG VideoGetSystemTime();
  265. //
  266. // stream clock functions
  267. //
  268. VOID VideoIndicateMasterClock(PHW_STREAM_REQUEST_BLOCK pSrb);
  269. //
  270. // SRB Queue Management functions
  271. //
  272. BOOL STREAMAPI QueueAddIfNotEmpty(
  273. IN PHW_STREAM_REQUEST_BLOCK,
  274. IN PKSPIN_LOCK,
  275. IN PLIST_ENTRY
  276. );
  277. BOOL STREAMAPI QueueAdd(
  278. IN PHW_STREAM_REQUEST_BLOCK,
  279. IN PKSPIN_LOCK,
  280. IN PLIST_ENTRY
  281. );
  282. BOOL STREAMAPI QueueRemove(
  283. IN OUT PHW_STREAM_REQUEST_BLOCK *,
  284. IN PKSPIN_LOCK,
  285. IN PLIST_ENTRY
  286. );
  287. BOOL STREAMAPI QueueRemoveSpecific(
  288. IN PHW_STREAM_REQUEST_BLOCK,
  289. IN PKSPIN_LOCK,
  290. IN PLIST_ENTRY
  291. );
  292. BOOL STREAMAPI QueueEmpty(
  293. IN PKSPIN_LOCK,
  294. IN PLIST_ENTRY
  295. );
  296. #ifdef __cplusplus
  297. }
  298. #endif // __cplusplus
  299. #endif //__CODMAIN_H__