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.

126 lines
3.2 KiB

  1. // Copyright (c) 1997 Microsoft Corporation. All Rights Reserved.
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include "ddraw.h"
  5. #include "mmstream.h"
  6. #include "amstream.h"
  7. #include "ddstream.h"
  8. #define RELEASE(x) if (x) (x)->Release();
  9. #define CHECK_ERROR(x) \
  10. if (FAILED(hr = (x))) { \
  11. printf(#x " failed with HRESULT(0x%8.8X)\n", hr); \
  12. goto Exit; \
  13. }
  14. HRESULT OpenMMStream(const char * pszFileName, IDirectDraw *pDD, IMultiMediaStream **ppMMStream)
  15. {
  16. *ppMMStream = NULL;
  17. IAMMultiMediaStream *pAMStream;
  18. HRESULT hr;
  19. CHECK_ERROR(CoCreateInstance(CLSID_AMMultiMediaStream, NULL, CLSCTX_INPROC_SERVER,
  20. IID_IAMMultiMediaStream, (void **)&pAMStream));
  21. CHECK_ERROR(pAMStream->Initialize(STREAMTYPE_READ, 0, NULL));
  22. CHECK_ERROR(pAMStream->AddMediaStream(pDD, &MSPID_PrimaryVideo, 0, NULL));
  23. CHECK_ERROR(pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL));
  24. WCHAR wPath[MAX_PATH];
  25. MultiByteToWideChar(CP_ACP, 0, pszFileName, -1, wPath, sizeof(wPath)/sizeof(wPath[0]));
  26. CHECK_ERROR(pAMStream->OpenFile(wPath, 0));
  27. *ppMMStream = pAMStream;
  28. pAMStream->AddRef();
  29. Exit:
  30. if (pAMStream == NULL) {
  31. printf("Could not create a CLSID_MultiMediaStream object\n"
  32. "Check you have run regsvr32 amstream.dll\n");
  33. }
  34. RELEASE(pAMStream);
  35. return hr;
  36. }
  37. HRESULT RenderStreamToSurface(IDirectDraw *pDD, IDirectDrawSurface *pPrimary,
  38. IMultiMediaStream *pMMStream)
  39. {
  40. HRESULT hr;
  41. IMediaStream *pPrimaryVidStream = NULL;
  42. IDirectDrawMediaStream *pDDStream = NULL;
  43. IDirectDrawSurface *pSurface = NULL;
  44. IDirectDrawStreamSample *pSample = NULL;
  45. RECT rect;
  46. CHECK_ERROR(pMMStream->GetMediaStream(MSPID_PrimaryVideo, &pPrimaryVidStream));
  47. CHECK_ERROR(pPrimaryVidStream->QueryInterface(IID_IDirectDrawMediaStream, (void **)&pDDStream));
  48. CHECK_ERROR(pDDStream->CreateSample(NULL, NULL, 0, &pSample));
  49. CHECK_ERROR(pSample->GetSurface(&pSurface, &rect));
  50. CHECK_ERROR(pMMStream->SetState(STREAMSTATE_RUN));
  51. while (true) {
  52. if (pSample->Update(0, NULL, NULL, 0) != S_OK) {
  53. break;
  54. }
  55. pPrimary->Blt(&rect, pSurface, &rect, DDBLT_WAIT, NULL);
  56. }
  57. Exit:
  58. RELEASE(pPrimaryVidStream);
  59. RELEASE(pDDStream);
  60. RELEASE(pSample);
  61. RELEASE(pSurface);
  62. return hr;
  63. }
  64. int _CRTAPI1
  65. main(
  66. int argc,
  67. char *argv[]
  68. )
  69. {
  70. if (argc < 2) {
  71. printf("Usage : simple movie.ext\n");
  72. exit(0);
  73. }
  74. CoInitialize(NULL);
  75. IDirectDraw *pDD;
  76. HRESULT hr = DirectDrawCreate(NULL, &pDD, NULL);
  77. if (SUCCEEDED(hr)) {
  78. DDSURFACEDESC ddsd;
  79. IDirectDrawSurface *pPrimarySurface;
  80. pDD->SetCooperativeLevel(GetDesktopWindow(), DDSCL_NORMAL);
  81. ddsd.dwSize = sizeof(ddsd);
  82. ddsd.dwFlags = DDSD_CAPS;
  83. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  84. hr = pDD->CreateSurface(&ddsd, &pPrimarySurface, NULL);
  85. if (SUCCEEDED(hr)) {
  86. IMultiMediaStream *pMMStream;
  87. hr = OpenMMStream(argv[1], pDD, &pMMStream);
  88. if (SUCCEEDED(hr)) {
  89. RenderStreamToSurface(pDD, pPrimarySurface, pMMStream);
  90. pMMStream->Release();
  91. }
  92. pPrimarySurface->Release();
  93. }
  94. pDD->Release();
  95. } else {
  96. printf("Could not open DirectDraw - check it is installed\n");
  97. }
  98. CoUninitialize();
  99. return 0;
  100. }