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 setBuffer (GstBuffer * buffer); 46 gboolean setCaps (GstCaps *caps); 47 gboolean initWinSys (); 48 GstGLContext *getQtContext(); 49 GstGLContext *getContext(); 50 GstGLDisplay *getDisplay(); videoItem()51 QtGLVideoItem *videoItem () { return qt_item; }; 52 53 void setDAR(gint, gint); 54 void getDAR(gint *, gint *); 55 void setForceAspectRatio(bool); 56 bool getForceAspectRatio(); 57 private: 58 QtGLVideoItem *qt_item; 59 QMutex lock; 60 }; 61 62 class InitializeSceneGraph; 63 64 class QtGLVideoItem : public QQuickItem, protected QOpenGLFunctions 65 { 66 Q_OBJECT 67 68 Q_PROPERTY(bool itemInitialized 69 READ itemInitialized 70 NOTIFY itemInitializedChanged) 71 72 public: 73 QtGLVideoItem(); 74 ~QtGLVideoItem(); 75 76 void setDAR(gint, gint); 77 void getDAR(gint *, gint *); 78 void setForceAspectRatio(bool); 79 bool getForceAspectRatio(); 80 bool itemInitialized(); 81 getInterface()82 QSharedPointer<QtGLVideoItemInterface> getInterface() { return proxy; }; 83 /* private for C interface ... */ 84 QtGLVideoItemPrivate *priv; 85 86 Q_SIGNALS: 87 void itemInitializedChanged(); 88 89 private Q_SLOTS: 90 void handleWindowChanged(QQuickWindow * win); 91 void onSceneGraphInitialized(); 92 void onSceneGraphInvalidated(); 93 94 protected: 95 QSGNode * updatePaintNode (QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData); 96 97 private: 98 99 friend class InitializeSceneGraph; 100 void setViewportSize(const QSize &size); 101 void shareContext(); 102 103 QSize m_viewportSize; 104 bool m_openGlContextInitialized; 105 106 QSharedPointer<QtGLVideoItemInterface> proxy; 107 }; 108 109 #endif /* __QT_ITEM_H__ */ 110