playerdemowindow.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef PLAYERDEMOWINDOW_H
  2. #define PLAYERDEMOWINDOW_H
  3. #include "AvPlayer/FFmpegVideoPuller.h"
  4. #pragma once
  5. #include <QAudioOutput>
  6. #include <QCheckBox>
  7. #include <QComboBox>
  8. #include <QIODevice>
  9. #include <QLabel>
  10. #include <QPushButton>
  11. #include <QSlider>
  12. #include <QWidget>
  13. #include <QThread>
  14. #include "AudioPlayer.h"
  15. #include "AvRecorder/ui/opengl_video_widget.h"
  16. #include "VideoPlayer.h"
  17. extern "C" {
  18. #include <libswresample/swresample.h>
  19. }
  20. struct sonicStreamStruct;
  21. class PlayerDemoWindow : public QWidget
  22. {
  23. Q_OBJECT
  24. public:
  25. explicit PlayerDemoWindow(QWidget* parent = nullptr);
  26. ~PlayerDemoWindow();
  27. void startPlay(const QString& url);
  28. void stopPlay();
  29. void setSpeed(float speed);
  30. private slots:
  31. void onProgressSliderMoved(int value);
  32. void onProgressSliderReleased();
  33. void onSpeedChanged(int index);
  34. void onPlayClicked();
  35. private:
  36. FFmpegVideoPuller* m_puller = nullptr;
  37. AudioPlayer* m_audioPlayer = nullptr;
  38. VideoPlayer* m_videoPlayer = nullptr;
  39. QThread* m_syncPlayThread = nullptr;
  40. std::atomic<bool> m_syncPlayRunning{false};
  41. void syncPlayLoop();
  42. OpenGLVideoWidget* m_videoWidget = nullptr;
  43. // UI
  44. QSlider* m_progressSlider = nullptr;
  45. QLabel* m_timeLabel = nullptr;
  46. QComboBox* m_speedCombo = nullptr;
  47. QPushButton* m_playBtn = nullptr;
  48. QCheckBox* m_keepAspectCheck = nullptr;
  49. // 进度相关
  50. bool m_sliderPressed = false;
  51. double m_firstPts = 0.0;
  52. double m_lastPts = 0.0;
  53. double m_duration = 0.0;
  54. bool m_playing = false;
  55. void updateProgress();
  56. QString formatTime(double seconds) const;
  57. private:
  58. SwrContext* m_swrCtx = nullptr;
  59. uint8_t* m_swrBuffer = nullptr;
  60. int m_swrBufferSize = 0;
  61. };
  62. #endif // PLAYERDEMOWINDOW_H