| 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 "streaminterface.h" |
| 24 |
#include "streaminterface_p.h" |
| 25 |
#include "abstractmediastream.h" |
| 26 |
#include "abstractmediastream_p.h" |
| 27 |
#include "mediasource_p.h" |
| 28 |
|
| 29 |
QT_BEGIN_NAMESPACE |
| 30 |
|
| 31 |
#ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM |
| 32 |
|
| 33 |
namespace Phonon |
| 34 |
{ |
| 35 |
|
| 36 |
StreamInterface::StreamInterface() |
| 37 |
: d(new StreamInterfacePrivate) |
| 38 |
{ |
| 39 |
d->q = this; |
| 40 |
} |
| 41 |
|
| 42 |
StreamInterface::~StreamInterface() |
| 43 |
{ |
| 44 |
if (d->connected) { |
| 45 |
AbstractMediaStreamPrivate *dd = d->mediaSource.stream()->d_func(); |
| 46 |
dd->setStreamInterface(0); |
| 47 |
} |
| 48 |
delete d; |
| 49 |
} |
| 50 |
|
| 51 |
void StreamInterface::connectToSource(const MediaSource &mediaSource) |
| 52 |
{ |
| 53 |
Q_ASSERT(!d->connected); |
| 54 |
d->connected = true; |
| 55 |
d->mediaSource = mediaSource; |
| 56 |
Q_ASSERT(d->mediaSource.type() == MediaSource::Stream); |
| 57 |
Q_ASSERT(d->mediaSource.stream()); |
| 58 |
AbstractMediaStreamPrivate *dd = d->mediaSource.stream()->d_func(); |
| 59 |
dd->setStreamInterface(this); |
| 60 |
d->mediaSource.stream()->reset(); |
| 61 |
} |
| 62 |
|
| 63 |
void StreamInterfacePrivate::disconnectMediaStream() |
| 64 |
{ |
| 65 |
Q_ASSERT(connected); |
| 66 |
connected = false; |
| 67 |
|
| 68 |
// if mediaSource has autoDelete set then it will delete the AbstractMediaStream again who's |
| 69 |
// destructor is calling us right now |
| 70 |
mediaSource.setAutoDelete(false); |
| 71 |
|
| 72 |
mediaSource = MediaSource(); |
| 73 |
q->endOfData(); |
| 74 |
q->setStreamSeekable(false); |
| 75 |
} |
| 76 |
|
| 77 |
void StreamInterface::needData() |
| 78 |
{ |
| 79 |
if (d->mediaSource.type() == MediaSource::Stream) { |
| 80 |
d->mediaSource.stream()->needData(); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
void StreamInterface::enoughData() |
| 85 |
{ |
| 86 |
Q_ASSERT(d->connected); |
| 87 |
if (d->mediaSource.type() == MediaSource::Stream) { |
| 88 |
d->mediaSource.stream()->enoughData(); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
void StreamInterface::seekStream(qint64 offset) |
| 93 |
{ |
| 94 |
Q_ASSERT(d->connected); |
| 95 |
if (d->mediaSource.type() == MediaSource::Stream) { |
| 96 |
d->mediaSource.stream()->seekStream(offset); |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
void StreamInterface::reset() |
| 101 |
{ |
| 102 |
Q_ASSERT(d->connected); |
| 103 |
if (d->mediaSource.type() == MediaSource::Stream) { |
| 104 |
d->mediaSource.stream()->reset(); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
} // namespace Phonon |
| 109 |
|
| 110 |
#endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM |
| 111 |
|
| 112 |
QT_END_NAMESPACE |