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.

201 lines
5.7 KiB

  1. /****************************************************************************
  2. *
  3. * capframe.c
  4. *
  5. * Single frame capture
  6. *
  7. * Microsoft Video for Windows Sample Capture Class
  8. *
  9. * Copyright (c) 1992, 1993 Microsoft Corporation. All Rights Reserved.
  10. *
  11. * You have a royalty-free right to use, modify, reproduce and
  12. * distribute the Sample Files (and/or any modified version) in
  13. * any way you find useful, provided that you agree that
  14. * Microsoft has no warranty obligations or liability for any
  15. * Sample Application Files which are modified.
  16. *
  17. ***************************************************************************/
  18. #define INC_OLE2
  19. #pragma warning(disable:4103)
  20. #include <windows.h>
  21. #include <windowsx.h>
  22. #include <win32.h>
  23. #include <mmsystem.h>
  24. #include <stdlib.h>
  25. #include <ctype.h>
  26. #include <string.h>
  27. #include <vfw.h>
  28. #include <mmddk.h>
  29. #include "ivideo32.h"
  30. #include "avicapi.h"
  31. #include "mmdebug.h"
  32. #ifdef _DEBUG
  33. #define DSTATUS(lpcs, sz) statusUpdateStatus(lpcs, IDS_CAP_INFO, (LPTSTR) TEXT(sz))
  34. #else
  35. #define DSTATUS(lpcs, sz)
  36. #endif
  37. /*
  38. * SingleFrameCaptureOpen
  39. *
  40. */
  41. BOOL FAR PASCAL SingleFrameCaptureOpen (LPCAPSTREAM lpcs)
  42. {
  43. UINT err;
  44. if ((lpcs->fCaptureFlags & CAP_fCapturingNow) || (lpcs->fCaptureFlags & CAP_fFrameCapturingNow)) {
  45. err = IDS_CAP_FILE_OPEN_ERROR;
  46. goto EarlyExit;
  47. }
  48. #ifdef NEW_COMPMAN
  49. /* Warm up the compressor function */
  50. if (lpcs->CompVars.hic) {
  51. if (ICSeqCompressFrameStart(&lpcs->CompVars, lpcs->lpBitsInfo) == FALSE) {
  52. err = IDS_CAP_COMPRESSOR_ERROR;
  53. goto EarlyExit;
  54. }
  55. // Kludge, offset the lpBitsOut ptr
  56. // Compman allocates the compress buffer too large by
  57. // 2048 + 16 so we will still have room
  58. ((LPBYTE) lpcs->CompVars.lpBitsOut) += 8;
  59. }
  60. #endif
  61. if (!CapFileInit(lpcs)) {
  62. err = IDS_CAP_FILE_OPEN_ERROR;
  63. goto EarlyExit;
  64. }
  65. lpcs->fCaptureFlags |= (CAP_fCapturingNow | CAP_fFrameCapturingNow);
  66. lpcs->dwReturn = DV_ERR_OK;
  67. statusUpdateStatus(lpcs, IDS_CAP_BEGIN); // Always the first message
  68. return TRUE;
  69. EarlyExit:
  70. errorUpdateError(lpcs, (UINT) err);
  71. return FALSE;
  72. }
  73. /*
  74. * SingleFrameCaptureClose
  75. *
  76. *
  77. */
  78. BOOL FAR PASCAL SingleFrameCaptureClose (LPCAPSTREAM lpcs)
  79. {
  80. if ((!(lpcs->fCaptureFlags & CAP_fCapturingNow)) && (!(lpcs->fCaptureFlags & CAP_fFrameCapturingNow))) {
  81. errorUpdateError(lpcs, IDS_CAP_FILE_OPEN_ERROR);
  82. return FALSE;
  83. }
  84. AVIFileFini(lpcs, TRUE /* fWroteJunkChunks */, FALSE /* fAbort */);
  85. #ifdef NEW_COMPMAN
  86. if (lpcs->CompVars.hic) {
  87. // Kludge, offset the lpBitsOut ptr
  88. if (lpcs->CompVars.lpBitsOut)
  89. ((LPBYTE) lpcs->CompVars.lpBitsOut) -= 8;
  90. ICSeqCompressFrameEnd(&lpcs->CompVars);
  91. }
  92. #endif
  93. lpcs->fCapFileExists = (lpcs->dwReturn == DV_ERR_OK);
  94. lpcs->fCaptureFlags &= ~(CAP_fCapturingNow | CAP_fFrameCapturingNow);
  95. statusUpdateStatus(lpcs, IDS_CAP_END); // Always the last message
  96. return TRUE;
  97. }
  98. /*
  99. * SingleFrameCapture
  100. *
  101. * Append to the open single frame capture file.
  102. */
  103. BOOL FAR PASCAL SingleFrameCapture (LPCAPSTREAM lpcs)
  104. {
  105. LPVIDEOHDR lpVidHdr = &lpcs->VidHdr;
  106. BOOL fOK = FALSE;
  107. DWORD dwBytesUsed;
  108. BOOL fKeyFrame;
  109. LPSTR lpData;
  110. if ((!(lpcs->fCaptureFlags & CAP_fCapturingNow)) ||
  111. (!((lpcs->fCaptureFlags & CAP_fStepCapturingNow) || (lpcs->fCaptureFlags & CAP_fFrameCapturingNow)))
  112. ) {
  113. errorUpdateError(lpcs, IDS_CAP_FILE_OPEN_ERROR);
  114. return FALSE;
  115. }
  116. videoFrame (lpcs->hVideoIn, &lpcs->VidHdr);
  117. InvalidateRect (lpcs->hwnd, NULL, TRUE);
  118. if (lpVidHdr->dwBytesUsed) {
  119. UINT wError;
  120. BOOL bPending = FALSE;
  121. if (lpcs->CallbackOnVideoFrame)
  122. lpcs->CallbackOnVideoFrame (lpcs->hwnd, lpVidHdr);
  123. // Prepend a RIFF chunk
  124. ((LPRIFF)lpVidHdr->lpData)[-1].dwType = MAKEAVICKID(cktypeDIBbits, 0);
  125. ((LPRIFF)lpVidHdr->lpData)[-1].dwSize = lpcs->VidHdr.dwBytesUsed;
  126. #ifdef NEW_COMPMAN
  127. //
  128. // We are automatically compressing during capture, so
  129. // compress the frame before we pass it on to be written
  130. //
  131. if (lpcs->CompVars.hic)
  132. {
  133. LPRIFF priff;
  134. dwBytesUsed = 0;
  135. lpData = ICSeqCompressFrame(&lpcs->CompVars, 0,
  136. lpVidHdr->lpData,
  137. &fKeyFrame,
  138. &dwBytesUsed);
  139. priff = ((LPRIFF)lpData) -1;
  140. priff->dwType = MAKEAVICKID(cktypeDIBbits, 0);
  141. priff->dwSize = dwBytesUsed;
  142. }
  143. else {
  144. lpData = lpVidHdr->lpData;
  145. dwBytesUsed = lpVidHdr->dwBytesUsed;
  146. fKeyFrame = lpVidHdr->dwFlags & VHDR_KEYFRAME;
  147. }
  148. #endif // NEW_COMPMAN
  149. // AVIWriteVideoFrame can compress while writing,
  150. // in this case, the dwBytesUsed and KeyFrame settings
  151. // may be modified, so pick these up after the write is finished
  152. AVIWriteVideoFrame (lpcs,
  153. lpData,
  154. dwBytesUsed,
  155. fKeyFrame,
  156. (UINT)-1, 0, &wError, &bPending);
  157. if (wError) {
  158. errorUpdateError(lpcs, wError);
  159. }
  160. else {
  161. fOK = TRUE;
  162. statusUpdateStatus (lpcs, IDS_CAP_STAT_CAP_L_FRAMES,
  163. lpcs->dwVideoChunkCount);
  164. }
  165. } // if the frame is done
  166. else
  167. errorUpdateError (lpcs, IDS_CAP_RECORDING_ERROR2);
  168. return fOK;
  169. }