~ubuntu-branches/ubuntu/precise/phonon-backend-gstreamer/precise-updates

« back to all changes in this revision

Viewing changes to gstreamer/mediaobject.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2011-01-24 10:38:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110124103826-k966exv2r89lgdcq
Tags: upstream-4.7.0really4.4.4
ImportĀ upstreamĀ versionĀ 4.7.0really4.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "medianode.h"
 
22
#include <phonon/mediaobjectinterface.h>
 
23
#include <phonon/addoninterface.h>
 
24
 
 
25
#include <QtCore/QObject>
 
26
#include <QtCore/QString>
 
27
#include <QtCore/QStringList>
 
28
#include <QtCore/QUrl>
 
29
#include <QtCore/QVariant>
 
30
 
 
31
#include <gst/pbutils/install-plugins.h>
 
32
 
 
33
#include "phonon-config-gstreamer.h"
 
34
 
 
35
QT_BEGIN_NAMESPACE
 
36
 
 
37
class QTimer;
 
38
typedef QMultiMap<QString, QString> TagMap;
 
39
 
 
40
namespace Phonon
 
41
{
 
42
namespace Gstreamer
 
43
{
 
44
 
 
45
class VideoWidget;
 
46
class AudioPath;
 
47
class VideoPath;
 
48
class AudioOutput;
 
49
 
 
50
class MediaObject : public QObject, public MediaObjectInterface
 
51
#ifndef QT_NO_PHONON_MEDIACONTROLLER
 
52
        , public AddonInterface
 
53
#endif
 
54
        , public MediaNode
 
55
{
 
56
    friend class Stream;
 
57
    friend class AudioDataOutput;
 
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
    MediaObject(Backend *backend, QObject *parent);
 
68
    ~MediaObject();
 
69
    Phonon::State state() const;
 
70
 
 
71
    bool hasVideo() const;
 
72
    bool isSeekable() const;
 
73
 
 
74
    qint64 currentTime() const;
 
75
    qint32 tickInterval() const;
 
76
 
 
77
    void setTickInterval(qint32 newTickInterval);
 
78
 
 
79
    void play();
 
80
    void pause();
 
81
    void stop();
 
82
    void seek(qint64 time);
 
83
 
 
84
    QString errorString() const;
 
85
    Phonon::ErrorType errorType() const;
 
86
 
 
87
    QUrl url() const;
 
88
    qint64 totalTime() const;
 
89
 
 
90
    qint32 prefinishMark() const;
 
91
    void setPrefinishMark(qint32 newPrefinishMark);
 
92
 
 
93
    qint32 transitionTime() const;
 
94
    void setTransitionTime(qint32);
 
95
    qint64 remainingTime() const;
 
96
 
 
97
    void setSource(const MediaSource &source);
 
98
    void setNextSource(const MediaSource &source);
 
99
    MediaSource source() const;
 
100
 
 
101
    // No additional interfaces currently supported
 
102
#ifndef QT_NO_PHONON_MEDIACONTROLLER
 
103
    bool hasInterface(Interface) const;
 
104
    QVariant interfaceCall(Interface, int, const QList<QVariant> &);
 
105
#endif
 
106
    bool isLoading()
 
107
    {
 
108
        return m_loading;
 
109
    }
 
110
 
 
111
    bool audioAvailable()
 
112
    {
 
113
        return m_hasAudio;
 
114
    }
 
115
 
 
116
    bool videoAvailable()
 
117
    {
 
118
        return m_hasVideo;
 
119
    }
 
120
 
 
121
    GstElement *audioGraph()
 
122
    {
 
123
        return m_audioGraph;
 
124
    }
 
125
 
 
126
    GstElement *videoGraph()
 
127
    {
 
128
        return m_videoGraph;
 
129
    }
 
130
 
 
131
    GstElement *pipeline()
 
132
    {
 
133
        return m_pipeline;
 
134
    };
 
135
 
 
136
    gulong capsHandler()
 
137
    {
 
138
        return m_capsHandler;
 
139
    };
 
140
 
 
141
    void connectVideo(GstPad *videoPad);
 
142
    void connectAudio(GstPad *audioPad);
 
143
    void handleBusMessage(const Message &msg);
 
144
    void handleTagMessage(GstMessage *msg);
 
145
    void handleStateMessage(GstMessage *msg);
 
146
    void handleErrorMessage(GstMessage *msg);
 
147
    void handleWarningMessage(GstMessage *msg);
 
148
    void handleBufferingMessage(GstMessage *msg);
 
149
    void handleElementMessage(GstMessage *msg);
 
150
    void handleDurationMessage(GstMessage *msg);
 
151
    void handleEOSMessage(GstMessage *msg);
 
152
    void handleEndOfStream();
 
153
    void addMissingCodecName(const QString &codec) { m_missingCodecs.append(codec); }
 
154
    void invalidateGraph();
 
155
 
 
156
    static void cb_newpad (GstElement *decodebin, GstPad *pad, gboolean last, gpointer data);
 
157
    static void cb_pad_added (GstElement *decodebin, GstPad *pad, gpointer data);
 
158
    static void cb_unknown_type (GstElement *decodebin, GstPad *pad, GstCaps *caps, gpointer data);
 
159
    void saveState();
 
160
    void resumeState();
 
161
 
 
162
public Q_SLOTS:
 
163
    void setState(State);
 
164
 
 
165
Q_SIGNALS:
 
166
    void currentSourceChanged(const MediaSource &newSource);
 
167
    void stateChanged(Phonon::State newstate, Phonon::State oldstate);
 
168
    void tick(qint64 time);
 
169
    void metaDataChanged(QMultiMap<QString, QString>);
 
170
    void seekableChanged(bool);
 
171
    void hasVideoChanged(bool);
 
172
 
 
173
    void finished();
 
174
    void prefinishMarkReached(qint32);
 
175
    void aboutToFinish();
 
176
    void totalTimeChanged(qint64 length);
 
177
    void bufferStatus(int percentFilled);
 
178
 
 
179
    QMultiMap<QString, QString> metaData();
 
180
    void setMetaData(QMultiMap<QString, QString> newData);
 
181
 
 
182
    // AddonInterface:
 
183
    void titleChanged(int);
 
184
    void availableTitlesChanged(int);
 
185
 
 
186
    // Not implemented
 
187
    void chapterChanged(int);
 
188
    void availableChaptersChanged(int);
 
189
    void angleChanged(int);
 
190
    void availableAnglesChanged(int);
 
191
 
 
192
    void availableSubtitlesChanged();
 
193
    void availableAudioChannelsChanged();
 
194
 
 
195
protected:
 
196
    void beginLoad();
 
197
    void loadingComplete();
 
198
    void newPadAvailable (GstPad *pad);
 
199
    void changeState(State);
 
200
    void setError(const QString &errorString, Phonon::ErrorType error = NormalError);
 
201
    /*
 
202
     * @param encodedUrl percent-encoded QString for source compat reasons.  Should change to QUrl
 
203
     */
 
204
    bool createPipefromURL(const QUrl &url);
 
205
    bool createPipefromStream(const MediaSource &);
 
206
    bool createPipefromDevice(const MediaSource &);
 
207
    bool createV4lPipe(const DeviceAccess &access, const MediaSource &);
 
208
 
 
209
    GstElement *audioElement()
 
210
    {
 
211
        Q_ASSERT(m_audioPipe);
 
212
        return m_audioPipe;
 
213
    }
 
214
 
 
215
    GstElement *videoElement()
 
216
    {
 
217
        Q_ASSERT(m_videoPipe);
 
218
        return m_videoPipe;
 
219
    }
 
220
 
 
221
private Q_SLOTS:
 
222
    void installMissingCodecs();
 
223
    void getStreamInfo();
 
224
    void emitTick();
 
225
    void beginPlay();
 
226
    void setVideoCaps(GstCaps *caps);
 
227
    void notifyStateChange(Phonon::State newstate, Phonon::State oldstate);
 
228
#ifdef PLUGIN_INSTALL_API
 
229
    void pluginInstallationResult(GstInstallPluginsReturn result);
 
230
#endif // PLUGIN_INSTALL_API
 
231
 
 
232
private:
 
233
    // GStreamer specific :
 
234
    void createPipeline();
 
235
    bool addToPipeline(GstElement *elem);
 
236
    void setTotalTime(qint64 newTime);
 
237
    void getStreamsInfo();
 
238
    bool updateTotalTime();
 
239
    void updateSeekable();
 
240
    qint64 getPipelinePos() const;
 
241
 
 
242
    int _iface_availableTitles() const;
 
243
    int _iface_currentTitle() const;
 
244
    void _iface_setCurrentTitle(int title);
 
245
    void setTrack(int title);
 
246
 
 
247
    // Plugin API callback
 
248
    static void pluginInstallationDone(GstInstallPluginsReturn result, gpointer userData);
 
249
 
 
250
    bool m_resumeState;
 
251
    State m_oldState;
 
252
    quint64 m_oldPos;
 
253
 
 
254
    State m_state;
 
255
    State m_pendingState;
 
256
    QTimer *m_tickTimer;
 
257
    qint32 m_tickInterval;
 
258
 
 
259
    MediaSource m_source;
 
260
    MediaSource m_nextSource;
 
261
    qint32 m_prefinishMark;
 
262
    qint32 m_transitionTime;
 
263
    bool m_isStream;
 
264
 
 
265
    qint64 m_posAtSeek;
 
266
 
 
267
    bool m_prefinishMarkReachedNotEmitted;
 
268
    bool m_aboutToFinishEmitted;
 
269
    bool m_loading;
 
270
    gulong m_capsHandler;
 
271
 
 
272
    GstElement *m_datasource;
 
273
    GstElement *m_decodebin;
 
274
 
 
275
    GstElement *m_audioPipe;
 
276
    GstElement *m_videoPipe;
 
277
 
 
278
    qint64 m_totalTime;
 
279
    int m_bufferPercent;
 
280
    bool m_hasVideo;
 
281
    bool m_videoStreamFound;
 
282
    bool m_hasAudio;
 
283
    bool m_seekable;
 
284
    bool m_atEndOfStream;
 
285
    bool m_atStartOfStream;
 
286
    Phonon::ErrorType m_error;
 
287
    QString m_errorString;
 
288
 
 
289
    GstElement *m_pipeline;
 
290
    GstElement *m_audioGraph;
 
291
    GstElement *m_videoGraph;
 
292
    int m_previousTickTime;
 
293
    bool m_resetNeeded;
 
294
    QStringList m_missingCodecs;
 
295
    QMultiMap<QString, QString> m_metaData;
 
296
    bool m_autoplayTitles;
 
297
    int m_availableTitles;
 
298
    int m_currentTitle;
 
299
    int m_pendingTitle;
 
300
    bool m_installingPlugin;
 
301
};
 
302
}
 
303
} //namespace Phonon::Gstreamer
 
304
 
 
305
QT_END_NAMESPACE
 
306
 
 
307
#endif // Phonon_GSTREAMER_MEDIAOBJECT_H