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.

125 lines
3.3 KiB

  1. // Copyright (c) 1997 Microsoft Corporation. All Rights Reserved.
  2. #define INIT_GUID
  3. #define INTTGUIDS
  4. #define INITGUID
  5. #define INIT_GUIDS
  6. #include <windows.h>
  7. #include <stdio.h>
  8. #include "ddraw.h"
  9. #include "mmstream.h"
  10. #include "amstream.h"
  11. #include "ddstream.h"
  12. #define RELEASE(x) if (x) (x)->Release();
  13. #define CHECK_ERROR(x) if (FAILED(hr = (x))) goto Exit;
  14. HRESULT RenderFileToMMStream(const char * pszFileName, IMultiMediaStream **ppMMStream, IDirectDraw *pDD)
  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, 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. // CHECK_ERROR(pAMStream->SetState(STREAMSTATE_RUN));
  28. *ppMMStream = pAMStream;
  29. pAMStream->AddRef();
  30. Exit:
  31. RELEASE(pAMStream);
  32. return hr;
  33. }
  34. HRESULT RenderStreamToSurface(IDirectDraw *pDD, IDirectDrawSurface *pPrimary, IMultiMediaStream *pMMStream)
  35. {
  36. HRESULT hr;
  37. IMediaStream *pPrimaryVidStream = NULL;
  38. IDirectDrawMediaStream *pDDStream = NULL;
  39. IDirectDrawSurface *pSurface = NULL;
  40. IDirectDrawStreamSample *pSample = NULL;
  41. CHECK_ERROR(pMMStream->GetMediaStream(MSPID_PrimaryVideo, &pPrimaryVidStream));
  42. CHECK_ERROR(pPrimaryVidStream->QueryInterface(IID_IDirectDrawMediaStream, (void **)&pDDStream));
  43. DDSURFACEDESC ddsd;
  44. ddsd.dwSize = sizeof(ddsd);
  45. CHECK_ERROR(pDDStream->GetFormat(&ddsd, NULL, NULL));
  46. RECT rect;
  47. rect.top = rect.left = 0;
  48. rect.bottom = ddsd.dwHeight;
  49. rect.right = ddsd.dwWidth;
  50. CHECK_ERROR(pDD->CreateSurface(&ddsd, &pSurface, NULL));
  51. CHECK_ERROR(pDDStream->CreateSample(pSurface, NULL, 0, &pSample));
  52. while (true) {
  53. if (pSample->Update(0, NULL, NULL, 0) != S_OK) {
  54. break;
  55. }
  56. pPrimary->Blt(&rect, pSurface, &rect, DDBLT_WAIT, NULL);
  57. }
  58. Exit:
  59. RELEASE(pPrimaryVidStream);
  60. RELEASE(pDDStream);
  61. RELEASE(pSample);
  62. RELEASE(pSurface);
  63. return hr;
  64. }
  65. int _CRTAPI1
  66. main(
  67. int argc,
  68. char *argv[]
  69. )
  70. {
  71. if (argc < 2) {
  72. printf("Usage : mmtest foo.bar\n");
  73. exit(0);
  74. }
  75. CoInitialize(NULL);
  76. IDirectDraw *pDD;
  77. HRESULT hr = DirectDrawCreate(NULL, &pDD, NULL);
  78. if (SUCCEEDED(hr)) {
  79. DDSURFACEDESC ddsd;
  80. IDirectDrawSurface *pPrimarySurface;
  81. pDD->SetCooperativeLevel(GetDesktopWindow(), DDSCL_NORMAL);
  82. ddsd.dwSize = sizeof(ddsd);
  83. ddsd.dwFlags = DDSD_CAPS;
  84. ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
  85. hr = pDD->CreateSurface(&ddsd, &pPrimarySurface, NULL);
  86. if (SUCCEEDED(hr)) {
  87. IMultiMediaStream *pMMStream;
  88. hr = RenderFileToMMStream(argv[1], &pMMStream, pDD);
  89. if (SUCCEEDED(hr)) {
  90. RenderStreamToSurface(pDD, pPrimarySurface, pMMStream);
  91. pMMStream->Release();
  92. }
  93. pPrimarySurface->Release();
  94. }
  95. pDD->Release();
  96. }
  97. CoUninitialize();
  98. return 0;
  99. }