• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef __QT_ITEM_H__
22 #define __QT_ITEM_H__
23 
24 #include <gst/gst.h>
25 #include <gst/gl/gl.h>
26 
27 #include "gstqtgl.h"
28 #include <QtCore/QMutex>
29 #include <QtQuick/QQuickItem>
30 #include <QtGui/QOpenGLContext>
31 #include <QtGui/QOpenGLFunctions>
32 
33 typedef struct _QtGLVideoItemPrivate QtGLVideoItemPrivate;
34 
35 class QtGLVideoItem;
36 
37 class QtGLVideoItemInterface : public QObject
38 {
39     Q_OBJECT
40 public:
QtGLVideoItemInterface(QtGLVideoItem * w)41     QtGLVideoItemInterface (QtGLVideoItem *w) : qt_item (w), lock() {};
42 
43     void invalidateRef();
44 
45     void setSink (GstElement * sink);
46     void setBuffer (GstBuffer * buffer);
47     gboolean setCaps (GstCaps *caps);
48     gboolean initWinSys ();
49     GstGLContext *getQtContext();
50     GstGLContext *getContext();
51     GstGLDisplay *getDisplay();
videoItem()52     QtGLVideoItem *videoItem () { return qt_item; };
53 
54     void setDAR(gint, gint);
55     void getDAR(gint *, gint *);
56     void setForceAspectRatio(bool);
57     bool getForceAspectRatio();
58 private:
59     QtGLVideoItem *qt_item;
60     QMutex lock;
61 };
62 
63 class QtGLVideoItem : public QQuickItem, protected QOpenGLFunctions
64 {
65     Q_OBJECT
66 
67     Q_PROPERTY(bool itemInitialized
68                READ itemInitialized
69                NOTIFY itemInitializedChanged)
70     Q_PROPERTY(bool forceAspectRatio
71                READ getForceAspectRatio
72                WRITE setForceAspectRatio
73                NOTIFY forceAspectRatioChanged)
74 
75 public:
76     QtGLVideoItem();
77     ~QtGLVideoItem();
78 
79     void setDAR(gint, gint);
80     void getDAR(gint *, gint *);
81     void setForceAspectRatio(bool);
82     bool getForceAspectRatio();
83     bool itemInitialized();
84 
getInterface()85     QSharedPointer<QtGLVideoItemInterface> getInterface() { return proxy; };
86     /* private for C interface ... */
87     QtGLVideoItemPrivate *priv;
88 
89 Q_SIGNALS:
90     void itemInitializedChanged();
91     void forceAspectRatioChanged(bool);
92 
93 private Q_SLOTS:
94     void handleWindowChanged(QQuickWindow * win);
95     void onSceneGraphInitialized();
96     void onSceneGraphInvalidated();
97 
98 protected:
99     QSGNode * updatePaintNode (QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) override;
100     void wheelEvent(QWheelEvent *) override;
101     void hoverEnterEvent(QHoverEvent *) override;
102     void hoverLeaveEvent (QHoverEvent *) override;
103     void hoverMoveEvent (QHoverEvent *) override;
104     void mousePressEvent(QMouseEvent*) override;
105     void mouseReleaseEvent(QMouseEvent*) override;
106 
107 private:
108 
109     void setViewportSize(const QSize &size);
110     void shareContext();
111 
112     void fitStreamToAllocatedSize(GstVideoRectangle * result);
113     QPointF mapPointToStreamSize(QPointF);
114 
115     void sendMouseEvent(QMouseEvent * event, const gchar * type);
116 
117     quint32 mousePressedButton;
118     bool mouseHovering;
119 
120     QSharedPointer<QtGLVideoItemInterface> proxy;
121 };
122 
123 #endif /* __QT_ITEM_H__ */
124