ShowVideoWidget.h 3.2 KB

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