Source code of Windows XP (NT5)
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.

163 lines
4.5 KiB

  1. /* Copyright (c) 1997 Microsoft Corporation. All Rights Reserved. */
  2. #include "foxbear.h"
  3. BOOL bMovie;
  4. BOOL bCamera;
  5. WCHAR wszMovie[100];
  6. #define RELEASE(x) if ((x) != NULL) (x)->lpVtbl->Release(x);
  7. #ifdef DEBUG
  8. HRESULT __inline check_error(HRESULT hr, LPSTR psz)
  9. {
  10. if (FAILED(hr)) {
  11. char sz[200];
  12. wsprintf(sz, "%s failed code 0x%8.8X\n", psz, hr);
  13. OutputDebugString(sz);
  14. }
  15. return hr;
  16. }
  17. #else
  18. HRESULT __inline check_error(HRESULT hr, LPSTR psz)
  19. {
  20. UNREFERENCED_PARAMETER(psz);
  21. return hr;
  22. }
  23. #endif
  24. #define CHECK_ERROR(x) if (FAILED(hr = check_error(x, #x))) goto Exit;
  25. HRESULT FindCaptureDevice(IMoniker **ppMoniker)
  26. {
  27. ICreateDevEnum *pCreateDevEnum;
  28. IEnumMoniker *pEm;
  29. ULONG cFetched;
  30. HRESULT hr = CoCreateInstance(
  31. &CLSID_SystemDeviceEnum,
  32. NULL,
  33. CLSCTX_INPROC_SERVER,
  34. &IID_ICreateDevEnum,
  35. (void**)&pCreateDevEnum);
  36. if (FAILED(hr))
  37. return hr;
  38. hr = ICreateDevEnum_CreateClassEnumerator(pCreateDevEnum,
  39. &CLSID_CVidCapClassManager,
  40. &pEm,
  41. 0);
  42. ICreateDevEnum_Release(pCreateDevEnum);
  43. if (FAILED(hr)) {
  44. return hr;
  45. }
  46. hr = IEnumMoniker_Next(pEm, 1, ppMoniker, &cFetched);
  47. IEnumMoniker_Release(pEm);
  48. return S_OK == hr ? hr : E_FAIL;
  49. }
  50. BOOL CreateVideoSource(IDirectDrawStreamSample **ppVideoSource, WCHAR * szFileName)
  51. {
  52. HRESULT hr;
  53. IAMMultiMediaStream *pAMStream = NULL;
  54. IMediaStream *pVideoStream = NULL;
  55. IDirectDrawMediaStream *pDDVideoStream = NULL;
  56. IDirectDrawSurface *pSurface = NULL;
  57. IMoniker *pMoniker = NULL;
  58. IDirectDrawPalette *pPalette = NULL;
  59. IBindCtx *pCtx = NULL;
  60. DDSURFACEDESC ddsd;
  61. CHECK_ERROR(CoCreateInstance(&CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER,
  62. &IID_IAMMultiMediaStream, (void **)&pAMStream));
  63. CHECK_ERROR(IAMMultiMediaStream_Initialize(pAMStream, STREAMTYPE_READ, 0, NULL));
  64. CHECK_ERROR(IAMMultiMediaStream_AddMediaStream(pAMStream, (IUnknown*)lpDD, &MSPID_PrimaryVideo, 0, &pVideoStream));
  65. CHECK_ERROR(IAMMultiMediaStream_AddMediaStream(pAMStream, NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL));
  66. if (bCamera) {
  67. CreateBindCtx(0, &pCtx);
  68. CHECK_ERROR(FindCaptureDevice(&pMoniker));
  69. CHECK_ERROR(IAMMultiMediaStream_OpenMoniker(
  70. pAMStream, pCtx, pMoniker, AMMSF_RENDERTOEXISTING));
  71. } else {
  72. CHECK_ERROR(IAMMultiMediaStream_OpenFile(
  73. pAMStream, bMovie ? wszMovie : szFileName, AMMSF_RENDERTOEXISTING));
  74. }
  75. CHECK_ERROR(IMediaStream_QueryInterface(pVideoStream, &IID_IDirectDrawMediaStream, (void **)&pDDVideoStream));
  76. ddsd.dwSize = sizeof(ddsd);
  77. CHECK_ERROR(IDirectDrawMediaStream_GetFormat(pDDVideoStream, &ddsd, NULL, NULL, NULL));
  78. pSurface = DDCreateSurface(ddsd.dwWidth, ddsd.dwHeight, FALSE, TRUE);
  79. hr = IDirectDrawSurface_GetPalette(lpFrontBuffer, &pPalette);
  80. if (SUCCEEDED(hr)) {
  81. CHECK_ERROR(IDirectDrawSurface_SetPalette(pSurface, pPalette));
  82. }
  83. CHECK_ERROR(IDirectDrawMediaStream_CreateSample(pDDVideoStream, pSurface, NULL, DDSFF_PROGRESSIVERENDER, ppVideoSource));
  84. CHECK_ERROR(IAMMultiMediaStream_SetState(pAMStream, STREAMSTATE_RUN));
  85. CHECK_ERROR(IDirectDrawStreamSample_Update(*ppVideoSource, SSUPDATE_ASYNC | SSUPDATE_CONTINUOUS, NULL, NULL, 0));
  86. Exit:
  87. RELEASE(pAMStream);
  88. RELEASE(pVideoStream);
  89. RELEASE(pDDVideoStream);
  90. RELEASE(pSurface);
  91. RELEASE(pMoniker);
  92. RELEASE(pPalette);
  93. RELEASE(pCtx);
  94. return hr == S_OK ? TRUE : FALSE;
  95. }
  96. BOOL DisplayVideoSource(IDirectDrawStreamSample *pVideoSource)
  97. {
  98. if (pVideoSource) {
  99. RECT rc;
  100. IDirectDrawSurface *pSurface;
  101. HRESULT CompStatus = IDirectDrawStreamSample_CompletionStatus(pVideoSource, COMPSTAT_NOUPDATEOK | COMPSTAT_WAIT, INFINITE);
  102. if (SUCCEEDED(CompStatus)) {
  103. HRESULT hr = IDirectDrawStreamSample_GetSurface(pVideoSource, &pSurface, &rc);
  104. if (hr == S_OK) {
  105. IDirectDrawSurface_BltFast(lpBackBuffer, 240, 180,
  106. pSurface, &rc, DDBLTFAST_SRCCOLORKEY | DDBLTFAST_WAIT);
  107. IDirectDrawSurface_Release(pSurface);
  108. }
  109. }
  110. if (CompStatus == MS_S_ENDOFSTREAM) {
  111. IMediaStream *pStream;
  112. IMultiMediaStream *pMMStream;
  113. IDirectDrawStreamSample_GetMediaStream(pVideoSource, &pStream);
  114. IMediaStream_GetMultiMediaStream(pStream, &pMMStream);
  115. IMultiMediaStream_Seek(pMMStream, 0);
  116. IMediaStream_Release(pStream);
  117. IMultiMediaStream_Release(pMMStream);
  118. }
  119. IDirectDrawStreamSample_Update(pVideoSource, SSUPDATE_ASYNC | SSUPDATE_CONTINUOUS, NULL, NULL, 0);
  120. return TRUE;
  121. } else {
  122. return FALSE;
  123. }
  124. }