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.

578 lines
20 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 - 1996 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. #ifdef TOSHIBA
  17. //#define _FPS_COUNT_ // For FPS confirm
  18. #endif//TOSHIBA
  19. #ifndef FIELDOFFSET
  20. #define FIELDOFFSET(type, field) (int)((INT_PTR)(&((type *)1)->field)-1)
  21. #endif
  22. #ifndef mmioFOURCC
  23. #define mmioFOURCC( ch0, ch1, ch2, ch3 ) \
  24. ( (DWORD)(BYTE)(ch0) | ( (DWORD)(BYTE)(ch1) << 8 ) | \
  25. ( (DWORD)(BYTE)(ch2) << 16 ) | ( (DWORD)(BYTE)(ch3) << 24 ) )
  26. #endif
  27. #ifdef TOSHIBA
  28. #define FOURCC_YVU9 mmioFOURCC('Y', 'V', 'U', '9')
  29. #define FOURCC_YUV12 mmioFOURCC('I', '4', '2', '0')
  30. #else //TOSHIBA
  31. #define FOURCC_YUV422 mmioFOURCC('U', 'Y', 'V', 'Y')
  32. #endif//TOSHIBA
  33. typedef struct _STREAMX;
  34. typedef struct _STREAMX *PSTREAMX;
  35. #ifdef TOSHIBA
  36. #define MAX_TSBVCAP_STREAMS 2
  37. #else //TOSHIBA
  38. #define MAX_TSBVCAP_STREAMS 4
  39. #endif//TOSHIBA
  40. #ifdef TOSHIBA
  41. /* possible capture formats */
  42. typedef enum _CAPTUREFORMAT {
  43. FmtInvalid = 0, // default fmt is 'not set yet'
  44. FmtYUV12, // yuv12 planar
  45. FmtYUV9, // yuv9 planar
  46. MaxCaptureFormat
  47. } CAPTUREFORMAT;
  48. #endif//TOSHIBA
  49. typedef struct _COMPRESSION_SETTINGS {
  50. LONG CompressionKeyFrameRate;
  51. LONG CompressionPFramesPerKeyFrame;
  52. LONG CompressionQuality;
  53. } COMPRESSION_SETTINGS, *PCOMPRESSION_SETTINGS;
  54. //
  55. // definition of the full HW device extension structure This is the structure
  56. // that will be allocated in HW_INITIALIZATION by the stream class driver
  57. // Any information that is used in processing a device request (as opposed to
  58. // a STREAM based request) should be in this structure. A pointer to this
  59. // structure will be passed in all requests to the minidriver. (See
  60. // HW_STREAM_REQUEST_BLOCK in STRMINI.H)
  61. //
  62. typedef struct _HW_DEVICE_EXTENSION {
  63. PULONG ioBaseLocal; // board base address
  64. USHORT Irq; // IRQ level
  65. BOOLEAN IRQExpected; // IRQ expected
  66. PSTREAMX pStrmEx [MAX_TSBVCAP_STREAMS]; // Pointers to each stream
  67. UINT ActualInstances [MAX_TSBVCAP_STREAMS]; // Counter of instances per stream
  68. PDEVICE_OBJECT PDO; // Physical Device Object
  69. DEVICE_POWER_STATE DeviceState; // D0 ... D3
  70. // Spinlock and Queue for the Adapter
  71. BOOL AdapterQueueInitialized; // Stays TRUE after first init
  72. KSPIN_LOCK AdapterSpinLock; // Multiprocessor safe access to AdapterSRBList
  73. LIST_ENTRY AdapterSRBList; // List of pending adapter commands
  74. BOOL ProcessingAdapterSRB; // Master flag which prevents reentry
  75. // Spinlocks and Queues for each data stream
  76. LIST_ENTRY StreamSRBList[MAX_TSBVCAP_STREAMS]; // List of pending read requests
  77. KSPIN_LOCK StreamSRBSpinLock[MAX_TSBVCAP_STREAMS];// Multiprocessor safe access to StreamSRBList
  78. int StreamSRBListSize[MAX_TSBVCAP_STREAMS];// Number of entries in the list
  79. // Control Queues for each data stream
  80. LIST_ENTRY StreamControlSRBList[MAX_TSBVCAP_STREAMS];
  81. BOOL ProcessingControlSRB[MAX_TSBVCAP_STREAMS];
  82. #ifdef TOSHIBA
  83. // VideoProcAmp settings
  84. LONG Brightness;
  85. LONG BrightnessFlags;
  86. LONG Contrast;
  87. LONG ContrastFlags;
  88. LONG Hue;
  89. LONG HueFlags;
  90. LONG Saturation;
  91. LONG SaturationFlags;
  92. LONG ColorEnable;
  93. LONG ColorEnableFlags;
  94. // VideoControl settings (these are set if a pin is not opened,
  95. // otherwise, the STREAMEX values are used.
  96. LONG VideoControlMode;
  97. // Compressor settings (these are set if a pin is not opened,
  98. // otherwise, the STREAMEX values are used.
  99. COMPRESSION_SETTINGS CompressionSettings;
  100. #ifdef TOSHIBA // '98-12-09 Added, for Bug-Report 253529
  101. KSPROPERTY_BOUNDS_LONG BrightnessRange;
  102. KSPROPERTY_BOUNDS_LONG ContrastRange;
  103. KSPROPERTY_BOUNDS_LONG HueRange;
  104. KSPROPERTY_BOUNDS_LONG SaturationRange;
  105. #endif//TOSHIBA
  106. // Misc
  107. volatile BOOL bVideoIn; // are we actually doing video in ?
  108. CAPTUREFORMAT Format; // format of destination DIB
  109. DWORD dwAsicRev;
  110. // source rectangle data
  111. RECT SrcRect;
  112. RECT MaxRect;
  113. // driver DMA structures for direct io
  114. PVOID pRpsDMABuf; // pointer to the RPS DMA buffer
  115. STREAM_PHYSICAL_ADDRESS pPhysRpsDMABuf;// physical address of RPS DMA buffer
  116. // driver capture buffer information
  117. PVOID pCaptureBufferY;
  118. PVOID pCaptureBufferU;
  119. PVOID pCaptureBufferV;
  120. STREAM_PHYSICAL_ADDRESS pPhysCaptureBufferY;
  121. STREAM_PHYSICAL_ADDRESS pPhysCaptureBufferU;
  122. STREAM_PHYSICAL_ADDRESS pPhysCaptureBufferV;
  123. PVOID pCapBuf2Y;
  124. PVOID pCapBuf2U;
  125. PVOID pCapBuf2V;
  126. STREAM_PHYSICAL_ADDRESS pPhysCapBuf2Y;
  127. STREAM_PHYSICAL_ADDRESS pPhysCapBuf2U;
  128. STREAM_PHYSICAL_ADDRESS pPhysCapBuf2V;
  129. BOOL dblBufflag;
  130. // configuration parameters for the video source and the format
  131. ULONG ulWidth;
  132. ULONG ulHeight;
  133. ULONG BufferSize;
  134. // RequestDpc flag for CaptureService
  135. BOOL bRequestDpc;
  136. volatile BOOLEAN DpcRequested;
  137. unsigned uiFramePerSecond;
  138. volatile DWORD s_physDmaActiveFlag;
  139. DWORD YoffsetOdd;
  140. DWORD UoffsetOdd;
  141. DWORD VoffsetOdd;
  142. DWORD YoffsetEven;
  143. DWORD UoffsetEven;
  144. DWORD VoffsetEven;
  145. DWORD Ystride;
  146. DWORD Ustride;
  147. DWORD Vstride;
  148. BOOL NeedCameraON;
  149. BOOL NeedCameraOFF;
  150. BOOL NeedHWInit;
  151. BOOL IsRPSReady;
  152. #else //TOSHIBA
  153. // Unique identifier for the analog video input pin
  154. KSPIN_MEDIUM AnalogVideoInputMedium;
  155. // Crossbar settings
  156. LONG VideoInputConnected; // which input is the video out connected to?
  157. LONG AudioInputConnected; // which input is the audio out connected to?
  158. // TV Tuner settings
  159. ULONG Frequency;
  160. ULONG VideoStandard;
  161. ULONG TuningQuality;
  162. ULONG TunerInput;
  163. ULONG Busy;
  164. // TV Audio settings
  165. ULONG TVAudioMode;
  166. // VideoProcAmp settings
  167. LONG Brightness;
  168. LONG BrightnessFlags;
  169. LONG Contrast;
  170. LONG ContrastFlags;
  171. LONG ColorEnable;
  172. LONG ColorEnableFlags;
  173. // CameraControl settings
  174. LONG Focus;
  175. LONG FocusFlags;
  176. LONG Zoom;
  177. LONG ZoomFlags;
  178. // AnalogVideoDecoder settings
  179. LONG VideoDecoderVideoStandard;
  180. LONG VideoDecoderOutputEnable;
  181. LONG VideoDecoderVCRTiming;
  182. // VideoControl settings (these are set if a pin is not opened,
  183. // otherwise, the STREAMEX values are used.
  184. LONG VideoControlMode;
  185. // Compressor settings (these are set if a pin is not opened,
  186. // otherwise, the STREAMEX values are used.
  187. COMPRESSION_SETTINGS CompressionSettings;
  188. // Channel Change information
  189. KS_TVTUNER_CHANGE_INFO TVTunerChangeInfo;
  190. #endif//TOSHIBA
  191. } HW_DEVICE_EXTENSION, *PHW_DEVICE_EXTENSION;
  192. //
  193. // this structure is our per stream extension structure. This stores
  194. // information that is relevant on a per stream basis. Whenever a new stream
  195. // is opened, the stream class driver will allocate whatever extension size
  196. // is specified in the HwInitData.PerStreamExtensionSize.
  197. //
  198. typedef struct _STREAMEX {
  199. PHW_DEVICE_EXTENSION pHwDevExt; // For timer use
  200. PHW_STREAM_OBJECT pStreamObject; // For timer use
  201. KS_VIDEOINFOHEADER *pVideoInfoHeader; // format (variable size!)
  202. KS_FRAME_INFO FrameInfo; // PictureNumber, etc.
  203. ULONG fDiscontinuity; // Discontinuity since last valid
  204. KSSTATE KSState; // Run, Stop, Pause
  205. UCHAR LineBuffer[720 * 3];// working buffer (RGB24)
  206. // Clock
  207. HANDLE hMasterClock; // Master clock to use
  208. REFERENCE_TIME QST_Now; // KeQuerySystemTime currently
  209. REFERENCE_TIME QST_NextFrame; // When to capture the next frame
  210. REFERENCE_TIME QST_StreamTime; // Stream time reported by master clock
  211. // Compressor settings (note these are duplicated in the
  212. // HW_DEVICE_EXTENSION to allow setting these before a pin is created)
  213. COMPRESSION_SETTINGS CompressionSettings;
  214. // VideoControl settings (note these are duplicated in the
  215. // HW_DEVICE_EXTENSION to allow setting these before a pin is created)
  216. LONG VideoControlMode;
  217. // Kernel DDraw interface
  218. BOOL KernelDirectDrawRegistered;
  219. HANDLE UserDirectDrawHandle; // DD itself
  220. HANDLE KernelDirectDrawHandle;
  221. BOOL PreEventOccurred;
  222. BOOL PostEventOccurred;
  223. } STREAMEX, *PSTREAMEX;
  224. //
  225. // this structure defines the per request extension. It defines any storage
  226. // space that the mini driver may need in each request packet.
  227. //
  228. typedef struct _SRB_EXTENSION {
  229. LIST_ENTRY ListEntry;
  230. PHW_STREAM_REQUEST_BLOCK pSrb;
  231. HANDLE UserSurfaceHandle; // DDraw
  232. HANDLE KernelSurfaceHandle; // DDraw
  233. } SRB_EXTENSION, * PSRB_EXTENSION;
  234. // -------------------------------------------------------------------
  235. //
  236. // Adapter level prototypes
  237. //
  238. // These functions affect the device as a whole, as opposed to
  239. // affecting individual streams.
  240. //
  241. // -------------------------------------------------------------------
  242. //
  243. // DriverEntry:
  244. //
  245. // This routine is called when the mini driver is first loaded. The driver
  246. // should then call the StreamClassRegisterAdapter function to register with
  247. // the stream class driver
  248. //
  249. ULONG DriverEntry (PVOID Context1, PVOID Context2);
  250. #ifdef TOSHIBA
  251. VOID GetPCIConfigSpace(PHW_STREAM_REQUEST_BLOCK pSrb);
  252. #endif//TOSHIBA
  253. //
  254. // This routine is called by the stream class driver with configuration
  255. // information for an adapter that the mini driver should load on. The mini
  256. // driver should still perform a small verification to determine that the
  257. // adapter is present at the specified addresses, but should not attempt to
  258. // find an adapter as it would have with previous NT miniports.
  259. //
  260. // All initialization of the adapter should also be performed at this time.
  261. //
  262. BOOL STREAMAPI HwInitialize (IN OUT PHW_STREAM_REQUEST_BLOCK pSrb);
  263. //
  264. // This routine is called when the system is going to remove or disable the
  265. // device.
  266. //
  267. // The mini-driver should free any system resources that it allocated at this
  268. // time. Note that system resources allocated for the mini-driver by the
  269. // stream class driver will be free'd by the stream driver, and should not be
  270. // free'd in this routine. (Such as the HW_DEVICE_EXTENSION)
  271. //
  272. BOOL STREAMAPI HwUnInitialize ( PHW_STREAM_REQUEST_BLOCK pSrb);
  273. //
  274. // This is the prototype for the Hardware Interrupt Handler. This routine
  275. // will be called whenever the minidriver receives an interrupt
  276. //
  277. BOOLEAN HwInterrupt ( IN PHW_DEVICE_EXTENSION pDeviceExtension );
  278. //
  279. // This is the prototype for the stream enumeration function. This routine
  280. // provides the stream class driver with the information on data stream types
  281. // supported
  282. //
  283. VOID STREAMAPI AdapterStreamInfo(PHW_STREAM_REQUEST_BLOCK pSrb);
  284. //
  285. // This is the prototype for the stream open function
  286. //
  287. VOID STREAMAPI AdapterOpenStream(PHW_STREAM_REQUEST_BLOCK pSrb);
  288. //
  289. // This is the prototype for the stream close function
  290. //
  291. VOID STREAMAPI AdapterCloseStream(PHW_STREAM_REQUEST_BLOCK pSrb);
  292. //
  293. // This is the prototype for the AdapterReceivePacket routine. This is the
  294. // entry point for command packets that are sent to the adapter (not to a
  295. // specific open stream)
  296. //
  297. VOID STREAMAPI AdapterReceivePacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  298. //
  299. // This is the protoype for the cancel packet routine. This routine enables
  300. // the stream class driver to cancel an outstanding packet.
  301. //
  302. VOID STREAMAPI AdapterCancelPacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  303. //
  304. // This is the packet timeout function. The adapter may choose to ignore a
  305. // packet timeout, or rest the adapter and cancel the requests, as required.
  306. //
  307. VOID STREAMAPI AdapterTimeoutPacket(IN PHW_STREAM_REQUEST_BLOCK Srb);
  308. //
  309. // Adapter level property set handling
  310. //
  311. VOID STREAMAPI AdapterGetCrossbarProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  312. VOID STREAMAPI AdapterSetCrossbarProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  313. VOID STREAMAPI AdapterSetTunerProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  314. VOID STREAMAPI AdapterGetTunerProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  315. VOID STREAMAPI AdapterSetVideoProcAmpProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  316. VOID STREAMAPI AdapterGetVideoProcAmpProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  317. VOID STREAMAPI AdapterSetCameraControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  318. VOID STREAMAPI AdapterGetCameraControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  319. VOID STREAMAPI AdapterSetTVAudioProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  320. VOID STREAMAPI AdapterGetTVAudioProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  321. VOID STREAMAPI AdapterSetAnalogVideoDecoderProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  322. VOID STREAMAPI AdapterGetAnalogVideoDecoderProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  323. VOID STREAMAPI AdapterSetVideoControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  324. VOID STREAMAPI AdapterGetVideoControlProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  325. VOID STREAMAPI AdapterGetVideoCompressionProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  326. VOID STREAMAPI AdapterSetVideoCompressionProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  327. VOID STREAMAPI AdapterSetProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  328. VOID STREAMAPI AdapterGetProperty(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  329. BOOL
  330. STREAMAPI
  331. AdapterVerifyFormat(
  332. PKSDATAFORMAT pKSDataFormatToVerify,
  333. int StreamNumber);
  334. BOOL
  335. STREAMAPI
  336. AdapterFormatFromRange(
  337. IN PHW_STREAM_REQUEST_BLOCK pSrb);
  338. VOID
  339. STREAMAPI
  340. CompleteDeviceSRB (
  341. IN PHW_STREAM_REQUEST_BLOCK pSrb
  342. );
  343. VOID
  344. STREAMAPI
  345. AdapterSetInstance (
  346. PHW_STREAM_REQUEST_BLOCK pSrb
  347. );
  348. //
  349. // prototypes for general queue management using a busy flag
  350. //
  351. BOOL
  352. STREAMAPI
  353. AddToListIfBusy (
  354. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  355. IN KSPIN_LOCK *SpinLock,
  356. IN OUT BOOL *BusyFlag,
  357. IN LIST_ENTRY *ListHead
  358. );
  359. BOOL
  360. STREAMAPI
  361. RemoveFromListIfAvailable (
  362. IN OUT PHW_STREAM_REQUEST_BLOCK *pSrb,
  363. IN KSPIN_LOCK *SpinLock,
  364. IN OUT BOOL *BusyFlag,
  365. IN LIST_ENTRY *ListHead
  366. );
  367. // -------------------------------------------------------------------
  368. //
  369. // Stream level prototypes
  370. //
  371. // These functions affect individual streams, as opposed to
  372. // affecting the device as a whole.
  373. //
  374. // -------------------------------------------------------------------
  375. //
  376. // Routines to manage the SRB queue on a per stream basis
  377. //
  378. VOID
  379. STREAMAPI
  380. VideoQueueAddSRB (
  381. IN PHW_STREAM_REQUEST_BLOCK pSrb
  382. );
  383. PHW_STREAM_REQUEST_BLOCK
  384. STREAMAPI
  385. VideoQueueRemoveSRB (
  386. PHW_DEVICE_EXTENSION pHwDevExt,
  387. int StreamNumber
  388. );
  389. VOID
  390. STREAMAPI
  391. VideoQueueCancelAllSRBs (
  392. PSTREAMEX pStrmEx
  393. );
  394. BOOL
  395. STREAMAPI
  396. VideoQueueCancelOneSRB (
  397. PSTREAMEX pStrmEx,
  398. PHW_STREAM_REQUEST_BLOCK pSrbToCancel
  399. );
  400. //
  401. // Data packet handlers
  402. //
  403. //
  404. // prototypes for data handling routines
  405. //
  406. VOID STREAMAPI CompleteStreamSRB (IN PHW_STREAM_REQUEST_BLOCK pSrb);
  407. BOOL STREAMAPI VideoSetFormat(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  408. VOID STREAMAPI VideoReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  409. VOID STREAMAPI VideoReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  410. VOID STREAMAPI AnalogVideoReceiveDataPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  411. VOID STREAMAPI AnalogVideoReceiveCtrlPacket(IN PHW_STREAM_REQUEST_BLOCK pSrb);
  412. VOID STREAMAPI EnableIRQ(PHW_STREAM_OBJECT pstrm);
  413. VOID STREAMAPI DisableIRQ(PHW_STREAM_OBJECT pstrm);
  414. //
  415. // prototypes for properties and states
  416. //
  417. VOID STREAMAPI VideoSetState(PHW_STREAM_REQUEST_BLOCK pSrb);
  418. VOID STREAMAPI VideoGetState(PHW_STREAM_REQUEST_BLOCK pSrb);
  419. VOID STREAMAPI VideoSetProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  420. VOID STREAMAPI VideoGetProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  421. VOID STREAMAPI VideoStreamGetConnectionProperty (PHW_STREAM_REQUEST_BLOCK pSrb);
  422. VOID STREAMAPI VideoStreamGetDroppedFramesProperty(PHW_STREAM_REQUEST_BLOCK pSrb);
  423. //
  424. // stream clock functions
  425. //
  426. VOID
  427. STREAMAPI
  428. VideoIndicateMasterClock (PHW_STREAM_REQUEST_BLOCK pSrb);
  429. ULONGLONG
  430. STREAMAPI
  431. VideoGetSystemTime();
  432. //
  433. // The point of it all
  434. //
  435. VOID
  436. STREAMAPI
  437. VideoCaptureRoutine(
  438. IN PSTREAMEX pStrmEx
  439. );
  440. #ifdef TOSHIBA
  441. VOID
  442. DeferredRoutine(
  443. PKDPC pDpc,
  444. PDEVICE_OBJECT pDeviceObject,
  445. PIRP pIrpNotUsed,
  446. PVOID Context
  447. );
  448. ULONG
  449. get_AblFilter (
  450. PHW_DEVICE_EXTENSION pHwDevExt
  451. );
  452. ULONG
  453. get_filtering (
  454. PHW_DEVICE_EXTENSION pHwDevExt
  455. );
  456. VOID
  457. set_filtering (
  458. PHW_DEVICE_EXTENSION pHwDevExt,
  459. BOOL bFlag
  460. );
  461. NTKERNELAPI
  462. PHYSICAL_ADDRESS
  463. MmGetPhysicalAddress (
  464. IN PVOID BaseAddress
  465. );
  466. NTKERNELAPI
  467. PVOID
  468. MmAllocateContiguousMemory (
  469. IN ULONG NumberOfBytes,
  470. IN PHYSICAL_ADDRESS HighestAcceptableAddress
  471. );
  472. NTKERNELAPI
  473. VOID
  474. MmFreeContiguousMemory (
  475. IN PVOID BaseAddress
  476. );
  477. #endif//TOSHIBA
  478. #ifdef __cplusplus
  479. }
  480. #endif // __cplusplus
  481. #endif //__CAPMAIN_H__