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
|
/* GStreamer
*
* Copyright (C) 2015 Alexandre Moreno <alexmorenocano@gmail.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 QGSTPLAYER_H
#define QGSTPLAYER_H
#include <QObject>
#include <QUrl>
#include <QSize>
//#include <QtGui/qwindowdefs.h>
#include <QtQml/QQmlPropertyMap>
#include <gst/player/player.h>
class QGstPlayer : public QObject
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
Q_PROPERTY(qint64 position READ position NOTIFY positionChanged)
Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
Q_PROPERTY(int buffering READ buffering NOTIFY bufferingChanged)
Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
Q_PROPERTY(QObject *mediaInfo READ mediaInfo NOTIFY mediaInfoChanged)
Q_PROPERTY(bool videoAvailable READ isVideoAvailable NOTIFY videoAvailableChanged)
Q_ENUMS(State)
public:
class VideoRenderer;
explicit QGstPlayer(QObject *parent = 0, VideoRenderer *renderer = 0);
typedef GstPlayerError Error;
enum State {
STOPPED = GST_PLAYER_STATE_STOPPED,
BUFFERING = GST_PLAYER_STATE_BUFFERING,
PAUSED = GST_PLAYER_STATE_PAUSED,
PLAYING = GST_PLAYER_STATE_PLAYING
};
class VideoRenderer
{
public:
GstPlayerVideoRenderer *renderer();
virtual GstElement *createVideoSink() = 0;
protected:
VideoRenderer();
virtual ~VideoRenderer();
private:
GstPlayerVideoRenderer *renderer_;
};
// TODO add remaining bits
class MediaInfo
{
public:
MediaInfo(GstPlayerMediaInfo *media_info);
QString title() const;
bool isSeekable() const;
private:
GstPlayerMediaInfo *mediaInfo_;
};
QUrl source() const;
qint64 duration() const;
qint64 position() const;
qreal volume() const;
bool isMuted() const;
int buffering() const;
State state() const;
GstElement *pipeline() const;
QSize resolution() const;
void setResolution(QSize size);
bool isVideoAvailable() const;
QQmlPropertyMap *mediaInfo() const;
signals:
void stateChanged(State new_state);
void bufferingChanged(int percent);
void enfOfStream();
void positionChanged(qint64 new_position);
void durationChanged(qint64 duration);
void resolutionChanged(QSize resolution);
void volumeChanged(qreal volume);
void mutedChanged(bool muted);
void mediaInfoChanged();
void sourceChanged(QUrl new_url);
void videoAvailableChanged(bool videoAvailable);
public slots:
void play();
void pause();
void stop();
void seek(qint64 position);
void setSource(QUrl const& url);
void setVolume(qreal val);
void setMuted(bool val);
void setPosition(qint64 pos);
private:
Q_DISABLE_COPY(QGstPlayer)
static void onStateChanged(QGstPlayer *, GstPlayerState state);
static void onPositionUpdated(QGstPlayer *, GstClockTime position);
static void onDurationChanged(QGstPlayer *, GstClockTime duration);
static void onBufferingChanged(QGstPlayer *, int percent);
static void onVideoDimensionsChanged(QGstPlayer *, int w, int h);
static void onVolumeChanged(QGstPlayer *);
static void onMuteChanged(QGstPlayer *);
static void onMediaInfoUpdated(QGstPlayer *, GstPlayerMediaInfo *media_info);
GstPlayer *player_;
State state_;
QSize videoDimensions_;
QQmlPropertyMap *mediaInfoMap_;
bool videoAvailable_;
};
Q_DECLARE_METATYPE(QGstPlayer*)
Q_DECLARE_METATYPE(QGstPlayer::State)
extern "C" {
typedef struct _GstPlayerQtVideoRenderer
GstPlayerQtVideoRenderer;
typedef struct _GstPlayerQtVideoRendererClass
GstPlayerQtVideoRendererClass;
#define GST_TYPE_PLAYER_QT_VIDEO_RENDERER (gst_player_qt_video_renderer_get_type ())
#define GST_IS_PLAYER_QT_VIDEO_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PLAYER_QT_VIDEO_RENDERER))
#define GST_IS_PLAYER_QT_VIDEO_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PLAYER_QT_VIDEO_RENDERER))
#define GST_PLAYER_QT_VIDEO_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PLAYER_QT_VIDEO_RENDERER, GstPlayerQtVideoRendererClass))
#define GST_PLAYER_QT_VIDEO_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PLAYER_QT_VIDEO_RENDERER, GstPlayerQtVideoRenderer))
#define GST_PLAYER_QT_VIDEO_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PLAYER_QT_VIDEO_RENDERER, GstPlayerQtVideoRendererClass))
#define GST_PLAYER_QT_VIDEO_RENDERER_CAST(obj) ((GstPlayerQtVideoRenderer*)(obj))
GType gst_player_qt_video_renderer_get_type (void);
typedef struct _GstPlayerQtSignalDispatcher
GstPlayerQtSignalDispatcher;
typedef struct _GstPlayerQtSignalDispatcherClass
GstPlayerQtSignalDispatcherClass;
#define GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER (gst_player_qt_signal_dispatcher_get_type ())
#define GST_IS_PLAYER_QT_SIGNAL_DISPATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER))
#define GST_IS_PLAYER_QT_SIGNAL_DISPATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER))
#define GST_PLAYER_QT_SIGNAL_DISPATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER, GstPlayerQtSignalDispatcherClass))
#define GST_PLAYER_QT_SIGNAL_DISPATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER, GstPlayerQtSignalDispatcher))
#define GST_PLAYER_QT_SIGNAL_DISPATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER, GstPlayerQtSignalDispatcherClass))
#define GST_PLAYER_QT_SIGNAL_DISPATCHER_CAST(obj) ((GstPlayerQtSignalDispatcher*)(obj))
GType gst_player_qt_video_renderer_get_type (void);
GstPlayerSignalDispatcher *
gst_player_qt_signal_dispatcher_new (gpointer player);
}
#endif // QGSTPLAYER_H
|