video_play_thread.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include <QDebug>
  3. #include <QImage>
  4. #include <QRegularExpression>
  5. #include <QThread>
  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 QThread
  15. {
  16. Q_OBJECT
  17. public:
  18. explicit VideoPlayThread(QObject* parent = nullptr, VideoState* pState = nullptr);
  19. ~VideoPlayThread();
  20. public:
  21. bool init_resample_param(AVCodecContext* pVideo, bool bHardware = false);
  22. public slots:
  23. void stop_thread();
  24. signals:
  25. void frame_ready(const QImage&);
  26. void frameReady(AVFrame*);
  27. void subtitle_ready(const QString&);
  28. protected:
  29. void run() override;
  30. private:
  31. void video_refresh(VideoState* is, double* remaining_time);
  32. void video_image_display(VideoState* is);
  33. void video_display(VideoState* is);
  34. // void video_audio_display(VideoState* s);
  35. void final_resample_param();
  36. inline int compute_mod(int a, int b) { return a < 0 ? (a % b + b) : (a % b); }
  37. void parse_subtitle_ass(const QString& text);
  38. private:
  39. VideoState* m_pState{nullptr};
  40. Video_Resample m_Resample;
  41. bool m_bExitThread{false};
  42. const static QRegularExpression m_assFilter;
  43. const static QRegularExpression m_assNewLineReplacer;
  44. };