record_desktop_duplication.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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:
  19. public record_desktop
  20. {
  21. public:
  22. record_desktop_duplication();
  23. ~record_desktop_duplication();
  24. virtual int init(
  25. const RECORD_DESKTOP_RECT &rect,
  26. const int fps);
  27. virtual int start();
  28. virtual int pause();
  29. virtual int resume();
  30. virtual int stop();
  31. protected:
  32. virtual void clean_up();
  33. private:
  34. int get_dst_adapter(IDXGIAdapter **adapter);
  35. int create_d3d_device(IDXGIAdapter *adapter,ID3D11Device **device);
  36. int init_d3d11();
  37. void clean_d3d11();
  38. int init_duplication();
  39. int free_duplicated_frame();
  40. void clean_duplication();
  41. bool attatch_desktop();
  42. int get_desktop_image(DXGI_OUTDUPL_FRAME_INFO *frame_info);
  43. int get_desktop_cursor(const DXGI_OUTDUPL_FRAME_INFO *frame_info);
  44. void draw_cursor();
  45. void do_sleep(int64_t dur, int64_t pre, int64_t now);
  46. void record_func();
  47. private:
  48. uint8_t *_buffer;
  49. uint32_t _buffer_size;
  50. uint32_t _width, _height;
  51. HMODULE _d3d11, _dxgi;
  52. ID3D11Device* _d3d_device;
  53. ID3D11DeviceContext* _d3d_ctx;
  54. ID3D11VertexShader* _d3d_vshader;
  55. ID3D11PixelShader* _d3d_pshader;
  56. ID3D11InputLayout* _d3d_inlayout;
  57. ID3D11SamplerState* _d3d_samplerlinear;
  58. IDXGIOutputDuplication *_duplication;
  59. ID3D11Texture2D *_image;
  60. DXGI_OUTPUT_DESC _output_des;
  61. int _output_index;
  62. DUPLICATION_CURSOR_INFO _cursor_info;
  63. };
  64. }
  65. #endif