device_directx9.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #if defined(_WIN32) || defined(_WIN64)
  3. #include "common_utils.h"
  4. #pragma warning(disable : 4201)
  5. #include <initguid.h>
  6. #include <d3d9.h>
  7. #include <dxva2api.h>
  8. #include <dxva.h>
  9. #include <windows.h>
  10. #define VIDEO_MAIN_FORMAT D3DFMT_YUY2
  11. class IGFXS3DControl;
  12. /// Base class for hw device
  13. class CHWDevice {
  14. public:
  15. virtual ~CHWDevice() {}
  16. /** Initializes device for requested processing.
  17. @param[in] hWindow Window handle to bundle device to.
  18. @param[in] nViews Number of views to process.
  19. @param[in] nAdapterNum Number of adapter to use
  20. */
  21. virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews,
  22. mfxU32 nAdapterNum) = 0;
  23. /// Reset device.
  24. virtual mfxStatus Reset() = 0;
  25. /// Get handle can be used for MFX session SetHandle calls
  26. virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl) = 0;
  27. /** Set handle.
  28. Particular device implementation may require other objects to operate.
  29. */
  30. virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl) = 0;
  31. virtual mfxStatus RenderFrame(mfxFrameSurface1 *pSurface,
  32. mfxFrameAllocator *pmfxAlloc) = 0;
  33. virtual void Close() = 0;
  34. };
  35. enum {
  36. MFX_HANDLE_GFXS3DCONTROL =
  37. 0x100, /* A handle to the IGFXS3DControl instance */
  38. MFX_HANDLE_DEVICEWINDOW = 0x101 /* A handle to the render window */
  39. }; //mfxHandleType
  40. /** Direct3D 9 device implementation.
  41. @note Can be initialized for only 1 or two 2 views. Handle to
  42. MFX_HANDLE_GFXS3DCONTROL must be set prior if initializing for 2 views.
  43. @note Device always set D3DPRESENT_PARAMETERS::Windowed to TRUE.
  44. */
  45. class CD3D9Device : public CHWDevice {
  46. public:
  47. CD3D9Device();
  48. virtual ~CD3D9Device();
  49. virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews,
  50. mfxU32 nAdapterNum);
  51. virtual mfxStatus Reset();
  52. virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl);
  53. virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl);
  54. virtual mfxStatus RenderFrame(mfxFrameSurface1 *pSurface,
  55. mfxFrameAllocator *pmfxAlloc);
  56. virtual void UpdateTitle(double /*fps*/) {}
  57. virtual void Close();
  58. void DefineFormat(bool isA2rgb10)
  59. {
  60. m_bIsA2rgb10 = (isA2rgb10) ? TRUE : FALSE;
  61. }
  62. protected:
  63. mfxStatus CreateVideoProcessors();
  64. bool CheckOverlaySupport();
  65. virtual mfxStatus FillD3DPP(mfxHDL hWindow, mfxU16 nViews,
  66. D3DPRESENT_PARAMETERS &D3DPP);
  67. private:
  68. IDirect3D9Ex *m_pD3D9;
  69. IDirect3DDevice9Ex *m_pD3DD9;
  70. IDirect3DDeviceManager9 *m_pDeviceManager9;
  71. D3DPRESENT_PARAMETERS m_D3DPP;
  72. UINT m_resetToken;
  73. mfxU16 m_nViews;
  74. IGFXS3DControl *m_pS3DControl;
  75. D3DSURFACE_DESC m_backBufferDesc;
  76. // service required to create video processors
  77. IDirectXVideoProcessorService *m_pDXVAVPS;
  78. //left channel processor
  79. IDirectXVideoProcessor *m_pDXVAVP_Left;
  80. // right channel processor
  81. IDirectXVideoProcessor *m_pDXVAVP_Right;
  82. // target rectangle
  83. RECT m_targetRect;
  84. // various structures for DXVA2 calls
  85. DXVA2_VideoDesc m_VideoDesc;
  86. DXVA2_VideoProcessBltParams m_BltParams;
  87. DXVA2_VideoSample m_Sample;
  88. BOOL m_bIsA2rgb10;
  89. };
  90. #endif // #if defined( _WIN32 ) || defined ( _WIN64 )