| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Copyright (C) 2016 Research In Motion |
| 5 | ** Contact: https://www.qt.io/licensing/ |
| 6 | ** |
| 7 | ** This file is part of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 10 | ** Commercial License Usage |
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 12 | ** accordance with the commercial license agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and The Qt Company. For licensing terms |
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 16 | ** information use the contact form at https://www.qt.io/contact-us. |
| 17 | ** |
| 18 | ** GNU Lesser General Public License Usage |
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 20 | ** General Public License version 3 as published by the Free Software |
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 22 | ** packaging of this file. Please review the following information to |
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 25 | ** |
| 26 | ** GNU General Public License Usage |
| 27 | ** Alternatively, this file may be used under the terms of the GNU |
| 28 | ** General Public License version 2.0 or (at your option) the GNU General |
| 29 | ** Public license version 3 or any later version approved by the KDE Free |
| 30 | ** Qt Foundation. The licenses are as published by the Free Software |
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 32 | ** included in the packaging of this file. Please review the following |
| 33 | ** information to ensure the GNU General Public License requirements will |
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 36 | ** |
| 37 | ** $QT_END_LICENSE$ |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #ifndef QDECLARATIVEVIDEOOUTPUT_RENDER_P_H |
| 42 | #define QDECLARATIVEVIDEOOUTPUT_RENDER_P_H |
| 43 | |
| 44 | // |
| 45 | // W A R N I N G |
| 46 | // ------------- |
| 47 | // |
| 48 | // This file is not part of the Qt API. It exists purely as an |
| 49 | // implementation detail. This header file may change from version to |
| 50 | // version without notice, or even be removed. |
| 51 | // |
| 52 | // We mean it. |
| 53 | // |
| 54 | |
| 55 | #include <private/qdeclarativevideooutput_backend_p.h> |
| 56 | #include <private/qsgvideonode_yuv_p.h> |
| 57 | #include <private/qsgvideonode_rgb_p.h> |
| 58 | #include <private/qsgvideonode_texture_p.h> |
| 59 | |
| 60 | #include <QtCore/qmutex.h> |
| 61 | #include <QtMultimedia/qabstractvideosurface.h> |
| 62 | |
| 63 | QT_BEGIN_NAMESPACE |
| 64 | |
| 65 | class QSGVideoItemSurface; |
| 66 | class QVideoRendererControl; |
| 67 | class QOpenGLContext; |
| 68 | class QAbstractVideoFilter; |
| 69 | class QVideoFilterRunnable; |
| 70 | |
| 71 | class QDeclarativeVideoRendererBackend : public QDeclarativeVideoBackend |
| 72 | { |
| 73 | public: |
| 74 | QDeclarativeVideoRendererBackend(QDeclarativeVideoOutput *parent); |
| 75 | ~QDeclarativeVideoRendererBackend(); |
| 76 | |
| 77 | bool init(QMediaService *service) override; |
| 78 | void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &changeData) override; |
| 79 | void releaseSource() override; |
| 80 | void releaseControl() override; |
| 81 | QSize nativeSize() const override; |
| 82 | void updateGeometry() override; |
| 83 | QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) override; |
| 84 | QAbstractVideoSurface *videoSurface() const override; |
| 85 | QRectF adjustedViewport() const override; |
| 86 | QOpenGLContext *glContext() const; |
| 87 | |
| 88 | friend class QSGVideoItemSurface; |
| 89 | void present(const QVideoFrame &frame); |
| 90 | void stop(); |
| 91 | |
| 92 | void appendFilter(QAbstractVideoFilter *filter) override; |
| 93 | void clearFilters() override; |
| 94 | void releaseResources() override; |
| 95 | void invalidateSceneGraph() override; |
| 96 | |
| 97 | private: |
| 98 | void scheduleDeleteFilterResources(); |
| 99 | |
| 100 | QPointer<QVideoRendererControl> m_rendererControl; |
| 101 | QList<QSGVideoNodeFactoryInterface*> m_videoNodeFactories; |
| 102 | QSGVideoItemSurface *m_surface; |
| 103 | QVideoSurfaceFormat m_surfaceFormat; |
| 104 | QOpenGLContext *m_glContext; |
| 105 | QVideoFrame m_frame; |
| 106 | QVideoFrame m_frameOnFlush; |
| 107 | bool m_frameChanged; |
| 108 | QSGVideoNodeFactory_YUV m_i420Factory; |
| 109 | QSGVideoNodeFactory_RGB m_rgbFactory; |
| 110 | QSGVideoNodeFactory_Texture m_textureFactory; |
| 111 | QMutex m_frameMutex; |
| 112 | QRectF m_renderedRect; // Destination pixel coordinates, clipped |
| 113 | QRectF m_sourceTextureRect; // Source texture coordinates |
| 114 | |
| 115 | struct Filter { |
| 116 | Filter() : filter(0), runnable(0) { } |
| 117 | Filter(QAbstractVideoFilter *filter) : filter(filter), runnable(0) { } |
| 118 | QAbstractVideoFilter *filter; |
| 119 | QVideoFilterRunnable *runnable; |
| 120 | }; |
| 121 | QList<Filter> m_filters; |
| 122 | }; |
| 123 | |
| 124 | class QSGVideoItemSurface : public QAbstractVideoSurface |
| 125 | { |
| 126 | Q_OBJECT |
| 127 | public: |
| 128 | explicit QSGVideoItemSurface(QDeclarativeVideoRendererBackend *backend, QObject *parent = 0); |
| 129 | ~QSGVideoItemSurface(); |
| 130 | QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override; |
| 131 | bool start(const QVideoSurfaceFormat &format) override; |
| 132 | void stop() override; |
| 133 | bool present(const QVideoFrame &frame) override; |
| 134 | void scheduleOpenGLContextUpdate(); |
| 135 | |
| 136 | private slots: |
| 137 | void updateOpenGLContext(); |
| 138 | |
| 139 | private: |
| 140 | QDeclarativeVideoRendererBackend *m_backend; |
| 141 | }; |
| 142 | |
| 143 | QT_END_NAMESPACE |
| 144 | |
| 145 | #endif |
| 146 | |