opengl_video_widget.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include <QMutex>
  3. #include <QOpenGLFunctions>
  4. #include <QOpenGLShaderProgram>
  5. #include <QOpenGLTexture>
  6. #include <QOpenGLWidget>
  7. #include "basic/frame.h" // 添加对 AVFrame 的支持
  8. // 定义 VideoFrame 结构体
  9. struct VideoFrame {
  10. unsigned char* data;
  11. int width;
  12. int height;
  13. int format;
  14. };
  15. class OpenGLVideoWidget : public QOpenGLWidget, protected QOpenGLFunctions
  16. {
  17. Q_OBJECT
  18. public:
  19. explicit OpenGLVideoWidget(QWidget* parent = nullptr);
  20. ~OpenGLVideoWidget();
  21. // 添加与 VideoRender 类似的接口
  22. bool Open(unsigned int width, unsigned int height);
  23. void Close();
  24. bool Render(AVFrame* frame);
  25. // 原有接口
  26. void updateFrame(const VideoFrame& frame);
  27. void clearFrame();
  28. // 添加从 AVFrame 转换的方法
  29. bool convertFromAVFrame(AVFrame* frame);
  30. protected:
  31. void initializeGL() override;
  32. void paintGL() override;
  33. void resizeGL(int width, int height) override;
  34. private:
  35. QOpenGLShaderProgram* m_program;
  36. GLuint m_textureId; // 使用原生OpenGL纹理ID
  37. // 存储原始帧数据
  38. unsigned char* m_frameData;
  39. int m_frameWidth;
  40. int m_frameHeight;
  41. int m_frameFormat; // 可以用来表示像素格式
  42. QMutex m_mutex;
  43. bool m_frameUpdated;
  44. bool m_initialized;
  45. // 顶点和纹理坐标
  46. GLfloat m_vertices[8];
  47. GLfloat m_texCoords[8];
  48. };