Windows NT 4.0 source code leak
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.

204 lines
5.6 KiB

4 years ago
  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 <msvideo.h>
  28. #include <drawdib.h>
  29. #include <mmddk.h>
  30. #include <avifmt.h>
  31. #include "ivideo32.h"
  32. #include "avicap.h"
  33. #include "avicapi.h"
  34. #include "mmdebug.h"
  35. #ifdef _DEBUG
  36. #define DSTATUS(lpcs, sz) statusUpdateStatus(lpcs, IDS_CAP_INFO, (LPTSTR) TEXT(sz))
  37. #else
  38. #define DSTATUS(lpcs, sz)
  39. #endif
  40. /*
  41. * SingleFrameCaptureOpen
  42. *
  43. */
  44. BOOL FAR PASCAL SingleFrameCaptureOpen (LPCAPSTREAM lpcs)
  45. {
  46. UINT err;
  47. if ((lpcs->fCaptureFlags & CAP_fCapturingNow) || (lpcs->fCaptureFlags & CAP_fFrameCapturingNow)) {
  48. err = IDS_CAP_FILE_OPEN_ERROR;
  49. goto EarlyExit;
  50. }
  51. #ifdef NEW_COMPMAN
  52. /* Warm up the compressor function */
  53. if (lpcs->CompVars.hic) {
  54. if (ICSeqCompressFrameStart(&lpcs->CompVars, lpcs->lpBitsInfo) == FALSE) {
  55. err = IDS_CAP_COMPRESSOR_ERROR;
  56. goto EarlyExit;
  57. }
  58. // Kludge, offset the lpBitsOut ptr
  59. // Compman allocates the compress buffer too large by
  60. // 2048 + 16 so we will still have room
  61. ((LPBYTE) lpcs->CompVars.lpBitsOut) += 8;
  62. }
  63. #endif
  64. if (!CapFileInit(lpcs)) {
  65. err = IDS_CAP_FILE_OPEN_ERROR;
  66. goto EarlyExit;
  67. }
  68. lpcs->fCaptureFlags |= (CAP_fCapturingNow | CAP_fFrameCapturingNow);
  69. lpcs->dwReturn = DV_ERR_OK;
  70. statusUpdateStatus(lpcs, IDS_CAP_BEGIN); // Always the first message
  71. return TRUE;
  72. EarlyExit:
  73. errorUpdateError(lpcs, (UINT) err);
  74. return FALSE;
  75. }
  76. /*
  77. * SingleFrameCaptureClose
  78. *
  79. *
  80. */
  81. BOOL FAR PASCAL SingleFrameCaptureClose (LPCAPSTREAM lpcs)
  82. {
  83. if ((!(lpcs->fCaptureFlags & CAP_fCapturingNow)) && (!(lpcs->fCaptureFlags & CAP_fFrameCapturingNow))) {
  84. errorUpdateError(lpcs, IDS_CAP_FILE_OPEN_ERROR);
  85. return FALSE;
  86. }
  87. AVIFileFini(lpcs, TRUE /* fWroteJunkChunks */, FALSE /* fAbort */);
  88. #ifdef NEW_COMPMAN
  89. if (lpcs->CompVars.hic) {
  90. // Kludge, offset the lpBitsOut ptr
  91. if (lpcs->CompVars.lpBitsOut)
  92. ((LPBYTE) lpcs->CompVars.lpBitsOut) -= 8;
  93. ICSeqCompressFrameEnd(&lpcs->CompVars);
  94. }
  95. #endif
  96. lpcs->fCapFileExists = (lpcs->dwReturn == DV_ERR_OK);
  97. lpcs->fCaptureFlags &= ~(CAP_fCapturingNow | CAP_fFrameCapturingNow);
  98. statusUpdateStatus(lpcs, IDS_CAP_END); // Always the last message
  99. return TRUE;
  100. }
  101. /*
  102. * SingleFrameCapture
  103. *
  104. * Append to the open single frame capture file.
  105. */
  106. BOOL FAR PASCAL SingleFrameCapture (LPCAPSTREAM lpcs)
  107. {
  108. LPVIDEOHDR lpVidHdr = &lpcs->VidHdr;
  109. BOOL fOK = FALSE;
  110. DWORD dwBytesUsed;
  111. BOOL fKeyFrame;
  112. LPSTR lpData;
  113. if ((!(lpcs->fCaptureFlags & CAP_fCapturingNow)) ||
  114. (!((lpcs->fCaptureFlags & CAP_fStepCapturingNow) || (lpcs->fCaptureFlags & CAP_fFrameCapturingNow)))
  115. ) {
  116. errorUpdateError(lpcs, IDS_CAP_FILE_OPEN_ERROR);
  117. return FALSE;
  118. }
  119. videoFrame (lpcs->hVideoIn, &lpcs->VidHdr);
  120. InvalidateRect (lpcs->hwnd, NULL, TRUE);
  121. if (lpVidHdr->dwBytesUsed) {
  122. UINT wError;
  123. BOOL bPending = FALSE;
  124. if (lpcs->CallbackOnVideoFrame)
  125. lpcs->CallbackOnVideoFrame (lpcs->hwnd, lpVidHdr);
  126. // Prepend a RIFF chunk
  127. ((LPRIFF)lpVidHdr->lpData)[-1].dwType = MAKEAVICKID(cktypeDIBbits, 0);
  128. ((LPRIFF)lpVidHdr->lpData)[-1].dwSize = lpcs->VidHdr.dwBytesUsed;
  129. #ifdef NEW_COMPMAN
  130. //
  131. // We are automatically compressing during capture, so
  132. // compress the frame before we pass it on to be written
  133. //
  134. if (lpcs->CompVars.hic)
  135. {
  136. LPRIFF priff;
  137. dwBytesUsed = 0;
  138. lpData = ICSeqCompressFrame(&lpcs->CompVars, 0,
  139. lpVidHdr->lpData,
  140. &fKeyFrame,
  141. &dwBytesUsed);
  142. priff = ((LPRIFF)lpData) -1;
  143. priff->dwType = MAKEAVICKID(cktypeDIBbits, 0);
  144. priff->dwSize = dwBytesUsed;
  145. }
  146. else {
  147. lpData = lpVidHdr->lpData;
  148. dwBytesUsed = lpVidHdr->dwBytesUsed;
  149. fKeyFrame = lpVidHdr->dwFlags & VHDR_KEYFRAME;
  150. }
  151. #endif // NEW_COMPMAN
  152. // AVIWriteVideoFrame can compress while writing,
  153. // in this case, the dwBytesUsed and KeyFrame settings
  154. // may be modified, so pick these up after the write is finished
  155. AVIWriteVideoFrame (lpcs,
  156. lpData,
  157. dwBytesUsed,
  158. fKeyFrame,
  159. (UINT)-1, 0, &wError, &bPending);
  160. if (wError) {
  161. errorUpdateError(lpcs, wError);
  162. }
  163. else {
  164. fOK = TRUE;
  165. statusUpdateStatus (lpcs, IDS_CAP_STAT_CAP_L_FRAMES,
  166. lpcs->dwVideoChunkCount);
  167. }
  168. } // if the frame is done
  169. else
  170. errorUpdateError (lpcs, IDS_CAP_RECORDING_ERROR2);
  171. return fOK;
  172. }