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.

320 lines
9.5 KiB

  1. /****************************************************************************
  2. *
  3. * capinit.c
  4. *
  5. * Initialization code.
  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. #include <windows.h>
  19. #include <windowsx.h>
  20. #include <ver.h>
  21. #include <mmsystem.h>
  22. //
  23. // define these before any msvideo.h, so our functions get declared right.
  24. //
  25. #ifndef WIN32
  26. #define VFWAPI FAR PASCAL _loadds
  27. #define VFWAPIV FAR CDECL _loadds
  28. #endif
  29. #include "msvideo.h"
  30. #include <drawdib.h>
  31. #include "avicap.h"
  32. #include "avicapi.h"
  33. // for correct handling of capGetDriverDescription on NT and Chicago
  34. // this is used by the NT version of avicap.dll (16bit) but not intended for
  35. // public use, hence not in msvideo.h
  36. DWORD WINAPI videoCapDriverDescAndVer (
  37. DWORD wDriverIndex,
  38. LPSTR lpszName, UINT cbName,
  39. LPSTR lpszVer, UINT cbVer);
  40. HINSTANCE ghInst;
  41. BOOL gfIsRTL;
  42. char szCaptureWindowClass[] = "ClsCapWin";
  43. typedef struct tagVS_VERSION
  44. {
  45. WORD wTotLen;
  46. WORD wValLen;
  47. char szSig[16];
  48. VS_FIXEDFILEINFO vffInfo;
  49. } VS_VERSION;
  50. typedef struct tagLANGANDCP
  51. {
  52. WORD wLanguage;
  53. WORD wCodePage;
  54. } LANGANDCP;
  55. BOOL FAR PASCAL RegisterCaptureClass (HINSTANCE hInst)
  56. {
  57. WNDCLASS cls;
  58. // If we're already registered, we're OK
  59. if (GetClassInfo(hInst, szCaptureWindowClass, &cls))
  60. return TRUE;
  61. cls.hCursor = LoadCursor(NULL, IDC_ARROW);
  62. cls.hIcon = NULL;
  63. cls.lpszMenuName = NULL;
  64. cls.lpszClassName = szCaptureWindowClass;
  65. cls.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
  66. cls.hInstance = hInst;
  67. cls.style = CS_HREDRAW|CS_VREDRAW | CS_BYTEALIGNCLIENT |
  68. CS_GLOBALCLASS;
  69. cls.lpfnWndProc = CapWndProc;
  70. cls.cbClsExtra = 0;
  71. // Kludge, VB Status and Error GlobalAlloc'd ptrs + room to grow...
  72. cls.cbWndExtra = sizeof (LPCAPSTREAM) + sizeof (DWORD) * 4;
  73. RegisterClass(&cls);
  74. return TRUE;
  75. }
  76. //
  77. // Internal version
  78. // Get the name and version of the video device
  79. //
  80. BOOL capInternalGetDriverDesc (WORD wDriverIndex,
  81. LPSTR lpszName, int cbName,
  82. LPSTR lpszVer, int cbVer)
  83. {
  84. return (BOOL) videoCapDriverDescAndVer(
  85. wDriverIndex,
  86. lpszName, cbName,
  87. lpszVer, cbVer);
  88. }
  89. //
  90. // Exported version
  91. // Get the name and version of the video device
  92. //
  93. BOOL VFWAPI capGetDriverDescription (WORD wDriverIndex,
  94. LPSTR lpszName, int cbName,
  95. LPSTR lpszVer, int cbVer)
  96. {
  97. return (capInternalGetDriverDesc (wDriverIndex,
  98. lpszName, cbName,
  99. lpszVer, cbVer));
  100. }
  101. //
  102. // Disconnect from hardware resources
  103. //
  104. BOOL CapWinDisconnectHardware(LPCAPSTREAM lpcs)
  105. {
  106. if( lpcs->hVideoCapture ) {
  107. videoStreamFini (lpcs->hVideoCapture);
  108. videoClose( lpcs->hVideoCapture );
  109. }
  110. if( lpcs->hVideoDisplay ) {
  111. videoStreamFini (lpcs->hVideoDisplay);
  112. videoClose( lpcs->hVideoDisplay );
  113. }
  114. if( lpcs->hVideoIn ) {
  115. videoClose( lpcs->hVideoIn );
  116. }
  117. lpcs->fHardwareConnected = FALSE;
  118. lpcs->hVideoCapture = NULL;
  119. lpcs->hVideoDisplay = NULL;
  120. lpcs->hVideoIn = NULL;
  121. lpcs->sCapDrvCaps.fHasDlgVideoSource = FALSE;
  122. lpcs->sCapDrvCaps.fHasDlgVideoFormat = FALSE;
  123. lpcs->sCapDrvCaps.fHasDlgVideoDisplay = FALSE;
  124. lpcs->sCapDrvCaps.fHasDlgVideoDisplay = FALSE;
  125. lpcs->sCapDrvCaps.hVideoIn = NULL;
  126. lpcs->sCapDrvCaps.hVideoOut = NULL;
  127. lpcs->sCapDrvCaps.hVideoExtIn = NULL;
  128. lpcs->sCapDrvCaps.hVideoExtOut = NULL;
  129. return TRUE;
  130. }
  131. //
  132. // Connect to hardware resources
  133. // Return: TRUE if hardware connected to the stream
  134. //
  135. BOOL CapWinConnectHardware (LPCAPSTREAM lpcs, WORD wDeviceIndex)
  136. {
  137. DWORD dwError;
  138. CHANNEL_CAPS VideoCapsExternalOut;
  139. char ach1[_MAX_CAP_PATH];
  140. char ach2[_MAX_CAP_PATH * 3];
  141. CAPINFOCHUNK cic;
  142. HINSTANCE hInstT;
  143. lpcs->hVideoCapture = NULL;
  144. lpcs->hVideoDisplay = NULL;
  145. lpcs->hVideoIn = NULL;
  146. lpcs->fHardwareConnected = FALSE;
  147. lpcs->fUsingDefaultPalette = TRUE;
  148. lpcs->sCapDrvCaps.fHasDlgVideoSource = FALSE;
  149. lpcs->sCapDrvCaps.fHasDlgVideoFormat = FALSE;
  150. lpcs->sCapDrvCaps.fHasDlgVideoDisplay = FALSE;
  151. lpcs->sCapDrvCaps.wDeviceIndex = wDeviceIndex;
  152. // Clear any existing capture device name chunk
  153. cic.fccInfoID = mmioFOURCC ('I','S','F','T');
  154. cic.lpData = NULL;
  155. cic.cbData = 0;
  156. SetInfoChunk (lpcs, &cic);
  157. // try and open the video hardware!!!
  158. if( !(dwError = videoOpen( &lpcs->hVideoIn, wDeviceIndex, VIDEO_IN ) ) ) {
  159. if( !(dwError = videoOpen( &lpcs->hVideoCapture, wDeviceIndex, VIDEO_EXTERNALIN ) ) ) {
  160. // We don't require the EXTERNALOUT channel,
  161. // but do require EXTERNALIN and IN
  162. videoOpen( &lpcs->hVideoDisplay, wDeviceIndex, VIDEO_EXTERNALOUT );
  163. if( (!dwError) && lpcs->hVideoCapture && lpcs->hVideoIn ) {
  164. lpcs->fHardwareConnected = TRUE;
  165. capInternalGetDriverDesc (wDeviceIndex,
  166. ach1, sizeof (ach1),
  167. ach2, sizeof (ach2));
  168. lstrcat (ach1, ", ");
  169. lstrcat (ach1, ach2);
  170. statusUpdateStatus (lpcs, IDS_CAP_INFO, (LPSTR) ach1);
  171. // Make a string of the current task and capture driver
  172. ach2[0] = '\0';
  173. if (hInstT = GetWindowWord (GetParent (lpcs->hwnd), GWW_HINSTANCE))
  174. GetModuleFileName (hInstT, ach2, sizeof (ach2));
  175. lstrcat (ach2, " -AVICAP- ");
  176. lstrcat (ach2, ach1);
  177. // Set software chunk with name of capture device
  178. if (*ach2) {
  179. cic.lpData = ach2;
  180. cic.cbData = lstrlen(ach2) + 1;
  181. SetInfoChunk (lpcs, &cic);
  182. }
  183. }
  184. }
  185. }
  186. if (dwError)
  187. errorDriverID (lpcs, dwError);
  188. if(!lpcs->fHardwareConnected) {
  189. CapWinDisconnectHardware(lpcs);
  190. }
  191. else {
  192. if (lpcs->hVideoDisplay && videoGetChannelCaps (lpcs->hVideoDisplay,
  193. &VideoCapsExternalOut,
  194. sizeof (CHANNEL_CAPS)) == DV_ERR_OK) {
  195. lpcs->sCapDrvCaps.fHasOverlay = (BOOL)(VideoCapsExternalOut.dwFlags &
  196. (DWORD)VCAPS_OVERLAY);
  197. }
  198. else
  199. lpcs->sCapDrvCaps.fHasOverlay = FALSE;
  200. // if the hardware doesn't support it, make sure we don't enable
  201. if (!lpcs->sCapDrvCaps.fHasOverlay)
  202. lpcs->fOverlayWindow = FALSE;
  203. // Start the external in channel streaming continuously
  204. videoStreamInit (lpcs->hVideoCapture, 0L, 0L, 0L, 0L);
  205. } // end if hardware is available
  206. #if 0
  207. // if we don't have a powerful machine, disable capture
  208. if (GetWinFlags() & (DWORD) WF_CPU286)
  209. CapWinDisconnectHardware(lpcs);
  210. #endif
  211. if (!lpcs->fHardwareConnected){
  212. lpcs->fLiveWindow = FALSE;
  213. lpcs->fOverlayWindow = FALSE;
  214. }
  215. if (lpcs->hVideoIn)
  216. lpcs->sCapDrvCaps.fHasDlgVideoFormat = !videoDialog (lpcs-> hVideoIn,
  217. lpcs-> hwnd, VIDEO_DLG_QUERY);
  218. if (lpcs->hVideoCapture)
  219. lpcs->sCapDrvCaps.fHasDlgVideoSource = !videoDialog (lpcs-> hVideoCapture,
  220. lpcs-> hwnd, VIDEO_DLG_QUERY);
  221. if (lpcs->hVideoDisplay)
  222. lpcs->sCapDrvCaps.fHasDlgVideoDisplay = !videoDialog (lpcs-> hVideoDisplay,
  223. lpcs-> hwnd, VIDEO_DLG_QUERY);
  224. lpcs->sCapDrvCaps.hVideoIn = lpcs->hVideoIn;
  225. lpcs->sCapDrvCaps.hVideoOut = NULL;
  226. lpcs->sCapDrvCaps.hVideoExtIn = lpcs->hVideoCapture;
  227. lpcs->sCapDrvCaps.hVideoExtOut = lpcs->hVideoDisplay;
  228. return lpcs->fHardwareConnected;
  229. }
  230. //
  231. // Creates a child window of the capture class
  232. // Normally:
  233. // Set lpszWindowName to NULL
  234. // Set dwStyle to WS_CHILD | WS_VISIBLE
  235. // Set hmenu to a unique child id
  236. HWND VFWAPI capCreateCaptureWindow (
  237. LPCSTR lpszWindowName,
  238. DWORD dwStyle,
  239. int x, int y, int nWidth, int nHeight,
  240. HWND hwndParent, int nID)
  241. {
  242. DWORD fdwFlags;
  243. #ifndef WS_EX_LEFTSCROLLBAR
  244. #define WS_EX_LEFTSCROLLBAR 0
  245. #define WS_EX_RIGHT 0
  246. #define WS_EX_RTLREADING 0
  247. #endif
  248. RegisterCaptureClass(ghInst);
  249. fdwFlags = gfIsRTL ? WS_EX_LEFTSCROLLBAR | WS_EX_RIGHT | WS_EX_RTLREADING : 0;
  250. return CreateWindowEx(fdwFlags,
  251. szCaptureWindowClass,
  252. lpszWindowName,
  253. dwStyle,
  254. x, y, nWidth, nHeight,
  255. hwndParent, (HMENU) nID,
  256. ghInst,
  257. NULL);
  258. }
  259. int CALLBACK LibMain(HINSTANCE hinst, WORD wDataSeg, WORD cbHeap,
  260. LPSTR lpszCmdLine )
  261. {
  262. char ach[2];
  263. ghInst = hinst;
  264. LoadString(ghInst, IDS_CAP_RTL, ach, sizeof(ach));
  265. gfIsRTL = ach[0] == '1';
  266. return TRUE;
  267. }
  268. int FAR PASCAL WEP(int i)
  269. {
  270. return 1;
  271. }