zero_copy_video_player/glwidget.h

64 lines
1.2 KiB
C++

#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QMutex>
#include <cuda_runtime.h>
#include <cuda_gl_interop.h>
extern "C" {
#include <libavcodec/avcodec.h>
}
class VideoDecoder;
class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions {
Q_OBJECT
public:
explicit GLWidget(QWidget *parent = nullptr);
~GLWidget() override;
void setVideoDecoder(VideoDecoder *decoder);
void clearVideo();
public slots:
void onFrameReady();
protected:
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
private:
void cleanupCudaGL();
VideoDecoder *m_videoDecoder;
QOpenGLShaderProgram m_shaderProgram;
// Texturas de OpenGL para NV12
GLuint m_texY;
GLuint m_texUV;
GLuint m_vbo;
// Recursos gráficos registrados de CUDA
cudaGraphicsResource_t m_cudaResourceY;
cudaGraphicsResource_t m_cudaResourceUV;
// Fotograma local reutilizable
AVFrame *m_localFrame;
// Dimensiones de texturas registradas en CUDA
int m_allocatedWidth;
int m_allocatedHeight;
};
#endif // GLWIDGET_H