common_utils_windows.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*****************************************************************************
  2. INTEL CORPORATION PROPRIETARY INFORMATION
  3. This software is supplied under the terms of a license agreement or
  4. nondisclosure agreement with Intel Corporation and may not be copied
  5. or disclosed except in accordance with the terms of that agreement.
  6. Copyright(c) 2005-2014 Intel Corporation. All Rights Reserved.
  7. *****************************************************************************/
  8. #include "common_utils.h"
  9. // ATTENTION: If D3D surfaces are used, DX9_D3D or DX11_D3D must be set in project settings or hardcoded here
  10. #ifdef DX9_D3D
  11. #include "common_directx.h"
  12. #elif DX11_D3D
  13. #include "common_directx11.h"
  14. #endif
  15. /* =======================================================
  16. * Windows implementation of OS-specific utility functions
  17. */
  18. mfxStatus Initialize(mfxIMPL impl, mfxVersion ver, MFXVideoSession* pSession, mfxFrameAllocator* pmfxAllocator, bool bCreateSharedHandles)
  19. {
  20. bCreateSharedHandles; // (Hugh) Currently unused
  21. pmfxAllocator; // (Hugh) Currently unused
  22. mfxStatus sts = MFX_ERR_NONE;
  23. // If mfxFrameAllocator is provided it means we need to setup DirectX device and memory allocator
  24. if (pmfxAllocator) {
  25. // Initialize Intel Media SDK Session
  26. sts = pSession->Init(impl, &ver);
  27. MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
  28. // Create DirectX device context
  29. mfxHDL deviceHandle;
  30. sts = CreateHWDevice(*pSession, &deviceHandle, NULL, bCreateSharedHandles);
  31. MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
  32. // Provide device manager to Media SDK
  33. sts = pSession->SetHandle(DEVICE_MGR_TYPE, deviceHandle);
  34. MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
  35. pmfxAllocator->pthis = *pSession; // We use Media SDK session ID as the allocation identifier
  36. pmfxAllocator->Alloc = simple_alloc;
  37. pmfxAllocator->Free = simple_free;
  38. pmfxAllocator->Lock = simple_lock;
  39. pmfxAllocator->Unlock = simple_unlock;
  40. pmfxAllocator->GetHDL = simple_gethdl;
  41. // Since we are using video memory we must provide Media SDK with an external allocator
  42. sts = pSession->SetFrameAllocator(pmfxAllocator);
  43. MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
  44. }
  45. else
  46. {
  47. // Initialize Intel Media SDK Session
  48. sts = pSession->Init(impl, &ver);
  49. MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);
  50. }
  51. return sts;
  52. }
  53. void Release()
  54. {
  55. #if defined(DX9_D3D) || defined(DX11_D3D)
  56. CleanupHWDevice();
  57. #endif
  58. }
  59. void mfxGetTime(mfxTime* timestamp)
  60. {
  61. QueryPerformanceCounter(timestamp);
  62. }
  63. double TimeDiffMsec(mfxTime tfinish, mfxTime tstart)
  64. {
  65. static LARGE_INTEGER tFreq = { 0 };
  66. if (!tFreq.QuadPart) QueryPerformanceFrequency(&tFreq);
  67. double freq = (double)tFreq.QuadPart;
  68. return 1000.0 * ((double)tfinish.QuadPart - (double)tstart.QuadPart) / freq;
  69. }
  70. /* (Hugh) Functions currently unused */
  71. #if 0
  72. void ClearYUVSurfaceVMem(mfxMemId memId)
  73. {
  74. #if defined(DX9_D3D) || defined(DX11_D3D)
  75. ClearYUVSurfaceD3D(memId);
  76. #endif
  77. }
  78. void ClearRGBSurfaceVMem(mfxMemId memId)
  79. {
  80. #if defined(DX9_D3D) || defined(DX11_D3D)
  81. ClearRGBSurfaceD3D(memId);
  82. #endif
  83. }
  84. #endif