File indexing completed on 2024-04-14 04:38:23

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) version 3, or any
0008     later version accepted by the membership of KDE e.V. (or its
0009     successor approved by the membership of KDE e.V.), Nokia Corporation
0010     (or its successors, if any) and the KDE Free Qt Foundation, which shall
0011     act as a proxy defined in Section 6 of version 3 of the license.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Lesser General Public License for more details.
0017 
0018     You should have received a copy of the GNU Lesser General Public
0019     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0020 
0021 */
0022 
0023 #include "abstractmediastream.h"
0024 #include "abstractmediastream_p.h"
0025 #include "mediaobjectinterface.h"
0026 #include "mediaobject_p.h"
0027 #include "phonondefs_p.h"
0028 #include "streaminterface_p.h"
0029 
0030 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
0031 
0032 namespace Phonon
0033 {
0034 
0035 AbstractMediaStream::AbstractMediaStream(QObject *parent)
0036     : QObject(parent),
0037     d_ptr(new AbstractMediaStreamPrivate)
0038 {
0039     d_ptr->q_ptr = this;
0040 }
0041 
0042 AbstractMediaStream::AbstractMediaStream(AbstractMediaStreamPrivate &dd, QObject *parent)
0043     : QObject(parent),
0044     d_ptr(&dd)
0045 {
0046     d_ptr->q_ptr = this;
0047 }
0048 
0049 AbstractMediaStream::~AbstractMediaStream()
0050 {
0051 }
0052 
0053 qint64 AbstractMediaStream::streamSize() const
0054 {
0055     return d_ptr->streamSize;
0056 }
0057 
0058 void AbstractMediaStream::setStreamSize(qint64 newSize)
0059 {
0060     d_ptr->setStreamSize(newSize);
0061 }
0062 
0063 void AbstractMediaStreamPrivate::setStreamSize(qint64 newSize)
0064 {
0065     streamSize = newSize;
0066     if (streamInterface) {
0067         streamInterface->setStreamSize(newSize);
0068     }
0069 }
0070 
0071 bool AbstractMediaStream::streamSeekable() const
0072 {
0073     return d_ptr->streamSeekable;
0074 }
0075 
0076 void AbstractMediaStream::setStreamSeekable(bool s)
0077 {
0078     d_ptr->setStreamSeekable(s);
0079 }
0080 
0081 void AbstractMediaStreamPrivate::setStreamSeekable(bool s)
0082 {
0083     streamSeekable = s;
0084     if (streamInterface) {
0085         streamInterface->setStreamSeekable(s);
0086     }
0087 }
0088 
0089 void AbstractMediaStream::writeData(const QByteArray &data)
0090 {
0091     d_ptr->writeData(data);
0092 }
0093 
0094 void AbstractMediaStreamPrivate::writeData(const QByteArray &data)
0095 {
0096     if (ignoreWrites) {
0097         return;
0098     }
0099     Q_ASSERT(streamInterface);
0100     streamInterface->writeData(data);
0101 }
0102 
0103 void AbstractMediaStream::endOfData()
0104 {
0105     d_ptr->endOfData();
0106 }
0107 
0108 void AbstractMediaStreamPrivate::endOfData()
0109 {
0110     if (streamInterface) {
0111         streamInterface->endOfData();
0112     }
0113 }
0114 
0115 void AbstractMediaStream::error(Phonon::ErrorType type, const QString &text)
0116 {
0117     Q_D(AbstractMediaStream);
0118     d->errorType = type;
0119     d->errorText = text;
0120     if (d->mediaObjectPrivate) {
0121         // TODO: MediaObject might be in a different thread
0122         d->mediaObjectPrivate->streamError(type, text);
0123     }
0124 }
0125 
0126 void AbstractMediaStream::enoughData()
0127 {
0128 }
0129 
0130 void AbstractMediaStream::seekStream(qint64)
0131 {
0132     Q_ASSERT(!d_ptr->streamSeekable);
0133 }
0134 
0135 AbstractMediaStreamPrivate::~AbstractMediaStreamPrivate()
0136 {
0137     if (mediaObjectPrivate) {
0138         // TODO: MediaObject might be in a different thread
0139         mediaObjectPrivate->removeDestructionHandler(this);
0140     }
0141     if (streamInterface) {
0142         // TODO: StreamInterface might be in a different thread
0143         streamInterface->d->disconnectMediaStream();
0144     }
0145 }
0146 
0147 void AbstractMediaStreamPrivate::setStreamInterface(StreamInterface *iface)
0148 {
0149     P_Q(AbstractMediaStream);
0150     streamInterface = iface;
0151     if (!iface) {
0152         // our subclass might be just about to call writeData, so tell it we have enoughData and
0153         // ignore the next writeData calls
0154         q->enoughData();
0155         ignoreWrites = true;
0156         return;
0157     }
0158     if (ignoreWrites) {
0159         ignoreWrites = false;
0160         // we had a StreamInterface before. The new StreamInterface expects us to start reading from
0161         // position 0
0162         q->reset();
0163     } else {
0164         iface->setStreamSize(streamSize);
0165         iface->setStreamSeekable(streamSeekable);
0166     }
0167 }
0168 
0169 void AbstractMediaStreamPrivate::setMediaObjectPrivate(MediaObjectPrivate *mop)
0170 {
0171     // TODO: MediaObject might be in a different thread
0172     mediaObjectPrivate = mop;
0173     mediaObjectPrivate->addDestructionHandler(this);
0174     if (!errorText.isEmpty()) {
0175         mediaObjectPrivate->streamError(errorType, errorText);
0176     }
0177 }
0178 
0179 void AbstractMediaStreamPrivate::phononObjectDestroyed(MediaNodePrivate *bp)
0180 {
0181     // TODO: MediaObject might be in a different thread
0182     Q_ASSERT(bp == mediaObjectPrivate);
0183     Q_UNUSED(bp);
0184     mediaObjectPrivate = nullptr;
0185 }
0186 
0187 } // namespace Phonon
0188 
0189 
0190 #include "moc_abstractmediastream.cpp"
0191 
0192 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
0193 
0194 // vim: sw=4 sts=4 et tw=100