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.

222 lines
7.4 KiB

  1. //==========================================================================;
  2. //
  3. // CWDMVBICaptureStream - VBI Capture Stream class implementation
  4. //
  5. // $Date: 05 Aug 1998 11:11:20 $
  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. {
  14. #include "strmini.h"
  15. #include "ksmedia.h"
  16. #include "ddkmapi.h"
  17. }
  18. #include "wdmvdec.h"
  19. #include "wdmdrv.h"
  20. #include "aticonfg.h"
  21. #include "capdebug.h"
  22. #include "defaults.h"
  23. CWDMVBICaptureStream::CWDMVBICaptureStream(PHW_STREAM_OBJECT pStreamObject,
  24. CWDMVideoDecoder * pCWDMVideoDecoder,
  25. PKSDATAFORMAT pKSDataFormat,
  26. PUINT puiErrorCode)
  27. : CWDMCaptureStream(pStreamObject, pCWDMVideoDecoder, puiErrorCode)
  28. {
  29. m_stateChange = Initializing;
  30. DBGTRACE(("CWDMVBICaptureStream::Startup()\n"));
  31. PKS_DATAFORMAT_VBIINFOHEADER pVBIInfoHeader =
  32. (PKS_DATAFORMAT_VBIINFOHEADER) pKSDataFormat;
  33. PKS_VBIINFOHEADER pVBIInfoHdrRequested =
  34. &pVBIInfoHeader->VBIInfoHeader;
  35. DBGINFO(("pVBIInfoHdrRequested->StartLine = %d\n", pVBIInfoHdrRequested->StartLine));
  36. DBGINFO(("pVBIInfoHdrRequested->EndLine = %d\n", pVBIInfoHdrRequested->EndLine));
  37. DBGINFO(("pVBIInfoHdrRequested->MinLineStartTime = %d\n", pVBIInfoHdrRequested->MinLineStartTime));
  38. DBGINFO(("pVBIInfoHdrRequested->MaxLineStartTime = %d\n", pVBIInfoHdrRequested->MaxLineStartTime));
  39. DBGINFO(("pVBIInfoHdrRequested->ActualLineStartTime = %d\n", pVBIInfoHdrRequested->ActualLineStartTime));
  40. DBGINFO(("pVBIInfoHdrRequested->VideoStandard = 0x%x\n", pVBIInfoHdrRequested->VideoStandard));
  41. DBGINFO(("pVBIInfoHdrRequested->SamplesPerLine = %d\n", pVBIInfoHdrRequested->SamplesPerLine));
  42. DBGINFO(("pVBIInfoHdrRequested->StrideInBytes = %d\n", pVBIInfoHdrRequested->StrideInBytes));
  43. DBGINFO(("pVBIInfoHdrRequested->BufferSize = %d\n", pVBIInfoHdrRequested->BufferSize));
  44. m_pVBIInfoHeader = &m_VBIFrameInfo.VBIInfoHeader;
  45. // Copy the VBIINFOHEADER requested to our storage
  46. RtlCopyMemory(
  47. m_pVBIInfoHeader,
  48. pVBIInfoHdrRequested,
  49. sizeof(KS_VBIINFOHEADER));
  50. Startup(puiErrorCode);
  51. }
  52. CWDMVBICaptureStream::~CWDMVBICaptureStream()
  53. {
  54. DBGTRACE(("CWDMVBICaptureStream::~CWDMVBICaptureStream()\n"));
  55. Shutdown();
  56. }
  57. BOOL CWDMVBICaptureStream::GetCaptureHandle()
  58. {
  59. if (m_hCapture == 0)
  60. {
  61. DBGTRACE(("Stream %d getting capture handle\n", m_pStreamObject->StreamNumber));
  62. DDOPENVPCAPTUREDEVICEIN ddOpenCaptureIn;
  63. DDOPENVPCAPTUREDEVICEOUT ddOpenCaptureOut;
  64. RtlZeroMemory(&ddOpenCaptureIn, sizeof(ddOpenCaptureIn));
  65. RtlZeroMemory(&ddOpenCaptureOut, sizeof(ddOpenCaptureOut));
  66. ddOpenCaptureIn.hDirectDraw = m_pVideoPort->GetDirectDrawHandle();
  67. ddOpenCaptureIn.hVideoPort = m_pVideoPort->GetVideoPortHandle();
  68. ddOpenCaptureIn.pfnCaptureClose = DirectDrawEventCallback;
  69. ddOpenCaptureIn.pContext = this;
  70. if ((!ddOpenCaptureIn.hDirectDraw)||
  71. (!ddOpenCaptureIn.hVideoPort)||
  72. (!ddOpenCaptureIn.pfnCaptureClose)||
  73. (!ddOpenCaptureIn.pContext))
  74. {
  75. return FALSE;
  76. }
  77. // Now to get the size, etc
  78. int xOrigin, yOrigin;
  79. m_pDevice->GetVBISurfaceOrigin(&xOrigin, &yOrigin);
  80. ddOpenCaptureIn.dwStartLine = 0 + yOrigin;
  81. ddOpenCaptureIn.dwEndLine = NTSCVBILines - 1 + yOrigin;
  82. // Fail-safe
  83. if (ddOpenCaptureIn.dwStartLine > 500)
  84. {
  85. DBGERROR(("Unexpected VBI start line = %d. Using default\n"));
  86. ddOpenCaptureIn.dwStartLine = m_pVBIInfoHeader->StartLine - VREFDiscard - 1;
  87. }
  88. if (ddOpenCaptureIn.dwEndLine > 500)
  89. {
  90. DBGERROR(("Unexpected VBI end line. Using default\n"));
  91. ddOpenCaptureIn.dwEndLine = m_pVBIInfoHeader->EndLine - VREFDiscard - 1;
  92. }
  93. DBGINFO(("VBI surface: %d, %d\n",
  94. ddOpenCaptureIn.dwStartLine,
  95. ddOpenCaptureIn.dwEndLine));
  96. ddOpenCaptureIn.dwFlags = DDOPENCAPTURE_VBI;
  97. ddOpenCaptureIn.dwCaptureEveryNFields = 1;
  98. DxApi(DD_DXAPI_OPENVPCAPTUREDEVICE, &ddOpenCaptureIn, sizeof(ddOpenCaptureIn), &ddOpenCaptureOut, sizeof(ddOpenCaptureOut));
  99. if (ddOpenCaptureOut.ddRVal != DD_OK)
  100. {
  101. m_hCapture = 0;
  102. DBGERROR(("DD_DXAPI_OPENVPCAPTUREDEVICE failed.\n"));
  103. // TRAP();
  104. return FALSE;
  105. }
  106. else
  107. {
  108. m_hCapture = ddOpenCaptureOut.hCapture;
  109. }
  110. }
  111. return TRUE;
  112. }
  113. VOID CWDMVBICaptureStream::SetFrameInfo(PHW_STREAM_REQUEST_BLOCK pSrb)
  114. {
  115. PSRB_DATA_EXTENSION pSrbExt = (PSRB_DATA_EXTENSION)pSrb->SRBExtension;
  116. PKSSTREAM_HEADER pDataPacket = pSrb->CommandData.DataBufferArray;
  117. LONGLONG droppedThisTime = 0;
  118. PKS_VBI_FRAME_INFO pFrameInfo = (PKS_VBI_FRAME_INFO) (pDataPacket + 1);
  119. m_VBIFrameInfo.dwFrameFlags = 0;
  120. m_VBIFrameInfo.ExtendedHeaderSize = pFrameInfo->ExtendedHeaderSize;
  121. // Set the discontinuity flag if frames have been previously dropped.
  122. if ((m_VBIFrameInfo.PictureNumber + 1) <
  123. pSrbExt->ddCapBuffInfo.dwFieldNumber)
  124. {
  125. droppedThisTime =
  126. pSrbExt->ddCapBuffInfo.dwFieldNumber -
  127. (m_VBIFrameInfo.PictureNumber + 1);
  128. m_VBIFrameInfo.DropCount += droppedThisTime;
  129. pDataPacket->OptionsFlags |= KSSTREAM_HEADER_OPTIONSF_DATADISCONTINUITY;
  130. #ifdef DEBUG
  131. static int j;
  132. DBGERROR((" D%d ", droppedThisTime));
  133. if ((++j % 10) == 0)
  134. {
  135. DBGERROR(("\n"));
  136. }
  137. #endif
  138. }
  139. m_VBIFrameInfo.PictureNumber = pSrbExt->ddCapBuffInfo.dwFieldNumber;
  140. m_VBIFrameInfo.dwSamplingFrequency = SamplingFrequency;
  141. if (m_pVideoDecoder->GetTunerInfo(&m_VBIFrameInfo.TvTunerChangeInfo))
  142. {
  143. m_VBIFrameInfo.dwFrameFlags |= KS_VBI_FLAG_TVTUNER_CHANGE;
  144. #ifdef DEBUG
  145. if (m_VBIFrameInfo.TvTunerChangeInfo.dwFlags & KS_TVTUNER_CHANGE_BEGIN_TUNE)
  146. {
  147. DBGTRACE(("Sending KS_TVTUNER_CHANGE_BEGIN_TUNE.\n"));
  148. }
  149. else if (m_VBIFrameInfo.TvTunerChangeInfo.dwFlags & KS_TVTUNER_CHANGE_END_TUNE)
  150. {
  151. DBGTRACE(("Sending KS_TVTUNER_CHANGE_END_TUNE.\n"));
  152. }
  153. else
  154. {
  155. DBGERROR(("Unexpected value in TVTunerChangeInfo.dwFlags\n"));
  156. }
  157. #endif
  158. }
  159. if (!m_bVBIinitialized)
  160. {
  161. m_VBIFrameInfo.dwFrameFlags |= KS_VBI_FLAG_VBIINFOHEADER_CHANGE;
  162. m_bVBIinitialized = TRUE;
  163. }
  164. if (pSrbExt->ddCapBuffInfo.bPolarity)
  165. {
  166. m_VBIFrameInfo.dwFrameFlags |= KS_VIDEO_FLAG_FIELD2;
  167. }
  168. else
  169. {
  170. m_VBIFrameInfo.dwFrameFlags |= KS_VIDEO_FLAG_FIELD1;
  171. }
  172. *pFrameInfo = (KS_VBI_FRAME_INFO)m_VBIFrameInfo;
  173. }
  174. void CWDMVBICaptureStream::ResetFrameCounters()
  175. {
  176. m_VBIFrameInfo.PictureNumber = 0;
  177. m_VBIFrameInfo.DropCount = 0;
  178. }
  179. void CWDMVBICaptureStream::GetDroppedFrames(PKSPROPERTY_DROPPEDFRAMES_CURRENT_S pDroppedFrames)
  180. {
  181. pDroppedFrames->PictureNumber = m_VBIFrameInfo.PictureNumber;
  182. pDroppedFrames->DropCount = m_VBIFrameInfo.DropCount;
  183. pDroppedFrames->AverageFrameSize = m_pVBIInfoHeader->BufferSize;
  184. }