File indexing completed on 2025-02-09 05:31:48
0001 /* 0002 Copyright (C) 2007 Matthias Kretz <kretz@kde.org> 0003 Copyright (C) 2011 Harald Sitter <sitter@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Lesser General Public 0007 License as published by the Free Software Foundation; either 0008 version 2.1 of the License, or (at your option) version 3, or any 0009 later version accepted by the membership of KDE e.V. (or its 0010 successor approved by the membership of KDE e.V.), Nokia Corporation 0011 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0012 act as a proxy defined in Section 6 of version 3 of the license. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Lesser General Public License for more details. 0018 0019 You should have received a copy of the GNU Lesser General Public 0020 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include "iodevicestream_p.h" 0024 #include "abstractmediastream_p.h" 0025 0026 #include <QIODevice> 0027 0028 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM 0029 0030 namespace Phonon 0031 { 0032 0033 class IODeviceStreamPrivate : public AbstractMediaStreamPrivate 0034 { 0035 P_DECLARE_PUBLIC(IODeviceStream) 0036 protected: 0037 IODeviceStreamPrivate(QIODevice *_ioDevice) 0038 : ioDevice(_ioDevice) 0039 { 0040 if (!ioDevice->isOpen()) { 0041 ioDevice->open(QIODevice::ReadOnly); 0042 } 0043 Q_ASSERT(ioDevice->isOpen()); 0044 Q_ASSERT(ioDevice->isReadable()); 0045 streamSize = ioDevice->size(); 0046 streamSeekable = !ioDevice->isSequential(); 0047 } 0048 0049 private: 0050 QIODevice *ioDevice; 0051 }; 0052 0053 IODeviceStream::IODeviceStream(QIODevice *ioDevice, QObject *parent) 0054 : AbstractMediaStream(*new IODeviceStreamPrivate(ioDevice), parent) 0055 { 0056 Q_D(IODeviceStream); 0057 d->ioDevice->reset(); 0058 } 0059 0060 IODeviceStream::~IODeviceStream() 0061 { 0062 } 0063 0064 void IODeviceStream::reset() 0065 { 0066 Q_D(IODeviceStream); 0067 d->ioDevice->reset(); 0068 } 0069 0070 void IODeviceStream::needData() 0071 { 0072 quint32 size = 4096; 0073 Q_D(IODeviceStream); 0074 const QByteArray data = d->ioDevice->read(size); 0075 writeData(data); 0076 if (d->ioDevice->atEnd()) { 0077 endOfData(); 0078 } 0079 } 0080 0081 void IODeviceStream::seekStream(qint64 offset) 0082 { 0083 Q_D(IODeviceStream); 0084 d->ioDevice->seek(offset); 0085 } 0086 0087 } // namespace Phonon 0088 0089 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM 0090 0091 #include "moc_iodevicestream_p.cpp" 0092 0093 // vim: sw=4 sts=4 et tw=100