Phonon

abstractmediastream.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2007 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#include "abstractmediastream.h"
24#include "abstractmediastream_p.h"
25#include "mediaobjectinterface.h"
26#include "mediaobject_p.h"
27#include "phonondefs_p.h"
28#include "streaminterface_p.h"
29
30#ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
31
32namespace Phonon
33{
34
36 : QObject(parent),
37 d_ptr(new AbstractMediaStreamPrivate)
38{
39 d_ptr->q_ptr = this;
40}
41
42AbstractMediaStream::AbstractMediaStream(AbstractMediaStreamPrivate &dd, QObject *parent)
43 : QObject(parent),
44 d_ptr(&dd)
45{
46 d_ptr->q_ptr = this;
47}
48
49AbstractMediaStream::~AbstractMediaStream()
50{
51}
52
54{
55 return d_ptr->streamSize;
56}
57
59{
60 d_ptr->setStreamSize(newSize);
61}
62
63void AbstractMediaStreamPrivate::setStreamSize(qint64 newSize)
64{
65 streamSize = newSize;
66 if (streamInterface) {
67 streamInterface->setStreamSize(newSize);
68 }
69}
70
72{
73 return d_ptr->streamSeekable;
74}
75
77{
78 d_ptr->setStreamSeekable(s);
79}
80
81void AbstractMediaStreamPrivate::setStreamSeekable(bool s)
82{
83 streamSeekable = s;
84 if (streamInterface) {
85 streamInterface->setStreamSeekable(s);
86 }
87}
88
90{
91 d_ptr->writeData(data);
92}
93
94void AbstractMediaStreamPrivate::writeData(const QByteArray &data)
95{
96 if (ignoreWrites) {
97 return;
98 }
99 Q_ASSERT(streamInterface);
100 streamInterface->writeData(data);
101}
102
104{
105 d_ptr->endOfData();
106}
107
108void AbstractMediaStreamPrivate::endOfData()
109{
110 if (streamInterface) {
111 streamInterface->endOfData();
112 }
113}
114
115void AbstractMediaStream::error(Phonon::ErrorType type, const QString &text)
116{
118 d->errorType = type;
119 d->errorText = text;
120 if (d->mediaObjectPrivate) {
121 // TODO: MediaObject might be in a different thread
122 d->mediaObjectPrivate->streamError(type, text);
123 }
124}
125
129
131{
132 Q_ASSERT(!d_ptr->streamSeekable);
133}
134
135AbstractMediaStreamPrivate::~AbstractMediaStreamPrivate()
136{
137 if (mediaObjectPrivate) {
138 // TODO: MediaObject might be in a different thread
139 mediaObjectPrivate->removeDestructionHandler(this);
140 }
141 if (streamInterface) {
142 // TODO: StreamInterface might be in a different thread
143 streamInterface->d->disconnectMediaStream();
144 }
145}
146
147void AbstractMediaStreamPrivate::setStreamInterface(StreamInterface *iface)
148{
149 P_Q(AbstractMediaStream);
150 streamInterface = iface;
151 if (!iface) {
152 // our subclass might be just about to call writeData, so tell it we have enoughData and
153 // ignore the next writeData calls
154 q->enoughData();
155 ignoreWrites = true;
156 return;
157 }
158 if (ignoreWrites) {
159 ignoreWrites = false;
160 // we had a StreamInterface before. The new StreamInterface expects us to start reading from
161 // position 0
162 q->reset();
163 } else {
164 iface->setStreamSize(streamSize);
165 iface->setStreamSeekable(streamSeekable);
166 }
167}
168
169void AbstractMediaStreamPrivate::setMediaObjectPrivate(MediaObjectPrivate *mop)
170{
171 // TODO: MediaObject might be in a different thread
172 mediaObjectPrivate = mop;
173 mediaObjectPrivate->addDestructionHandler(this);
174 if (!errorText.isEmpty()) {
175 mediaObjectPrivate->streamError(errorType, errorText);
176 }
177}
178
179void AbstractMediaStreamPrivate::phononObjectDestroyed(MediaNodePrivate *bp)
180{
181 // TODO: MediaObject might be in a different thread
182 Q_ASSERT(bp == mediaObjectPrivate);
183 Q_UNUSED(bp);
184 mediaObjectPrivate = nullptr;
185}
186
187} // namespace Phonon
188
189
190#include "moc_abstractmediastream.cpp"
191
192#endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
193
194// vim: sw=4 sts=4 et tw=100
Base class for custom media data streams.
void writeData(const QByteArray &data)
Sends the media data to the backend for decoding.
bool streamSeekable() const
Returns whether your data stream is set as seekable.
void endOfData()
Tells the backend that the media data stream is at its end.
void setStreamSeekable(bool)
Sets whether your data stream is seekable.
virtual Q_INVOKABLE void seekStream(qint64 offset)
Reimplement this function if your stream is seekable.
virtual Q_INVOKABLE void enoughData()
Reimplement this function to be notified when the backend has enough data and your stream object may ...
qint64 streamSize() const
Returns the stream size that was set with setStreamSize.
AbstractMediaStream(QObject *parent=nullptr)
Constructs an AbstractMediaStream object with a parent.
void setStreamSize(qint64)
Sets the size of the stream in number of bytes.
void error(Phonon::ErrorType errorType, const QString &errorString)
If an I/O error occurs you should call this function to make MediaObject go into ErrorState.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:53:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.