|
1 /* This file is part of the KDE project. |
|
2 |
|
3 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 |
|
5 This library is free software: you can redistribute it and/or modify |
|
6 it under the terms of the GNU Lesser General Public License as published by |
|
7 the Free Software Foundation, either version 2.1 or 3 of the License. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 GNU Lesser General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Lesser General Public License |
|
15 along with this library. If not, see <http://www.gnu.org/licenses/>. |
|
16 */ |
|
17 |
|
18 #ifndef Phonon_GSTREAMER_MEDIAOBJECT_H |
|
19 #define Phonon_GSTREAMER_MEDIAOBJECT_H |
|
20 |
|
21 #include "backend.h" |
|
22 #include "common.h" |
|
23 #include "medianode.h" |
|
24 #include <phonon/mediaobjectinterface.h> |
|
25 #include <phonon/addoninterface.h> |
|
26 |
|
27 #include <QtCore/QHash> |
|
28 #include <QtCore/QString> |
|
29 #include <QtCore/QVariant> |
|
30 #include <QtCore/QObject> |
|
31 #include <QtCore/QDate> |
|
32 #include <QtCore/QEvent> |
|
33 #include <QtCore/QUrl> |
|
34 #include <gst/gst.h> |
|
35 |
|
36 QT_BEGIN_NAMESPACE |
|
37 |
|
38 class QTimer; |
|
39 typedef QMultiMap<QString, QString> TagMap; |
|
40 |
|
41 namespace Phonon |
|
42 { |
|
43 namespace Gstreamer |
|
44 { |
|
45 |
|
46 class VideoWidget; |
|
47 class AudioPath; |
|
48 class VideoPath; |
|
49 class AudioOutput; |
|
50 |
|
51 class MediaObject : public QObject, public MediaObjectInterface |
|
52 #ifndef QT_NO_PHONON_MEDIACONTROLLER |
|
53 , public AddonInterface |
|
54 #endif |
|
55 , public MediaNode |
|
56 { |
|
57 friend class Stream; |
|
58 Q_OBJECT |
|
59 Q_INTERFACES(Phonon::MediaObjectInterface |
|
60 #ifndef QT_NO_PHONON_MEDIACONTROLLER |
|
61 Phonon::AddonInterface |
|
62 #endif |
|
63 Phonon::Gstreamer::MediaNode |
|
64 ) |
|
65 |
|
66 public: |
|
67 |
|
68 MediaObject(Backend *backend, QObject *parent); |
|
69 ~MediaObject(); |
|
70 Phonon::State state() const; |
|
71 |
|
72 bool hasVideo() const; |
|
73 bool isSeekable() const; |
|
74 |
|
75 qint64 currentTime() const; |
|
76 qint32 tickInterval() const; |
|
77 |
|
78 void setTickInterval(qint32 newTickInterval); |
|
79 |
|
80 void play(); |
|
81 void pause(); |
|
82 void stop(); |
|
83 void seek(qint64 time); |
|
84 |
|
85 QString errorString() const; |
|
86 Phonon::ErrorType errorType() const; |
|
87 |
|
88 QUrl url() const; |
|
89 qint64 totalTime() const; |
|
90 |
|
91 qint32 prefinishMark() const; |
|
92 void setPrefinishMark(qint32 newPrefinishMark); |
|
93 |
|
94 qint32 transitionTime() const; |
|
95 void setTransitionTime(qint32); |
|
96 qint64 remainingTime() const; |
|
97 |
|
98 void setSource(const MediaSource &source); |
|
99 void setNextSource(const MediaSource &source); |
|
100 MediaSource source() const; |
|
101 |
|
102 // No additional interfaces currently supported |
|
103 #ifndef QT_NO_PHONON_MEDIACONTROLLER |
|
104 bool hasInterface(Interface) const; |
|
105 QVariant interfaceCall(Interface, int, const QList<QVariant> &); |
|
106 #endif |
|
107 bool isLoading() |
|
108 { |
|
109 return m_loading; |
|
110 } |
|
111 |
|
112 bool audioAvailable() |
|
113 { |
|
114 return m_hasAudio; |
|
115 } |
|
116 |
|
117 bool videoAvailable() |
|
118 { |
|
119 return m_hasVideo; |
|
120 } |
|
121 |
|
122 GstElement *audioGraph() |
|
123 { |
|
124 return m_audioGraph; |
|
125 } |
|
126 |
|
127 GstElement *videoGraph() |
|
128 { |
|
129 return m_videoGraph; |
|
130 } |
|
131 |
|
132 GstElement *pipeline() |
|
133 { |
|
134 return m_pipeline; |
|
135 }; |
|
136 |
|
137 gulong capsHandler() |
|
138 { |
|
139 return m_capsHandler; |
|
140 }; |
|
141 |
|
142 void connectVideo(GstPad *videoPad); |
|
143 void connectAudio(GstPad *audioPad); |
|
144 void handleBusMessage(const Message &msg); |
|
145 void handleEndOfStream(); |
|
146 void addMissingCodecName(const QString &codec) { m_missingCodecs.append(codec); } |
|
147 void invalidateGraph() { |
|
148 m_resetNeeded = true; |
|
149 if (m_state == Phonon::PlayingState || m_state == Phonon::PausedState) { |
|
150 changeState(Phonon::StoppedState); |
|
151 } |
|
152 } |
|
153 static void cb_newpad (GstElement *decodebin, GstPad *pad, gboolean last, gpointer data); |
|
154 static void cb_pad_added (GstElement *decodebin, GstPad *pad, gpointer data); |
|
155 static void cb_unknown_type (GstElement *decodebin, GstPad *pad, GstCaps *caps, gpointer data); |
|
156 static void cb_no_more_pads (GstElement * decodebin, gpointer data); |
|
157 void saveState(); |
|
158 void resumeState(); |
|
159 |
|
160 public Q_SLOTS: |
|
161 void setState(State); |
|
162 |
|
163 Q_SIGNALS: |
|
164 void currentSourceChanged(const MediaSource &newSource); |
|
165 void stateChanged(Phonon::State newstate, Phonon::State oldstate); |
|
166 void tick(qint64 time); |
|
167 void metaDataChanged(QMultiMap<QString, QString>); |
|
168 void seekableChanged(bool); |
|
169 void hasVideoChanged(bool); |
|
170 |
|
171 void finished(); |
|
172 void prefinishMarkReached(qint32); |
|
173 void aboutToFinish(); |
|
174 void totalTimeChanged(qint64 length); |
|
175 void bufferStatus(int percentFilled); |
|
176 |
|
177 QMultiMap<QString, QString> metaData(); |
|
178 void setMetaData(QMultiMap<QString, QString> newData); |
|
179 |
|
180 // AddonInterface: |
|
181 void titleChanged(int); |
|
182 void availableTitlesChanged(int); |
|
183 |
|
184 // Not implemented |
|
185 void chapterChanged(int); |
|
186 void availableChaptersChanged(int); |
|
187 void angleChanged(int); |
|
188 void availableAnglesChanged(int); |
|
189 |
|
190 void availableSubtitlesChanged(); |
|
191 void availableAudioChannelsChanged(); |
|
192 |
|
193 protected: |
|
194 void beginLoad(); |
|
195 void loadingComplete(); |
|
196 void newPadAvailable (GstPad *pad); |
|
197 void changeState(State); |
|
198 void setError(const QString &errorString, Phonon::ErrorType error = NormalError); |
|
199 /* |
|
200 * @param encodedUrl percent-encoded QString for source compat reasons. Should change to QUrl |
|
201 */ |
|
202 bool createPipefromURL(const QUrl &url); |
|
203 bool createPipefromStream(const MediaSource &); |
|
204 |
|
205 private Q_SLOTS: |
|
206 void noMorePadsAvailable(); |
|
207 void getStreamInfo(); |
|
208 void emitTick(); |
|
209 void beginPlay(); |
|
210 void setVideoCaps(GstCaps *caps); |
|
211 void notifyStateChange(Phonon::State newstate, Phonon::State oldstate); |
|
212 protected: |
|
213 GstElement *audioElement() |
|
214 { |
|
215 Q_ASSERT(m_audioPipe); |
|
216 return m_audioPipe; |
|
217 } |
|
218 |
|
219 GstElement *videoElement() |
|
220 { |
|
221 Q_ASSERT(m_videoPipe); |
|
222 return m_videoPipe; |
|
223 } |
|
224 |
|
225 private: |
|
226 |
|
227 // GStreamer specific : |
|
228 void createPipeline(); |
|
229 bool addToPipeline(GstElement *elem); |
|
230 void setTotalTime(qint64 newTime); |
|
231 void getStreamsInfo(); |
|
232 bool updateTotalTime(); |
|
233 void updateSeekable(); |
|
234 qint64 getPipelinePos() const; |
|
235 |
|
236 int _iface_availableTitles() const; |
|
237 int _iface_currentTitle() const; |
|
238 void _iface_setCurrentTitle(int title); |
|
239 |
|
240 bool m_resumeState; |
|
241 State m_oldState; |
|
242 quint64 m_oldPos; |
|
243 |
|
244 State m_state; |
|
245 State m_pendingState; |
|
246 QTimer *m_tickTimer; |
|
247 qint32 m_tickInterval; |
|
248 |
|
249 MediaSource m_source; |
|
250 MediaSource m_nextSource; |
|
251 qint32 m_prefinishMark; |
|
252 qint32 m_transitionTime; |
|
253 |
|
254 qint64 m_posAtSeek; |
|
255 |
|
256 bool m_prefinishMarkReachedNotEmitted; |
|
257 bool m_aboutToFinishEmitted; |
|
258 bool m_loading; |
|
259 gulong m_capsHandler; |
|
260 |
|
261 GstElement *m_datasource; |
|
262 GstElement *m_decodebin; |
|
263 |
|
264 GstElement *m_audioPipe; |
|
265 GstElement *m_videoPipe; |
|
266 |
|
267 qint64 m_totalTime; |
|
268 int m_bufferPercent; |
|
269 bool m_hasVideo; |
|
270 bool m_videoStreamFound; |
|
271 bool m_hasAudio; |
|
272 bool m_seekable; |
|
273 bool m_atEndOfStream; |
|
274 bool m_atStartOfStream; |
|
275 Phonon::ErrorType m_error; |
|
276 QString m_errorString; |
|
277 |
|
278 GstElement *m_pipeline; |
|
279 GstElement *m_audioGraph; |
|
280 GstElement *m_videoGraph; |
|
281 int m_previousTickTime; |
|
282 bool m_resetNeeded; |
|
283 QStringList m_missingCodecs; |
|
284 QMultiMap<QString, QString> m_metaData; |
|
285 bool m_autoplayTitles; |
|
286 int m_availableTitles; |
|
287 int m_currentTitle; |
|
288 }; |
|
289 } |
|
290 } //namespace Phonon::Gstreamer |
|
291 |
|
292 QT_END_NAMESPACE |
|
293 |
|
294 #endif // Phonon_GSTREAMER_MEDIAOBJECT_H |