Phonon

abstractmediastream2.h
1/* This file is part of the KDE project
2 Copyright (C) 2007-2008 Matthias Kretz <kretz@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), Nokia Corporation
10 (or its successors, if any) and the KDE Free Qt Foundation, which shall
11 act as a proxy defined in Section 6 of version 3 of the license.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23#ifndef PHONON_ABSTRACTMEDIASTREAM2_H
24#define PHONON_ABSTRACTMEDIASTREAM2_H
25
26#include "abstractmediastream.h"
27
28
29class QByteArray;
30
31namespace Phonon
32{
33class MediaObject;
34class AbstractMediaStream2Private;
35
36/** \class AbstractMediaStream2 abstractmediastream2.h phonon/AbstractMediaStream2
37 * \brief Base class for custom media data streams.
38 *
39 * Implement this class to provide a custom data stream to the backend. The class supports both, the
40 * push and the pull model.
41 *
42 * Push:
43 * \code
44 * PushStream::PushStream(QObject *parent)
45 * : AbstractMediaStream2(parent), m_timer(new QTimer(this))
46 * {
47 * setStreamSize(getMediaStreamSize());
48 *
49 * connect(m_timer, SIGNAL(timeout()), SLOT(moreData()));
50 * m_timer->setInterval(0);
51 * }
52 *
53 * void PushStream::moreData()
54 * {
55 * const QByteArray data = getMediaData();
56 * if (data.isEmpty()) {
57 * endOfData();
58 * } else {
59 * writeData(data);
60 * }
61 * }
62 *
63 * void PushStream::needData()
64 * {
65 * m_timer->start();
66 * moreData();
67 * }
68 *
69 * void PushStream::enoughData()
70 * {
71 * m_timer->stop();
72 * }
73 * \endcode
74 *
75 * Pull:
76 * \code
77 * PullStream::PullStream(QObject *parent)
78 * : AbstractMediaStream2(parent)
79 * {
80 * setStreamSize(getMediaStreamSize());
81 * }
82 *
83 * void PullStream::needData()
84 * {
85 * const QByteArray data = getMediaData();
86 * if (data.isEmpty()) {
87 * endOfData();
88 * } else {
89 * writeData(data);
90 * }
91 * }
92 * \endcode
93 *
94 * \ingroup Playback
95 * \author Matthias Kretz <kretz@kde.org>
96 */
97class PHONON_EXPORT AbstractMediaStream2 : public AbstractMediaStream
98{
99 Q_OBJECT
100 Q_DECLARE_PRIVATE(AbstractMediaStream2)
101 friend class MediaObject;
102 friend class MediaObjectPrivate;
103 friend class MediaSourcePrivate;
104 protected:
105 /////////////////////////////////////////////////////////////
106 // functions an implementation will call:
107 /////////////////////////////////////////////////////////////
108
109 /**
110 * Constructs an AbstractMediaStream2 object with a \p parent.
111 */
112 explicit AbstractMediaStream2(QObject *parent = 0);
113
114 void resetDone();
115 void seekStreamDone();
116
117 /////////////////////////////////////////////////////////////
118 // functions to implement:
119 /////////////////////////////////////////////////////////////
120
121 /**
122 * Reimplement this function to be notified when the backend needs data.
123 *
124 * When this function is called you should try to call writeData or endOfData before
125 * returning.
126 *
127 * \param size The number of bytes that are needed. If possible, pass \p size bytes of media
128 * data in the next writeData call.
129 */
130 virtual void needData(quint32 size) = 0;
131
132 /////////////////////////////////////////////////////////////
133 // internal
134 /////////////////////////////////////////////////////////////
135
136 bool event(QEvent *e);
137 AbstractMediaStream2(AbstractMediaStream2Private &dd, QObject *parent);
138
139 private:
140 // hide needData() explicitly
141 virtual void needData() {}
142
143 Q_PRIVATE_SLOT(d_func(), void _k_handleStreamEvent())
144};
145
146} // namespace Phonon
147
148
149#endif // PHONON_ABSTRACTMEDIASTREAM2_H
Base class for custom media data streams.
virtual void needData(quint32 size)=0
Reimplement this function to be notified when the backend needs data.
Base class for custom media data streams.
Interface for media playback of a given URL.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.