-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGStreamerPlayer.h
182 lines (149 loc) · 4.55 KB
/
GStreamerPlayer.h
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
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
Copyright (C) 2010 Marco Ballesio <[email protected]>
Copyright (C) 2011-2013 Collabora Ltd.
@author George Kiagiadakis <[email protected]>
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
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/>.
*/
#ifndef GStreamerPlayer_H
#define GStreamerPlayer_H
#include <QObject>
#include <QTimer>
#include <QGst/Pipeline>
#include <QGst/Message>
class GStreamerPlayer : public QObject
{
Q_OBJECT
public:
Q_PROPERTY(int brightness READ getBrightness WRITE setBrightness NOTIFY brightnessChanged)
Q_PROPERTY(int contrast READ getContrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(int hue READ getHue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(int saturation READ getSaturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(bool playing READ getPlaying WRITE setPlaying NOTIFY playingChanged)
Q_PROPERTY(bool paused READ getPaused WRITE setPaused NOTIFY pausedChanged)
Q_PROPERTY(bool stopped READ getStopped WRITE setStopped NOTIFY stoppedChanged)
explicit GStreamerPlayer(QObject *parent = 0);
~GStreamerPlayer();
void setVideoSink(const QGst::ElementPtr & sink);
int getBrightness()
{
m_brightness = m_videoSink->property("brightness").toInt();
return m_brightness;
}
int getContrast()
{
m_contrast = m_videoSink->property("contrast").toInt();
return m_contrast;
}
int getHue()
{
m_hue = m_videoSink->property("hue").toInt();
return m_hue;
}
int getSaturation()
{
m_saturation = m_videoSink->property("saturation").toInt();
return m_saturation;
}
bool getPlaying()
{
return m_playing;
}
bool getPaused()
{
return m_paused;
}
bool getStopped()
{
return m_stopped;
}
void setPlaying(bool play)
{
play ? m_playing = this->play() : m_playing = false;
emit playingChanged(m_playing);
}
void setPaused(bool pause)
{
m_paused = pause;
emit pausedChanged(m_paused);
this->pause();
}
void setStopped(bool)
{
// First send EOS in case the stream is going to a file
if (!m_stopTimer.isActive())
{
sendEOS();
m_stopTimer.start(1000);
}
}
void setBrightness(int brightness)
{
m_brightness = brightness;
emit brightnessChanged(brightness);
m_videoSink->setProperty("brightness", brightness);
}
void setContrast(int contrast)
{
m_contrast = contrast;
emit contrastChanged(contrast);
m_videoSink->setProperty("contrast", contrast);
}
void setHue(int hue)
{
m_hue = hue;
emit hueChanged(hue);
m_videoSink->setProperty("hue", hue);
}
void setSaturation(int saturation)
{
m_saturation = saturation;
emit saturationChanged(saturation);
m_videoSink->setProperty("saturation", saturation);
}
public Q_SLOTS:
bool play();
void pause();
void stop();
void toggleFullScreen();
void onStopTimer();
void initialize();
void setPipelineString(const QString & pipelineString)
{
m_pipelineString = pipelineString;
}
signals:
void brightnessChanged(int);
void contrastChanged(int);
void hueChanged(int);
void saturationChanged(int);
void playingChanged(bool);
void pausedChanged(bool);
void stoppedChanged(bool);
void messageBox(QString text);
private:
void onBusMessage(const QGst::MessagePtr & message);
void handlePipelineStateChange(const QGst::StateChangedMessagePtr & scm);
void sendEOS();
QTimer m_stopTimer;
QGst::PipelinePtr m_pipeline;
QGst::ElementPtr m_videoSink;
QString m_currentPipelineString;
QString m_pipelineString;
int m_brightness;
int m_contrast;
int m_hue;
int m_saturation;
bool m_playing;
bool m_paused;
bool m_stopped;
};
#endif // GStreamerPlayer_H