summaryrefslogtreecommitdiff
path: root/elements/gstqtvideosink/gstqtvideosinksurface.h
blob: ee3b74e5ec6d9bb68c520aba65daf0aaf03d87a7 (plain)
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
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
    Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). <qt-info@nokia.com>
    Copyright (C) 2011 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 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/>.
*/

#ifndef GST_QT_VIDEO_SINK_SURFACE_H
#define GST_QT_VIDEO_SINK_SURFACE_H

#include "gstqtvideosinkbase.h"
#include "bufferformat.h"
#include "abstractsurfacepainter.h"

#include <QtCore/QObject>
#include <QtCore/QEvent>
#include <QtCore/QSet>
#include <QtCore/QReadWriteLock>

class QGLContext;


class GstQtVideoSinkSurface : public QObject
{
    Q_OBJECT
public:
    enum EventType {
        BufferEventType = QEvent::User,
        DeactivateEventType
    };

    //-------------------------------------

    class BufferEvent : public QEvent
    {
    public:
        inline BufferEvent(GstBuffer *buf, bool formatDirty)
            : QEvent(static_cast<QEvent::Type>(BufferEventType)),
              buffer(gst_buffer_ref(buf)),
              formatDirty(formatDirty)
        {
        }

        GstBuffer *buffer;
        bool formatDirty;
    };

    //-------------------------------------

    class DeactivateEvent : public QEvent
    {
    public:
        inline DeactivateEvent()
            : QEvent(static_cast<QEvent::Type>(DeactivateEventType))
        {
        }
    };

    //-------------------------------------

    explicit GstQtVideoSinkSurface(GstQtVideoSinkBase *sink, QObject *parent = 0);
    ~GstQtVideoSinkSurface();

    // API for GstQtVideoSink

    QSet<GstVideoFormat> supportedPixelFormats() const;

    bool isActive() const;
    void setActive(bool playing);

    // GstColorBalance interface

    int brightness() const;
    void setBrightness(int brightness);

    int contrast() const;
    void setContrast(int contrast);

    int hue() const;
    void setHue(int hue);

    int saturation() const;
    void setSaturation(int saturation);

    // force-aspect-ratio property

    bool forceAspectRatio() const;
    void setForceAspectRatio(bool force);

    // glcontext property

#ifndef GST_QT_VIDEO_SINK_NO_OPENGL
    QGLContext *glContext() const;
    void setGLContext(QGLContext *context);

    enum ShaderType
    {
        NoShaders = 0x00,
        FragmentProgramShader = 0x01,
        GlslShader = 0x02
    };

    Q_DECLARE_FLAGS(ShaderTypes, ShaderType)
#endif

    // paint action signal

    void paint(QPainter *painter, qreal x, qreal y, qreal width, qreal height);

protected:
    bool event(QEvent *event);

private:
    void changePainter(const BufferFormat & format);
    void destroyPainter();


    AbstractSurfacePainter *m_painter;

#ifndef GST_QT_VIDEO_SINK_NO_OPENGL
    QGLContext *m_glContext;
    ShaderTypes m_supportedShaderTypes;
    ShaderType m_shaderType;
#endif

    // colorbalance interface properties
    mutable QReadWriteLock m_colorsLock;
    bool m_colorsDirty;
    int m_brightness;
    int m_contrast;
    int m_hue;
    int m_saturation;

    // force-aspect-ratio property
    mutable QReadWriteLock m_forceAspectRatioLock;
    bool m_forceAspectRatioDirty;
    bool m_forceAspectRatio;

    // format caching
    bool m_formatDirty;
    BufferFormat m_bufferFormat;
    PaintAreas m_areas;
    QRectF m_clipRect;

    // whether the sink is active (PAUSED or PLAYING)
    mutable QReadWriteLock m_isActiveLock;
    bool m_isActive;

    // the buffer to be drawn next
    GstBuffer *m_buffer;

    GstQtVideoSinkBase *m_sink;
};

#ifndef GST_QT_VIDEO_SINK_NO_OPENGL
Q_DECLARE_OPERATORS_FOR_FLAGS(GstQtVideoSinkSurface::ShaderTypes)
#endif

#endif // GST_QT_VIDEO_SINK_SURFACE_H