| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #pragma once
- #include <QMutex>
- #include <QOpenGLFunctions>
- #include <QOpenGLShaderProgram>
- #include <QOpenGLTexture>
- #include <QOpenGLWidget>
- #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);
- 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];
- };
|