File indexing completed on 2025-02-09 05:31:53
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 "streaminterface.h" 0024 #include "streaminterface_p.h" 0025 #include "abstractmediastream.h" 0026 #include "abstractmediastream_p.h" 0027 #include "mediasource_p.h" 0028 0029 #ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM 0030 0031 namespace Phonon 0032 { 0033 0034 StreamInterface::StreamInterface() 0035 : d(new StreamInterfacePrivate) 0036 { 0037 d->q = this; 0038 } 0039 0040 StreamInterface::~StreamInterface() 0041 { 0042 if (d->connected) { 0043 AbstractMediaStreamPrivate *dd = d->mediaSource.stream()->d_func(); 0044 dd->setStreamInterface(nullptr); 0045 } 0046 delete d; 0047 } 0048 0049 void StreamInterface::connectToSource(const MediaSource &mediaSource) 0050 { 0051 Q_ASSERT(!d->connected); 0052 d->connected = true; 0053 d->mediaSource = mediaSource; 0054 Q_ASSERT(d->mediaSource.type() == MediaSource::Stream); 0055 Q_ASSERT(d->mediaSource.stream()); 0056 AbstractMediaStreamPrivate *dd = d->mediaSource.stream()->d_func(); 0057 dd->setStreamInterface(this); 0058 // Operations above do not access the stream itself, so they do not need to 0059 // use invokeMethod. 0060 reset(); 0061 } 0062 0063 // Does not need to use invokeMethod as we are are not accessing the stream. 0064 void StreamInterfacePrivate::disconnectMediaStream() 0065 { 0066 Q_ASSERT(connected); 0067 connected = false; 0068 0069 // if mediaSource has autoDelete set then it will delete the AbstractMediaStream again who's 0070 // destructor is calling us right now 0071 mediaSource.setAutoDelete(false); 0072 0073 mediaSource = MediaSource(); 0074 q->endOfData(); 0075 q->setStreamSeekable(false); 0076 } 0077 0078 void StreamInterface::needData() 0079 { 0080 if (d->mediaSource.type() == MediaSource::Stream) { 0081 QMetaObject::invokeMethod(d->mediaSource.stream(), "needData", Qt::QueuedConnection); 0082 } 0083 } 0084 0085 void StreamInterface::enoughData() 0086 { 0087 Q_ASSERT(d->connected); 0088 if (d->mediaSource.type() == MediaSource::Stream) { 0089 QMetaObject::invokeMethod(d->mediaSource.stream(), "enoughData", Qt::QueuedConnection); 0090 } 0091 } 0092 0093 void StreamInterface::seekStream(qint64 offset) 0094 { 0095 Q_ASSERT(d->connected); 0096 if (d->mediaSource.type() == MediaSource::Stream) { 0097 QMetaObject::invokeMethod(d->mediaSource.stream(), "seekStream", Qt::QueuedConnection, Q_ARG(qint64, offset)); 0098 } 0099 } 0100 0101 void StreamInterface::reset() 0102 { 0103 Q_ASSERT(d->connected); 0104 if (d->mediaSource.type() == MediaSource::Stream) { 0105 QMetaObject::invokeMethod(d->mediaSource.stream(), "reset", Qt::QueuedConnection); 0106 } 0107 } 0108 0109 } // namespace Phonon 0110 0111 #endif //QT_NO_PHONON_ABSTRACTMEDIASTREAM 0112 0113