videomaterial.h 2.45 KB
Newer Older
Gus Grubba's avatar
Gus Grubba committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
    Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
    Copyright (C) 2013 basysKom GmbH <info@basyskom.com>
    Copyright (C) 2013 Collabora Ltd. <info@collabora.com>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License version 2.1
    as published by the Free Software Foundation.

    This program 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 Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

/**
 * @file
 *   @brief Extracted from QtGstreamer to avoid overly complex dependency
 *   @author Gus Grubba <mavlink@grubba.com>
 */

25
#pragma once
Gus Grubba's avatar
Gus Grubba committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

#include "../utils/bufferformat.h"
#include <QSize>
#include <QMutex>
#include <QMatrix4x4>

#include <QtQuick/QSGMaterial>

class VideoMaterialShader;

class VideoMaterial : public QSGMaterial
{
public:
    static VideoMaterial *create(const BufferFormat & format);

    virtual ~VideoMaterial();

    virtual int compare(const QSGMaterial *other) const;

    void setCurrentFrame(GstBuffer *buffer);
    void updateColors(int brightness, int contrast, int hue, int saturation);

    void bind();

protected:
    VideoMaterial();
    void initRgbTextureInfo(GLenum internalFormat, GLuint format,
53 54 55
                            GLenum type, const GstVideoInfo& videoInfo);
    void initYuv420PTextureInfo(const GstVideoInfo& videoInfo);
    void updateYuv420PTextureInfo(const GstVideoInfo& videoInfo);
Gus Grubba's avatar
Gus Grubba committed
56 57 58 59 60
    void init(GstVideoColorMatrix colorMatrixType);

private:
    void bindTexture(int i, const quint8 *data);

61 62
    GstVideoInfo m_videoInfo;
    GstBufferPool* m_bufferPool;
Gus Grubba's avatar
Gus Grubba committed
63 64 65 66 67 68 69 70 71
    GstBuffer *m_frame;
    QMutex m_frameMutex;

    static const int Num_Texture_IDs = 3;
    int m_textureCount;
    GLuint m_textureIds[Num_Texture_IDs];
    int m_textureWidths[Num_Texture_IDs];
    int m_textureHeights[Num_Texture_IDs];
    int m_textureOffsets[Num_Texture_IDs];
72 73
    int m_textureStrides[Num_Texture_IDs];
    bool m_textureAllocated[Num_Texture_IDs];
Gus Grubba's avatar
Gus Grubba committed
74 75 76 77 78 79 80 81 82 83 84

    GLenum m_textureFormat;
    GLuint m_textureInternalFormat;
    GLenum m_textureType;

    QMatrix4x4 m_colorMatrix;
    GstVideoColorMatrix m_colorMatrixType;

    friend class VideoMaterialShader;
};