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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
/* This file is part of the KDE project.
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
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 or 3 of the License.
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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef Phonon_GSTREAMER_MEDIAOBJECT_H
#define Phonon_GSTREAMER_MEDIAOBJECT_H
#include "backend.h"
#include "common.h"
#include "medianode.h"
#include <phonon/mediaobjectinterface.h>
#include <phonon/addoninterface.h>
#include <QtCore/QHash>
#include <QtCore/QString>
#include <QtCore/QVariant>
#include <QtCore/QObject>
#include <QtCore/QDate>
#include <QtCore/QEvent>
#include <QtCore/QUrl>
#include <gst/gst.h>
QT_BEGIN_NAMESPACE
class QTimer;
typedef QMultiMap<QString, QString> TagMap;
namespace Phonon
{
namespace Gstreamer
{
class VideoWidget;
class AudioPath;
class VideoPath;
class AudioOutput;
class MediaObject : public QObject, public MediaObjectInterface, public AddonInterface, public MediaNode
{
friend class Stream;
Q_OBJECT
Q_INTERFACES(Phonon::MediaObjectInterface Phonon::AddonInterface Phonon::Gstreamer::MediaNode)
public:
MediaObject(Backend *backend, QObject *parent);
~MediaObject();
Phonon::State state() const;
bool hasVideo() const;
bool isSeekable() const;
qint64 currentTime() const;
qint32 tickInterval() const;
void setTickInterval(qint32 newTickInterval);
void play();
void pause();
void stop();
void seek(qint64 time);
QString errorString() const;
Phonon::ErrorType errorType() const;
QUrl url() const;
qint64 totalTime() const;
qint32 prefinishMark() const;
void setPrefinishMark(qint32 newPrefinishMark);
qint32 transitionTime() const;
void setTransitionTime(qint32);
qint64 remainingTime() const;
void setSource(const MediaSource &source);
void setNextSource(const MediaSource &source);
MediaSource source() const;
// No additional interfaces currently supported
bool hasInterface(Interface) const
{
return false;
}
QVariant interfaceCall(Interface, int, const QList<QVariant> &)
{
return QVariant();
}
bool isLoading()
{
return m_loading;
}
bool audioAvailable()
{
return m_hasAudio;
}
bool videoAvailable()
{
return m_hasVideo;
}
GstElement *audioGraph()
{
return m_audioGraph;
}
GstElement *videoGraph()
{
return m_videoGraph;
}
GstElement *pipeline()
{
return m_pipeline;
};
gulong capsHandler()
{
return m_capsHandler;
};
void connectVideo(GstPad *videoPad);
void connectAudio(GstPad *audioPad);
void handleBusMessage(const Message &msg);
void handleEndOfStream();
void addMissingCodecName(const QString &codec) { m_missingCodecs.append(codec); }
void invalidateGraph() {
m_resetNeeded = true;
if (m_state == Phonon::PlayingState || m_state == Phonon::PausedState) {
changeState(Phonon::StoppedState);
}
}
static void cb_newpad (GstElement *decodebin, GstPad *pad, gboolean last, gpointer data);
static void cb_pad_added (GstElement *decodebin, GstPad *pad, gpointer data);
static void cb_unknown_type (GstElement *decodebin, GstPad *pad, GstCaps *caps, gpointer data);
static void cb_no_more_pads (GstElement * decodebin, gpointer data);
void saveState();
void resumeState();
public Q_SLOTS:
void setState(State);
Q_SIGNALS:
void currentSourceChanged(const MediaSource &newSource);
void stateChanged(Phonon::State newstate, Phonon::State oldstate);
void tick(qint64 time);
void metaDataChanged(QMultiMap<QString, QString>);
void seekableChanged(bool);
void hasVideoChanged(bool);
void finished();
void prefinishMarkReached(qint32);
void aboutToFinish();
void totalTimeChanged(qint64 length);
void bufferStatus(int percentFilled);
QMultiMap<QString, QString> metaData();
void setMetaData(QMultiMap<QString, QString> newData);
protected:
void beginLoad();
void loadingComplete();
void newPadAvailable (GstPad *pad);
void changeState(State);
void setError(const QString &errorString, Phonon::ErrorType error = NormalError);
/*
* @param encodedUrl percent-encoded QString for source compat reasons. Should change to QUrl
*/
bool createPipefromURL(const QUrl &url);
bool createPipefromStream(const MediaSource &);
private Q_SLOTS:
void noMorePadsAvailable();
void getStreamInfo();
void emitTick();
void beginPlay();
void setVideoCaps(GstCaps *caps);
void notifyStateChange(Phonon::State newstate, Phonon::State oldstate);
protected:
GstElement *audioElement()
{
Q_ASSERT(m_audioPipe);
return m_audioPipe;
}
GstElement *videoElement()
{
Q_ASSERT(m_videoPipe);
return m_videoPipe;
}
private:
// GStreamer specific :
void createPipeline();
bool addToPipeline(GstElement *elem);
void setTotalTime(qint64 newTime);
void getStreamsInfo();
bool updateTotalTime();
void updateSeekable();
qint64 getPipelinePos() const;
bool m_resumeState;
State m_oldState;
quint64 m_oldPos;
State m_state;
State m_pendingState;
QTimer *m_tickTimer;
qint32 m_tickInterval;
MediaSource m_source;
MediaSource m_nextSource;
qint32 m_prefinishMark;
qint32 m_transitionTime;
qint64 m_posAtSeek;
bool m_prefinishMarkReachedNotEmitted;
bool m_aboutToFinishEmitted;
bool m_loading;
gulong m_capsHandler;
GstElement *m_datasource;
GstElement *m_decodebin;
GstElement *m_audioPipe;
GstElement *m_videoPipe;
qint64 m_totalTime;
int m_bufferPercent;
bool m_hasVideo;
bool m_videoStreamFound;
bool m_hasAudio;
bool m_seekable;
bool m_atEndOfStream;
bool m_atStartOfStream;
Phonon::ErrorType m_error;
QString m_errorString;
GstElement *m_pipeline;
GstElement *m_audioGraph;
GstElement *m_videoGraph;
int m_previousTickTime;
bool m_resetNeeded;
QStringList m_missingCodecs;
QMultiMap<QString, QString> m_metaData;
};
}
} //namespace Phonon::Gstreamer
QT_END_NAMESPACE
#endif // Phonon_GSTREAMER_MEDIAOBJECT_H
|