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.

376 lines
11 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. #include "strmini.h"
  12. #include "ksmedia.h"
  13. #include "capmain.h"
  14. #include "capdebug.h"
  15. #include "vbixfer.h"
  16. #include "vbidata.h"
  17. /*
  18. ** DEBUG variables to play with
  19. */
  20. #if DBG
  21. unsigned short dCCScanWave = 0;
  22. unsigned short dCCScanLog = 0;
  23. unsigned short dCCLogOnce = 1;
  24. unsigned short dCCEncode5A = 0;
  25. #endif //DBG
  26. /*
  27. ** CC_ImageSynth()
  28. **
  29. ** Copies canned CC bytes
  30. **
  31. ** Arguments:
  32. **
  33. ** pSrb - The stream request block for the Video stream
  34. **
  35. ** Returns:
  36. ** Nothing
  37. **
  38. ** Side Effects: none
  39. */
  40. void CC_ImageSynth (
  41. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  42. )
  43. {
  44. PSTREAMEX pStrmEx = pSrb->StreamObject->HwStreamExtension;
  45. int StreamNumber = pSrb->StreamObject->StreamNumber;
  46. PKSSTREAM_HEADER pStreamHeader = pSrb->CommandData.DataBufferArray;
  47. PCC_HW_FIELD pCCfield = (PCC_HW_FIELD)pStreamHeader->Data;
  48. unsigned int field;
  49. unsigned int cc_index;
  50. DEBUG_ASSERT(pSrb->NumberOfBuffers == 1);
  51. if (pSrb->CommandData.DataBufferArray->FrameExtent < sizeof (CC_HW_FIELD)) {
  52. DbgLogError(("testcap: CC output pin handed buffer size %d, need %d\n",
  53. pSrb->CommandData.DataBufferArray->FrameExtent,
  54. sizeof (CC_HW_FIELD)));
  55. TRAP;
  56. return;
  57. }
  58. field = (unsigned int)(pStrmEx->VBIFrameInfo.PictureNumber % CCfieldCount);
  59. RtlZeroMemory(pCCfield, sizeof (*pCCfield));
  60. cc_index = 0;
  61. pCCfield->PictureNumber = pStrmEx->VBIFrameInfo.PictureNumber;
  62. pCCfield->fieldFlags = (field & 1)? KS_VBI_FLAG_FIELD1 : KS_VBI_FLAG_FIELD2;
  63. field >>= 1;
  64. SETBIT(pCCfield->ScanlinesRequested.DwordBitArray, 21);
  65. if (KS_VBI_FLAG_FIELD1 == pCCfield->fieldFlags) {
  66. pCCfield->Lines[cc_index].Decoded[0] = CCfields[field][0];
  67. pCCfield->Lines[cc_index].Decoded[1] = CCfields[field][1];
  68. }
  69. else {
  70. pCCfield->Lines[cc_index].Decoded[0] = 0;
  71. pCCfield->Lines[cc_index].Decoded[1] = 0;
  72. }
  73. //DbgKdPrint(("%c%c", CCfields[field][0] & 0x7F, CCfields[field][1] & 0x7F));
  74. ++cc_index;
  75. pStreamHeader->DataUsed = sizeof (CC_HW_FIELD);
  76. }
  77. /*
  78. ** CC_EncodeWaveform()
  79. **
  80. ** Writes out a CC waveform encoding the supplied data bytes
  81. **
  82. ** Arguments:
  83. **
  84. ** waveform - the buffer for the CC waveform data
  85. ** cc1 - the first byte to encode into the waveform
  86. ** cc2 - the second byte to encode into the waveform
  87. **
  88. ** Returns:
  89. ** Nothing
  90. **
  91. ** Side Effects: overwrites waveform with an EIA-608 signal
  92. */
  93. void CC_EncodeWaveform(
  94. unsigned char *waveform,
  95. unsigned char cc1,
  96. unsigned char cc2)
  97. {
  98. unsigned int waveIdx;
  99. unsigned char DC_zero = CCsampleWave[0];
  100. unsigned char DC_one = CCsampleWave[34];
  101. unsigned short DC_last;
  102. // 455/8 = 56.875 bytes per CC bit at KS_VBISAMPLINGRATE_5X_NABTS(~28.6mhz)
  103. unsigned int CCstride = 455;
  104. unsigned char *samp, *end, byte;
  105. unsigned int bit, done;
  106. #if DBG
  107. if (dCCEncode5A) {
  108. cc1 = 0x5A;
  109. cc2 = 0x5A;
  110. }
  111. if (dCCScanWave) {
  112. // Scan EIGHT bits worth of samples for low / high DC values
  113. for (samp=CCsampleWave, end=CCsampleWave+CCstride; samp < end; ++samp) {
  114. if (*samp > DC_one)
  115. DC_one = *samp;
  116. else if (*samp < DC_zero)
  117. DC_zero = *samp;
  118. }
  119. for (samp = CCsampleWave + 500; samp < &CCsampleWave[550] ; ++samp) {
  120. if (*samp >= DC_one - 5)
  121. break;
  122. }
  123. waveIdx = (unsigned int)((samp - CCsampleWave) * 8);
  124. if (dCCScanLog) {
  125. DbgKdPrint(("testcap::CC_EncodeWaveform: DC_zero = %u, DC_one = %u, waveIdx = %u\n", DC_zero, DC_one, waveIdx/8));
  126. dCCScanLog = 0;
  127. }
  128. }
  129. else {
  130. #endif //DBG
  131. waveIdx = CCsampleWaveDataOffset * 8;
  132. DC_zero = CCsampleWaveDC_zero;
  133. DC_one = CCsampleWaveDC_one;
  134. #if DBG
  135. }
  136. #endif //DBG
  137. // Copy Run-in bytes and first three bits as-is
  138. RtlCopyMemory(waveform, CCsampleWave, waveIdx/8);
  139. DC_last = waveform[waveIdx/8 - 1] * 4;
  140. // Now encode the requested bytes
  141. samp = &waveform[waveIdx/8];
  142. for (byte = cc1, done = 0; ; byte = cc2, done = 1)
  143. {
  144. unsigned int bitpos;
  145. for (bitpos = 0; bitpos < 8; ++bitpos) {
  146. bit = byte & 1;
  147. byte >>= 1;
  148. for (end = &waveform[(waveIdx + CCstride)/8]; samp < end; ++samp) {
  149. if (bit == 1) {
  150. if (DC_last/4 < DC_one) {
  151. DC_last += 7;
  152. if (DC_last/4 > DC_one)
  153. DC_last = DC_one * 4;
  154. }
  155. }
  156. else /* bit == 0 */ {
  157. if (DC_last/4 > DC_zero) {
  158. DC_last -= 7;
  159. if (DC_last/4 < DC_zero)
  160. DC_last = DC_zero * 4;
  161. }
  162. }
  163. ASSERT(samp < &waveform[768*2]);
  164. *samp = DC_last/4;
  165. }
  166. waveIdx += CCstride;
  167. }
  168. if (done)
  169. break;
  170. }
  171. // Finish up at DC_zero
  172. for (end = &waveform[768*2]; samp < end; ++samp) {
  173. if (DC_last/4 > DC_zero) {
  174. DC_last -= 7;
  175. if (DC_last/4 < DC_zero)
  176. DC_last = DC_zero * 4;
  177. }
  178. *samp = DC_last/4;
  179. }
  180. }
  181. /*
  182. ** NABTS_ImageSynth()
  183. **
  184. ** Copies canned NABTS bytes
  185. **
  186. ** Arguments:
  187. **
  188. ** pSrb - The stream request block for the Video stream
  189. **
  190. ** Returns:
  191. ** Nothing
  192. **
  193. ** Side Effects: none
  194. */
  195. unsigned char HammingEncode[16] = {
  196. 0x15, 0x02, 0x49, 0x5E, 0x64, 0x73, 0x38, 0x2F,
  197. 0xD0, 0xC7, 0x8C, 0x9B, 0xA1, 0xB6, 0xFD, 0xEA
  198. };
  199. void NABTS_ImageSynth (
  200. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  201. )
  202. {
  203. PSTREAMEX pStrmEx = pSrb->StreamObject->HwStreamExtension;
  204. int StreamNumber = pSrb->StreamObject->StreamNumber;
  205. PKSSTREAM_HEADER pStreamHeader = pSrb->CommandData.DataBufferArray;
  206. PNABTS_BUFFER pNbuf = (PNABTS_BUFFER)pStreamHeader->Data;
  207. unsigned int field;
  208. #ifdef VBIDATA_NABTS
  209. // Check to make sure that the supplied buffer is large enough
  210. if (pSrb->CommandData.DataBufferArray->FrameExtent < sizeof (NABTS_BUFFER)) {
  211. DbgLogError(("testcap: NABTS output pin handed buffer size %d, need %d\n",
  212. pSrb->CommandData.DataBufferArray->FrameExtent,
  213. sizeof (NABTS_BUFFER)));
  214. TRAP;
  215. return;
  216. }
  217. DEBUG_ASSERT (pSrb->NumberOfBuffers == 1);
  218. pNbuf->PictureNumber = pStrmEx->VBIFrameInfo.PictureNumber;
  219. // Copy the next apropriate field
  220. field = (unsigned int)(pStrmEx->VBIFrameInfo.PictureNumber % NABTSfieldCount);
  221. RtlCopyMemory(pNbuf, NABTSfields[field], sizeof (NABTS_BUFFER));
  222. #else /*VBIDATA_NABTS*/
  223. unsigned char i, line, ci;
  224. PNABTS_BUFFER_LINE pNline;
  225. // Check to make sure that the supplied buffer is large enough
  226. if (pSrb->CommandData.DataBufferArray->FrameExtent < sizeof (NABTS_BUFFER)) {
  227. DbgLogError(("testcap: NABTS output pin handed buffer size %d, need %d\n",
  228. pSrb->CommandData.DataBufferArray->FrameExtent,
  229. sizeof (NABTS_BUFFER)));
  230. TRAP;
  231. return;
  232. }
  233. // Create a test pattern
  234. RtlZeroMemory(pNbuf, sizeof (NABTS_BUFFER));
  235. ci = (unsigned char)(pStrmEx->VBIFrameInfo.PictureNumber % 15);
  236. pNbuf->PictureNumber = pStrmEx->VBIFrameInfo.PictureNumber;
  237. for (line = 10, pNline = pNbuf->NabtsLines;
  238. line < 21;
  239. ++line, ++pNline)
  240. {
  241. SETBIT(pNbuf->ScanlinesRequested.DwordBitArray, line);
  242. pNline->Confidence = 102; // We're 102% sure this NABTS is OK
  243. // NABTS Header bytes
  244. pNline->Bytes[00] =
  245. pNline->Bytes[01] = 0x55;
  246. pNline->Bytes[02] = 0xE7;
  247. // Set GroupID 0x8F4
  248. pNline->Bytes[03] = HammingEncode[0x8];
  249. pNline->Bytes[04] = HammingEncode[0xF];
  250. pNline->Bytes[05] = HammingEncode[0x4];
  251. pNline->Bytes[06] = HammingEncode[ci];
  252. pNline->Bytes[07] = HammingEncode[0x0]; // PS = Reg, Full, No suffix
  253. // NABTS Payload
  254. i = 8;
  255. pNline->Bytes[i++] = 0xA0; // Mark the start of payload,
  256. pNline->Bytes[i++] = 0xA0; // just for fun
  257. pNline->Bytes[i++] = ci; // Put frame # into payload
  258. pNline->Bytes[i++] = line; // Put line # into payload
  259. // The rest zeros for now...
  260. }
  261. #endif /*VBIDATA_NABTS*/
  262. pStreamHeader->DataUsed = sizeof (NABTS_BUFFER);
  263. }
  264. /*
  265. ** VBI_ImageSynth()
  266. **
  267. ** Copies canned VBI samples
  268. **
  269. ** Arguments:
  270. **
  271. ** pSrb - The stream request block for the Video stream
  272. ** ImageXferCommands - Index specifying the image to generate
  273. **
  274. ** Returns:
  275. ** Nothing
  276. **
  277. ** Side Effects: none
  278. */
  279. void VBI_ImageSynth (
  280. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  281. )
  282. {
  283. PSTREAMEX pStrmEx = pSrb->StreamObject->HwStreamExtension;
  284. int StreamNumber = pSrb->StreamObject->StreamNumber;
  285. PKSSTREAM_HEADER pStreamHeader = pSrb->CommandData.DataBufferArray;
  286. PUCHAR pImage = pStreamHeader->Data;
  287. unsigned int field, cc_field;
  288. unsigned char cc1, cc2;
  289. DEBUG_ASSERT (pSrb->NumberOfBuffers == 1);
  290. // Check to make sure that the supplied buffer is large enough
  291. if (pSrb->CommandData.DataBufferArray->FrameExtent < VBIfieldSize) {
  292. DbgLogError(("testcap: VBI output pin handed buffer size %d, need %d\n",
  293. pSrb->CommandData.DataBufferArray->FrameExtent,
  294. VBIfieldSize));
  295. TRAP;
  296. return;
  297. }
  298. // Copy the next apropriate field
  299. field = (unsigned int)(pStrmEx->VBIFrameInfo.PictureNumber % VBIfieldCount);
  300. RtlCopyMemory(pImage, VBIsamples[field], VBIfieldSize);
  301. // Now mangle the CC waveform to match the HW data
  302. if (field & 1) {
  303. cc_field = (unsigned int)
  304. (pStrmEx->VBIFrameInfo.PictureNumber >> 1) % CCfieldCount;
  305. cc1 = CCfields[cc_field][0];
  306. cc2 = CCfields[cc_field][1];
  307. }
  308. else {
  309. cc1 = 0;
  310. cc2 = 0;
  311. }
  312. CC_EncodeWaveform(VBIsamples[field][21-10], cc1, cc2);
  313. // Report back the actual number of bytes copied to the destination buffer
  314. pStreamHeader->DataUsed = VBIfieldSize;
  315. }