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.

455 lines
10 KiB

  1. #include "precomp.h"
  2. extern HANDLE g_hVidEventHalfDuplex;
  3. ///////////////////////////////////////////////////////
  4. //
  5. // Public methods
  6. //
  7. VideoInControl::VideoInControl ( void )
  8. {
  9. }
  10. VideoInControl::~VideoInControl ( void )
  11. {
  12. }
  13. VideoOutControl::VideoOutControl ( void )
  14. {
  15. }
  16. VideoOutControl::~VideoOutControl ( void )
  17. {
  18. }
  19. HRESULT VideoInControl::Initialize ( MEDIACTRLINIT * p )
  20. {
  21. HRESULT hr = DPR_SUCCESS;
  22. DEBUGMSG (ZONE_VERBOSE, ("VideoInControl::Initialize: enter.\r\n"));
  23. m_dwFlags = p->dwFlags;
  24. m_hEvent = NULL;
  25. m_uDuration = MC_DEF_DURATION;
  26. m_uTimeout = MC_DEF_RECORD_TIMEOUT;
  27. m_uPrefeed = MC_DEF_RECORD_BUFS;
  28. //Request the max, and let QOS throttle us back
  29. m_FPSRequested = m_FPSMax = 2997;
  30. DEBUGMSG (ZONE_VERBOSE, ("VideoInControl::Initialize: exit, hr=0x%lX\r\n", hr));
  31. return hr;
  32. }
  33. HRESULT VideoOutControl::Initialize ( MEDIACTRLINIT * p )
  34. {
  35. HRESULT hr = DPR_SUCCESS;
  36. DEBUGMSG (ZONE_VERBOSE, ("VideoOutControl::Initialize: enter.\r\n"));
  37. if ((hr =MediaControl::Initialize( p)) != DPR_SUCCESS)
  38. return hr;
  39. m_uTimeout = MC_DEF_PLAY_TIMEOUT;
  40. m_uPrefeed = MC_DEF_PLAY_BUFS;
  41. DEBUGMSG (ZONE_VERBOSE, ("VideoOutControl::Initialize: exit, hr=0x%lX\r\n", hr));
  42. return hr;
  43. }
  44. HRESULT VideoInControl::Configure ( MEDIACTRLCONFIG * p )
  45. {
  46. UINT uBlockAlign;
  47. DEBUGMSG (ZONE_VERBOSE, ("VideoInControl::Configure: enter.\r\n"));
  48. m_hStrm = p->hStrm;
  49. m_uDevId = p->uDevId;
  50. m_pDevFmt = p->pDevFmt;
  51. if (m_pDevFmt == NULL) return DPR_INVALID_PARAMETER;
  52. if ((m_uDuration = p->uDuration) == MC_USING_DEFAULT)
  53. {
  54. m_cbSizeDevData = ((VIDEOFORMATEX *) m_pDevFmt)->nAvgBytesPerSec * p->cbSamplesPerPkt
  55. /((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec;
  56. m_uDuration = p->cbSamplesPerPkt*1000 /((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec;
  57. } else {
  58. // roughly calculate the buffer size based on 20ms
  59. m_cbSizeDevData = ((VIDEOFORMATEX *) m_pDevFmt)->nAvgBytesPerSec
  60. * m_uDuration / 1000;
  61. // need to be on the block alignment boundary
  62. uBlockAlign = ((VIDEOFORMATEX *) m_pDevFmt)->nBlockAlign;
  63. m_cbSizeDevData = ((m_cbSizeDevData + uBlockAlign - 1) / uBlockAlign)
  64. * uBlockAlign;
  65. }
  66. // at configuration we set the max. frame rate
  67. if (m_uDuration)
  68. m_FPSMax = 100000 / m_uDuration; // convert msec/frame to fps
  69. m_FPSRequested = ((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec * 100;
  70. DEBUGMSG (ZONE_VERBOSE, ("VideoInControl::Configure: exit\r\n"));
  71. return DPR_SUCCESS;
  72. }
  73. HRESULT VideoOutControl::Configure ( MEDIACTRLCONFIG * p )
  74. {
  75. UINT uBlockAlign;
  76. DEBUGMSG (ZONE_VERBOSE, ("VideoOutControl::Configure: enter.\r\n"));
  77. m_hStrm = p->hStrm;
  78. m_uDevId = p->uDevId;
  79. m_pDevFmt = p->pDevFmt;
  80. if (m_pDevFmt == NULL) return DPR_INVALID_PARAMETER;
  81. if ((m_uDuration = p->uDuration) == MC_USING_DEFAULT)
  82. {
  83. m_cbSizeDevData = ((VIDEOFORMATEX *) m_pDevFmt)->nAvgBytesPerSec * p->cbSamplesPerPkt
  84. /((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec;
  85. m_uDuration = p->cbSamplesPerPkt*1000 /((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec;
  86. } else {
  87. // roughly calculate the buffer size based on 20ms
  88. m_cbSizeDevData = ((VIDEOFORMATEX *) m_pDevFmt)->nAvgBytesPerSec
  89. * m_uDuration / 1000;
  90. // need to be on the block alignment boundary
  91. uBlockAlign = ((VIDEOFORMATEX *) m_pDevFmt)->nBlockAlign;
  92. m_cbSizeDevData = ((m_cbSizeDevData + uBlockAlign - 1) / uBlockAlign)
  93. * uBlockAlign;
  94. }
  95. DEBUGMSG (ZONE_VERBOSE, ("VideoOutControl::Configure: exit\r\n"));
  96. return DPR_SUCCESS;
  97. }
  98. HRESULT VideoInControl::Open ( void )
  99. {
  100. HRESULT hr;
  101. FINDCAPTUREDEVICE fcd;
  102. HFRAMEBUF hbuf;
  103. DWORD dwSize, i;
  104. LPBITMAPINFOHEADER lpbi;
  105. int iWidth, iHeight;
  106. char szName[MAX_PATH];
  107. fcd.dwSize = sizeof (FINDCAPTUREDEVICE);
  108. if (m_uDevId == -1)
  109. FindFirstCaptureDevice(&fcd, NULL);
  110. else
  111. {
  112. if (!FindFirstCaptureDeviceByIndex(&fcd, m_uDevId))
  113. {
  114. // Update m_uDevId with new device index
  115. if (FindFirstCaptureDevice(&fcd, NULL))
  116. m_uDevId = fcd.nDeviceIndex;
  117. }
  118. }
  119. #ifndef NO_QCCOLOR_HACK
  120. if (fcd.szDeviceName[0] && lstrcmpi(fcd.szDeviceName, "qccolor.drv") == 0) {
  121. // this hack clears out the [conf] section of qccolor.ini to prevent problems in
  122. // setformat when the driver initializes to an unknown format that is recorded in
  123. // the ini file.
  124. dwSize = GetModuleFileName(NULL, szName, sizeof(szName));
  125. for (i = dwSize-1; i; i--)
  126. if (szName[i] == '\\' || szName[i] == ':')
  127. break;
  128. i++;
  129. MoveMemory (szName, &szName[i], dwSize-i+1);
  130. dwSize -= i;
  131. for (i = dwSize-1; i; i--)
  132. if (szName[i] == '.') {
  133. szName[i] = 0;
  134. break;
  135. }
  136. dwSize = 0;
  137. WritePrivateProfileSection(szName, (LPCTSTR)&dwSize, "QCCOLOR.INI");
  138. }
  139. #endif
  140. if (!(m_hDev = (DPHANDLE)OpenCaptureDevice(fcd.nDeviceIndex)) && m_uDevId != -1) {
  141. DEBUGMSG (1, ("MediaVidCtrl::Open: OpenCaptureDevice failed, trying VIDEO_MAPPER\r\n" ));
  142. FindFirstCaptureDevice(&fcd, NULL);
  143. if (m_hDev = (DPHANDLE)OpenCaptureDevice(fcd.nDeviceIndex))
  144. m_uDevId = (UINT) -1; // use VIDEO_MAPPER next time
  145. }
  146. if (m_hDev) {
  147. hr = DPR_SUCCESS;
  148. } else {
  149. DEBUGMSG (1, ("MediaVidCtrl::Open: OpenCaptureDevice failed\r\n" ));
  150. hr = DPR_CANT_OPEN_DEV;
  151. }
  152. return hr;
  153. }
  154. HRESULT VideoOutControl::Open ( void )
  155. {
  156. return DPR_SUCCESS;
  157. }
  158. HRESULT VideoInControl::Close ( void )
  159. {
  160. HRESULT hr = DPR_INVALID_PLATFORM;
  161. if (m_hDev)
  162. {
  163. CloseCaptureDevice((HCAPDEV)m_hDev);
  164. hr = DPR_SUCCESS;
  165. }
  166. else
  167. {
  168. hr = DPR_INVALID_HANDLE;
  169. }
  170. m_hDev = NULL;
  171. return hr;
  172. }
  173. HRESULT VideoOutControl::Close ( void )
  174. {
  175. return DPR_SUCCESS;
  176. }
  177. HRESULT VideoInControl::Start ( void )
  178. {
  179. return DPR_SUCCESS;
  180. }
  181. HRESULT VideoOutControl::Start ( void )
  182. {
  183. return DPR_SUCCESS;
  184. }
  185. HRESULT VideoInControl::Stop ( void )
  186. {
  187. return DPR_SUCCESS;
  188. }
  189. HRESULT VideoOutControl::Stop ( void )
  190. {
  191. return DPR_INVALID_PARAMETER;
  192. }
  193. HRESULT VideoInControl::Reset ( void )
  194. {
  195. return VideoInControl::Stop();
  196. }
  197. HRESULT VideoOutControl::Reset ( void )
  198. {
  199. return DPR_SUCCESS;
  200. }
  201. HRESULT VideoInControl::DisplayDriverDialog (HWND hwnd, DWORD dwDlgId)
  202. {
  203. HRESULT hr = DPR_SUCCESS;
  204. DWORD dwRes;
  205. PDWORD pdwMask;
  206. if (m_hDev) {
  207. if (dwDlgId & CAPTURE_DIALOG_SOURCE)
  208. dwDlgId = CAPDEV_DIALOG_SOURCE;
  209. else
  210. dwDlgId = CAPDEV_DIALOG_IMAGE;
  211. #if 1
  212. if (!CaptureDeviceDialog(m_hDev, hwnd, dwDlgId, NULL)) {
  213. #else
  214. if (!CaptureDeviceDialog(m_hDev, hwnd, dwDlgId, &((VIDEOFORMATEX *)m_pDevFmt)->bih)) {
  215. #endif
  216. dwRes = GetLastError();
  217. if (dwRes == ERROR_DCAP_DIALOG_FORMAT || dwRes == ERROR_DCAP_DIALOG_STREAM) {
  218. DEBUGMSG (1, ("MediaVidCtrl::Open: CaptureDeviceDialog failed\r\n" ));
  219. hr = DPR_CONVERSION_FAILED; // user did something in the dialog that caused a problem
  220. }
  221. else
  222. hr = DPR_INVALID_PARAMETER;
  223. }
  224. }
  225. else
  226. hr = DPR_INVALID_HANDLE;
  227. return hr;
  228. }
  229. HRESULT VideoInControl::SetProp ( DWORD dwPropId, DWORD_PTR dwPropVal )
  230. {
  231. HRESULT hr = DPR_SUCCESS;
  232. UINT ms;
  233. switch (dwPropId)
  234. {
  235. case MC_PROP_TIMEOUT:
  236. m_uTimeout = (DWORD)dwPropVal;
  237. break;
  238. case MC_PROP_PREFEED:
  239. m_uPrefeed = (DWORD)dwPropVal;
  240. break;
  241. case MC_PROP_VIDEO_FRAME_RATE:
  242. case MC_PROP_MAX_VIDEO_FRAME_RATE:
  243. break;
  244. default:
  245. hr = MediaControl::SetProp(dwPropId, dwPropVal );
  246. break;
  247. }
  248. return hr;
  249. }
  250. HRESULT VideoOutControl::SetProp ( DWORD dwPropId, DWORD_PTR dwPropVal )
  251. {
  252. HRESULT hr = DPR_SUCCESS;
  253. switch (dwPropId)
  254. {
  255. case MC_PROP_TIMEOUT:
  256. m_uTimeout = (DWORD)dwPropVal;
  257. break;
  258. case MC_PROP_PREFEED:
  259. m_uPrefeed = (DWORD)dwPropVal;
  260. break;
  261. default:
  262. hr = MediaControl::SetProp(dwPropId, dwPropVal );
  263. break;
  264. }
  265. return hr;
  266. }
  267. HRESULT VideoInControl::GetProp ( DWORD dwPropId, PDWORD_PTR pdwPropVal )
  268. {
  269. HRESULT hr = DPR_SUCCESS;
  270. DWORD dwMask;
  271. if (pdwPropVal)
  272. {
  273. switch (dwPropId)
  274. {
  275. case MC_PROP_TIMEOUT:
  276. *pdwPropVal = m_uTimeout;
  277. break;
  278. case MC_PROP_PREFEED:
  279. *pdwPropVal = m_uPrefeed;
  280. break;
  281. case MC_PROP_SPP:
  282. // *pdwPropVal = (DWORD) ((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec
  283. // * m_uDuration / 100UL;
  284. *pdwPropVal = m_cbSizeDevData * (DWORD) ((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec
  285. /(DWORD) ((VIDEOFORMATEX *) m_pDevFmt)->nAvgBytesPerSec;
  286. break;
  287. case MC_PROP_SPS:
  288. *pdwPropVal = (DWORD) ((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec;
  289. break;
  290. case MC_PROP_VIDEO_FRAME_RATE:
  291. case MC_PROP_MAX_VIDEO_FRAME_RATE:
  292. break;
  293. case MC_PROP_VFW_DIALOGS:
  294. *pdwPropVal = 0;
  295. if (vcmGetDevCapsDialogs(m_uDevId, &dwMask) == (MMRESULT)MMSYSERR_NOERROR) {
  296. if (dwMask & SOURCE_DLG_ON)
  297. *pdwPropVal = CAPTURE_DIALOG_SOURCE;
  298. if (dwMask & FORMAT_DLG_ON)
  299. *pdwPropVal |= CAPTURE_DIALOG_FORMAT;
  300. }
  301. break;
  302. default:
  303. hr = MediaControl::GetProp( dwPropId, pdwPropVal );
  304. break;
  305. }
  306. }
  307. else
  308. {
  309. hr = DPR_INVALID_PARAMETER;
  310. }
  311. return hr;
  312. }
  313. HRESULT VideoOutControl::GetProp ( DWORD dwPropId, PDWORD_PTR pdwPropVal )
  314. {
  315. HRESULT hr = DPR_SUCCESS;
  316. if (pdwPropVal)
  317. {
  318. switch (dwPropId)
  319. {
  320. case MC_PROP_TIMEOUT:
  321. *pdwPropVal = m_uTimeout;
  322. break;
  323. case MC_PROP_PREFEED:
  324. *pdwPropVal = m_uPrefeed;
  325. break;
  326. case MC_PROP_SPP:
  327. // *pdwPropVal = (DWORD) ((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec
  328. // * m_uDuration / 100UL;
  329. *pdwPropVal = m_cbSizeDevData * (DWORD) ((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec
  330. /(DWORD) ((VIDEOFORMATEX *) m_pDevFmt)->nAvgBytesPerSec;
  331. break;
  332. case MC_PROP_SPS:
  333. *pdwPropVal = (DWORD) ((VIDEOFORMATEX *) m_pDevFmt)->nSamplesPerSec;
  334. default:
  335. hr = MediaControl::GetProp( dwPropId, pdwPropVal );
  336. break;
  337. }
  338. }
  339. else
  340. {
  341. hr = DPR_INVALID_PARAMETER;
  342. }
  343. return hr;
  344. }
  345.