video_play_thread.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include "ThreadBase.h"
  3. #include <QDebug>
  4. #include <QImage>
  5. #include <QRegularExpression>
  6. #include "packets_sync.h"
  7. #define PRINT_VIDEO_BUFFER_INFO 0
  8. typedef struct Video_Resample
  9. {
  10. AVFrame* pFrameRGB{nullptr};
  11. uint8_t* buffer_RGB{nullptr};
  12. struct SwsContext* sws_ctx{nullptr};
  13. } Video_Resample;
  14. class VideoPlayThread : public ThreadBase
  15. {
  16. public:
  17. explicit VideoPlayThread(VideoState* pState = nullptr);
  18. ~VideoPlayThread();
  19. bool init_resample_param(AVCodecContext* pVideo, bool bHardware = false);
  20. void stop() override;
  21. protected:
  22. void run() override;
  23. private:
  24. void video_refresh(VideoState* is, double* remaining_time);
  25. void video_image_display(VideoState* is);
  26. void video_display(VideoState* is);
  27. void final_resample_param();
  28. inline int compute_mod(int a, int b) { return a < 0 ? (a % b + b) : (a % b); }
  29. void parse_subtitle_ass(const QString& text);
  30. private:
  31. VideoState* m_pState{nullptr};
  32. Video_Resample m_Resample;
  33. std::atomic<bool> m_bExitThread{false};
  34. const static QRegularExpression m_assFilter;
  35. const static QRegularExpression m_assNewLineReplacer;
  36. };