| 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 | |
| 32 | namespace Phonon |
| 33 | { |
| 34 | |
| 35 | AbstractMediaStream::AbstractMediaStream(QObject *parent) |
| 36 | : QObject(parent), |
| 37 | d_ptr(new AbstractMediaStreamPrivate) |
| 38 | { |
| 39 | d_ptr->q_ptr = this; |
| 40 | } |
| 41 | |
| 42 | AbstractMediaStream::AbstractMediaStream(AbstractMediaStreamPrivate &dd, QObject *parent) |
| 43 | : QObject(parent), |
| 44 | d_ptr(&dd) |
| 45 | { |
| 46 | d_ptr->q_ptr = this; |
| 47 | } |
| 48 | |
| 49 | AbstractMediaStream::~AbstractMediaStream() |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | qint64 AbstractMediaStream::streamSize() const |
| 54 | { |
| 55 | return d_ptr->streamSize; |
| 56 | } |
| 57 | |
| 58 | void AbstractMediaStream::setStreamSize(qint64 newSize) |
| 59 | { |
| 60 | d_ptr->setStreamSize(newSize); |
| 61 | } |
| 62 | |
| 63 | void AbstractMediaStreamPrivate::setStreamSize(qint64 newSize) |
| 64 | { |
| 65 | streamSize = newSize; |
| 66 | if (streamInterface) { |
| 67 | streamInterface->setStreamSize(newSize); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | bool AbstractMediaStream::streamSeekable() const |
| 72 | { |
| 73 | return d_ptr->streamSeekable; |
| 74 | } |
| 75 | |
| 76 | void AbstractMediaStream::setStreamSeekable(bool s) |
| 77 | { |
| 78 | d_ptr->setStreamSeekable(s); |
| 79 | } |
| 80 | |
| 81 | void AbstractMediaStreamPrivate::setStreamSeekable(bool s) |
| 82 | { |
| 83 | streamSeekable = s; |
| 84 | if (streamInterface) { |
| 85 | streamInterface->setStreamSeekable(s); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | void AbstractMediaStream::writeData(const QByteArray &data) |
| 90 | { |
| 91 | d_ptr->writeData(data); |
| 92 | } |
| 93 | |
| 94 | void AbstractMediaStreamPrivate::writeData(const QByteArray &data) |
| 95 | { |
| 96 | if (ignoreWrites) { |
| 97 | return; |
| 98 | } |
| 99 | Q_ASSERT(streamInterface); |
| 100 | streamInterface->writeData(data); |
| 101 | } |
| 102 | |
| 103 | void AbstractMediaStream::endOfData() |
| 104 | { |
| 105 | d_ptr->endOfData(); |
| 106 | } |
| 107 | |
| 108 | void AbstractMediaStreamPrivate::endOfData() |
| 109 | { |
| 110 | if (streamInterface) { |
| 111 | streamInterface->endOfData(); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | void AbstractMediaStream::error(Phonon::ErrorType type, const QString &text) |
| 116 | { |
| 117 | Q_D(AbstractMediaStream); |
| 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 | |
| 126 | void AbstractMediaStream::enoughData() |
| 127 | { |
| 128 | } |
| 129 | |
| 130 | void AbstractMediaStream::seekStream(qint64) |
| 131 | { |
| 132 | Q_ASSERT(!d_ptr->streamSeekable); |
| 133 | } |
| 134 | |
| 135 | AbstractMediaStreamPrivate::~AbstractMediaStreamPrivate() |
| 136 | { |
| 137 | if (mediaObjectPrivate) { |
| 138 | // TODO: MediaObject might be in a different thread |
| 139 | mediaObjectPrivate->removeDestructionHandler(handler: this); |
| 140 | } |
| 141 | if (streamInterface) { |
| 142 | // TODO: StreamInterface might be in a different thread |
| 143 | streamInterface->d->disconnectMediaStream(); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void 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 | |
| 169 | void AbstractMediaStreamPrivate::setMediaObjectPrivate(MediaObjectPrivate *mop) |
| 170 | { |
| 171 | // TODO: MediaObject might be in a different thread |
| 172 | mediaObjectPrivate = mop; |
| 173 | mediaObjectPrivate->addDestructionHandler(handler: this); |
| 174 | if (!errorText.isEmpty()) { |
| 175 | mediaObjectPrivate->streamError(errorType, errorText); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | void 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 |
| 195 | |