Phonon

iodevicestream.cpp
1/*
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
3 Copyright (C) 2011 Harald Sitter <sitter@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) version 3, or any
9 later version accepted by the membership of KDE e.V. (or its
10 successor approved by the membership of KDE e.V.), Nokia Corporation
11 (or its successors, if any) and the KDE Free Qt Foundation, which shall
12 act as a proxy defined in Section 6 of version 3 of the license.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "iodevicestream_p.h"
24#include "abstractmediastream_p.h"
25
26#include <QIODevice>
27
28#ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM
29
30namespace Phonon
31{
32
33class IODeviceStreamPrivate : public AbstractMediaStreamPrivate
34{
35 P_DECLARE_PUBLIC(IODeviceStream)
36 protected:
37 IODeviceStreamPrivate(QIODevice *_ioDevice)
38 : ioDevice(_ioDevice)
39 {
40 if (!ioDevice->isOpen()) {
41 ioDevice->open(QIODevice::ReadOnly);
42 }
43 Q_ASSERT(ioDevice->isOpen());
44 Q_ASSERT(ioDevice->isReadable());
45 streamSize = ioDevice->size();
46 streamSeekable = !ioDevice->isSequential();
47 }
48
49 private:
50 QIODevice *ioDevice;
51};
52
53IODeviceStream::IODeviceStream(QIODevice *ioDevice, QObject *parent)
54 : AbstractMediaStream(*new IODeviceStreamPrivate(ioDevice), parent)
55{
56 Q_D(IODeviceStream);
57 d->ioDevice->reset();
58}
59
60IODeviceStream::~IODeviceStream()
61{
62}
63
64void IODeviceStream::reset()
65{
66 Q_D(IODeviceStream);
67 d->ioDevice->reset();
68}
69
70void IODeviceStream::needData()
71{
72 quint32 size = 4096;
73 Q_D(IODeviceStream);
74 const QByteArray data = d->ioDevice->read(size);
75 writeData(data);
76 if (d->ioDevice->atEnd()) {
77 endOfData();
78 }
79}
80
81void IODeviceStream::seekStream(qint64 offset)
82{
83 Q_D(IODeviceStream);
84 d->ioDevice->seek(offset);
85}
86
87} // namespace Phonon
88
89#endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM
90
91#include "moc_iodevicestream_p.cpp"
92
93// vim: sw=4 sts=4 et tw=100
bool isOpen() const const
bool isReadable() const const
virtual bool isSequential() const const
virtual bool open(QIODeviceBase::OpenMode mode)
virtual qint64 size() const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:24 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.