3 * Copyright (C) 2015 Alexandre Moreno <alexmorenocano@gmail.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
27 //#include <QtGui/qwindowdefs.h>
31 #include <gst/player/player.h>
33 namespace QGstPlayer {
42 class Player : public QObject
45 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
46 Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged)
47 Q_PROPERTY(qint64 position READ position NOTIFY positionUpdated)
48 Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged)
49 Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
50 Q_PROPERTY(int buffering READ buffering NOTIFY bufferingChanged)
51 Q_PROPERTY(QSize resolution READ resolution WRITE setResolution NOTIFY resolutionChanged)
52 Q_PROPERTY(State state READ state NOTIFY stateChanged)
53 Q_PROPERTY(QObject *mediaInfo READ mediaInfo NOTIFY mediaInfoChanged)
54 Q_PROPERTY(bool videoAvailable READ isVideoAvailable NOTIFY videoAvailableChanged)
55 Q_PROPERTY(QVariant currentVideo READ currentVideo WRITE setCurrentVideo)
56 Q_PROPERTY(QVariant currentAudio READ currentAudio WRITE setCurrentAudio)
57 Q_PROPERTY(QVariant currentSubtitle READ currentSubtitle WRITE setCurrentSubtitle)
58 Q_PROPERTY(bool subtitleEnabled READ isSubtitleEnabled WRITE setSubtitleEnabled
59 NOTIFY subtitleEnabledChanged)
60 Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay)
61 Q_PROPERTY(QList<QUrl> playlist READ playlist WRITE setPlaylist)
66 explicit Player(QObject *parent = 0, VideoRenderer *renderer = 0);
69 typedef GstPlayerError Error;
71 STOPPED = GST_PLAYER_STATE_STOPPED,
72 BUFFERING = GST_PLAYER_STATE_BUFFERING,
73 PAUSED = GST_PLAYER_STATE_PAUSED,
74 PLAYING = GST_PLAYER_STATE_PLAYING
78 qint64 duration() const;
79 qint64 position() const;
82 int buffering() const;
84 GstElement *pipeline() const;
85 QSize resolution() const;
86 void setResolution(QSize size);
87 bool isVideoAvailable() const;
88 MediaInfo *mediaInfo() const;
89 QVariant currentVideo() const;
90 QVariant currentAudio() const;
91 QVariant currentSubtitle() const;
92 bool isSubtitleEnabled() const;
93 bool autoPlay() const;
94 QList<QUrl> playlist() const;
97 void stateChanged(State new_state);
98 void bufferingChanged(int percent);
100 void positionUpdated(qint64 new_position);
101 void durationChanged(qint64 duration);
102 void resolutionChanged(QSize resolution);
103 void volumeChanged(qreal volume);
104 void mutedChanged(bool muted);
105 void mediaInfoChanged();
106 void sourceChanged(QUrl new_url);
107 void videoAvailableChanged(bool videoAvailable);
108 void subtitleEnabledChanged(bool enabled);
114 void seek(qint64 position);
115 void setSource(QUrl const& url);
116 void setVolume(qreal val);
117 void setMuted(bool val);
118 void setPosition(qint64 pos);
119 void setCurrentVideo(QVariant track);
120 void setCurrentAudio(QVariant track);
121 void setCurrentSubtitle(QVariant track);
122 void setSubtitleEnabled(bool enabled);
123 void setPlaylist(const QList<QUrl> &playlist);
126 void setAutoPlay(bool auto_play);
129 Q_DISABLE_COPY(Player)
130 static void onStateChanged(Player *, GstPlayerState state);
131 static void onPositionUpdated(Player *, GstClockTime position);
132 static void onDurationChanged(Player *, GstClockTime duration);
133 static void onBufferingChanged(Player *, int percent);
134 static void onVideoDimensionsChanged(Player *, int w, int h);
135 static void onVolumeChanged(Player *);
136 static void onMuteChanged(Player *);
137 static void onMediaInfoUpdated(Player *, GstPlayerMediaInfo *media_info);
138 static void onEndOfStreamReached(Player *);
140 void setUri(QUrl url);
144 QSize videoDimensions_;
145 MediaInfo *mediaInfo_;
146 bool videoAvailable_;
147 bool subtitleEnabled_;
149 QList<QUrl> playlist_;
150 QList<QUrl>::iterator iter_;
156 GstPlayerVideoRenderer *renderer();
157 virtual GstElement *createVideoSink() = 0;
160 virtual ~VideoRenderer();
162 GstPlayerVideoRenderer *renderer_;
165 class MediaInfo : public QObject
168 Q_PROPERTY(QString uri READ uri NOTIFY uriChanged)
169 Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged)
170 Q_PROPERTY(QString title READ title NOTIFY titleChanged)
171 Q_PROPERTY(QList<QObject*> videoStreams READ videoStreams CONSTANT)
172 Q_PROPERTY(QList<QObject*> audioStreams READ audioStreams CONSTANT)
173 Q_PROPERTY(QList<QObject*> subtitleStreams READ subtitleStreams CONSTANT)
174 Q_PROPERTY(QImage sample READ sample NOTIFY sampleChanged)
177 explicit MediaInfo(Player *player = 0);
179 QString title() const;
180 bool isSeekable() const;
181 const QList<QObject*> &videoStreams() const;
182 const QList<QObject*> &audioStreams() const;
183 const QList<QObject*> &subtitleStreams() const;
184 const QImage &sample();
188 void seekableChanged();
190 void sampleChanged();
193 void update(GstPlayerMediaInfo *info);
198 QList<QObject*> videoStreams_;
199 QList<QObject*> audioStreams_;
200 QList<QObject*> subtitleStreams_;
204 class StreamInfo : public QObject
207 Q_PROPERTY(int index READ index CONSTANT)
212 StreamInfo(GstPlayerStreamInfo* info);
214 GstPlayerStreamInfo *stream_;
218 class VideoInfo : public StreamInfo
221 Q_PROPERTY(QSize resolution READ resolution CONSTANT)
223 VideoInfo(GstPlayerVideoInfo *info);
224 QSize resolution() const;
227 GstPlayerVideoInfo *video_;
231 class AudioInfo : public StreamInfo
234 Q_PROPERTY(QString language READ language CONSTANT)
235 Q_PROPERTY(int channels READ channels CONSTANT)
236 Q_PROPERTY(int bitRate READ bitRate CONSTANT)
237 Q_PROPERTY(int sampleRate READ sampleRate CONSTANT)
240 AudioInfo(GstPlayerAudioInfo *info);
241 QString const& language() const;
242 int channels() const;
244 int sampleRate() const;
247 GstPlayerAudioInfo *audio_;
254 class SubtitleInfo : public StreamInfo
257 Q_PROPERTY(QString language READ language CONSTANT)
259 SubtitleInfo(GstPlayerSubtitleInfo *info);
260 QString const& language() const;
263 GstPlayerSubtitleInfo *subtitle_;
269 Q_DECLARE_METATYPE(QGstPlayer::Player*)
270 Q_DECLARE_METATYPE(QGstPlayer::Player::State)
271 Q_DECLARE_METATYPE(QGstPlayer::MediaInfo*)
275 typedef struct _GstPlayerQtVideoRenderer
276 GstPlayerQtVideoRenderer;
278 typedef struct _GstPlayerQtVideoRendererClass
279 GstPlayerQtVideoRendererClass;
281 #define GST_TYPE_PLAYER_QT_VIDEO_RENDERER (gst_player_qt_video_renderer_get_type ())
282 #define GST_IS_PLAYER_QT_VIDEO_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PLAYER_QT_VIDEO_RENDERER))
283 #define GST_IS_PLAYER_QT_VIDEO_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PLAYER_QT_VIDEO_RENDERER))
284 #define GST_PLAYER_QT_VIDEO_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PLAYER_QT_VIDEO_RENDERER, GstPlayerQtVideoRendererClass))
285 #define GST_PLAYER_QT_VIDEO_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PLAYER_QT_VIDEO_RENDERER, GstPlayerQtVideoRenderer))
286 #define GST_PLAYER_QT_VIDEO_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PLAYER_QT_VIDEO_RENDERER, GstPlayerQtVideoRendererClass))
287 #define GST_PLAYER_QT_VIDEO_RENDERER_CAST(obj) ((GstPlayerQtVideoRenderer*)(obj))
289 GType gst_player_qt_video_renderer_get_type (void);
291 typedef struct _GstPlayerQtSignalDispatcher
292 GstPlayerQtSignalDispatcher;
294 typedef struct _GstPlayerQtSignalDispatcherClass
295 GstPlayerQtSignalDispatcherClass;
297 #define GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER (gst_player_qt_signal_dispatcher_get_type ())
298 #define GST_IS_PLAYER_QT_SIGNAL_DISPATCHER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER))
299 #define GST_IS_PLAYER_QT_SIGNAL_DISPATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER))
300 #define GST_PLAYER_QT_SIGNAL_DISPATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER, GstPlayerQtSignalDispatcherClass))
301 #define GST_PLAYER_QT_SIGNAL_DISPATCHER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER, GstPlayerQtSignalDispatcher))
302 #define GST_PLAYER_QT_SIGNAL_DISPATCHER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PLAYER_QT_SIGNAL_DISPATCHER, GstPlayerQtSignalDispatcherClass))
303 #define GST_PLAYER_QT_SIGNAL_DISPATCHER_CAST(obj) ((GstPlayerQtSignalDispatcher*)(obj))
305 GType gst_player_qt_video_renderer_get_type (void);
307 GstPlayerSignalDispatcher *
308 gst_player_qt_signal_dispatcher_new (gpointer player);
312 #endif // QGSTPLAYER_H