record_desktop_duplication.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef RECORD_DESKTOP_DUPLICATION
  2. #define RECORD_DESKTOP_DUPLICATION
  3. #include "record_desktop.h"
  4. #include <Windows.h>
  5. #include <d3d11.h>
  6. #include <dxgi1_2.h>
  7. namespace am {
  8. typedef struct _PTR_INFO
  9. {
  10. _Field_size_bytes_(BufferSize) BYTE *buff;
  11. DXGI_OUTDUPL_POINTER_SHAPE_INFO shape;
  12. POINT position;
  13. bool visible;
  14. UINT size;
  15. UINT output_index;
  16. LARGE_INTEGER pre_timestamp;
  17. } DUPLICATION_CURSOR_INFO;
  18. class record_desktop_duplication : public record_desktop
  19. {
  20. public:
  21. record_desktop_duplication();
  22. ~record_desktop_duplication();
  23. virtual int init(const RECORD_DESKTOP_RECT &rect, const int fps);
  24. virtual int start();
  25. virtual int pause();
  26. virtual int resume();
  27. virtual int stop();
  28. protected:
  29. virtual void clean_up();
  30. private:
  31. int get_dst_adapter(IDXGIAdapter **adapter);
  32. int create_d3d_device(IDXGIAdapter *adapter, ID3D11Device **device);
  33. int init_d3d11();
  34. void clean_d3d11();
  35. int init_duplication();
  36. int free_duplicated_frame();
  37. void clean_duplication();
  38. bool attatch_desktop();
  39. int get_desktop_image(DXGI_OUTDUPL_FRAME_INFO *frame_info);
  40. int get_desktop_cursor(const DXGI_OUTDUPL_FRAME_INFO *frame_info);
  41. void draw_cursor();
  42. void do_sleep(int64_t dur, int64_t pre, int64_t now);
  43. void record_func();
  44. private:
  45. uint8_t *_buffer;
  46. uint32_t _buffer_size;
  47. uint32_t _width, _height;
  48. HMODULE _d3d11, _dxgi;
  49. ID3D11Device *_d3d_device;
  50. ID3D11DeviceContext *_d3d_ctx;
  51. ID3D11VertexShader *_d3d_vshader;
  52. ID3D11PixelShader *_d3d_pshader;
  53. ID3D11InputLayout *_d3d_inlayout;
  54. ID3D11SamplerState *_d3d_samplerlinear;
  55. IDXGIOutputDuplication *_duplication;
  56. ID3D11Texture2D *_image;
  57. DXGI_OUTPUT_DESC _output_des;
  58. int _output_index;
  59. DUPLICATION_CURSOR_INFO _cursor_info;
  60. };
  61. } // namespace am
  62. #endif