基于qt,msvc2017-64bits,ffmpeg.opengl的播放器
chenshijun
2020-12-03 f96dd824b3653896bfec4e3bfdb6b02e84793075
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef SHOWVIDEOWIDGET_H
#define SHOWVIDEOWIDGET_H
 
#include <QWidget>
#include <QPaintEvent>
#include <QResizeEvent>
 
#include <QOpenGLWidget>
#include <QOpenGLShaderProgram>
#include <QOpenGLFunctions>
#include <QOpenGLTexture>
#include <QFile>
 
#include "Base/FunctionTransfer.h"
#include "VideoPlayer/Video/VideoFrame.h"
 
namespace Ui {
class ShowVideoWidget;
}
 
struct FaceInfoNode
{
    QRect faceRect;
};
 
///显示视频用的widget(使用OPENGL绘制YUV420P数据)
///这个仅仅是显示视频画面的控件
 
class ShowVideoWidget : public QOpenGLWidget,protected QOpenGLFunctions
{
    Q_OBJECT
 
public:
    explicit ShowVideoWidget(QWidget *parent = 0);
    ~ShowVideoWidget();
 
    void setPlayerId(QString id){mPlayerId=id;} //用于协助拖拽 区分是哪个窗口
    QString getPlayerId(){return mPlayerId;}
 
    void setCloseAble(bool isCloseAble);
 
    void clear();
    
    void setIsPlaying(bool value);
    void setPlayFailed(bool value);
    
    void setCameraName(QString name);
 
    void setVideoWidth(int w, int h);
 
    void setShowFaceRect(bool value){mIsShowFaceRect = value;}
 
    qint64 getLastGetFrameTime(){return mLastGetFrameTime;}
 
    void inputOneFrame(VideoFramePtr videoFrame);
 
signals:
    void sig_CloseBtnClick();
    void sig_Drag(QString id_from, QString id_to);
 
protected:
    void enterEvent(QEvent *event);
    void leaveEvent(QEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
 
private:
    bool mIsPlaying;
    bool mPlayFailed; //播放失败
    bool mIsCloseAble; //是否显示关闭按钮
 
    QString mCameraName;
    qint64 mLastGetFrameTime; //上一次获取到帧的时间戳
    void resetGLVertex(int window_W, int window_H);
 
protected:
    void initializeGL() Q_DECL_OVERRIDE;
    void resizeGL(int window_W, int window_H) Q_DECL_OVERRIDE;
    void paintGL() Q_DECL_OVERRIDE;
 
private:
    ///OPenGL用于绘制图像
    GLuint textureUniformY; //y纹理数据位置
    GLuint textureUniformU; //u纹理数据位置
    GLuint textureUniformV; //v纹理数据位置
    GLuint id_y; //y纹理对象ID
    GLuint id_u; //u纹理对象ID
    GLuint id_v; //v纹理对象ID
    QOpenGLTexture* m_pTextureY;  //y纹理对象
    QOpenGLTexture* m_pTextureU;  //u纹理对象
    QOpenGLTexture* m_pTextureV;  //v纹理对象
    QOpenGLShader *m_pVSHader;  //顶点着色器程序对象
    QOpenGLShader *m_pFSHader;  //片段着色器对象
    QOpenGLShaderProgram *m_pShaderProgram; //着色器程序容器
    GLfloat *m_vertexVertices; // 顶点矩阵
 
    float mPicIndex_X; //按比例显示情况下 图像偏移量百分比 (相对于窗口大小的)
    float mPicIndex_Y; //
    int m_nVideoW; //视频分辨率宽
    int m_nVideoH; //视频分辨率高
 
    VideoFramePtr mVideoFrame;
    QList<FaceInfoNode> mFaceInfoList;
 
    bool mIsOpenGLInited; //openGL初始化函数是否执行过了
 
    ///OpenGL用于绘制矩形
    bool mIsShowFaceRect;
    GLuint m_posAttr;
    GLuint m_colAttr;
    QOpenGLShaderProgram *m_program;
 
    bool mCurrentVideoKeepAspectRatio; //当前模式是否是按比例 当检测到与全局变量不一致的时候 则重新设置openGL矩阵
 
    QString mPlayerId;
 
private:
    Ui::ShowVideoWidget *ui;
 
};
 
#endif // SHOWVIDEOWIDGET_H