#pragma once #include #include #include #include #include #include "basic/frame.h" // 添加对 AVFrame 的支持 // 定义 VideoFrame 结构体 struct VideoFrame { unsigned char* data; int width; int height; int format; }; class OpenGLVideoWidget : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT public: explicit OpenGLVideoWidget(QWidget* parent = nullptr); ~OpenGLVideoWidget(); // 添加与 VideoRender 类似的接口 bool Open(unsigned int width, unsigned int height); void Close(); bool Render(AVFrame* frame); // 原有接口 void updateFrame(const VideoFrame& frame); void clearFrame(); // 添加从 AVFrame 转换的方法 bool convertFromAVFrame(AVFrame* frame); void setKeepAspectRatio(bool keep) { m_keepAspectRatio = keep; update(); } bool keepAspectRatio() const { return m_keepAspectRatio; } protected: void initializeGL() override; void paintGL() override; void resizeGL(int width, int height) override; private: QOpenGLShaderProgram* m_program; GLuint m_textureId; // 使用原生OpenGL纹理ID // 存储原始帧数据 unsigned char* m_frameData; int m_frameWidth; int m_frameHeight; int m_frameFormat; // 可以用来表示像素格式 QMutex m_mutex; bool m_frameUpdated; bool m_initialized; // 顶点和纹理坐标 GLfloat m_vertices[8]; GLfloat m_texCoords[8]; bool m_keepAspectRatio = true; };