CSdlProc.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /// <summary>
  2. /// C语言SDL程序
  3. /// </summary>
  4. #pragma once
  5. #include <qobject.h>
  6. #include <sdl/SDL.h>
  7. extern "C"
  8. {
  9. #include <libavcodec/avcodec.h>
  10. #include <libavformat/avformat.h>
  11. #include <libswscale/swscale.h>
  12. #include <libavdevice/avdevice.h>
  13. #include <libavutil/opt.h>
  14. #include <libavfilter/avfilter.h>
  15. #include <libavfilter/buffersrc.h>
  16. #include <libavfilter/buffersink.h>
  17. #include <libavutil/imgutils.h>
  18. #include <libavutil/frame.h>
  19. };
  20. class SDL_Window;
  21. class SDL_Renderer;
  22. class SDL_Texture;
  23. class SwsContext;
  24. class AVFrame;
  25. struct _TTF_Font;
  26. class SDL_Rect;
  27. class CSdlProc
  28. {
  29. public:
  30. CSdlProc();
  31. ~CSdlProc();
  32. public:
  33. bool Init(void * pWnd, int nVideoWidth, int nVideoHeight, bool bHard);
  34. void DisplayFrame(AVFrame *pFrame);
  35. void DisplayFrame(uint8_t *pData, int nWidth, int nHeight);
  36. void SetRect(int nOffset_x, int nOffset_y, int nWidth, int nHeight);
  37. void Destroy();
  38. SDL_Window* GetWindow()
  39. {
  40. return m_screen;
  41. };
  42. static void SetUseDispalyArea(bool bUseDispalyArea);
  43. void SetDispalyAreaFalse()
  44. {
  45. m_bDisplayArea = false;
  46. }
  47. void UpdateAreaPoint(const QPoint &ptArea)
  48. {
  49. m_ptArea = ptArea;
  50. }
  51. void UpdateAreaRect(const QPoint &ptlt, const QPoint &ptbr)
  52. {
  53. m_ptlt = ptlt;
  54. m_ptbr = ptbr;
  55. }
  56. void SetDispalyRect(bool b)
  57. {
  58. m_bDisplayRect = b;
  59. }
  60. void UpdateAreaText(const std::string &strText)
  61. {
  62. m_strText = strText;
  63. }
  64. void DisplayReconn();
  65. private:
  66. void DisplayChooseArea(const QPoint& pt);
  67. void DisplayChooseAreaRect(const QPoint& ptlt, const QPoint& ptbr);
  68. private:
  69. //sdl显示需要成员
  70. SDL_Window *m_screen{nullptr};
  71. SDL_Renderer* m_sdlRenderer{ nullptr };
  72. SDL_Texture* m_sdlTexture{ nullptr };
  73. SDL_Rect * m_sdlRect { nullptr };
  74. SwsContext *m_img_convert_ctx{ nullptr };
  75. AVFrame *m_pFrameYUV{ nullptr };
  76. uint8_t *m_out_buffer{ nullptr };
  77. QPoint m_ptArea{400,200};
  78. std::string m_strText{"X1"};
  79. _TTF_Font *m_pFont{nullptr};
  80. //全局设置
  81. static bool m_bUseDispalyArea;
  82. //对于全景,不显示通过m_bDisplayArea判断
  83. bool m_bDisplayArea{true};
  84. QPoint m_ptlt{ 200,200 };
  85. QPoint m_ptbr{ 400,300 };
  86. bool m_bDisplayRect{ false };
  87. };