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.

1046 lines
44 KiB

  1. //==========================================================================;
  2. //
  3. // WDM Video Decoder stream informaition declarations
  4. //
  5. // $Date: 17 Aug 1998 15:00:38 $
  6. // $Revision: 1.0 $
  7. // $Author: Tashjian $
  8. //
  9. // $Copyright: (c) 1997 - 1998 ATI Technologies Inc. All Rights Reserved. $
  10. //
  11. //==========================================================================;
  12. extern "C" {
  13. #include "strmini.h"
  14. #include "ksmedia.h"
  15. #include "math.h"
  16. }
  17. #include "defaults.h"
  18. #include "mediums.h"
  19. #include "StrmInfo.h"
  20. #include "StrmProp.h"
  21. #include "capdebug.h"
  22. // devine MEDIASUBTYPE_UYVY here... can be removed if someday defined in ksmedia.h
  23. #define STATIC_KSDATAFORMAT_SUBTYPE_UYVY\
  24. 0x59565955, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 // MEDIASUBTYPE_UYVY
  25. DEFINE_GUIDSTRUCT("59565955-0000-0010-8000-00aa00389b71", KSDATAFORMAT_SUBTYPE_UYVY);
  26. #define KSDATAFORMAT_SUBTYPE_UYVY DEFINE_GUIDNAMED(KSDATAFORMAT_SUBTYPE_UYVY)
  27. //
  28. // For event handling on the VP stream
  29. //
  30. NTSTATUS STREAMAPI VPStreamEventProc (PHW_EVENT_DESCRIPTOR);
  31. //
  32. // For event handling on the VP VBI stream
  33. //
  34. NTSTATUS STREAMAPI VPVBIStreamEventProc (PHW_EVENT_DESCRIPTOR);
  35. // ------------------------------------------------------------------------
  36. // The master list of all streams supported by this driver
  37. // ------------------------------------------------------------------------
  38. KSEVENT_ITEM VPEventItm[] =
  39. {
  40. {
  41. KSEVENT_VPNOTIFY_FORMATCHANGE,
  42. 0,
  43. 0,
  44. NULL,
  45. NULL,
  46. NULL
  47. }
  48. };
  49. GUID MY_KSEVENTSETID_VPNOTIFY = {STATIC_KSEVENTSETID_VPNotify};
  50. KSEVENT_SET VPEventSet[] =
  51. {
  52. {
  53. &MY_KSEVENTSETID_VPNOTIFY,
  54. SIZEOF_ARRAY(VPEventItm),
  55. VPEventItm,
  56. }
  57. };
  58. KSEVENT_ITEM VPVBIEventItm[] =
  59. {
  60. {
  61. KSEVENT_VPVBINOTIFY_FORMATCHANGE,
  62. 0,
  63. 0,
  64. NULL,
  65. NULL,
  66. NULL
  67. }
  68. };
  69. GUID MY_KSEVENTSETID_VPVBINOTIFY = {STATIC_KSEVENTSETID_VPVBINotify};
  70. KSEVENT_SET VPVBIEventSet[] =
  71. {
  72. {
  73. &MY_KSEVENTSETID_VPVBINOTIFY,
  74. SIZEOF_ARRAY(VPVBIEventItm),
  75. VPVBIEventItm,
  76. }
  77. };
  78. //---------------------------------------------------------------------------
  79. // All of the video and vbi data formats we might use
  80. //---------------------------------------------------------------------------
  81. //---------------------------------------------------------------------------
  82. // Capture Stream Formats
  83. //---------------------------------------------------------------------------
  84. KS_DATARANGE_VIDEO StreamFormatUYVY_Capture_NTSC =
  85. {
  86. // KSDATARANGE
  87. {
  88. sizeof(KS_DATARANGE_VIDEO), // FormatSize
  89. 0, // Flags
  90. 0,//DefWidth * DefHeight * 2, // SampleSize
  91. 0, // Reserved
  92. STATIC_KSDATAFORMAT_TYPE_VIDEO, // aka. MEDIATYPE_Video
  93. STATIC_KSDATAFORMAT_SUBTYPE_UYVY, // aka. MEDIASUBTYPE_UYVY
  94. STATIC_KSDATAFORMAT_SPECIFIER_VIDEOINFO // aka. FORMAT_VideoInfo
  95. },
  96. TRUE, // BOOL, bFixedSizeSamples (all samples same size?)
  97. TRUE, // BOOL, bTemporalCompression (all I frames?)
  98. 0,//KS_VIDEOSTREAM_CAPTURE, // StreamDescriptionFlags (KS_VIDEO_DESC_*)
  99. 0, // MemoryAllocationFlags (KS_VIDEO_ALLOC_*)
  100. // _KS_VIDEO_STREAM_CONFIG_CAPS
  101. {
  102. STATIC_KSDATAFORMAT_SPECIFIER_VIDEOINFO, // GUID
  103. KS_AnalogVideo_NTSC_Mask & ~KS_AnalogVideo_NTSC_433 | KS_AnalogVideo_PAL_60 | KS_AnalogVideo_PAL_M, // AnalogVideoStandard
  104. {
  105. NTSCMaxInWidth, NTSCMaxInHeight // SIZE InputSize
  106. },
  107. {
  108. NTSCMinInWidth, NTSCMinInHeight // SIZE MinCroppingSize; smallest rcSrc cropping rect allowed
  109. },
  110. {
  111. NTSCMaxInWidth, NTSCMaxInHeight // SIZE MaxCroppingSize; largest rcSrc cropping rect allowed
  112. },
  113. 2, // int CropGranularityX; // granularity of cropping size
  114. 2, // int CropGranularityY;
  115. 2, // int CropAlignX; // alignment of cropping rect
  116. 2, // int CropAlignY;
  117. {
  118. NTSCMinOutWidth, NTSCMinOutHeight // SIZE MinOutputSize; // smallest bitmap stream can produce
  119. },
  120. {
  121. NTSCMaxOutWidth, NTSCMaxOutHeight // SIZE MaxOutputSize; // largest bitmap stream can produce
  122. },
  123. 80, // int OutputGranularityX; // granularity of output bitmap size
  124. 60, // int OutputGranularityY;
  125. 0, // StretchTapsX (0 no stretch, 1 pix dup, 2 interp...)
  126. 0, // StretchTapsY
  127. 2, // ShrinkTapsX
  128. 2, // ShrinkTapsY
  129. (LONGLONG)NTSCFieldDuration, // LONGLONG MinFrameInterval; // 100 nS units
  130. (LONGLONG)NTSCFieldDuration*MAXULONG, // LONGLONG MaxFrameInterval;
  131. NTSCFrameRate * 80 * 40 * 2 * 8, // LONG MinBitsPerSecond;
  132. NTSCFrameRate * 720 * 480 * 2 * 8 // LONG MaxBitsPerSecond;
  133. },
  134. // KS_VIDEOINFOHEADER (default format)
  135. {
  136. 0,0,0,0, // RECT rcSource; // The bit we really want to use
  137. 0,0,0,0, // RECT rcTarget; // Where the video should go
  138. DefWidth * DefHeight * 2 * NTSCFrameRate, // DWORD dwBitRate; // Approximate bit data rate
  139. 0L, // DWORD dwBitErrorRate; // Bit error rate for this stream
  140. // 30 fps
  141. NTSCFieldDuration * 2, // REFERENCE_TIME AvgTimePerFrame; // Average time per frame (100ns units)
  142. sizeof(KS_BITMAPINFOHEADER), // DWORD biSize;
  143. DefWidth, // LONG biWidth;
  144. DefHeight, // LONG biHeight;
  145. 1, // WORD biPlanes;
  146. 16, // WORD biBitCount;
  147. FOURCC_UYVY, // DWORD biCompression;
  148. DefWidth * DefHeight * 2, // DWORD biSizeImage;
  149. 0, // LONG biXPelsPerMeter;
  150. 0, // LONG biYPelsPerMeter;
  151. 0, // DWORD biClrUsed;
  152. 0 // DWORD biClrImportant;
  153. }
  154. };
  155. KS_DATARANGE_VIDEO StreamFormatUYVY_Capture_PAL =
  156. {
  157. // KSDATARANGE
  158. {
  159. sizeof(KS_DATARANGE_VIDEO), // FormatSize
  160. 0, // Flags
  161. 0,//QCIFWidth * QCIFHeight * 2, // SampleSize
  162. 0, // Reserved
  163. STATIC_KSDATAFORMAT_TYPE_VIDEO, // aka. MEDIATYPE_Video
  164. STATIC_KSDATAFORMAT_SUBTYPE_UYVY, // aka. MEDIASUBTYPE_UYVY
  165. STATIC_KSDATAFORMAT_SPECIFIER_VIDEOINFO // aka. FORMAT_VideoInfo
  166. },
  167. TRUE, // BOOL, bFixedSizeSamples (all samples same size?)
  168. TRUE, // BOOL, bTemporalCompression (all I frames?)
  169. KS_VIDEOSTREAM_CAPTURE, // StreamDescriptionFlags (KS_VIDEO_DESC_*)
  170. 0, // MemoryAllocationFlags (KS_VIDEO_ALLOC_*)
  171. // _KS_VIDEO_STREAM_CONFIG_CAPS
  172. {
  173. STATIC_KSDATAFORMAT_SPECIFIER_VIDEOINFO, // GUID
  174. KS_AnalogVideo_PAL_Mask & ~KS_AnalogVideo_PAL_60 & ~KS_AnalogVideo_PAL_M | KS_AnalogVideo_SECAM_Mask | KS_AnalogVideo_NTSC_433, // AnalogVideoStandard
  175. {
  176. 720, 576 // SIZE InputSize
  177. },
  178. {
  179. QCIFWidth, QCIFHeight // SIZE MinCroppingSize; smallest rcSrc cropping rect allowed
  180. },
  181. {
  182. QCIFWidth * 4, QCIFHeight * 4 // SIZE MaxCroppingSize; largest rcSrc cropping rect allowed
  183. },
  184. 1, // int CropGranularityX; // granularity of cropping size
  185. 1, // int CropGranularityY;
  186. 1, // int CropAlignX; // alignment of cropping rect
  187. 1, // int CropAlignY;
  188. {
  189. QCIFWidth, QCIFHeight // SIZE MinOutputSize; // smallest bitmap stream can produce
  190. },
  191. {
  192. QCIFWidth * 2, QCIFHeight * 2 // SIZE MaxOutputSize; // largest bitmap stream can produce
  193. },
  194. QCIFWidth, // int OutputGranularityX; // granularity of output bitmap size
  195. QCIFHeight, // int OutputGranularityY;
  196. 0, // StretchTapsX (0 no stretch, 1 pix dup, 2 interp...)
  197. 0, // StretchTapsY
  198. 2, // ShrinkTapsX
  199. 2, // ShrinkTapsY
  200. (LONGLONG)PALFieldDuration, // LONGLONG MinFrameInterval; // 100 nS units
  201. (LONGLONG)PALFieldDuration*MAXULONG, // LONGLONG MaxFrameInterval;
  202. 1 * QCIFWidth * QCIFHeight * 2 * 8, // LONG MinBitsPerSecond;
  203. 25 * QCIFWidth * QCIFHeight * 16 * 2 * 8 // LONG MaxBitsPerSecond;
  204. },
  205. // KS_VIDEOINFOHEADER (default format)
  206. {
  207. 0,0,0,0, // RECT rcSource; // The bit we really want to use
  208. 0,0,0,0, // RECT rcTarget; // Where the video should go
  209. QCIFWidth * 4 * QCIFHeight * 2 * 25L, // DWORD dwBitRate; // Approximate bit data rate
  210. 0L, // DWORD dwBitErrorRate; // Bit error rate for this stream
  211. // 30 fps
  212. PALFieldDuration * 2, // REFERENCE_TIME AvgTimePerFrame; // Average time per frame (100ns units)
  213. sizeof KS_BITMAPINFOHEADER, // DWORD biSize;
  214. QCIFWidth * 2, // LONG biWidth;
  215. QCIFHeight * 2, // LONG biHeight;
  216. 1, // WORD biPlanes;
  217. 16, // WORD biBitCount;
  218. FOURCC_UYVY, // DWORD biCompression;
  219. QCIFWidth * QCIFHeight * 2 * 4, // DWORD biSizeImage;
  220. 0, // LONG biXPelsPerMeter;
  221. 0, // LONG biYPelsPerMeter;
  222. 0, // DWORD biClrUsed;
  223. 0 // DWORD biClrImportant;
  224. }
  225. };
  226. KS_DATARANGE_VIDEO StreamFormatUYVY_Capture_NTSC_QCIF =
  227. {
  228. // KSDATARANGE
  229. {
  230. sizeof(KS_DATARANGE_VIDEO), // FormatSize
  231. 0, // Flags
  232. QCIFWidth * QCIFHeight * 2, // SampleSize
  233. 0, // Reserved
  234. STATIC_KSDATAFORMAT_TYPE_VIDEO, // aka. MEDIATYPE_Video
  235. STATIC_KSDATAFORMAT_SUBTYPE_UYVY, // aka. MEDIASUBTYPE_UYVY
  236. STATIC_KSDATAFORMAT_SPECIFIER_VIDEOINFO // aka. FORMAT_VideoInfo
  237. },
  238. TRUE, // BOOL, bFixedSizeSamples (all samples same size?)
  239. TRUE, // BOOL, bTemporalCompression (all I frames?)
  240. KS_VIDEOSTREAM_CAPTURE, // StreamDescriptionFlags (KS_VIDEO_DESC_*)
  241. 0, // MemoryAllocationFlags (KS_VIDEO_ALLOC_*)
  242. // _KS_VIDEO_STREAM_CONFIG_CAPS
  243. {
  244. STATIC_KSDATAFORMAT_SPECIFIER_VIDEOINFO, // GUID
  245. KS_AnalogVideo_NTSC_Mask & ~KS_AnalogVideo_NTSC_433 | KS_AnalogVideo_PAL_60 | KS_AnalogVideo_PAL_M, // AnalogVideoStandard
  246. {
  247. NTSCMaxInWidth, NTSCMaxInHeight // SIZE InputSize
  248. },
  249. {
  250. QCIFWidth, QCIFHeight // SIZE MinCroppingSize; smallest rcSrc cropping rect allowed
  251. },
  252. {
  253. QCIFWidth, QCIFHeight // SIZE MaxCroppingSize; largest rcSrc cropping rect allowed
  254. },
  255. 1, // int CropGranularityX; // granularity of cropping size
  256. 1, // int CropGranularityY;
  257. 1, // int CropAlignX; // alignment of cropping rect
  258. 1, // int CropAlignY;
  259. {
  260. QCIFWidth, QCIFHeight // SIZE MinOutputSize; // smallest bitmap stream can produce
  261. },
  262. {
  263. QCIFWidth, QCIFHeight // SIZE MaxOutputSize; // largest bitmap stream can produce
  264. },
  265. 1, // int OutputGranularityX; // granularity of output bitmap size
  266. 1, // int OutputGranularityY;
  267. 0, // StretchTapsX (0 no stretch, 1 pix dup, 2 interp...)
  268. 0, // StretchTapsY
  269. 2, // ShrinkTapsX
  270. 2, // ShrinkTapsY
  271. (LONGLONG)NTSCFieldDuration, // LONGLONG MinFrameInterval; // 100 nS units
  272. (LONGLONG)NTSCFieldDuration*MAXULONG, // LONGLONG MaxFrameInterval;
  273. 1 * QCIFWidth * QCIFHeight * 2 * 8, // LONG MinBitsPerSecond;
  274. 30 * QCIFWidth * QCIFHeight * 2 * 8 // LONG MaxBitsPerSecond;
  275. },
  276. // KS_VIDEOINFOHEADER (default format)
  277. {
  278. 0,0,0,0, // RECT rcSource; // The bit we really want to use
  279. 0,0,0,0, // RECT rcTarget; // Where the video should go
  280. QCIFWidth * QCIFHeight * 2 * 30L, // DWORD dwBitRate; // Approximate bit data rate
  281. 0L, // DWORD dwBitErrorRate; // Bit error rate for this stream
  282. // 30 fps
  283. NTSCFieldDuration * 2, // REFERENCE_TIME AvgTimePerFrame; // Average time per frame (100ns units)
  284. sizeof KS_BITMAPINFOHEADER, // DWORD biSize;
  285. QCIFWidth, // LONG biWidth;
  286. QCIFHeight, // LONG biHeight;
  287. 1, // WORD biPlanes;
  288. 16, // WORD biBitCount;
  289. FOURCC_UYVY, // DWORD biCompression;
  290. QCIFWidth * QCIFHeight * 2, // DWORD biSizeImage;
  291. 0, // LONG biXPelsPerMeter;
  292. 0, // LONG biYPelsPerMeter;
  293. 0, // DWORD biClrUsed;
  294. 0 // DWORD biClrImportant;
  295. }
  296. };
  297. KSDATAFORMAT StreamFormatVideoPort =
  298. {
  299. {
  300. sizeof(KSDATAFORMAT),
  301. 0,
  302. 0,
  303. 0,
  304. STATIC_KSDATAFORMAT_TYPE_VIDEO,
  305. STATIC_KSDATAFORMAT_SUBTYPE_VPVideo,
  306. STATIC_KSDATAFORMAT_SPECIFIER_NONE
  307. }
  308. };
  309. KS_DATARANGE_VIDEO_VBI StreamFormatVBI_NTSC =
  310. {
  311. // KSDATARANGE
  312. {
  313. {
  314. sizeof(KS_DATARANGE_VIDEO_VBI),
  315. 0,
  316. VBISamples * NTSCVBILines, // SampleSize
  317. 0, // Reserved
  318. { STATIC_KSDATAFORMAT_TYPE_VBI },
  319. { STATIC_KSDATAFORMAT_SUBTYPE_RAW8 },
  320. { STATIC_KSDATAFORMAT_SPECIFIER_VBI }
  321. }
  322. },
  323. TRUE, // BOOL, bFixedSizeSamples (all samples same size?)
  324. TRUE, // BOOL, bTemporalCompression (all I frames?)
  325. KS_VIDEOSTREAM_VBI, // StreamDescriptionFlags (KS_VIDEO_DESC_*)
  326. 0, // MemoryAllocationFlags (KS_VIDEO_ALLOC_*)
  327. // _KS_VIDEO_STREAM_CONFIG_CAPS
  328. {
  329. { STATIC_KSDATAFORMAT_SPECIFIER_VBI },
  330. KS_AnalogVideo_NTSC_M, // AnalogVideoStandard
  331. {
  332. VBISamples, NTSCVBILines // SIZE InputSize
  333. },
  334. {
  335. VBISamples, NTSCVBILines // SIZE MinCroppingSize; smallest rcSrc cropping rect allowed
  336. },
  337. {
  338. VBISamples, NTSCVBILines // SIZE MaxCroppingSize; largest rcSrc cropping rect allowed
  339. },
  340. 1, // int CropGranularityX; // granularity of cropping size
  341. 1, // int CropGranularityY;
  342. 1, // int CropAlignX; // alignment of cropping rect
  343. 1, // int CropAlignY;
  344. {
  345. VBISamples, NTSCVBILines // SIZE MinOutputSize; // smallest bitmap stream can produce
  346. },
  347. {
  348. VBISamples, NTSCVBILines // SIZE MaxOutputSize; // largest bitmap stream can produce
  349. },
  350. 1, // int OutputGranularityX; // granularity of output bitmap size
  351. 2, // int OutputGranularityY;
  352. 0, // StretchTapsX (0 no stretch, 1 pix dup, 2 interp...)
  353. 0, // StretchTapsY
  354. 0, // ShrinkTapsX
  355. 0, // ShrinkTapsY
  356. NTSCFieldDuration, // LONGLONG MinFrameInterval; // 100 nS units
  357. NTSCFieldDuration, // LONGLONG MaxFrameInterval;
  358. VBISamples * 30 * NTSCVBILines * 2 * 8, // LONG MinBitsPerSecond;
  359. VBISamples * 30 * NTSCVBILines * 2 * 8 // LONG MaxBitsPerSecond;
  360. },
  361. // KS_VBIINFOHEADER (default format)
  362. {
  363. NTSCVBIStart, // StartLine -- inclusive
  364. NTSCVBIEnd, // EndLine -- inclusive
  365. SamplingFrequency, // SamplingFrequency
  366. 454, // MinLineStartTime; // (uS past HR LE) * 100
  367. 900, // MaxLineStartTime; // (uS past HR LE) * 100
  368. // empirically discovered
  369. 780, // ActualLineStartTime // (uS past HR LE) * 100
  370. 5902, // ActualLineEndTime; // (uS past HR LE) * 100
  371. KS_AnalogVideo_NTSC_M, // VideoStandard;
  372. VBISamples, // SamplesPerLine;
  373. VBISamples, // StrideInBytes;
  374. VBISamples * NTSCVBILines // BufferSize;
  375. }
  376. };
  377. KSDATAFORMAT StreamFormatVideoPortVBI =
  378. {
  379. {
  380. sizeof(KSDATAFORMAT),
  381. 0,
  382. 0,
  383. 0,
  384. STATIC_KSDATAFORMAT_TYPE_VIDEO,
  385. STATIC_KSDATAFORMAT_SUBTYPE_VPVBI,
  386. STATIC_KSDATAFORMAT_SPECIFIER_NONE
  387. }
  388. };
  389. static KS_DATARANGE_ANALOGVIDEO StreamFormatAnalogVideo =
  390. {
  391. // KS_DATARANGE_ANALOGVIDEO
  392. {
  393. sizeof (KS_DATARANGE_ANALOGVIDEO), // FormatSize
  394. 0, // Flags
  395. sizeof (KS_TVTUNER_CHANGE_INFO), // SampleSize
  396. 0, // Reserved
  397. STATIC_KSDATAFORMAT_TYPE_ANALOGVIDEO, // aka MEDIATYPE_AnalogVideo
  398. STATIC_KSDATAFORMAT_SUBTYPE_NONE, // ie. Wildcard
  399. STATIC_KSDATAFORMAT_SPECIFIER_ANALOGVIDEO, // aka FORMAT_AnalogVideo
  400. },
  401. // KS_ANALOGVIDEOINFO
  402. {
  403. 0, 0, 720, 480, // rcSource;
  404. 0, 0, 720, 480, // rcTarget;
  405. 720, // dwActiveWidth;
  406. 480, // dwActiveHeight;
  407. NTSCFrameDuration, // REFERENCE_TIME AvgTimePerFrame;
  408. }
  409. };
  410. //---------------------------------------------------------------------------
  411. // Capture Stream Formats, Mediums, and PinNames
  412. //---------------------------------------------------------------------------
  413. static PKSDATAFORMAT CaptureStreamFormats[] =
  414. {
  415. (PKSDATAFORMAT) &StreamFormatUYVY_Capture_NTSC,
  416. (PKSDATAFORMAT) &StreamFormatUYVY_Capture_NTSC_QCIF,
  417. (PKSDATAFORMAT) &StreamFormatUYVY_Capture_PAL,
  418. };
  419. #define NUM_CAPTURE_STREAM_FORMATS (SIZEOF_ARRAY (CaptureStreamFormats))
  420. static GUID CaptureStreamPinName = {STATIC_PINNAME_VIDEO_CAPTURE};
  421. //---------------------------------------------------------------------------
  422. // Video Port Stream Formats, Mediums, and PinNames
  423. //---------------------------------------------------------------------------
  424. static PKSDATAFORMAT VPStreamFormats[] =
  425. {
  426. (PKSDATAFORMAT) &StreamFormatVideoPort,
  427. };
  428. #define NUM_VP_STREAM_FORMATS (SIZEOF_ARRAY (VPStreamFormats))
  429. static GUID VideoPortPinName = {STATIC_PINNAME_VIDEO_VIDEOPORT};
  430. //---------------------------------------------------------------------------
  431. // VBI Stream Formats, Mediums, and PinNames
  432. //---------------------------------------------------------------------------
  433. static PKSDATAFORMAT VBIStreamFormats[] =
  434. {
  435. (PKSDATAFORMAT) &StreamFormatVBI_NTSC,
  436. };
  437. #define NUM_VBI_STREAM_FORMATS (SIZEOF_ARRAY (VBIStreamFormats))
  438. static GUID VBIStreamPinName = {STATIC_PINNAME_VIDEO_VBI};
  439. //---------------------------------------------------------------------------
  440. // Video Port VBI Stream Formats, Mediums, and PinNames
  441. //---------------------------------------------------------------------------
  442. static PKSDATAFORMAT VPVBIStreamFormats[] =
  443. {
  444. (PKSDATAFORMAT) &StreamFormatVideoPortVBI,
  445. };
  446. #define NUM_VPVBI_STREAM_FORMATS (SIZEOF_ARRAY (VPVBIStreamFormats))
  447. static GUID VPVBIPinName = {STATIC_PINNAME_VIDEO_VIDEOPORT_VBI};
  448. //---------------------------------------------------------------------------
  449. // Analog Video Stream Formats, Mediums, and PinNames
  450. //---------------------------------------------------------------------------
  451. static PKSDATAFORMAT AnalogVideoFormats[] =
  452. {
  453. (PKSDATAFORMAT) &StreamFormatAnalogVideo,
  454. };
  455. #define NUM_ANALOG_VIDEO_FORMATS (SIZEOF_ARRAY (AnalogVideoFormats))
  456. static GUID AnalogVideoStreamPinName = {STATIC_PINNAME_VIDEO_ANALOGVIDEOIN};
  457. ALL_STREAM_INFO Streams [] =
  458. {
  459. // -----------------------------------------------------------------
  460. // The Video Capture output stream
  461. // -----------------------------------------------------------------
  462. {
  463. // HW_STREAM_INFORMATION -------------------------------------------
  464. {
  465. 1, // NumberOfPossibleInstances
  466. KSPIN_DATAFLOW_OUT, // DataFlow
  467. TRUE, // DataAccessible
  468. NUM_CAPTURE_STREAM_FORMATS, // NumberOfFormatArrayEntries
  469. CaptureStreamFormats, // StreamFormatsArray
  470. 0, // ClassReserved[0]
  471. 0, // ClassReserved[1]
  472. 0, // ClassReserved[2]
  473. 0, // ClassReserved[3]
  474. NumVideoStreamProperties, // NumStreamPropArrayEntries
  475. (PKSPROPERTY_SET)VideoStreamProperties, // StreamPropertiesArray
  476. 0, // NumStreamEventArrayEntries;
  477. 0, // StreamEventsArray;
  478. &CaptureStreamPinName, // Category
  479. &CaptureStreamPinName, // Name
  480. 0, // MediumsCount
  481. NULL, // Mediums
  482. },
  483. // STREAM_OBJECT_INFO ------------------------------------------------
  484. {
  485. FALSE, // Dma
  486. TRUE, // Pio
  487. sizeof (KS_FRAME_INFO), // StreamHeaderMediaSpecific
  488. 0, // StreamHeaderWorkspace
  489. TRUE, // Allocator
  490. NULL, // HwEventRoutine
  491. }
  492. },
  493. // -----------------------------------------------------------------
  494. // The Video Port output stream
  495. // -----------------------------------------------------------------
  496. {
  497. // HW_STREAM_INFORMATION -------------------------------------------
  498. {
  499. 1, // NumberOfPossibleInstances
  500. KSPIN_DATAFLOW_OUT, // DataFlow
  501. TRUE, // DataAccessible.
  502. NUM_VP_STREAM_FORMATS, // NumberOfFormatArrayEntries
  503. VPStreamFormats, // StreamFormatsArray
  504. 0, // ClassReserved[0]
  505. 0, // ClassReserved[1]
  506. 0, // ClassReserved[2]
  507. 0, // ClassReserved[3]
  508. NumVideoPortProperties, // NumStreamPropArrayEntries
  509. (PKSPROPERTY_SET)VideoPortProperties, // StreamPropertiesArray
  510. SIZEOF_ARRAY(VPEventSet), // NumStreamEventArrayEntries
  511. VPEventSet, // StreamEventsArray
  512. &VideoPortPinName, // Category
  513. &VideoPortPinName, // Name
  514. 0, // MediumsCount
  515. NULL, // Mediums
  516. },
  517. // STREAM_OBJECT_INFO ------------------------------------------------
  518. {
  519. FALSE, // Dma
  520. FALSE, // Pio
  521. 0, // StreamHeaderMediaSpecific
  522. 0, // StreamHeaderWorkspace
  523. FALSE, // Allocator
  524. VPStreamEventProc, // HwEventRoutine;
  525. }
  526. },
  527. // -----------------------------------------------------------------
  528. // The VBI Capture output stream
  529. // -----------------------------------------------------------------
  530. {
  531. // HW_STREAM_INFORMATION -------------------------------------------
  532. {
  533. 1, // NumberOfPossibleInstances
  534. KSPIN_DATAFLOW_OUT, // DataFlow
  535. TRUE, // DataAccessible
  536. NUM_VBI_STREAM_FORMATS, // NumberOfFormatArrayEntries
  537. VBIStreamFormats, // StreamFormatsArray
  538. 0, // ClassReserved[0]
  539. 0, // ClassReserved[1]
  540. 0, // ClassReserved[2]
  541. 0, // ClassReserved[3]
  542. NumVideoStreamProperties, // NumStreamPropArrayEntries
  543. (PKSPROPERTY_SET)VideoStreamProperties, // StreamPropertiesArray
  544. 0, // NumStreamEventArrayEntries;
  545. 0, // StreamEventsArray;
  546. &VBIStreamPinName, // Category
  547. &VBIStreamPinName, // Name
  548. 0, // MediumsCount
  549. NULL, // Mediums
  550. },
  551. // STREAM_OBJECT_INFO ------------------------------------------------
  552. {
  553. FALSE, // Dma
  554. TRUE, // Pio
  555. sizeof (KS_VBI_FRAME_INFO), // StreamHeaderMediaSpecific
  556. 0, // StreamHeaderWorkspace
  557. TRUE, // Allocator
  558. NULL, // HwEventRoutine
  559. }
  560. },
  561. // -----------------------------------------------------------------
  562. // The Video Port VBI output stream
  563. // -----------------------------------------------------------------
  564. {
  565. // HW_STREAM_INFORMATION -------------------------------------------
  566. {
  567. 1, // NumberOfPossibleInstances
  568. KSPIN_DATAFLOW_OUT, // DataFlow
  569. TRUE, // DataAccessible.
  570. NUM_VPVBI_STREAM_FORMATS, // NumberOfFormatArrayEntries
  571. VPVBIStreamFormats, // StreamFormatsArray
  572. 0, // ClassReserved[0]
  573. 0, // ClassReserved[1]
  574. 0, // ClassReserved[2]
  575. 0, // ClassReserved[3]
  576. NumVideoPortVBIProperties, // NumStreamPropArrayEntries
  577. (PKSPROPERTY_SET)VideoPortVBIProperties,// StreamPropertiesArray
  578. SIZEOF_ARRAY(VPVBIEventSet), // NumStreamEventArrayEntries
  579. VPVBIEventSet, // StreamEventsArray
  580. &VPVBIPinName, // Category
  581. &VPVBIPinName, // Name
  582. 0, // MediumsCount
  583. NULL, // Mediums
  584. },
  585. // STREAM_OBJECT_INFO ------------------------------------------------
  586. {
  587. FALSE, // Dma
  588. FALSE, // Pio
  589. 0, // StreamHeaderMediaSpecific
  590. 0, // StreamHeaderWorkspace
  591. FALSE, // Allocator
  592. VPVBIStreamEventProc, // HwEventRoutine;
  593. }
  594. },
  595. // -----------------------------------------------------------------
  596. // The Analog Video Input Stream
  597. // -----------------------------------------------------------------
  598. {
  599. // HW_STREAM_INFORMATION -------------------------------------------
  600. {
  601. 1, // NumberOfPossibleInstances
  602. KSPIN_DATAFLOW_IN, // DataFlow
  603. TRUE, // DataAccessible
  604. NUM_ANALOG_VIDEO_FORMATS, // NumberOfFormatArrayEntries
  605. AnalogVideoFormats, // StreamFormatsArray
  606. 0, // ClassReserved[0]
  607. 0, // ClassReserved[1]
  608. 0, // ClassReserved[2]
  609. 0, // ClassReserved[3]
  610. 0, // NumStreamPropArrayEntries
  611. 0, // StreamPropertiesArray
  612. 0, // NumStreamEventArrayEntries;
  613. 0, // StreamEventsArray;
  614. &AnalogVideoStreamPinName, // Category
  615. &AnalogVideoStreamPinName, // Name
  616. 1, // MediumsCount
  617. &CrossbarMediums[3], // Mediums
  618. },
  619. // STREAM_OBJECT_INFO ------------------------------------------------
  620. {
  621. FALSE, // Dma
  622. TRUE, // Pio
  623. 0, // StreamHeaderMediaSpecific
  624. 0, // StreamHeaderWorkspace
  625. FALSE, // Allocator
  626. NULL, // HwEventRoutine
  627. },
  628. }
  629. };
  630. extern const ULONG NumStreams = SIZEOF_ARRAY(Streams);
  631. //---------------------------------------------------------------------------
  632. // Topology
  633. //---------------------------------------------------------------------------
  634. // Categories define what the device does.
  635. static GUID Categories[] = {
  636. STATIC_KSCATEGORY_VIDEO,
  637. STATIC_KSCATEGORY_CAPTURE,
  638. STATIC_KSCATEGORY_CROSSBAR,
  639. };
  640. #define NUMBER_OF_CATEGORIES SIZEOF_ARRAY (Categories)
  641. KSTOPOLOGY Topology = {
  642. NUMBER_OF_CATEGORIES, // CategoriesCount
  643. (GUID*) &Categories, // Categories
  644. 0, // TopologyNodesCount
  645. NULL, // TopologyNodes
  646. 0, // TopologyConnectionsCount
  647. NULL, // TopologyConnections
  648. NULL, // TopologyNodesNames
  649. 0, // Reserved
  650. };
  651. /*
  652. ** AdapterCompareGUIDsAndFormatSize()
  653. **
  654. ** Checks for a match on the three GUIDs and FormatSize
  655. **
  656. ** Arguments:
  657. **
  658. ** IN DataRange1
  659. ** IN DataRange2
  660. ** BOOL fCompareFormatSize - TRUE when comparing ranges
  661. ** - FALSE when comparing formats
  662. **
  663. ** Returns:
  664. **
  665. ** TRUE if all elements match
  666. ** FALSE if any are different
  667. **
  668. ** Side Effects: none
  669. */
  670. BOOL AdapterCompareGUIDsAndFormatSize(
  671. IN PKSDATARANGE DataRange1,
  672. IN PKSDATARANGE DataRange2,
  673. BOOL fCompareFormatSize
  674. )
  675. {
  676. return (
  677. IsEqualGUID (
  678. DataRange1->MajorFormat,
  679. DataRange2->MajorFormat) &&
  680. IsEqualGUID (
  681. DataRange1->SubFormat,
  682. DataRange2->SubFormat) &&
  683. IsEqualGUID (
  684. DataRange1->Specifier,
  685. DataRange2->Specifier) &&
  686. (fCompareFormatSize ?
  687. (DataRange1->FormatSize == DataRange2->FormatSize) : TRUE));
  688. }
  689. /*
  690. ** MultiplyCheckOverflow()
  691. **
  692. ** Perform a 32-bit unsigned multiplication with status indicating whether overflow occured.
  693. **
  694. ** Arguments:
  695. **
  696. ** a - first operand
  697. ** b - second operand
  698. ** pab - result
  699. **
  700. ** Returns:
  701. **
  702. ** TRUE - no overflow
  703. ** FALSE - overflow occurred
  704. **
  705. */
  706. BOOL
  707. MultiplyCheckOverflow(
  708. ULONG a,
  709. ULONG b,
  710. ULONG *pab
  711. )
  712. {
  713. *pab = a * b;
  714. if ((a == 0) || (((*pab) / a) == b)) {
  715. return TRUE;
  716. }
  717. return FALSE;
  718. }
  719. /*
  720. ** AdapterVerifyFormat()
  721. **
  722. ** Checks the validity of a format request by walking through the
  723. ** array of supported KSDATA_RANGEs for a given stream.
  724. **
  725. ** Arguments:
  726. **
  727. ** pKSDataFormat - pointer of a KSDATAFORMAT structure.
  728. ** StreamNumber - index of the stream being queried / opened.
  729. **
  730. ** Returns:
  731. **
  732. ** TRUE if the format is supported
  733. ** FALSE if the format cannot be suppored
  734. **
  735. ** Side Effects: none
  736. */
  737. BOOL AdapterVerifyFormat(PKSDATAFORMAT pKSDataFormatToVerify, int StreamNumber)
  738. {
  739. BOOL fOK = FALSE;
  740. ULONG j;
  741. ULONG NumberOfFormatArrayEntries;
  742. PKSDATAFORMAT *pAvailableFormats;
  743. //
  744. // Check that the stream number is valid
  745. //
  746. if (StreamNumber >= NumStreams) {
  747. TRAP();
  748. return FALSE;
  749. }
  750. NumberOfFormatArrayEntries =
  751. Streams[StreamNumber].hwStreamInfo.NumberOfFormatArrayEntries;
  752. //
  753. // Get the pointer to the array of available formats
  754. //
  755. pAvailableFormats = Streams[StreamNumber].hwStreamInfo.StreamFormatsArray;
  756. DBGINFO(("AdapterVerifyFormat, Stream=%d\n", StreamNumber));
  757. DBGINFO(("FormatSize=%d\n",
  758. pKSDataFormatToVerify->FormatSize));
  759. DBGINFO(("MajorFormat=%x\n",
  760. pKSDataFormatToVerify->MajorFormat));
  761. //
  762. // Walk the formats supported by the stream
  763. //
  764. for (j = 0; j < NumberOfFormatArrayEntries; j++, pAvailableFormats++) {
  765. // Check for a match on the three GUIDs and format size
  766. if (!AdapterCompareGUIDsAndFormatSize(
  767. pKSDataFormatToVerify,
  768. *pAvailableFormats,
  769. FALSE /* CompareFormatSize */)) {
  770. continue;
  771. }
  772. //
  773. // Now that the three GUIDs match, switch on the Specifier
  774. // to do a further type-specific check
  775. //
  776. // -------------------------------------------------------------------
  777. // Specifier FORMAT_VideoInfo for VIDEOINFOHEADER
  778. // -------------------------------------------------------------------
  779. if (IsEqualGUID(pKSDataFormatToVerify->Specifier, KSDATAFORMAT_SPECIFIER_VIDEOINFO) &&
  780. pKSDataFormatToVerify->FormatSize >= sizeof(KS_DATAFORMAT_VIDEOINFOHEADER)) {
  781. PKS_DATAFORMAT_VIDEOINFOHEADER pDataFormatVideoInfoHeader =
  782. (PKS_DATAFORMAT_VIDEOINFOHEADER) pKSDataFormatToVerify;
  783. PKS_VIDEOINFOHEADER pVideoInfoHdrToVerify =
  784. (PKS_VIDEOINFOHEADER) &pDataFormatVideoInfoHeader->VideoInfoHeader;
  785. PKS_DATARANGE_VIDEO pKSDataRangeVideo = (PKS_DATARANGE_VIDEO) *pAvailableFormats;
  786. KS_VIDEO_STREAM_CONFIG_CAPS *pConfigCaps = &pKSDataRangeVideo->ConfigCaps;
  787. // Validate each step of the size calculations for arithmetic overflow,
  788. // and verify that the specified sizes correlate
  789. // (with unsigned math, a+b < b iff an arithmetic overflow occured)
  790. {
  791. ULONG VideoHeaderSize = pVideoInfoHdrToVerify->bmiHeader.biSize +
  792. FIELD_OFFSET(KS_VIDEOINFOHEADER,bmiHeader);
  793. ULONG FormatSize = VideoHeaderSize +
  794. FIELD_OFFSET(KS_DATAFORMAT_VIDEOINFOHEADER,VideoInfoHeader);
  795. if (VideoHeaderSize < FIELD_OFFSET(KS_VIDEOINFOHEADER,bmiHeader) ||
  796. FormatSize < FIELD_OFFSET(KS_DATAFORMAT_VIDEOINFOHEADER,VideoInfoHeader) ||
  797. FormatSize > pKSDataFormatToVerify->FormatSize) {
  798. fOK = FALSE;
  799. break;
  800. }
  801. }
  802. // Validate the image size and dimension parameters
  803. // (the equivalent of using the KS_DIBSIZE macro)
  804. {
  805. ULONG ImageSize = 0;
  806. if (!MultiplyCheckOverflow(
  807. (ULONG)pVideoInfoHdrToVerify->bmiHeader.biWidth,
  808. (ULONG)pVideoInfoHdrToVerify->bmiHeader.biBitCount,
  809. &ImageSize
  810. )) {
  811. fOK = FALSE;
  812. break;
  813. }
  814. // Convert bits to an even multiple of 4 bytes
  815. ImageSize = ((ImageSize / 8) + 3) & ~3;
  816. // Now calculate the full size
  817. if (!MultiplyCheckOverflow(
  818. ImageSize,
  819. (ULONG)abs(pVideoInfoHdrToVerify->bmiHeader.biHeight),
  820. &ImageSize
  821. )) {
  822. fOK = FALSE;
  823. break;
  824. }
  825. // Finally, is the specified image size big enough?
  826. if (pDataFormatVideoInfoHeader->DataFormat.SampleSize < ImageSize ||
  827. pVideoInfoHdrToVerify->bmiHeader.biSizeImage < ImageSize
  828. ) {
  829. fOK = FALSE;
  830. break;
  831. }
  832. }
  833. fOK = TRUE;
  834. break;
  835. } // End of VIDEOINFOHEADER specifier
  836. // -------------------------------------------------------------------
  837. // Specifier FORMAT_VideoInfo for VBIINFOHEADER
  838. // -------------------------------------------------------------------
  839. if (IsEqualGUID (pKSDataFormatToVerify->Specifier, KSDATAFORMAT_SPECIFIER_VBI) &&
  840. pKSDataFormatToVerify->FormatSize >= sizeof(KS_DATAFORMAT_VBIINFOHEADER)) {
  841. PKS_DATAFORMAT_VBIINFOHEADER pKSVBIDataFormat =
  842. (PKS_DATAFORMAT_VBIINFOHEADER)pKSDataFormatToVerify;
  843. PKS_VBIINFOHEADER pVBIInfoHeader =
  844. &pKSVBIDataFormat->VBIInfoHeader;
  845. // Validate the VBI format and sample size parameters
  846. {
  847. ULONG SampleSize = 0;
  848. // Do the StartLine and Endline values make sense?
  849. if (pVBIInfoHeader->StartLine > pVBIInfoHeader->EndLine ||
  850. pVBIInfoHeader->StartLine < (VREFDiscard + 1) ||
  851. pVBIInfoHeader->EndLine - (VREFDiscard + 1) > 500
  852. ) {
  853. fOK = FALSE;
  854. break;
  855. }
  856. // Calculate the sample size
  857. if (!MultiplyCheckOverflow(
  858. pVBIInfoHeader->EndLine - pVBIInfoHeader->StartLine + 1,
  859. pVBIInfoHeader->SamplesPerLine,
  860. &SampleSize
  861. )) {
  862. fOK = FALSE;
  863. break;
  864. }
  865. // Are the size parameters big enough?
  866. if (pKSVBIDataFormat->DataFormat.SampleSize < SampleSize ||
  867. pVBIInfoHeader->BufferSize < SampleSize
  868. ) {
  869. fOK = FALSE;
  870. break;
  871. }
  872. }
  873. fOK = TRUE;
  874. break;
  875. } // End of VBI specifier
  876. // -------------------------------------------------------------------
  877. // Specifier FORMAT_AnalogVideo for KS_ANALOGVIDEOINFO
  878. // -------------------------------------------------------------------
  879. if (IsEqualGUID (pKSDataFormatToVerify->Specifier, KSDATAFORMAT_SPECIFIER_ANALOGVIDEO) &&
  880. pKSDataFormatToVerify->FormatSize >= sizeof(KS_DATARANGE_ANALOGVIDEO)) {
  881. fOK = TRUE;
  882. break;
  883. } // End of KS_ANALOGVIDEOINFO specifier
  884. // -------------------------------------------------------------------
  885. // Specifier STATIC_KSDATAFORMAT_TYPE_VIDEO for Video Port
  886. // -------------------------------------------------------------------
  887. if (IsEqualGUID (pKSDataFormatToVerify->Specifier, KSDATAFORMAT_SPECIFIER_NONE) &&
  888. IsEqualGUID (pKSDataFormatToVerify->SubFormat, KSDATAFORMAT_SUBTYPE_VPVideo)) {
  889. fOK = TRUE;
  890. break;
  891. } // End of Video port section
  892. // -------------------------------------------------------------------
  893. // Specifier KSDATAFORMAT_SPECIFIER_NONE for VP VBI
  894. // -------------------------------------------------------------------
  895. if (IsEqualGUID (pKSDataFormatToVerify->Specifier, KSDATAFORMAT_SPECIFIER_NONE) &&
  896. IsEqualGUID (pKSDataFormatToVerify->SubFormat, KSDATAFORMAT_SUBTYPE_VPVBI)) {
  897. fOK = TRUE;
  898. break;
  899. } // End of VP VBI section
  900. } // End of loop on all formats for this stream
  901. return fOK;
  902. }