qtitem.h 2.84 KB
Newer Older
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
/*
 * GStreamer
 * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef __QT_ITEM_H__
#define __QT_ITEM_H__

#include <gst/gst.h>
#include <gst/gl/gl.h>
26 27

#include "gstqtgl.h"
28
#include <QtCore/QMutex>
29 30 31
#include <QtQuick/QQuickItem>
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLFunctions>
32 33 34

typedef struct _QtGLVideoItemPrivate QtGLVideoItemPrivate;

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
class QtGLVideoItem;

class QtGLVideoItemInterface : public QObject
{
    Q_OBJECT
public:
    QtGLVideoItemInterface (QtGLVideoItem *w) : qt_item (w), lock() {};

    void invalidateRef();

    void setBuffer (GstBuffer * buffer);
    gboolean setCaps (GstCaps *caps);
    gboolean initWinSys ();
    GstGLContext *getQtContext();
    GstGLContext *getContext();
    GstGLDisplay *getDisplay();
    QtGLVideoItem *videoItem () { return qt_item; };

    void setDAR(gint, gint);
    void getDAR(gint *, gint *);
    void setForceAspectRatio(bool);
    bool getForceAspectRatio();
private:
    QtGLVideoItem *qt_item;
    QMutex lock;
};

62 63
class InitializeSceneGraph;

64 65 66
class QtGLVideoItem : public QQuickItem, protected QOpenGLFunctions
{
    Q_OBJECT
67 68 69 70 71

    Q_PROPERTY(bool itemInitialized
               READ itemInitialized
               NOTIFY itemInitializedChanged)

72 73 74 75 76 77 78 79
public:
    QtGLVideoItem();
    ~QtGLVideoItem();

    void setDAR(gint, gint);
    void getDAR(gint *, gint *);
    void setForceAspectRatio(bool);
    bool getForceAspectRatio();
80
    bool itemInitialized();
81

82
    QSharedPointer<QtGLVideoItemInterface> getInterface() { return proxy; };
83 84 85
    /* private for C interface ... */
    QtGLVideoItemPrivate *priv;

86
Q_SIGNALS:
87
    void itemInitializedChanged();
88

89 90 91 92 93 94 95 96 97
private Q_SLOTS:
    void handleWindowChanged(QQuickWindow * win);
    void onSceneGraphInitialized();
    void onSceneGraphInvalidated();

protected:
    QSGNode * updatePaintNode (QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData);

private:
98

99
    friend class InitializeSceneGraph;
100 101 102 103
    void setViewportSize(const QSize &size);
    void shareContext();

    QSize m_viewportSize;
104
    bool m_openGlContextInitialized;
105

106 107
    QSharedPointer<QtGLVideoItemInterface> proxy;
};
108 109

#endif /* __QT_ITEM_H__ */